You are here

function lightbox2_field_formatter_info in Lightbox2 6

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

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.

1 call to lightbox2_field_formatter_info()
lightbox2_insert_styles in ./lightbox2.insert.inc
Implementation of hook_insert_styles().

File

./lightbox2.module, line 731
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_field_formatter_info() {
  $formatters = array();
  $lightbox = $slideshow = $iframe = array();

  // Handle imagefield and filefield images.
  if (module_exists('imagecache') && (module_exists('imagefield') || module_exists('filefield'))) {
    $rules = array();
    if (function_exists('imagecache_presets')) {
      $presets = imagecache_presets();
      foreach ($presets as $preset_id => $preset_info) {
        $rules[$preset_id] = $preset_info['presetname'];
      }
    }
    else {
      $rules = _imagecache_get_presets();
    }

    // By convention, empty variable means "All presets enabled".
    // Options is an array of enabled formatter options. Instead of storing complete
    // formatter id it's better to store formatter options so we then can construct
    // labels (or any other required properties) without parsing.
    //
    // Each element is itself an array of the following form:
    // $formatter_options = array(
    //   'type' => 'foo' // lightbox2, lightshow2, or lightframe2
    //   'compact' => 'foo' // TRUE or FALSE
    //   'source' => 'foo' // preset id of the source (formatted image) or reserved keyword
    //   'dest' => 'foo' // preset id of the popup or reserved keyword
    // );
    //
    // Source keywords: 'original', 'link'. 'link' is not compatible
    // with "compact" mode.
    // Destination keywords: 'original', 'node'.
    //
    // Lightframe2 type supports only 'node' destination.
    //
    $options = variable_get('lightbox2_image_formatter_options', array());
    if (!empty($options)) {
      $label = '';
      foreach ($options as $o) {
        switch ($o['type']) {
          case 'lightshow2':
            $label = 'Lightbox2 slideshow: ';
            break;
          case 'lightframe2':
            $label = 'Lightbox2 iframe: ';
            break;
          case 'lightbox2':
            $label = 'Lightbox2: ';
            break;
        }
        $label .= $o['source'] . '->' . $o['dest'];
        if ($o['compact']) {
          $label .= ' compact';
        }
        $id = _lightbox2_get_formatter_id($o);
        $formatters[$id] = array(
          'label' => $label,
          'field types' => array(
            'image',
            'filefield',
          ),
        );
      }
    }
    else {
      $iframe['imagefield__lightframe2__original__node'] = array(
        'label' => 'Lightbox2 iframe: original->node page',
        'field types' => array(
          'image',
          'filefield',
        ),
      );
      $iframe['imagefield__lightframe2__link__node'] = array(
        'label' => 'Lightbox2 iframe: link->node page',
        'field types' => array(
          'image',
          'filefield',
        ),
      );
      foreach ($rules as $ruleid => $view_rule) {
        $lightbox['imagefield__lightbox2__original__' . $view_rule] = array(
          'label' => 'Lightbox2: original->' . $view_rule,
          'field types' => array(
            'image',
            'filefield',
          ),
        );
        $lightbox['imagefield__lightbox2_compact__original__' . $view_rule] = array(
          'label' => 'Lightbox2: original->' . $view_rule . ' compact',
          'field types' => array(
            'image',
            'filefield',
          ),
        );
        $lightbox['imagefield__lightbox2__' . $view_rule . '__original'] = array(
          'label' => 'Lightbox2: ' . $view_rule . '->original',
          'field types' => array(
            'image',
            'filefield',
          ),
        );
        $lightbox['imagefield__lightbox2_compact__' . $view_rule . '__original'] = array(
          'label' => 'Lightbox2: ' . $view_rule . '->original compact',
          'field types' => array(
            'image',
            'filefield',
          ),
        );
        $lightbox['imagefield__lightbox2__link__' . $view_rule] = array(
          'label' => 'Lightbox2: link->' . $view_rule,
          'field types' => array(
            'image',
            'filefield',
          ),
        );
        $slideshow['imagefield__lightshow2__original__' . $view_rule] = array(
          'label' => 'Lightbox2 slideshow: original->' . $view_rule,
          'field types' => array(
            'image',
            'filefield',
          ),
        );
        $slideshow['imagefield__lightshow2_compact__original__' . $view_rule] = array(
          'label' => 'Lightbox2 slideshow: original->' . $view_rule . ' compact',
          'field types' => array(
            'image',
            'filefield',
          ),
        );
        $slideshow['imagefield__lightshow2__' . $view_rule . '__original'] = array(
          'label' => 'Lightbox2 slideshow: ' . $view_rule . '->original',
          'field types' => array(
            'image',
            'filefield',
          ),
        );
        $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['imagefield__lightframe2__' . $view_rule . '__node'] = array(
          'label' => 'Lightbox2 iframe: ' . $view_rule . '->node page',
          'field types' => array(
            'image',
            'filefield',
          ),
        );
        foreach ($rules as $rid => $lightbox_rule) {
          $lightbox['imagefield__lightbox2__' . $view_rule . '__' . $lightbox_rule] = array(
            'label' => 'Lightbox2: ' . $view_rule . '->' . $lightbox_rule,
            'field types' => array(
              'image',
              'filefield',
            ),
          );
          $lightbox['imagefield__lightbox2_compact__' . $view_rule . '__' . $lightbox_rule] = array(
            'label' => 'Lightbox2: ' . $view_rule . '->' . $lightbox_rule . ' compact',
            'field types' => array(
              'image',
              'filefield',
            ),
          );
          $slideshow['imagefield__lightshow2__' . $view_rule . '__' . $lightbox_rule] = array(
            'label' => 'Lightbox2 slideshow: ' . $view_rule . '->' . $lightbox_rule,
            'field types' => array(
              'image',
              'filefield',
            ),
          );
          $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('filefield')) {
    $formatters['filefield_lightframe'] = array(
      'label' => t('Lightbox2 iframe'),
      'field types' => array(
        'filefield',
      ),
    );
  }
  return $formatters;
}