You are here

node_gallery.themes.inc in Node Gallery 6

Node gallery themes.

File

node_gallery.themes.inc
View source
<?php

/**
 * @file
 * Node gallery themes. 
 *
 */
function theme_gallery_list($items, $account = NULL) {
  $output = '<div class="gallery-list">';
  $output .= node_gallery_operations('list', $account);
  if (empty($items)) {
    $output .= t('There are currently no galleries.');
  }
  else {
    $output .= theme('item_list', $items, NULL, 'ul', array(
      'class' => 'gallery-cover-list',
    ));
  }
  $output .= '</div>';
  return $output;
}
function template_preprocess_gallery_cover_view(&$vars) {
  $gallery = $vars['gallery'];
  $config = $vars['config'];
  if (empty($gallery->cover)) {
    $gallery->cover->filepath = $config->default_cover;
  }
  $gallery->cover->title = $gallery->title;
  $vars['cover_image'] = theme('image_view', $config->image_size['cover'], $gallery->cover);
  $vars['meta_data'] = theme('item_list', theme('gallery_meta', $gallery));
  $vars['cover_operations'] = node_gallery_operations('cover', $gallery);
}
function theme_gallery_meta($gallery) {
  $items[] = format_plural($gallery->image_count, '1 image', '@count images');
  $items[] = t('Created at: !date', array(
    '!date' => format_date($gallery->created, 'custom', 'Y-m-d'),
  ));
  return $items;
}
function theme_gallery_image_view($type, $image, $config) {
  if ($type == 'cover') {
    if (empty($image)) {
      $image->filepath = $config->default_cover;
    }
  }
  return theme('imagecache', $config->image_size[$type], $image->filepath, $image->title, $image->title, array(
    'class' => 'gallery-image-' . $type,
  ));
}
function theme_gallery_teaser($gallery, $config) {

  //cover display
  if ($config->teaser['gallery_display_type'] == 'cover') {

    // Make sure to avoid an "Invalid argument supplied for foreach()" error
    if ($gallery->images) {
      $no_cover = TRUE;
      foreach ($gallery->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) {
        $cover = $gallery->images[0];
      }
    }
    $cover->filepath = empty($cover->filepath) ? $config->default_cover : $cover->filepath;
    $cover->title = $gallery->title;
    $image_tag = theme('image_view', $config->image_size['cover'], $cover);
    return l($image_tag, 'node/' . $gallery->nid, array(
      'html' => TRUE,
    ));
  }
  elseif ($config->teaser['gallery_display_type'] == 'lightbox2_gallery' && module_exists('lightbox2')) {

    // Note - There is no display num, as lightbox2 will require seeing all
    // thumbs
    // Make sure to avoid an "Invalid argument supplied for foreach()" error
    if ($gallery->images) {
      foreach ($gallery->images as $image) {
        $image_tag = theme('image_view', $config->image_size['thumbnail'], $image);
        $items[] = l($image_tag, imagecache_create_url($config->teaser['lightbox2_gallery'], $image->filepath), array(
          'html' => TRUE,
          'attributes' => array(
            'rel' => 'lightshow[' . $gallery->nid . ']',
          ),
        ));
      }
    }
    return theme('item_list', $items);
  }
  else {

    // return thumbnail display
    $display_num = $config->teaser['thumbnails_num'];
    $i = 0;

    // Make sure to avoid an "Invalid argument supplied for foreach()" error
    if ($gallery->images) {
      foreach ($gallery->images as $image) {
        if ($i < $display_num) {
          $image_tag = theme('image_view', $config->image_size['thumbnail'], $image);
          $items[] = l($image_tag, 'node/' . $gallery->nid, array(
            'html' => TRUE,
          ));
        }
      }
    }
    return theme('item_list', $items);
  }
}
function theme_image_view($imagecache, $image) {
  return theme('imagecache', $imagecache, $image->filepath, $image->title, $image->title);
}
function theme_gallery_edit_images_form(&$form) {
  drupal_add_tabledrag('upload-attachments', 'order', 'sibling', 'upload-weight');
  $header = array(
    '',
    t('Delete'),
    t('Thumbnail'),
    t('Edit'),
    t('Weight'),
    t('Cover'),
  );
  foreach (element_children($form['files']) as $key) {

    // Add class to group weight fields for drag and drop.
    $form['files'][$key]['weight']['#attributes']['class'] = 'upload-weight';
    $row = array(
      '',
    );
    $row[] = drupal_render($form['files'][$key]['remove']);
    $row[] = theme('imagecache', $form['#config']->image_size['thumbnail'], $form['files'][$key]['filepath']['#value'], $form['files'][$key]['filename']['#value'], $form['files'][$key]['filename']['#value']);
    $row[] = drupal_render($form['files'][$key]['edit_form']);
    $row[] = drupal_render($form['files'][$key]['weight']);
    if ($form['is_cover']) {
      $row[] = drupal_render($form['is_cover'][$key]);
    }
    $rows[] = array(
      'data' => $row,
      'class' => 'draggable',
    );
  }
  $output = theme('table', $header, $rows, array(
    'id' => 'upload-attachments',
  ));
  $output .= drupal_render($form);
  return $output;
}
function theme_gallery_images_list($gallery, $config) {
  $output = '<div class="gallery-images-list">';
  if (!count($gallery->images)) {
    $output .= '<p>' . t('There are no photos in this gallery currently.');
    if (node_gallery_user_access('edit', $gallery)) {
      $output .= '  ' . l('Upload Some!', 'node/' . $gallery->nid . '/upload', array(
        'query' => 'destination=node/' . $gallery->nid,
      ));
    }
    $output .= '</p>';
  }
  elseif ($config->gallery['gallery_display'] == 'lightbox2_gallery' && module_exists('lightbox2')) {
    foreach ($gallery->images as $nid => $image) {
      $items[] = theme('gallery_image_lightbox2', $image, $config, $gallery);
    }
    $output .= theme('item_list', $items);
  }
  elseif ($config->gallery['gallery_display'] == 'cover') {
    $no_cover = TRUE;
    foreach ($gallery->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($gallery->images);
      $first_key = $keys[0];
      $cover = $gallery->images[$first_key];
      unset($keys, $first_key);
    }
    $navigator = new Gallery(array(
      'nid' => $gallery->nid,
    ));
    $navigation = $navigator
      ->get_image_navigator($cover->nid);
    $cover->filepath = empty($cover->filepath) ? $config->default_cover : $cover->filepath;
    $cover->title = $gallery->title;
    $output .= l(theme('image_view', $config->gallery['image'], $cover), 'node/' . $navigation['next_nid'], array(
      'html' => TRUE,
    ));
    $output .= '<p>' . l(t('Continue to the Next Photo'), 'node/' . $navigation['next_nid'], array(
      'html' => TRUE,
    )) . '</p>';
  }
  else {
    foreach ($gallery->images as $nid => $image) {
      $items[] = theme('gallery_image_thumbnail', $image, $config);
    }
    unset($image);
    $output .= theme('item_list', $items);
  }
  $output .= '</div>';
  return $output;
}
function theme_gallery_image_thumbnail($image, $config) {
  $output = '<div class="image-thumbnail">';
  $output .= l(theme('image_view', $config->gallery['image'], $image), 'node/' . $image->nid, array(
    'html' => TRUE,
  ));
  $output .= l($image->title, 'node/' . $image->nid);
  $output .= '</div>';
  return $output;
}
function theme_gallery_image_lightbox2($image, $config, $gallery) {
  $output = '<div class="image-thumbnail">';
  $output .= l(theme('image_view', $config->gallery['image'], $image), imagecache_create_url($config->gallery['lightbox2_gallery_preset'], $image->filepath), array(
    'html' => TRUE,
    'attributes' => array(
      'rel' => 'lightshow[hi]',
    ),
  ));
  $output .= l($image->title, 'node/' . $image->nid);
  $output .= '</div>';
  return $output;
}
function theme_gallery_image_navigator($navigator, $image) {
  $col1 = array(
    'data' => t("Image %current/Total %total", array(
      '%current' => $navigator['current'],
      '%total' => $navigator['total'],
    )),
    'class' => 'image-navigator-left',
  );
  $col2 = array(
    'data' => l(t('Prev'), 'node/' . $navigator['prev_nid']) . '/' . l(t('Next'), 'node/' . $navigator['next_nid']),
    'class' => 'image-navigator-mid',
  );
  $col3 = array(
    'data' => node_gallery_operations('image', $image),
    'class' => 'image-navigator-right',
  );
  $rows[] = array(
    $col1,
    $col2,
    $col3,
  );
  return theme('table', NULL, $rows, array(
    'class' => 'image-navigator',
  ));
}

/**
 * theme_node_gallery_image()
 *
 * This is the code that directly calls the image node (page view) display
 * We provide this theme function as a user may way to inject some custom markup
 * around already determined theme functions
 */
function theme_node_gallery_image($config, $node) {
  $image_view = theme('image_view', $config->image_size['preview'], $node);
  if ($config->view_original == 'default') {
    $output = l($image_view, file_create_url($node->filepath), array(
      'attributes' => array(
        'target' => '_blank',
      ),
      'html' => TRUE,
    ));
  }
  elseif ($config->view_original == 'text') {
    $download_text = t('Download the Original Image');
    if (check_plain($config->view_original_text) != '') {
      $download_text = check_plain($config->view_original_text);
    }
    $output = $image_view . '<div class="download-full-link">' . l($download_text, file_create_url($node->filepath), array(
      'attributes' => array(
        'target' => '_blank',
      ),
      'html' => FALSE,
    )) . '</div>';
  }
  elseif ($config->view_original == 'lightbox2') {
    $output = l($image_view, imagecache_create_url($config->lightbox2, $node->filepath), array(
      'attributes' => array(
        'rel' => 'lightbox',
      ),
      'html' => TRUE,
    ));
  }
  else {
    $output = $image_view;
  }
  return '<div class="image-preview">' . $output . '</div>';
}

/**
 * theme_node_gallery_teaser()
 *
 * In the event the teaser image_view is directly called, we want to
 * allow people to be able to wrap the image with custom markup
 */
function theme_node_gallery_teaser($config, $node) {
  return theme('image_view', $config->teaser['image'], $node);
}