 modules/mm_node/includes/mm_node.content.inc |  85 ++++----
 modules/mm_node/includes/mm_node.emfield.inc |  38 ++--
 modules/mm_node/includes/mm_node.node.inc    |  27 +--
 modules/mm_node/includes/mm_node.upload.inc  |  29 ++-
 modules/mm_node/mm_node.formater.inc         |  49 +++--
 modules/mm_node/mm_node.info                 |   8 +-
 modules/mm_node/mm_node.install              |   2 -
 modules/mm_node/mm_node.module               | 300 +++++++++++++++------------
 modules/mm_node/mm_node.theme.inc            |  14 +-
 modules/mm_utilities/mm_utilities.info       |   2 +-
 modules/mm_utilities/mm_utilities.install    |   9 +-
 modules/mm_utilities/mm_utilities.module     | 126 +++++++----
 12 files changed, 393 insertions(+), 296 deletions(-)

diff --git a/modules/mm_node/includes/mm_node.content.inc b/modules/mm_node/includes/mm_node.content.inc
index 683cc0b..bba5d52 100644
--- a/modules/mm_node/includes/mm_node.content.inc
+++ b/modules/mm_node/includes/mm_node.content.inc
@@ -1,7 +1,5 @@
 <?php
 
-// $Id$
-
 /**
  * @file
  *
@@ -27,7 +25,7 @@ function mm_node_content_field_select_config($step) {
     '#multiple' => TRUE,
     '#title' => t('Select files from these CCK fields'),
     '#description' => t('Select the CCK fields to harvest files from.'),
-    '#options' => mm_node_cck_fields(array('text', 'filefield', 'imagefield')),
+    '#options' => mm_node_cck_fields(array('text', 'file', 'image')),
     '#default_value' => isset($step->settings['harvest_field']) ? $step->settings['harvest_field'] : '',
   );
   $form['mm_node_content_field_select_config']['file_types'] = array(
@@ -62,13 +60,13 @@ function mm_node_content_field_select_config($step) {
  */
 function mm_node_content_field_select($step) {
   $files = array();
-  $fields = content_fields();
+  $fields = field_info_instances('node');
 
   $harvest_conditions = '';
 
   // Are we harvesting from a specific node?
   if ($node = $step->parameter_get('node')) {
-    $harvest_conditions = ' AND n.nid = '.  $node->nid;
+    $harvest_conditions = ' AND n.nid = ' .  $node->nid;
   }
 
   // We need to harvest from each field that was selected for that node tyoe
@@ -85,10 +83,10 @@ function mm_node_content_field_select($step) {
         // @TODO need to handle this
         case 'text':
           // $node->{$field['field_name']} = array(array('value' => $file['process_file']));
-        break;
+          break;
 
-        // handle image field case
-        case 'filefield':
+        // handle file/image field case
+        case 'file':
         case 'image':
           // are file types being checked?
           if ($step->settings['file_types']) {
@@ -97,25 +95,26 @@ function mm_node_content_field_select($step) {
               $conditions[] = "f.filepath LIKE '%.$type'";
             }
             // build the SQL to check against the file types
-            $file_type_conditions = ' ('. implode(' OR ', $conditions) .')';
+            $file_type_conditions = ' (' . implode(' OR ', $conditions) . ')';
           }
 
+          // @todo Please convert this statement to the D7 database API syntax.
           $results = db_query('SELECT DISTINCT f.filepath AS filepath, c.nid, f.fid FROM {files} f
-            LEFT JOIN {'. $db_info['table'] .'} c ON c.'. $db_info['columns']['fid']['column'] .' = f.fid
+            LEFT JOIN {' . $db_info['table'] . '} c ON c.' . $db_info['columns']['fid']['column'] . ' = f.fid
             LEFT JOIN {node} n ON c.nid = n.nid
-            LEFT JOIN {media_mover_files} m ON m.fid = f.fid AND m.cid = "%s"
+            LEFT JOIN {media_mover_files} m ON m.fid = f.fid AND m.cid = :cid
             WHERE
               ' . $file_type_conditions . '
-              AND f.filepath NOT IN (SELECT source_filepath FROM {media_mover_files} WHERE cid ="%s")
-              AND n.type = "%s"
+              AND f.filepath NOT IN (SELECT source_filepath FROM {media_mover_files} WHERE cid = :cid)
+              AND n.type = :node_type
             ORDER BY f.timestamp',
-            $step->cid, $step->cid, $node_type);
+            array(':cid' => $step->cid, ':node_type' => $node_type))->execute();
 
-          // now build the out going file data
-          while ($result = db_fetch_array($results)) {
+          // now build the outgoing file data
+          while ($result = $results->fetchAssoc()) {
             $files[] = $result;
           }
-        break;
+          break;
       }
     }
   }
@@ -179,7 +178,7 @@ function mm_node_content_field_store_config($step) {
       a derivative of the file that is being replaced. If neither of these
       is the case it is likely that your configuration will fail on this
       step.'),
-    '#options' => mm_node_cck_fields(array('text', 'filefield', 'imagefield')),
+    '#options' => mm_node_cck_fields(array('text', 'file', 'image')),
     '#default_value' => $step->settings['cck_field_save_node'],
   );
   $form['mm_node_content_field_store_config']['replace_existing'] = array(
@@ -211,7 +210,7 @@ function mm_node_content_field_store($step, $file) {
   if (! $node = $step->parameter_get('node')) {
     if (! $node = $file->node_get()) {
       watchdog('mm_node', 'No node data was passed for storing file data in a specified CCK field.',
-        array(), WATCHDOG_ERROR, l(t($file->mmfid),  'admin/media_mover/file/edit/'. $file->mmfid));
+        array(), WATCHDOG_ERROR, l(t($file->mmfid), MMA_CONFIG_PATH . '/file/edit/' . $file->mmfid));
       return;
     }
     // Ensure that we have CCK data
@@ -220,16 +219,17 @@ function mm_node_content_field_store($step, $file) {
 
   // Get the field that we are using
   $field_name = explode('--', $step->settings['cck_field_save_node']);
-  $field = content_fields($field_name[1], $node->type);
+  $fields = field_info_instances('node', $node->type);
+  $field = $fields[$field_name[1]];
 
   switch ($field['type']) {
     case 'text':
       $item = array('value' => $file->file_path);
-    break;
+      break;
 
-    // Handle CCK image and CCK file field cases
+    // handle file/image field case
+    case 'file':
     case 'image':
-    case 'filefield':
       // Replacing existing file on node
 
       if ($step->settings['replace_existing']) {
@@ -244,7 +244,7 @@ function mm_node_content_field_store($step, $file) {
         // Overwrite the existing file
         drupal_write_record('files', $data, 'fid');
         // Delete the source material
-        $source_filepath = db_query("SELECT filepath FROM {files} WHERE fid = %d", $file->fid);
+        $source_filepath = db_query("SELECT filepath FROM {files} WHERE fid = :fid", array(':fid' => $file->fid))->execute()->fetchField();
         if ($file->filepath != $source_filepath) {
           file_delete($source_file);
         }
@@ -265,25 +265,25 @@ function mm_node_content_field_store($step, $file) {
         // Use the new filepath
         $file->filepath = $item['filepath'];
       }
-    break;
+      break;
 
     // We handle emfield content here so that this function
     // does not have to be duplicated
     case 'emfield':
       $item = mm_emfield_parse_url($file->filepath, $field);
-    break;
-
-    // Append the new field data onto the node
-    if (! is_array($node->{$field['field_name']})) {
-      $node->{$field['field_name']} = $item;
-    }
-    elseif (! isset($node->{$field['field_name']}[0]))  {
-      $node->{$field['field_name']} = $item;
-    }
-    // Files exist, append this file
-    else {
-      $node->{$field['field_name']}[] = $item;
-    }
+//@todo: FIXME! this code was disabled by an early "break;"
+      // Append the new field data onto the node
+      if (! is_array($node->{$field['field_name']})) {
+        $node->{$field['field_name']} = $item;
+      }
+      elseif (! isset($node->{$field['field_name']}[0])) {
+        $node->{$field['field_name']} = $item;
+      }
+      // Files exist, append this file
+      else {
+        $node->{$field['field_name']}[] = $item;
+      }
+      break;
   }
 
   // If the node was passed in during hook_nodeapi we need to not save
@@ -291,13 +291,17 @@ function mm_node_content_field_store($step, $file) {
     // Save our new data
     node_save($node);
     // Clear node cache
-    cache_clear_all('content:'. $node->nid . ':' . $node->vid, 'cache_content', TRUE);
+    cache_clear_all('content:' . $node->nid . ':' . $node->vid, 'cache_content', TRUE);
   }
 
   // return the file
   return $file->filepath;
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function mm_node_content_field_store_file_exists($node, $step, $mm_file, &$found) {
   // $node, $step, $mm_file, &$found
 }
@@ -357,6 +361,9 @@ function mm_node_content_field_filefield($file, $field) {
 function mm_node_content_field_widget_files_directory($file, $field) {
   $path = file_directory_path();
   if (isset($file->data['user']->uid) and module_exists('token')) {
+    // @todo Convert "user_load" to "user_load_multiple" if "$file->data['user']->uid" is other than a uid.
+    // To return a single user object, wrap "user_load_multiple" with "array_shift" or equivalent.
+    // Example: array_shift(user_load_multiple(array(), $file->data['user']->uid))
     $user = user_load($file->data['user']->uid);
     $path_tokens = $field['widget']['file_path'];
     if ($directories = token_replace($path_tokens, 'user', $user)) {
diff --git a/modules/mm_node/includes/mm_node.emfield.inc b/modules/mm_node/includes/mm_node.emfield.inc
index 0cbcf79..c2aa0fe 100644
--- a/modules/mm_node/includes/mm_node.emfield.inc
+++ b/modules/mm_node/includes/mm_node.emfield.inc
@@ -1,7 +1,5 @@
 <?php
 
-// $Id$
-
 /**
  * @file
  *
@@ -23,7 +21,7 @@ function mm_node_emfield_harvest_config($step) {
     '#description' => t('This module selects files attached to an Embedded Media Field'),
   );
   // Get content types
-  if ($types = node_get_types()) {
+  if ($types = node_type_get_types()) {
     foreach ($types as $type) {
       $options[$type->type] = $type->name;
     }
@@ -59,12 +57,12 @@ function mm_node_emfield_harvest_config($step) {
  */
 function mm_node_emfield_harvest($step) {
   $files = array();
-  $fields = content_fields();
+  $fields = field_info_instances('node');
 
   $harvest_conditions = '';
   // Are we harvesting from a specific NID ?
   if ($nid = $step->parameters['nid']) {
-    $harvest_conditions = ' AND n.nid = '. $nid;
+    $harvest_conditions = ' AND n.nid = ' . $nid;
   }
 
   // We need to harvest from each field that was selected.
@@ -72,22 +70,22 @@ function mm_node_emfield_harvest($step) {
     // Get the relevant database information for this field.
     $db_info = content_database_info($fields[$field_name]);
 
-    $results = db_query("SELECT c.". $field_name ."_embed AS harvest_file, n.nid
-      FROM {". $db_info['table'] ."} c
+    $results = db_query("SELECT c." . $field_name . "_embed AS harvest_file, n.nid
+      FROM {" . $db_info['table'] . "} c
       LEFT JOIN {node} n ON c.nid = n.nid
-      LEFT JOIN {media_mover_files} m ON m.cid = %d
+      LEFT JOIN {media_mover_files} m ON m.cid = :cid
       WHERE ((n.nid IS NOT NULL AND m.nid IS NULL)
-        OR (n.nid IS NOT NULL AND n.nid = m.nid AND c.". $field_name ."_embed <> m.harvest_file))
-        AND n.type = \"%s\"
-        AND c.". $field_name ."_embed NOT IN (SELECT harvest_file FROM {media_mover_files} WHERE cid = %d)
-        AND n.created >= %d
-      ORDER BY n.created
-      ", $step->cid, $step->settings['mm_emfield_harvest_node_type'], $step->cid, $step->stop_time);
-
-      // Now build the outgoing file data.
-      while ($result = db_fetch_array($results)) {
-        $files[] = $result;
-      }
+        OR (n.nid IS NOT NULL AND n.nid = m.nid AND c." . $field_name . "_embed <> m.harvest_file))
+        AND n.type = :node_type
+        AND c." . $field_name . "_embed NOT IN (SELECT harvest_file FROM {media_mover_files} WHERE cid = :cid)
+        AND n.created >= :created
+      ORDER BY n.created",
+      array(':cid' => $step->cid, ':node_type' => $step->settings['mm_emfield_harvest_node_type'], ':created' => $step->stop_time))->execute();
+
+    // Now build the outgoing file data.
+    while ($result = $results->fetchAssoc()) {
+      $files[] = $result;
+    }
   }
   return $files;
 }
@@ -130,7 +128,7 @@ function mm_node_emfield_node_file_delete($step, $file) {
         unset($node->{$field}[$key]);
         // Save the node without the file
         node_save($node);
-        watchdog('MM Emfield', 'Deleted media attached to an Embedded Media Field for !node', array('!node' => l($node->title, 'node/'. $node->nid)), WATCHDOG_INFO);
+        watchdog('MM Emfield', 'Deleted media attached to an Embedded Media Field for !node', array('!node' => l($node->title, 'node/' . $node->nid)), WATCHDOG_INFO);
       }
     }
   }
diff --git a/modules/mm_node/includes/mm_node.node.inc b/modules/mm_node/includes/mm_node.node.inc
index 99f91da..9bb2597 100644
--- a/modules/mm_node/includes/mm_node.node.inc
+++ b/modules/mm_node/includes/mm_node.node.inc
@@ -1,7 +1,5 @@
 <?php
 
-// $Id$
-
 /**
  * @file
  *
@@ -93,7 +91,7 @@ function mm_node_save_config($step) {
   $form['storage']['node']['node_save_type'] = array(
     '#title' => t('Content type'),
     '#type' => 'select',
-    '#options' => node_get_types('names'),
+    '#options' => node_type_get_names(),
     '#default_value' => $step->settings['node_save_type'],
     '#description' => t('Save the file as new node of this type'),
   );
@@ -172,8 +170,8 @@ function mm_node_save_config($step) {
  */
 function mm_node_save_config_validate($element, &$form_state) {
   // Is the user valid?
-  if (! $account = user_load(array('name' => $element['#value']))) {
-    form_error($element,  t('Sorry, the name you chose for a default node author was not valid.'));
+  if (! $account = array_shift(user_load_multiple(array(), array('name' => $element['#value'])))) {
+    form_error($element,   t('Sorry, the name you chose for a default node author was not valid.'));
   }
   // Should validate fields against nodes
 
@@ -224,7 +222,7 @@ function mm_node_publish_set_options($step, $file) {
  *
  * @param array $file
  * @param array $configuration
- * @ TODO finish up this functionality to deploy
+ * @TODO finish up this functionality to deploy
  *        requires creating the data store
  */
 function mm_node_save($step, $file) {
@@ -311,7 +309,8 @@ function mm_node_save($step, $file) {
     // Check for CCK fields
     else {
       // Get the field that we will save to.
-      $field = content_fields($kind, $type);
+      $fields = field_info_instances('node', $type);
+      $field = $fields[$kind];
 
       // Now what do we do with it?
       switch ($field['type']) {
@@ -333,7 +332,7 @@ function mm_node_save($step, $file) {
           else {
             $node->{$field['field_name']}[] = $cck_saved_file;
           }
-        break;
+          break;
 
         // EMField options
         case 'emvideo':
@@ -342,7 +341,7 @@ function mm_node_save($step, $file) {
           // We have to have a provided file so emfield does not die.
           // @TODO PHP Stream Wrappers should address this in d7.
           if (! $item = mm_node_cck_emfield_parse_url($file, $field)) {
-            watchdog('MM Emfield', 'Failed to parse %url for provider media to attach to the Embedded Media Field for !file.', array('%url' => $file->filepath, '!file' => l(t('MM file @file', array('@file' => $file->mmfid)),  'admin/media_mover/file/edit/'. $file->mmfid)), WATCHDOG_ERROR);
+            watchdog('MM Emfield', 'Failed to parse %url for provider media to attach to the Embedded Media Field for !file.', array('%url' => $file->filepath, '!file' => l(t('MM file @file', array('@file' => $file->mmfid)), MMA_CONFIG_PATH . '/file/edit/' . $file->mmfid)), WATCHDOG_ERROR);
             return FALSE;
           }
           $cck_saved_file = array('embed' => $file->filepath);
@@ -353,7 +352,7 @@ function mm_node_save($step, $file) {
           else {
             $node->{$field['field_name']}[] = $cck_saved_file;
           }
-        break;
+          break;
       }
 
       // Now save the node with the updated data
@@ -371,12 +370,14 @@ function mm_node_save($step, $file) {
 /**
  * Removes references to files from files table where they were stored
  *
- * @ TODO this needs to be completed
+ * @TODO this needs to be completed
  */
 function mm_node_upload_file_delete($file) {
   if ($file->fid) {
     // Delete all files associated with the node
-    db_query('DELETE FROM {files} WHERE fid = %d', $file->fid);
+    db_delete('files')
+    ->condition('fid', $file->fid)
+    ->execute();
     file_delete($file->filepath);
   }
 
@@ -400,7 +401,7 @@ function mm_node_create_form() {
   );
 
   // Get content types.
-  if ($types = node_get_types()) {
+  if ($types = node_type_get_types()) {
     foreach ($types as $type) {
       $options[$type->type] = $type->name;
     }
diff --git a/modules/mm_node/includes/mm_node.upload.inc b/modules/mm_node/includes/mm_node.upload.inc
index 0a431a7..61f5c98 100644
--- a/modules/mm_node/includes/mm_node.upload.inc
+++ b/modules/mm_node/includes/mm_node.upload.inc
@@ -1,7 +1,5 @@
 <?php
 
-// $Id$
-
 /**
  * @file
  *
@@ -26,7 +24,7 @@ function mm_node_upload_harvest_config($step) {
     '#type' => 'select',
     '#title' => t('Choose files from these content types'),
     '#description' => t('Choose content types you wish to search for video files to convert. You can select multiple file types.'),
-    '#options' => node_get_types('names') ,
+    '#options' => node_type_get_names(),
     '#multiple' => TRUE,
     '#default_value' => $step->settings['mm_node_types'],
   );
@@ -60,10 +58,10 @@ function mm_node_upload_harvest($step) {
   if ($node_types = $step->settings['mm_node_types'] ) {
     foreach ($node_types as $type) {
       if ($type) {
-        $node_type_list[] = '"'. $type .'"';
+        $node_type_list[] = '"' . $type . '"';
       }
     }
-    $node_type_list = 'n.type IN ('. implode(', ', $node_type_list) .')';
+    $node_type_list = 'n.type IN (' . implode(', ', $node_type_list) . ')';
 
     // Select from specified file types
     if ($step->settings['file_types']) {
@@ -72,12 +70,12 @@ function mm_node_upload_harvest($step) {
         $conditions[] = "f.filepath LIKE '%%.$type'";
       }
       // build the SQL to check against the file types
-      $file_type_conditions = ' AND ('. implode(' OR ', $conditions) .')';
+      $file_type_conditions = ' AND (' . implode(' OR ', $conditions) . ')';
     }
 
     // are we harvesting from a specific NID ?
     if (isset($step->parameters['nid'])) {
-      $harvest_conditions = ' AND n.nid = '. $step->parameters['nid'];
+      $harvest_conditions = ' AND n.nid = ' . $step->parameters['nid'];
     }
 
     // Select all files and join with nodes of $node_type_list
@@ -91,22 +89,23 @@ function mm_node_upload_harvest($step) {
       AND u.fid NOT IN (
         SELECT mmf.fid FROM {media_mover_files} mmf
           WHERE
-            mmf.cid = "%s" AND
+            mmf.cid = :cid AND
             mmf.source_filepath = f.filepath
       )
       ORDER BY n.changed DESC';
 
     // Now run the query
-    $results = db_query($query, $step->cid, $step->stop_time);
+    $results = db_query($query, array(':cid' => $step->cid))->execute();
     $files = array();
     // take each result and add it to the output
-    while ($result = db_fetch_array($results)) {
+    while ($result = $results->fetchAssoc()) {
       // Now we harvest file
-      $file['filepath'] = $result['filepath'];
-      $file['nid'] = $result['nid'];
-      $file['fid'] = $result['fid'];
-      $file['data']['user']->uid = $result['uid'];
-      $files[] = $result;
+      $files[] = array(
+        'filepath' => $result['filepath'],
+        'nid' = $result['nid'],
+        'fid' = $result['fid'],
+        'data' => array('user' => (object) array('uid' => $result['uid'])),
+      );
     }
     return $files;
   }
diff --git a/modules/mm_node/mm_node.formater.inc b/modules/mm_node/mm_node.formater.inc
index f8bc042..b7a024e 100644
--- a/modules/mm_node/mm_node.formater.inc
+++ b/modules/mm_node/mm_node.formater.inc
@@ -1,33 +1,39 @@
 <?php
 
-// $Id$
-
 /**
  * @file
  * Provides a formatter for CCK data- overrides filefield defaults
  *
  */
 
+// @TODO: filefield module has been renamed into file module. Need to redesign all themes and hooks appropriately.
+
 /**
  * Theme function for the 'default' filefield formatter.
+ * Inserted into theme registry by mm_node_theme_registry_alter().
  */
-function theme_mm_node_filefield_formatter_default($element) {
+function theme_mm_node_filefield_formatter_default($variables) {
+  $element = $variables['$element'];
   $file = $element['#item'];
+  //@todo FIXME replace content_fields() with field_info_instances() or?
   $field = content_fields($element['#field_name']);
-  $output = theme('filefield_item', $file, $field);
+  $output = theme('filefield_item', array('file' => $file, 'field' => $field));
   return $output;
 }
 
 /**
  * Theme function for the 'path_plain' formatter.
+ * Inserted into theme registry by mm_node_theme_registry_alter().
  */
-function theme_mm_node_filefield_formatter_path_plain($element) {
+function theme_mm_node_filefield_formatter_path_plain($variables) {
+  $element = $variables['$element'];
   // Inside a View this function may be called with null data. In that case,
   // just return.
   if (empty($element['#item'])) {
     return '';
   }
 
+  //@todo FIXME replace content_fields() with field_info_instances() or?
   $field = content_fields($element['#field_name']);
   $item = $element['#item'];
   // If there is no image on the database, use default.
@@ -38,19 +44,22 @@ function theme_mm_node_filefield_formatter_path_plain($element) {
     $item = array_merge($item, field_file_load($item['fid']));
   }
 
-  return empty($item['filepath']) ? '' : mm_node_filepath_check($item);;
+  return empty($item['filepath']) ? '' : mm_node_filepath_check($item);
 }
 
 /**
  * Theme function for the 'url_plain' formatter.
+ * Inserted into theme registry by mm_node_theme_registry_alter().
  */
-function theme_mm_node_filefield_formatter_url_plain($element) {
+function theme_mm_node_filefield_formatter_url_plain($variables) {
+  $element = $variables['$element'];
   // Inside a View this function may be called with null data. In that case,
   // just return.
   if (empty($element['#item'])) {
     return '';
   }
 
+  //@todo FIXME replace content_fields() with field_info_instances() or?
   $field = content_fields($element['#field_name']);
   $item = $element['#item'];
   // If there is no image on the database, use default.
@@ -66,6 +75,7 @@ function theme_mm_node_filefield_formatter_url_plain($element) {
 
 /**
  * Theme function for any file that is managed by FileField.
+ * Inserted into theme registry by mm_node_theme_registry_alter().
  *
  * It doesn't really format stuff by itself but rather redirects to other
  * formatters that are telling us they want to handle the concerned file.
@@ -74,19 +84,23 @@ function theme_mm_node_filefield_formatter_url_plain($element) {
  * if viewing the file is not allowed for any reason. If you need to display it
  * in any case, please use theme('filefield') instead.
  */
-function theme_mm_node_filefield_item($file, $field) {
+function theme_mm_node_filefield_item($variables) {
+  $file = $variables['file'];
+  $field = $variables['field'];
   // Ensure that the filefield functions are loaded
   module_load_include('inc', 'filefield', 'filefield_formatter');
   if (filefield_view_access($field['field_name']) && filefield_file_listed($file, $field)) {
-    return theme('filefield_file', $file);
+    return theme('filefield_file', array('file' => $file));
   }
   return '';
 }
 
 /**
- * Overrides the standard filefield file display
+ * Overrides the standard filefield file display.
+ * Inserted into theme registry by mm_node_theme_registry_alter().
  */
-function theme_mm_node_filefield_file($file) {
+function theme_mm_node_filefield_file($variables) {
+  $file = $variables['file'];
   // Views may call this function with a NULL value, return an empty string.
   if (empty($file['fid'])) {
     return '';
@@ -96,11 +110,11 @@ function theme_mm_node_filefield_file($file) {
   // If this filepath has a URI in it, do not format it
   $url = mm_node_filepath_check($file);
 
-  $icon = theme('filefield_icon', $file);
+  $icon = theme('file_icon', array('file' => $file, 'icon_directory' => NULL));
 
   // Set options as per anchor format described at
   // http://microformats.org/wiki/file-format-examples
-  // TODO: Possibly move to until I move to the more complex format described
+  // @TODO: Possibly move to until I move to the more complex format described
   // at http://darrelopry.com/story/microformats-and-media-rfc-if-you-js-or-css
   $options = array(
     'attributes' => array(
@@ -117,13 +131,16 @@ function theme_mm_node_filefield_file($file) {
     $options['attributes']['title'] = $file['filename'];
   }
 
-  return '<div class="filefield-file clear-block">'. $icon . l($link_text, $url, $options) .'</div>';
+  return '<div class="filefield-file clear-block">' . $icon . l($link_text, $url, $options) . '</div>';
 }
 
 /**
  * Overrides the standard drupal file attachment
+ * Inserted into theme registry by mm_node_theme_registry_alter().
  */
-function theme_mm_node_upload_attachments($files) {
+// @todo: FIXME: There are no more 'standard attachments' in Drupal 7. Remove this and dependent code.
+function theme_mm_node_upload_attachments($variables) {
+  $files = $variables['files'];
   $header = array(t('Attachment'), t('Size'));
   $rows = array();
   foreach ($files as $file) {
@@ -135,6 +152,6 @@ function theme_mm_node_upload_attachments($files) {
     }
   }
   if (count($rows)) {
-    return theme('table', $header, $rows, array('id' => 'attachments'));
+    return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'attachments')));
   }
 }
\ No newline at end of file
diff --git a/modules/mm_node/mm_node.info b/modules/mm_node/mm_node.info
index e4ab2e7..047e814 100644
--- a/modules/mm_node/mm_node.info
+++ b/modules/mm_node/mm_node.info
@@ -10,4 +10,10 @@ files[] = mm_node.upload.inc
 files[] = mm_node.content.inc
 files[] = mm_node.emfield.inc
 
-core=6.x
\ No newline at end of file
+core = 7.x
+; Information added by drupal.org packaging script on 2012-11-29
+version = "7.x-1.x-dev"
+core = "7.x"
+project = "media_mover"
+datestamp = "1354194482"
+
diff --git a/modules/mm_node/mm_node.install b/modules/mm_node/mm_node.install
index 49abb28..814441b 100644
--- a/modules/mm_node/mm_node.install
+++ b/modules/mm_node/mm_node.install
@@ -1,7 +1,5 @@
 <?php
 
-// $Id$
-
 /**
  * @file
  * Install file
diff --git a/modules/mm_node/mm_node.module b/modules/mm_node/mm_node.module
index 46a15d5..edadf0a 100644
--- a/modules/mm_node/mm_node.module
+++ b/modules/mm_node/mm_node.module
@@ -1,7 +1,5 @@
 <?php
 
-// $Id$
-
 /**
  * @file
  *
@@ -21,7 +19,7 @@
  */
 function mm_node_menu() {
   $items = array();
-  $items['admin/build/media_mover/settings/mm_node'] = array(
+  $items[MMA_CONFIG_PATH . '/settings/mm_node'] = array(
     'title' => 'Auto Run',
     '#description' => t('Specify Media Mover configurations to automatically run on nodes.'),
     'access arguments' => array('administer media_mover'),
@@ -34,41 +32,49 @@ function mm_node_menu() {
 
 
 /**
- * Implements hook_nodeapi().
- *
- * @ingroup drupal_hooks
- */
-function mm_node_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
-  switch ($op) {
-    case 'load':
-      // Load all files for this node
-      return mm_node_node_load($node);
-    break;
-    case 'view':
-      // Add media mover files to node display
-      mm_node_node_file_view($node);
-    break;
-    case 'insert':
-      // @TODO is this really needed/working?
-      mm_node_files_translation_insert($node);
-    break;
-    case 'presave':
-      mm_node_node_presave($node);
-      mm_node_auto_run($node);
-    break;
-    case "delete":
-      // invoke MM modules here and delete files associated with this node
-      mm_node_files_delete($node);
-    break;
-
-    // rss feed support
-    // @TODO is this even a good idea?
-    case 'rss item':
-      return mm_node_rss($node);
-    break;
+ * Implements hook_node_load().
+ */
+function mm_node_node_load(&$nodes, $types) {
+  foreach ($nodes as $nid => $node) {
+    // Make sure the changes are saved to the $nodes
+    _mm_node_node_load($nodes[$nid]);
   }
 }
 
+/**
+ * Implements hook_node_view().
+ */
+function mm_node_node_view($node, $view_mode, $langcode) {
+  if ($view_mode = 'rss') {
+    return mm_node_rss($node);
+  }
+  // Add media mover files to node display
+  return mm_node_node_file_view($node);
+}
+
+/**
+ * Implements hook_node_insert().
+ */
+function mm_node_node_insert($node) {
+  // @TODO is this really needed/working?
+  mm_node_files_translation_insert($node);
+}
+
+/**
+ * Implements hook_node_presave().
+ */
+function mm_node_node_presave($node) {
+  _mm_node_node_presave($node);
+  mm_node_auto_run($node);
+}
+
+/**
+ * Implements hook_node_delete().
+ */
+function mm_node_node_delete($node) {
+  // invoke MM modules here and delete files associated with this node
+  mm_node_files_delete($node);
+}
 
 /**
  * Implements hook_form_alter().
@@ -84,18 +90,27 @@ function mm_node_form_alter(&$form, $form_state, $form_id) {
 }
 
 
-function mm_node_form_node_form_alter($form, $form_state) {
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
+function mm_node_form_node_form_alter(&$form, &$form_state) {
 
 }
 
 
 /**
- * Implements hook_perm().
+ * Implements hook_permission().
  * @return $perm
  *   array
  */
-function mm_node_perm() {
-  return array('view media mover files');
+function mm_node_permission() {
+  return array(
+    'view media mover files' => array(
+      'title' => t('view media mover files'),
+      'description' => t('View media mover files'),
+    ),
+  );
 }
 
 
@@ -110,7 +125,7 @@ function mm_node_perm() {
  */
 function mm_node_form_node_delete_confirm_alter(&$form, $form_state) {
   // check if there is any media mover content
-  // @TODO should check better parameters here
+  // @TODO should check parameters here
   if ($node_mm_files = $form['#parameters'][2]->media_mover ) {
     $files = array();
     foreach ($node_mm_files as $cid => $mmfiles) {
@@ -132,11 +147,11 @@ function mm_node_form_node_delete_confirm_alter(&$form, $form_state) {
 function mm_node_theme() {
   return array(
     'mm_node_files_view' => array(
-      'arguments' => array('element' => NULL),
+      'variables' => array('files' => NULL),
       'file' => 'mm_node.theme.inc',
     ),
     'mm_node_files_edit' => array(
-      'arguments' => array('form' => NULL),
+      'variables' => array('form' => NULL),
       'file' => 'mm_node.theme.inc',
     ),
   );
@@ -149,6 +164,7 @@ function mm_node_theme() {
 function mm_node_theme_registry_alter(&$theme_registry) {
   // We need to override all of the filefield theme functions
   // so that a non-local URI can be used to display the file
+// @todo FIXME - these themes are not defined in Drupal 7 file.module. Need to update!
   $types = array(
     'filefield_file',
     'filefield_formatter_default',
@@ -180,11 +196,12 @@ function mm_node_media_mover() {
   $items = array();
   // We can only offer these if the upload module is enabled
   if (module_exists('upload')) {
+    // @todo: remove, there's no more 'upload.module' in D7
     $items['drupal_upload'] = array(
       'description' => t('Select: Drupal uploaded files'),
       'configuration' => 'mm_node_upload_harvest_config',
       'callback' => 'mm_node_upload_harvest',
-      'harvest' => TRUE,
+      'select' => 1,
       'harvest_from_node' => TRUE,
       'file' => 'includes/mm_node.upload'
     );
@@ -196,12 +213,12 @@ function mm_node_media_mover() {
     );
   }
   // We can only offer these if CCK is enabled
-  if (module_exists('content')) {
+  if (module_exists('field')) {
     $items['mm_node_content_field_select'] = array(
       'description' => t('Select: from a CCK field'),
       'callback' => 'mm_node_content_field_select',
       'configuration' => 'mm_node_content_field_select_config',
-      'harvest' => TRUE,
+      'select' => 1,
       'file' => 'includes/mm_node.content'
     );
     $items['mm_node_content_node_field_store'] = array(
@@ -217,7 +234,7 @@ function mm_node_media_mover() {
       'description' => t('Select: data from an Embedded Media Field'),
       'callback' => 'mm_node_emfield_harvest',
       'configuration' => 'mm_node_emfield_harvest_config',
-      'harvest' => TRUE,
+      'select' => 1,
       'file' => 'includes/mm_node.emfield'
     );
   }
@@ -247,12 +264,12 @@ function mm_node_media_mover() {
 /* ********************************************** */
 
 /**
- * Builds the settings form, used on admin/settings/mm_auto_run and
- * admin/media_mover/settings
+ * Builds the settings form, used on MMA_CONFIG_PATH . '/mm_auto_run' and
+ * MMA_CONFIG_PATH . '/settings'
  *
  * @return array
  */
-function mm_node_run_settings_form() {
+function mm_node_run_settings_form($form, &$form_state) {
   // build some description information
   $form['auto_run'] = array(
     '#type' => 'fieldset',
@@ -266,7 +283,16 @@ function mm_node_run_settings_form() {
   // get a list of all current MM configurations
   $configurations = media_mover_api_configurations_load();
   foreach ($configurations as $configuration) {
-    $options[$configuration->cid] = '<strong>'. l($configuration->name, 'admin/build/media_mover/configurations/' . $configuration->cid) .'</strong><br />'. $configuration->description;
+    $options[$configuration->cid] = '<strong>' . l($configuration->name, MMA_CONFIG_PATH . '/configurations/' . $configuration->cid) . '</strong><br />' . $configuration->description;
+  }
+
+  if (empty($options)) {
+    return array(
+      'auto_run' => array(
+        '#markup' => t('There are no configurations in the system. Please !create one.', array('!create' => l(t('create'), MMA_CONFIG_PATH . '/add'))),
+        '#type' => 'item',
+      ),
+    );
   }
 
   $form['auto_run']['mm_node_run_configs'] = array(
@@ -301,29 +327,27 @@ function mm_node_run_settings_form() {
  *   media mover file array
  */
 function mm_node_node_files_get($nid, $status = MMA_FILE_STATUS_FINISHED) {
-  $file_status = '';
-  $status_id = '';
-
-  if ($status) {
-    $status_id = "_$status";
-    $file_status = "AND status = \"$status\" ";
-  }
-
-  // Create cache name
-  $cache_name = 'node_files_'. $nid . $status_id;
+  $cache_name = 'node_files_' . $nid . ($status ? '_' . $status : '');
   // Get data from the cache
   $data = cache_get($cache_name, 'cache_media_mover');
   // We can haz cache?
-  if (! is_array($data->data)) {
+  if (!is_array($data)) {
     $data = array();
-    $items = db_query('SELECT mmfid, cid FROM {media_mover_files} WHERE nid = %d ' . $file_status . ' ORDER BY cid', $nid);
-    while ($item = db_fetch_object($items)) {
+    $query = db_select('media_mover_files', 'mmf')
+      ->fields('mmf', array('mmfid', 'cid'))
+      ->condition('nid', $nid);
+    if ($status) {
+      $query->condition('status', $status);
+    }
+    $query->orderBy('cid');
+    $result = $query->execute();
+    foreach ($result as $item) {
       $data[$item->cid][$item->mmfid] = media_mover_api_file_get($item->mmfid);
     }
     // Note that we cache a node with zero files
     cache_set($cache_name, $data, 'cache_media_mover', CACHE_TEMPORARY);
   }
-  return $data->data;
+  return $data;
 }
 
 
@@ -425,7 +449,7 @@ function mm_node_save_drupal_file($step, $filepath, $uid = 0, $destination = NUL
   $file->filepath = $filepath;
   $file->filemime = file_get_mimetype($filepath);
   $file->filesize = file_exists($filepath) ? filesize($filepath) : '';
-  $file->timestamp = time();
+  $file->timestamp = REQUEST_TIME;
   $file->list = variable_get('upload_list_default', 1);
   $file->status = 1;
   // save the file
@@ -457,7 +481,7 @@ function mm_node_map_user($file, $step) {
       // check to see if we have this data
       if ($file->data['user']->{$key}) {
         // try to load a user
-        if ($account = user_load(array($key => $file->data['user']->{$key}))) {
+        if ($account = array_shift(user_load_multiple(array(), array($key => $file->data['user']->{$key})))) {
           break;
         }
       }
@@ -465,7 +489,7 @@ function mm_node_map_user($file, $step) {
   }
   // fall back to node data to load the user
   elseif ($file->data['node']->uid && ! $step->settings['node_save_override'] ) {
-    if ($account = user_load(array($key => $file->data['user']->{$key}))) {
+    if ($account = array_shift(user_load_multiple(array(), array($key => $file->data['user']->{$key})))) {
       break;
     }
   }
@@ -474,13 +498,13 @@ function mm_node_map_user($file, $step) {
   if (! $account) {
     // Do we have an override user name or should returned user be anonymous?
     if ($step->settings['node_save_name']) {
-      $array = array('name' => $step->settings['node_save_name']);
+      $array = array();
+      $account = array_shift(user_load_multiple(array(), array('name' => $step->settings['node_save_name'])));
     }
     else {
-      $array = array('uid' => 0);
+      // load the account
+      $account = user_load(0);
     }
-    // load the account
-    $account = user_load($array);
   }
   return $account;
 }
@@ -512,16 +536,16 @@ function mm_node_files_edit_form(&$form) {
     );
     foreach ($node->media_mover as $cid => $files) {
       foreach ($files as $mmfid => $file) {
-        $description = "<small>". check_plain($file->filepath) ."</small>";
-        $form['mm_node_files']['mm_node_'. $file->mmfid]['filepath'] = array('#type' => 'markup', '#value' => $file->filepath);
-        $form['mm_node_files']['mm_node_'. $file->mmfid]['size'] = array('#value' => format_size($file->filesize));
-        $form['mm_node_files']['mm_node_'. $file->mmfid]['remove'] = array('#type' => 'checkbox', '#default_value' => ! empty($file->remove));
-        $form['mm_node_files']['mm_node_'. $file->mmfid]['reprocess'] = array('#type' => 'checkbox');
-        $form['mm_node_files']['mm_node_'. $file->mmfid]['list'] = array(
+        $description = "<small>" . check_plain($file->filepath) . "</small>";
+        $form['mm_node_files']['mm_node_' . $file->mmfid]['filepath'] = array('#type' => 'markup', '#value' => $file->filepath);
+        $form['mm_node_files']['mm_node_' . $file->mmfid]['size'] = array('#value' => format_size($file->filesize));
+        $form['mm_node_files']['mm_node_' . $file->mmfid]['remove'] = array('#type' => 'checkbox', '#default_value' => ! empty($file->remove));
+        $form['mm_node_files']['mm_node_' . $file->mmfid]['reprocess'] = array('#type' => 'checkbox');
+        $form['mm_node_files']['mm_node_' . $file->mmfid]['list'] = array(
           '#type' => 'checkbox',
           '#default_value' => $file->data['list'],
         );
-        $form['mm_node_files']['mm_node_'. $file->mmfid]['status'] = array('#type' => 'markup',  '#value' => $file->status);
+        $form['mm_node_files']['mm_node_' . $file->mmfid]['status'] = array('#type' => 'markup',   '#value' => $file->status);
       }
     }
   }
@@ -555,7 +579,7 @@ function mm_node_files_edit_form_submit($form, $form_state) {
       // @NOTE not sure what to do with any files that were associated with tis file
       elseif ($key['reprocess']) {
         // Set the file status
-       // media_mover_api_file_process($file);
+        // media_mover_api_file_process($file);
       //  $configuration = media_mover_api_configuration_load($file->cid);
       //  $configuration->run_file($file);
       }
@@ -567,7 +591,7 @@ function mm_node_files_edit_form_submit($form, $form_state) {
       }
 
       // Reset the media mover cache for this node
-      $cid = 'node_files_'. $form_state['values']['nid'] . '_' . MMA_FILE_STATUS_FINISHED;
+      $cid = 'node_files_' . $form_state['values']['nid'] . '_' . MMA_FILE_STATUS_FINISHED;
       cache_clear_all($cid, 'cache_media_mover');
 
     }
@@ -584,24 +608,34 @@ function mm_node_files_edit_form_submit($form, $form_state) {
 function mm_node_cck_fields($allowed_types = array()) {
   $options = array();
   // Get all the node types
-  foreach (content_types() as $type_name => $type) {
-     // Get all their fields
-     foreach ($type['fields'] as $field_name => $field) {
-       if ($type) {
-         if (in_array($field['type'], $allowed_types)) {
-           $key = $type_name . '--' . $field_name;
-           $value = $type['name'] . ': ' . $field['widget']['label'];
-           $options[$key] = $value;
-         }
-       }
-       else {
-         $key = $type_name . '--' . $field_name;
-         $value = $type['name'] . ': ' . $field['widget']['label'];
-         $options[$key] = $value;
-       }
-     }
-   }
-   return $options;
+  foreach (node_type_get_types() as $type_name => $type) {
+    $type = (array)$type;
+    // Get all their fields
+    foreach (field_info_instances('node', $type['type']) as $field_name => $field) {
+      // Ignore deleted fields
+      if (!empty($field['deleted'])) {
+        continue;
+      }
+      // field_info_instances() does not return $field['type'], so we set it
+      $field_info = field_info_field($field_name);
+      $field['type'] = $field_info['type'];
+//    foreach ($type['fields'] as $field_name => $field) {
+// @todo: FIXME, what is the purpose of this "if ($type)" - are we expecting it to be empty? Then "else" uses $type['name'] which will fail.
+      if ($type) {
+        if (in_array($field['type'], $allowed_types)) {
+          $key = $type_name . '--' . $field_name;
+          $value = $type['name'] . ': ' . $field['widget']['label'];
+          $options[$key] = $value;
+        }
+      }
+      else {
+        $key = $type_name . '--' . $field_name;
+        $value = $type['name'] . ': ' . $field['widget']['label'];
+        $options[$key] = $value;
+      }
+    }
+  }
+  return $options;
 }
 
 
@@ -669,17 +703,17 @@ function mm_node_auto_run($node) {
 
 
 /**
- * Implements hook_node_load().
+ * Load all files for this node.
  */
-function mm_node_node_load(&$node) {
-	return array('media_mover' => mm_node_node_files_get($node->nid));
+function _mm_node_node_load($node) {
+  $node->media_mover = mm_node_node_files_get($node->nid);
 }
 
 
 /**
- * Implements hook_node_presave().
+ * Worker code for hook_node_presave().
  */
-function mm_node_node_presave(&$node) {
+function _mm_node_node_presave(&$node) {
 
   // The problem with file deletion from nodes is that media mover
   // can harvest and store to different fields which makes it hard
@@ -687,35 +721,35 @@ function mm_node_node_presave(&$node) {
   // for each configuration to specifically look for the file for each
   // step on the configuration
 
-	// Do we have any files stored for this node?
-	if ($configurations_files = mm_node_node_files_get($node->nid)) {
-	  foreach ($configurations_files as $configuration_files) {
-	    foreach ($configuration_files as $file) {
-  	  	$found = array('found' => FALSE, 'delete' => TRUE);
-  		  // Identify any steps that were created by mm_node
-  		  if ($steps = $file->steps_filtered_by_module('mm_node')) {
-  		    foreach ($steps as $step) {
-  	        module_load_include('inc', 'mm_node', $step->build['file']);
-  	        // The file exists functions are the same for each callback
-  	        $function = $step->build['callback'] . '_file_exists';
-  	        if (function_exists($function)) {
-  	        	// Check if this file exists and/or should be deleted. Functions
-  	        	// should set found = TRUE or delete = FALSE to stop the deletion
-  	          if ($function($node, $step, $file, $found)) {
+  // Do we have any files stored for this node?
+  if ($configurations_files = mm_node_node_files_get($node->nid)) {
+    foreach ($configurations_files as $configuration_files) {
+      foreach ($configuration_files as $file) {
+        $found = array('found' => FALSE, 'delete' => TRUE);
+        // Identify any steps that were created by mm_node
+        if ($steps = $file->steps_filtered_by_module('mm_node')) {
+          foreach ($steps as $step) {
+            module_load_include('inc', 'mm_node', $step->build['file']);
+            // The file exists functions are the same for each callback
+            $function = $step->build['callback'] . '_file_exists';
+            if (function_exists($function)) {
+              // Check if this file exists and/or should be deleted. Functions
+              // should set found = TRUE or delete = FALSE to stop the deletion
+              if ($function($node, $step, $file, $found)) {
                 break;
               }
-  	        }
-  	    	}
-  		  }
-	    }
-	    // The file was not found on any part of the node
-	    if (! $found['found']) {
-	    	// Are we supposed to delete this file
-	      if ($found['delete']) {
-	    	  $file->delete();
-	      }
-	    }
-	  }
+            }
+          }
+        }
+      }
+      // The file was not found on any part of the node
+      if (! $found['found']) {
+        // Are we supposed to delete this file
+        if ($found['delete']) {
+          $file->delete();
+        }
+      }
+    }
   }
 }
 
@@ -742,7 +776,7 @@ function mm_node_rss($node) {
           array(
             'key' => 'enclosure',
             'attributes' => array(
-              'url' => $GLOBALS['base_url'] .'/'. $file['filepath'],
+              'url' => $GLOBALS['base_url'] . '/' . $file['filepath'],
               'length' => format_size(filesize($file['filepath'])),
               'type' => file_get_mimetype($file['filepath']),
             )
@@ -774,13 +808,13 @@ function mm_node_publish_options() {
 /**
  * Display media mover files on a node
  *
- * @param type $node
+ * @param object $node
  */
 function mm_node_node_file_view(&$node) {
   // Should we display any files?
   if (count($node->media_mover) && user_access('view media mover files')) {
     $node->content['media_mover_files'] = array(
-      '#value' => theme('mm_node_files_view', $node->media_mover),
+      '#value' => theme('mm_node_files_view', array('files' => $node->media_mover)),
       '#weight' => 50,
     );
   }
diff --git a/modules/mm_node/mm_node.theme.inc b/modules/mm_node/mm_node.theme.inc
index e0d7d7b..2275bd0 100644
--- a/modules/mm_node/mm_node.theme.inc
+++ b/modules/mm_node/mm_node.theme.inc
@@ -1,7 +1,5 @@
 <?php
 
-// $Id$
-
 /**
  * @file
  * This contains the theming functions for node display
@@ -14,7 +12,8 @@
  * @param type $files
  * @return string
  */
-function theme_mm_node_files_view($files) {
+function theme_mm_node_files_view($variables) {
+  $files = $variables['files'];
   $header = array(t('Media Mover files'), t('Size'));
   $rows = array();
   foreach ($files as $cid => $configuration) {
@@ -25,7 +24,7 @@ function theme_mm_node_files_view($files) {
     }
   }
   if (count($rows)) {
-    return theme('table', $header, $rows, array('id' => 'attachments'));
+    return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'attachments')));
   }
 }
 
@@ -35,7 +34,8 @@ function theme_mm_node_files_view($files) {
  *
  * @ingroup themeable
  */
-function theme_mm_node_files_edit(&$form) {
+function theme_mm_node_files_edit($variables) {
+  $form = $variables['form'];
   $header = array(t('List'), t('Delete'), t('Filepath'), t('Size'), t('Status'));
   foreach (element_children($form) as $key) {
     $row = array();
@@ -47,7 +47,7 @@ function theme_mm_node_files_edit(&$form) {
     $row[] = drupal_render($form[$key]['status']);
     $rows[] = array('data' => $row);
   }
-  $output = theme('table', $header, $rows, array('id' => 'mm_node-files'));
-  $output .= drupal_render($form);
+  $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'mm_node-files')));
+  $output .= drupal_render_children($form);
   return $output;
 }
\ No newline at end of file
diff --git a/modules/mm_utilities/mm_utilities.info b/modules/mm_utilities/mm_utilities.info
index 05ffcec..f864c7f 100644
--- a/modules/mm_utilities/mm_utilities.info
+++ b/modules/mm_utilities/mm_utilities.info
@@ -2,5 +2,5 @@ name = "Media Mover Utilities"
 description = Enables utilties for Media Mover Functions
 package = "Media Mover"
 dependencies[] = media_mover_api
-core = 6.x
+core = 7.x
 php = 5.0
diff --git a/modules/mm_utilities/mm_utilities.install b/modules/mm_utilities/mm_utilities.install
index 4e97744..66ab07b 100644
--- a/modules/mm_utilities/mm_utilities.install
+++ b/modules/mm_utilities/mm_utilities.install
@@ -1,7 +1,5 @@
 <?php
 
-// $Id$
-
 /**
  * @file
  * Installation for run control
@@ -12,8 +10,7 @@
  * Install the token table
  */
 function mm_utilities_install() {
-  // Create tables.
-  drupal_install_schema('mm_utilities');
+  // drupal_(un)install_schema functions are called automatically in D7.
 }
 
 
@@ -21,12 +18,12 @@ function mm_utilities_install() {
  * Implements hook_uninstall().
  */
 function mm_utilities_uninstall() {
-  drupal_uninstall_schema('mm_utilities');
+  // drupal_(un)install_schema functions are called automatically in D7.
 }
 
 
 /**
- * Implementation of hook_schema().
+ * Implements hook_schema().
  */
 function mm_utilities_schema() {
   $schema = array();
diff --git a/modules/mm_utilities/mm_utilities.module b/modules/mm_utilities/mm_utilities.module
index 5e30aba..53f33d8 100644
--- a/modules/mm_utilities/mm_utilities.module
+++ b/modules/mm_utilities/mm_utilities.module
@@ -8,6 +8,12 @@
  * reporting on various items
  */
 
+/**
+ * Default 'mm_utilities_monitors' variable value
+ */
+function _mm_utilities_monitors_default() {
+  return array('cpu' => 0, 'file_time' => 0, 'file_count' => 0, 'node_run' => 0, 'cron' => 1);
+}
 
 /* ****************************************** */
 /* Drupal Hook Functions                      */
@@ -32,11 +38,11 @@ function mm_utilities_cron() {
  */
 function mm_utilities_mail($key, &$message, $params) {
   $language = $message['language'];
-  switch($key) {
+  switch ($key) {
     default:
-      $message['subject'] = t($params['subject'], $params['params'], $language->language);
-      $message['body'][] = t($params['body'], $params['params'], $language->language);
-    break;
+      $message['subject'] = t($params['subject'], $params['params'], array('langcode' => $language->language));
+      $message['body'][] = t($params['body'], $params['params'], array('langcode' => $language->language));
+      break;
   }
 }
 
@@ -83,6 +89,7 @@ function mm_utilities_admin_form(&$form) {
       add and edit forms. Each configuration can have it\'s own settings.'),
   );
   $enabled = variable_get('mm_utilities_monitors', array());
+  $enabled += _mm_utilities_monitors_default();
   $form['mm_utilities']['mm_utilities_cpu'] = array(
     '#title' => t('CPU'),
     '#type' => 'checkbox',
@@ -111,7 +118,7 @@ function mm_utilities_admin_form(&$form) {
   $form['mm_utilities']['mm_utilities_cron'] = array(
     '#title' => t('Cron'),
     '#type' => 'checkbox',
-    '#default_value' => isset($enabled['cron']) ? $enabled['cron'] : TRUE,
+    '#default_value' => $enabled['cron'],
     '#description' => t('Enable or disable configurations to run on cron. Default is on.'),
   );
 }
@@ -126,11 +133,9 @@ function mm_utilities_admin_form(&$form) {
  */
 function mm_utilities_admin_form_submit($form, $form_state) {
   $options = array();
-  foreach ($form_state['values'] as $key => $value) {
-    if (strpos($key, 'mm_utilities') !== FALSE && $value) {
-      $key = str_replace('mm_utilities_', '', $key);
-      $options[$key] = TRUE;
-    }
+  foreach (_mm_utilities_monitors_default() as $key => $default) {
+    $value = isset($form_state['values']['mm_utilities_' . $key]) ? !!$form_state['values']['mm_utilities_' . $key] : 0;
+    $options[$key] = $value;
   }
   variable_set('mm_utilities_monitors', $options);
 }
@@ -143,11 +148,11 @@ function mm_utilities_admin_form_submit($form, $form_state) {
  * @return unknown_type
  */
 function mm_utilities_configuration_form(&$form, $form_state) {
-  if ($enabled = variable_get('mm_utilities_monitors', FALSE)) {
-
-    $configuration = $form['#configuration'];
-    $configuration = $form_state['values'] ? (object)($form_state['values']['configuration']) : $configuration;
-
+  $enabled = variable_get('mm_utilities_monitors', array());
+  $enabled += _mm_utilities_monitors_default();
+  $configuration = $form['#configuration'];
+  $configuration = isset($form_state['values']) ? (object) ($form_state['values']['configuration']) : $configuration;
+  if (isset($configuration->settings)) {
     $form['mm_utilities'] = array(
       '#type' => 'fieldset',
       '#title' => t('Run time control'),
@@ -165,12 +170,11 @@ function mm_utilities_configuration_form(&$form, $form_state) {
         '#title' => t('Email monitoring'),
         '#collapsible' => TRUE,
         '#collapsed' => $configuration->settings['email_monitor']['mm_utilities_email_file'] ? false : true,
-        '#description' => t('Sometimes a files fail to complete during processing.
-          If a file is running longer than the specified time, an email will be sent'),
+        '#description' => t('Sometimes a files fail to complete during processing. If a file is running longer than the specified time, an email will be sent'),
       );
       $form['mm_utilities']['email_monitor']['mm_utilities_email_file'] = array(
         '#type' => 'checkbox',
-        '#title' => t('Notify admin when a MM file has run to long'),
+        '#title' => t('Notify admin when a MM file has run too long'),
         '#default_value' => $configuration->settings['email_monitor']['mm_utilities_email_file'],
       );
       $form['mm_utilities']['email_monitor']['mm_utilities_email_file_email'] = array(
@@ -233,12 +237,11 @@ function mm_utilities_configuration_form(&$form, $form_state) {
         '#type' => 'checkbox',
         '#title' => t('Node create/update'),
         '#default_value' => $configuration->settings['node_run_enabled']['mm_utilities_node_run'],
-        '#description' => t('When nodes are created or updated run this configuration.
-          This is only usefull for configurations that harvest files from nodes'),
+        '#description' => t('When nodes are created or updated run this configuration. This is only usefull for configurations that harvest files from nodes'),
       );
     }
 
-    // Limit by file_count. 
+    // Limit by file_count.
     if ($enabled['file_count']) {
       $form['mm_utilities']['file_count_settings'] = array(
         '#type' => 'fieldset',
@@ -285,21 +288,21 @@ function mm_utilities_configuration_form(&$form, $form_state) {
 function mm_utilities_monitor_files() {
   $configurations = media_mover_api_configurations_load();
   foreach ($configurations as $cid => $configuration) {
-    if (!$configuration->settings['email_monitor']['mm_utilities_email_file']) { 
+    if (!$configuration->settings['email_monitor']['mm_utilities_email_file']) {
       continue;
     }
     // Only send one email per email frequency per configuration
-    if ($configuration->settings['email_monitor']['mm_utilities_email_last_sent'] > (time() - variable_get('mm_utilities_email_frequency', 3600))) {
+    if ($configuration->settings['email_monitor']['mm_utilities_email_last_sent'] > (REQUEST_TIME - variable_get('mm_utilities_email_frequency', 3600))) {
       continue;
     }
     $rows = array();
-    $time = time() - ($configuration->settings['email_monitor']['mm_utilities_email_file_time'] * 60);
-    $results = db_query("SELECT mmfid, cid, lock_date FROM {media_mover_files} WHERE lock_date < %d AND status = '%s' AND cid = '%s' ORDER BY lock_date", $time, MMA_FILE_STATUS_LOCKED, $cid);
-    while ($result = db_fetch_array($results)) {
+    $time = REQUEST_TIME - ($configuration->settings['email_monitor']['mm_utilities_email_file_time'] * 60);
+    $results = db_query("SELECT mmfid, cid, lock_date FROM {media_mover_files} WHERE lock_date < :lock_date AND status = :status AND cid = :cid ORDER BY lock_date", array(':lock_date' => $time, ':status' => MMA_FILE_STATUS_LOCKED, ':cid' => $cid))->execute();
+    while ($result = $results->fetchAssoc()) {
       $rows[] = t('!mmfid | !date | !link', array(
         '!mmfid' => $result['mmfid'],
         '!date' => format_date($result['lock_date']),
-        '!link' => l($result['mmfid'], '/admin/build/media_mover/file/edit/' . $result['mmfid'], array('absolute' => TRUE))
+        '!link' => l($result['mmfid'], MMA_CONFIG_PATH . '/file/edit/' . $result['mmfid'], array('absolute' => TRUE))
       ));
     }
 
@@ -315,7 +318,7 @@ or examine the following configurations to see if there is a particular issue wi
 
     $params = array(
       '!name' => $configuration->name,
-      '!time' => intval( (time() - $configuration->start_time) / 60),
+      '!time' => intval( (REQUEST_TIME - $configuration->start_time) / 60),
       '!site_name' => variable_get('site_name', '')
     );
 
@@ -326,7 +329,7 @@ or examine the following configurations to see if there is a particular issue wi
     );
 
     // Only send one email per email frequency per configuration
-    $configuration->settings['email_monitor']['mm_utilities_email_last_sent'] = time();
+    $configuration->settings['email_monitor']['mm_utilities_email_last_sent'] = REQUEST_TIME;
     $configuration->save();
     drupal_mail('mm_utilities', 'long_running_files', $configuration->settings['email_monitor']['mm_utilities_email_file_email'], language_default(), $email_params);
 
@@ -347,8 +350,8 @@ function mm_utilities_cpu_load($time = NULL) {
     $time = variable_get('mma_cpu_limit_sample', 5);
   }
   ob_start();
-    passthru('w' ." 2>&1", $command_return);
-    $command_output = ob_get_contents();
+  passthru('w' . " 2>&1", $command_return);
+  $command_output = ob_get_contents();
   ob_end_clean();
 
   // split the output
@@ -363,7 +366,7 @@ function mm_utilities_cpu_load($time = NULL) {
 /* ****************************************** */
 
 /**
- * Implements of hook_media_mover().
+ * Implements hook_media_mover().
  *
  * @return array
  */
@@ -373,7 +376,7 @@ function mm_utilities_media_mover() {
     'description' => t('Select: from a Media Mover configuration'),
     'configuration' => 'mm_utilties_select_mm_config',
     'callback' => 'mm_utilities_select_mm',
-    'harvest' => TRUE,
+    'select' => 1,
   );
   $items['mm_utilities_delete'] =  array(
     'description' => t('Process: delete source material'),
@@ -398,8 +401,8 @@ function mm_utilities_media_mover_process_control_alter(&$errors, $file, $step)
   static $run_count = array();
 
   $configuration = media_mover_api_configuration_load($step->cid);
-  
-    // CPU limiting
+
+  // CPU limiting
   if ($configuration->settings['cpu_monitor']['mm_utilities_cpu_load']) {
     $load = mm_utilities_cpu_load($configuration->settings['cpu_monitor']['mm_utilities_cpu_average']);
     // Is the CPU load higher than the threshold?
@@ -430,6 +433,45 @@ function mm_utilities_media_mover_process_control_alter(&$errors, $file, $step)
   }
 }
 
+/**
+ * Implements hook_media_mover_configuration_load().
+ */
+function mm_utilities_media_mover_configuration_load_alter(&$configuration) {
+// @todo: Implement mm_utilities settings
+  $configuration->settings += array(
+    'email_monitor' => array(
+      'mm_utilities_email_file' => 1,
+      'mm_utilities_email_file_email' => '',
+      'mm_utilities_email_file_time' => 5,
+    ),
+
+    'cpu_monitor' => array(
+      'mm_utilities_cpu' => 1,
+      'mm_utilities_cpu_threshold' => 5,
+      'mm_utilities_cpu_average' => 1,
+    ),
+
+    'node_run_enabled' => array(
+      'mm_utilities_node_run' => 1,
+    ),
+
+    'file_count_settings' => array(
+      'mm_utilities_file_count' => 5,
+    ),
+
+    'cron_settings' => array(
+      'mm_utilities_cron' => 1,
+    ),
+  );
+//drupal_set_message('IN configuration_load_alter '.iprintr($configuration, 'configuration'));
+}
+
+/**
+ * Implements hook_media_mover_configuration_presave().
+ */
+function mm_utilities_media_mover_configuration_presave_alter(&$configuration) {
+//drupal_set_message('IN configuration_presave_alter '.iprintr($configuration, 'configuration'));
+}
 
 /**
  * Configuration for harvesting files from Media Mover configurations
@@ -521,14 +563,12 @@ function mm_utilities_select_mm($step) {
 
   // We find files that are more recent that the last time that
   // this harvest process
-  $results = db_query("SELECT mmf.mmfid AS mmfid
-    FROM {media_mover_files} mmf
-    WHERE mmf.cid = '%s'
-    AND mmf.status = '%s' AND mmf.date >= %d",
-    $cid, MMA_FILE_STATUS_FINISHED, $step->cid, $step->stop_time);
-
-  // We have our files, now pull them out of the db;
-  while ($result = db_fetch_array($results)) {
+  $results = db_query("SELECT mmf.mmfid AS mmfid FROM {media_mover_files} mmf
+    WHERE mmf.cid = :mmf.cid AND mmf.status = :mmf.status AND mmf.date >= :mmf.date",
+    array(':mmf.cid' => $cid, ':mmf.status' => MMA_FILE_STATUS_FINISHED, ':mmf.date' => $step->cid, '' => $step->stop_time))->execute();
+
+  // We have our files, now pull them out of the db
+  while ($result = $results->fetchAssoc()) {
     // Load the file
     $file = media_mover_api_file_get($result['mmfid']);
     // Retrive the filepath from the previous file
