You are here

function return_presets in Image javascript crop 6

Same name and namespace in other branches
  1. 5 imagecrop.module \return_presets()

Helper function to determine which preset exists and which to load

Parameters

$presetname Name of active preset.:

Return value

$presets array with presetid to load and list of all other possible presets

4 calls to return_presets()
imagecrop_cron in ./imagecrop.module
Implementation of hook_cron(). Delete all references in imagecrop table when a) file doesn't exist anymore. b) when preset has been deleted. c) when javascrip_crop action is removed from a preset.
imagecrop_docrop in ./imagecrop.admin.inc
Callback with javascript crop.
imagecrop_form_alter in ./imagecrop.module
Implementation of hook_form_alter(). Hook into several existing image modules/fields.
imagecrop_showcrop in ./imagecrop.admin.inc
Show the cropped image.

File

./imagecrop.module, line 459
Provides a javascript toolbox through an imagecache action.

Code

function return_presets($presetname = '', $module = '', $field = '', $node_type = '') {
  $filter = array();

  // get possible presets for current imagefield
  if ($module == 'imagefield' && $field) {
    $element = content_fields($field, $node_type);
    if ($element['widget']['imagecrop']) {
      $filter = $element['widget']['imagecrop_presets'];
    }
  }
  $all_presets = imagecache_presets();
  $presets = array();
  foreach ($all_presets as $preset) {
    foreach ($preset['actions'] as $action) {
      if ($action['action'] == 'imagecrop_javascript') {
        if (!count($filter) || !empty($filter[$preset['presetname']])) {
          $presets['tabs'][] = $preset['presetname'];
          if ($presetname == $preset['presetname']) {
            $presets['active_preset'] = $preset['presetname'];
          }
        }
      }
    }
  }
  if (!isset($presets['active_preset']) && count($presets) > 0) {
    $presets['active_preset'] = $presets['tabs'][0];
  }
  return $presets;
}