Lowkey Posted September 12, 2008 Share Posted September 12, 2008 I've been trying to modify a bit of code from the Fireboard Joomla! component, to turn Picasa RSS URL's into an embedded slideshow. There is already some code doing this for Youtube URL's, but I can't quite figure out how to write the regular expressions, which picks out the relevant pieces of information, since I'm only just beginning to learn all this stuff. Here's some of the code: This seems to make URL's into links - I don't really have to change anything there, but I guess it explains why the next piece of code looks for the html tags. function hyperlink($text) { $text = ' '.$text.' '; // match protocol://address:port/path/file.extension?some=variable&another=asf% // match protocol://address/path/file.extension?some=variable&another=asf% // match www.something.domain:port/path/file.extension?some=variable&another=asf% // match www.something.domain/path/file.extension?some=variable&another=asf% $text = preg_replace('/(?<!S)((http(s?):\/\/)|(www.))+([a-zA-Z0-9\/*+-_?&;:%=.,#]+)/', '<a href="http$3://$4$5" target="_blank" rel="nofollow">$4$5</a>', $text); // match name@address $text = preg_replace('/(?<!S)([a-zA-Z0-9_.\-]+\@[a-zA-Z][a-zA-Z0-9_.\-]+[a-zA-Z]{2,6})/', '<a href="mailto://$1">$1</a>', $text); return substr($text, 1, -1); } Next the conversion from link to embedded object takes place. // convert youtube links to embedded player $task->text = preg_replace('/<a href=[^>]+youtube.([^>\/]+)\/watch\?[^>]*v=([^>"&]+)[^>]+>[^<]+<\/a>/', '<object width="425" height="344"><param name="movie" value="http://www.youtube.$1/v/$2&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.$1/v/$2&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>', $task->text); // convert youtube playlists to embedded player $task->text = preg_replace('/<a href=[^>]+youtube.([^>\/]+)\/view_play_list\?[^>]*p=([^>"&]+)[^>]+>[^<]+<\/a>/', '<object width="480" height="385"><param name="movie" value="http://www.youtube.$1/p/$2"></param><embed src="http://www.youtube.$1/p/$2" type="application/x-shockwave-flash" width="480" height="385"></embed></object>', $task->text); Now, what I wanted, is to do the same thing with the picasa rss url, which looks like this: http://picasaweb.google.com/data/feed/base/user/lowkeydk/albumid/5192036729503695473?kind=photo&alt=rss&authkey=1LsBL6zHMN8&hl=en_US and turn it into this: <embed type="application/x-shockwave-flash" src="http://picasaweb.google.com/s/c/bin/slideshow.swf" width="288" height="192" flashvars="host=picasaweb.google.com&RGB=0x000000&feed=http%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2Flowkeydk%2Falbumid%2F5192036729503695473%3Fkind%3Dphoto%26alt%3Drss%26authkey%3D1LsBL6zHMN8" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed> So I need to extract the user, albumid and authkey. I've tried to write a regular expression based on the youtube example, but it seems that some characters aren't escaped properly when I run the script. If you need actual errormessages, I'll happily generate one for you, but that will be based on my feeble attempts. Quote Link to comment Share on other sites More sharing options...
effigy Posted September 12, 2008 Share Posted September 12, 2008 <pre> <?php $str = 'http://picasaweb.google.com/data/feed/base/user/lowkeydk/albumid/5192036729503695473?kind=photo&alt=rss&authkey=1LsBL6zHMN8&hl=en_US'; echo preg_replace('% \b http://picasaweb .+? user/([^/]+) /albumid/([^?]+) .+? authkey=([^&]+) \S+ (?<!\p{P}) %x', ' <embed type="application/x-shockwave-flash" src="http://picasaweb.google.com/s/c/bin/slideshow.swf" width="288" height="192" flashvars="host=picasaweb.google.com&RGB=0x000000&feed=http%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2F$1%2Falbumid%2F$2%3Fkind%3Dphoto%26alt%3Drss%26authkey%3D$3" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed> ', $str); ?> </pre> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.