imported>mutante mNo edit summary |
imported>mutante mNo edit summary |
||
Line 22:
This is possible due to using a) the [http://www.flickr.com/services/api/ Flickr API], b) [http://www.phpflickr.com/ phpFlickr], c) the Debian [http://packages.debian.org/unstable/web/php-pear PHP-Pear packages] and d) a nice article in the latest [[iX]] (german) magazine, issue July 2006, p. 62 called "Bildergeflimmer". We could call this a [[Flickr]]->[[Mediawiki]] [http://www.programmableweb.com/matrix Mashup] (->same iX issue, p. 55). [[User:mutante|mutante]] 20:56, 18 June 2006 (CEST)
=== Source ===
<pre>
<?php
# Flickr > Mediawiki MashUp Test (Web 2.3)
# mutante from http://s23.org/wiki
# inspired by "iX" magazine issue July 2006, p.62 article "Bildergeflimmer"
# greets to cosmea
$wgExtensionFunctions[] = "wfFlickrExtension";
# extension hook callback function from mediawiki
function wfFlickrExtension() {
global $wgParser;
$wgParser->setHook( "flickr", "renderFlickr" );
}
function renderFlickr( $input, $argv ) {
global $wgOutputEncoding;
# How many pictures to show , limit < 10
if (is_numeric($argv["limit"]) && $argv["limit"]>=0 && $argv["limit"] <=11) {
$limit=$argv["limit"];
} else {
$limit=3;
}
# just in case
$input = mysql_escape_string($input);
# If not too long, set Input Text as Tag
if (!is_string($input) || strlen($input)>255) {
$input="error";
} else {
$tag=$input;
}
require_once("phpFlickr.php");
$f = new phpFlickr("<Your FlickrAPI key here>");
$f->enableCache("fs","./flickr_cache");
# get the X most interesting pictures for this tag
$photos_interesting = $f->photos_search(array("tags"=>"$tag", "sort"=>"interestingness-desc","per_page"=>$limit));
# output a table with the pictures
$output.="<table><tr><td colspan='$limit'>The $limit most interesting photos from Flickr for the tag <b>'$tag'</b></td></tr><$
foreach ($photos_interesting['photo'] as $photo) {
$output.="<td><img border='0' alt='$photo[title]' " . " src=". $f->buildPhotoURL($photo, "Square") . "></td>";
}
$output.="</tr></table>";
return $output;
}
?>
</pre>
As always, this is just a quick example, and can be heavily extended. Feel free to do so.
[[Category:Mediawiki Extensions]]
|
Revision as of 19:08, 18 June 2006
I have written this little Mediawiki Extension to include Flickr thumbnails, this gets the x most interesting (yes, Flickr really sorts like "sort"=>"interestingness-desc", by the users rating) for the tag you specify. You can use this to put some related pictures on Wiki pages that dont have pictures yet very quickly.
What you type:
<flickr>Leary</flickr>
What you get:
<flickr>Leary</flickr>
What you type:
<flickr limit=5>Fnord</flickr>
What you get:
<flickr limit=5>Fnord</flickr>
The <flickr>-tag surrounds a keyword/Flickr Tag and optionally you can use limit to change the amount of thumbnails being shown, the maximum for tag-length is 255 chars and the maximum for limit is 10.
This is possible due to using a) the Flickr API, b) phpFlickr, c) the Debian PHP-Pear packages and d) a nice article in the latest iX (german) magazine, issue July 2006, p. 62 called "Bildergeflimmer". We could call this a Flickr->Mediawiki Mashup (->same iX issue, p. 55). mutante 20:56, 18 June 2006 (CEST)
Source
<?php # Flickr > Mediawiki MashUp Test (Web 2.3) # mutante from http://s23.org/wiki # inspired by "iX" magazine issue July 2006, p.62 article "Bildergeflimmer" # greets to cosmea $wgExtensionFunctions[] = "wfFlickrExtension"; # extension hook callback function from mediawiki function wfFlickrExtension() { global $wgParser; $wgParser->setHook( "flickr", "renderFlickr" ); } function renderFlickr( $input, $argv ) { global $wgOutputEncoding; # How many pictures to show , limit < 10 if (is_numeric($argv["limit"]) && $argv["limit"]>=0 && $argv["limit"] <=11) { $limit=$argv["limit"]; } else { $limit=3; } # just in case $input = mysql_escape_string($input); # If not too long, set Input Text as Tag if (!is_string($input) || strlen($input)>255) { $input="error"; } else { $tag=$input; } require_once("phpFlickr.php"); $f = new phpFlickr("<Your FlickrAPI key here>"); $f->enableCache("fs","./flickr_cache"); # get the X most interesting pictures for this tag $photos_interesting = $f->photos_search(array("tags"=>"$tag", "sort"=>"interestingness-desc","per_page"=>$limit)); # output a table with the pictures $output.="<table><tr><td colspan='$limit'>The $limit most interesting photos from Flickr for the tag <b>'$tag'</b></td></tr><$ foreach ($photos_interesting['photo'] as $photo) { $output.="<td><img border='0' alt='$photo[title]' " . " src=". $f->buildPhotoURL($photo, "Square") . "></td>"; } $output.="</tr></table>"; return $output; } ?>
As always, this is just a quick example, and can be heavily extended. Feel free to do so.