Index: imagecache/imagecache.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache.module,v retrieving revision 1.68.2.1 diff -u -p -r1.68.2.1 imagecache.module --- imagecache/imagecache.module 30 Apr 2008 14:40:52 -0000 1.68.2.1 +++ imagecache/imagecache.module 6 May 2008 04:35:12 -0000 @@ -68,6 +68,13 @@ function imagecache_menu($may_cache) { 'access' => true, 'type' => MENU_CALLBACK ); + + } + else { + // re-cache imagecache presets when enabling/disabling modules + if (arg(0) == 'admin' && arg(2) == 'modules') { + imagecache_presets(true); + } } return $items; } @@ -777,6 +784,16 @@ function imagecache_presets($reset = fal $presets[$preset['presetid']] = $preset; $presets[$preset['presetid']]['actions'] = imagecache_preset_actions($preset); } + foreach (module_implements('imagecache_presets') as $module) { + $function = $module .'_imagecache_presets'; + foreach ($function() as $name => $preset) { + $presets[$module .'-'. $name] = array( + 'presetid' => $module .'-'. $name, + 'presetname' => $module .'-'. $name, + 'actions' => $preset, + ); + } + } cache_set('imagecache:presets', 'cache', serialize($presets)); } return $presets; Index: imagecache/imagecache_ui.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache_ui.module,v retrieving revision 1.11 diff -u -p -r1.11 imagecache_ui.module --- imagecache/imagecache_ui.module 24 Apr 2008 05:27:45 -0000 1.11 +++ imagecache/imagecache_ui.module 6 May 2008 04:35:12 -0000 @@ -67,6 +67,15 @@ function imagecache_ui_menu($may_cache) 'callback arguments' => array('imagecache_ui_preset_form', arg(4)), 'type' => MENU_CALLBACK, ); + if (is_numeric(arg(4))) { + $items[] = array( + 'path' => 'admin/build/imagecache/preset/'. arg(4) .'/export', + 'title' => t('Export Preset: !presetname', $t), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('imagecache_ui_preset_export', arg(4)), + 'type' => MENU_CALLBACK, + ); + } $definition = imagecache_action_definition(arg(7)); if (!empty($definition)) { @@ -108,22 +117,53 @@ function imagecache_ui_menu($may_cache) */ function imagecache_ui_presets() { - $header = array(t('Preset Name'), t('Actions')); + $header = array(t('Preset Name'), t('Provider'), t('Actions')); $rows = array(); - foreach (imagecache_presets() as $preset) { + foreach (imagecache_presets() as $presetid => $preset) { $row = array(); $row[] = l($preset['presetname'], 'admin/build/imagecache/preset/'. $preset['presetid']); $links = array(); - $links[] = l(t('edit'), 'admin/build/imagecache/preset/'. $preset['presetid']); - $links[] = l(t('remove'), 'admin/build/imagecache/preset/'. $preset['presetid'] .'/delete'); - $links[] = l(t('flush'), 'admin/build/imagecache/preset/'. $preset['presetid'] .'/flush' ); + // Test for whether this preset is provided by a user or in code by a module + if (is_numeric($presetid)) { + $row[] = t('user'); + $links[] = l(t('edit'), 'admin/build/imagecache/preset/'. $preset['presetid']); + $links[] = l(t('remove'), 'admin/build/imagecache/preset/'. $preset['presetid'] .'/delete'); + $links[] = l(t('flush'), 'admin/build/imagecache/preset/'. $preset['presetid'] .'/flush' ); + $links[] = l(t('export'), 'admin/build/imagecache/preset/'. $preset['presetid'] .'/export' ); + } + else { + $row[] = t('module'); + $links[] = l(t('view'), 'admin/build/imagecache/preset/'. $preset['presetid']); + $links[] = l(t('flush'), 'admin/build/imagecache/preset/'. $preset['presetid'] .'/flush' ); + } $row[] = implode('    ', $links); $rows[] = $row; } $output = theme('table', $header, $rows); + $output .= drupal_get_form('imagecache_ui_presets_recache'); return $output; } +function imagecache_ui_presets_recache() { + $form = array(); + $form['help'] = array( + '#type' => 'item', + '#title' => t('Clear preset cache'), + '#value' => t('Imagecache stores a cache of all imagecache presets in the database. Sometimes this cache can become stale when you export presets to code. You can manually clear the preset cache using the button below.'), + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Clear cache'), + ); + return $form; +} + +function imagecache_ui_presets_recache_submit() { + imagecache_presets(true); + drupal_set_message(t('The preset cache has been cleared and rebuilt.')); + return 'admin/build/imagecache'; +} + function imagecache_ui_preset_add_form($presetid = 0) { $form = array(); $form['presetname'] = array( @@ -217,7 +257,64 @@ function imagecache_ui_preset_flush_form return 'admin/build/imagecache'; } +function imagecache_ui_preset_export($presetid) { + $preset = imagecache_preset($presetid, true); + + if (!$preset) { + drupal_set_message(t('The specified preset was not found'), 'error'); + drupal_goto('admin/build/imagecache'); + } + else if (!is_numeric($presetid)) { + drupal_set_message(t('You cannot export a code-defined preset.'), 'error'); + drupal_goto('admin/build/imagecache'); + } + // Prepare the preset data for exporting + $presetname = $preset['presetname']; + $preset = $preset['actions']; + foreach ($preset as &$action) { + unset($action['actionid']); + unset($action['presetid']); + unset($action['weight']); + } + $export = var_export($preset, true); + + // Correctly indent the exported data + $export = explode("\n", $export); + foreach ($export as &$line) { + $line = ' '. $line; + } + $export = implode("\n", $export); + + // Help comment + $comment = t('You may add additional exported presets to the array here.'); + + // Surround export with example comment and hook function + $export = +'/** + * Implementation of hook_imagecache_presets() + */ +function hook_imagecache_presets() { + $items = array(); + $items["'. $presetname .'"] = '. $export .'; + // '. $comment .' + return $items; +} +'; + + $form = array(); + $form['help'] = array( + '#type' => 'item', + '#value' => "

". t('You can store this imagecache preset in a module by copying and pasting this code and replacing "hook" in the function name with the appropriate module name. Multiple presets can be provided by adding additional preset definitions to the returned array.') ."

", + ); + $form['presetexport'] = array( + '#type' => textarea, + '#rows' => 12, + '#title' => t('Preset Export'), + '#default_value' => $export, + ); + return $form; +} @@ -228,6 +325,9 @@ function imagecache_ui_preset_form($pres drupal_set_message(t('The specified preset was not found'), 'error'); drupal_goto('admin/build/imagecache'); } + else if (!is_numeric($presetid)) { + drupal_set_message(t('This preset is provided by a module. It cannot be altered.')); + } $form = array(); $form['presetname'] = array( @@ -237,6 +337,7 @@ function imagecache_ui_preset_form($pres '#default_value' => $preset['presetname'], '#description' => t('The namespace is used in URL\'s for images to tell imagecache how to process an image. Please only use alphanumic characters, underscores (_), and hyphens (-) for preset names.'), '#validate' => array('imagecache_element_presetname_validate' => array()), + '#disabled' => is_numeric($presetid) ? false : true, ); $form['presetid'] = array( '#type' => 'value', @@ -285,34 +386,38 @@ function imagecache_ui_preset_form($pres $action_form['weight'] = array( '#type' => 'weight', '#default_value' => $action['weight'], + '#disabled' => is_numeric($presetid) ? false : true, ); - $action_form['configure'] = array( - '#value' => l(t('Configure'), 'admin/build/imagecache/preset/'. $action['presetid'] .'/action/'. $action['actionid'] ), - ); - $action_form['remove'] = array( - '#value' => l(t('Delete'), 'admin/build/imagecache/preset/'. $action['presetid'] .'/action/'. $action['actionid'] .'/delete'), - ); + if (is_numeric($presetid)) { + $action_form['configure'] = array( + '#value' => l(t('Configure'), 'admin/build/imagecache/preset/'. $action['presetid'] .'/action/'. $action['actionid'] ), + ); + $action_form['remove'] = array( + '#value' => l(t('Delete'), 'admin/build/imagecache/preset/'. $action['presetid'] .'/action/'. $action['actionid'] .'/delete'), + ); + } $form['actions'][$i] = $action_form; } - $form['actions']['new'] = array( - '#tree' => false, - '#type' => 'fieldset', - '#title' => t('New Actions'), - '#collapsible' => true, - '#collapsed' => true, - ); - - - foreach (imagecache_action_definitions() as $action => $definition) { - $form['actions']['new'][] = array( - '#type' => 'markup', - '#prefix' => '
', - '#suffix' => '
', - '#value' => l(t('Add !action', array('!action' => $definition['name'])), - 'admin/build/imagecache/preset/'. $preset['presetid'] .'/action/add/'. $action) . - ' - '. $definition['description'], - ); + if (is_numeric($presetid)) { + $form['actions']['new'] = array( + '#tree' => false, + '#type' => 'fieldset', + '#title' => t('New Actions'), + '#collapsible' => true, + '#collapsed' => true, + ); + + foreach (imagecache_action_definitions() as $action => $definition) { + $form['actions']['new'][] = array( + '#type' => 'markup', + '#prefix' => '
', + '#suffix' => '
', + '#value' => l(t('Add !action', array('!action' => $definition['name'])), + 'admin/build/imagecache/preset/'. $preset['presetid'] .'/action/add/'. $action) . + ' - '. $definition['description'], + ); + } } /** @@ -348,10 +453,13 @@ function imagecache_ui_preset_form($pres ); */ - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Update Preset'), - ); + if (is_numeric($presetid)) { + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Update Preset'), + ); + } + return $form; }