You are here

function lightbox2_link_alter in Lightbox2 6

Same name and namespace in other branches
  1. 8 lightbox2.module \lightbox2_link_alter()
  2. 5.2 lightbox2.module \lightbox2_link_alter()
  3. 7.2 lightbox2.module \lightbox2_link_alter()
  4. 7 lightbox2.module \lightbox2_link_alter()

Implementation of hook_link_alter().

Add a lightbox2 rel attribute to the image link sizes on the image node.

File

./lightbox2.module, line 1375
Enables the use of lightbox2 which places images above your current page, not within. This frees you from the constraints of the layout, particularly column widths.

Code

function lightbox2_link_alter(&$links, $node) {
  $image_node_handler = variable_get('lightbox2_image_node', 0);

  // Only operate on image nodes and if automatic handling for image nodes is
  // enabled.  Also ensure $links is an array (bug in contemplate module).
  if (!$image_node_handler || $node->type != 'image' && $image_node_handler || !is_array($links)) {
    return;
  }
  $trigger_sizes = variable_get('lightbox2_trigger_image_size', array(
    'thumbnail',
  ));

  // Change original ('original') to '_original'.
  if (isset($trigger_sizes['original'])) {
    unset($trigger_sizes['original']);
    $trigger_sizes['_original'] = '_original';
  }
  $rel = '';
  switch ($image_node_handler) {
    case 1:

    // Lightbox.
    case 2:

    // Lightbox grouped.
    case 3:

      // Slideshow.
      $rel = 'lightbox';
      break;
    case 4:

    // Lightframe.
    case 5:

      // Lightframe grouped.
      $rel = 'lightframe';
      break;
  }
  $rel = $rel . '[][' . $node->title . ']';
  foreach ($trigger_sizes as $size) {
    if (isset($links['image_size_' . $size])) {
      $links['image_size_' . $size]['attributes']['rel'] = $rel;
      $links['image_size_' . $size]['href'] = $node->images[$size];
      unset($links['image_size_' . $size]['query']);
    }
  }
}