You are here

function _node_gallery_gallery_view in Node Gallery 6.2

Same name and namespace in other branches
  1. 6.3 node_gallery.module \_node_gallery_gallery_view()
1 call to _node_gallery_gallery_view()
node_gallery_nodeapi in ./node_gallery.module
Implementation of hook_nodeapi().

File

./node_gallery.module, line 292
Node gallery module file

Code

function _node_gallery_gallery_view(&$node, $teaser = NULL, $page = NULL) {
  $config = node_gallery_get_config($node->type);
  if (!$teaser) {

    //$node->content['gallery_operations'] = array('#value' => node_gallery_operations('gallery', $node), '#weight' => -5);
    if ($config['gallery']['gallery_display_type'] == 'cover') {
      $no_cover = TRUE;

      // if there are some images
      if ($node->images) {
        foreach ($node->images as $image) {
          if ($image->is_cover) {
            $cover = $image;
            $no_cover = FALSE;
            break;
          }
        }
        unset($image);

        // If there is no cover image, use the first one
        if ($no_cover == TRUE) {
          $keys = array_keys($node->images);
          $first_key = $keys[0];
          $cover = $node->images[$first_key];
          unset($keys, $first_key);
        }
      }
      else {

        // no images in the gallery
        $cover = new stdClass();
      }

      // Make sure the node title matches the gallery and not the cover image
      $cover->title = $node->title;

      //make sure there is a cover image before we try to load the navigator
      if (!empty($cover->filepath)) {

        // Load the navigator
        // $node->nid = gallery id (gid)
        $navigator = node_gallery_get_image_navigator($node->nid, $cover->nid);
        $output .= l(theme('image_view', $config['image_size']['cover'], $cover), 'node/' . $navigator['next_nid'], array(
          'html' => TRUE,
        ));
        $output .= '<p>' . l(t('Continue to the Next Photo'), 'node/' . $navigator['next_nid']) . '</p>';
      }
      else {

        // If there are no images, display the default cover
        $cover->filepath = empty($cover->filepath) ? $config->default_cover : $cover->filepath;

        // only display the default cover image if a default exists
        if (!empty($cover->filepath)) {
          $output .= theme('image_view', $config->gallery['image'], $cover);
        }
      }
      $node->content['gallery'] = array(
        '#value' => $output,
        '#weight' => -3,
      );
    }
    else {

      //looking at thumbnails, the default
      $node->content['gallery'] = array(
        '#value' => theme('gallery_images_list', $node, $config),
        '#weight' => -3,
      );
      $node->content['pager'] = array(
        '#value' => theme('pager', NULL, variable_get('node_images_page_number', 20), NODE_GALLERY_IMAGE_PAGER_ELEMENT),
        '#weight' => 10,
      );
    }
    drupal_set_breadcrumb(array(
      l(t('Home'), NULL),
      l(t('Galleries'), 'galleries'),
      l(t('!user\'s Galleries', array(
        '!user' => $node->name,
      )), 'galleries/' . $node->uid),
    ));
  }
  else {
    $node->content['gallery'] = array(
      '#value' => theme('gallery_teaser', $node, $config),
      '#weight' => -3,
    );
  }
}