You are here

lightbox2.module in Lightbox2 8

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.

This module is for Drupal 6.x only.

Module by: Mark Ashmead Mailto: bugzie@gmail.com Co-maintainer: Stella Power (http://drupal.org/user/66894)

Image Node Support: Steve McKenzie

File

lightbox2.module
View source
<?php

/**
 * @file
 * 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.
 *
 * This module is for Drupal 6.x only.
 *
 * Module by: Mark Ashmead
 * Mailto: bugzie@gmail.com
 * Co-maintainer: Stella Power (http://drupal.org/user/66894)
 *
 * Image Node Support: Steve McKenzie
 */

/**
 * Implementation of hook_help().
 */
function lightbox2_help($path, $arg) {
  switch ($path) {
    case 'admin/modules#description':
      $output = t('Enables Lightbox2 for Drupal');
      break;
    case 'admin/help#lightbox2':
      $output = '<h3>' . t('Overview') . '</h3>';
      $output .= '<p>' . t('Lightbox2 JS is a simple, unobtrusive script used to overlay images on the current page. It\'s a snap to setup and works on all modern browsers. The module comes with a Lightbox2 Lite option which does not use the JQuery libraries; it is therefore less likely to conflict with anything else.') . '</p>';
      $output .= '<p>' . t('Places images above your current page, not within. This frees you from the constraints of the layout, particularly column widths. Keeps users on the same page. Clicking to view an image and then having to click the back button to return to your site is bad for continuity (and no fun!).') . '</p>';

      // Features
      $output .= '<h3>' . t('Features') . '</h3>';
      $output .= '<p>' . t('The version 2 module has several benefits over the plain Lightbox module. Note, not all of these features are available when the "Lightbox2 Lite" option is enabled.') . '</p>';
      $output .= '<ul>';
      $output .= '<li>' . t('Image Sets: group related images and navigate through them with ease - ideal for your image galleries.') . '</li>';
      $output .= '<li>' . t('Slideshow Capability: automatically transition between grouped images, includes play/pause and previous and next buttons.') . '</li>';
      $output .= '<li>' . t('HTML Content Support: ability to show websites or other HTML content in a lightbox.') . '</li>';
      $output .= '<li>' . t('Video Content Support: ability to show videos in a lightbox.') . '</li>';
      $output .= '<li>' . t('Visual Effects: fancy pre-loader and transition when you click on the image.') . '</li>';
      $output .= '<li>' . t('Keyboard Shortcuts: useful <a href="http://drupal.org/node/249827">keyboard shortcuts</a> for switching between images, toggling play / pause, etc.') . '</li>';
      $output .= '<li>' . t('Zoom Capability: larger images are reduced in size so they fit snugly inside the browser window.  A zoom button can then be clicked on to see it in its original size.') . '</li>';
      $output .= '<li>' . t('Automatic Image Detection: configurable automatic re-formatting of image thumbnails, so there is no need to add \'rel="lightbox"\' to each image link on your site. ');
      $output .= t('<a href="!image">Image</a>, <a href="!inline">Inline</a>, <a href="!flickr">Flickr</a>, <a href="!img_assist">Image Assist</a> and <a href="!imagefield">CCK Imagefield</a> modules are all supported. ', array(
        '!image' => 'http://drupal.org/project/image',
        '!inline' => 'http://drupal.org/project/inline',
        '!flickr' => 'http://drupal.org/project/flickr',
        '!img_assist' => 'http://drupal.org/project/img_assist',
        '!imagefield' => 'http://drupal.org/project/imagefield',
      ));
      $output .= t('It\'s also possible to configure a custom list of image classes which should trigger the lightbox functionality.');
      $output .= '</li>';
      $output .= '<li>' . t('<a href="!imagecache">Imagecache</a> Support: adds a Lightbox2 field formatter for <a href="!imagefield">CCK imagefields</a> for your custom <a href="!views">views</a>.', array(
        '!imagecache' => 'http://drupal.org/project/imagecache',
        '!imagefield' => 'http://drupal.org/project/imagefield',
        '!views' => 'http://drupal.org/project/views',
      )) . '</li>';
      $output .= '<li>' . t('Image Page Link: a link to the image node can be provided within the lightbox itself.') . '</li>';
      $output .= '<li>' . t('Page Exclusion Capability: exclude certain pages on your site from having the lightbox2 functionality.') . '</li>';
      $output .= '<li>' . t('Login Support: ability to modify all user/login links so the login form appears in a lightbox.') . '</li>';
      $output .= '<li>' . t('Skin and Animation Configuration: configure the order and speed of the lightbox animations, along with the lightbox colors, border size and overlay opacity.') . '</li>';
      $output .= '<li>' . t('Gallery 2 Support: support for Gallery 2 images via the <a href="!gallery">Gallery</a> module (beta).', array(
        '!gallery' => 'http://drupal.org/project/gallery',
      )) . '</li>';
      $output .= '</ul>';

      // Usage
      $output .= '<h3>' . t('Usage') . '</h3>';
      $output .= '<h5 style="text-decoration: underline;">' . t('Adding a Basic Lightbox') . '</h5>';
      $output .= '<p>' . t('Add rel=&quot;lightbox&quot; attribute to any link tag to activate the lightbox. For example:') . '</p>';
      $output .= '<code>' . t('&lt;a href=&quot;image-1.jpg&quot; rel=&quot;lightbox&quot;&gt;image #1&lt;/a&gt;<br />
                              &lt;a href=&quot;image-1.jpg&quot; rel=&quot;lightbox[][my caption]&quot;&gt;image #1&lt;/a&gt;') . '</code>';
      $output .= '<p>' . t('Optional: To show a caption either use the title attribute or put in the second set of [] of the rel attribute.') . '</p>';

      // Grouping Images
      $output .= '<h5 style="text-decoration: underline;">' . t('Grouping Images') . '</h5>';
      $output .= '<p>' . t('If you have a set of related images that you would like to group, follow step one but additionally include a group name between square brackets in the rel attribute. For example:') . '</p>';
      $output .= '<code>' . t('&lt;a href="images/image-1.jpg" rel="lightbox[roadtrip]"&gt;image #1&lt;/a&gt;<br />
                              &lt;a href="images/image-2.jpg" rel="lightbox[roadtrip][caption 2]"&gt;image#2&lt;/a&gt;<br />
                              &lt;a href="images/image-3.jpg" rel="lightbox[roadtrip][caption 3]"&gt;image#3&lt;/a&gt;') . '</code>';
      $output .= '<p>' . t('No limits to the number of image sets per page or how many images are allowed in each set.') . '</p>';
      $output .= '<p>' . t('If you have a set of images that you would like to group together in a lightbox, but only wish for one of these images to be visible on your page, you can assign the "lightbox_hide_image" class to hide the additional images. For example:') . '</p>';
      $output .= '<p><code>' . t('&lt;a href="images/image-1.jpg" rel="lightbox[roadtrip]"&gt;image #1&lt;/a&gt;<br />
                              &lt;a href="images/image-2.jpg" rel="lightbox[roadtrip]" class="lightbox_hide_image"&gt;image #2&lt;/a&gt;<br />
                              &lt;a href="images/image-3.jpg" rel="lightbox[roadtrip][caption 3]" class="lightbox_hide_image"&gt;image #3&lt;/a&gt;') . '</code></p>';

      // Slideshow
      $output .= '<h5 style="text-decoration: underline;">' . t('Slideshow') . '</h5>';
      $output .= '<p>' . t('This is very similar to the grouping functionality described above. The only difference is that "rel" attribute should be set to "lightshow" instead of "lightbox". Using the same example as above, we could launch the images in a slideshow by doing:') . '</p>';
      $output .= '<p><code>' . t('&lt;a href="images/image-1.jpg" rel="lightshow[roadtrip]"&gt;image #1&lt;/a&gt;<br />
                              &lt;a href="images/image-2.jpg" rel="lightshow[roadtrip][caption 2]"&gt;image #2&lt;/a&gt;<br />
                              &lt;a href="images/image-3.jpg" rel="lightshow[roadtrip][caption 3]"&gt;image #3&lt;/a&gt;') . '</code></p>';

      // Video Content
      $output .= '<h5 style="text-decoration: underline;">' . t('Video Content') . '</h5>';
      $output .= '<p>' . t('It\'s possible to show video content in the lightbox. In this case the "rel" attribute should be set to <code>lightvideo</code>. It\'s possible to group videos and to control the size of the lightbox by setting the \'width\' and \'height\' properties. The properties can be configured like <code>lightvideo[group|width:300px; height: 200px;]</code> and <code>lightvideo[|width:300px; height: 200px;][my caption]</code>. The properties should all be of the format "property: value;" - note the closing semi-colon. If no properties are set, then the default width and height of 400px will be used. See below for more detailed examples.') . '</p>';
      $output .= '<p>' . t('Basic example:') . '<br />';
      $output .= '<code>' . t('&lt;a href="http://video.google.com/videoplay?docid=1811233136844420765" rel="lightvideo"&gt;Google video example - default size&lt;/a&gt;') . '</code></p>';
      $output .= '<p>' . t('Basic example with caption:') . '<br />';
      $output .= '<code>' . t('&lt;a href="http://video.google.com/videoplay?docid=1811233136844420765" rel="lightvideo[][my caption]"&gt;Google video example - default size&lt;/a&gt;') . '</code></p>';
      $output .= '<p>' . t('Grouped example:') . '<br />';
      $output .= '<code>' . t('&lt;a href="http://video.google.com/videoplay?docid=29023498723974239479" rel="lightvideo[group][my caption]"&gt;Grouped example 1&lt;/a&gt;<br />
                              &lt;a href="http://video.google.com/videoplay?docid=1811233136844420765" rel="lightvideo[group][my caption]"&gt;Grouped example 2&lt;/a&gt;') . '</code></p>';
      $output .= '<p>' . t('Controlling lightbox size example:') . '<br />';
      $output .= '<code>' . t('&lt;a href="http://video.google.com/videoplay?docid=1811233136844420765" rel="lightvideo[|width:400px; height:300px;][my caption]"&gt;Google video example - custom size&lt;/a&gt;') . '<br /></code></p>';
      $output .= '<p>' . t('Supported Video Formats:') . '<br />';
      $output .= t('asx, wmv, mov and swf videos should all be supported. A number of video providers are also supported, for example YouTube and Google Video. For full details on how to integrate these with lightbox, please see the online documentation.') . '</p>';

      // HTML Content
      $output .= '<h5 style="text-decoration: underline;">' . t('HTML Content') . '</h5>';
      $output .= '<p>' . t('It\'s possible to show webpage content in the lightbox, using iframes. In this case the "rel" attribute should be set to <code>lightframe</code>. Again it\'s possible to group the items, (e.g. <code>lightframe[search]</code>) but in addition to that, it\'s possible to control some of the iframe properties. It\'s possible to set the \'width\', \'height\' and \'scrolling\' properties of the iframe. The properties are separated from the group name by a <code>|</code>, for example <code>lightframe[search|width:100px;]</code> and <code>lightframe[search|width:120px][my caption]</code>. If no grouping is being used, then the <code>|</code> is still used and the format would be <code>lightframe[|width:100px;]</code>. The properties should all be of the format "property: value;" - note the closing semi-colon.  If no iframe properties are set, then the default width and height of 400px will be used.  See below for more detailed examples.') . '</p>';
      $output .= '<p>' . t('Basic example:') . '<br />';
      $output .= '<code>' . t('&lt;a href="http://www.google.com" rel="lightframe[][Search Google]"&gt;Search google&lt;/a&gt;') . '</code></p>';
      $output .= '<p>' . t('Grouped example:') . '<br />';
      $output .= '<code>' . t('&lt;a href="http://www.google.com" rel="lightframe[search]"&gt;Search google&lt;/a&gt;<br />
                              &lt;a href="http://www.yahoo.com" rel="lightframe[search][Search Yahoo]"&gt;Search yahoo&lt;/a&gt;') . '</code></p>';
      $output .= '<p>' . t('Controlling iframe property example:') . '<br />';
      $output .= '<code>' . t('&lt;a href="http://www.google.com" rel="lightframe[|width:400px; height:300px; scrolling: auto;]"&gt;Search google&lt;/a&gt;') . '</code></p>';
      $output .= '<p>' . t('Controlling iframe property when grouped example:') . '<br />';
      $output .= '<code>' . t('&lt;a href="http://www.google.com" rel="lightframe[search|width:400px; height:300px; scrolling: auto;]"&gt;Search google&lt;/a&gt;<br />
                              &lt;a href="http://www.yahoo.com" rel="lightframe[search|width:400px; height:300px;][Search Yahoo]"&gt;Search yahoo&lt;/a&gt;') . '</code></p>';

      // Inline Content Support
      $output .= '<h5 style="text-decoration: underline;">' . t('Inline Content Support') . '</h5>';
      $output .= '<p>' . t('It\'s possible to show HTML snippets in the lightbox, that is on the same domain. In this case the "rel" attribute should be set to <code>lightmodal</code>. Again it\'s possible to group the content, (e.g. <code>lightmodal[search]</code>) but in addition to that, it\'s possible to control some of the inline / modal properties. It\'s possible to set the \'width\', \'height\' and \'scrolling\' properties of the inline content. The properties are separated from the group name by a <code>|</code>, for example <code>lightmodal[search|width:100px;]</code> and <code>lightmodal[search|width:100px;][my caption]</code>. If no grouping is being used, then the <code>|</code> is still used and the format would be <code>lightmodal[|width:100px;]</code>. The properties should all be of the format "property: value;" - note the closing semi-colon. If no properties are set, then the default width and height of 400px will be used. See below for more detailed examples.') . '</p>';
      $output .= '<p>' . t('Basic example:') . '<br />';
      $output .= '<code>' . t('&lt;a href="search.php" rel="lightmodal"&gt;Search&lt;/a&gt;') . '</code></p>';
      $output .= '<p>' . t('Basic example with caption:') . '<br />';
      $output .= '<code>' . t('&lt;a href="search.php" rel="lightmodal[][my caption]"&gt;Search&lt;/a&gt;') . '</code></p>';
      $output .= '<p>' . t('Grouped example:') . '<br />';
      $output .= '<code>' . t('&lt;a href="search.php" rel="lightmodal[search]"&gt;Search&lt;/a&gt;<br />
                              &lt;a href="search.php?status=1" rel="lightmodal[search][published]"&gt;Search published content&lt;/a&gt;') . '</code></p>';
      $output .= '<p>' . t('Controlling modal property example:') . '<br />';
      $output .= '<code>' . t('&lt;a href="search.php" rel="lightmodal[|width:400px; height:300px; scrolling: auto;]"&gt;Search&lt;/a&gt;') . '</code></p>';
      $output .= '<p>' . t('Controlling modal property when grouped example:') . '<br />';
      $output .= '<code>' . t('&lt;a href="search.php" rel="lightmodal[search|width:400px; height:300px; scrolling: auto;]"&gt;Search&lt;/a&gt;<br />
                              &lt;a href="search.php?status=1" rel="lightmodal[search|width:400px; height:300px;][Search published]"&gt;Search published content&lt;/a&gt;<br />
                              &lt;a href="search.php?status=0" rel="lightmodal[search|width:400px; height:300px;][Search Unpublished]"&gt;Search unpublished content&lt;/a&gt;') . '</code></p>';

      // Keyboard Shortcuts
      $output .= '<h3>' . t('Keyboard Shortcuts') . '</h3>';
      $output .= '<p>' . t('The default keyboard shortcuts are listed below. You can override these on the admin page.') . '</p>';
      $output .= '<table>';
      $output .= '<tr><td>' . t('Close Lightbox') . '</td><td>x</td></tr>';
      $output .= '<tr><td></td><td>o</td></tr>
                  <tr><td></td><td>c</td></tr>
                  <tr><td></td><td>ESC</td></tr>';
      $output .= '<tr><td>' . t('Previous Image') . '</td><td>p</td></tr>';
      $output .= '<tr><td></td><td>' . t('Left Arrow') . '</td></tr>';
      $output .= '<tr><td>' . t('Next Image') . '</td><td>n</td></tr>';
      $output .= '<tr><td></td><td>' . t('Right Arrow') . '</td></tr>';
      $output .= '<tr><td>' . t('Toggle Zoom') . '</td><td>' . t('z (not available in slideshow)') . '</td></tr>';
      $output .= '<tr><td>' . t('Toggle Play / Pause') . '</td><td>' . t('Spacebar (slideshow only)') . '</td></tr>';
      $output .= '</table>';
      $output .= '<p>' . t('Not all of the keyboard shortcuts work in the Opera browser, for example "z" for toggling the zoom and "spacebar" for toggling play / pause in slideshows. This can be overcome by updating your shortcut settings in the Opera preferences editor.') . '</p>';
      break;
  }
  return !empty($output) ? $output : '';
}

/**
 * Implementation of hook_permission().
 */
function lightbox2_permission() {
  return array(
    'administer lightbox2' => array(
      'title' => t('Administer Lightbox2'),
      'description' => t('Allow the user administer Lightbox2 settings'),
    ),
    'download original image' => array(
      'title' => t('Download Original'),
      'description' => t('Create a link that allow the user download the original image'),
    ),
  );
}

/**
 * Implementation of hook_menu().
 */
function lightbox2_menu() {
  $items = array();
  $items['system/lightbox2/filter-xss'] = array(
    'title' => 'Filter XSS',
    'page callback' => 'lightbox2_filter_xss',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  $items['admin/config/user-interface/lightbox2'] = array(
    'title' => 'Lightbox2',
    'description' => 'Allows the user to configure the lightbox2 settings',
    'file' => 'lightbox2.admin.inc',
    'page callback' => 'lightbox2_settings_page',
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer lightbox2',
    ),
  );
  $items['admin/config/user-interface/lightbox2/general'] = array(
    'title' => 'General',
    'description' => 'Allows the user to configure the lightbox2 settings',
    'file' => 'lightbox2.admin.inc',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'lightbox2_general_settings_form',
    ),
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer lightbox2',
    ),
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => 0,
  );
  $items['admin/config/user-interface/lightbox2/slideshow'] = array(
    'title' => 'Slideshow',
    'description' => 'Allows the user to configure the lightbox2 slideshow functionality',
    'file' => 'lightbox2.admin.inc',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'lightbox2_slideshow_settings_form',
    ),
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer lightbox2',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 1,
  );
  $items['admin/config/user-interface/lightbox2/html_content'] = array(
    'title' => 'HTML Content',
    'file' => 'lightbox2.admin.inc',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'lightbox2_iframe_settings_form',
    ),
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer lightbox2',
    ),
    'description' => 'Allows the user to configure the lightbox2 HTML content functionality.',
    'type' => MENU_LOCAL_TASK,
    'weight' => 2,
  );
  $items['admin/config/user-interface/lightbox2/automatic'] = array(
    'title' => 'Automatic image handling',
    'description' => 'Allows the user to configure the lightbox2 automatic image handling settings',
    'file' => 'lightbox2.admin.inc',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'lightbox2_auto_image_handling_settings_form',
    ),
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer lightbox2',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 3,
  );

  /**
  if (module_exists('emfield') && module_exists('emvideo')) {
    $items['video-cck/lightbox2/%node'] = array(
      'page callback' => 'lightbox2_emvideo',
      'page arguments' => array(2),
      'access callback' => 'node_access',
      'access arguments' => array('view', 2),
      'type' => MENU_CALLBACK,
    );
  }
  */

  /**
  * There is not a version from acidfree to drupal 7
    if (module_exists('acidfree') && module_exists('video')) {
   $items['node/%node/lightframevideo'] = array(
     'page callback' => 'lightbox2_acidfree_video',
     'page arguments' => array(1),
     'access callback' => 'lightbox2_acidfree_video_access',
     'access arguments' => array(1),
     'type' => MENU_CALLBACK,
   );
    }
  */
  $items['user/login/lightbox2'] = array(
    'title' => 'Login',
    'page callback' => 'lightbox2_login',
    'access callback' => 'user_is_anonymous',
    'type' => MENU_CALLBACK,
  );
  $items['contact/lightbox2'] = array(
    'title' => 'Contact',
    'page callback' => 'lightbox2_contact',
    'access arguments' => array(
      'access site-wide contact form',
    ),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Acidfree video access control.
 */

/**
 * No acidvideo for drupal 7
 * function lightbox2_acidfree_video_access($node) {
  if (user_access('play video') && node_access('view', $node)) {
    return TRUE;
  }
  return FALSE;
}
*/

/**
 * Implementation of hook_init().
 */
function lightbox2_init() {
  if (lightbox2_exclude_these_paths() != 1) {
    lightbox2_add_files();
  }
}

/**
 * Implementation of hook_filter_tips().
 */

/*
* This is not used any more on drupal 7, keep here only to help with the
* conversion, when there is a drupal 7 port, delete this function
function lightbox2_filter_tips($delta, $format, $long = FALSE) {
 if ($delta == 0) {
   if (!$long) {
     return t('Image links with \'rel="lightbox"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
   }
   else {
     $output = '<p>'. t('To add a lightbox to your images, add rel="lightbox" attribute to any link tag to activate the lightbox. For example:') .'</p>';
     $output .= '<p>'. t('<code>&lt;a href="image-1.jpg" rel="lightbox"&gt;image #1&lt;/a&gt;</code>') .'</p>';
     $output .= '<p>'. t('<code>&lt;a href="image-1.jpg" rel="lightbox[][my caption]"&gt;image #1&lt;/a&gt;</code>') .'</p>';
     $output .= '<p>'. t('To show a caption either use the title attribute or put in the second set of square brackets of the rel attribute.') .'</p>';
     $output .= '<p>'. t('If you have a set of related images that you would like to group, then you will need to include a group name between square brackets in the rel attribute. For example:') .'</p>';
     $output .= '<p>'. t('<code>&lt;a href="image-1.jpg" rel="lightbox[roadtrip]"&gt;image #1&lt;/a&gt;<br /> &lt;a href="image-2.jpg" rel="lightbox[roadtrip][caption 2]"&gt;image #2&lt;/a&gt;<br /> &lt;a href="image-3.jpg" rel="lightbox[roadtrip][caption 3]"&gt;image #3&lt;/a&gt;<br /> </code>') .'</p>';
     $output .= '<p>'. t('There are no limits to the number of image sets per page or how many images are allowed in each set.') .'</p>';
     $output .= '<p>'. t('If you wish to turn the caption into a link, format your caption in the following way:') .'</p>';
     $output .= '<p>'. t('<code>&lt;a href="image-1.jpg" rel=\'lightbox[][&lt;a href="http://www.yourlink.com"&gt;View Image Details&lt;/a&gt;]\' &gt;image #1&lt;/a&gt;</code>') .'</p>';
     return $output;
   }
 }
 elseif ($delta == 1) {
   return t('Image links from G2 are formatted for use with Lightbox2');
 }
 elseif ($delta == 2) {
   if (!$long) {
     return t('Image links with \'rel="lightshow"\' in the &lt;a&gt; tag will appear in a Lightbox slideshow when clicked on.');
   }
   else {
     $output = '<p>'. t('To add a lightbox slideshow to your images, add rel="lightshow[slideshowname][slide caption]" attribute to any link tag to activate the slideshow. For example:') .'</p>';
     $output .= '<p>'. t('<code>&lt;a href="image-1.jpg" rel="lightshow[show1]"&gt;image #1&lt;/a&gt;<br /> &lt;a href="image-2.jpg" rel="lightshow[show1]"&gt;image #2&lt;/a&gt;<br /> &lt;a href="image-3.jpg" rel="lightshow[show1]"&gt;image #3&lt;/a&gt;<br /> </code>') .'</p>';
     $output .= '<p>'. t('The title attribute in the link tag is optional. The addition of this attribute enables the display of a caption with the image displayed in the lightbox.') .'</p>';
     $output .= '<p>'. t('There are no limits to the number of slideshow image sets per page or how many images are allowed in each slideshow.') .'</p>';
     $output .= '<p>'. t('If you wish to turn the caption into a link, format your caption in the following way:') .'</p>';
     $output .= '<p>'. t('<code>&lt;a href="image-1.jpg" rel=\'lightshow[show1][&lt;a href="http://www.yourlink.com"&gt;View Image Details&lt;/a&gt;]\'&gt;image #1&lt;/a&gt;</code>') .'</p>';
     return $output;
   }
 }
 elseif ($delta == 3) {
   if (!$long) {
     return t('Links to HTML content with \'rel="lightframe"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
   }
   else {
     $output = '<p>'. t('It\'s possible to show webpage content in the lightbox, using iframes.  In this case the "rel" attribute should be set to "lightframe".  Again it\'s possible to group the content, (e.g. <code>lightframe[search][caption]</code>) but in addition to that, it\'s possible to control some of the iframe properties.  It\'s possible to set the "width", "height" and "scrolling" properties of the iframe.  The properties are separated from the group name by a <code>|</code>, for example <code>lightframe[search|width:100px;][caption]</code>.  If no grouping is being used, then the <code>|</code> is still used and the format would be <code>lightframe[|width:100px;]</code>.  The properties should all be of the format "property: value;" - note the closing semi-colon.  If no iframe properties are set, then the default width and height of 400px will be used.  See below for more detailed examples.') .'</p>';
     $output .= '<p>'. t('Basic example:') .'<br />';
     $output .= t('<code>&lt;a href=&quot;http://www.google.com&quot; rel=&quot;lightframe&quot;&gt;Search google&lt;/a&gt;</code>') .'</p>';
     $output .= '<p>'. t('Grouped example:') .'<br />';
     $output .= t('<code>&lt;a href=&quot;http://www.google.com&quot; rel=&quot;lightframe[search][caption]&quot;&gt;Search google&lt;/a&gt;<br />&lt;a href=&quot;http://www.yahoo.com&quot; rel=&quot;lightframe[search]&quot;&gt;Search yahoo&lt;/a&gt;</code>') .'</p>';

     $output .= '<p>'. t('Controlling iframe property example:') .'<br />';
     $output .= t('<code>&lt;a href=&quot;http://www.google.com&quot; rel=&quot;lightframe[|width:400px; height:300px; scrolling: auto;][caption]&quot;&gt;Search google&lt;/a&gt;</code>') .'</p>';
     $output .= '<p>'. t('Controlling iframe property when grouped example:') .'<br />';
     $output .= t('<code>&lt;a href=&quot;http://www.google.com&quot; rel=&quot;lightframe[search|width:400px; height:300px; scrolling: auto;]&quot;&gt;Search google&lt;/a&gt;<br />&lt;a href=&quot;http://www.yahoo.com&quot; rel=&quot;lightframe[search|width:400px; height:300px;]&quot;&gt;Search yahoo&lt;/a&gt;</code>') .'</p>';

     return $output;
   }
 }
 elseif ($delta == 4) {
   if (!$long) {
     return t('Links to video content with \'rel="lightvideo"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
   }
   else {
     $output = '<p>'. t('It\'s possible to show video content in the lightbox.  In this case the "rel" attribute should be set to <code>lightvideo</code>.  It\'s possible to group videos and to control the size of the lightbox by setting the "width" and "height" properties.  The properties can be configured like <code>lightvideo[group|width:300px; height: 200px;][caption]</code>.  The properties should all be of the format "property: value;" - note the closing semi-colon.  If no properties are set, then the default width and height of 400px will be used.  See below for more detailed examples.') .'</p>';
     $output .= '<p>'. t('Basic example:') .'<br />';
     $output .= t('<code>&lt;a href=&quot;http://video.google.com/videoplay?docid=1811233136844420765&quot; rel=&quot;lightvideo&quot;&gt;Google video example - default size&lt;/a&gt;</code>') .'</p>';
     $output .= '<p>'. t('Controlling lightbox size example:') .'<br />';
     $output .= t('<code>&lt;a href=&quot;http://video.google.com/videoplay?docid=1811233136844420765&quot; rel=&quot;lightvideo[group|width:400px; height:300px;][caption]&quot;&gt;Google video example - custom size&lt;/a&gt;</code>') .'</p>';
     $output .= '<p>'. t('Supported video formats include asx, wmv, mov and swf.  A number of online video providers are also supported, including YouTube and Google Video.  For a full list of the current supported video providers please see the documentation on drupal.org.') .'</p>';
     return $output;
   }
 }
 elseif ($delta == 5) {
   if (!$long) {
     return t('Links to inline or modal content with \'rel="lightmodal"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
   }
   else {
     $output = '<p>'. t('It\'s possible to show HTML snippets in the lightbox, that is on the same domain.  In this case the "rel" attribute should be set to "lightmodal".  Again it\'s possible to group the content, (e.g. <code>lightmodal[group][caption]</code>) but in addition to that, it\'s possible to control some of the modal properties.  It\'s possible to set the "width", "height" and "scrolling" properties of the modal.  The properties are separated from the group name by a <code>|</code>, for example <code>lightmodal[group|width:100px;][caption]</code>.  If no grouping is being used, then the <code>|</code> is still used and the format would be <code>lightmodal[|width:100px;]</code>.  The properties should all be of the format "property: value;" - note the closing semi-colon.  If no modal properties are set, then the default width and height of 400px will be used.  See below for more detailed examples.') .'</p>';
     $output .= '<p>'. t('Basic example:') .'<br />';
     $output .= t('<code>&lt;a href=&quot;search.php&quot; rel=&quot;lightmodal&quot;&gt;Search&lt;/a&gt;</code>') .'</p>';
     $output .= '<p>'. t('Grouped example:') .'<br />';
     $output .= t('<code>&lt;a href=&quot;search.php&quot; rel=&quot;lightmodal[search][caption 1]&quot;&gt;Search&lt;/a&gt;<br />&lt;a href=&quot;search.php?status=1&quot; rel=&quot;lightmodal[search]&quot;&gt;Search published&lt;/a&gt;</code>') .'</p>';

     $output .= '<p>'. t('Controlling modal property example:') .'<br />';
     $output .= t('<code>&lt;a href=&quot;search.php&quot; rel=&quot;lightmodal[|width:400px; height:300px; scrolling: auto;][caption]&quot;&gt;Search&lt;/a&gt;</code>') .'</p>';
     $output .= '<p>'. t('Controlling modal property when grouped example:') .'<br />';
     $output .= t('<code>&lt;a href=&quot;search.php&quot; rel=&quot;lightmodal[search|width:400px; height:300px; scrolling: auto;]&quot;&gt;Search&lt;/a&gt;<br />&lt;a href=&quot;search.php?status=1&quot; rel=&quot;lightmodal[search|width:400px; height:300px;]&quot;&gt;Search published&lt;/a&gt;</code>') .'</p>';

     return $output;
   }
 }
}

/**
* Implementation of hook_filter().
*/

/*
 * This is not used any more on drupal 7, keep here only to help with the
 * conversion, when there is a drupal 7 port, delete this function
function lightbox2_filter($op, $delta = 0, $format = -1, $text = '') {
  switch ($op) {
    case 'list':
      return array(
        0 => t('Lightbox filter'),
        1 => t('Lightbox G2 filter'),
        2 => t('Lightbox slideshow filter'),
        3 => t('Lightbox iframe filter'),
        4 => t('Lightbox video filter'),
        5 => t('Lightbox modal filter'),
        6 => t('Disable Lightbox iframe filter'),
      );

    case 'description':
      if ($delta == 0) {
        return t('Image links with \'rel="lightbox"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
      }
      elseif ($delta == 1) {
        return t('Turns g2_filter links into Lightbox2 appropriate links');
      }
      elseif ($delta == 2) {
        return t('Image links with \'rel="lightshow"\' in the &lt;a&gt; tag will appear in a Lightbox slideshow when clicked on.');
      }
      elseif ($delta == 3) {
        return t('Links to HTML content with \'rel="lightframe"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
      }
      elseif ($delta == 4) {
        return t('Links to video content with \'rel="lightvideo"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
      }
      elseif ($delta == 5) {
        return t('Links to inline or modal content with \'rel="lightmodal"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
      }
      elseif ($delta == 6) {
        return t('It\'s possible to show webpage content in the lightbox, using iframes.  In this case the "rel" attribute should be set to "lightframe".  However, users can do this without any filters to be enabled.  To prevent users from adding iframes to the site in this manner, then please enable this option.');
      }

    case 'process':
      if ($delta == 1) {
        $text = ' '. $text .' ';
        $text = preg_replace('/ShowItem/', 'DownloadItem', $text);
        $text = preg_replace('/<img\s+([^>]*?)src="/', '<img \1rel="lightbox" src="', $text);
        $text = drupal_substr($text, 1, -1);
      }
      elseif ($delta == 6) {
        $text = preg_replace('/<a([^>]*?)(rel=[\'"]*lightframe[\'"]*)([^>]*?)>/i', '<a\1\3>', $text);
      }
      return $text;

    default:
      return $text;
  }
}
*/

/**
 * Process callback for Lightbox G2 filter.
 */
function _lightbox2_process_filter($text, $format) {
  $text = ' ' . $text . ' ';
  $text = preg_replace('/ShowItem/', 'DownloadItem', $text);
  $text = preg_replace('/src="/', 'rel="lightbox" src="', $text);
  $text = \Drupal\Component\Utility\Unicode::substr($text, 1, -1);
  return $text;
}

/**
 * Process callback for Disable Lightbox iframe filter.
 */
function _lightbox2_process_disable_filter($text, $format) {
  $text = preg_replace('/<a([^>]*?)(rel=[\'"]*lightframe[\'"]*)([^>]*?)>/i', '<a\\1\\3>', $text);
  return $text;
}

/**
 * Implements hook_filter_info().
 */
function lightbox2_filter_info() {
  $filters = array();
  $filters['lightbox2_filter'] = array(
    'title' => t('Lightbox filter'),
    'description' => t('Image links with \'rel="lightbox"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.'),
  );
  $filters['lightbox2_gd_filter'] = array(
    'title' => t('Lightbox GD filter'),
    'description' => t('Turns g2_filter links into Lightbox2 appropriate links'),
    'process callback' => '_lightbox2_process_filter',
  );
  $filters['lightbox_slideshow_filter'] = array(
    'title' => t('Lightbox slideshow filter'),
    'description' => t('Image links with \'rel="lightshow"\' in the &lt;a&gt; tag will appear in a Lightbox slideshow when clicked on.'),
  );
  $filters['lightbox_iframe_filter'] = array(
    'title' => t('Lightbox iframe filter'),
    'description' => t('Links to HTML content with \'rel="lightframe"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.'),
  );
  $filters['lightbox_video_filter'] = array(
    'title' => t('Lightbox video filter'),
    'description' => t('Links to video content with \'rel="lightvideo"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.'),
  );
  $filters['lightbox_modal_filter'] = array(
    'title' => t('Lightbox modal filter'),
    'description' => t('Links to inline or modal content with \'rel="lightmodal"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.'),
  );
  $filters['lightbox_disable_iframe_filter'] = array(
    'title' => t('Disable Lightbox iframe filter'),
    'description' => t('It\'s possible to show webpage content in the lightbox, using iframes.  In this case the "rel" attribute should be set to "lightframe".  However, users can do this without any filters to be enabled.  To prevent users from adding iframes to the site in this manner, then please enable this option.'),
    'process callback' => '_lightbox2_process_disable_filter',
  );
  return $filters;
}

/**
 * Provide links to the CSS stylesheet and JS file associated with
 * this module.
 */
function lightbox2_add_files() {
  global $language, $user;
  static $already_added = FALSE;
  if ($already_added) {
    return;

    // Don't add the JavaScript and CSS multiple times.
  }
  $already_added = TRUE;

  // Load required js and css files.
  $path = drupal_get_path('module', 'lightbox2');

  // Initialise some variables.
  $inline_image_handler = \Drupal::config('lightbox2.settings')
    ->get('lightbox2_inline');
  $flickr_image_handler = \Drupal::config('lightbox2.settings')
    ->get('lightbox2_flickr');
  $gallery2_block_handler = \Drupal::config('lightbox2.settings')
    ->get('lightbox2_gallery2_blocks');
  $image_assist_handler = \Drupal::config('lightbox2.settings')
    ->get('lightbox2_image_assist_custom');
  $image_node_handler = \Drupal::config('lightbox2.settings')
    ->get('lightbox2_image_node');
  $custom_class_handler = 0;
  switch (\Drupal::config('lightbox2.settings')
    ->get('lightbox2_custom_class_handler')) {
    case 1:
      $custom_class_handler = 'lightbox_ungrouped';
      break;
    case 2:
      $custom_class_handler = 'lightbox';
      break;
    case 3:
      $custom_class_handler = 'lightshow';
      break;
    case 4:
      $custom_class_handler = 'lightframe_ungrouped';
      break;
    case 5:
      $custom_class_handler = 'lightframe';
      break;
  }

  // Set the list of image classes to format urls for.
  $image_node_sizes = '';
  $trigger_lightbox_classes = '';
  $trigger_lightbox_group_classes = '';
  $trigger_slideshow_classes = '';
  $trigger_lightframe_classes = '';
  $trigger_lightframe_group_classes = '';

  // Inline module images.
  switch ($inline_image_handler) {
    case 1:
      $trigger_lightbox_classes .= 'img.inline,';
      break;
    case 2:
      $trigger_lightbox_group_classes .= 'img.inline,';
      break;
    case 3:
      $trigger_slideshow_classes .= 'img.inline,';
      break;
    case 4:
      $trigger_lightframe_classes .= 'img.inline,';
      break;
    case 5:
      $trigger_lightframe_group_classes .= 'img.inline,';
      break;
  }

  // Flickr images.
  switch ($flickr_image_handler) {
    case 1:
      $trigger_lightbox_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
      break;
    case 2:
      $trigger_lightbox_group_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
      break;
    case 3:
      $trigger_slideshow_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
      break;
    case 4:
      $trigger_lightframe_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
      break;
    case 5:
      $trigger_lightframe_group_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
      break;
  }

  // Gallery2 block images.
  switch ($gallery2_block_handler) {
    case 1:
      $trigger_lightbox_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
      break;
    case 2:
      $trigger_lightbox_group_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
      break;
    case 3:
      $trigger_slideshow_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
      break;
    case 4:
      $trigger_lightframe_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
      break;
    case 5:
      $trigger_lightframe_group_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
      break;
  }

  // Image Assist custom size images.
  switch ($image_assist_handler) {
    case 1:
      $trigger_lightbox_classes .= 'img.image-img_assist_custom,';
      break;
    case 2:
      $trigger_lightbox_group_classes .= 'img.image-img_assist_custom,';
      break;
    case 3:
      $trigger_slideshow_classes .= 'img.image-img_assist_custom,';
      break;
    case 4:
      $trigger_lightframe_classes .= 'img.image-img_assist_custom,';
      break;
    case 5:
      $trigger_lightframe_group_classes .= 'img.image-img_assist_custom,';
      break;
  }

  // Image nodes.
  if ($image_node_handler) {

    // @FIXME
    // Could not extract the default value because it is either indeterminate, or
    // not scalar. You'll need to provide a default value in
    // config/install/lightbox2.settings.yml and config/schema/lightbox2.schema.yml.
    $trigger_sizes = \Drupal::config('lightbox2.settings')
      ->get('lightbox2_trigger_image_size');
    usort($trigger_sizes, "sort_by_length");
    foreach ($trigger_sizes as $size) {
      $triggers = "img.{$size}, img.image-{$size},";
      if (empty($size)) {
        if (\Drupal::currentUser()
          ->hasPermission('view original images')) {
          $triggers = "img._original, img.image-_original,";
        }
      }
      else {
        $image_node_sizes .= "\\.{$size}|";
      }
      switch ($image_node_handler) {
        case 1:
          $trigger_lightbox_classes .= $triggers;
          break;
        case 2:
          $trigger_lightbox_group_classes .= $triggers;
          break;
        case 3:
          $trigger_slideshow_classes .= $triggers;
          break;
        case 4:
          $trigger_lightframe_classes .= $triggers;
          break;
        case 5:
          $trigger_lightframe_group_classes .= $triggers;
          break;
      }
    }
  }

  // Custom images.
  $custom_triggers = \Drupal::config('lightbox2.settings')
    ->get('lightbox2_custom_trigger_classes');
  $custom_trigger_classes = '';
  if ($custom_class_handler && !empty($custom_triggers)) {
    $trigger_classes = preg_split("/(\r\n|\n)/", $custom_triggers);
    foreach ($trigger_classes as $class) {
      if (!empty($class)) {
        $custom_trigger_classes .= "img.{$class},";
      }
    }
  }
  $trigger_lightbox_classes = rtrim($trigger_lightbox_classes, ",");
  $trigger_lightbox_group_classes = rtrim($trigger_lightbox_group_classes, ",");
  $trigger_slideshow_classes = rtrim($trigger_slideshow_classes, ",");
  $trigger_lightframe_classes = rtrim($trigger_lightframe_classes, ",");
  $trigger_lightframe_group_classes = rtrim($trigger_lightframe_group_classes, ",");
  $custom_trigger_classes = rtrim($custom_trigger_classes, ",");
  $image_node_sizes = '(' . rtrim($image_node_sizes, "|") . ')';
  $enable_video = \Drupal::config('lightbox2.settings')
    ->get('lightbox2_enable_video');
  $enable_login = $user->uid == 0 && \Drupal::config('lightbox2.settings')
    ->get('lightbox2_enable_login');
  $enable_contact = \Drupal::moduleHandler()
    ->moduleExists('contact') && \Drupal::config('lightbox2.settings')
    ->get('lightbox2_enable_contact') && \Drupal::currentUser()
    ->hasPermission('access site-wide contact form');
  $display_image_size = \Drupal::config('lightbox2.settings')
    ->get('lightbox2_display_image_size');
  if ($display_image_size == 'original' && \Drupal::currentUser()
    ->hasPermission('view original images')) {
    $display_image_size = '';
  }
  $font_color = \Drupal::config('lightbox2.settings')
    ->get('lightbox2_font_color');
  $box_color = \Drupal::config('lightbox2.settings')
    ->get('lightbox2_box_color');
  $file_path = base_path() . '(\\w\\w/)' . file_default_scheme() . ':/';

  // @FIXME
  // // @FIXME
  // // This looks like another module's variable. You'll need to rewrite this call
  // // to ensure that it uses the correct configuration object.
  // if ( variable_get('file_downloads', 'FILE_DOWNLOADS_PUBLIC') == 'FILE_DOWNLOADS_PRIVATE' ) {
  //     $file_path = base_path() . '(\w\w/)system/files';
  //   }
  // Load the javascript settings.
  $js_settings = array(
    'rtl' => $language->direction,
    'file_path' => $file_path,
    'default_image' => base_path() . $path . '/images/brokenimage.jpg',
    'border_size' => (int) \Drupal::config('lightbox2.settings')
      ->get('lightbox2_border_size'),
    'font_color' => !empty($font_color) ? $font_color : '000',
    'box_color' => !empty($box_color) ? $box_color : '000',
    'top_position' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_top_position'),
    'overlay_opacity' => str_replace(',', '.', \Drupal::config('lightbox2.settings')
      ->get('lightbox2_overlay_opacity')),
    'overlay_color' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_overlay_color'),
    'disable_close_click' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_disable_close_click'),
    'resize_sequence' => (int) \Drupal::config('lightbox2.settings')
      ->get('lightbox2_resize_sequence'),
    'resize_speed' => 1000 * str_replace(',', '.', \Drupal::config('lightbox2.settings')
      ->get('lightbox2_resize_speed')),
    'fade_in_speed' => 1000 * str_replace(',', '.', \Drupal::config('lightbox2.settings')
      ->get('lightbox2_fadein_speed')),
    'slide_down_speed' => 1000 * str_replace(',', '.', \Drupal::config('lightbox2.settings')
      ->get('lightbox2_slidedown_speed')),
    'use_alt_layout' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_use_alt_layout'),
    'disable_resize' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_disable_resize'),
    'disable_zoom' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_disable_zoom'),
    'force_show_nav' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_force_show_nav'),
    'show_caption' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_show_caption'),
    'loop_items' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_loop_items'),
    'node_link_text' => \Drupal\Component\Utility\Html::escape(\Drupal::config('lightbox2.settings')
      ->get('lightbox2_node_link_text')),
    'node_link_target' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_node_link_target'),
    'image_count' => \Drupal\Component\Utility\Html::escape(\Drupal::config('lightbox2.settings')
      ->get('lightbox2_image_count_str')),
    'video_count' => \Drupal\Component\Utility\Html::escape(\Drupal::config('lightbox2.settings')
      ->get('lightbox2_video_count_str')),
    'page_count' => \Drupal\Component\Utility\Html::escape(\Drupal::config('lightbox2.settings')
      ->get('lightbox2_page_count_str')),
    'lite_press_x_close' => t('press !x to close', array(
      '!x' => '<a href="#" onclick="hideLightbox(); return FALSE;"><kbd>x</kbd></a>',
    )),
    'download_link_text' => '',
    'enable_login' => $enable_login,
    'enable_contact' => $enable_contact,
    // Automatic image handling settings.
    'keys_close' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_keys_close'),
    'keys_previous' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_keys_previous'),
    'keys_next' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_keys_next'),
    'keys_zoom' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_keys_zoom'),
    'keys_play_pause' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_keys_play_pause'),
    'display_image_size' => $display_image_size,
    'image_node_sizes' => $image_node_sizes,
    'trigger_lightbox_classes' => $trigger_lightbox_classes,
    'trigger_lightbox_group_classes' => $trigger_lightbox_group_classes,
    'trigger_slideshow_classes' => $trigger_slideshow_classes,
    'trigger_lightframe_classes' => $trigger_lightframe_classes,
    'trigger_lightframe_group_classes' => $trigger_lightframe_group_classes,
    'custom_class_handler' => $custom_class_handler,
    'custom_trigger_classes' => $custom_trigger_classes,
    'disable_for_gallery_lists' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_disable_nested_galleries'),
    'disable_for_acidfree_gallery_lists' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_disable_nested_acidfree_galleries'),
    'enable_acidfree_videos' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_enable_acidfree_videos'),
    // Slideshow settings.
    'slideshow_interval' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_slideshow_interval') * 1000,
    'slideshow_automatic_start' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_slideshow_automatic_start'),
    'slideshow_automatic_exit' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_slideshow_automatic_exit'),
    'show_play_pause' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_slideshow_show_play_pause'),
    'pause_on_next_click' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_slideshow_pause_on_next_click'),
    'pause_on_previous_click' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_slideshow_pause_on_previous_click'),
    'loop_slides' => \Drupal::config('lightbox2.settings')
      ->get('lightbox2_loop_slides'),
    // Iframe settings.
    'iframe_width' => (int) \Drupal::config('lightbox2.settings')
      ->get('lightbox2_default_frame_width'),
    'iframe_height' => (int) \Drupal::config('lightbox2.settings')
      ->get('lightbox2_default_frame_height'),
    'iframe_border' => (int) \Drupal::config('lightbox2.settings')
      ->get('lightbox2_frame_border'),
    // Video settings.
    'enable_video' => $enable_video,
    'useragent' => $_SERVER['HTTP_USER_AGENT'],
  );
  if ($enable_video) {

    // @FIXME
    // url() expects a route name or an external URI.
    // $js_settings['flvPlayer'] = url(\Drupal\Component\Utility\Html::escape(trim(variable_get('lightbox2_flv_player_path', 'flvplayer.swf'), '/')));
    $js_settings['flvFlashvars'] = \Drupal\Component\Utility\Html::escape(\Drupal::config('lightbox2.settings')
      ->get('lightbox2_flv_player_flashvars'));
  }

  // Only supply these if the user has the correct permissions.
  if (\Drupal::currentUser()
    ->hasPermission('download original image') && \Drupal::currentUser()
    ->hasPermission('view original images')) {
    $js_settings['download_link_text'] = \Drupal\Component\Utility\Html::escape(\Drupal::config('lightbox2.settings')
      ->get('lightbox2_download_link_text'));
  }

  // @FIXME
  // The Assets API has totally changed. CSS, JavaScript, and libraries are now
  // attached directly to render arrays using the #attached property.
  //
  //
  // @see https://www.drupal.org/node/2169605
  // @see https://www.drupal.org/node/2408597
  // drupal_add_js(array('lightbox2' => $js_settings), array( 'type' => 'setting' ) );
  // Check where we should load the javascript files - header or footer.
  $js_location = \Drupal::config('lightbox2.settings')
    ->get('lightbox2_js_location');

  // Lightbox2 Plus.
  if (!\Drupal::config('lightbox2.settings')
    ->get('lightbox2_lite')) {
    $css = $path . '/css/lightbox.css';
    if (\Drupal::config('lightbox2.settings')
      ->get('lightbox2_use_alt_layout')) {
      $css = $path . '/css/lightbox_alt.css';
    }

    // @FIXME
    // The Assets API has totally changed. CSS, JavaScript, and libraries are now
    // attached directly to render arrays using the #attached property.
    //
    //
    // @see https://www.drupal.org/node/2169605
    // @see https://www.drupal.org/node/2408597
    // drupal_add_css($css);
    // Check to see if any automatic image handling options are enabled.
    if ($image_node_handler || $flickr_image_handler || $gallery2_block_handler || $inline_image_handler || $image_assist_handler || $custom_triggers != '') {

      // @FIXME
      // The Assets API has totally changed. CSS, JavaScript, and libraries are now
      // attached directly to render arrays using the #attached property.
      //
      //
      // @see https://www.drupal.org/node/2169605
      // @see https://www.drupal.org/node/2408597
      // drupal_add_js($path . '/js/auto_image_handling.js', array( 'scope' => $js_location ) );
    }
    if (\Drupal::config('lightbox2.settings')
      ->get('lightbox2_enable_video')) {

      // @FIXME
      // The Assets API has totally changed. CSS, JavaScript, and libraries are now
      // attached directly to render arrays using the #attached property.
      //
      //
      // @see https://www.drupal.org/node/2169605
      // @see https://www.drupal.org/node/2408597
      // drupal_add_js($path . '/js/lightbox_video.js', array( 'scope' => $js_location ) );
    }
    if ($enable_login || $enable_contact) {

      // @FIXME
      // The Assets API has totally changed. CSS, JavaScript, and libraries are now
      // attached directly to render arrays using the #attached property.
      //
      //
      // @see https://www.drupal.org/node/2169605
      // @see https://www.drupal.org/node/2408597
      // drupal_add_js($path . '/js/lightbox_modal.js', array( 'scope' => $js_location ) );
    }

    //drupal_add_js($path .'/js/prototype.js', array( 'scope' => $js_location, 'cache' => false ) );

    //drupal_add_js($path .'/js/scriptaculous.js', array( 'scope' => $js_location, 'cache' => false ) );

    // @FIXME
    // The Assets API has totally changed. CSS, JavaScript, and libraries are now
    // attached directly to render arrays using the #attached property.
    //
    //
    // @see https://www.drupal.org/node/2169605
    // @see https://www.drupal.org/node/2408597
    // drupal_add_js($path . '/js/lightbox.js', array( 'scope' => $js_location));
  }
  else {
    $css = $path . '/css/lightbox_lite.css';

    // @FIXME
    // The Assets API has totally changed. CSS, JavaScript, and libraries are now
    // attached directly to render arrays using the #attached property.
    //
    //
    // @see https://www.drupal.org/node/2169605
    // @see https://www.drupal.org/node/2408597
    // drupal_add_css($css);
    // @FIXME
    // The Assets API has totally changed. CSS, JavaScript, and libraries are now
    // attached directly to render arrays using the #attached property.
    //
    //
    // @see https://www.drupal.org/node/2169605
    // @see https://www.drupal.org/node/2408597
    // drupal_add_js($path . '/js/lightbox_lite.js', array( 'scope' => $js_location ) );
  }
}

/**
 * Helper function for image styles.
 */
function lightbox2_image_styles() {
  $image_styles = array(
    '0' => 'original',
  );
  $tmp = image_styles();
  foreach ($tmp as $style) {
    $image_styles[$style['name']] = $style['name'];
  }
  return $image_styles;
}

/**
 * Helper function for possible fields to display as the caption.
 */
function lightbox2_image_fields() {
  $fields = array(
    'hidden' => t('Hidden'),
    'title' => t('File title'),
    'filename' => t('Filename'),
  );
  foreach (field_info_instances("file", "image") as $field) {
    $fields[$field['field_name']] = $field['label'];
  }
  return $fields;
}

/**
 * Helper function for possible lightbox styles.
 */
function lightbox2_lightbox_types() {
  return array(
    'lightbox' => t('Single lightbox'),
    'lightshow' => t('Lightshow'),
  );
}

/**
 * Implements hook_field_formatter_settings_form().
 */
function lightbox2_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $form = array();
  $form['type'] = array(
    '#title' => t('Lightbox type'),
    '#type' => 'select',
    '#options' => lightbox2_lightbox_types(),
    '#default_value' => $settings['type'],
  );
  $form['image_style'] = array(
    '#title' => t('Image style'),
    '#description' => t('The thumbnail to display as a link for the lightbox.'),
    '#type' => 'select',
    '#options' => lightbox2_image_styles(),
    '#default_value' => $settings['image_style'],
  );
  $form['lightbox_style'] = array(
    '#title' => t('Lightbox style'),
    '#description' => t('The image style to show inside the lightbox.'),
    '#type' => 'select',
    '#options' => lightbox2_image_styles(),
    '#default_value' => $settings['lightbox_style'],
  );
  $form['caption'] = array(
    '#title' => t('Caption field'),
    '#description' => t('The field to use as a caption.'),
    '#type' => 'select',
    '#options' => lightbox2_image_fields(),
    '#default_value' => $settings['caption'],
  );
  return $form;
}

/**
 * Implements hook_field_formatter_settings_summary().
 */
function lightbox2_field_formatter_settings_summary($field, $instance, $view_mode) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $image_styles = lightbox2_image_styles();
  $fields = lightbox2_image_fields();
  $types = lightbox2_lightbox_types();
  $summary = '';
  if (isset($settings['caption']) && isset($settings['type']) && isset($settings['image_style']) && isset($settings['lightbox_style'])) {
    $summary .= '<strong>' . t('Caption field') . '</strong>: ' . $fields[$settings['caption']] . '<br/>';
    $summary .= '<strong>' . t('Display') . '</strong>: ';
    $summary .= $types[$settings['type']];
    $summary .= ': ';
    $summary .= $image_styles[$settings['image_style']];
    $summary .= ' => ';
    $summary .= $image_styles[$settings['lightbox_style']];
  }
  else {
    $summary = 'Title - Lightbox: original => original';
  }
  return $summary;
}

/**
 * Implementation of hook_field_formatter_info().
 *
 * Add certain lightbox and imagecache formatters to CCK image fields if
 * the imagefield.module and the imagecache.module exist.  Add additional
 * formatters if emfield, emimage and/or emvideo modules exist.
 */
function lightbox2_field_formatter_info() {
  $formatters = array();
  if (\Drupal::moduleHandler()
    ->moduleExists('image')) {
    $formatters['lightbox2'] = array(
      'label' => 'Lightbox2',
      'field types' => array(
        'image',
      ),
      'settings' => array(
        'type' => 'lightbox',
        'image_style' => 'original',
        'lightbox_style' => 'original',
        'caption' => 'hidden',
      ),
    );
  }
  return $formatters;

  /*
  // Handle imagefield and filefield images.
  if (module_exists('image')) {
  	$rules = array();
    if (function_exists('image_styles')) {
      $presets = image_styles();
      foreach ($presets as $preset_id => $preset_info) {
        $rules[$preset_id] = $preset_info['name'];
      }
    }
    $iframe['image__lightframe2__original__node'] = array(
      'label' => 'Lightbox2 iframe: original->node page',
      'field types' => array('image', 'file'),
    );
    $iframe['imagefield__lightframe2__link__node'] = array(
      'label' => 'Lightbox2 iframe: link->node page',
      'field types' => array('image', 'file'),
    );
    foreach ($rules as $view_rule) {
      $lightbox['image__lightbox2__original__'. $view_rule] = array(
        'label' => 'Lightbox2: original->'. $view_rule,
        'field types' => array('image', 'file'),
      );
      $lightbox['imagefield__lightbox2_compact__original__'. $view_rule] = array(
        'label' => 'Lightbox2: original->'. $view_rule . ' compact',
        'field types' => array('image', 'file'),
      );
      $lightbox['image__lightbox2__'. $view_rule .'__original'] = array(
        'label' => 'Lightbox2: '. $view_rule .'->original',
        'field types' => array('image', 'file'),
      );
      $lightbox['imagefield__lightbox2_compact__'. $view_rule .'__original'] = array(
        'label' => 'Lightbox2: '. $view_rule .'->original compact',
        'field types' => array('image', 'file'),
      );
      $lightbox['imagefield__lightbox2__link__'. $view_rule] = array(
        'label' => 'Lightbox2: link->'. $view_rule,
        'field types' => array('image', 'file'),
      );
      $slideshow['image__lightshow2__original__'. $view_rule] = array(
        'label' => 'Lightbox2 slideshow: original->'. $view_rule,
        'field types' => array('image', 'file'),
      );
      $slideshow['imagefield__lightshow2_compact__original__'. $view_rule] = array(
        'label' => 'Lightbox2 slideshow: original->'. $view_rule . ' compact',
        'field types' => array('image', 'filefield'),
      );
      $slideshow['image__lightshow2__'. $view_rule .'__original'] = array(
        'label' => 'Lightbox2 slideshow: '. $view_rule .'->original',
        'field types' => array('image', 'file'),
      );
      $slideshow['imagefield__lightshow2_compact__'. $view_rule .'__original'] = array(
        'label' => 'Lightbox2 slideshow: '. $view_rule .'->original compact',
        'field types' => array('image', 'filefield'),
      );
      $slideshow['imagefield__lightshow2__link__'. $view_rule] = array(
        'label' => 'Lightbox2 slideshow: link->'. $view_rule,
        'field types' => array('image', 'filefield'),
      );
      $iframe['image__lightframe2__'. $view_rule .'__node'] = array(
        'label' => 'Lightbox2 iframe: '. $view_rule .'->node page',
        'field types' => array('image', 'file'),
      );
  	foreach ($rules as $lightbox_rule) {
        $lightbox['image__lightbox2__'. $view_rule .'__'. $lightbox_rule] = array(
  	 'label' => 'Lightbox2: '. $view_rule .'->'. $lightbox_rule,
          'field types' => array('image', 'file'),
        );
        $lightbox['imagefield__lightbox2_compact__'. $view_rule .'__'. $lightbox_rule] = array(
          'label' => 'Lightbox2: '. $view_rule .'->'. $lightbox_rule . ' compact',
          'field types' => array('image', 'filefield'),
        );
        $slideshow['image__lightshow2__'. $view_rule .'__'. $lightbox_rule] = array(
          'label' => 'Lightbox2 slideshow: '. $view_rule .'->'. $lightbox_rule,
          'field types' => array('image', 'file'),
        );
        $slideshow['imagefield__lightshow2_compact__'. $view_rule .'__'. $lightbox_rule] = array(
          'label' => 'Lightbox2 slideshow: '. $view_rule .'->'. $lightbox_rule . ' compact',
          'field types' => array('image', 'filefield'),
        );
      }
    }
    // Adding them now so they are in some sort of sensible order.
    $formatters = array_merge($lightbox, $slideshow, $iframe);
  }
  if (module_exists('emfield') && module_exists('emimage')) {
    $formatters['emimage_lightbox2'] = array(
      'label' => t('Lightbox2: Image Thumbnail -> Original'),
      'field types' => array('emimage'),
    );
    $formatters['emimage_lightshow2'] = array(
      'label' => t('Lightbox2 slideshow: Image Thumbnail -> Original'),
      'field types' => array('emimage'),
    );
    $formatters['emimage_lightframe2'] = array(
      'label' => t('Lightbox2 iframe: Image Thumbnail -> Content'),
      'field types' => array('emimage'),
    );
  }
  if (variable_get('lightbox2_enable_video', FALSE) && module_exists('emfield') && module_exists('emvideo')) {
    $formatters['emvideo_lightvideo'] = array(
      'label' => t('Lightbox2: Image Thumbnail -> Full Size Video'),
      'field types' => array('emvideo'),
    );
  }
  if (module_exists('file')) {
    $formatters['file_lightframe'] = array(
      'label' => t('Lightbox2 iframe'),
      'field types' => array('file'),
    );
  }
  */
}

/**
 * Implements hook_field_formatter_view().
 * 
 * Temporarily a (pretty much) straight copy of image's
 */
function lightbox2_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display["settings"];
  $lightbox_type = $settings['type'];
  $image_style = $settings['image_style'];
  $lightbox_style = $settings['lightbox_style'];
  if ($image_style == 'original') {
    $image_style = NULL;
  }
  if ($lightbox_style == 'original') {
    $lightbox_style = NULL;
  }
  $wrapper = entity_metadata_wrapper($entity_type, $entity);
  foreach ($items as $delta => $item) {
    $uri = array(
      'path' => file_create_url($item['uri']),
      'options' => array(),
    );
    $element[$delta] = array(
      '#theme' => 'lightbox2_image',
      '#item' => $item,
      '#lightbox_type' => $lightbox_type,
      '#image_style' => $image_style,
      '#lightbox_style' => $lightbox_style,
      '#path' => $uri,
      '#node_id' => $wrapper
        ->getIdentifier(),
      '#field_name' => $field['field_name'],
      '#caption' => $settings['caption'],
    );
  }
  return $element;

  /*$element = array();

    // Check if the formatter involves a particular image style.
    //$matches = array();
    //if (preg_match('/__([a-z0-9_]+)/', $display['type'], $matches)) {
    //  $image_style = $matches[1];
    //}

    $pieces = explode('__', $display);
    $image_style = $pieces[2];
    // Temporary hardcoding link_file and image_style for debugging
    //$image_style = 'thumbnail';
    $link_file = TRUE;

    foreach ($items as $delta => $item) {
      if (isset($link_file)) {
        $uri = array(
          'path' => file_create_url($item['uri']),
          'options' => array(),
        );
      }
      $element[$delta] = array(
        '#theme' => 'lightbox2_image',
        '#item' => $item,
        '#image_style' => isset($image_style) ? $image_style : '',
        '#path' => isset($uri) ? $uri : '',
      );
    }

    return $element;*/
}

/**
 * Implementation of hook_theme().
 */
function lightbox2_theme($existing, $type, $theme, $path) {
  $theme = array();
  $theme['lightbox2_image'] = array(
    'variables' => array(
      'item' => NULL,
      'path' => NULL,
      'lightbox_type' => NULL,
      'image_style' => NULL,
      'lightbox_style' => NULL,
      'node_id' => NULL,
      'field_name' => NULL,
      'caption' => NULL,
    ),
  );

  //return($theme);

  /*
    $theme = array(
      'lightbox2_image' => array(
      'variables' => array(
       'item' => NULL,
       'path' => NULL,
       'image_style' => NULL
       ),
      ),
      // Emfield theme functions.
      'lightbox2_emimage' => array(
        'variables' => array(
          'field' => NULL,
          'item' => NULL,
          'formatter' => NULL,
          'node' => NULL,
          'args' => array()
        ),
      ),
      'lightbox2_formatter_emimage' => array(
        'render element' => 'element',
      ),
      'lightbox2_formatter_emimage_lightbox2' => array(
        'render element' => 'element',
        'function' => 'theme_lightbox2_formatter_emimage',
      ),
      'lightbox2_formatter_emimage_lightshow2' => array(
        'render element' => 'element',
        'function' => 'theme_lightbox2_formatter_emimage',
      ),
      'lightbox2_formatter_emimage_lightframe2' => array(
        'render element' => 'element',
        'function' => 'theme_lightbox2_formatter_emimage',
      ),
      'lightbox2_formatter_emvideo_lightvideo' => array(
        'render element' => 'element',
      ),
      'lightbox2_emvideo' => array(
        'variables' => array(
          'field' => NULL,
          'item' => NULL,
          'formatter' => NULL,
          'node' => NULL
        ),
      ),
      // Filefield theme functions.
      'lightbox2_formatter_filefield_lightframe' => array(
        'render element' => 'element',
      ),
      'lightbox2_file_formatter_lightbox2_iframe' => array(
        'variables' => array(
          'file' => NULL,
          'field' => NULL,
          'file_formatter_settings' => NULL
  	  ),
      ),
      // Global imagecache + imagefield theme functions.
      'lightbox2_formatter_imagefield' => array(
         'render element' => 'element',
      ),
      'imagefield_image_imagecache_lightbox2' => array(
        'variables' => array(
          'view_preset' => NULL,
          'field_name' => NULL,
          'item' => NULL,
          'node' => NULL,
          'rel' => 'lightbox',
          'args' => array()
        ),
      ),
    );

     // Additional imagecache + imagefield theme functions, by preset.
    if (module_exists("image")) {

      $theme['lightbox2_formatter_imagefield__lightframe2__original__node'] = array(
        'render element' => 'element',
        'function' => 'theme_lightbox2_formatter_imagefield',
      );
      $theme['lightbox2_formatter_imagefield__lightframe2__link__node'] = array(
        'arguments' => array('element' => NULL),
        'function' => 'theme_lightbox2_formatter_imagefield',
        'file' => 'lightbox2.formatter.inc',
      );

      foreach (image_styles() as $src) {
        $theme['lightbox2_formatter_imagefield__lightbox2__'. $src['name'] .'__original'] = array(
          'render element' => 'element',
          'function' => 'theme_lightbox2_formatter_imagefield',
          'file' => 'lightbox2.formatter.inc',
        );
        $theme['lightbox2_formatter_imagefield__lightbox2_compact__'. $src['name'] .'__original'] = array(
          'arguments' => array('element' => NULL),
          'function' => 'theme_lightbox2_formatter_imagefield',
          'file' => 'lightbox2.formatter.inc',
        );
        $theme['lightbox2_formatter_imagefield__lightshow2__'. $src['name'] .'__original'] = array(
          'render element' => 'element',
          'function' => 'theme_lightbox2_formatter_imagefield',
        );
        $theme['lightbox2_formatter_imagefield__lightshow2_compact__'. $src['name'] .'__original'] = array(
          'arguments' => array('element' => NULL),
          'function' => 'theme_lightbox2_formatter_imagefield',
          'file' => 'lightbox2.formatter.inc',
        );
        $theme['lightbox2_formatter_imagefield__lightbox2__original__'. $src['name']] = array(
          'render element' => 'element',
          'function' => 'theme_lightbox2_formatter_imagefield',
        );
        $theme['lightbox2_formatter_imagefield__lightbox2_compact__original__'. $src['name']] = array(
          'arguments' => array('element' => NULL),
          'function' => 'theme_lightbox2_formatter_imagefield',
          'file' => 'lightbox2.formatter.inc',
        );
      	$theme['lightbox2_formatter_imagefield__lightshow2__original__'. $src['name']] = array(
          'render element' => 'element',
          'function' => 'theme_lightbox2_formatter_imagefield',

        );
        $theme['lightbox2_formatter_imagefield__lightshow2_compact__original__'. $src['name']] = array(
          'arguments' => array('element' => NULL),
          'function' => 'theme_lightbox2_formatter_imagefield',
          'file' => 'lightbox2.formatter.inc',
        );
        $theme['lightbox2_formatter_imagefield__lightframe2__'. $src['name'] .'__node'] = array(
          'render element' => 'element',
          'function' => 'theme_lightbox2_formatter_imagefield',
        );
        $theme['lightbox2_formatter_imagefield__lightbox2__link__'. $src['name']] = array(
          'arguments' => array('element' => NULL),
          'function' => 'theme_lightbox2_formatter_imagefield',
          'file' => 'lightbox2.formatter.inc',
        );
        $theme['lightbox2_formatter_imagefield__lightshow2__link__'. $src['name']] = array(
          'arguments' => array('element' => NULL),
          'function' => 'theme_lightbox2_formatter_imagefield',
          'file' => 'lightbox2.formatter.inc',
        );

        foreach (image_styles() as $dest) {
          $theme['lightbox2_formatter_imagefield__lightbox2__'. $src['name'] .'__'. $dest['name']] = array(
            'render element' => 'element',
            'function' => 'theme_lightbox2_formatter_imagefield',
          );
          $theme['lightbox2_formatter_imagefield__lightbox2_compact__'. $src['name'] .'__'. $dest['name']] = array(
            'arguments' => array('element' => NULL),
            'function' => 'theme_lightbox2_formatter_imagefield',
            'file' => 'lightbox2.formatter.inc',
          );
          $theme['lightbox2_formatter_imagefield__lightshow2__'. $src['name'] .'__'. $dest['name']] = array(
            'render element' => 'element',
            'function' => 'theme_lightbox2_formatter_imagefield',
          );
          $theme['lightbox2_formatter_imagefield__lightshow2_compact__'. $src['name'] .'__'. $dest['name']] = array(
            'arguments' => array('element' => NULL),
            'function' => 'theme_lightbox2_formatter_imagefield',
            'file' => 'lightbox2.formatter.inc',
          );
        }
      }
    }

    // Additional Insert theme functions.
    if (module_exists('insert')) {
      // Theme functions in lightbox2.insert.inc.
      $theme['lightbox2_insert_image'] = array(
        'arguments' => array('item' => NULL, 'widget' => NULL, 'type' => NULL, 'image_preset_name' => NULL, 'link_preset_name' => NULL),
        'template' => 'lightbox2-insert-image',
      );
    }*/
  foreach ($theme as &$array) {
    $array['file'] = 'lightbox2.formatter.inc';
  }
  return $theme;
}

/**
 * Configures settings and outputs the video.
 *
 * @param nid
 *   The node id.
 * @param width
 *   The lightbox video width.
 * @param height
 *   The lightbox video height.
 * @param field_name
 *   The name of the cck field the video is contained in.
 * @param provider
 *   The name of the 3rd party video provider.
 * @param id
 *   The video id.
 */

/*
function lightbox2_emvideo($node, $width, $height, $field_name, $provider, $id) {
  $field = content_fields($field_name);
  $field['widget']['video_width'] = $width;
  $field['widget']['video_height'] = $height;
  $field['widget']['video_autoplay'] = 1;
  if (!content_access('view', $field, NULL, $node)) {
    drupal_access_denied();
    return;
  }

  $items = $node->$field_name;
  if (is_array($items)) {
    foreach ($items as $item) {
      if ($item['provider'] == $provider && $item['value'] == $id) {
        break;
      }
    }
  }
  print theme('emvideo_video_video', $field, $item, 'video_video', $node);
}*/

/**
 * Return TRUE if current path is disabled for lightbox according to
 * lightbox2_page_list and lightbox2_page_init_action.
 */
function lightbox2_exclude_these_paths() {
  $action = \Drupal::config('lightbox2.settings')
    ->get('lightbox2_page_init_action');
  $page_list = \Drupal::config('lightbox2.settings')
    ->get('lightbox2_page_list');
  if (!empty($page_list)) {

    // Retrieve Drupal alias for the current path (if exists).
    $alias = drupal_get_path_alias($_GET['q']);
    if (drupal_match_path($_GET['q'], $page_list) || drupal_match_path($alias, $page_list)) {
      return $action == 'page_disable' ? 1 : 0;
    }
  }
  return $action == 'page_disable' ? 0 : 1;
}

/**
 * Preprocess function for template by theme('page').
 */
function lightbox2_preprocess_page(&$variables) {
  if (arg(0) != 'node' || arg(2) != 'lightbox2') {
    return;
  }

  //Overwrite template_preprocess_page() region settings.
  $theme = \Drupal::theme()
    ->getActiveTheme()
    ->getName();

  // Retrieve all block regions.
  $regions = system_region_list($theme);

  // Remove all region content assigned via blocks.
  foreach (array_keys($regions) as $region) {
    if ($region != 'content') {
      $variables[$region] = NULL;
    }
  }

  // Set up layout variable to none.
  $variables['layout'] = 'none';

  //additional template files for e.g. page-node-lightbox.tpl.php are allready implemented through template_preprocess_page()
}

/**
 * Display the video object.
 *
 * Displays the video object for a specified nid.  It is used for displaying
 * videos in acidfree lists in a lightbox when the thumbnail is clicked on.  It
 * is only triggered for the url 'node/%nid/lightframevideo'.
 *
 * @param $node
 *   The $node object.
 */

/*
function lightbox2_acidfree_video($node) {
print theme('video_player', array( 'node' => $node ) );
}
*/

/**
 * Implementation of filefield's hook_file_formatter_info().
 */
function lightbox2_file_formatter_info() {
  return array(
    'lightbox2_iframe' => array(
      'suitability callback' => 'lightbox2_check_filefield_extension',
      'label' => t('Lightbox2 iframe'),
      'description' => t('Displays all kinds of files in a popup lightbox in an iframe.'),
    ),
    'lightbox2_image' => array(
      'suitability callback' => 'lightbox2_check_filefield_image_extension',
      'label' => t('Lightbox2 image'),
      'description' => t('Displays image files in a popup lightbox.'),
    ),
  );
}

/**
 * Suitability callback function for the filefield formatter.
 *
 * @param $file
 *   The file object, containing filepath, mime type, etc.
 * @param $field
 *   CCK field information.
 * @return
 *   True if file extension is supported.
 */
function lightbox2_check_filefield_extension($file, $field) {
  $ext = array_pop(explode('.', $file->filename));
  return lightbox2_supported_file_extension($ext);
}

/**
 * Suitability callback function for the image filefield formatter.
 *
 * @param $file
 *   The file object, containing filepath, mime type, etc.
 * @param $field
 *   CCK field information.
 * @return
 *   True if file extension is supported.
 */
function lightbox2_check_filefield_image_extension($file, $field) {
  $ext = array_pop(explode('.', $file->filename));
  return lightbox2_supported_file_extension($ext, 'image');
}

/**
 * Check whether a given file extension is supported by the lightbox iframe.
 *
 * @param $ext
 *   File extension
 * @param $type
 *   Type of file extensions to check.
 * @return
 *   TRUE if extension is supported.
 */
function lightbox2_supported_file_extension($ext, $type = 'all') {
  $image_extensions = array(
    'png',
    'jpg',
    'jpeg',
    'gif',
    'bmp',
  );
  $movie_extensions = array(
    'dv',
    'mov',
    'moov',
    'movie',
    'mp4',
    'asf',
    'wm',
    'wmv',
    'avi',
    'mpg',
    'mpeg',
  );
  $web_extensions = array(
    'asp',
    'aspx',
    'cgi',
    'cfm',
    'htm',
    'html',
    'pl',
    'php',
    'php3',
    'php4',
    'php5',
    'phtml',
    'rb',
    'rhtml',
    'shtml',
    'txt',
    'vbs',
  );
  $misc_extensions = array(
    'pdf',
  );
  $extensions = array();
  switch ($type) {
    case 'image':
      $extensions = $image_extensions;
      break;
    case 'movie':
      $extensions = $movie_extensions;
      break;
    case 'web':
      $extensions = $web_extensions;
      break;
    case 'misc':
      $extensions = $misc_extensions;
      break;
    case 'all':
    default:
      $extensions = array_merge($image_extensions, $movie_extensions, $web_extensions, $misc_extensions);
      break;
  }
  if (in_array(\Drupal\Component\Utility\Unicode::strtolower($ext), $extensions)) {
    return TRUE;
  }
  return FALSE;
}

/**
 * Helper function to compare the string length of two items.  Used when trying
 * to sort an array by value length.
 *
 * @param $a
 *   String to compare.
 * @param $b
 *   String to compare.
 * @return
 *   0 if they are the same length, -1 if $a is longer than $b, 1 otherwise.
 */
function sort_by_length($a, $b) {
  if ($a == $b) {
    return 0;
  }
  return \Drupal\Component\Utility\Unicode::strlen($a) > \Drupal\Component\Utility\Unicode::strlen($b) ? -1 : 1;
}

/**
 * Get the user login form.
 */
function lightbox2_login() {

  // do not use lightbox2 for failed validation ie: bad password
  // instead, return the fully rendered Drupal page with errors.
  if (count($_POST)) {
    return \Drupal::formBuilder()
      ->getForm('user_login_block');
  }
  else {
    print \Drupal::service("renderer")
      ->render(\Drupal::formBuilder()
      ->getForm('user_login_block'));

    // If the OpenID module is enabled, the javascript and css may not exist
    // on the page, so add them dynamically.
    if (\Drupal::moduleHandler()
      ->moduleExists('openid')) {
      $path = drupal_get_path('module', 'openid');
      $js_file = base_path() . $path . '/openid.js';
      $css_file = base_path() . $path . '/openid.css';

      // Load the javascript dynamically.
      print '<script type="text/javascript">$.getScript("' . $js_file . '", function () {if ($.isFunction(Drupal.behaviors.openid)) { Drupal.behaviors.openid(document); } });</script>';

      // Load the css file dynamically.
      print '<script type="text/javascript">
        var fileref=document.createElement("link");
        fileref.setAttribute("rel", "stylesheet");
        fileref.setAttribute("type", "text/css");
        fileref.setAttribute("href", "' . $css_file . '");
        document.getElementsByTagName("head")[0].appendChild(fileref);
        </script>';
    }

    // drupal_add_js() with 'inline' didn't seem to work, possibly because this is
    // AJAX loaded content.
    print '<script type="text/javascript">Drupal.attachBehaviors();</script>';
  }
  exit;
}

/**
 * Get the contact form.
 */
function lightbox2_contact() {
  if (\Drupal::moduleHandler()
    ->moduleExists('contact') && \Drupal::config('lightbox2.settings')
    ->get('lightbox2_enable_contact') && \Drupal::currentUser()
    ->hasPermission('access site-wide contact form')) {
    $path = drupal_get_path('module', 'contact');
    include_once $path . '/contact.pages.inc';
    print \Drupal::service("renderer")
      ->render(\Drupal::formBuilder()
      ->getForm('contact_site_form'));

    // drupal_add_js() with 'inline' didn't seem to work, possibly because this is
    // AJAX loaded content.
    print '<script type="text/javascript">Drupal.attachBehaviors();</script>';
    exit;
  }
}

/**
 * Implementation of hook_form_alter().
 *
 * Update the page action and input size.
 *
 * @param &$form
 *   General reference used in drupal, defining the structure & the fields of
 *   a form.
 * @param $form_state
 *   General variable, used to control the processing of the form.
 * @param $form_id
 *   The default is "user_login_block"; hold the page where the function is being
 *   used.
 * @return
 *   Return the structure of the form.
 */
function lightbox2_form_user_login_block_alter(&$form, $form_state, $form_id = "user_login_block") {
  if ($form_id == 'user_login_block' && arg(0) == 'user' && arg(1) == 'login' && arg(2) == 'lightbox2') {

    // @FIXME
    // url() expects a route name or an external URI.
    // $form['#action'] = url('user/login/lightbox2', array('query' => array('destination' => $_GET['destination'])));
  }
}
function lightbox2_form_contact_site_form_alter(&$form, $form_state, $form_id = "contact_site_form") {
  if ($form_id == 'contact_site_form' && arg(0) == 'contact' && arg(1) == 'lightbox2') {
    $form['#action'] = \Drupal\Core\Url::fromRoute('contact.site_page');
  }
}

/**
 * Implementation of hook_link_alter().
 *
 * Add a lightbox2 rel attribute to the image link sizes on the image node.
 */
function lightbox2_link_alter(&$links, $node) {
  $image_node_handler = \Drupal::config('lightbox2.settings')
    ->get('lightbox2_image_node');

  // 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;
  }

  // @FIXME
  // Could not extract the default value because it is either indeterminate, or
  // not scalar. You'll need to provide a default value in
  // config/install/lightbox2.settings.yml and config/schema/lightbox2.schema.yml.
  $trigger_sizes = \Drupal::config('lightbox2.settings')
    ->get('lightbox2_trigger_image_size');

  // 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']);
    }
  }
}

/**
 * Implementation of hook_views_api().
 */
function lightbox2_views_api() {
  return array(
    'api' => '3.0',
  );
}
function lightbox2_filter_xss() {
  $allowed_tags = trim(\Drupal::config('lightbox2.settings')
    ->get('lightbox2_filter_xss_allowed_tags'));
  $allowed_tags = empty($allowed_tags) ? array() : preg_split('/[,\\s]+/', $allowed_tags);
  if (!empty($_POST['allowed_tags']) && $_POST['allowed_tags'] != 'undefined') {
    $allowed_tags = explode(',', $_POST['allowed_tags']);
    $output = \Drupal\Component\Utility\Xss::filter($_POST['string'], $allowed_tags);
  }
  else {
    $output = \Drupal\Component\Utility\Xss::filter($_POST['string'], $allowed_tags);
  }
  drupal_json_output($output);
}

Functions

Namesort descending Description
lightbox2_add_files Provide links to the CSS stylesheet and JS file associated with this module.
lightbox2_check_filefield_extension Suitability callback function for the filefield formatter.
lightbox2_check_filefield_image_extension Suitability callback function for the image filefield formatter.
lightbox2_contact Get the contact form.
lightbox2_exclude_these_paths Return TRUE if current path is disabled for lightbox according to lightbox2_page_list and lightbox2_page_init_action.
lightbox2_field_formatter_info Implementation of hook_field_formatter_info().
lightbox2_field_formatter_settings_form Implements hook_field_formatter_settings_form().
lightbox2_field_formatter_settings_summary Implements hook_field_formatter_settings_summary().
lightbox2_field_formatter_view Implements hook_field_formatter_view().
lightbox2_file_formatter_info Implementation of filefield's hook_file_formatter_info().
lightbox2_filter_info Implements hook_filter_info().
lightbox2_filter_xss
lightbox2_form_contact_site_form_alter
lightbox2_form_user_login_block_alter Implementation of hook_form_alter().
lightbox2_help Implementation of hook_help().
lightbox2_image_fields Helper function for possible fields to display as the caption.
lightbox2_image_styles Helper function for image styles.
lightbox2_init Implementation of hook_init().
lightbox2_lightbox_types Helper function for possible lightbox styles.
lightbox2_link_alter Implementation of hook_link_alter().
lightbox2_login Get the user login form.
lightbox2_menu Implementation of hook_menu().
lightbox2_permission Implementation of hook_permission().
lightbox2_preprocess_page Preprocess function for template by theme('page').
lightbox2_supported_file_extension Check whether a given file extension is supported by the lightbox iframe.
lightbox2_theme Implementation of hook_theme().
lightbox2_views_api Implementation of hook_views_api().
sort_by_length Helper function to compare the string length of two items. Used when trying to sort an array by value length.
_lightbox2_process_disable_filter Process callback for Disable Lightbox iframe filter.
_lightbox2_process_filter Process callback for Lightbox G2 filter.