--- imagecache\imagecache.module	Tue Feb 17 13:36:18 2009
+++ imagecache\imagecache_new.module	Tue Feb 17 15:02:58 2009
@@ -1055,3 +1055,98 @@
   imagecache_preset_flush($preset);
   imagecache_presets(true);
 }
+
+/**
+ * Implementation of hook_action_info().
+ * 
+ */
+function imagecache_action_info() {
+  return array(
+    'imagecache_node_refresh_action' => array(
+       'type' => 'node',
+       'description' => t('Regenerate nodes images (flush + generate)'),
+       'configurable' => FALSE,
+       'hooks' => array(
+         'nodeapi' => array('presave', 'insert', 'update', 'view'),
+       )
+    )
+  );
+}
+
+/**
+ * Regenerate all pictures in a given node
+ * @param &$node
+ *   
+ * 
+ * Notes
+ *   This is a slow function, since it waits for each derivative to be generated
+ */
+function imagecache_node_refresh_action(&$node, $context) {
+  $paths = imagecache_get_filepaths_via_nid($node->nid);
+  foreach ($paths as $path) {
+    if ($path['type'] == 'image') {
+      imagecache_image_flush($path['path']);
+      imagecache_generate_all_presets($path['path']);
+    }
+  }
+}
+
+
+/**
+ * Get all filefield files connected to a node id.
+ * @param $nid
+ *   The Node ID.
+ * 
+ * Returns array()
+ *   ['fid'] = file id
+ *   ['type'] = type of cck field
+ *   ['path'] = path to file
+ *
+ * Notes
+ *   Does not return imagecache child files, only the base file.
+ */
+function imagecache_get_filepaths_via_nid($nid)
+{
+  $fids = array();
+  $filepaths = array();
+  foreach (content_fields() as $field) {
+    // If Field is an Image (imagefield.module) or filefield then
+    if ($field['type'] == 'image' || $field['type'] == 'filefield') {
+      $db_info = content_database_info($field);
+      // Get Content Type DB name - FROM statement
+      $tablename = $db_info['table'];
+      //Get File ID DB Column Name - SELECT statement
+      $fid_column = $db_info['columns']['fid']['column'];
+      
+      //get file id's
+      $sql = "SELECT ".$fid_column." FROM ".$tablename." WHERE nid = '%s'";
+      $result = db_query($sql, array($nid));
+      while ($fileid_row = db_fetch_array($result)) {
+        $fids[] = array('fid' => $fileid_row[$fid_column], 'type' => $field['type']);
+      }
+    }
+  }
+  foreach ($fids as $fid) {
+    //get paths for file id
+    $sql = "SELECT filepath FROM files WHERE fid = '%s'";
+    $result = db_query($sql, array($fid['fid']));
+    while ($filepath_row = db_fetch_array($result)) {
+      $filepaths[] = array('fid' => $fid['fid'], 'type' => $fid['type'], 'path' => $filepath_row['filepath']);
+    }
+  }
+  return $filepaths;
+}
+
+/**
+ * Request URI, thus generating pic 
+ * @param $path
+ *   The path to the orginal file
+ * 
+ * Notes
+ *   This is a slow function, since it waits for each derivative to be generated
+ */
+function imagecache_generate_all_presets($path) {
+  foreach (imagecache_presets() as $preset) {
+    file_get_contents(base_url.$base_path.imagecache_create_path($preset['presetname'], $path));
+  }
+}
\ No newline at end of file
