# Blosxom Plugin: flickr # Author(s): Adrian Sampson # Version: 0.1 # Documentation: See the bottom of this file or type: perldoc flickr # Updates: http://adrian.pygmysoftware.com/blog/blosxom/flickr/ # Copyright 2004 Adrian Sampson # Released under the same License as Blosxom package flickr; use File::stat; # --- Configurable variables ----- # URL of feed from Flickr my $url = 'http://www.flickr.com/services/feeds/photos_public.gne?id=48889110751@N01&format=rss_200'; # html template for each photo my $template = '$title'."\n"; # items to display (0 for no limit) $num_display = 4; # seconds to cache between downloads $reload_delay = 30 * 60; # feed cache file my $cache = "$blosxom::plugin_state_dir/flickr_cache.rss"; # set the path to curl to use it instead of LWP::Simple # my $curl_path = '/usr/bin/curl'; # probably '/usr/bin/curl' # -------------------------------- # reference as $flickr::photos $photos; sub start { 1; } sub head { my($pkg, $currentdir, $head_ref) = @_; # fill out html representation if (!-d $cache_dir) { mkdir $cache_dir; } my $rss; if (!stat($cache) || time - stat($cache)->mtime >= $reload_delay) { if ($curl_path) { $rss = `$curl_path '$url' 2>/dev/null`; } else { require LWP::Simple; $rss = LWP::Simple::get($url); } open(FILE,'>',$cache); print FILE $rss; close FILE; } elsif (open(FILE,$cache)) { $rss = join '',; close FILE; } my @items = parse_rss($rss); for my $item (@items[0..(($num_display && $num_display < $#items) ? $num_display-1 : @items-1)]) { my $title = $item->{'title'}; my $link = $item->{'link'}; my $description = $item->{'description'}; $description =~ /src="(.+?)"/; my $image = $1; if ($image) { $image =~ s/_m\./_s\./; $photos .= eval("qq{$template}"); } } 1; } # my extremely simple, extremely slow (presumably) RSS parser # to eliminate dependencies # will probably break on a lot of feeds sub parse_rss { local $_; my @items; my @rss_items = split(/ ]/,shift); for (@rss_items[1..@rss_items-1]) { my %item; $item{'title'} = (/(.*)<\/title>/s)[0]; $item{'link'} = (/<link>(.*)<\/link>/s)[0]; $item{'description'} = (/<description>(.*)<\/description>/s)[0]; push @items,\%item; } @items; } 1; __END__ =head1 NAME Blosxom Plug-in: C<flickr> =head1 SYNOPSIS Purpose: Displays a Flickr photostream in flavour templates. Flickr is an online photo sharing site. L<http://www.flickr.com/> =head1 VERSION 0.1 =head1 CONFIGURATION There are a few values that need to be configured before C<flickr> is useful. =over =item C<$url> The URL of the Flickr RSS feed to be displayed. =item C<$template> The format for each article. C<$title> will be replaced with the title of the photo; C<$link> will be replaced with the URL of the photo's info page on Flickr; C<$image> will be replaced with the URL of the photo's square (75x75) thumbnail. =item C<$num_display> Maximum number of photos to display. =item C<$reload_delay> The number of seconds to cache the photostream before downloading it again. =item C<$cache> The file where C<flickr> should store its cached RSS feed. =item C<$curl_path> By default, C<flickr> fetches RSS feeds using C<LWP::Simple>. If C<$curl_path> is set, it will use the C<curl> at that location instead. =back =head1 USAGE In the head.flavour and foot.flavour templates, use C<$flickr::photos> to insert your syndicated photos. =head1 AUTHOR Adrian Sampson <adrian@pygmysoftware.com> L<http://caprahircus.ws/> =head1 BUGS =over =item * RSS parser is unbelievably simplistic and probably breaks. It's ridiculously undertested. =back Reports of other bugs should be directed to the author. =head1 LICENSE C<flickr> Copyright 2003, Adrian Sampson (This license is the same as Blosxom's.) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.