Flickr Gallery 0.5

November 23rd, 2004

This project is now closed. Please use the much superior FAlbum if you want to integrate Wordpress and Flickr.

Update (1/8/2005) - A new version is available here with some of the features requested in this post’s comments and also some bug fixes.

This is an update to my Flickr gallery plugin with a couple new features and some bug fixes. Some of the salient features include:

  • Flickr photosets as “albums” - complete with descriptions and meta
  • Support for Flickr “notes” feature - just this plugin uses all CSS and Javascript instead of Flash (the plugin’s output looks like this)
  • EXIF data support to display camera settings the photo was snapped with — in addition to the description and meta info from Flickr
  • Valid XHTML output
  • * new * Option to respect photos marked “private”
  • * new * Thumbnail size choices

You can download it in .tar.gz format here or .zip format here.

An example installation can be found here. Read on for installation instructions.

Installation Instructions:

  1. Make sure you have your Flickr photos organized into photosets.
  2. Extract the files somewhere.
  3. Edit flickr-gallery.php with your settings.
    1. Set FLICKR_USER_ROOT constant to your Flickr page (something like http://www.flickr.com/photos/username/ - it’s your Flickr “alias”) so that the plugin can build the comments links for your photos.
    2. Set FLICKR_EMAIL constant to your Flickr account login (the email address you signed up with)
    3. Set FLICKR_PASSWORD constant to your Flickr account password
    4. Set FLICKR_CACHE_PATH constant to the path of your cache directory (something like /var/www/localhost/wp-content/flickr-cache/). This directory should be in your WP-content directory and must be writable by the web server/PHP.
    5. Optional - Set FLICKR_CACHE_EXPIRE to the number of seconds you want the cache to live for. 600 secs (10 mins) is suggested so as to not overload Flickr with API traffic and get your IP address banned.
    6. Set FLICKR_THUMBNAIL_SIZE constant to the size you want your thumbnails to appear as (’s’ = 75px x 75px, ‘t’ = 100px x 75px, ‘m’ = 240px x 180px)
    7. Set FLICKR_SHOW_PRIVATE constant to false if you want to respect photos marked as private in Flickr

    Do not change the API key. Also, PLEASE do not steal the API key. This one has been assigned to this plugin and Flickr uses it to track API usage. You can get your own API key here for your own projects or derivatives of this code.

  4. Put flickr-gallery.php in your WP-content/plugins/ directory and activate the plugin via your WP admin console.
  5. Copy your index.php file to gallery.php (or another filename if you want). Edit gallery.php by replacing everything inside
    <div id="content"> ... </div>

    with

    <?php flickr_show_photos($_GET['album'], $_GET['photo']); ?>

    Make sure you still have <div id=”content”>. Then create links to gallery.php from wherever you want to link to it.

  6. Define the flickr-album, flickr-thumbnail, flickr-photo, flickr-title, and maybe flickr-description style
    classes in your style sheet. Modify the classes to fit the look and
    feel of your site. My classes look like this:
    .flickr-album {
    	padding: 0;
    	width: 550px;
    	clear:both;
    }
    .flickr-thumbnail {
    	float:left;
    	padding-right: 20px;
    	background-color: #fff;
    	border: 1px solid #a9a9a9;
    	margin: 6px 6px 6px 6px;
    	padding: 4px;
    	margin-top:10px;
    }
    .flickr-photo {
    	padding-right: 20px;
    	background-color: #fff;
    	border: 1px solid #a9a9a9;
    	margin: 6px 6px 6px 6px;
    	padding: 4px;
    	margin-top:10px;
    }
    .flickr-title {
    	width: 500px;
    	color: #260;
    	padding-top: 6px;
    }
    
  7. If you want to use the Flickr “notes” part of the plugin you must do the following:
    1. Put annimg.js somewhere (I put it in my blog root).
    2. Add
      <script type="text/javascript" src="<?php echo get_settings('siteurl'); ?>/annimg.js">
      </script>

      to your gallery.php head.

    3. Define the a.annotation, a.annotation span, and a.annotation:hover styles in your style sheet. My classes look like this:
      a.annotation {
      	position: absolute;
      	border: 1px solid white;
      	padding: 0;
      	display: none;
      }
      a.annotation span {
      	display: block;
      	width: 100%;
      	height: 100%;
      	/* Setup translucent background in notes box with browser specific opacity
      	 * properties (they aren't valid CSS - sorry).  If having valid CSS is
      	 * so important	to you just get rid of the next 4 lines after these
      	 * comments (you'll sacrifice the translucent background in the notes
      	 * boxes though).
      	*/
      	background: white;
      	opacity: 0.2;
      	-moz-opacity: 0.2;
      	filter: alpha(opacity=20);
      }
      a.annotation:hover {
      	border-color: yellow;
      }
      

System Requirements:
PHP 4.1 or greater - with allow_url_fopen enabled (to make remote API/REST calls and download images)
Wordpress isn’t actually required because this doesn’t use any of WP’s plugin hooks

Of course this code comes with no guarantee. If you need support I’ll be glad to help (within reason) — just shoot me an email. If you want to suggest future features or just tell me that you are using my plugin I’d appreciate that feedback too.

Copyright (c) 2004
Released under the GPL license

42 Responses to “Flickr Gallery 0.5”

  1. Basse Says:

    I just installed your marvellous plugin on my blog. Thank you - it’s fairly easy to install, works great and looks good with little or no hassle.

    I have one “issue” with it, though. Since the rest of my blog is in Swedish I would really like my gallery to be in Swedish as well. It looks kind of stupid with English text interleaved between my titles and descriptions in Swedish.

    I would be willing to translate the few bits of text, but where do I put the translations? The text is probably hardcoded in the PHP file at the moment. Do you intend to move it out of there or should I just make a Swedish version of the file?

  2. Ray Says:

    Basse,

    Localization is something I haven’t thought of yet. Yes, the text is hardcoded in the PHP. It is probably easiest for you to simply make a Swedish version of the file.

    Your question got me looking at WP localization features though, and for future versions of my plugins I think I am going to try to use gettext for translation. That would allow users to use the already translated dictionaries. On the other hand, I doesn’t look like it is quite as simple as flipping a switch to change languages.

    Ray

  3. basseblog » Flickrgalleri pÃ¥ basseblog Says:

    [...] saker och ting fort framåt. En dag efter att jag upptäckte Flickr hittade jag en galleriplugin för Wordpress, som jag förstås genast installera [...]

  4. basseblog Says:

    Flickrgalleri på basseblog
    Ibland gÃ¥r saker och ting fort framÃ¥t. En dag efter att jag upptäckte Flickr hittade jag en “galleriplugin”:http://www.worrad.com/archives/2004/11/23/flickr-gallery-WP-plugin/ för Wordpress, som jag förstÃ¥s genast installerade pÃ¥ prov. Det fun…

  5. Basse Says:

    Sorry for the “comment spam”, I didn’t remember to turn off Pingback for all URIs when posting. BTW, if you’re wondering - the strange characters are UTF8-coded umlauts.

  6. striatic Says:

    this looks like a terrific implementation .. i am looking forward to playing around with it soon.

    the best thing is that it doesn’t require wordpress.

    one thing that would be very useful to me would be the ability to list all of my {or someone else’s} images on a single page, in thumbnail. it makes for much easier image image browsing at a glance, in my opinion. like when you first meet a new contact and want to check out their previous work at a glance.

  7. skippy Says:

    Fantastic work! An easy-to-use and elegant solution. Thanks for sharing this — it’s _exactly_ what I’ve been looking for!

  8. Mark J Says:

    One thing that someone brought up on my site is that large galleries take a long time to load. I think pagination would be a valuable feature to implement.

  9. Carsten Ringe Says:

    Nice plugin. My provider disabled URL file access, so I can’t use it - but it’s a good idea anyway.

  10. Aaron Says:

    A nice plugin!
    And I just wonder how you post the source code with indentation in WP….could you mind to telll me how?

  11. Ray Says:

    Aaron,

    I just stick the code in <pre> ... </pre> tags. That keeps the original whitespace and everything (and allows users to copy and paste it without getting a bunch of markup junk). It might be more semantically correct to put it in <code> ... </code> tags, but I find my way works better if you want to copy and paste the code into something.

    Ray

  12. Mark J Says:

    Using code for a one-line snippet and using pre for a block is a widely-accepted practice… I don’t think there is a semantical problem.

    So how about pagination? You think that’s doable?

  13. Ray Says:

    Mark J,

    I do think pagination is doable, but I won’t have time to work on it until this weekend. I’ll let you know what I come up with.

    Ray

  14. Olly Says:

    Hello!
    Is it possible, that this plugin doesn’t work with wordpress alpha versions 1.3? Tried it out a couple of minutes ago and got only a PHP error in line 57 of flickr-gallery.php?

  15. Marc's Voice Says:

    Coolio Flickr apps
    Here’s the latest from Eric Costello…. One of the things I love about Flickr is its openness. We are open as a company, participating in discussions with our members on public message boards about our future plans, our (ever dwindling list of) bugs,…

  16. Scott Says:

    Works like a charm for me on Wordpress 1.3a. This is a great tool; thanks for hooking it up!

  17. All the Pretty Words » Flickr Gallery Says:

    [...] nks,” you’ll see a link to my nice new Flickr Gallery :D. Many many thanks to Ramon Darrow for the plugin :). I know it’s not a very good place for [...]

  18. jayson franklin Says:

    I was having trouble finding your email, sir. I was hoping you would help me with flickr plugin.

    http://www.franklinfamily.org/gallery.php

    -jayson

  19. simone messina Says:

    If you see here:
    http://www.officialsm.net/test/wordpress/wordpress/gallery.php

    you can see the problem in the page.
    The tag < ?php flickr_show_photos($_GET['album'], $_GET['photo']); ?>
    is write without space,
    Anyone help me, with some idea?
    Thank you

  20. dan Says:

    Having some config issues…


    Warning: fopen(/var/www/localhost/htdocs/weblog/wp-content/flickr-cache//http%3A%2F%2Fwww.flickr.com%2Fservices%2Frest%2F%3Fmethod%3Dflickr.photosets.getList%26api_key%3D3a4570b7e7e2aaf6be97a55b07e89db5%26email%3Ddantrevino%40gmail.com%26password%3Dinsmodppa.cached): failed to open stream: Permission denied in /var/www/localhost/htdocs/weblog/wp-content/plugins/flickr-gallery.php on line 340


    Warning: fwrite(): supplied argument is not a valid stream resource in /var/www/localhost/htdocs/weblog/wp-content/plugins/flickr-gallery.php on line 343


    Warning: fclose(): supplied argument is not a valid stream resource in /var/www/localhost/htdocs/weblog/wp-content/plugins/flickr-gallery.php on line 345


    Warning: file_get_contents(/var/www/localhost/htdocs/weblog/wp-content/flickr-cache//http%3A%2F%2Fwww.flickr.com%2Fservices%2Frest%2F%3Fmethod%3Dflickr.photosets.getList%26api_key%3D3a4570b7e7e2aaf6be97a55b07e89db5%26email%3Ddantrevino%40gmail.com%26password%3Dinsmodppa.cached): failed to open stream: Permission denied in /var/www/localhost/htdocs/weblog/wp-content/plugins/flickr-gallery.php on line 349


    An error occurred. Here is the response from Flickr:


    And here is the response after passing through the parser:
    array (
    )

    flickr-cache is 666 and owned by apache user
    line 340 is:

    $f2 = fopen($cache_filename,"w+"); // Open local cache file

    and

    FLICKR_CACHE_PATH='my path.../weblog/wp-content/flickr-cache/'

    Anny ideas?

  21. dan Says:

    so…fixed my previous error by ‘chmod 777 flickr-cache’ … doh! … also note, the password in the URL above is fake, my real password DID include some special characters, but the plugin does not work with my ‘real’ password. A bug in flickr.photosets.getList ????

  22. 海豚微笑的背后 » Flickr Gallery Says:

    [...] Flickr Gallery
    Filed under: 技巧.j — kDolphin @ 1:33 pm

      Flickr Gallery这个插件可以把你的Flickr相册整合到你的WP Blogä¸ [...]

  23. Clark Says:

    Here is my error:

    Parse error: parse error, unexpected T_ENDFOREACH in /home/clark/www.wvofuels.com/gallery.php on line 14

    Any ideas?

    I love what you have done with the slide show right in the content of WP. I also especially like the thumbnails. Since I can’t experiment with it, are those feature that are pre coded or extra fancies that you’ve done for just your blog?

  24. Ray Says:

    Clark,

    Why don’t you send me a copy of your gallery.php to rdarrow at worrad DOT com. It looks like you have some bits of the the WP loop hanging around that shouldn’t be there. I’d be glad to help you out.

    Ray

  25. Fil Says:

    I’ve been trying to get this plugin to work for a few days now with no luck.
    This is the error I get:

    Fatal error: Call to undefined function: flickr_show_photos() in /path/to/my/wp/installation/gallery.php on line 34

    Any ideas why it keeps bombing?
    Here’s a link to see it
    Thanks,
    Fil

  26. cinefilo Says:

    I´m very happy to find this plugins, but I cann´t run because this APIKey I don´t know it.
    It´s need API/key?

    Excuse me because my english is very bad, bye.

  27. Mark's Place Says:

    pLog 跟 Flickr 的完美結合
    Flickr 是最近很流行的社會型網路的相簿服務服平台,尤其是在 Schee 的大力推薦下幾乎 Blog 圈中人手一個帳號!Schee 真的把 Flickr 講得é

  28. Ray Says:

    Cinefilo,

    You do not need to change the API Key in order to get the plugin to work. In fact, it is the one thing you should not change. Also, you should probably use the latest version (0.6).

    Ray

  29. Mark Says:

    Very impressive plugin. Good that you can now respect photos marked Private in Flickr. However, Flickr lets you define various levels of privacy: Friends, Family etc. Most of my Flickr photos are not public, but my weblog is, so I don’t want to display all my Flickr images there.

    Instead of hard-coding my user ID and password and passing it through the Flickr API, could you include fields for Flickr login in gallery.php? That way, friends and family coming to my blog could enter their login information on that page first, and that user ID/PW would be saved in variables and then passed to Flickr through the API (instead of my hard-coded info).

  30. Josh Says:

    I’m having similar problems to a previous commenter:
    file_get_contents(/home/.heathcote/schwa23/uncleleron.com/wp/wp-content/flickr-cache//http%3A%2F%2Fwww.flickr.com%2Fservices%2Frest%2F%3Fmethod%3Dflickr.photosets.getList%26api_key%3D3a4570b7e7e2aaf6be97a55b07e89db5%26email%3Dxxx%40uncleleron.com%26password%3Dxxxxxx.cached): failed to open stream: No such file or directory in /home/.heathcote/schwa23/uncleleron.com/wp/wp-content/plugins/flickr-gallery.php on line 390

    An error occurred. Here is the response from Flickr:

    And here is the response after passing through the parser:
    array (
    )

    Not sure if it’s because my host doesn’t enable allow_url_fopen or what — any suggestions?

    oh, and I xxxedout my email and password in the code above.

  31. Ray Says:

    Mark,

    The different levels of privacy are surely something you could add support for if you want. Unfortunately, forcing the user to have to login with their own Flickr id is a little bit of a hinderance for usability. If your users are required to already have a Flickr id to view your photos you may as well require them to view them inside Flickr.

    I think are on the right track for how to implement your idea though. The list of photos is based on what userid the request is made from, so you would have to get the user’s id and password they registered with Flickr with (and requires that your users trust you not to abuse the knowledge of their id and password). The challenge of course is that you have to then store the id and password in something that is going to last longer than a single page load, namely a cookie or a session, otherwise your users will have to login again for every request they make. That adds a whole new level of complexity to the script that I didn’t really want to get into.

    Feel free to hack it yourself though. It was released under the GPL so derivatives and branches are allowed and even encouraged. I know one user is already working on a version that will show the entire Flickr photostream instead of requiring that photos be organized into photosets. So, have at it and add all the features you want.

    Ray

  32. Ray Says:

    Josh,

    This could probably be due to one of two problems:

    1. allow_url_fopen could be disabled. Make a new .php file and just put the following in it:
    <?php
    phpinfo();
    ?>

    This will show you all your PHP settings. Just search for allow_url_fopen. It must be set to “On” for the script to work. Of course there is probably a way around it by writing a hack to connect to Flickr through a socket connection, but that would be up to you to write. The easiest way would be just to get allow_url_fopen turned on.

    2. flickr-cache could have the wrong permissions set. It must be writable by the webserver. Most people just set their permissions to 777 (which is pretty permiscuous, but it is definitely writable by the webserver).

    Also, you should probably be running version 0.6 of the plugin. It fixes a potential security risk.

    Ray

  33. seongeunlee Says:

    I installed it. but How can I use this plugin.
    I have error :::
    http://www.all-iran.info/home/gallery.php
    ———————————

    An error occurred. Here is the response from Flickr:
    <?xml version="1.0" encoding="utf-8" ?>
    <rsp stat="fail">
    <err code="1" msg="User not found" />
    </err></rsp>

    And here is the response after passing through the parser:
    array (
    'rsp' =>
    array (
    'err' =>
    array (
    'code' => '1',
    'msg' => 'User not found',
    ),
    ),
    )

    problem..?

  34. Ray Says:

    seongeunlee,

    That error means you aren’t logging into Flickr successfully. Double check the email and password you signed up for Flickr with.

    Ray

  35. Matt Says:

    Warning: exif_read_data(1947315_d808e6626f_o.jpg): file not supported in /home/matt/public_html/wp-content/plugins/flickr-gallery.php on line 260

    Any idea what I’m missing that could be causing that error?

  36. Adam Says:

    Hmm… I’m getting “Fatal error: Call to undefined function: flickr_show_photos() in /home/lasnik/public_html/photography/flickr/testy.htm on line 1″

    I don’t use WP, so I just put “< ?php flickr_show_photos($_GET['album'], $_GET['photo']); ?>” into a test.php file and accessed that via my browser.

    I assume I’m missing something really obvious here?

  37. Adam Says:

    Okay, I’m a dodobrain… I had overlooked that my server couldn’t automatically guess where the gallery script was. So I realized I have to load the script directly or include it somehow. Duh.

  38. Ray Says:

    Matt,

    The exif_read_data() error you are getting would seem to be because your installation of PHP doesn’t support the EXIF functions. You could always look at the output of your phpinfo() function to see whether EXIF is turned on in your installation of PHP. You could also simply comment out line 260 and skip the EXIF functions altogether.

    Ray

  39. Matt Says:

    Here’s the output from phpinfo()
    EXIF Support enabled
    EXIF Version 1.4 $Id: exif.c,v 1.118.2.27 2003/12/17 09:08:37 helly Exp $
    Supported EXIF Version 0220
    Supported filetypes JPEG,TIFF

    I commented out the line and got things more or less working. It still displays the information regarding shutter speed, flash, etc. What does that one line control?

  40. The Renaissance Man » New Feature–Flickr Gallery! Says:

    [...] I’ve added a new feature to my blog today. I’m now using a plugin called Flickr Gallery which allows me to link up my Flickr photos to my blog. I̵ [...]

  41. bruto » Flickr Says:

    [...] Iba a escribir sobre un plugin para WordPress, el flickr-gallery-0.5, que te permite hacer un álbum fotográfico en tu propia página usando las fotos que tienes alojadas en flickr (aunque por lo que dice su autor no necesitas ni el WordPress), pero ya que me pongo a hablar de flickr, contemos algunas cosas más. [...]

  42. Pawls Blog » flickr: WP-gallery Plugin Says:

    [...] http://www.worrad.com/archives/2004/11/23/flickr-gallery-WP-plugin/ [...]