Index: nodewords_bypath.forms.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodewords_bypath/Attic/nodewords_bypath.forms.inc,v
retrieving revision 1.1.2.3
diff -u -u -p -r1.1.2.3 nodewords_bypath.forms.inc
--- nodewords_bypath.forms.inc	6 Aug 2008 13:28:29 -0000	1.1.2.3
+++ nodewords_bypath.forms.inc	30 Dec 2008 22:40:21 -0000
@@ -13,18 +13,23 @@
  */
 function nodewords_bypath_admin_overview() {
   $form  = array();
-  $rules = _nodewords_bypath_get_all();
-  
-  foreach ($rules as $rule) {
-    $form[$rule->id]['id'] = array(
-      '#type'  => 'value',
-      '#value' => $rule->id,
-    );
-    
-    $form[$rule->id]['name']   = array('#value' => $rule->name);
-    $form[$rule->id]['weight'] = array('#value' => $rule->weight);
-    $form[$rule->id]['edit']   = array('#value' => l(t('Edit'), 'admin/content/nodewords/path/edit/'. $rule->id));
-    $form[$rule->id]['delete'] = array('#value' => l(t('Delete'), 'admin/content/nodewords/path/delete/'. $rule->id));
+  $rules = _nodewords_bypath_load_all();
+
+  if (empty($rules)) {
+    $form['emptytext']['#value'] = t('No rules found. <a href="@newrule">Create a new rule to get started.</a>', array('@newrule' => url('admin/content/nodewords/path/new')));
+  }
+  else {
+    foreach ($rules as $rule) {
+      $form[$rule->id]['id'] = array(
+        '#type'  => 'value',
+        '#value' => $rule->id,
+      );
+      
+      $form[$rule->id]['name']   = array('#value' => $rule->name);
+      $form[$rule->id]['weight'] = array('#value' => $rule->weight);
+      $form[$rule->id]['edit']   = array('#value' => l(t('Edit'), 'admin/content/nodewords/path/'. $rule->id .'/edit'));
+      $form[$rule->id]['delete'] = array('#value' => l(t('Delete'), 'admin/content/nodewords/path/'. $rule->id .'/delete'));
+    }
   }
   
   return $form;
@@ -35,17 +40,16 @@ function nodewords_bypath_admin_overview
  * Generate the form for creating a new custom title rule or editing an
  * existing one.
  *
- * @param $id int The ID of an existing title pattern to edit. If specified,
- *        this title pattern will be used to populate the form fields.
+ * @param $rule An existing rule to edit. If specified, this rule will be used
+ *   to populate the form fields.
  *
  * @return array The form.
  */
-function nodewords_bypath_create_form($id = -1) {
+function nodewords_bypath_form(&$form_state, $rule = NULL) {
   $form = array();
-  
-  $existing = ($id > -1) ? _nodewords_bypath_load_instance($id) : NULL;
-  if ($existing !== NULL) {
-    $existing->tags = _nodewords_bypath_get_tags_for($id);
+
+  if (!$rule) {
+    $rule = new stdClass;
   }
 
   //------------------------------------------------------------------------
@@ -54,25 +58,25 @@ function nodewords_bypath_create_form($i
     '#type'        => 'fieldset',
     '#title'       => t('Meta Tag Rule'),
     '#collapsible' => TRUE,
-    '#weight'      => -5,
+    '#weight'      => -10,
   );
   
   $form['meta_rule']['rule_id'] = array(
     '#type'  => 'value',
-    '#value' => ($existing !== NULL) ? $existing->id : -1,
+    '#value' => $rule->id,
   );
   
   $form['meta_rule']['name'] = array(
     '#type'          => 'textfield',
     '#title'         => t('Name'),
-    '#default_value' => ($existing !== NULL) ? $existing->name : '',
+    '#default_value' =>  $rule->name,
     '#description'   => t('A short name to help you identify this rule when it\'s shown in the list view.'),
   );
   
   $form['meta_rule']['weight'] = array(
     '#type'        => 'select',
     '#title'       => t('Weight'),
-    '#default_value' => ($existing !== NULL) ? $existing->weight : 0,
+    '#default_value' => ($rule) ? $rule->weight : 0,
     '#options'     => drupal_map_assoc(range(-10, 10)),
     '#description' => t('This determines the order that rules are evaluated. Rules with lower weight values are evaluated before rules with higher weights. Evaluation stops at the first rule that matches the path.'),
   );
@@ -85,7 +89,7 @@ function nodewords_bypath_create_form($i
   $form['meta_rule']['type'] = array(
     '#type'        => 'radios',
     '#title'       => t('Rule Application'),
-    '#default_value' => ($existing !== NULL) ? $existing->type : 1,
+    '#default_value' => ($rule) ? $rule->type : 1,
     '#options'     => $options,
     '#description' => t('Determines the method used apply the meta tag rule.'),
   );
@@ -104,7 +108,7 @@ function nodewords_bypath_create_form($i
   $form['meta_rule']['paths'] = array(
       '#type'          => 'textarea',
       '#title'         => t('Path(s)'),
-      '#default_value' => ($existing !== NULL) ? $existing->path_expr : '',
+      '#default_value' => ($rule) ? $rule->path_expr : '',
       '#description'   => $description,
   );
 
@@ -125,10 +129,10 @@ function nodewords_bypath_create_form($i
   foreach (_nodewords_get_possible_tags() as $tag) {
     $function = 'nodewords_'. $tag .'_form';
     if ($settings['edit'][$tag] && function_exists($function)) {
-      $default = ($existing !== NULL) ? $existing->tags[$tag] : '';
+      $default = ($rule) ? $rule->tags[$tag] : '';
       $element = $function('page', $default, $settings);
       if ($element) {
-        $form['meta_tags']['meta_tag_' . $tag] = $element;
+        $form['meta_tags']['meta_tag_'. $tag] = $element;
       }
     }
   }
@@ -136,7 +140,7 @@ function nodewords_bypath_create_form($i
   //------------------------------------------------------------------------
   $form['submit'] = array(
     '#type'  => 'submit', 
-    '#value' => ($existing !== NULL) ? t('Update Rule') : t('Save Rule'),
+    '#value' => ($rule) ? t('Update Rule') : t('Save Rule'),
   );
   
   $form['cancel'] = array(
@@ -154,30 +158,32 @@ function nodewords_bypath_create_form($i
  * @param $form_id mixed The ID of the form.
  * @param $form_values array The form values. 
  */
-function nodewords_bypath_create_form_submit($form_id, $form_values) {
+function nodewords_bypath_form_submit($form, &$form_state) {
   // -------------------------------------------------------------------------
   // Bail out on cancel.
-  if ($form_values['op'] == t('Cancel')) {
-    return 'admin/content/nodewords/path';
+  if ($form_state['values']['op'] == t('Cancel')) {
+    $form_state['redirect'] = 'admin/content/nodewords/path';
+    return;
   }
   
   // -------------------------------------------------------------------------
   // Build the rule object and save it.
   $rule            = new stdClass;
-  $rule->id        = $form_values['rule_id'];
-  $rule->name      = trim($form_values['name']);
-  $rule->path_expr = trim($form_values['paths']);
-  $rule->weight    = intval($form_values['weight']);
-  $rule->type      = intval($form_values['type']);
+  $rule->id        = $form_state['values']['rule_id'];
+  $rule->name      = trim($form_state['values']['name']);
+  $rule->path_expr = trim($form_state['values']['paths']);
+  $rule->weight    = intval($form_state['values']['weight']);
+  $rule->type      = intval($form_state['values']['type']);
   $rule->tags      = array();
   
   $viewable_tags = _nodewords_get_viewable_tags();
-    
   foreach ($viewable_tags as $tag_name) {
-    $rule->tags[$tag_name] = trim($form_values['meta_tag_' . $tag_name]);
+    if (array_key_exists('meta_tag_'. $tag_name, $form_state['values'])) {
+      $rule->tags[$tag_name] = trim($form_state['values']['meta_tag_'. $tag_name]);
+    }
   }
   
-  _nodewords_bypath_save($rule);
+  nodewords_bypath_rule_save($rule);
   if ($rule->id > -1) {
     drupal_set_message(t('Updated meta tag rule %name', array('%name' => $rule->name)));
   }
@@ -185,34 +191,33 @@ function nodewords_bypath_create_form_su
     drupal_set_message(t('', array('%name' => $rule->name)));
   }
   
-  return 'admin/content/nodewords/path';
+  $form_state['redirect'] = 'admin/content/nodewords/path';
+  return; 
 }
 
 
 /**
  * Generate the confirmation form for deleting a title.
  *
- * @param $id int The ID of the rule to delete.
+ * @param $rule The rule to delete.
  *
  * @return array The form.
  */
-function nodewords_bypath_delete_form($id) {
+function nodewords_bypath_delete_form(&$form_state, $rule) {
   $form = array();
   
-  $existing = _nodewords_bypath_load_instance($id);
-  
   $form['pattern_id'] = array(
     '#type'  => 'value',
-    '#value' => $id,
+    '#value' => $rule->id,
   );
   
   $form['pattern_name'] = array(
     '#type'  => 'value',
-    '#value' => $existing->name,
+    '#value' => $rule->name,
   );
   
   $question = t('You are about to remove the meta tag rule "%name".',
-                array('%name' => $existing->name,));
+                array('%name' => $rule->name));
   $desc     = t('This action cannot be undone.');
                 
   return confirm_form($form, $question, 'admin/content/nodewords/path', $desc, t('Delete'), t('Cancel'));
@@ -228,15 +233,16 @@ function nodewords_bypath_delete_form($i
  * @return string The path to send the browser to after the form is
  *         submitted.
  */
-function nodewords_bypath_delete_form_submit($form_id, $form_values) {
-  $id = $form_values['pattern_id'];
+function nodewords_bypath_delete_form_submit($form, &$form_state) {
+  $id = $form_state['values']['pattern_id'];
   
   db_query('DELETE FROM {nodewords_bypath_rules} WHERE id = %d', $id);
   db_query('DELETE FROM {nodewords_bypath_tags} WHERE rule_id = %d', $id);
   
-  drupal_set_message(t('Meta tag path rule "%name" has been deleted.', array('%name' => $form_values['pattern_name'])));
+  drupal_set_message(t('Meta tag path rule "%name" has been deleted.', array('%name' => $form_state['values']['pattern_name'])));
   
-  return 'admin/content/nodewords/path';
+  $form_state['redirect'] = 'admin/content/nodewords/path';
+  return; 
 }
 
 
@@ -260,10 +266,10 @@ function nodewords_bypath_tokenref_form(
     '#description' => t('Global tokens are available site wide. They may be used for meta tag rules that affect any page.'),
   );
   
-  foreach($tokens['global'] as $token => $description) {
+  foreach ($tokens['global'] as $token => $description) {
     $form['global_tokens'][$token]['left'] = array(
       '#type'  => 'item',
-      '#value' => '[' . $token . ']',
+      '#value' => '['. $token .']',
     );
     
     $form['global_tokens'][$token]['right'] = array(
@@ -282,10 +288,10 @@ function nodewords_bypath_tokenref_form(
     '#description' => t('Node tokens are available for page-level node presentation.'),
   );
   
-  foreach($tokens['node'] as $token => $description) {
+  foreach ($tokens['node'] as $token => $description) {
     $form['node_tokens'][$token]['left'] = array(
       '#type'  => 'item',
-      '#value' => '[' . $token . ']',
+      '#value' => '['. $token .']',
     );
     
     $form['node_tokens'][$token]['right'] = array(
@@ -297,7 +303,6 @@ function nodewords_bypath_tokenref_form(
   return $form;
 }
 
-
 /**
  * Theme the token reference form.
  *
@@ -362,20 +367,23 @@ function theme_nodewords_bypath_tokenref
  * @return string The rendered form elements.
  */
 function theme_nodewords_bypath_admin_overview($form) {
-  $rows = array();
-  foreach ($form as $name => $element) {
-    if (isset($element['name']) && is_array($element['name'])) {
-      $rows[] = array(
-        drupal_render($element['name']),
-        drupal_render($element['weight']),
-        drupal_render($element['edit']),
-        drupal_render($element['delete'])
-      );
-      unset($form[$name]);
+  $output = '';
+  if (!$form['emptytext']) {
+    $rows = array();
+    foreach ($form as $name => $element) {
+      if (isset($element['name']) && is_array($element['name'])) {
+        $rows[] = array(
+          drupal_render($element['name']),
+          drupal_render($element['weight']),
+          drupal_render($element['edit']),
+          drupal_render($element['delete'])
+        );
+        unset($form[$name]);
+      }
     }
+    $header = array(t('Name'), t('Weight'), t('Edit'), t('Delete'));
+    $output = theme('table', $header, $rows);
   }
-  $header = array(t('Name'), t('Weight'), t('Edit'), t('Delete'));
-  $output = theme('table', $header, $rows);
   $output .= drupal_render($form);
 
   return $output;
Index: nodewords_bypath.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodewords_bypath/Attic/nodewords_bypath.info,v
retrieving revision 1.1.2.1
diff -u -u -p -r1.1.2.1 nodewords_bypath.info
--- nodewords_bypath.info	17 Jun 2008 18:36:25 -0000	1.1.2.1
+++ nodewords_bypath.info	30 Dec 2008 22:40:21 -0000
@@ -1,5 +1,5 @@
 ; $Id: nodewords_bypath.info,v 1.1.2.1 2008/06/17 18:36:25 shannonlucas Exp $
 name = Meta tags by path
 description = Allows custom meta tags based on path rules
-dependencies = nodewords
-core = 5.x
+dependencies[] = nodewords
+core = 6.x
Index: nodewords_bypath.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodewords_bypath/Attic/nodewords_bypath.install,v
retrieving revision 1.1.2.1
diff -u -u -p -r1.1.2.1 nodewords_bypath.install
--- nodewords_bypath.install	17 Jun 2008 18:36:25 -0000	1.1.2.1
+++ nodewords_bypath.install	30 Dec 2008 22:40:21 -0000
@@ -11,74 +11,97 @@
  * Implementation of hook_install().
  */
 function nodewords_bypath_install() {
-	switch ($GLOBALS['db_type']) {
-		case 'mysql':
-		case 'mysqli':
-		  // -----------------------------------------------------------------------
-		  // Maps a Drupal path expression or PHP logic to a set of meta tags and 
-		  // their values that should be placed in the HTML head on pages matching
-		  // that expression.
-		  //
-		  // The 'type' column indicates whether the path_expr is a list of paths
-		  // or a block of PHP code. The allowed values are:
-		  //        0 - Reserved (don't use)
-		  //        1 - Show on only the listed pages.
-		  //        2 - Show if path_expr contains PHP code that returns TRUE
-		  //
-		  // 'weight' is the order in which the expressions are evaluated. Items
-		  // with lower weights are evaluated before items with higher weights.
-		  db_query("CREATE TABLE {nodewords_bypath_rules} (
-		                         id          int        unsigned NOT NULL,
-		                         name        varchar(128)        NOT NULL,
-		                         type        tinyint(1) unsigned NOT NULL default 1,
-		                         path_expr   text                NOT NULL,
-		                         weight      tinyint             NOT NULL default 0,
-		                   PRIMARY KEY (id)
-		           )"
-		  );
-
-		  db_query('CREATE TABLE {nodewords_bypath_tags} (
-		                         rule_id    int unsigned NOT NULL,
-		                         meta_tag   varchar(32)  NOT NULL,
-		                         meta_value text,
-		                   PRIMARY KEY (rule_id, meta_tag)
-		           )'
-		  );
-
-			$success = TRUE;
-			break;
-		default:
-			drupal_set_message(t('Unsupported database.'));
-	}
-	
-	if ($success) {
-		drupal_set_message(t('Meta tags by path installed all tables successfully.'));
-	}
-	else {
-		drupal_set_message(t('Meta tags by path could not be installed.'), 'error');
-	}		
+  drupal_install_schema('nodewords_bypath');
 }
 
-
 /**
  * Implementation of hook_uninstall().
  */
 function nodewords_bypath_uninstall() {
-	switch ($GLOBALS['db_type']) {
-		case 'mysql':
-		case 'mysqli':
-		  db_query('DROP TABLE IF EXISTS {nodewords_bypath_rules} CASCADE');
-		  db_query('DROP TABLE IF EXISTS {nodewords_bypath_tags} CASCADE');
-			$success = TRUE;
-			break;
-		default:
-			drupal_set_message(t('Unsupported database.'));
-	}
-	
-	if ($success) {
-		drupal_set_message(t('Meta tags by path uninstalled successfully.'));
-	}
-	else {
-		drupal_set_message(t('Meta tags by path could not be uninstalled.'), 'error');
-	}
+  drupal_uninstall_schema('nodewords_bypath');
+}
+
+/**
+ * Implementation of hook_schema().
+ */
+function nodewords_bypath_schema() {
+  $schema = array();
+  // -----------------------------------------------------------------------
+  // Maps a Drupal path expression or PHP logic to a set of meta tags and 
+  // their values that should be placed in the HTML head on pages matching
+  // that expression.
+  //
+  // The 'type' column indicates whether the path_expr is a list of paths
+  // or a block of PHP code. The allowed values are:
+  //        0 - Reserved (don't use)
+  //        1 - Show on only the listed pages.
+  //        2 - Show if path_expr contains PHP code that returns TRUE
+  //
+  // 'weight' is the order in which the expressions are evaluated. Items
+  // with lower weights are evaluated before items with higher weights.
+
+  $schema['nodewords_bypath_rules'] = array(
+    'description' => t('Stores nodewords meta tag content based on paths'),
+    'fields' => array(
+      'id' => array(
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'description' => t('unique id'),
+      ),
+      'name' => array(
+        'type' => 'varchar',
+        'length' => 128,
+        'not null' => TRUE,
+        'description' => t('Meta tag name.'),
+      ),
+      'type' => array(
+        'type' => 'int',
+        'length' => 1,
+        'not null' => TRUE,
+        'description' => t('type'),
+        'default' => '1',
+      ),
+      'path_expr' => array(
+        'type' => 'text',
+        'length' => 256,
+        'not null' => TRUE,
+        'description' => t('path expression to match'),
+      ),
+      'weight' => array(
+        'type' => 'int',
+        'length' => 1,
+        'not null' => TRUE,
+        'description' => t('path expression to match'),
+      ),
+    ),
+    'primary key' => array('id'),
+  );
+
+  $schema['nodewords_bypath_tags'] = array(
+    'description' => t('Stores nodewords meta tag content based on paths'),
+    'fields' => array(
+      'rule_id' => array(
+        'type' => 'int',
+        'length' => 10,
+        'not null' => TRUE,
+        'description' => t('unique id'),
+      ),
+      'meta_tag' => array(
+        'type' => 'varchar',
+        'length' => 32,
+        'not null' => TRUE,
+        'description' => t('meta tag'),
+      ),
+      'meta_value' => array(
+        'type' => 'text',
+        'length' => 255,
+        'not null' => TRUE,
+        'description' => t('meta value'),
+      ),
+    ),
+    'primary key' => array('rule_id', 'meta_tag'),
+  );
+  return $schema;
 }
+
Index: nodewords_bypath.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodewords_bypath/Attic/nodewords_bypath.module,v
retrieving revision 1.1.2.1
diff -u -u -p -r1.1.2.1 nodewords_bypath.module
--- nodewords_bypath.module	17 Jun 2008 18:36:25 -0000	1.1.2.1
+++ nodewords_bypath.module	30 Dec 2008 22:40:21 -0000
@@ -9,9 +9,6 @@
 /** The empty field specifier. */
 define('NODEWORDS_NONE', '<none>');
 
-require_once(drupal_get_path('module', 'nodewords_bypath') . '/nodewords_bypath.forms.inc');
-
-
 /**
  * Implementation of hook_help().
  *
@@ -19,17 +16,17 @@ require_once(drupal_get_path('module', '
  *
  * @return string The help text for the provided path.
  */
-function nodewords_bypath_help($section) {
-  switch($section) {
+function nodewords_bypath_help($path, $arg) {
+  switch ($path) {
     case 'admin/content/nodewords/path':
       $subs = array('!ref_link' => l(t('Token Reference Page'), 'admin/content/nodewords/path/tokens'));
-      $help = '<p>' . t('Meta tag path rules allow the values of meta tags to be specified by path. The value may include dynamic content using the tokens specified in the !ref_link page. Rules are evaluated by their weight with lighter rules are evaluated before heavier ones. Rule evaluation stops on the first rule encountered that matches any given path. For example, if the lightest weight rule matches a path, that rule is evaluated and no further rules are evaluated against that path.', $subs) . '</p>';
+      $help = '<p>'. t('Meta tag path rules allow the values of meta tags to be specified by path. The value may include dynamic content using the tokens specified in the !ref_link page. Rules are evaluated by their weight with lighter rules are evaluated before heavier ones. Rule evaluation stops on the first rule encountered that matches any given path. For example, if the lightest weight rule matches a path, that rule is evaluated and no further rules are evaluated against that path.', $subs) .'</p>';
       return $help;
     
     case 'admin/content/nodewords/path/new':
       // Fall through.
-    case 'admin/content/nodewords/path/edit/' . arg(5):
-      $help = '<p>' . t('When using tokens in the meta tag fields, keep in mind that node tokens are only available when a page is displaying a single node. Global tokens are available on all pages.') . '</p>';
+    case 'admin/content/nodewords/path/edit/'. arg(5):
+      $help = '<p>'. t('When using tokens in the meta tag fields, keep in mind that node tokens are only available when a page is displaying a single node. Global tokens are available on all pages.') .'</p>';
       return $help;   
   }
 }
@@ -41,71 +38,83 @@ function nodewords_bypath_help($section)
  * @param $may_cache bool TRUE if this call is for the cached menu,
  *        FALSE if not.
  */
-function nodewords_bypath_menu($may_cache) {
+function nodewords_bypath_menu() {
   $items = array();
   
-  if ($may_cache) {
-    $items[] = array(
-      'path'     => 'admin/content/nodewords/path',
-      'title'    => t('By Path'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('nodewords_bypath_admin_overview'),
-      'type'     => MENU_LOCAL_TASK,
-      'access'   => user_access('administer meta tags'),
-      'weight'   => 5,
-    );
-    
-    $items[] = array(
-      'path'     => 'admin/content/nodewords/path/list',
-      'title'    => t('List'),
-      'callback' => 'nodewords_bypath_admin_overview',
-      'type'     => MENU_DEFAULT_LOCAL_TASK,
-      'access'   => user_access('administer meta tags'),
-    );
-    
-    $items[] = array(
-      'path'     => 'admin/content/nodewords/path/new',
-      'title'    => t('New Rule'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('nodewords_bypath_create_form'),
+  $items['admin/content/nodewords/path'] = array(
+    'title'    => 'By Path',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('nodewords_bypath_admin_overview'),
+    'type'     => MENU_LOCAL_TASK,
+    'access arguments'   => array('administer meta tags'),
+    'weight'   => 5,
+    'file' => 'nodewords_bypath.forms.inc',
+  );
+  
+  $items['admin/content/nodewords/path/list'] = array(
+    'title'    => 'List',
+    'page callback' => 'nodewords_bypath_admin_overview',
+    'type'     => MENU_DEFAULT_LOCAL_TASK,
+    'access arguments'   => array('administer meta tags'),
+    'file' => 'nodewords_bypath.forms.inc',
+  );
+  
+  $items['admin/content/nodewords/path/new'] = array(
+    'title'    => 'New Rule',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('nodewords_bypath_form'),
+    'type'     => MENU_LOCAL_TASK,
+    'weight'   => 1,
+    'access arguments'   => array('administer meta tags'),
+    'file' => 'nodewords_bypath.forms.inc',
+  );
+  
+  if (function_exists('token_get_list')) {
+    $items['admin/content/nodewords/path/tokens'] = array(
+      'title'    => 'Token Reference',
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('nodewords_bypath_tokenref_form'),
       'type'     => MENU_LOCAL_TASK,
-      'weight'   => 1,
-      'access'   => user_access('administer meta tags'),
-    );
-    
-    if (function_exists('token_get_list')) {
-      $items[] = array(
-        'path'     => 'admin/content/nodewords/path/tokens',
-        'title'    => t('Token Reference'),
-        'callback' => 'drupal_get_form',
-        'callback arguments' => array('nodewords_bypath_tokenref_form'),
-        'type'     => MENU_LOCAL_TASK,
-        'weight'   => 2,
-        'access'   => user_access('administer meta tags'),
-      );
-    }
-  }
-  else {
-    $items[] = array(
-      'path' => 'admin/content/nodewords/path/edit/' . arg(5),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('nodewords_bypath_create_form', arg(5)),
-      'type'     => MENU_CALLBACK,
-      'access'   => user_access('administer meta tags'),
-    );
-    
-    $items[] = array(
-      'path' => 'admin/content/nodewords/path/delete/' . arg(5),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('nodewords_bypath_delete_form', arg(5)),
-      'type'     => MENU_CALLBACK,
-      'access'   => user_access('administer meta tags'),
+      'weight'   => 2,
+      'access arguments'   => array('administer meta tags'),
+      'file' => 'nodewords_bypath.forms.inc',
     );
   }
+ 
+  $items['admin/content/nodewords/path/%nodewords_bypath_rule/edit'] = array(
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('nodewords_bypath_form', 4),
+    'type'     => MENU_CALLBACK,
+    'access arguments'   => array('administer meta tags'),
+    'file' => 'nodewords_bypath.forms.inc',
+  );
   
+  $items['admin/content/nodewords/path/%nodewords_bypath_rule/delete'] = array(
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('nodewords_bypath_delete_form', 4),
+    'type'     => MENU_CALLBACK,
+    'access arguments'   => array('administer meta tags'),
+    'file' => 'nodewords_bypath.forms.inc',
+  );
+
   return $items;
 }
 
+/**
+ * Implements hook_theme()
+ */
+function nodewords_bypath_theme() {
+  return array(
+    'nodewords_bypath_tokenref_form' => array(
+      'arguments' => array('form' => NULL),
+      'file' => 'nodewords_bypath.forms.inc',
+    ),
+    'nodewords_bypath_admin_overview' => array(
+      'arguments' => array('form' => NULL),
+      'file' => 'nodewords_bypath.forms.inc',
+    ),
+ );
+}
 
 /**
  * Implementation of hook_nodewords().
@@ -122,41 +131,41 @@ function nodewords_bypath_menu($may_cach
 function nodewords_bypath_nodewords(&$tags, $op, $type, $ids) {
   switch ($op) {
     case 'prepare':
-      $path      = drupal_get_path_alias($_GET['q']);
-      $rule      = _nodewords_bypath_get_path_rule($path);
-      $rule_tags = _nodewords_bypath_get_tags_for($rule->id);
-      
-      //--------------------------------------------------------------------
-      // Determine the context for token replacement.
-      $scope  = 'global';
-      $object = NULL;
-      
-      if ($type == 'node') {
-        $scope  = 'node';
-        $object = node_load($ids[0]);
-      }
-      else if ($type == 'term') {
-        $scope  = 'taxonomy';
-        $object = taxonomy_get_term($ids[0]);
-      }
-      
-      //--------------------------------------------------------------------
-      // Set the value for the tag and use the token module if it is
-      // available.
-      foreach ($rule_tags as $key => $value) {
-        if (!empty($value)) {
-          if (function_exists('token_replace')) {
-            $tags[$key] = strip_tags(token_replace($value, $scope, $object));
+      $path = drupal_get_path_alias($_GET['q']);
+      if ($rule = _nodewords_bypath_path_rule_load($path)) {
+        $rule_tags = _nodewords_bypath_tags_load($rule->id);
+
+        //--------------------------------------------------------------------
+        // Determine the context for token replacement.
+        $scope  = 'global';
+        $object = NULL;
+        
+        if ($type == 'node') {
+          $scope  = 'node';
+          $object = node_load($ids[0]);
+        }
+        elseif ($type == 'term') {
+          $scope  = 'taxonomy';
+          $object = taxonomy_get_term($ids[0]);
+        }
+        
+        //--------------------------------------------------------------------
+        // Set the value for the tag and use the token module if it is
+        // available.
+        foreach ($rule_tags as $key => $value) {
+          if (!empty($value)) {
+            if (function_exists('token_replace')) {
+              $tags[$key] = strip_tags(token_replace($value, $scope, $object));
+            }
+            else {
+              $tags[$key] = $value;
+            }
           }
-          else {
-            $tags[$key] = $value;
+          elseif ($value == NODEWORDS_NONE) {
+            $tags[$key] = '';
           }
         }
-        elseif ($value == NODEWORDS_NONE) {
-          $tags[$key] = '';
-        }
       }
-      
       break;
   }
 }
@@ -167,49 +176,44 @@ function nodewords_bypath_nodewords(&$ta
  *
  * @param $rule object The rule instance to create or update.
  */
-function _nodewords_bypath_save($rule) {
+function nodewords_bypath_rule_save($rule) {
   // Updating an existing rule
   if (isset($rule->id) && ($rule->id > -1)) {
-    db_query("UPDATE {nodewords_bypath_rules} SET 
-                     name = '%s', type = %d, path_expr = '%s', weight = %d
-              WHERE id = %d",
-              $rule->name, $rule->type, $rule->path_expr,
-              $rule->weight, $rule->id);
+    drupal_write_record('nodewords_bypath_rules', $rule, 'id');
     
     //----------------------------------------------------------------------
     // Tags are trickier. They could exist already, or they may be new if
     // the administrator has recently changed the available tags.
-    foreach ($rule->tags as $tag => $value) {
+    foreach ($rule->tags as $name => $value) {
+      $tag = new stdClass;
+      $tag->rule_id = $rule->id;
+      $tag->meta_tag = $name;
+      $tag->meta_value = $value;
+      
       $exists = db_result(db_query("SELECT COUNT(*) FROM {nodewords_bypath_tags} 
                                            WHERE (rule_id = %d AND meta_tag = '%s')",
-                                    $rule->id, $tag));
+                                    $rule->id, $name));
       if ($exists > 0) {
-        db_query("UPDATE {nodewords_bypath_tags} SET meta_value = '%s' 
-                         WHERE (rule_id = %d AND meta_tag = '%s')",
-                 $value, $rule->id, $tag);  
+        drupal_write_record('nodewords_bypath_tags', $tag, array('rule_id', 'meta_tag'));
       }
       else {
-        db_query("INSERT INTO {nodewords_bypath_tags} (rule_id, meta_tag, meta_value)
-                         VALUES (%d, '%s', '%s')", $rule->id, $tag, $value);
+        drupal_write_record('nodewords_bypath_tags', $tag);
       }
     }
   }
   // Saving a new rule
   else {
-    $id = db_next_id('{nodewords_bypath_rules}_id');
-    db_query("INSERT INTO {nodewords_bypath_rules} 
-                     (id, name, type, path_expr, weight)
-                     VALUES (%d, '%s', %d, '%s', %d)",
-                     $id, $rule->name, $rule->type,
-                     $rule->path_expr, $rule->weight);
-    foreach ($rule->tags as $tag => $value) {
-      db_query("INSERT INTO {nodewords_bypath_tags} (rule_id, meta_tag, meta_value)
-                       VALUES (%d, '%s', '%s')", $id, $tag, $value);
+    drupal_write_record('nodewords_bypath_rules', $rule);
+    foreach ($rule->tags as $name => $value) {
+      $tag = new stdClass;
+      $tag->rule_id = $rule->id;
+      $tag->meta_tag = $name;
+      $tag->meta_value = $value;
+      drupal_write_record('nodewords_bypath_tags', $tag);
     }
   }
 }
 
-
 /**
  * Retrieve the meta tags for the given rule ID.
  *
@@ -217,7 +221,7 @@ function _nodewords_bypath_save($rule) {
  *
  * @return array A mapping of term names (string) to their values (string).
  */
-function _nodewords_bypath_get_tags_for($id) {
+function _nodewords_bypath_tags_load($id) {
   $tags   = array();
   $result = db_query('SELECT meta_tag, meta_value 
                              FROM {nodewords_bypath_tags} WHERE rule_id = %d', $id);
@@ -237,17 +241,17 @@ function _nodewords_bypath_get_tags_for(
  * @return array The meta tag rule information, or NULL if no rule with the
  *         given ID was found.
  */
-function _nodewords_bypath_load_instance($id) {
-  $title  = NULL;
-  
-  $result = db_fetch_object(db_query('SELECT id, name, type, path_expr, weight
+function nodewords_bypath_rule_load($id) {
+  $rule = db_fetch_object(db_query('SELECT id, name, type, path_expr, weight
                                              FROM {nodewords_bypath_rules} WHERE id = %d', $id));
   
-  if (!empty($result) AND (!empty($result->id))) {
-    $result->tags = _nodewords_bypath_get_tags_for($result->id);
+  if ($rule AND (!empty($rule->id))) {
+    $rule->tags = _nodewords_bypath_tags_load($rule->id);
+    return $rule;
+  }
+  else {
+    return FALSE;
   }
-
-  return $result;
 }
 
 
@@ -256,15 +260,15 @@ function _nodewords_bypath_load_instance
  *
  * @return array The meta tag rule objects.
  */
-function _nodewords_bypath_get_all() {
+function _nodewords_bypath_load_all() {
   $rules  = array();
   $result = db_query('SELECT id, name, type, path_expr, weight
                              FROM {nodewords_bypath_rules} ORDER BY weight, name ASC');
   
   // The tags aren't loaded here. They're loaded on demand when the path
   // is matched.
-  while ($row = db_fetch_object($result)) {
-    $rules[] = $row;
+  while ($rule = db_fetch_object($result)) {
+    $rules[] = $rule;
   }
   
   return $rules;
@@ -278,8 +282,8 @@ function _nodewords_bypath_get_all() {
  *
  * @return object The meta tag rule for the given path.
  */
-function _nodewords_bypath_get_path_rule($path) {
-  $rules  = _nodewords_bypath_get_all();
+function _nodewords_bypath_path_rule_load($path) {
+  $rules  = _nodewords_bypath_load_all();
 
   foreach ($rules as $rule) {
     //----------------------------------------------------------------------
