You are here

lightbox2.insert.inc in Lightbox2 8

Same filename and directory in other branches
  1. 6 lightbox2.insert.inc
  2. 7.2 lightbox2.insert.inc
  3. 7 lightbox2.insert.inc

Lightbox2 support for Insert module.

File

lightbox2.insert.inc
View source
<?php

// $Id: lightbox2.insert.inc,v 1.1.2.6 2010/09/22 10:47:15 snpower Exp $

/**
 * @file
 * Lightbox2 support for Insert module.
 */

/**
 * Implementation of hook_insert_styles().
 */
function lightbox2_insert_styles() {
  $cck_formatters = lightbox2_field_formatter_info();
  $insert_styles = array();

  // Reformat CCK formatter ids as Insert style ids.
  foreach ($cck_formatters as $formatter_id => $formatter_info) {

    // Currently only the "imagefield--lightbox2" formatters are implemented as styles.
    if (preg_match('/^imagefield__lightbox2__((?:_(?!_)|[^_])+)__((?:_(?!_)|[^_])+)$/', $formatter_id, $matches)) {
      $style_id = 'lightbox2--' . $matches[1] . '--' . $matches[2];
      $insert_styles[$style_id] = $formatter_info;
    }
  }
  return $insert_styles;
}

/**
 * Implementation of hook_insert_content().
 */
function lightbox2_insert_content($item, $style, $widget) {
  if (preg_match('/^lightbox2--((?:-(?!-)|[^-])+)--((?:-(?!-)|[^-])+)$/', $style['name'], $matches)) {
    $image_preset_name = $matches[1];
    $link_preset_name = $matches[2];

    // @FIXME
    // theme() has been renamed to _theme() and should NEVER be called directly.
    // Calling _theme() directly can alter the expected output and potentially
    // introduce security issues (see https://www.drupal.org/node/2195739). You
    // should use renderable arrays instead.
    //
    //
    // @see https://www.drupal.org/node/2195739
    // return theme('lightbox2_insert_image', $item, $widget, 'view', $image_preset_name, $link_preset_name);
  }
  else {
    return '';
  }
}

/**
 * Theme the content that will be inserted for Lightbox2 presets.
 */
function template_preprocess_lightbox2_insert_image(&$vars) {
  if ($vars['image_preset_name'] != 'original') {
    $filepath = imagecache_create_path($vars['image_preset_name'], $vars['item']['filepath']);
  }
  else {
    $filepath = $vars['item']['filepath'];
  }
  $vars['url'] = insert_create_url($filepath);
  if ($vars['link_preset_name'] != 'original') {
    $linkpath = imagecache_create_path($vars['link_preset_name'], $vars['item']['filepath']);
  }
  else {
    $linkpath = $vars['item']['filepath'];
  }
  $vars['linkurl'] = insert_create_url($linkpath);
  $vars['download_link'] = '';
  $download_link_text = \Drupal\Component\Utility\Html::escape(\Drupal::config('lightbox2.settings')
    ->get('lightbox2_download_link_text'));
  if (!empty($download_link_text) && \Drupal::currentUser()
    ->hasPermission('download original image')) {

    // @FIXME
    // l() expects a Url object, created from a route name or external URI.
    // $vars['download_link'] = '<br /><br />' . l($download_link_text, $vars['linkurl'], array('attributes' => array('target' => '_blank', 'id' => 'lightbox2-download-link-text')));
  }
  $vars['class'] = !empty($vars['widget']['insert_class']) ? $vars['widget']['insert_class'] : '';
}

Functions

Namesort descending Description
lightbox2_insert_content Implementation of hook_insert_content().
lightbox2_insert_styles Implementation of hook_insert_styles().
template_preprocess_lightbox2_insert_image Theme the content that will be inserted for Lightbox2 presets.