Image Gallery Summary View

Summary

This module themes a views summary for a set of image galleries.  The image galleries are defined with a view using an argument (usually Term or User).  The summary view shows a thumbnail of the latest image from each gallery, the page title, last modified date, and number of images in the gallery.  This is nearly identical to the gallery summary provided by the Image module's Image Gallery contrib module.  This can be used to theme per-user gallery summaries or per-term gallery summaries.   I can't think of (and haven't tested) other possibilities, but it should work with any argument type and any node type that defines at least one image where you want a nice looking summary.

  • I just really liked the look of the Image Gallery module's summary page, but I wanted to use CCK imagefield rather than the Image module.  There seem to be a lot of people out there looking for this, but there just were no nice looking summary views available. 
  • All of the theming code was ripped directly from image_gallery.module : http://drupal.org/project/image
  • The module is used, for example,  to create the summary view at: http://lasqueti.ca/photos/gallery

Overview

Requires:

  • a view with (1) a CCK imagefield defined as one of the fields; and (2) a view argument (like Term or User)
  • an imagecache preset named "Thumbnail" (this can be configured in the script)
  • a style-sheet for styling the gallery summary view - I've included image_gallery.css, ripped directly from the Image module.

Options:

  • combine this with the Views Summary Mock Menu modulette for a complete image gallery browsing experience!

Source Code

All code snippets, modules, and modulettes on this site are covered by GPL - see license.txt

The source code is attached below...

Full instructions for installing and using this module are included as comments in the source file.

AttachmentSize
summary_view_image_gallery.zip15.01 KB

Comments

Image gallery summary view

I like what you have done, I wanted to see if you could help me figure out why I constantly only get the static text "there is 1 photo in this gallery"; I see the code in the php doc and it all seems right.

I have a content type that has one image field object that allows multiple images to be uploaded, is that the problem and if so, how can I fix the count?

Many thanks
Chris

multi-image nodes...

Hi Chris,

I doubt the script correctly handles mutli-image nodes.  The number in the text "there is 1 photo..." is the node count returned by the view, not the number of images.  Do you still get '1 photo' even in galleries that have multiple nodes in them? 

This could likely be fixed, but I don't have time to look into it just now - sorry.   I use one image per node, and then use Views to create multi-image displays - this seems more flexible to me, although I can see why a multi-image node could be useful.

Missing slash keeps CSS from taking effect

I found a slight problem in the phptemplate_views_summary_YOUR_VIEW() function that goes in template.php. For some reason the image_gallery.css file wasn't taking effect, and I finally figured out by looking in the source code. The problem was in the drupal_add_css call:


drupal_add_css(drupal_get_path('theme', 'YOUR THEME') .'image_gallery.css', 'theme');

There is no slash between the theme directory name and the file name, so what comes out in the HTML is this:

@import "/sites/all/themes/tastelesslystyle.css";

By adding a slash in front of the file name, like this:


drupal_add_css(drupal_get_path('theme', 'YOUR THEME') .'/image_gallery.css', 'theme');

the path in the HTML is correct, and the CSS takes effect.

trouble including in template.php

Sorry if this is a stupid question but I'm a total newbee when it comes to code and templating in Drupal...
I am getting the following error having cut and pasted
require_once('view_summary_image_gallery.php');
into the Template.php file

Fatal error: require_once() [function.require]: Failed opening required 'view_summary_image_gallery.php' (include_path='.:/usr/share/pear5') in /home/sites/disscamera.org.uk/public_html/themes/aberdeen/template.php on line 25

I guess it is not finding the correct file. How do I tell it the correct filepath?

Many thanks for your help.

you need to install the file...

That error seems to indicate that you have not installed the module code itself - view_summary_image_gallery.php
You need that file - it contains all the code that creates the image gallery listing page.

Download the zip file above and unzip it into the same directory as your template.php file.
That should fix your problem - require_once( filepath ) will accept a relative path, so if the file being included is in the same directory, just the file name is required, as in the example given.

webmaster (at) lasqueti.ca

Filename

I noticed that the filename in the folder after downloading is summary_view_image_gallery.php, but the filename referenced in the header of that file is view_summary_image_gallery.php. I got an error when I copied verbatim from the comments, but correcting the filename fixed it.

Still have same problem..

I did have the file in place, even tried adding it to the subdirectory which corresponded to a variation of the theme I am using. Still same problem and error message.
I haven't yet un-commented and edited the following section of code for insertion in template.php:
/** - In your template.php file, add the following code to override the
* summary method for YOUR_VIEW (substitute your view name):
*
*function phptemplate_views_summary_galleries_by_user2($view, $type, $level, $nodes, $args) {
*drupal_add_css(drupal_get_path('theme', 'YOUR THEME') .'image_gallery.css', 'theme');
* return theme_summary_view_image_gallery($view, $type, $level, $nodes, $args);
* }
other than replacing the YOUR_VIEW bits with the gallery name as it appears on the left in the Administer views page as above I'm not sure what else I might need to do to this bit of code - it looks like I might need to select a .css template to replace the YOUR THEME bit...
Could the fact that this section remains incomplete and commented out be causing the above problem?

sorry you're having problems q_man...

That error you are getting has nothing to do with the code itself - you aren't there yet, PHP has not been able to include the file.  I can't help you debug that, but here's some advice from php_nuke on possible causes and solutions:

  • The file is really not there, something went wrong with the installation
  • The file is there but the web server does not have the right to open it - check permissions
  • There is a .htaccess file somewhere in the directory hierarchy that denies access to you.
  • There is something wrong with the include path of the PHP interpreter 
  • You might see more information on the cause of your problem if you have access to the web server access and error logs.

I'm guessing it has something to do with the way you installed this or your PHP include path.  As a simple, but inelegant, solution, you could simply copy all the code out of the module file and paste it directly into your template.php file, right in place of the offending include statement.

As an aside - from the path in the error message, it does look like your theme is stored directly in with the Drupal install rather than under the sites directory - that is pretty error-prone - be careful when you upgrade Drupal or you could lose your custom theme!

I do offer consulting services if you need a hired gun to resolve this one - use site contact form.

Good luck q_man - hope you nail it.

Thanks for the tips...

I will try out your suggestions, thank you for the swift response. Just out of interest could you forward me your rates, just in case I get stuck and need to hire a gun...

last post may be wrong if i got posted at all...

My last post may be wrong in assuming it was looking in the wrong place as I have noticed other image paths which work follow the same format of Src=http://mysite/system/files/images and the ones from the new image gallery summary view have the same but with /imagecache/Thumbnail replacing the /images part.
Maybe things just aren't set up right in my view, user names don't come up - they only show as %1's Gallery etc. and no specific images are linked o in the paths. Perhaps an argument is missing?
The view I am working on is here:
http://www.disscamera.org.uk/galleries/by_user2/

Any suggestions would be appreciated.

Made some progress

I ended up copying and pasting the whole script into the template.php file and it seems to be working to some extent. It looks like it has formatted it like the gallery from the image module but it can't find the image thumbnails to link to. I have set my filesystem settings to a higher level folder than the drupal install / public file system in order to prevent direct linking and stealing of original files. It looks like the script somehow, or something it references doesn't pick up on this and it is looking for the images in the default "files" subfolder of the drupal install in the public folder. Any way round this or will it need a major re-code?

private files...

Hey Q_man,

the script was definitely written with a public files folder in mind - the script assumes the relative path to the files directory is under the pulic web root.   I'm sure it could be adapted to work with private files - but private files need to be served, they can't simply be linked in with an img tag.  I don't have time right now to look into this - sorry.

last updated not working

Thanks for the great code! Unfortunately, when I implement this on my site (using an unmodified, as yet, zen starterkit) the Last Updated: time does not appear under my photos. Any idea why that might be?

On a side note, is it possible to sort the galleries by this last updated date? (or by node creation date?)

Thanks again for your work!

Answers for jason?

Last Updated date not showing:  the relevant code is:
    $modDate = $result['items'][0]->node_changed;

The $result comes from building the view with the taxonomy argument:
    $result = views_build_view('items', $view, array($arg), false, 1);

But I'm not sure why "node_changed" would not be set in your case - perhaps this comes from sorting the view by modification date?   I'm not sure - would require some investigating and thought.

Sort Summary View by Last Updated:  what a great idea!
It almost looked like you could be the summary view to do this:  "Summary: sorted as view"  but when I tried this, it just made a mess.  Might still be the ticket though.
The "Sumary: sorted ascending" view lists the taxonomy term arguments in alphabetical order - and you don't get the modified date until AFTER loading the view.  Of course, this could be accomplished by splitting ub the  
   foreach ($nodes as $query) {  ... }
loop - first build an array with the output for each query + the node_changed,  sort it, then output the sorted array.

I do offer consulting services if you want some help with this - just contact me...

webmaster (at) lasqueti dot ca

Fixed it - mostly

So for some reason node_changed was not available in my $result array, so I ended up using node_created_created which works fine for me.

I've modified the code to sort by date by creating

$sortby=array()

before

foreach ($nodes as $query) {

and then replacing the end of the loop (I've kept the first line the same so that you can easily reference where to insert this) with the following code:

$linkText = $imgTag .' '. $title;
// Create an array with the created date as keys and the themed output as values
$content2 = _theme_gallery_summary($imgTag, $url, $title, $query->num_nodes, $modDate, $description);
$sortdate[$modDate] = $content2;
// sort by date, newest to oldest
krsort($sortdate);
}
foreach ($sortdate as $value) {
$content .= $value;
}

Hopefully this is helpful to someone! One final question to bounce off of you - this code limits the number of summary galleries to the number of images I have set to display per page in my view. For example, I have set in my view to display 12 photos per page with a pager; consequently, only the 12 most recent albums show on my summary album page - there is no pager on this page.

I thought that I might could fix this by changing the false to true in

$result = views_build_view('items', $view, array($arg), false, 1);

but this only messed things up. Any ideas how I could add a pager so that my summary album page will show all of my albums?

Thanks again for your help!

Hi :-) Does this work with

Hi :-)

Does this work with D6?

I'm a rookie with Drupal, but I'm already getting (extra) grey hairs in my desperate search for something that looks exactly like the gallery views you've made in the example here. It's just amazing :-)

However, it looks like the file isn't there anymore?
Du you still have it? Or is there any other way to reach to both joined list, user list and category lists of pictures?

Any help would be greatly appreciated.

- Anita

Thanks!

I'm not sure what happened - at some point all my attachements disappeared!
In any case, they are back - please let me know if you have any trouble downloading them again.

This module only provides the "Summary View" for the photo galleries.  The galleries themselves are standard View-CCK based views, using imagecache and the lightbox viewer.

This site and all the modules I developed for it were written for D5 - I haven't plans to migrate to D6 yet.

Good luck.

webmaster (at) lasqueti.ca

For a Drupal 6 solution, try

For a Drupal 6 solution, try Views catalogue module.

attachment - file not found.

attachment - file not found. help?