--- /home/darren/autosave/autosave.module	2008-07-20 19:42:11.000000000 -0400
+++ autosave.module	2008-09-09 18:50:29.000000000 -0400
@@ -6,79 +6,79 @@
  * Automatically saves a node after a period of time.
  */
 
+define('AUTOSAVE_PATH', drupal_get_path('module', 'autosave'));
+
 /**
  * Implementation of hook_help().
  */
-function autosave_help($section) {
-  switch ($section) {
+function autosave_help($path, $arg) {
+  $output = '';
+  switch ($path) {
     case 'admin/help#autosave':
       $output = '<p>'. t('The autosave module automatically saves a form after a period of time.') .'</p>';
-      return $output;
+      break;
   }
+  return $output;
 }
 
 /**
  * Implementation of hook_menu().
  */
-function autosave_menu($may_cache) {
-  global $user;
-  $items = array();
+function autosave_menu() {
+  $items['admin/autosave'] = array(
+    'title'           => 'Autosave save',
+    'page callback'   => 'autosave_save',
+    'access callback' => TRUE,
+    'type'            => MENU_CALLBACK,
+  );
 
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/autosave', 
-      'title' => t('Autosave save'),
-      'callback' => 'autosave_save', 
-      'access' => TRUE,
-      'type' => MENU_CALLBACK,
-    );
-    
-    $items[] = array(
-      'path' => 'admin/settings/autosave',
-      'title' => t('Autosave'),
-      'description' => t('Configure autosave settings.'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('autosave_admin_settings'),
-      'access' => user_access('administer nodes'),
-    );
-  }
+  $items['admin/settings/autosave'] = array(
+    'title'            => 'Autosave',
+    'description'      => 'Configure autosave settings.',
+    'page callback'    => 'drupal_get_form',
+    'page arguments'   => array('autosave_admin_settings'),
+    'access arguments' => array('administer nodes'),
+  );
   return $items;
 }
 
 /**
+ * Implementation of hook_form_alter() for node_type_form
+ */
+function autosave_form_node_type_form_alter(&$form, $form_state) {
+  $form['workflow']['autosave'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Enable Autosave to add/edit forms for this node type'),
+    '#default_value' => variable_get('autosave_'. $form['#node_type']->type, 0),
+    '#description' => t('Check this box to enable Autosave for this node type.')
+  );
+}
+
+/**
  * Implementation of hook_form_alter().
  */
-function autosave_form_alter($form_id, &$form) {
- 
+function autosave_form_alter(&$form, &$form_state, $form_id) {
+
   // TODO: Allow user to configure which forms can be autosaved.
   if (end(explode('/', $_GET['q'])) == 'configure-autosave') {
     drupal_add_js('var configure_autosave = true;', 'inline');
-    drupal_add_js(drupal_get_path('module', 'autosave') .'/autosave.js');
-    drupal_add_js(drupal_get_path('module', 'autosave') .'/jquery.field.js');
-    drupal_add_css(drupal_get_path('module', 'autosave') .'/autosave.css');
-  }
-  
-  if ($form_id == 'node_type_form') {
-    $form['workflow']['autosave'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Enable Autosave to add/edit forms for this node type'),
-      '#default_value' => variable_get('autosave_'. $form['#node_type']->type, 0),
-      '#description' => t('Check this box to enable Autosave for this node type.')
-    );
-  }  
-   
+    drupal_add_js(AUTOSAVE_PATH .'/autosave.js');
+    drupal_add_js(AUTOSAVE_PATH .'/jquery.field.js');
+    drupal_add_css(AUTOSAVE_PATH .'/autosave.css');
+  }
+
   if (isset($form['type']['#value']) && ($form_id == $form['type']['#value'] .'_node_form')) {
-    
+
     // check if this content_type has the autosave function enabled and make sure it's a node edit or add form
-    if ( (variable_get('autosave_'. $form['type']['#value'], 0) == 1) && 
+    if ( (variable_get('autosave_'. $form['type']['#value'], 0) == 1) &&
           ( (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'edit') || (arg(0) == 'node' && arg(1) == 'add') )
         ) {
       global $user;
       $path = $_GET['q'];
-      drupal_add_js(drupal_get_path('module', 'autosave') .'/autosave.js');
-      drupal_add_js(drupal_get_path('module', 'autosave') .'/jquery.field.js');
-      drupal_add_css(drupal_get_path('module', 'autosave') .'/autosave.css');
-      
+      drupal_add_js(AUTOSAVE_PATH .'/autosave.js');
+      drupal_add_js(AUTOSAVE_PATH .'/jquery.field.js');
+      drupal_add_css(AUTOSAVE_PATH .'/autosave.css');
+
       if ($form['type']['#value'] .'_node_form' == $form_id) {
         $settings['form_id'] = 'node_form';
       }
@@ -88,7 +88,7 @@ function autosave_form_alter($form_id, &
       $settings['period'] = variable_get('autosave_period', 10);
       $settings['autosave_url'] = url('admin/autosave');
       $settings['q'] = $path;
-      
+
       // If an autosaved version of the form exists, make it available via javascript.
       if ($autosaved_form = autosave_get_autosaved_form($form_id, $path, $user->uid)) {
         $autosaved_form_id = ($form['type']['#value'] .'_node_form' == $form_id) ? 'node_form' : $form_id;
@@ -107,20 +107,15 @@ function autosave_form_alter($form_id, &
  * Menu callback; return the autosave module settings form.
  */
 function autosave_admin_settings() {
-  $types = node_get_types();
-  
-  $path = drupal_get_path('module', 'autosave');
-  
-  if (!file_exists($path .'/jquery.field.js')) {
+  if (!file_exists(AUTOSAVE_PATH .'/jquery.field.js')) {
     drupal_set_message(t('Unable to find the jQuery Field Plugin in !path. Please <a href="http://plugins.jquery.com/files/jquery.field.js_4.txt">download jquery.field.js</a> and place it into !path.', array('!path' => $path)), 'error');
   }
-  
+
   $form['autosave_period'] = array(
     '#type' => 'textfield',
     '#title' => t('Autosave after this amount seconds has passed'),
     '#default_value' => variable_get('autosave_period', 10),
   );
-
   return system_settings_form($form);
 }
 
@@ -128,30 +123,34 @@ function autosave_admin_settings() {
  * Menu callback; autosaves the node.
  */
 function autosave_save() {
-  global $user;  
+  global $user;
   $path = $_POST['q'];
   $form_id = $_POST['form_id'];
   // Not all variables need to be serialized.
-  //unset($_POST['form_token'], $_POST['q']);    
-  unset($_POST['q']);  
+  //unset($_POST['form_token'], $_POST['q']);
+  unset($_POST['q']);
   $serialized = serialize($_POST);
-  
+
   // check if node has just been saved - if it has then it's because AS ajax fired off as user was submitting
   // if it had just been submitted - no need to AS now
   //    - easy to figure out if we are submitting an edit to existing node
   //    - little harder if we have just added a node
-  $path_args = explode("/", $path);                
+  $path_args = explode("/", $path);
   // update case
-  if (is_numeric($path_args[1])) $submitted = node_load($path_args[1]);       
-  // add case  
-  else $submitted->changed = db_result(db_query("SELECT created FROM {node} WHERE uid = %d and type = '%s' ORDER BY created DESC LIMIT 1", $user->uid, str_replace("-", "_", $path_args[2])));                                 
+  if (is_numeric($path_args[1])) {
+    $submitted = node_load($path_args[1]);
+  }
+  else {
+    // add case
+    $submitted->changed = db_result(db_query("SELECT created FROM {node} WHERE uid = %d and type = '%s' ORDER BY created DESC LIMIT 1", $user->uid, str_replace("-", "_", $path_args[2])));
+  }
+
   if (!$submitted || (time() - $submitted->changed) > 10) {
     // Currently, each user can have only one autosave form at a particular path.
     db_query("DELETE FROM {autosaved_forms} WHERE form_id = '%s' AND path = '%s' AND uid = %d", $form_id, $path, $user->uid);
-    db_query("INSERT INTO {autosaved_forms} (form_id, path, uid, timestamp, serialized) VALUES ('%s', '%s', %d, %d, '%s')",
-      $form_id, $path, $user->uid, time(), $serialized);
+    db_query("INSERT INTO {autosaved_forms} (form_id, path, uid, timestamp, serialized) VALUES ('%s', '%s', %d, %d, '%s')", $form_id, $path, $user->uid, time(), $serialized);
   }
-    
+
   exit();
 }
 
@@ -160,16 +159,16 @@ function autosave_save() {
  *
  * @param string $form_id
  *   The form_id of the form.
- * @param string $path 
+ * @param string $path
  *   The the internal Drupal path where the form is located
- * @param string $uid 
+ * @param string $uid
  *   Drupal UID of the user
  * @return
  *   An array containing the serialized values of the autosaved form and the timestamp of when the form was autosaved.
  */
 function autosave_get_autosaved_form($form_id, $path, $uid) {
   $result = db_query("SELECT form_id, serialized, timestamp FROM {autosaved_forms} WHERE form_id = '%s' AND path = '%s' AND uid = %d", $form_id, $path, $uid);
-  
+
   while ($data = db_fetch_object($result)) {
     $form['serialized'] = $data->serialized;
     $form['timestamp'] = $data->timestamp;
@@ -179,13 +178,12 @@ function autosave_get_autosaved_form($fo
 
 /**
  * Implementation of hook_nodeapi().
- * 
+ *
  * Delete autosave table entry on successful submit (add or update) of node
  *
  */
 function autosave_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
   if ($op == 'submit') {
-      //global $user;
       // we remove ALL edits for that page (not just the users) to avoid:
       //  - user1 asaves but doesnt submit
       //  - user2 edits same node and submits
