You are here

function imagecache_presets in ImageCache 6.2

Same name and namespace in other branches
  1. 5.2 imagecache.module \imagecache_presets()

Get an array of all presets and their settings.

Parameters

reset: if set to TRUE it will clear the preset cache

Return value

array of presets array( $preset_id => array('presetid' => integer, 'presetname' => string))

18 calls to imagecache_presets()
imagecache_action_delete in ./imagecache.module
imagecache_action_save in ./imagecache.module
imagecache_add_js in ./imagecache.module
Imagecache JS settings and theme function.
imagecache_drush_preset_build in ./imagecache.drush.inc
Drush callback to perform actual imagecache preset build.
imagecache_drush_preset_flush in ./imagecache.drush.inc
Drush callback to perform actual imagecache preset flush.

... See full list

File

./imagecache.module, line 968
Dynamic image resizer and image cacher.

Code

function imagecache_presets($reset = FALSE) {
  static $presets = array();

  // Clear  caches if $reset is TRUE;
  if ($reset) {
    $presets = array();
    cache_clear_all('imagecache:presets', 'cache');

    // Clear the content.module cache (refreshes the list of formatters provided by imagefield.module).
    if (module_exists('content')) {
      content_clear_type_cache();
    }
  }

  // Return presets if the array is populated.
  if (!empty($presets)) {
    return $presets;
  }

  // Grab from cache or build the array. To ensure that the Drupal 5 upgrade
  // path works, we also check whether the presets list is an array.
  if (($cache = cache_get('imagecache:presets', 'cache')) && is_array($cache->data)) {
    $presets = $cache->data;
  }
  else {
    $normal_presets = array();
    $result = db_query('SELECT * FROM {imagecache_preset} ORDER BY presetname');
    while ($preset = db_fetch_array($result)) {
      $presets[$preset['presetid']] = $preset;
      $presets[$preset['presetid']]['actions'] = imagecache_preset_actions($preset);
      $presets[$preset['presetid']]['storage'] = IMAGECACHE_STORAGE_NORMAL;

      // Collect normal preset names so we can skip defaults and mark overrides accordingly
      $normal_presets[$preset['presetname']] = $preset['presetid'];
    }

    // Collect default presets and allow modules to modify them before they
    // are cached.
    $default_presets = module_invoke_all('imagecache_default_presets');
    drupal_alter('imagecache_default_presets', $default_presets);

    // Add in default presets if they don't conflict with any normal presets.
    // Mark normal presets that take the same preset namespace as overrides.
    foreach ($default_presets as $preset) {
      if (!empty($preset['presetname'])) {
        if (!isset($normal_presets[$preset['presetname']])) {
          $preset['storage'] = IMAGECACHE_STORAGE_DEFAULT;

          // Use a string preset identifier
          $preset['presetid'] = $preset['presetname'];
          $presets[$preset['presetname']] = $preset;
        }
        else {
          $presetid = $normal_presets[$preset['presetname']];
          $presets[$presetid]['storage'] = IMAGECACHE_STORAGE_OVERRIDE;
        }
      }
    }
    cache_set('imagecache:presets', $presets);
  }
  return $presets;
}