[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/features/includes/ -> features.imagecache.inc (source)

   1  <?php
   2  // $Id: features.imagecache.inc,v 1.1.2.14 2010/07/21 00:45:15 yhahn Exp $
   3  
   4  /**
   5   * Implementation of hook_features_api().
   6   */
   7  function imagecache_features_api() {
   8    return array(
   9      'imagecache' => array(
  10        'name' => t('Imagecache presets'),
  11        'default_hook' => 'imagecache_default_presets',
  12      )
  13    );
  14  }
  15  
  16  /**
  17   * Implementation of hook_features_export_options().
  18   */
  19  function imagecache_features_export_options() {
  20    $options = array();
  21    foreach (imagecache_presets() as $preset) {
  22      $options[$preset['presetname']] = $preset['presetname'];
  23    }
  24    return $options;
  25  }
  26  
  27  /**
  28   * Implementation of hook_features_export().
  29   */
  30  function imagecache_features_export($data, &$export, $module_name = '') {
  31    // Collect a module to preset map
  32    $map = features_get_default_map('imagecache', 'presetname');
  33    foreach ($data as $preset) {
  34      // If another module provides this preset, add it as a dependency
  35      if (isset($map[$preset]) && $map[$preset] != $module_name) {
  36        $module = $map[$preset];
  37        $export['dependencies'][$module] = $module;
  38      }
  39      // Otherwise, export the preset
  40      else {
  41        $export['features']['imagecache'][$preset] = $preset;
  42      }
  43    }
  44  }
  45  
  46  /**
  47   * Implementation of hook_features_export_render().
  48   */
  49  function imagecache_features_export_render($module_name, $data) {
  50    $items = array();
  51    foreach ($data as $key) {
  52      // This second argument to clear the static cache relies on patch in
  53      // http://drupal.org/node/665284.
  54      $preset = imagecache_preset_by_name($key, TRUE);
  55      _imagecache_features_preset_sanitize($preset);
  56      $items[$key] = $preset;
  57    }
  58    $code = "  \$items = ". features_var_export($items, '  ') .";\n";
  59    $code .= '  return $items;';
  60    return array('imagecache_default_presets' => $code);
  61  }
  62  
  63  /**
  64   * Implementation of hook_features_revert().
  65   */
  66  function imagecache_features_revert($module) {
  67    if ($default_presets = features_get_default('imagecache', $module)) {
  68      foreach (array_keys($default_presets) as $default_preset) {
  69        $preset = imagecache_preset_by_name($default_preset);
  70        if ($preset) {
  71          imagecache_preset_delete($preset);
  72        }
  73      }
  74    }
  75  }
  76  
  77  /**
  78   * Remove unnecessary keys for export.
  79   */
  80  function _imagecache_features_preset_sanitize(&$preset) {
  81    $omit = array('presetid', 'storage', 'actionid');
  82    if (is_array($preset)) {
  83      foreach ($preset as $k => $v) {
  84        if (in_array($k, $omit, TRUE)) {
  85          unset($preset[$k]);
  86        }
  87        else if (is_array($v)) {
  88          _imagecache_features_preset_sanitize($preset[$k]);
  89        }
  90      }
  91    }
  92  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7