Index: menutrails.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/menutrails/menutrails.module,v
retrieving revision 1.5
diff -u -p -r1.5 menutrails.module
--- menutrails.module	2 Aug 2008 03:06:00 -0000	1.5
+++ menutrails.module	24 Oct 2008 12:21:51 -0000
@@ -1,18 +1,18 @@
 <?php
 // $Id: menutrails.module,v 1.5 2008/08/02 03:06:00 joshk Exp $
 
+
 /**
  * @file
- * Menutrails allows the assigment of "trails" which will keep menu items 
+ * Menutrails allows the assigment of "trails" which will keep menu items
  * active for individual node views.
  */
 
-
 /**
-* Implementation of hook_menu
-*
-* For settings page
-*/
+ * Implementation of hook_menu().
+ *
+ * For settings page.
+ */
 function menutrails_menu() {
   $items['admin/settings/menutrails'] = array(
     'title' => 'Menu Trails',
@@ -25,18 +25,17 @@ function menutrails_menu() {
   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.
+ */
 function menutrails_nodeapi(&$node, $op, $a3 = NULL, $page = FALSE) {
-  if ($op == 'view' && $page == TRUE) { 
+  if ($op == 'view' && $page == TRUE) {
     $item = menutrails_node_location($node);
     if ($item) {
       menu_set_item(NULL, $item);
@@ -45,13 +44,17 @@ 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
+  // This should only fire if the menu isn't already active.
   $item = menu_get_item();
   if (db_result(db_query("SELECT count(mlid) FROM {menu_links} WHERE link_path = '%s'", $item['href'])) == 0) {
     $type_trails = variable_get('menutrails_node_types', array());
-    $href = $type_trails[$node->type] ? $type_trails[$node->type] : FALSE;
+    $href        = $type_trails[$node->type] ? $type_trails[$node->type] : FALSE;
     $term_trails = variable_get('menutrails_terms', array());
     foreach ($node->taxonomy as $tid => $term) {
       if ($term_trails[$tid] > 0) {
@@ -59,9 +62,10 @@ function menutrails_node_location($node)
       }
     }
   }
-  // organic groups support
+  // Organic groups support.
   if (module_exists('og') && !empty($node->og_groups)) {
-    $group = array_shift($node->og_groups); // we can only do one, so we take the first...
+    // We can only do one, so we take the first.
+    $group = array_shift($node->og_groups);
     if (variable_get('menutrails_og_group_menu', FALSE) != FALSE) {
       if (db_result(db_query("SELECT count(mlid) FROM {menu_links} WHERE link_path = '%s'", $item['href'])) == 0) {
         $href = 'node/'. $group;
@@ -84,10 +88,9 @@ function menutrails_node_location($node)
   return FALSE;
 }
 
-/***
-* 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']);
@@ -98,54 +101,57 @@ function menutrails_comment($comment, $o
   }
 }
 
-/***
-* 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.
-*/
-
+/**
+ * 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>');
-  $limit = _menu_parent_depth_limit($item);
-  $menus = menu_get_menus();
-  foreach($menus as $menu_name => $title) {
+  $limit   = _menu_parent_depth_limit($item);
+  $menus   = menu_get_menus();
+  foreach ($menus as $menu_name => $title) {
     $tree = menu_tree_all_data($menu_name, NULL);
     $options[$menu_name .':0'] = '<'. $title .'>';
     _menutrails_parents_recurse($tree, $menu_name, '--', $options, $item['mlid'], $limit);
   }
   $form['description'] = array(
-    '#tyoe' => 'markup',
-    '#weight' => '-100',
+    '#type' => 'markup',
+    '#weight' => '-10',
     '#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',
-    '#weight' => '-99',
-    '#value' => t('<p>Menu trials are evaluated in the order they are shown below.</p>'),
+  $form['order'] = array(
+    '#type' => 'markup',
+    '#weight' => '-1',
+    '#value' => t('Menu trials are evaluated in the order they are shown below.'),
+    '#prefix' => '<p>',
+    '#suffix' => '</p>',
   );
-  
+
   $extra = module_invoke_all('menutrails_settings', $options);
-  
+
   $form = array_merge($form, $extra);
-  
+
   return system_settings_form($form);
 }
 
-
 /**
- * Implementation of menutrails_settings_api
+ * Implementation of hook_menutrails_settings().
  *
- * This api allows other modules to define their own menutrail behavior.
- *
- * @param $options
- *  Options array to be used by other modules to define their own menutrails.
- * @return
- *  A form element (or array) for the menutrails system settings form.
+ * Allows other modules to define their own menutrail behavior.
  *
  * Please define your input as a fieldset and do not assign a weight. This will
  * keep the groups of menutrails settings in order.
+ *
+ * @param $options
+ *   Options array to be used by other modules to define their own menutrails.
+ *
+ * @return
+ *   A form element (or array) for the menutrails system settings form.
  */
 function menutrails_menutrails_settings($options) {
   $form = array();
@@ -154,11 +160,11 @@ function menutrails_menutrails_settings(
   $vocabs = taxonomy_get_vocabularies();
   $term_trails = variable_get('menutrails_terms', array());
   $form['menutrails_node_types'] = array(
-      '#tree' => TRUE,
-      '#type' => 'fieldset',
-      '#collapsible' => TRUE,
-      '#collapsed' => TRUE,
-      '#title' => t('Node types'),
+    '#tree' => TRUE,
+    '#type' => 'fieldset',
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+    '#title' => t('Node types'),
   );
   foreach ($node_types as $key => $value) {
     $form['menutrails_node_types'][$key] = array('#type' => 'select',
@@ -177,14 +183,14 @@ function menutrails_menutrails_settings(
     );
     $terms = taxonomy_get_tree($vocab->vid);
     foreach ($terms as $term) {
-       $form[$vocab->vid]['menutrails_terms'][$term->tid] = array('#type' => 'select',
+      $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,
       );
     }
   }
-  // organic groups support
+  // Organic groups support.
   if (module_exists('og')) {
     $form['menutrails_og'] = array(
       '#type' => 'fieldset',
@@ -220,7 +226,7 @@ function menutrails_menutrails_settings(
     }
     $form['menutrails_og']['menutrails_og_group_menu'] = array(
       '#type' => 'checkbox',
-      '#title' => t('Use Group\'s Menu Item'),
+      '#title' => t('Use Group\'s Menu Item For Posts'),
       '#default_value' => variable_get('menutrails_og_group_menu', FALSE),
       '#description' => t('If a specific group node has an assigned menu item, use this as the trail for nodes which have that group as an audience. If present, this will override all other group settings.'),
     );
@@ -229,14 +235,14 @@ function menutrails_menutrails_settings(
 }
 
 /**
- * Inspired by _menu_parents_recurse()
+ * Inspired by _menu_parents_recurse().
  *
- * The same as above, except it delivers hrefs rather than coded ids
+ * The same as above, except it delivers hrefs rather than coded ids.
  */
 function _menutrails_parents_recurse($tree, $menu_name, $indent, &$options, $exclude, $depth_limit) {
   foreach ($tree as $data) {
     if ($data['link']['depth'] > $depth_limit) {
-      // Don't iterate through any links on this level.
+      // Don't iterate over any links on this level.
       break;
     }
     if ($data['link']['mlid'] != $exclude && $data['link']['hidden'] >= 0) {
@@ -251,19 +257,17 @@ function _menutrails_parents_recurse($tr
   }
 }
 
-
-/***
-* 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);
@@ -275,21 +279,14 @@ function _phptemplate_variables($hook, $
 */
 
 
-/***
-* SUBSTITUTE THEME FUNCTION
-*/
-
-/***
-* This is a substitute function for theme_links()
-*
-* The important difference is that we use the in_active_trail bit here to set
-* an "active" CSS class, which is what most themes (e.g. garland) use to 
-* denote an active/open menu item. You should alter/override this as your 
-* design needs dictate.
-*
-*/
-
-
+/**
+ * Theme override for theme_links().
+ *
+ * The important difference is that we use the in_active_trail bit here to set
+ * an "active" CSS class, which is what most themes (e.g. garland) use to
+ * denote an active/open menu item. You should alter/override this as your
+ * design needs dictate.
+ */
 function phptemplate_links($links, $attributes = array('class' => 'links')) {
   $output = '';
 
@@ -312,13 +309,13 @@ function phptemplate_links($links, $attr
       if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))) {
         $class .= ' active';
       }
-      
+
       if (isset($link['href'])) {
         // add active class for containing <li> and <a> if active-trail is set on the link itself
         if (strpos($link['attributes']['class'], 'active-trail') !== FALSE && strpos($class, 'active') === FALSE) {
-           $class .= ' active';
-           $link['attributes']['class'] .= ' active';
-         }
+          $class .= ' active';
+          $link['attributes']['class'] .= ' active';
+        }
         // Pass in $link as $options, they share the same keys.
         $link = l($link['title'], $link['href'], $link);
       }
@@ -343,4 +340,5 @@ function phptemplate_links($links, $attr
     $output .= '</ul>';
   }
   return $output;
-}
\ No newline at end of file
+}
+
