'admin/build/imagecache', 'title' => t('Imagecache'), 'description' => t('Administer imagecache presets and actions.'), 'callback' => 'imagecache_ui_presets', 'access' => user_access('administer imagecache'), ); $items[] = array( 'path' => 'admin/build/imagecache/list', 'title' => t('List'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items[] = array( 'path' => 'admin/build/imagecache/add', 'title' => t('Add New Preset'), 'callback' => 'drupal_get_form', 'callback arguments' => array('imagecache_ui_preset_add_form'), 'access' => user_access('administer imagecache'), 'type' => MENU_LOCAL_TASK, ); } // Use Dynamic menu items to get better breadcrumb trails by default. elseif (arg(0) == 'admin' && arg(1) == 'build' && arg(2) == 'imagecache' && arg(3) == 'preset') { $preset = imagecache_preset(arg(4)); if (empty($preset)) { return $items; } $t = array('!presetname' => $preset['presetname']); $items[] = array( 'path' => 'admin/build/imagecache/preset/'. arg(4) .'/delete', 'title' => t('Delete Preset: !presetname', $t), 'callback' => 'drupal_get_form', 'callback arguments' => array('imagecache_ui_preset_delete_form', arg(4)), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/build/imagecache/preset/'. arg(4) .'/flush', 'title' => t('Flush Preset: !presetname', $t), 'callback' => 'drupal_get_form', 'callback arguments' => array('imagecache_ui_preset_flush_form', arg(4)), 'access' => user_access('flush imagecache'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/build/imagecache/preset/'. arg(4), 'title' => t('!presetname', $t), 'callback' => 'drupal_get_form', 'callback arguments' => array('imagecache_ui_preset_form', arg(4)), 'type' => MENU_CALLBACK, ); $definition = imagecache_action_definition(arg(7)); if (!empty($definition)) { $t['!action'] = $definition['name']; $items[] = array( 'path' => 'admin/build/imagecache/preset/'. arg(4) .'/action/add/'. arg(7), 'title' => t('Add !action to !presetname', $t), 'callback' => 'drupal_get_form', 'callback arguments' => array('imagecache_ui_action_add_form', arg(4), arg(7)), 'type' => MENU_CALLBACK, ); } $action = imagecache_action(arg(6)); if ($action) { $t['!action'] = $action['name']; $items[] = array( 'path' => 'admin/build/imagecache/preset/'. arg(4) .'/action/'. arg(6), 'title' => t('!action for preset !presetname', $t), 'callback' => 'drupal_get_form', 'callback arguments' => array('imagecache_ui_action_form', arg(6)), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/build/imagecache/preset/'. arg(4) .'/action/'. arg(6) .'/delete', 'title' => t('Delete !action for preset !presetname', $t), 'callback' => 'drupal_get_form', 'callback arguments' => array('imagecache_ui_action_delete_form', arg(4), arg(6)), 'type' => MENU_CALLBACK, ); } } return $items; } /** * Preset Admin callbacks and required functions. */ function imagecache_ui_presets() { $header = array(t('Preset Name'), t('Actions')); $rows = array(); foreach (imagecache_presets() as $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' ); $row[] = implode(' ', $links); $rows[] = $row; } $output = theme('table', $header, $rows); return $output; } function imagecache_ui_preset_add_form($presetid = 0) { $form = array(); $form['presetname'] = array( '#type' => 'textfield', '#size' => '64', '#title' => t('Preset Namespace'), '#default_value' => '', '#description' => t('The namespace is used in URLs for images to tell imagecache how to process an image. Please only use alphanumeric characters, underscores (_), and hyphens (-) for preset names.'), '#validate' => array('imagecache_element_presetname_validate' => array()), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Create New Preset'), ); return $form; } function imagecache_ui_preset_add_form_submit($id, $form_values) { $preset = array('presetname' => $form_values['presetname']); $preset = imagecache_preset_save($preset); drupal_set_message(t('Preset "%name" (ID: @id) Created.', array('%name' => $preset['presetname'], '@id' => $preset['presetid']))); return 'admin/build/imagecache/preset/'. $preset['presetid']; } function imagecache_element_presetname_validate($element) { // Check for duplicates $presets = imagecache_presets(); if (in_array($element['#value'], $presets)) { form_set_error($element['#name'], t('The namespace you have chosen is already in use.')); } // Check for illegal characters in preset names if (preg_match('/[^0-9a-zA-Z_\-]/', $element['#value'])) { form_set_error($element['#name'], t('Please only use alphanumeric characters, underscores (_), and hyphens (-) for preset names.')); } } function imagecache_ui_preset_delete_form($presetid) { $preset = imagecache_preset($presetid); if (!$preset) { drupal_set_message(t('The specified preset was not found'), 'error'); drupal_goto('admin/build/imagecache'); } $form = array(); $form['presetid'] = array('#type' => 'value', '#value' => $preset['presetid']); return confirm_form( $form, t('Are you sure you want to delete the preset %preset?', array('%preset' => $preset['presetname']) ), 'admin/build/imagecache', t('This action cannot be undone.'), t('Delete'), t('Cancel') ); } function imagecache_ui_preset_delete_form_submit($form_id, $form_values) { $preset = imagecache_preset($form_values['presetid']); imagecache_preset_delete($preset); drupal_set_message(t('Preset "%name" (ID: @id) deleted.', array('%name' => $preset['presetname'], '@id' => $preset['presetid']))); return 'admin/build/imagecache'; } function imagecache_ui_preset_flush_form($presetid) { $preset = imagecache_preset($presetid); if (!$preset) { drupal_set_message(t('The specified preset was not found'), 'error'); drupal_goto('admin/build/imagecache'); } $form = array(); $form['presetid'] = array('#type' => 'value', '#value' => $preset['presetid']); return confirm_form( $form, t('Are you sure you want to flush the preset %preset?', array('%preset' => $preset['presetname']) ), 'admin/build/imagecache', t('This action cannot be undone.'), t('Flush'), t('Cancel') ); } function imagecache_ui_preset_flush_form_submit($form_id, $form_values) { $preset = imagecache_preset($form_values['presetid']); imagecache_preset_flush($preset); drupal_set_message(t('Preset "%name" (ID: @id) flushed.', array('%name' => $preset['presetname'], '@id' => $preset['presetid']))); return 'admin/build/imagecache'; } function imagecache_ui_preset_form($presetid) { $preset = imagecache_preset($presetid, true); if (!$preset) { drupal_set_message(t('The specified preset was not found'), 'error'); drupal_goto('admin/build/imagecache'); } $form = array(); $form['presetname'] = array( '#type' => 'textfield', '#size' => '64', '#title' => t('Preset Namespace'), '#default_value' => $preset['presetname'], '#description' => t('The namespace is used in URLs for images to tell imagecache how to process an image. Please only use alphanumeric characters, underscores (_), and hyphens (-) for preset names.'), '#validate' => array('imagecache_element_presetname_validate' => array()), ); $form['presetid'] = array( '#type' => 'value', '#value' => $preset['presetid'], ); $form['actions'] = array( '#type' => 'fieldset', '#title' => t('Actions'), '#tree' => true, '#theme' => 'imagecache_ui_preset_actions', ); foreach ($preset['actions'] as $i => $action) { // skip unknown actions... if (!$definition = imagecache_action_definition($action['action'])) { continue; } $action_name = t($definition['name']); $action_form['name'] = array( '#value' => $action_name, ); $action_form['action'] = array( '#type' => 'value', '#value' => $action['action'], ); $action_form['actionid'] = array( '#type' => 'value', '#value' => $action['actionid'], ); $action_form['presetid'] = array( '#type' => 'value', '#value' => $action['presetid'], ); $action_form['settings'] = array( '#theme' => $action['action'], '#value' => $action['data'], ); $action_form['data'] = array( '#type' => 'value', '#value' => $action['data'], ); $action_form['weight'] = array( '#type' => 'weight', '#default_value' => $action['weight'], ); $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' => '