<?php if (!defined('PmWiki')) exit (); /* Original info: copyright 2010, Adam Overton based on code by Jon Haupt, copyright 2007-8 which was built on code from swf.php copyright 2004 Patrick R. Michaud and from quicktime.php copyright 2006 Sebastian Siedentopf. This file is distributed under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This recipe enables embedding of video and images hosted on Flickr.com using: (:flickr ...:) for slideshows & (:flickrvid ...:) for videos To install, add the following line to your config.php: include_once("$FarmD/cookbook/swf-sites-Flickr.php"); Be sure to add any default setup variables before including the recipe. See below for details. Replace-On-Edit Patterns ($ROEPatterns) have been created for this recipe, so that visitors can simply copy-and-paste the embed code, click save or save-and-edit, and have the code automatically converted to the appropriate pmwiki markup. If this is undesired, an admin can disable this in config.php by setting $FlickrSlideshowROEenabled & $FlickrVidROEenabled to false. FLICKRSLIDESHOW FlickrSlideshow markup accepts a handful of parameters: (:flickr username userID [ photoset ] [ param1=... param2=... ]:) (in some cases username & userID are optional) FlickrSlideshow parameters: * username * userID - numerical ID, usually comes in the format of "12345678@N03" (userID can be found in the embed code for a slideshow, or by visiting http://idgettr.com) * photoset - optional: ID for the photoset you want to view (using the number in the url following /sets/12345.../) * tag - optional: used if you want display images labeled with a specific tag, i.e tag=cats * search - optional: used if you want to display images that comes up during a search, i.e. search=ugly+cats * sort (default: relevance) - optional: used in conjunction with search - options include relevance, interest, and recent * width & height (defaults: width=400, height=300) - in pixels, but don't add 'px' at the end! * scale (default: 1) - scale the slideshow's dimensions by some numerical factor (ex: 0.5 = half-size) (non-api) Examples: Simplest FlickrSlideshow embed: (:flickr myusername 12345678@N03:) Provide your own width & height (:flickr myusername 12345678@N03 width=700 height=525:) Display a photoset (providing a userID not required for this) (:flickr myusername 9876543210:) Display photos in your account that are tagged "cats" (:flickr myusername 12345678@N03 tag=cats:) Display photos in your account that come up when searching for "cats", sorted by most recent (:flickr myusername 12345678@N03 search=cats sort=recent:) Similarly, if you'd like to display any photos on Flickr that are tagged "cats", or that come up during a search of "cats", just omit the account information: (:flickr tag=cats:) (:flickr search=cats sort=recent:) If you've added a default username and userID to your config (see below), then they can be omitted from most of the examples above, for example (:flickr:) will return all photos from your photostream. * exception: if you want to display tags or searches in your own profile, you *must* provide your username & userID - reason: if the default userinfo was always used, then the recipe wouldn't allow displaying all photos from the rest of flickr with those tags or searchterms. The following default setup variables are available for use in config.php, before including the recipe: * $FlickrSlideshowDefaultParams, examples: ** set the default width & height *** $FlickrSlideshowDefaultParams['width'] = "700"; *** $FlickrSlideshowDefaultParams['height'] = "525"; ** adding these prevents you from ever having to enter in your username or user_id *** $FlickrSlideshowDefaultParams['flickr_username'] = "myusername"; *** $FlickrSlideshowDefaultParams['flickr_user_id'] = "12345678@N03"; * $FlickrSlideshowROEenabled - true or false (default: true) - turns Replace-On-Edit-Patterns Off/On for embed code entered into a browser window * $FlickrSlideshowROEFmt - default is '(:flickr [args] scale=1:)' - default replacement of FlickrSlideshow embed code - change it if you'd rather FlickrSlideshow embed code be replaced with a different set of default variables. * Note: FlickrSlideshow is not yet XHTML 1.0 compliant FLICKRVID FlickrVid markup accepts a handful of parameters, though not as many as Vimeo & Youtube: (:flickrvid videocode secret=secretval [ param1=val1 param2=val2 ... ] :) Look for videocode in the embed code for "photo_id=somenumber" FlickrVid parameters: * secret (required) - this can be obtained from the embed code on the users pages - look for photo_secret=somenumber * width & height (defaults: width=400, height=300) - in pixels, but don't add 'px' at the end! (non-api) * scale (default: 1) - scale the video's dimensions by some numerical factor (ex: 0.5 = half-size) (non-api) * showinfo - true or false (default: true) - display the video information before and after playing Examples: Simplest FlickrVid embed: (:flickrvid secret=98765 id=43210:) ... or provide your own width & height, and turn video info off (:flickrvid secret=98765 id=43210 width=425 height=344 showinfo=false:) The following default setup variables are available for use in config.php, before including the recipe: * $FlickrVidDefaultParams * $FlickrVidROEenabled - true or false (default: true) - turns Replace-On-Edit-Patterns Off/On for embed code entered into a browser window * $FlickrVidROEFmt - default is '(:flickrvid $1 scale=1:)' - default replacement of FlickrVid embed code - change it if you'd rather FlickrVid embed code be replaced with a different set of default variables. * Note: FlickrVid is not yet XHTML 1.0 compliant - I was unable to locate any leads online yet that work. If you have any suggestions, do let me know. . . . Versions: * 2010-12-21 - fixed bug with FlickrVid that was causing (:flickr:) markup to also catch content intended for (:flickrvid:) * 2010-05-16 - initial release - incorporated FlickrVid and FlickrSlideshow into one recipe */ # Version date $RecipeInfo['SWFSites-Flickr']['Version'] = '2010-12-21'; ### FLICKR SLIDESHOW ### (:flickr username photoset params=params:) /* ## original Markup('flickrslideshow', '<img', "/\\(:flickr\\s+([^\\s]+)\\s+(([^\\s]+@[^\\s]+)|(\d*))\\s*(.*):\\)/e", // $2 = set or userID ##"/\\(:flickr\\s+([^\\s\=]+)\\s*(([^\\s\=]+@[^\\s\=]+)|(\d*))\\s*(.*):\\)/e", # attempt to only accept tag "DisplayFlickrSlideshow('$1','$3','$4','$5')"); */ Markup('flickrslideshow', '<img', "/\\(:flickr\\s+(.*):\\)/e", "DisplayFlickrSlideshow('$1')"); SDVA($FlickrSlideshowDefaultParams, array( 'width' => '400' ,'height' => '300' ,'scale' => '1' ,'flickr_username' => '' # default username ,'flickr_user_id' => '' # default userID - you can find this by visiting http://idgettr.com ,'sort' => 'relevance' )); SDV($FlickrSlideshowROEenabled, true); # ROEPatterns - FLICKRSLIDESHOW EMBED CONVERSION # Converts pasted FlickrSlideshow embed code into valid pmwiki (:flickr:) code if ($FlickrSlideshowROEenabled) { $ROEPatterns['!<object.*http://www.flickr.com/apps/slideshow.*<\/object>!ie'] = "FlickrSlideshowROE(PSS('$0'))"; SDV($FlickrSlideshowROEFmt, '(:flickr [args] scale=1:)'); #SDV($FlickrSlideshowROEFmt, '(:flickr [args] scale=1 width='.$FlickrSlideshowDefaultParams['width'].' height='.$FlickrSlideshowDefaultParams['height'].':)'); function FlickrSlideshowROE($args) { global $FlickrSlideshowROEFmt; # switch out urlcodes for [/, ?, =, &] to make it easier to read and find certain items $args = str_replace(array("%2F","%3F","%3D","%26","%40"),array("/","?","=","&","@"),$args); # get username - photos/username/ if(preg_match('#photos/([^/]+)/#', $args, $matches)) $flickr_username = $matches[1]; # get user_id - &user_id=12345678@N03& if(preg_match('#user_id=([^&]+)&#', $args, $matches)) $flickr_user_id = " $matches[1]"; # get set_id - &set_id=12345678901234567& if(preg_match('#set_id=([^&]+)&#', $args, $matches)) $photosetID = " $matches[1]"; # get tag - /tags/blammo/ if(preg_match('#tags/([^/]+)/#', $args, $matches)) $tags = " tag=$matches[1]"; # get search & sort - ?q=searchterm& if(preg_match('#\?q\=([^&]+)&#', $args, $matches)) $search = " search=$matches[1]"; if(preg_match('#&s=([^&]+)&#', $args, $matches)) { if ($matches[1]=="rec") $sort = " sort=recent"; elseif ($matches[1]=="int") $sort = " sort=interesting"; else $sort = " sort=relevance"; } ## gathering width and height here b/c flickr offers different embed dimensions preg_match('#width=["\'](\d+)["\'] height=["\'](\d+)["\']#', $args, $matches); $size = " width=".$matches[1]." height=".$matches[2]; # output #$out = str_replace('[args]',"$flickr_username$photosetID$flickr_user_id$tags$size",$FlickrSlideshowROEFmt); $out = str_replace('[args]',"$flickr_username$photosetID$flickr_user_id$tags$size$search$sort",$FlickrSlideshowROEFmt); return $out; } } # FLICKR SLIDESHOW FUNCTION #function DisplayFlickrSlideshow($flickr_username, $flickr_user_id, $photosetID, $args, $tagsOnly) { function DisplayFlickrSlideshow($args) { global $FlickrSlideshowDefaultParams; $args = array_merge($FlickrSlideshowDefaultParams, ParseArgs($args)); # PARSE ARGS - to make things easier, parsing args here rather than in the MarkupExpr ## $args[""] contains all arguments unpreceded by "arg=" -- in this case $flickr_user_id, $photoset, and $flickr_username are located here and must be pulled out... if($args[""]) { foreach($args[""] as $k => $v) { #echo "key: $k, val: $v<br />"; preg_match("#(([^\\s]+@[^\\s]+)|(\d+)|([^\\s]+))#",$v,$matches); if($matches[2]) $flickr_user_id = $matches[2]; # flickr_user_id elseif($matches[3]) $photosetID = $matches[3]; # photoset elseif($matches[4]) $flickr_username = $matches[4]; # flickr_username } #echo "<br />"; } #echo $flickr_user_id."<br />".$photosetID."<br />".$flickr_username."<br />"; # use default username & user_id if not provided # don't get user info if a search is being performed, or if a tag is being looked for... may not want a specific user while searching... if (!$args["search"] && !$args["tag"]) { if (!$flickr_username) $flickr_username = $args["flickr_username"]; if (!$flickr_user_id) $flickr_user_id = $args["flickr_user_id"]; } # define width & height ## one can supply a 'scale' default different than '1', but it's not suggested, as it could be confusing to users $scale = $args['scale']; $width = $args['width'] * $scale; $height = $args['height'] * $scale; # get tag (can only provide 1 tag) - multiple words are separated by '+' $tag = $args['tag']; #echo $tag."<br />"; if ($tag) { $tagSlash = "tags/$tag/"; $tag = "&tags=$tag"; } # get search terms $search = $args['search']; if ($search) { $sort = $args['sort']; if ($sort=="interesting") { $sort = "int"; $sortLong = "interestingness-desc"; } elseif ($sort=="recent") { $sort = "rec"; $sortLong = "date-posted-desc"; } else { $sort = ""; $sortLong = "relevance"; } } # get jump_to - jump_to starts the slideshow at whatever pic you specify $jumpto = $args['jumpto']; # SLIDESHOW # show a photoset if ($photosetID) { $flickrArgs = "offsite=true&lang=en-us&page_show_url=/photos/$flickr_username/sets/$photosetID/show/&page_show_back_url=/photos/$flickr_username/sets/$photosetID/&set_id=$photosetID&jump_to=$jumpto"; } else { if ($flickr_user_id) $flickr_user_id_url = "&user_id=$flickr_user_id"; if ($flickr_username) $flickr_username = "$flickr_username/"; # display a user's entire photostream as slideshow if (!$search) { ### Flickr is able to display all photos on it's site that contain a single tag; Haven't yet implemented that version with this recipe, but below is some experimentation... ### # show photos from flickr with a particular tag, but with no user specified $flickrArgs = "offsite=true&lang=en-us&page_show_url=/photos/$flickr_username{$tagSlash}show/&page_show_back_url=/photos/$flickr_username$tagSlash$flickr_user_id_url$tag&jump_to=$jumpto"; # displaying a search as a slideshow } else { ### Flickr is able to display all photos on it's site that contain a single tag; Haven't yet implemented that version with this recipe, but below is some experimentation... ### # show photos from flickr with a particular tag, but with no user specified $flickrArgs = "offsite=true&lang=en-us&page_show_url=/search/show/?q=$search&w=$flickr_user_id&s=$sort&page_show_back_url=/search/?q=$search&w=$flickr_user_id&s=$sort&method=flickr.photos.search&api_params_str=&api_text=$search&api_tag_mode=bool&api_user_id=$flickr_user_id&api_media=all&api_sort=$sortLong&jump_to=$jumpto&start_index=0"; } } # output code $out = "<object width='$width' height='$height'>"; $out .= "\n <param name='flashvars' value='$flickrArgs'></param>"; $out .= "\n <param name='movie' value='http://www.flickr.com/apps/slideshow/show.swf?v=71649'></param>"; $out .= "\n <param name='allowFullScreen' value='true'></param>"; $out .= "\n <embed type='application/x-shockwave-flash' src='http://www.flickr.com/apps/slideshow/show.swf?v=71649' allowFullScreen='true' flashvars='$flickrArgs' width='$width' height='$height'></embed>"; $out .= "\n</object>"; return Keep($out); } #### FLICKRVID Markup('flickrvid', '<img', "/\\(:flickrvid\\s+([^\\s]+)\\s*(.*)\\s*:\\)/e", "ShowFlickrVid('$1','$2')"); SDVA($FlickrVidDefaultParams, array( 'secret' => '' ,'width' => '400' ,'height' => '300' ,'scale' => '1' ,'showinfo' => '1' )); #SDV($FlickrVid_XHTMLcompliant, true); SDV($FlickrVidROEenabled, true); # ROEPatterns - FLICKRVID EMBED CONVERSION # Converts pasted FlickrVid embed code into valid pmwiki (:flickrvid:) code if ($FlickrVidROEenabled) { $ROEPatterns['!<object.*data="http://www\.flickr\.com/apps/video.*<\/object>!ie'] = "FlickrVidROE(PSS('$0'))"; SDV($FlickrVidROEFmt, '(:flickrvid [args] scale=1:)'); function FlickrVidROE($args) { global $FlickrVidROEFmt; # gather other parameters - secret, id, width, height, showinfo if(preg_match('#photo_id=(\d+)#', $args, $matches)) $params = "$matches[1]"; ## gathering width and height here b/c flickrvid now offers different embed dimensions preg_match('#width=["\'](\d+)["\'] height=["\'](\d+)["\']#', $args, $matches); $params .= " width=".$matches[1]." height=".$matches[2]; if(preg_match('#photo_(secret=[^&]+)&#', $args, $matches)) $params .= " $matches[1]"; if(strpos($args,'flickr_show_info_box=true')) $params .= " showinfo=true"; $out = str_replace('[args]',$params,$FlickrVidROEFmt); return $out; } } function ShowFlickrVid($videocode, $args) { global $FlickrVidDefaultParams; $args = array_merge($FlickrVidDefaultParams, ParseArgs($args)); if(!$args['secret']) return "flickr error: you must provide the photo_secret"; # define width & height ## one can supply a 'scale' default different than '1', but it's not suggested, as it could be confusing to users $scale = $args['scale']; $width = $args['width'] * $scale; $height = $args['height'] * $scale; # flickr_show_info_box - this is an optional api-argument if ($args['showinfo']=='1' || $args['showinfo']=='true') $showinfo = "&flickr_show_info_box=true"; # ?v=NNNN doesn't seem to be necessary //$url = "http://www.flickr.com/apps/video/stewart.swf?v=1.167"; $url = "http://www.flickr.com/apps/video/stewart.swf"; $params = "intl_lang=en-us&photo_secret=".$args['secret']."&photo_id=".$videocode.$showinfo; $hw = "width='$width' height='$height'"; #echo "<br />$url $params $hw"; /* # XHTML 1.0 COMPLIANT ## seems like this should work, but it doesn't - commented out for now $out = "\n<object type='application/x-shockwave-flash' $hw data='$url' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'>"; $out .= "\n <param name='movie' value='$url' />"; $out .= "\n <param name='flashvars' value='$params' />"; $out .= "\n <param name='bgcolor' value='#000000' />"; $out .= "\n <param name='allowFullScreen' value='true' />"; $out .= "\n</object>"; */ # NON-COMPLIANT (exactly what Flickr provides) $out = "\n<object type='application/x-shockwave-flash' $hw data='$url' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'>"; $out .= "\n <param name='flashvars' value='$params' />"; $out .= "\n <param name='movie' value='$url' />"; $out .= "\n <param name='bgcolor' value='#000000' />"; $out .= "\n <param name='allowFullScreen' value='true' />"; $out .= "\n <embed type='application/x-shockwave-flash' src='$url' bgcolor='#000000' allowfullscreen='true' flashvars='$params' $hw></embed>"; $out .= "\n</object>"; return Keep($out); }