Index: /Users/rob/Sites/dev/chipin/sprout/manager/trunk/htdocs/sites/all/modules/media_mover/media_mover.module
===================================================================
--- /Users/rob/Sites/dev/chipin/sprout/manager/trunk/htdocs/sites/all/modules/media_mover/media_mover.module	(revision 359)
+++ /Users/rob/Sites/dev/chipin/sprout/manager/trunk/htdocs/sites/all/modules/media_mover/media_mover.module	(working copy)
@@ -14,9 +14,9 @@
   * @ TODO think through how to add non file based content- modules can create their own db tables
   *        and store data pertanent to them. A secondary concern is how to deal with content that
   *        is not associated with a specific node. Modules can perhaps create their own nodes for this...
-  *        
+  *
   *        update- this has started to be addressed with how modules harvest- there is the $file array which
-  *        has $file['data']['node'] and $file['data']['user'] which is useful for saving things. 
+  *        has $file['data']['node'] and $file['data']['user'] which is useful for saving things.
   *
   * @ TODO stop unnecessarily making objects
   *
@@ -53,7 +53,7 @@
       'access' => user_access('administer media_mover'),
       'type' => MENU_NORMAL_ITEM,
     );
-    
+
     // main page
     $items[] = array(
       'path' => 'admin/media_mover/default',
@@ -85,7 +85,7 @@
       'access' => user_access('administer media_mover'),
       'type' => MENU_NORMAL_ITEM, // optional
      );
- 
+
     // add a new configuration
     $items[] = array(
       'path' => 'admin/media_mover/config/add',
@@ -104,11 +104,11 @@
       'access' => user_access('administer media_mover'),
       'type' => MENU_LOCAL_TASK,
       'weight' => -9,
-    );     
+    );
   } // $may_cache
-   
-   
-  // Non cachable menu items  
+
+
+  // Non cachable menu items
   // edit an existing configuration
   $items[] = array(
     'path' => 'admin/media_mover/config/edit',
@@ -128,7 +128,7 @@
     'type' => MENU_CALLBACK,
     'callback arguments' => array(arg(4)),
   );
-  
+
   // reset an existing configuration
   $items[] = array(
     'path' => 'admin/media_mover/config/reset',
@@ -138,7 +138,7 @@
     'type' => MENU_CALLBACK,
     'callback arguments' => array(arg(4)),
   );
-  
+
   // reset an existing configuration and remove files
   $items[] = array(
     'path' => 'admin/media_mover/config/reset/full',
@@ -148,7 +148,7 @@
     'type' => MENU_CALLBACK,
     'callback arguments' => array(arg(5)),
   );
-  
+
   // test run configurations
   $items[] = array(
     'path' => 'admin/media_mover/test',
@@ -159,7 +159,7 @@
     'type' => MENU_LOCAL_TASK,
     'weight' => -10,
   );
-  
+
   // edit a file
   $items[] = array(
     'path' => 'admin/media_mover/file/edit',
@@ -179,13 +179,13 @@
     'type' => MENU_CALLBACK,
     'callback arguments' => array(arg(4)),
   );
-  
+
   return $items;
 }
 
 /**
  * Implementation of hook_settings
- * calls all of the media mover modules which 
+ * calls all of the media mover modules which
  * implement the 'admin' param
  */
 function media_mover_admin_settings() {
@@ -220,7 +220,7 @@
  * @param $cid is a configuration id
  */
 function media_mover_test($cid = null) {
-  if (! $cid) { 
+  if (! $cid) {
     $configurations = _mm_get_active_configurations();
     $output = t('Running all configurations') .'<br /><hr><br />';
     foreach ($configurations as $config) {
@@ -238,26 +238,25 @@
 }
 
 /**
- * Implementation of nodeapi
+ * Implementation of hook_nodeapi().
  */
 function media_mover_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
   switch ($op) {
-    case "load":
-      $node->media_mover = _mm_files_db_fetch($node->nid);
-      return $node;
-    break;
+    case 'load':
+      if ($files = _mm_files_db_fetch($node->nid)) {
+        return array('media_mover' => $files);
+      }
+      break;
 
-    case "view":
+    case 'view':
       // Add the attachments list to node body
-      if (count($node->media_mover) > 0) {
-       $node->body .= theme('media_mover_files', $node->media_mover);
+      if (isset($node->media_mover)) {
+        $node->content['media_mover'] = array(
+          '#value' => theme('media_mover_files', $node->media_mover),
+          '#weight' => 10,
+        );
       }
-      return $node;
-    break;
-
-    case "prepare":
-
-    break;
+      break;
   }
 }
 
@@ -296,14 +295,14 @@
 function _media_mover_run_config($config, $debug = true) {
 
   // check to see if this config is running
-  if (!  _mm_configuration_is_running($config->cid)) {   
-    
+  if (!  _mm_configuration_is_running($config->cid)) {
+
     $output = t('Running') .' '. l($config->name, 'admin/media_mover/config/'. $config->cid) ."<br />";
 
     // check directories
     _media_mover_check_config_dirs($config);
 
-    // HARVEST  
+    // HARVEST
 
     $output .= t('Harvesting.... ') .'<br />';
     $files = module_invoke($config->harvest->module, 'media_mover', 'harvest', $config->harvest->action, $config->harvest->configuration, null, $config);
@@ -311,7 +310,7 @@
     // run process, store and complete for each harvested file
     if (count($files) > 0 ) {
       foreach ($files as $harvested_file) {
-       
+
        // save harvested file
        // file data other than what's stored in the media_mover_files table
        $mmfid = _mm_file_db_add($harvested_file, $config, 'harvest', $config->harvest->module, $config->harvest->action, $config->harvest->configuration);
@@ -334,17 +333,17 @@
        $output .= t('completion....') .'<br />';
        $harvested_file = module_invoke($config->complete->module, 'media_mover', 'complete', $config->complete->action, $config->complete->configuration, $harvested_file, $config);
        _mm_file_db_update($harvested_file);
-       
+
      }//foreach
-   }  
+   }
    // no files found, alert admin
    else { $output .= t('No files harvested'); }
-  
+
     // ends the configuration run
-    _mm_configuration_stop_run($config->cid);  
+    _mm_configuration_stop_run($config->cid);
   }
 
-  // if in debug mode..... 
+  // if in debug mode.....
   if ($debug) {
     return $output;
   }
@@ -356,7 +355,7 @@
  * @param $config is a mm configuration
  */
 function _media_mover_check_config_dirs($config) {
-  foreach (_mm_verbs() as $verb) { 
+  foreach (_mm_verbs() as $verb) {
     $dirs = module_invoke($config->$verb->module, 'media_mover', 'directories' );
     if ($dirs) {
       _media_mover_check_dirs($dirs);
@@ -403,10 +402,10 @@
  * @return is a the text string from the module
  * */
 function _mm_action_name($module, $id) {
-  static $names; 
+  static $names;
   if (! $names[$module][$id]) {
     $names[$module] = module_invoke($module, 'media_mover', 'actions');
-  }    
+  }
   return $names[$module][$id];
 }
 
@@ -420,36 +419,36 @@
 /**
  * checks to see if a configuration is running, prevents
  * overlapping condition
- * 
+ *
  * @cid is a configuration id
  * @return false if cofnig is not running, true if so
  */
 function _mm_configuration_is_running($cid) {
-  
+
   // lock the tables to prevent over run
   db_lock_table('media_mover_config_list');
-  
+
   $config = db_fetch_array(db_query('SELECT * FROM {media_mover_config_list} WHERE cid = %d', $cid));
 
   if ($config['status'] == 'running') {$output = true;}
   else {
-    // set status to running, and set the start run time. 
-    db_query('UPDATE {media_mover_config_list} SET status = "running", last_start_time = %d, start_time = %d WHERE cid = %d', $config['start_time'], time(), $cid );        
+    // set status to running, and set the start run time.
+    db_query('UPDATE {media_mover_config_list} SET status = "running", last_start_time = %d, start_time = %d WHERE cid = %d', $config['start_time'], time(), $cid );
   }
   db_unlock_tables('media_mover_config_list');
-  
+
   if ($output) {
     $message = t('Media Mover dected another media mover process running and stopped. You may want to consider decreasing your cron.php frequency.');
     watchdog('media_mover', $message, 'WATCHDOG_NOTICE' );
   }
-  
+
   return $output;
 }
 
 /**
  * ends a configuration run, sets the status flag to off
  * @cid configuration id
- * 
+ *
  */
 function _mm_configuration_stop_run($cid) {
   db_query('UPDATE {media_mover_config_list} SET status = "stopped"  WHERE cid = %d', $cid);
@@ -479,8 +478,8 @@
 /**
  * adds a newly created media_mover file to the media_mover db table
  * @TODO think through how to add non file based content
- * 
- * @param $file is a file array with all the data harvested 
+ *
+ * @param $file is a file array with all the data harvested
  * @param $config is a MM config
  * @param $verb is what MM processs is calling this
  * @param $module is the name of the module that did the harvest
@@ -489,19 +488,19 @@
  * @return $mmfid for this files ID
  */
 function _mm_file_db_add($file, $config, $verb = 'harvest', $module = null, $action = null, $action_config) {
-  
+
   // get next mmfid
   $mmfid = db_next_id("{media_mover_files}_mmfid");
-  
-  // add to db     
+
+  // add to db
   db_query("INSERT INTO {media_mover_files} (mmfid, nid, fid, cid, ". $verb ."_file, status, data) VALUES (%d, %d, %d, %d, '%s', %d, '%s')", $mmfid, $file['nid'], $file['fid'], $config->cid, $file['filepath'], 1, serialize($file));
-  
-  // don't need to run this unless requested 
+
+  // don't need to run this unless requested
   // media_mover_run_config always calls this
   if ($module && $action && $config) {
     module_invoke($module, 'media_mover', 'add', $action, $action_config, $file );
   }
-  
+
   return $mmfid;
 }
 
@@ -509,12 +508,13 @@
  * fetches files from files db
  * invokes media_mover fetch hook to get additional data that media mover
  * modules may have saved in seperate tables regarding a node
- * 
+ *
  * @param nid node id value
  * @return files array
  */
 function _mm_files_db_fetch($nid) {
   $files = db_query("SELECT * FROM {media_mover_files} WHERE nid= %d", $nid);
+  $return_files = array();
   while ($file = db_fetch_array($files)) {
     foreach (_mm_verbs() as $verb) {
       $merge = module_invoke($file["{$verb}_module"], 'media_mover', 'fetch', $file["{$verb}_action"], $file  );
@@ -534,9 +534,9 @@
  * @return file array
  */
 function _mm_file_db_fetch($mmfid) {
-  $file = db_fetch_array(db_query("SELECT * FROM {media_mover_files} WHERE mmfid= %d", $mmfid)); 
-    
-  $file['data'] = unserialize($file['data']);  
+  $file = db_fetch_array(db_query("SELECT * FROM {media_mover_files} WHERE mmfid= %d", $mmfid));
+
+  $file['data'] = unserialize($file['data']);
   foreach (_mm_verbs() as $verb) {
     $merge = module_invoke($file["{$verb}_module"], 'media_mover', 'fetch', $file["{$verb}_action"], $file  );
     if ($merge) {
@@ -560,7 +560,7 @@
 
 /**
  * update a specific configuration
- * 
+ *
  * @param cid is a config id
  * @param verb is verb to match on
  * @param configuration is a serialized array
@@ -597,7 +597,7 @@
 /**
  * run a delete function for harvest and storage modules to delete
  * files they've handled
- * 
+ *
  * @param $cid is a configuration id
  */
 function _mm_config_file_delete($cid){
@@ -613,7 +613,7 @@
 /**
  * creates a single runable configuration
  * @ TODO stop converting this array into an object
- * @param $config_name is a 
+ * @param $config_name is a
  */
 function media_mover_get_configuration($config_name) {
   $config->name = $config_name['name'];
@@ -650,7 +650,7 @@
 
 /**
  * Get a single configuration from the db
- * @ TODO deprechiate this 
+ * @ TODO deprechiate this
  * @param $cid is configuration id
  * @return the configuration description
  */
@@ -701,8 +701,8 @@
     unset($item);
   }
 
-  // @ TODO make this a fieldset 
-  
+  // @ TODO make this a fieldset
+
   $output = theme('table', $header, $row);
 
   // @ TODO deactivate a configuration
@@ -711,13 +711,13 @@
   $header = array(t('Name'), t('Description'), t('Last run'), t('Status'), t('Run'), t('Edit'), t('Reset'), t('Dump files'), t('Delete'), );
   $results =  pager_query('SELECT * FROM {media_mover_config_list} ORDER BY status');
   while ($result = db_fetch_array($results)) {
-    
+
     // replace status == stopped with enabled
     if ($result['status'] == 'stopped') { $status = 'enabled';}
     else {
       $status = $result['status'];
     }
-    
+
     $row[] = array(
       $result['name'],
       $result['description'],
@@ -728,7 +728,7 @@
       l(t('reset'), 'admin/media_mover/config/reset/'. $result['cid']),
       l(t('dump'), 'admin/media_mover/config/reset/full/'. $result['cid']),
       l(t('delete'), 'admin/media_mover/config/delete/'. $result['cid']),
-      
+
     );
   }
 
@@ -778,10 +778,10 @@
  * helper function to fetch all configuration options from media mover modules
  */
 function _media_mover_build_add_config() {
-  
+
   // add the javascript to show and hide configuration for modules
   drupal_add_js(drupal_get_path('module', 'media_mover') .'/media_mover.js');
-  
+
   $verbs = _mm_verbs();
   foreach ($verbs as $verb) {
     $form[$verb] = array(
@@ -811,7 +811,7 @@
     );
     unset($options);
   }
-  
+
   return $form;
 }
 
@@ -880,17 +880,17 @@
  */
 function media_mover_config_reset_confirm($cid) {
   $form['cid'] = array(
-    '#type' => 'value', 
+    '#type' => 'value',
     '#value' => $cid
   );
 
   return confirm_form(
     $form,
     t('Are you sure you want to reset this configuration?'),
-    'admin/media_mover', 
+    'admin/media_mover',
     t('This action cannot be undone.'),
-    t('Reset'), 
-    t('Cancel')  
+    t('Reset'),
+    t('Cancel')
   );
 }
 
@@ -924,17 +924,17 @@
  */
 function media_mover_config_reset_full_confirm($cid) {
   $form['cid'] = array(
-    '#type' => 'value', 
+    '#type' => 'value',
     '#value' => $cid
   );
 
   return confirm_form(
     $form,
     t('Are you sure you want to reset this configuration and remove references to its files?'),
-    'admin/media_mover', 
+    'admin/media_mover',
     t('This action cannot be undone.'),
-    t('Reset'), 
-    t('Cancel')  
+    t('Reset'),
+    t('Cancel')
   );
 }
 
@@ -968,16 +968,16 @@
  */
 function media_mover_config_delete_confirm($cid) {
   $form['cid'] = array(
-    '#type' => 'value', 
+    '#type' => 'value',
     '#value' => $cid
   );
 
   return confirm_form(
     $form,
     t('Are you sure you want to delete this configuration?'),
-    'admin/media_mover', 
+    'admin/media_mover',
     t('This action cannot be undone.'),
-    t('Delete'), 
+    t('Delete'),
     t('Cancel')
   );
 }
@@ -1003,10 +1003,10 @@
 
 /**
  * pulls the forms up to edit a specific configuration
- * this does not allow changing the MM modules that are in use, 
- * only the specific configurations for the origional configuration 
+ * this does not allow changing the MM modules that are in use,
+ * only the specific configurations for the origional configuration
  * can be change which prevents some potentially bad things from happening
- * 
+ *
  * @param $cid is a configuration id
  * @return drupal form
  */
@@ -1017,7 +1017,7 @@
   // if it is, return user
   if ($config_description->status == 'running') {
     drupal_set_message(t('This configuration is currently running. You need to wait to modify it until it is complete.'));
-    drupal_goto('admin/media_mover');  
+    drupal_goto('admin/media_mover');
   }
 
   // name and description, universal
@@ -1047,12 +1047,12 @@
     '#options' => $options,
     '#default_value' => $status,
   );
- 
+
   $form['edit_config']['mm_config_status_value'] = array(
     '#type' => 'hidden',
     '#value' => $config_description->status,
   );
- 
+
   $form['config']['cid']= array(
     '#type' => 'hidden',
     '#value' => $cid,
@@ -1062,7 +1062,7 @@
 
   while ($config = db_fetch_array($configs)) {
     $form[$config['verb']]["{$config['module']}--{$config['action']}"] = module_invoke($config['module'], 'media_mover', 'config', $config['verb'] .'--'. $config['action'], unserialize($config['configuration']));
-    $form[$config['verb']]['#description'] = $config['module'] .': '. _mm_action_name($config['module'], $config['action']); 
+    $form[$config['verb']]['#description'] = $config['module'] .': '. _mm_action_name($config['module'], $config['action']);
   }
 
   $verbs = _mm_verbs();
@@ -1112,8 +1112,8 @@
  */
 function media_mover_config_edit_form_submit($form_id, $form_values) {
 
-  // check to see if the status was disabled 
-  // this is somewhat of a hackish approach here 
+  // check to see if the status was disabled
+  // this is somewhat of a hackish approach here
   if (! $form_values['mm_config_status']) { $status = 'disabled'; }
   elseif ($form_values['mm_config_status_value'] == 'disabled' ) { $status = 'enabled'; }
   else {$status = $form_values['mm_config_status_value']; }
@@ -1159,13 +1159,13 @@
   $header = array(t('MMfid'), t('Configuration'), t('File'), t('Edit'), t('Delete') );
   while ($file = db_fetch_array($results)) {
     // @ TODO make this match up with the media_mover_files db
-    
+
     $node = l('node/'. $file['nid'], 'node/'. $file['nid']);
-    
+
     $config_name = _mm_get_configuration_description($file['cid']);
     $row[] = array(
-      $file['mmfid'],     
-      l($config_name->name, 'admin/media_mover/config/edit/'. $file['cid']) .'<br />'. $node,      
+      $file['mmfid'],
+      l($config_name->name, 'admin/media_mover/config/edit/'. $file['cid']) .'<br />'. $node,
       $file['harvest_file'],
       l(t('Edit ') . $file['mmfid'], 'admin/media_mover/file/edit/'. $file['mmfid']),
       l(t('Delete ') . $file['mmfid'], 'admin/media_mover/file/delete/'. $file['mmfid']),
@@ -1314,7 +1314,7 @@
   foreach ($files as $file) {
     if ($custom = module_invoke($file['storage_module'], 'media_mover', 'theme', '', $file) ) {
       $output .= $custom;
-    } 
+    }
     else {
       if ($file['storage_file']) {
         $output .= print_r($file, true);
