You are here

cloud_zoom.module in Cloud Zoom 6

Same filename and directory in other branches
  1. 8 cloud_zoom.module
  2. 7 cloud_zoom.module

This module integrates the Cloud Zoom JQuery library from: http://www.professorcloud.com/mainsite/cloud-zoom.htm

File

cloud_zoom.module
View source
<?php

/**
 * @file
 * This module integrates the Cloud Zoom JQuery library from:
 * http://www.professorcloud.com/mainsite/cloud-zoom.htm
 */

/**
 * Preset Storage constants
 */
define('CLOUD_ZOOM_STORAGE_NORMAL', 0);

// User Defined
define('CLOUD_ZOOM_STORAGE_DEFAULT', 1);

// Module Defined
define('CLOUD_ZOOM_STORAGE_OVERRIDE', 2);

// Module Defined, User overidden

/**
 * Implementation of hook_help().
 */
function cloud_zoom_help($path, $args) {
  switch ($path) {
    case 'admin/settings/cloudzoom':
      return t('Available fields are listed below. You can modify the settings for each by clicking edit');
  }
}

/**
 * Implementation of hook_menu().
 */
function cloud_zoom_menu() {
  $items = array();
  $items['admin/settings/cloudzoom'] = array(
    'title' => 'Cloud Zoom',
    'description' => 'Configure the Cloud Zoom display features',
    'page callback' => 'cloud_zoom_admin_overview',
    'file' => 'cloud_zoom.admin.inc',
    'access arguments' => array(
      'configure cloud zoom field display',
    ),
  );
  $items['admin/settings/cloudzoom/overview'] = array(
    'title' => 'Overview',
    'access arguments' => array(
      'configure cloud zoom field display',
    ),
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );
  $base = array(
    'title callback' => 'cloud_zoom_admin_preset_title',
    'access arguments' => array(
      'configure cloud zoom field display',
    ),
    'page callback' => 'drupal_get_form',
    'file' => 'cloud_zoom.admin.inc',
    'type' => MENU_CALLBACK,
  );
  $items['admin/settings/cloudzoom/add'] = array(
    'title' => 'Add',
    'title callback' => NULL,
    'page arguments' => array(
      'cloud_zoom_admin_preset_edit_form',
    ),
    'type' => MENU_LOCAL_TASK,
  ) + $base;
  $items['admin/settings/cloudzoom/%cloud_zoom_preset_name/edit'] = array(
    'title arguments' => array(
      3,
      'Edit',
    ),
    'page arguments' => array(
      'cloud_zoom_admin_preset_edit_form',
      3,
    ),
  ) + $base;
  $items['admin/settings/cloudzoom/%cloud_zoom_preset_name/delete'] = array(
    'title arguments' => array(
      3,
      'Delete',
    ),
    'page arguments' => array(
      'cloud_zoom_admin_preset_delete_confirm',
      3,
    ),
  ) + $base;
  $items['admin/settings/cloudzoom/%cloud_zoom_preset_name/revert'] = array(
    'title arguments' => array(
      3,
      'Revert',
    ),
    'page arguments' => array(
      'cloud_zoom_admin_preset_revert_confirm',
      3,
    ),
  ) + $base;
  return $items;
}

/**
 * Profile title callbac for add and edit pages
 */
function cloud_zoom_admin_preset_title($preset, $operation) {
  return t('Cloud Zoom - @operation - @name', array(
    '@operation' => t($operation),
    '@name' => $preset['name'],
  ));
}

/**
 * Preset loader. Used for Menu API wildcard loader.
 */
function cloud_zoom_preset_name_load($preset_name) {
  return cloud_zoom_get_settings($preset_name);
}

/**
 * Implementation of hook_field_formatter().
 */
function cloud_zoom_field_formatter_info() {
  $formatters = array();
  $settings = cloud_zoom_get_settings();
  foreach ($settings as $key => $values) {
    $formatters['imagefield__cloud_zoom__' . $key] = array(
      'label' => t('Cloud Zoom: !presetname', array(
        '!presetname' => $key,
      )),
      'field types' => array(
        'filefield',
      ),
    );
  }
  return $formatters;
}

/**
 * Implementation of hook_theme().
 */
function cloud_zoom_theme() {

  // Define a base theme handler
  $theme = array(
    'cloud_zoom_formatter_imagefield' => array(
      'arguments' => array(
        'element' => NULL,
      ),
      'file' => 'cloud_zoom.theme.inc',
    ),
    'cloud_zoom_admin_settings_table' => array(
      'arguments' => array(
        'element' => NULL,
      ),
      'file' => 'cloud_zoom.theme.inc',
    ),
  );
  $presets = cloud_zoom_get_settings();
  foreach ($presets as $preset) {
    $theme['cloud_zoom_formatter_imagefield__cloud_zoom__' . $preset['name']] = array(
      'arguments' => array(
        'element' => NULL,
      ),
      'function' => 'theme_cloud_zoom_formatter_imagefield',
      'file' => 'cloud_zoom.theme.inc',
    );
  }
  return $theme;
}

/**
 * Implementation of hook_imagecache_default_presets().
 */
function cloud_zoom_imagecache_default_presets() {
  return array(
    array(
      'presetname' => 'cloud_zoom_small',
      'actions' => array(
        array(
          'weight' => 0,
          'module' => 'cloud_zoom',
          'action' => 'imagecache_scale',
          'data' => array(
            'width' => 240,
            'height' => '',
            'upscale' => 0,
          ),
        ),
      ),
    ),
    array(
      'presetname' => 'cloud_zoom_large',
      'actions' => array(
        array(
          'weight' => 0,
          'module' => 'cloud_zoom',
          'action' => 'imagecache_scale',
          'data' => array(
            'width' => 768,
            'height' => '',
            'upscale' => 0,
          ),
        ),
      ),
    ),
  );
}

/**
 * Private function for the default settings
 */
function _cloud_zoom_default_settings() {
  return array(
    'zoomWidth' => array(
      'default' => 'auto',
      'quoted' => TRUE,
      'description' => 'The width of the zoom window in pixels. If \'auto\' is specified, the width will be the same as the small image.',
    ),
    'zoomHeight' => array(
      'default' => 'auto',
      'quoted' => TRUE,
      'description' => 'The height of the zoom window in pixels. If \'auto\' is specified, the height will be the same as the small image.',
    ),
    'position' => array(
      'default' => 'right',
      'quoted' => TRUE,
      'description' => 'Specifies the position of the zoom window relative to the small image. <br />Allowable values are \'left\', \'right\', \'top\', \'bottom\', \'inside\' or you can specifiy the id of an html element to place the zoom window in e.g. position: \'element1\'',
    ),
    'adjustX' => array(
      'default' => 0,
      'quoted' => FALSE,
      'description' => 'Allows you to fine tune the x-position of the zoom window in pixels.',
    ),
    'adjustY' => array(
      'default' => 0,
      'quoted' => FALSE,
      'description' => 'Allows you to fine tune the y-position of the zoom window in pixels.',
    ),
    'tint' => array(
      'default' => 'false',
      'quoted' => FALSE,
      'description' => 'Specifies a tint colour which will cover the small image. Colours should be specified in hex format, e.g. \'#aa00aa\'. Does not work with softFocus.',
    ),
    'tintOpacity' => array(
      'default' => 0.5,
      'quoted' => FALSE,
      'description' => 'Opacity of the tint, where 0 is fully transparent, and 1 is fully opaque.',
    ),
    'lensOpacity' => array(
      'default' => 0.5,
      'quoted' => FALSE,
      'description' => 'Opacity of the lens mouse pointer, where 0 is fully transparent, and 1 is fully opaque. In tint and soft-focus modes, it will always be transparent.',
    ),
    'softFocus' => array(
      'default' => 'false',
      'quoted' => FALSE,
      'description' => 'Applies a subtle blur effect to the small image. Set to true or false. Does not work with tint.',
    ),
    'smoothMove' => array(
      'default' => 3,
      'quoted' => FALSE,
      'description' => 'Amount of smoothness/drift of the zoom image as it moves. The higher the number, the smoother/more drifty the movement will be. 1 = no smoothing.',
    ),
    'showTitle' => array(
      'default' => 'true',
      'quoted' => FALSE,
      'description' => 'Shows the title tag of the image. True or false.',
    ),
    'titleOpacity' => array(
      'default' => 0.5,
      'quoted' => FALSE,
      'description' => 'Specifies the opacity of the title if displayed, where 0 is fully transparent, and 1 is fully opaque.',
    ),
  );
}

/**
 * Implementation of hook_cloud_zoom_preset_info().
 */
function cloud_zoom_cloud_zoom_preset_info() {
  return array(
    'default' => array(
      'name' => 'default',
      'settings' => array(),
      'view_preset' => 'cloud_zoom_small',
      'zoom_preset' => 'cloud_zoom_large',
    ),
  );
}

/**
 * Function to get the cloud_zoom settings
 * Settings are cached both statically and in the cache table for performance.
 */
function cloud_zoom_get_settings($preset_name = NULL, $reset = FALSE) {
  if (variable_get('cloud_zoom_schema_version', 0) < 6001) {
    return array();
  }

  // Static settings cache variable
  static $settings = NULL;

  // If we're resetting, clear static and cache table
  if ($reset) {
    $settings = NULL;
    cache_clear_all('cloud_zoom:presets', 'cache');
  }

  // If settings are not set, lets define them
  if (!isset($settings)) {

    // First, try to get from the cache table
    if (($cache = cache_get('cloud_zoom:presets', 'cache')) && is_array($cache->data)) {
      $settings = $cache->data;
    }
    else {

      // Initialize the settings
      $settings = array();

      // Get anything we have defined from the DB
      $result = db_query('SELECT * FROM {cloud_zoom_presets}');
      while ($preset = db_fetch_array($result)) {

        // Mark as "normal" items
        $preset['storage'] = CLOUD_ZOOM_STORAGE_NORMAL;
        $preset['settings'] = unserialize($preset['settings']);

        // Store the preset
        $settings[$preset['name']] = $preset;
      }

      // Now loop over the hook to get any module defined presets, using
      // hook_cloud_zoom_default_presets().
      $default_presets = module_invoke_all('cloud_zoom_preset_info');

      // Allow other modules to alter the module-defined presets using:
      // hook_cloud_zoom_default_presets_alter(&$default_presets)
      drupal_alter('cloud_zoom_preset_info', $default_presets);

      // Add each defined preset to our list...
      foreach ($default_presets as $preset) {

        // ... but only if a name is set!
        if (!empty($preset['name'])) {

          // If the name is already in our settings, then we have overridden a module-level item
          if (isset($settings[$preset['name']])) {

            // Set the preset as 'overridden', but do not store the module defined preset
            $settings[$preset['name']]['storage'] = CLOUD_ZOOM_STORAGE_OVERRIDE;
          }
          else {

            // Store the preset as a default store
            $preset['storage'] = CLOUD_ZOOM_STORAGE_DEFAULT;
            $settings[$preset['name']] = $preset;
          }
        }
      }

      // Cache it for later use
      cache_set('cloud_zoom:presets', $settings);
    }
  }

  // Did we ask for a SPECIFIC preset by name? If so, return it (or FALSE if
  // it is not available)
  if ($preset_name) {
    return isset($settings[$preset_name]) ? $settings[$preset_name] : FALSE;
  }

  // Otherwise, return ALL settings
  return $settings;
}

/**
 * Implementation of hook_features_api().
 */
function cloud_zoom_features_api() {
  return array(
    'cloud_zoom_preset' => array(
      'name' => t('Cloud Zoom Presets'),
      'default_hook' => 'cloud_zoom_preset_info',
      'default_file' => 'FEATURES_DEFAULTS_INCLUDED_COMMON',
      'features_source' => TRUE,
      'file' => drupal_get_path('module', 'cloud_zoom') . '/cloud_zoom.features.inc',
    ),
  );
}

Functions

Namesort descending Description
cloud_zoom_admin_preset_title Profile title callbac for add and edit pages
cloud_zoom_cloud_zoom_preset_info Implementation of hook_cloud_zoom_preset_info().
cloud_zoom_features_api Implementation of hook_features_api().
cloud_zoom_field_formatter_info Implementation of hook_field_formatter().
cloud_zoom_get_settings Function to get the cloud_zoom settings Settings are cached both statically and in the cache table for performance.
cloud_zoom_help Implementation of hook_help().
cloud_zoom_imagecache_default_presets Implementation of hook_imagecache_default_presets().
cloud_zoom_menu Implementation of hook_menu().
cloud_zoom_preset_name_load Preset loader. Used for Menu API wildcard loader.
cloud_zoom_theme Implementation of hook_theme().
_cloud_zoom_default_settings Private function for the default settings

Constants