ed43c9fe6ce1ba8c14b2b650d4bd52395097d4a4
5 * Administrative interface to imagecache.
9 function imagecache_ui_help($section) {
11 case
'admin/build/imagecache': return t('Manage imagecache preset.');
15 function imagecache_ui_menu($may_cache) {
19 'path' => 'admin/build/imagecache',
20 'title' => t('Imagecache Presets'),
21 'description' => t('Administer imagecache presets and actions.'),
22 'callback' => 'imagecache_ui_presets',
23 'access' => user_access('administer imagecache'),
27 'path' => 'admin/build/imagecache/list',
29 'type' => MENU_DEFAULT_LOCAL_TASK
,
33 'path' => 'admin/build/imagecache/add',
34 'title' => t('Add New Preset'),
35 'callback' => 'drupal_get_form',
36 'callback arguments' => array('imagecache_ui_preset_add_form'),
37 'access' => user_access('administer imagecache'),
38 'type' => MENU_LOCAL_TASK
,
41 // Use Dynamic menu items to get better breadcrumb trails by default.
42 elseif (arg(0) == 'admin' && arg(1) == 'build' && arg(2) == 'imagecache' && arg(3) == 'preset') {
43 $preset = imagecache_preset(arg(4));
47 $t = array('!presetname' => $preset['presetname']);
49 'path' => 'admin/build/imagecache/preset/'.
arg(4) .
'/delete',
50 'title' => t('Delete Preset: !presetname', $t),
51 'callback' => 'drupal_get_form',
52 'callback arguments' => array('imagecache_ui_preset_delete_form', arg(4)),
53 'type' => MENU_CALLBACK
,
56 'path' => 'admin/build/imagecache/preset/'.
arg(4) .
'/flush',
57 'title' => t('Flush Preset: !presetname', $t),
58 'callback' => 'drupal_get_form',
59 'callback arguments' => array('imagecache_ui_preset_flush_form', arg(4)),
60 'access' => user_access('flush imagecache'),
61 'type' => MENU_CALLBACK
,
64 'path' => 'admin/build/imagecache/preset/'.
arg(4),
65 'title' => t('!presetname', $t),
66 'callback' => 'drupal_get_form',
67 'callback arguments' => array('imagecache_ui_preset_form', arg(4)),
68 'type' => MENU_CALLBACK
,
72 'path' => 'admin/build/imagecache/preset/'. arg(4) .'/action/add',
73 'title' => t('Add !action to !presetname', $t),
74 'callback' => 'imagecache_ui_action_add_list',
75 'callback arguments' => array(arg(4)),
76 'type' => MENU_CALLBACK,
79 $definition = imagecache_action_definition(arg(7));
80 if (!empty($definition)) {
81 $t['!action'] = $definition['name'];
83 'path' => 'admin/build/imagecache/preset/'.
arg(4) .
'/action/add/'.
arg(7),
84 'title' => t('Add !action to !presetname', $t),
85 'callback' => 'drupal_get_form',
86 'callback arguments' => array('imagecache_ui_action_add_form', arg(4), arg(7)),
87 'type' => MENU_CALLBACK
,
91 $action = imagecache_action(arg(6));
93 $t['!action'] = $action['name'];
95 'path' => 'admin/build/imagecache/preset/'.
arg(4) .
'/action/'.
arg(6),
96 'title' => t('!action for preset !presetname', $t),
97 'callback' => 'drupal_get_form',
98 'callback arguments' => array('imagecache_ui_action_form', arg(6)),
99 'type' => MENU_CALLBACK
,
103 'path' => 'admin/build/imagecache/preset/'.
arg(4) .
'/action/'.
arg(6) .
'/delete',
104 'title' => t('Delete !action for preset !presetname', $t),
105 'callback' => 'drupal_get_form',
106 'callback arguments' => array('imagecache_ui_action_delete_form', arg(4), arg(6)),
107 'type' => MENU_CALLBACK
,
115 * Preset Admin callbacks and required functions.
118 function imagecache_ui_presets() {
119 $header = array(t('Preset Name'), t('Actions'));
121 foreach(imagecache_presets() as
$preset) {
123 $row[] = l($preset['presetname'], 'admin/build/imagecache/preset/'.
$preset['presetid']);
125 $links[] = l(t('edit'), 'admin/build/imagecache/preset/'.
$preset['presetid']);
126 $links[] = l(t('remove'),'admin/build/imagecache/preset/'.
$preset['presetid'] .
'/delete');
127 $links[] = l(t('flush'),'admin/build/imagecache/preset/'.
$preset['presetid'] .
'/flush' );
128 $row[] = implode (' ', $links);
131 $output = theme('table', $header, $rows);
135 function imagecache_ui_preset_add_form($presetid = 0) {
137 $form['presetname'] = array(
138 '#type' => 'textfield',
140 '#title' => t('Preset Namespace'),
141 '#default_value' => '',
142 '#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.'),
143 '#validate' => array('imagecache_element_presetname_validate' => array()),
145 $form['submit'] = array(
147 '#value' => t('Create New Preset'),
152 function imagecache_ui_preset_add_form_submit($id, $form_values) {
153 $preset = array('presetname' => $form_values['presetname']);
154 $preset = imagecache_preset_save($preset);
155 drupal_set_message(t('Preset "%name" (ID: @id) Created.', array('%name' => $preset['presetname'], '@id' => $preset['presetid'])));
156 return 'admin/build/imagecache';
159 function imagecache_element_presetname_validate($element) {
160 // Check for duplicates
161 $presets = imagecache_presets();
162 if (in_array($element['#value'], $presets)) {
163 form_set_error($element['#name'], t('The namespace you have chosen is already in use.'));
166 // Check for illegal characters in preset names
167 if (preg_match('/[^0-9a-zA-Z_\-]/', $element['#value'])) {
168 form_set_error($element['#name'], t('Please only use alphanumic characters, underscores (_), and hyphens (-) for preset names.'));
172 function imagecache_ui_preset_delete_form($presetid) {
173 $preset = imagecache_preset($presetid);
176 drupal_set_message(t('The specified preset was not found'), 'error');
177 drupal_goto('admin/build/imagecache');
181 $form['presetid'] = array('#type' => 'value', '#value' => $preset['presetid']);
184 t('Are you sure you want to delete the preset %preset?',
185 array('%preset' => $preset['presetname'])
187 'admin/build/imagecache',
188 t('This action cannot be undone.'),
189 t('Delete'), t('Cancel')
193 function imagecache_ui_preset_delete_form_submit($form_id, $form_values) {
194 $preset = imagecache_preset($form_values['presetid']);
195 imagecache_preset_delete($preset);
196 drupal_set_message(t('Preset "%name" (ID: @id) deleted.', array('%name' => $preset['presetname'], '@id' => $preset['presetid'])));
197 return 'admin/build/imagecache';
200 function imagecache_ui_preset_flush_form($presetid) {
201 $preset = imagecache_preset($presetid);
204 drupal_set_message(t('The specified preset was not found'), 'error');
205 drupal_goto('admin/build/imagecache');
209 $form['presetid'] = array('#type' => 'value', '#value' => $preset['presetid']);
212 t('Are you sure you want to flush the preset %preset?',
213 array('%preset' => $preset['presetname'])
215 'admin/build/imagecache',
216 t('This action cannot be undone.'),
217 t('Flush'), t('Cancel')
221 function imagecache_ui_preset_flush_form_submit($form_id, $form_values) {
222 $preset = imagecache_preset($form_values['presetid']);
223 imagecache_preset_flush($preset);
224 drupal_set_message(t('Preset "%name" (ID: @id) flushed.', array('%name' => $preset['presetname'], '@id' => $preset['presetid'])));
225 return 'admin/build/imagecache';
232 function imagecache_ui_preset_form($presetid) {
233 $preset = imagecache_preset($presetid, TRUE
);
236 drupal_set_message(t('The specified preset was not found'), 'error');
237 drupal_goto('admin/build/imagecache');
241 $form['presetname'] = array(
242 '#type' => 'textfield',
244 '#title' => t('Preset Namespace'),
245 '#default_value' => $preset['presetname'],
246 '#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.'),
247 '#validate' => array('imagecache_element_presetname_validate' => array()),
249 $form['presetid'] = array(
251 '#value' => $preset['presetid'],
254 $form['actions'] = array(
255 '#type' => 'fieldset',
256 '#title' => t('Actions'),
258 '#theme' => 'imagecache_ui_preset_actions',
262 foreach($preset['actions'] as
$i => $action) {
263 // skip unknown actions...
264 if(!$definition = imagecache_action_definition($action['action'])) {
267 $action_name = t($definition['name']);
268 $action_form['name'] = array(
269 '#value' => $action_name,
272 $action_form['action'] = array(
274 '#value' => $action['action'],
276 $action_form['actionid'] = array(
278 '#value' => $action['actionid'],
280 $action_form['presetid'] = array(
282 '#value' => $action['presetid'],
285 $action_form['settings'] = array(
286 '#theme' => $action['action'],
287 '#value' => $action['data'],
289 $action_form['data'] = array(
291 '#value' => $action['data'],
293 $action_form['weight'] = array(
295 '#default_value' => $action['weight'],
297 $action_form['configure'] = array(
298 '#value' => l(t('Configure'), 'admin/build/imagecache/preset/'.
$action['presetid'] .
'/action/'.
$action['actionid'] ),
300 $action_form['remove'] = array(
301 '#value' => l(t('Delete'), 'admin/build/imagecache/preset/'.
$action['presetid'] .
'/action/'.
$action['actionid'] .
'/delete'),
303 $form['actions'][$i] = $action_form;
306 $form['actions']['new'] = array(
308 '#type' => 'fieldset',
309 '#title' => t('New Actions'),
310 '#collapsible' => TRUE
,
311 '#collapsed' => TRUE
,
315 foreach(imagecache_action_definitions() as
$action => $definition) {
316 $form['actions']['new'][] = array(
318 '#prefix' => '<div>',
319 '#suffix' => '</div>',
320 '#value' => l(t('Add !action', array('!action' => $definition['name'])),
321 'admin/build/imagecache/preset/'.
$preset['presetid'] .
'/action/add/'.
$action) .
322 ' - '.
$definition['description'],
327 @todo: 404/403 image per preset.
328 @todo: global 404/403 image.
330 $form['files'] = array(
331 '#type' => 'fieldset',
332 '#collapsible' => TRUE,
333 '#collapsed' => TRUE,
334 '#title' => t('Error Files'),
337 $form['files']['403']['file'] = array(
339 '#title' => t('403 Image'),
340 '#description' => t('Image that will be used when access is denied to the source image.'),
343 $path403 = imagecache/'. $preset['presetname'] .'/403.png';
344 if (file_exists($path403)) {
345 $url403 = imagecache_create_url($preset['presetname'], $path403);
347 $form['files']['403']['view'] = array(
348 '#value' => '<img src="'. $url403 .'">',
352 $form['files']['404'] = array(
354 '#title' => t('404 Image'),
355 '#description' => t('Image that will be used when the source image cannot be found.'),
359 $form['submit'] = array(
361 '#value' => t('Update Preset'),
367 function theme_imagecache_admin_title($element) {
368 return '<h2>'.
$element['value'].
'</h2>';
371 function theme_imagecache_ui_preset_actions($element) {
372 $header = array(t('Action'), t('Settings'), t('Weight'), '','');
374 foreach(element_children($element) as
$key) {
376 $row[] = drupal_render($element[$key]['name']);
377 $row[] = drupal_render($element[$key]['settings']);
378 $row[] = drupal_render($element[$key]['weight']);
379 $row[] = drupal_render($element[$key]['configure']);
380 $row[] = drupal_render($element[$key]['remove']);
383 $output .
= theme('table', $header, $rows);
384 $output .
= drupal_render($element);
388 function imagecache_ui_preset_form_submit($form_id, $form_values) {
389 if (isset($form_values['actions'])) {
390 foreach($form_values['actions'] as
$action) {
391 imagecache_action_save($action);
394 imagecache_preset_save($form_values);
395 return 'admin/build/imagecache/preset/'.
$form_values['presetid'];
398 function imagecache_ui_action_form($actionid) {
399 $definitions = imagecache_action_definitions();
401 if (!$action = imagecache_action($actionid)) {
402 drupal_set_message('Unknown Action.'.
$actionid, 'error');
403 drupal_goto('admin/build/imagecache');
406 if (!$preset = imagecache_preset($action['presetid'])) {
407 drupal_set_message('Unknown Preset.');
408 drupal_goto('admin/build/imagecache');
415 $form['actionid'] = array(
417 '#value' => $action['actionid'],
421 if ($definitions[$action['action']]['file']) {
422 require_once($definitions[$action['action']]['file']);
424 $form['data'] = call_user_func($action['action'] .
'_form', $action['data']);
425 $form['submit'] = array(
427 '#value' => t('Update Action'),
432 function imagecache_ui_action_form_submit($form_id, $form_values) {
433 if ($action = imagecache_action($form_values['actionid'])) {
434 $action = array_merge($action, $form_values);
435 imagecache_action_save($action);
436 drupal_set_message('Action Updated');
437 return 'admin/build/imagecache/preset/'.
$action['presetid'];
439 drupal_set_message('Unknown Action: '.
$form_values['actionid']);
440 return 'admin/build/imagecache';
443 function imagecache_ui_action_delete_form($presetid, $actionid) {
444 if (!$action = imagecache_action($actionid)) {
445 drupal_set_message('Unknown Action.'.
$actionid, 'error');
446 drupal_goto('admin/build/imagecache');
448 if (!$preset = imagecache_preset($action['presetid'])) {
449 drupal_set_message('Unknown Preset.');
450 drupal_goto('admin/build/imagecache');
454 $form['actionid'] = array('#type' => 'value', '#value' => $action['actionid']);
457 t('Are you sure you want to delete the !action action from preset !preset?',
458 array('!preset' => $preset['presetname'], '!action' => $action['name'])
460 'admin/build/imagecache',
461 t('This action cannot be undone.'),
462 t('Delete'), t('Cancel')
467 function imagecache_ui_action_delete_form_submit($form_id, $form_values) {
468 $action = imagecache_action($form_values['actionid']);
469 imagecache_action_delete($action);
470 drupal_set_message(t('The action has been deleted.'));
471 return 'admin/build/imagecache/preset/'.
$action['presetid'];
474 function imagecache_ui_action_add_form($presetid, $actionname) {
475 $definition = imagecache_action_definition($actionname);
480 $form['action'] = array(
482 '#value' => $actionname,
484 $form['presetid'] = array(
486 '#value' => $presetid,
488 $form['weight'] = array(
490 '#title' => t('Weight'),
493 $form['data'] = call_user_func($actionname .
'_form', $action['data']);
494 $form['submit'] = array(
496 '#value' => t('Add Action'),
502 function imagecache_ui_action_add_form_submit($form_id, $form_values) {
503 imagecache_action_save($form_values);
504 return 'admin/build/imagecache/preset/'.
$form_values['presetid'];