? imagecache-374202-1.patch
? imagecache-374202-2.patch
? imagecache-374202-3.patch
? imagecache-374202-4.patch
? imagecache-374202-5.patch
? imagecache-374202-6.patch
Index: imagecache.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache.module,v
retrieving revision 1.112.2.5
diff -u -p -r1.112.2.5 imagecache.module
--- imagecache.module	19 Aug 2009 20:59:07 -0000	1.112.2.5
+++ imagecache.module	2 Apr 2010 17:20:49 -0000
@@ -1103,3 +1103,137 @@ function imagecache_action_delete($actio
   imagecache_preset_flush($preset);
   imagecache_presets(TRUE);
 }
+
+/**
+ * Implementation of hook_action_info().
+ */
+function imagecache_action_info() {
+  return array(
+    'imagecache_flush_action' => array(
+      'type' => 'node',
+      'description' => t('Flush all imagecache presets for this node'),
+      'configurable' => FALSE,
+      'hooks' => array(
+        'nodeapi' => array('presave', 'delete', 'insert', 'update'),
+      )
+    ),
+    'imagecache_generate_all_action' => array(
+      'type' => 'node',
+      'description' => t('Generate ALL imagecache presets for this node'),
+      'configurable' => FALSE,
+      'hooks' => array(
+        'nodeapi' => array('presave', 'insert', 'update'),
+      )
+    ),
+    'imagecache_generate_action' => array(
+      'type' => 'node',
+      'description' => t('Generate Configured imagecache preset(s) for this node'),
+      'configurable' => TRUE,
+      'hooks' => array(
+        'nodeapi' => array('presave', 'insert', 'update'),
+      )
+    ),
+  );
+}
+
+/**
+ * Flush all imagecache presets for a given node.
+ *
+ * @param &$node
+ *   A node object.
+ * @param $context
+ *   Contains values from the calling action.
+ */
+function imagecache_flush_action(&$node, $context) {
+  $files = filefield_get_node_files($node);
+  foreach ($files as $file) {
+    if (stristr($file['filemime'], 'image')) {
+      imagecache_image_flush($file['filepath']);
+    }
+  }
+}
+
+/**
+ * Generate all imagecache presets for the given node.
+ *
+ * @param &$node
+ *   A node object.
+ * @param $context
+ *   Contains values from the calling action.
+ */
+function imagecache_generate_all_action(&$node, $context) {
+  $files = filefield_get_node_files($node);
+  foreach ($files as $file) {
+    if (stristr($file['filemime'], 'image')) {
+      foreach (imagecache_presets() as $presetname) {
+        imagecache_generate_image($presetname['imagecache_presets'], $file['filepath']);
+      }
+    }
+  }
+}
+
+/**
+ * Generate imagecache presets for the given node and presets.
+ *
+ * @param &$node
+ *   A node object.
+ * @param $context
+ *   Contains values from the calling action.
+ */
+function imagecache_generate_action(&$node, $context) {
+  $files = filefield_get_node_files($node);
+  foreach ($files as $file) {
+    if (stristr($file['filemime'], 'image')) {
+      foreach ($context['imagecache_presets'] as $presetname) {
+        imagecache_generate_image($presetname, $file['filepath']);
+      }
+    }
+  }
+}
+
+/**
+ * Implementation of hook_form().
+ */
+function imagecache_generate_action_form($context) {
+  $options = array();
+  foreach (imagecache_presets() as $preset) {
+    $options[$preset['presetname']] = $preset['presetname'];
+  }
+  $form['presets'] = array(
+    '#type' => 'checkboxes',
+    '#options' => $options,
+    '#description' => t('Select which imagecache presets will be effected'),
+    '#required' => TRUE,
+    '#default_value' => isset($context['imagecache_presets']) ? $context['imagecache_presets'] : '',
+  );
+  return $form;
+}
+
+/**
+ * Implementation of hook_submit().
+ */
+function imagecache_generate_action_submit($form, $form_state) {
+  $presets = array();
+  foreach ($form_state['values']['presets'] as $preset) {
+    if (!empty($preset)) {
+      $presets['imagecache_presets'][] = $preset;
+    }
+  }
+  return $presets;
+}
+
+/**
+ * Generate imagecache image given presetname and filepath.
+ *
+ * @param $presetname
+ *   Imagecache preset.
+ * @param $filepath
+ *   filepath from the files table.
+ */
+function imagecache_generate_image($presetname, $filepath) {
+  $preset = imagecache_preset_by_name($presetname);
+  $dst = imagecache_create_path($preset['presetname'], $filepath);
+  if (!file_exists($dst)) {
+    imagecache_build_derivative($preset['actions'], $filepath, $dst);
+  }
+}
