This file is indexed.

/usr/share/drupal6/modules/imagecache/imagecache_ui.pages.inc is in drupal6-mod-imagecache 2.0~beta10-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
<?php
// $Id: imagecache_ui.pages.inc,v 1.6 2009/05/03 17:27:46 drewish Exp $

/**
 * Preset Admin callbacks and required functions.
 */
function imagecache_ui_preset_overview() {
  $header = array(t('Preset Name'), t('Storage'), t('Actions'));
  $rows = array();
  // Always clear the preset cache on this display.
  foreach (imagecache_presets(TRUE) as $preset) {
    $row = array();
    $row[] = l($preset['presetname'], 'admin/build/imagecache/'. $preset['presetid']);
    $links = array();
    switch ($preset['storage']) {
      case IMAGECACHE_STORAGE_DEFAULT:
        $row[] = t('Default');
        $links[] = l(t('View'), 'admin/build/imagecache/'. $preset['presetid']);
        $links[] = l(t('Flush'), 'admin/build/imagecache/'. $preset['presetid'] .'/flush' );
        break;
      case IMAGECACHE_STORAGE_OVERRIDE:
        $row[] = t('Override');
        $links[] = l(t('Edit'), 'admin/build/imagecache/'. $preset['presetid']);
        $links[] = l(t('Revert'), 'admin/build/imagecache/'. $preset['presetid'] .'/delete');
        $links[] = l(t('Flush'), 'admin/build/imagecache/'. $preset['presetid'] .'/flush' );
        $links[] = l(t('Export'), 'admin/build/imagecache/'. $preset['presetid'] .'/export' );
        break;
      case IMAGECACHE_STORAGE_NORMAL:
        $row[] = t('Normal');
        $links[] = l(t('Edit'), 'admin/build/imagecache/'. $preset['presetid']);
        $links[] = l(t('Delete'), 'admin/build/imagecache/'. $preset['presetid'] .'/delete');
        $links[] = l(t('Flush'), 'admin/build/imagecache/'. $preset['presetid'] .'/flush' );
        $links[] = l(t('Export'), 'admin/build/imagecache/'. $preset['presetid'] .'/export' );
        break;
    }
    $row[] = implode('&nbsp;&nbsp;&nbsp;&nbsp;', $links);
    $rows[] = $row;
  }
  $output = theme('table', $header, $rows);
  return $output;
}

function imagecache_ui_preset_delete_form($form_state, $preset = array()) {
  if (empty($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, &$form_state) {
  $preset = imagecache_preset($form_state['values']['presetid']);
  imagecache_preset_delete($preset);
  drupal_set_message(t('Preset %name (ID: @id) was deleted.', array('%name' => $preset['presetname'], '@id' => $preset['presetid'])));
  $form_state['redirect'] = 'admin/build/imagecache';
}


function imagecache_ui_preset_flush_form(&$form_state, $preset = array()) {
  if (empty($preset)) {
    drupal_set_message(t('The specified preset was not found'), 'error');
    $form_state['redirect'] = '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, &$form_state) {
  $preset = imagecache_preset($form_state['values']['presetid']);
  imagecache_preset_flush($preset);
  drupal_set_message(t('Preset %name (ID: @id) was flushed.', array('%name' => $preset['presetname'], '@id' => $preset['presetid'])));
  $form_state['redirect'] = 'admin/build/imagecache';
}


/**
 * Imagecache preset export form.
 */
function imagecache_ui_preset_export_form(&$form_state, $preset = array()) {
  if (empty($preset)) {
    drupal_set_message(t('The specified preset was not found'), 'error');
    $form_state['redirect'] = 'admin/build/imagecache';
  }

  if (isset($preset['presetid'])) {
    unset($preset['presetid']);
  }
  if (isset($preset['storage'])) {
    unset($preset['storage']);
  }
  foreach ($preset['actions'] as $id => $action) {
    unset($preset['actions'][$id]['actionid']);
    unset($preset['actions'][$id]['presetid']);
  }
  $exported = '$presets = array();';
  $exported .= "\n";
  $exported .= '$presets[\''. $preset['presetname'] .'\'] = ';
  $exported .= var_export($preset, TRUE) .';';
  $rows = substr_count($exported, "\n") + 1;

  $form = array();
  $form['export'] = array(
    '#type' => 'textarea',
    '#default_value' => $exported,
    '#rows' => $rows,
    '#resizable' => FALSE,
  );
  return $form;
}


function imagecache_ui_preset_form($form_state, $preset = array()) {
  $form = array();

  $form['presetid'] = array(
    '#type' => 'value',
    '#value' => $preset['presetid'],
  );

  // Browsers don't submit disabled form values so we've got to put two copies
  // of the name on the form: one for the submit handler and one for the user.
  if ($preset['storage'] === IMAGECACHE_STORAGE_DEFAULT) {
    $form['presetname'] = array(
      '#type' => 'value',
      '#value' => $preset['presetname'],
    );
    $form['presetname_display'] = array(
      '#type' => 'textfield',
      '#size' => '64',
      '#title' => t('Preset Namespace'),
      '#default_value' => $preset['presetname'],
      '#disabled' => TRUE,
    );
  }
  else {
    $form['presetname'] = array(
      '#type' => 'textfield',
      '#size' => '64',
      '#title' => t('Preset Namespace'),
      '#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 alphanumeric characters, underscores (_), and hyphens (-) for preset names.'),
      '#validate' => array('imagecache_element_presetname_validate' => array()),
    );
  }

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => $preset['storage'] === IMAGECACHE_STORAGE_DEFAULT ? t('Override Defaults') : t('Save Preset'),
    '#weight' => 9,
  );

  // For new presets don't show the preview or all actions to be added.
  if (empty($preset['presetid'])) {
    return $form;
  }

  $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_form['name'] = array(
      '#value' => t($definition['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'],
      '#access' => $preset['storage'] !== IMAGECACHE_STORAGE_DEFAULT,
    );
    $action_form['configure'] = array(
      '#value' => l(t('Configure'), 'admin/build/imagecache/'. $action['presetid'] .'/'. $action['actionid'] ),
      '#access' => $preset['storage'] !== IMAGECACHE_STORAGE_DEFAULT,
    );
    $action_form['remove'] = array(
      '#value' => l(t('Delete'), 'admin/build/imagecache/'. $action['presetid'] .'/'. $action['actionid'] .'/delete'),
      '#access' => $preset['storage'] !== IMAGECACHE_STORAGE_DEFAULT,
    );
    $form['actions'][$i] = $action_form;
  }

  $form['actions']['new'] = array(
    '#tree' => FALSE,
    '#type' => 'fieldset',
    '#title' => t('New Actions'),
    '#collapsible' => TRUE,
    '#collapsed' => count($preset['actions']) > 0,
    '#access' => $preset['storage'] !== IMAGECACHE_STORAGE_DEFAULT,
  );
  foreach (imagecache_action_definitions() as $action => $definition) {
    $form['actions']['new'][] = array(
      '#type' => 'markup',
      '#prefix' => '<div>',
      '#suffix' => '</div>',
      '#value' => l(t('Add !action', array('!action' => $definition['name'])),
                    'admin/build/imagecache/'.  $preset['presetid'] .'/add/'. $action) .
                    ' - '. $definition['description'],
    );
  }

  // Display a preview image for this action. Put it below the submit button so
  // users don't have to do a bunch of scrolling.
  $preview_path = file_create_path('imagecache_sample.png');
  if (!file_exists($preview_path)) {
    // Copy of the image into the files directory so rather than generating it
    // from the original so we don't end up creating subdirectories mirroring
    // the path to the this module.
    $preview_path = drupal_get_path('module', 'imagecache_ui') .'/sample.png';
    file_copy($preview_path, 'imagecache_sample.png');
  }
  imagecache_image_flush($preview_path);
  $imagecache_path = imagecache_create_url($preset['presetname'], $preview_path, TRUE);
  $form['preview'] = array(
    '#type' => 'item',
    '#title' => t('Preview'),
    '#value' => l($imagecache_path, $imagecache_path) .'<br />'. l("<img src='$imagecache_path' />", $imagecache_path, array('html' => TRUE)),
    '#weight' => 10,
  );

  return $form;
}

function imagecache_ui_preset_form_validate($form, &$form_state) {
  $values = $form_state['values'];
  // Check for duplicates
  foreach (imagecache_presets() as $preset) {
    if ($values['presetname'] == $preset['presetname'] && $values['presetid'] != $preset['presetid']) {
      form_set_error('presetname', t('The preset name you have chosen is already in use.'));
      break;
    }
  }

  // Check for illegal characters in preset names
  if (preg_match('/[^0-9a-zA-Z_\-]/', $values['presetname'])) {
    form_set_error('presetname', t('Please only use alphanumeric characters, underscores (_), and hyphens (-) for preset names.'));
  }
}

function imagecache_ui_preset_form_submit($form, &$form_state) {
  // Save the preset first to retrieve the presetid when overriding
  $preset = imagecache_preset_save($form_state['values']);

  // Populate the presetid as needed for overrides
  if (isset($form_state['values']['actions'])) {
    foreach($form_state['values']['actions'] as $action) {
      if (empty($action['presetid'])) {
        $action['presetid'] = $preset['presetid'];
      }
      imagecache_action_save($action);
    }
  }

  // Push back to the preset form
  $form_state['redirect'] = 'admin/build/imagecache/'. $preset['presetid'];
}

function theme_imagecache_ui_preset_actions($form) {
  $header = array(t('Action'), t('Settings'));
  // $header = array(, t('Weight'), '','');
  $rows = array();
  foreach(element_children($form) as $key) {
    if (!is_numeric($key)) {
      continue;
    }
    $row = array();
    $row[] = drupal_render($form[$key]['name']);
    $row[] = drupal_render($form[$key]['settings']);

    // Check for form access before rendering these portions of the table / header
    if (!empty($form[$key]['weight']['#access'])) {
      if (empty($header['weight'])) {
        $header['weight'] = t('Weight');
      }
      $form[$key]['weight']['#attributes']['class'] = 'imagecache-action-order-weight';
      $row[] = drupal_render($form[$key]['weight']);
    }
    if (!empty($form[$key]['configure']['#access'])) {
      if (empty($header['configure'])) {
        $header['configure'] = '';
      }
      $row[] = drupal_render($form[$key]['configure']);
    }
    if (!empty($form[$key]['remove']['#access'])) {
      if (empty($header['remove'])) {
        $header['remove'] = '';
      }
      $row[] = drupal_render($form[$key]['remove']);
    }
    $rows[] = array(
      'data' => $row,
      'class' => 'draggable',
    );
  }

  $output = '';
  if ($rows) {
    drupal_add_tabledrag('imagecache-preset-actions', 'order', 'sibling', 'imagecache-action-order-weight');
    $output = theme('table', $header, $rows, array('id' => 'imagecache-preset-actions'));
  }
  $output .= drupal_render($form);
  return $output;
}


/**
 * Page with form for adding a new action to add to a preset.
 */
function imagecache_ui_action_add_page($preset, $actionname) {
  // Make sure the name is valid.
  if (!$definition = imagecache_action_definition($actionname)) {
    drupal_set_message(t('Unknown action.'), 'error');
    drupal_goto('admin/build/imagecache/'. $preset['presetid']);
  }
  $action = array(
    'presetid' => $preset['presetid'],
    'action' => $actionname,
    'data' => array(),
  );
  return drupal_get_form('imagecache_ui_action_form', $preset, $action);
}


function imagecache_ui_action_form($form_state, $preset, $action) {
  // Do some error checking.
  if (empty($preset['presetid'])) {
    drupal_set_message(t('Unknown preset.'), 'error');
    drupal_goto('admin/build/imagecache');
  }
  if (empty($action['action']) || !$definition = imagecache_action_definition($action['action'])) {
    drupal_set_message(t('Unknown action.'), 'error');
    drupal_goto('admin/build/imagecache/'. $preset['presetid']);
  }
  if ($action['presetid'] != $preset['presetid']) {
    drupal_set_message(t('This %action action is not associated %preset preset.', array('%action' => $action['action'], '%preset' => $preset['presetname'])), 'error');
    drupal_goto('admin/build/imagecache/'. $preset['presetid']);
  }

  $form['#tree'] = TRUE;
  $form['presetid'] = array(
    '#type' => 'value',
    '#value' => $action['presetid'],
  );
  $form['actionid'] = array(
    '#type' => 'value',
    '#value' => $action['actionid'],
  );
  $form['action'] = array(
    '#type' => 'value',
    '#value' => $action['action'],
  );

  if (!empty($definition['file'])) {
    require_once($definition['file']);
  }
  if (function_exists($action['action'] .'_form')) {
    $form['data'] = call_user_func($action['action'] .'_form', $action['data']);
  }

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => empty($action['actionid']) ? t('Create Action') : t('Update Action'),
  );
  return $form;
}

function imagecache_ui_action_form_submit($form, &$form_state) {
  imagecache_action_save($form_state['values']);
  if (empty($form_state['values']['presetid'])) {
    drupal_set_message(t('The action was succesfully created.'));
  }
  else {
    drupal_set_message(t('The action was succesfully updated.'));
  }
  $form_state['redirect'] = 'admin/build/imagecache/'. $form_state['values']['presetid'];
}


function imagecache_ui_action_delete_form($form_state, $preset = array(), $action = array()) {
  if (empty($action)) {
    drupal_set_message(t('Unknown Action.'), 'error');
    drupal_goto('admin/build/imagecache');
  }
  if (empty($preset)) {
    drupal_set_message(t('Unknown Preset.'), 'error');
    drupal_goto('admin/build/imagecache');
  }

  $form = array();
  $form['actionid'] = array('#type' => 'value', '#value' => $action['actionid']);
  return confirm_form(
    $form,
    t('Are you sure you want to delete the !action action from preset !preset?',
      array('!preset' => $preset['presetname'], '!action' => $action['name'])
    ),
    'admin/build/imagecache',
    t('This action cannot be undone.'),
    t('Delete'),  t('Cancel')
  );
}

function imagecache_ui_action_delete_form_submit($form, &$form_state) {
  $action = imagecache_action($form_state['values']['actionid']);
  imagecache_action_delete($action);
  drupal_set_message(t('The action has been deleted.'));
  $form_state['redirect'] = 'admin/build/imagecache/'. $action['presetid'];
}