Index: CHANGELOG.txt
===================================================================
RCS file: CHANGELOG.txt
diff -N CHANGELOG.txt
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ CHANGELOG.txt	25 Oct 2008 18:19:50 -0000
@@ -0,0 +1,11 @@
+// $Id: CHANGELOG.txt,v 1.1.2.2 2008/10/25 18:00:43 sun Exp $
+
+Menu Trails x.x-x.x, xxxx-xx-xx
+-------------------------------
+
+
+Menu Trails 5.x-x.x, xxxx-xx-xx
+-------------------------------
+#325613 by sun: Code clean-up.
+#154464 by joshk: Fixed Menu Trails By Category in $nodetype not saved.
+
Index: menutrails.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/menutrails/menutrails.info,v
retrieving revision 1.1
diff -u -p -r1.1 menutrails.info
--- menutrails.info	29 May 2007 22:06:33 -0000	1.1
+++ menutrails.info	25 Oct 2008 18:04:44 -0000
@@ -1,5 +1,4 @@
 ; $Id: menutrails.info,v 1.1 2007/05/29 22:06:33 joshk Exp $
 name = Menu Trails
-description = Contains functions for utilization in your theme to keep Drupal's menu's active when looking at sub-sections and/or individual nodes.
+description = Dynamically assign "trails" so that Drupal menus remain in active state when viewing individual nodes.
 dependencies = menu
-version = "$Name:  $"
Index: menutrails.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/menutrails/menutrails.module,v
retrieving revision 1.2.2.1
diff -u -p -r1.2.2.1 menutrails.module
--- menutrails.module	27 Jun 2007 23:09:56 -0000	1.2.2.1
+++ menutrails.module	25 Oct 2008 18:16:21 -0000
@@ -1,38 +1,43 @@
 <?php
-// $Id:
+// $Id: menutrails.module,v 1.4.2.6 2008/10/25 18:00:43 sun Exp $
+
 
 /**
-* Implementation of hook_menu
-*
-* For settings page
-*/
+ * @file
+ * Menutrails allows the assigment of "trails" which will keep menu items
+ * active for individual node views.
+ */
+
+/**
+ * Implementation of hook_menu().
+ *
+ * For settings page.
+ */
 function menutrails_menu($may_cache) {
   $items = array();
   if ($may_cache) {
     $items[] = array(
       'path' => 'admin/settings/menutrails',
-      'access' => user_access('administer site configuration'),
       'title' => t('Menu Trails'),
       'description' => t('Configure your menu trails.'),
       'callback' => 'drupal_get_form',
       'callback arguments' => array('menutrails_settings_form'),
+      'access' => user_access('administer site configuration'),
       'type' => MENU_NORMAL_ITEM,
     );
   }
   return $items;
 }
 
-/***
-* Implementation of hook_nodeapi
-*
-* This will evaluate individual nodes when being viewed and take the necessary
-* steps to set the active_trail for menus.
-*
-* This will retain menu state at the node/view level. For instance, forum nodes
-* would maintain an active trail to the forum menu item.
-*
-*/
-
+/**
+ * Implementation of hook_nodeapi().
+ *
+ * This will evaluate individual nodes when being viewed and take the necessary
+ * steps to set the active_trail for menus.
+ *
+ * This will retain menu state at the node/view level. For instance, forum nodes
+ * would maintain an active trail to the forum menu item.
+ */
 // TODO: this too cries out for an admin configuration screen
 function menutrails_nodeapi(&$node, $op, $a3 = NULL, $page = FALSE) {
   if ($op == 'view' && $page == TRUE) {
@@ -41,17 +46,20 @@ function menutrails_nodeapi(&$node, $op,
   }
 }
 
-
-// inspired by _menu_get_active_trail()
+/**
+ * Determine the menu location of a node.
+ *
+ * Inspired by _menu_get_active_trail().
+ */
 function menutrails_node_location($node) {
-  // this should only fire if the menu isn't already active
-  $item = menu_get_item(NULL, 'node/'.$node->nid);
+  // This should only fire if the menu isn't already active.
+  $item = menu_get_item(NULL, 'node/'. $node->nid);
   // type = 4 is for a callback
   if ($item['type'] == 4) {
     $type_trails = variable_get('menutrails_node_types', array());
-    $mid = $type_trails[$node->type];
+    $mid         = $type_trails[$node->type];
     $term_trails = variable_get('menutrails_terms', array());
-    foreach($node->taxonomy as $tid => $term) {
+    foreach ($node->taxonomy as $tid => $term) {
       if ($term_trails[$tid] > 0) {
         $mid = $term_trails[$tid];
       }
@@ -63,33 +71,31 @@ function menutrails_node_location($node)
         $mid = $mid = $item['pid'];
       }
       $location = array_reverse($location);
-      $location[] = array('path' => 'node/'.$node->nid, 'title' => $node->title);
+      $location[] = array('path' => 'node/'. $node->nid, 'title' => $node->title);
     }
     return $location;
   }
 }
 
-/***
-* This implements the same functionality as the nodeapi, but for comment urls.
-*
-*/
+/**
+ * This implements the same functionality as the nodeapi, but for comment urls.
+ */
 function menutrails_comment($comment, $op) {
   if ($op == 'form' && arg(0) == 'comment') {
-    $node = node_load($comment['nid']['#value']);
-    $location = menutrails_node_location($node);
+    $node       = node_load($comment['nid']['#value']);
+    $location   = menutrails_node_location($node);
     $location[] = array('path' => "comment/reply/$node->nid");
     menu_set_location($location);
   }
 }
 
-/***
-* Form function for settings
-*
-* This is where menutrails rules are set. The interface here could definitely stand for some improvement. It's especially unhelpful for tagging vocabularies with lots and lots of terms.
-*
-* TODO: See about integrating views (e.g. node qualifies to be in a view, gets a menutrail, similar to how noderefrence lets you limit possibilities)
-*/
-
+/**
+ * Form builder function for settings.
+ *
+ * This is where menutrails rules are set. The interface here could definitely
+ * stand for some improvement. It's especially unhelpful for tagging
+ * vocabularies with lots and lots of terms.
+ */
 function menutrails_settings_form() {
   $options = array('NONE');
   $options = $options + menu_parent_options($item['mid'], variable_get('menu_parent_items', 0)); 
@@ -97,26 +103,29 @@ function menutrails_settings_form() {
   $node_trails = variable_get('menutrails_node_types', array());
   $vocabs = taxonomy_get_vocabularies();
   $term_trails = variable_get('menutrails_terms', array());
+
   $form['description'] = array(
-    '#tyoe' => 'markup',
+    '#type' => 'markup',
     '#weight' => '-100',
     '#value' => t('Use these settings to configure the "menu trails" for your nodes. This determines what menu items are activated when viewing an individual node. For instance, if you have a menu item for "Blog," you may want to have all blog posts fall under that menu.'),
+    '#prefix' => '<p>',
+    '#suffix' => '</p>',
   );
-    $form['oder'] = array(
-    '#tyoe' => 'markup',
+  $form['order'] = array(
+    '#type' => 'markup',
     '#weight' => '-99',
     '#value' => t('<p>Menu trials are evaluated in the following order:</p> <ol><li>Node type</li><li>Taxonomy category</li><li>Node-specific menu setting</li></ol><p>In other words, category-based menu trails override node-type, and specific settings made on the node itself override both. Category-based menu trails are evaluated by weight in the order shown here, so settings in lower vocabularies take precidence.</p>'),
   );
   $form['menutrails_node_types'] = array(
-      '#tree' => TRUE,
-      '#type' => 'fieldset',
-      '#collapsible' => TRUE,
-      '#collapsed' => TRUE,
-      '#title' => t('Menu trails by node type'),
+    '#tree' => TRUE,
+    '#type' => 'fieldset',
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+    '#title' => t('Menu trails by node type'),
   );
   foreach ($node_types as $key => $value) {
     $form['menutrails_node_types'][$key] = array('#type' => 'select',
-      '#title' => t('Parent item for'). " $value",
+      '#title' => t('Parent item for') ." $value",
       '#default_value' => $node_trails[$key],
       '#options' => $options,
     );
@@ -127,34 +136,32 @@ function menutrails_settings_form() {
       '#type' => 'fieldset',
       '#collapsible' => TRUE,
       '#collapsed' => TRUE,
-      '#title' => t('Menu trails by category:'). " $vocab->name",
+      '#title' => t('Menu trails by category:') ." $vocab->name",
     );
     $terms = taxonomy_get_tree($vocab->vid);
     foreach ($terms as $term) {
-       $form[$vocab->vid]['menutrails_terms'][$term->tid] = array('#type' => 'select',
-        '#title' => t('Parent item for'). " $term->name",
+      $form[$vocab->vid]['menutrails_terms'][$term->tid] = array('#type' => 'select',
+        '#title' => t('Parent item for') ." $term->name",
         '#default_value' => $term_trails[$term->tid],
         '#options' => $options,
       );
     }
   }
-  
+
   return system_settings_form($form);
 }
 
-
 /***
-* This is an example _phptemplate_variables() implementation. 
-*
-* You need to add this code (or something like it) to your template.php file 
-* for this module to do anything useful. Obviously in template.php you don't
-* want the code commented out.
-*
-*/
+ * This is an example _phptemplate_variables() implementation.
+ *
+ * You need to add this code (or something like it) to your template.php file
+ * for this module to do anything useful. Obviously in template.php you don't
+ * want the code commented out.
+ */
 
 /*
 function _phptemplate_variables($hook, $vars = array()) {
-  switch ($hook) { // what function is active?
+  switch ($hook) {
     case 'page': // page is where menu comes into play
       // set the primary links
       $vars['primary_links'] = menutrails_primary_links(1);
@@ -165,20 +172,17 @@ function _phptemplate_variables($hook, $
 }
 */
 
+/**
+ * SUBSTITUTE MENU FUNCTIONS
+ */
 
-/***
-* SUBSTITUTE MENU FUNCTIONS
-*/
-
-/***
-* This is a substitute function for menu_primary_links()
-*
-* The important difference is a different criteria for determining if an item
-* is "active" or not, and the use of our own _menu_item() function to make use
-* of that active status.
-*
-*/
-
+/**
+ * This is a substitute function for menu_primary_links()
+ *
+ * The important difference is a different criteria for determining if an item
+ * is "active" or not, and the use of our own _menu_item() function to make use
+ * of that active status.
+ */
 function menutrails_primary_links($start_level = 1, $pid = 0) {
   if (!module_exists('menu')) {
     return NULL;
@@ -206,17 +210,22 @@ function menutrails_primary_links($start
 
   $menu = menu_get_menu();
   $links = array();
-  $trail = _menu_get_active_trail();   // Custom data for use down the line
+  // Custom data for use down the line
+  $trail = _menu_get_active_trail();
   if ($pid && is_array($menu['visible'][$pid]) && isset($menu['visible'][$pid]['children'])) {
     $count = 1;
     foreach ($menu['visible'][$pid]['children'] as $cid) {
       $index = "menu-$start_level-$count-$pid";
-      unset($active); // this needs to be unset
-      if  (in_array($cid, $trail)) { // changed from menu_in_active_subtrail
+      // this needs to be unset
+      unset($active);
+      // changed from menu_in_active_subtrail
+      if (in_array($cid, $trail)) {
         $index .= "-active";
-        $active = TRUE; // we use this below
+        // we use this below
+        $active = TRUE;
       }
-      $links[$index] = menutrails_item_link($cid, FALSE, $active); // use $active
+      // use $active
+      $links[$index] = menutrails_item_link($cid, FALSE, $active);
       $count++;
     }
   }
@@ -225,25 +234,23 @@ function menutrails_primary_links($start
   if (empty($links) && $start_level == 1 && $pid == variable_get('menu_primary_menu', 0) && user_access('administer menu')) {
     $links['1-1'] = array(
       'title' => t('Edit primary links'),
-      'href' => 'admin/build/menu'
+      'href' => 'admin/build/menu',
     );
   }
 
   return $links;
-} 
-
-/***
-* This is a substitute function for menu_item_link()
-*
-* The important difference is that this will pick up the $active bit from the
-* function above, and assign the "active" class to the link if it is present.
-*
-*/
+}
 
+/**
+ * This is a substitute function for menu_item_link()
+ *
+ * The important difference is that this will pick up the $active bit from the
+ * function above, and assign the "active" class to the link if it is present.
+ */
 function menutrails_item_link($mid, $theme = TRUE, $active = FALSE) {
-  $item = menu_get_item($mid);
+  $item      = menu_get_item($mid);
   $link_item = $item;
-  $link = '';
+  $link      = '';
   while ($link_item['type'] & MENU_LINKS_TO_PARENT) {
     $link_item = menu_get_item($link_item['pid']);
   }
@@ -255,7 +262,7 @@ function menutrails_item_link($mid, $the
     $link = array(
       'title' => $item['title'],
       'href' => $link_item['path'],
-      'attributes' => !empty($item['description']) ? array('title' => $item['description']) : array()
+      'attributes' => !empty($item['description']) ? array('title' => $item['description']) : array(),
     );
     if ($active) {
       $link['attributes']['class'] = 'active';
@@ -263,4 +270,5 @@ function menutrails_item_link($mid, $the
   }
   $link['mid'] = $mid;
   return $link;
-} 
\ No newline at end of file
+}
+
