Index: mm_dir.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/media_mover/contrib/mm_dir/Attic/mm_dir.module,v
retrieving revision 1.1.2.12.2.9
diff -u -p -w -r1.1.2.12.2.9 mm_dir.module
--- mm_dir.module	16 Nov 2009 05:07:24 -0000	1.1.2.12.2.9
+++ mm_dir.module	19 Dec 2009 23:34:03 -0000
@@ -98,6 +98,13 @@ function mm_dir_config_harvest($configur
     '#default_value' => $configuration['file_types'] ? $configuration['file_types'] : 'avi mov wmv mpeg mp4 mpeg2 dv 3gp 3g2 mpeg4',
     '#description' => t('Space separated list of file types that can be harvested. These are file extensions and are values like "avi mov wmv mpeg mp4 mpeg2 dv".'),
   );
+  $form['mm_dir_conf']['imagecache_association'] = array(
+    '#title' => t('Find node association for files created by imagecache'),
+    '#type' => 'checkbox',
+    '#default_value' => 0,
+    '#description' => t('If a harvested file appears to have been generated by imagecache, attempt to find the original file, and use its node association if one exists. This is useful if you have another media mover configuration that harvests files from a cck field.'),
+  );
+
   return $form;
 }
 
@@ -211,11 +218,32 @@ function mm_dir_harvest ($configuration)
         // now we need to see if we have this file in the database. Note that in
         // this instance, we are not checking dates on files vs. the database
         $result = db_fetch_array(db_query('SELECT mmfid FROM {media_mover_files} WHERE cid = %d AND harvest_file = "%s"', $configuration['cid'], $file->filename));
+
   	    if (! $result) {
+          if ($configuration['imagecache_association'] == 1) { 
+            // check if the file was created by imagecache
+            $pattern = '/imagecache\/*.*\//';
+            preg_match($pattern, $file->filename, $matches, PREG_OFFSET_CAPTURE, 3);
+            if (!empty($matches)) {
+              $original_file = str_replace($matches[0][0], '', $file->filename);
+              $nid = db_result(db_query('SELECT nid FROM {media_mover_files} WHERE harvest_file="%s"', $original_file));
+
+              // check if the original file has a node association and return it if so
+              if ($nid) {
+                $files[] = array('harvest_file' => $file->filename, 'nid' => $nid);
+              } 
+            }
+            else {
+              $files[] = array('harvest_file' => $file->filename);
+            }
+          } 
+          else {
           $files[] = array('harvest_file' => $file->filename);
         }
 	    }
     }
+    }
+
     // if we have files, return them
   	if (count($files)) {
   	  return $files;
