You are here

function lightbox2_link_alter in Lightbox2 5.2

Same name and namespace in other branches
  1. 8 lightbox2.module \lightbox2_link_alter()
  2. 6 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 2398
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(&$node, &$links) {
  $image_node_handler = variable_get('lightbox2_image_node', 0);

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

  // Change original ('') to '_original'.
  if (isset($trigger_sizes[''])) {
    unset($trigger_sizes['']);
    $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']);
    }
  }
}