You are here

function template_preprocess_galleria in Galleria 6

Implementation of template_preprocess_hook().

Build a Galleria from an array of images. This is called in both cases (i.e. building Galleria from CCK imagefield or from attached files).

Parameters

$images: An array of file objects representing the images to be included in the Galleria

Return value

$vars Themed Galleria.

File

./galleria.module, line 279
Turns a node into a Galleria image gallery.

Code

function template_preprocess_galleria(&$vars) {
  $images = $vars['images'];
  $image_list = array();
  $i = 0;
  $imagecache_exists = module_exists('imagecache');
  $img_preset = variable_get('galleria_imagecache_preset', '');
  $thumb_preset = variable_get('galleria_thumb_imagecache_preset', '');
  $lightbox_integration = variable_get('galleria_lightbox', 'none');
  $lightbox_preset = variable_get('galleria_lightbox_preset', '');
  foreach ($images as $image) {
    $caption = $image->description != $image->filename ? $image->description : '';
    $filepath = $image->filepath;

    // We have the main image opening in a lightbox.
    if ($lightbox_integration != 'none') {

      // User has selected an Imagecache preset to resize the lightbox image.
      if ($lightbox_preset && $imagecache_exists) {
        $alt_text = imagecache_create_url($lightbox_preset, $filepath);
      }
      else {
        $alt_text = url($filepath, array(
          'absolute' => TRUE,
        ));
      }
    }
    else {
      $alt_text = $image->alt;
    }
    if ($imagecache_exists && $thumb_preset) {
      $thumb = theme('imagecache', $thumb_preset, $filepath, $alt_text, $caption);
    }
    if ($imagecache_exists && $img_preset) {
      if ($thumb) {

        // There is an imagecache preset for both thumbnail and gallery image.
        $image = l($thumb, imagecache_create_url($img_preset, $filepath), array(
          'html' => TRUE,
          'attributes' => array(
            'title' => $caption,
          ),
        ));
      }
      else {

        // There is an imagecache preset for only the gallery image.
        $image = theme('imagecache', $img_preset, $filepath, $alt_text, $caption);
      }
    }
    else {
      if ($thumb) {

        // There is an imagecache preset for only the thumbnail image.
        $image = l($thumb, $filepath, array(
          'html' => TRUE,
          'attributes' => array(
            'title' => $caption,
          ),
        ));
      }
      else {

        // No imagecache presets selected.
        $image = theme('image', $filepath, $alt_text, $caption);
      }
    }
    $image_list[] = array(
      'data' => $image,
      'class' => $i == 0 ? 'active' : '',
    );
    $i++;
  }
  $attribs = array(
    'class' => 'gallery clear-block',
  );
  $vars['thumbnails'] = theme('item_list', $image_list, NULL, 'ul', $attribs);
  $vars['image_count'] = $i;
  $vars['prev'] = t('previous');
  $vars['next'] = t('next');

  // jCarousel integration setup
  if (module_exists('jcarousel') && variable_get('galleria_jcarousel', 'enabled') == 'enabled' && $i > 1) {
    $options = array(
      'vertical' => variable_get('galleria_jcarousel_vertical', 'false') == 'true' ? TRUE : FALSE,
      'visible' => variable_get('galleria_jcarousel_visible', '3'),
      'scroll' => variable_get('galleria_jcarousel_scroll', '3'),
      'animation' => variable_get('galleria_jcarousel_animation', 'fast'),
      'wrap' => variable_get('galleria_jcarousel_wrap', 'null'),
      'initCallback' => 'Drupal.galleria.jcarousel_initCallback',
    );
    jcarousel_add('.gallery', $options);
  }
}