You are here

asset_lightbox.module in Asset 6

Same filename and directory in other branches
  1. 5 asset_lightbox/asset_lightbox.module

File

asset_lightbox/asset_lightbox.module
View source
<?php

function asset_lightbox_asset_formatter($op = 'info', $asset = null, $attr = array()) {
  switch ($op) {
    case 'info':
      $presets = imagecache_presets();
      foreach ($presets as $preset) {
        if (variable_get('asset_imagecache_preset_' . $preset['presetid'], 1)) {
          $formats[$preset['presetname']] = array(
            'name' => $preset['presetname'] . ' (imagecache + lightbox link)',
            'types' => array(
              'local' => array(
                'jpg',
                'gif',
                'png',
              ),
            ),
          );
        }
      }
      return $formats;
    case 'options':
      $path = imagecache_create_path($attr['format'], $asset->filepath);
      if (!file_exists($path)) {

        // this is the easiest albeit indirect way i can see to generate the image
        $result = drupal_http_request(url(file_create_url($path)));
      }
      $size = image_get_info(imagecache_create_path($attr['format'], $asset->filepath));
      $form['width'] = array(
        '#type' => 'hidden',
        '#value' => $size['width'],
      );
      $form['height'] = array(
        '#type' => 'hidden',
        '#value' => $size['height'],
      );
      $form['resizable'] = array();
      $form['_width'] = array(
        '#type' => 'item',
        '#title' => t('Width, preset by imagecache'),
        '#value' => $size['width'] . 'px',
      );
      $form['_height'] = array(
        '#type' => 'item',
        '#title' => t('Height, preset by imagecache'),
        '#value' => $size['height'] . 'px',
      );
      return $form;
      break;
    case 'img':
      return imagecache_create_path($attr['format'], $asset->filepath);
    case 'preview':
      return theme('imagecache', $attr['format'], $asset->filepath, '', '', array(
        'width' => '100',
      ));
    case 'render':
      return '<a href="' . base_path() . $asset->filepath . '" rel="lightbox">' . theme('imagecache', $attr['format'], $asset->filepath) . '</a>';
  }
}

Functions