? imagecache-374202-7.patch
? imagecache-374202.33.patch
Index: imagecache.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache.module,v
retrieving revision 1.112.2.6
diff -u -p -r1.112.2.6 imagecache.module
--- imagecache.module	3 May 2010 16:15:55 -0000	1.112.2.6
+++ imagecache.module	3 May 2010 18:51:22 -0000
@@ -1103,3 +1103,134 @@ 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['presetname'], $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'] : array(),
+  );
+  return $form;
+}
+
+/**
+ * Implementation of hook_submit().
+ */
+function imagecache_generate_action_submit($form, $form_state) {
+  $presets = array();
+  // Only return if the preset is not empty.
+  $presets['imagecache_presets'] = array_filter($form_state['values']['presets']);
+  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);
+  $destination = imagecache_create_path($preset['presetname'], $filepath);
+  if (!file_exists($destination)) {
+    imagecache_build_derivative($preset['actions'], $filepath, $destination);
+  }
+}
