Flicker Module and Thickbox

Tue, 07/22/2008 - 18:59

As you may know I have the Flickr module enabled on this site. I use it to host images from my Flickr photostream instead of uploading them directly to this server. This module also provides functionality to display the Flickr pool that you can see at the far right. It's a handy module if you use Flickr, and it works fairly well. However, there is one qualm I have with the Flickr module, each image is displayed as a link that will take you off-site to the Flickr page. I found this very annoying and disruptive to the "flow" of the site, but that's what theme functions are for and part of the charm of Drupal.

This is really a pretty simple themeing problem, but I think it may be helpful to others, so here is how to integrate the Flickr module with Jquery's Thickbox plugin. I should mention that I am running Drupal 6.x. I decided to use the Thickbox functionality mainly because the user will never leave the page when viewing pictures. Thus no reload or "break" involved in their viewing of the content of this site. To do this you will first need to download the necessary files for the Thickbox plugin:

I simply threw these files into the same directory as my theme.

The next step is to tell Drupal that you are adding a new stylesheet and javascript. There are several ways to do this, but as I want this functionality to be loaded on every page, I decided to do this in my theme's .info file. Only two lines are need to be added here:

scripts[] = thickbox.js
stylesheets[all][] = thickbox.css
If you have put these files in their own folder then you should include the path relative to your theme.

Okay, simple so far. This step is probably the most complex, but not very. We will need to override the theme function in the flickr module that outputs the linked images. This function is

<?php
function theme_flickr_photo($p, $size = NULL, $format = NULL, $attribs = NULL){
 
$img = flickr_img($p, $size, $attribs);
 
$photo_url = flickr_photo_page_url($p['owner'], $p['id']);
 
$title = is_array($p['title']) ? $p['title']['_content'] : $p['title'];
  return
l($img, $photo_url, array('attributes' => array('title' => $title, 'class' => 'thickbox'), 'absolute' => TRUE, 'html' => TRUE));
}
?>
and is located in flickr.inc. To override this function simply copy it into your theme's template.php file and make the following changes:
<?php
function phptemplate_flickr_photo($p, $size = NULL, $format = NULL, $attribs = NULL) {
 
$img = flickr_img($p, $size, $attribs);
 
//replaces $photo_url and links directly to the flickr farm
 
$thickbox_img = flickr_photo_img($p);
 
$title = is_array($p['title']) ? $p['title']['_content'] : $p['title'];
 
//links href is changed to the new $thickbox_img
  //  and the 'thickbox' class is added
 
return l($img, $thickbox_img, array('attributes' => array('title' => $title, 'class' => 'thickbox'), 'absolute' => TRUE, 'html' => TRUE));
}
?>
Assuming that you have correctly configured the Flick module then that's it! Now the images being displayed by the Flickr module will behave with the Thickbox plugin.

changed?

Thu, 08/21/2008 - 09:26
Posted by: Brian (not verified)

Maybe the flickr module has changed for Drupal 6? I don't think the function is themeable. I couldn't get it to work in any case.

For the better I believe.

Thu, 08/21/2008 - 10:25
Posted by: rho

It's working fine for me on D6. In fact the themeing functions have a notable improvement from the D5 release of this module. Before anything, you might make sure that the Flickr block bug in D6 is not affecting you. Another option, if you can't wrestle thickbox into working, is to use lightbox. I have heard that they have built in flickr.module compatibility that works quite nicely.

Version?

Thu, 08/21/2008 - 23:32
Posted by: Brian (not verified)

May I ask what version you are using? I have the alpha from April 2nd, and I don't see the function theme_flickr_photo.

6.x-1.0-Alpha1

Thu, 08/21/2008 - 23:54
Posted by: rho

Also using the alpha from April 2nd. The theme_flickr_photo function is on line 202 of flickr.module.  

thanks

Fri, 08/22/2008 - 22:42
Posted by: Brian (not verified)

Great, thanks much I had been looking in flickr.info.

Do you think there would be a way to link to the flickr page from thickbox? At the bottom there is "close or esc key" and I think it might be nice to be able to visit the flickr page too if desired.

Appreciate your help very much.

This is great! Thanks for

Thu, 10/30/2008 - 01:31
Posted by: Davuid Peteson (not verified)

This is great! Thanks for sharing. It was simple to get it working on my Drupal 5 site.

Cheers,

David

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.