|
Cookbook /
FlickrAlbumSummary: Display images dynamically from Flickr
Status: Stable
Version: 2007-03-05
Prerequisites: PmWiki 2.0
Maintainer: JonHaupt
Categories: Images
Questions answered by this recipe
DescriptionUsing this recipe will allow you to have albums of Flickr photos in your wiki that update automatically when new photos are added to Flickr. This recipe requires the use of the phpFlickr class written by Dan Coulter, a Flickr API key, and this recipe. You may also need to use MySQL (see below). Follow these steps to Flickr photos in your site:
The script will display an album of photos by a given username. The album is contained in a div called "flickralbum" which can then be styled using skin or local css. The simplest album can be created by using the markup (:flickralbum:) which will create an album of 12 of the most recent photos added to Flickr in 6 columns. (:flickralbum user=foo:) can, then, be used to create a similar album of recent photos by someone with the Flickr username foo, etc. The following is a list of arguments possible for other combinations:
As of version 0.5, you can also specify that the images returned be displayed using Lightbox, using "lightbox=1". In order to do this, you have to install Lightbox JS on your server in a web-accessible location, then add the following to config.php:
# lightbox
$HTMLHeaderFmt['lightbox'] = "
<script type='text/javascript' src='http://your.url/lightbox/js/prototype.js'></script>
<script type='text/javascript' src='http://your.url/lightbox/js/scriptaculous.js?load=effects'></script>
<script type='text/javascript' src='http://your.url/lightbox/js/lightbox.js'></script>";
For examples, see my test site. NotesMany other uses of phpFlickr are available and future tweaks of this recipe are planned, particularly for displaying photos in sets and groups.
Updates2007-05-03: Added global variables for database/filesystem caches, changed styling for images (now you should use .flickralbum in your CSS instead of #flickralbum).
Comments
I originally wrote this specifically to require a username, but perhaps it isn't necessary. I'll see about making no-username an option. (update: fixed for 0.3) As for wildcards, I'm not sure how to do that, I'll look into it. - JonHaupt
I'm confused about the difference between screen names and user names in Flickr--are they different? I believe that the script will look up only by username. In any event, if the username has two words, you'll need to use single quotes, as in user='Geoffrey Wright', not double quotes. I tried it with a couple of user names and it does seem to work. Let me know if this still doesn't work. -- JonHaupt
I plan to get around to this eventually, indeed it's a fairly basic functionality, but I don't really have time right now; if anybody wants to add this, feel free.
Please find below code to be added into flickr-album.php to support photo set. Be sure to get latest phpFlickr.
case 3: // Set
$photos = $f->photosets_getPhotos($opt['set'], NULL, NULL, $opt['number']);
if (is_array($photos['photo'])) {
// Build the album
foreach ($photos['photo'] as $photo) {
// Have to fix url for each photo if no username
if ($opt['user'] == '') $photos_url = "http://www.flickr.com/photos/".$photo['owner']."/";
// Build image and link tags for each photo
$output .= "<a href='";
if ($opt['lightbox'] == 1) $output .= $f->buildPhotoURL($photo, $opt['size2'])."' rel='lightbox[flickr]' title='<a href="$photos_url$photo[id]">$photo[title]</a>'";
else $output .= "$photos_url$photo[id]'";
$output .= "><img alt='$photo[title]' "."src='".$f->buildPhotoURL($photo, $opt['size'])."'>";
$output .= "</a>";
$i++;
// If it reaches the end photo for $opt['columns'], insert a line break
if ($i % $opt['columns'] == 0) $output .= "<br />";
} // End of user search
}// End of if
break;
what should be opened when you click on the thumbnail? -- JonHaupt
ah i mean a larger version of the picture, eventually with a link to the corresponding flickrpage. maybe fullsize is to big as some flickr images are pretty big at full reso. maybe and aditional atrribute which defines the defines the dimension of the fullsize image? just some suggestions... i would do that myself id i had any php skills -- elektromeier
I'm working on groups and sets, but having trouble currently with variable mixups between PmWiki and phpFlickr. I do plan to release this sometime though, and if anyone else feels like trying it, go right ahead. -- JonHaupt
Warning: Invalid argument supplied for foreach() in ../PmWiki/cookbook/flickr-album.php on line 119
Warning: Cannot modify header information - headers already sent by (output started at ../PmWiki/cookbook/flickr-album.php:119) in ..PmWiki/pmwiki.php on line 870
-straitastudents
I've fixed the problem. If you're still getting errors, let me know. - JonHaupt
Sure - all you need to do is style images within the .flickralbum div using CSS. So you can add something like the below to the local.css file in /pub/css. --JonHaupt
.flickralbum { margin:25px; }
.flickralbum img {
padding:5px;
margin:5px;
border:1px solid #afafaf;
}
It would be great to be able to search by group and also to add a randomiser in there...Thanks Nick See AlsoContributors |