I tried to integrate thickbox with node images using the modification provided by tic2000. It displays the photos in a slideshow type gallery but does not count them properly. For instance, when 2 pictures are uploaded, it says there are three. And when cycling through the images, it displays the 2nd picture, but lists it as the 3rd (ie 3 out of 3).

Before modifying Tic2000's code, it would list double the amount of pictures uploaded. IE, if 4 were uploaded it would says 1 out of 16. If 2 uploaded, it would say 1 of out 4, and so on.

By adding the $output .= $output .= node_images_gallery_thickbox($node); before the return $output; I managed to get it to fix that doubling bug, but as I mentioned before, it still adds one phantom picture to the total.

The solution must be something simple, but darned if I can figure it out.

Can someone take a look and see if they can't figure out a solution? This would be a very cool feature to the already brilliant node images module.

function node_images_gallery_thickbox($node) {
  if (empty($node->node_images)) {
    drupal_set_message(t('No images uploaded for this content.'));
    if (user_access('create node images') && node_access('update', $node)) {
      $output = t('Click <a href="!url">here</a> to upload new images.', array('!url' =>   url('node/'.$node->nid.'/images')));
    }
    return '<p>'.$output.'</p>';
  }
    $node->node_images = (count($node->node_images) > 1) ? array_slice($node->node_images, 1) : array();
  foreach ($node->node_images as $id=>$image) {
    $output .= '<a href="'.file_create_url($image->filepath).'" class="thickbox" rel="'.$node->title.'" title="'.$image->description.'"></a>';
  }
  return '<div id="thickbox_image_gallery" style="display:none;">'.$output.'</div>';
}

function theme_node_images_view($node, $teaser, $page, $format = NULL) {
  if (arg(2) == 'image_gallery' || empty($node->node_images)) return;

  $output = '';
  $i = 0;

  // set maximum number of images for teaser/body
  $view = ($teaser ? 'teaser' : 'body');
  $count = variable_get('node_images_'.$view.'_images_'.$node->type, 2);
  if (isset($count) && $count === 0) return;
  if (!$format) {
    $format = variable_get('node_images_'.$view.'_format_'.$node->type, 'thumbs');
  }

  foreach((array)$node->node_images as $id=>$image) {
    $description = check_plain($image->description);
    $pattern = '<img src="%path" alt="%description" />';
    $thumb = strtr($pattern, array('%path'=>file_create_url($image->thumbpath), '%description'=>$description));
    $fullsize = strtr($pattern, array('%path'=>file_create_url($image->filepath), '%description'=>$description));

    if ($info = getimagesize($image->filepath)) {
      $width = $info[0] + 36;
      $height = $info[1] + 36;
    }
    else {
      $width = 420;
      $height = 315;
    }

    if ($format == 'thumbs') {
$output .= '<a href="'.file_create_url($image->filepath).'" title="'.$description.'" class="thickbox" rel="'.$node->title.'" >'.$thumb.'</a> '.' ';
    }
    else {
      $output .= $fullsize.' ';
    } 
     if ($count>0 && ++$i >= $count) break;
  }
  $output .= node_images_gallery_thickbox($node);
  return $output;
}

Here is a screenshot of when two pictures are uploaded to a node, 1st picture selected:

http://img221.imageshack.us/img221/75/nodeimagesthickboxmodnd6.jpg

Here is a screenshot of the same node, but with the 2nd picture selected:

http://img155.imageshack.us/img155/7561/nodeimagesthickboxmod2xm6.jpg

CommentFileSizeAuthor
#5 node_images-theme-thumb-1.patch1.44 KBray007

Comments

H3rnand3z’s picture

this is not a solution to your problem but an alternative, What I did to integrate thickbox with node_images was replace lines 577 and 578 in node_images.module

$output .= '<a href="javascript:void(0);" title="'.$description.'" onclick="window.open(\''.
file_create_url($image->filepath).'\', \'\', \'height='.$height.',width='.$width.'\');">'.$thumb.'</a> ';

with

$output .= '<a href="' . file_create_url($image->filepath) . '" title="' . $description . '" class="thickbox" rel=node_' . $node->nid . '"/>'.$thumb.'</a> ';
B.P.B’s picture

Thank you but that only displays one image, not a gallery that can be cycled through.

H3rnand3z’s picture

It cycles thru all the images displayed in the node teaser or body. If you are displaying all images in the Node body then it will cycle thru all of them.

ray007’s picture

As I just wrote at http://drupal.org/node/116515#comment-248696, having the a-tag as result of a themeable function would solve the problem for all of us ...

ray007’s picture

StatusFileSize
new1.44 KB

The applied patch introduces a new function theme_node_images_thumb() and uses it in theme_node_images_view();

We could probably need something similar for use in theme_node_images_gallery_thumbs(), but unfortunately the variable environment there looks quite different. Maybe I can come up with something that covers both, but I'm currently happy with what I have.

Comments?

subspaceeddy’s picture

Just to let you know, I've implemented this patch along with many others and uploaded a new module here: http://drupal.org/node/150904.

These are the things incorporated:

* H3rnand3z & ray007 ('please help with thickbox modification' - http://drupal.org/node/139349)
* mad-admin & soflete ('Integrate with lightbox' - http://drupal.org/node/116515)
* Vallenwood ('Highly Enhanced Thumbnail generation - supersedes "Keep fixed thumnail size" - http://drupal.org/node/147538)
* terrybritton ('Altering the image gallery layout.' - http://drupal.org/node/135572 - *you will need his css file*)
* subspaceeddy ('div not closed in theme_node_images_gallery($element)' - http://drupal.org/node/145220)
* also further modifications by subspaceeddy to switch between lightbox, thickbox and default, and an ability to alter position of node body on 'Imaqe Gallery' page.

m19peters’s picture

I've created a workaround for this if anyone is struggling with trying to do this with Drupal 6x.... I've posted it here: http://mattabase.com/archives/141

asb’s picture

Version: » 6.x-2.x-dev
Status: Active » Closed (won't fix)

No activity for >2 years. Closing.