<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Joe's Amazing Technicolor Weblog &#187; flickr</title>
	<atom:link href="http://slagwerks.com/blog/index.php/tag/flickr/feed/" rel="self" type="application/rss+xml" />
	<link>http://slagwerks.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 23 Jul 2010 22:31:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Custom flickr sidebar via wget, cron &amp; PHP</title>
		<link>http://slagwerks.com/blog/index.php/2009/07/29/custom-flickr-sidebar-via-wget-cron-php/</link>
		<comments>http://slagwerks.com/blog/index.php/2009/07/29/custom-flickr-sidebar-via-wget-cron-php/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 15:33:15 +0000</pubDate>
		<dc:creator>joe</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://slagwerks.com/blog/?p=305</guid>
		<description><![CDATA[The new site launched with a sidebar that shows two random photos from our flickr account, using their javascript widget. This was a great way to get things going, but now we&#8217;ve developed slightly more involved needs and I&#8217;ve had to come up with a custom&#160;solution. Getting the list of&#160;photos You need a flickr API [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://thefoodproject.org/">The new site</a> launched with a sidebar that shows two random photos from our flickr account, using their javascript widget. This was a great way to get things going, but now we&#8217;ve developed slightly more involved needs and I&#8217;ve had to come up with a custom&nbsp;solution.</p>
<h3>Getting the list of&nbsp;photos</h3>
<p>You need a flickr <span class="caps">API</span> key, which is quick <span class="amp">&amp;</span> easy to get. Then wget <span class="amp">&amp;</span> cron to get &#8216;em: <code>wget --quiet 'http://api.flickr.com/services/rest/?method=flickr.photos.search&amp;api_key=YOUR_API_KEY&amp;user_id=YOUR_USER_ID&amp;tags=website&amp;per_page=500' -O&nbsp;photos.xml</code></p>
<p>Note that this includes a <em>tags</em> argument. The thing that pushed me to switch the workflow was the desire to be able to upload photos to our flickr account that don&#8217;t necessarily fit into the sidebar format, such as panoramics. To handle this, everything that belongs on the website gets the tag <em>website</em>, and we only fetch those ones. We&#8217;ve also talked about just getting landscape oriented photos, but haven&#8217;t implemented&nbsp;that.</p>
<p>I&#8217;m running this daily, which is plenty often to update the available photo list. I believe this gets the newest 500, which seems more than adequate, particularly since we don&#8217;t have close to 500 photos&nbsp;yet.</p>
<h3>Parsing the list <span class="amp">&amp;</span> generating the&nbsp;<span class="caps">HTML</span></h3>
<p><span class="caps">PHP5</span>&#8217;s SimpleXML is pretty nice&thinsp;&#8212;&thinsp;here&#8217;s what we&#8217;re doing:<br />
<code> </code></p>
<pre>try {
  $xml = new SimpleXMLElement(file_get_contents('photos.xml'));
    $number_of_photos = count($xml-&gt;photos-&gt;photo);
    $displayed_photos = array();
    array_push(
      $displayed_photos,
      $xml-&gt;photos-&gt;photo[rand(0, $number_of_photos - 1)]);
    array_push(
      $displayed_photos,
      $xml-&gt;photos-&gt;photo[rand(0, $number_of_photos - 1)]);
    foreach ($displayed_photos as $photo) { ?&gt;
  &lt;div&gt;
&lt;?php
      print "&lt;a href=\"http://www.flickr.com/photos/8562013@N07/" .
        $photo['id'] . "\"&gt;&lt;img src=\"http://farm" . $photo['farm'] .
        ".static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" .
        $photo['secret'] .  "_m.jpg\" alt=\"" . $photo['title'] . "\" /&gt;&lt;/a&gt;";
?&gt;
  &lt;/div&gt;
&lt;?php
 }
} catch (Exception $e) {
  error_log("flickr badge had some troubles: " .
    $e-&gt;getMessage());
}</pre>
<p>This snippet takes my laptop less than 1/20th of a second to run from the command line, which suits me fine. The actual code sits in&nbsp;<code>page.tpl.php</code>.</p>
<p><a href="http://www.flickr.com/services/api/">Flickr&#8217;s <span class="caps">API</span> docs</a>, in particular the <span class="caps">API</span> Explorer, were awful handy in figuring this all&nbsp;out.</p>
]]></content:encoded>
			<wfw:commentRss>http://slagwerks.com/blog/index.php/2009/07/29/custom-flickr-sidebar-via-wget-cron-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
