A problem occured while loading the plugin: krl_flickr_photoset -> : Assigning the return value of new by reference is deprecated on line 18
kelvinluck.com: krl_flickr_photoset
Get Firefox! creative commons

krl_flickr_photoset

I wrote this simple plugin because I wanted to display a list of my photosets from flickr.com on my photos page. It connects to flickr.com through the Flickr API and calls flickr.photosets.getList to get a list of photo sets for a given user and then outputs the primary photo thumbnail, title and description for each photo set and a link to the photo set on flickr.com.

Use the tag like so:

If you don’t use Textpattern but still want to use the underlying PHP code then please check the section “No Textpattern? No Problem!”.

PARAMETERS

The plugin takes one parameter, “id”. This should be the id of the user whose photo sets you want to get. In my case this is “51035610516@N01”.

CHANGELOG

2005-04-16 v0.1 First Release

REQUIREMENTS

This plugin relies on the DOMIT! XML parsing library for PHP. You must download this and put the files somewhere in your PHP include_path (or edit the require_once line to include the correct path). I am using version 0.99 and it works fine.

If you want to style the output of the photosets you can using CSS. This is how I do it on my site:

CSS:
div.photoset {
  padding: 0 5px 10px;
  border-bottom: 1px solid #ddd;
  margin: 0 0 10px;
  height: 80px;
}
div.photoset img {
  float: left;
  width: 75px;
  height: 75px;
  border: 1px solid #333;
  margin: 0 5px 0 0;
}

You could also choose to style “div.photoset h3” or “div.photoset p” if you want. For full control, after you have installed the plugin edit the code which is outputing the photoset HTML and make it something more suitable to your needs.

DOWNLOAD

You can download the plug-in from here:

krl_flickr_photoset 0.1


NO TEXTPATTERN? NO PROBLEM!

If you don’t use Textpattern but still have access to PHP on your server then maybe you would just like to use the code behind krl_flickr_photoset to power your own flickr photoset on your site? If so then this should help you! Note that the requirements section above will still be relevant to you.

PHP:
<?php

/**
* Simple code to display a user's Flickr photosets on a webpage
*
* Kelvin Luck < kelvin at kelvinluck dot com >
**/


define("REST_ENDPOINT", "http://www.flickr.com/services/rest/");

// change the following to the NSID of the person whose photos you want to display
$user_id = "51035610516@N01";
// and change the following to your Flickr API key
$api_key = "92502cc96511a84c1cfdbf990b71e8c1";
// and change this to be the path to your DOMIT installation - or the relative path from your include_path
$domit_path = "domit/"


$curl_url = REST_ENDPOINT."?api_key=".$api_key;
$curl_url .= "&method=flickr.photosets.getList";
$curl_url .= "&user_id=".$user_id;
$cu = curl_init($curl_url);
curl_setopt($cu, CURLOPT_RETURNTRANSFER, true);

$method_result = curl_exec($cu);
curl_close($cu);


require_once($domit_path."xml_domit_lite_include.php");
       
$xml_doc =& new DOMIT_Lite_Document();

$xml_doc->parseXML($method_result);

$photosets = $xml_doc->getElementsByTagName("photoset");

$num_photosets = $photosets->getLength();

$photosets_array = array();

for ($i=0; $i<$num_photosets; $i++) {
    $photoset_xml = $photosets->item($i);
    $photoset = array();
    $photoset["id"] = $photoset_xml->attributes["id"];
    $photoset["primary"] = $photoset_xml->attributes["primary"];
    $photoset["secret"] = $photoset_xml->attributes["secret"];
    $photoset["server"] = $photoset_xml->attributes["server"];
    $photoset["num_photos"] = $photoset_xml->attributes["photos"];
    $photoset["title"] = $photoset_xml->firstChild->firstChild->nodeValue;
    $photoset["description"] = $photoset_xml->childNodes[1]->firstChild->nodeValue;
    array_push($photosets_array, $photoset);
}

// that was the interesting part - try uncommenting the following line to see what you have:
// print_r $photosets_array;

// the rest of the code just outputs it in some HTML - you can edit it or rewrite it as you want.

$out = "";

foreach ($photosets_array as $photoset) {
    $out .= "<div class=\"photoset\">";
    $img_url = "http://photos".$photoset["server"].".flickr.com/";
    $img_url .= $photoset["primary"]."_".$photoset["secret"]."_s.jpg";
    $out .= "<img src=\"$img_url\" />";
    $out .= "<h3>".$photoset["title"]." [".$photoset["num_photos"]." photos]</h3>";
    $out .= "<p>".$photoset["description"];
    $out .= "<br /><a href=\"http://www.flickr.com/photos/".$user_id."/sets/".$photoset["id"]."\">";
    $out .= "view photoset";
    $out .= "</a></p>";
    $out .= "</div>";
}

// and edit this line if you want to do something other than echo the produced HTML
echo $out;
?>

FEEDBACK

Please leave any feedback on the plugin or suggestions for improvement below.

  1. Hey thanks for posting this Kelvin.

    Now I just need to get my host to address why curl is not working.

    -Josh
    — Joshua Bloom    Apr 25, 20:20    #
  2. No worries :)

    I should have mentioned about that you will need the CURL libraries compiled into your PHP install to use the above code…

    Cheers,

    Kelvin.
    Kelvin    Apr 30, 02:12    #
  3. So bwainee Kelvin…
    Michael Scott    May 22, 23:01    #
  4. thanks mixmaster :)
    Kelvin    May 27, 22:56    #