--- token/token_node.inc.orig 2008-05-26 17:00:12.000000000 +0200 +++ token/token_node.inc 2008-05-26 17:01:38.000000000 +0200 @@ -52,7 +52,7 @@ } // Now get the menu related information. - if ($node->menu['mlid']) { + if ($node->menu['mlid'] or $node->menu['plid']) { $menus = menu_get_menus(); $menu_name = $node->menu['menu_name']; $menu_title = $menus[$menu_name]; @@ -61,16 +61,25 @@ foreach ($trail_raw as $title) { $trail[] = check_plain($title); } - $values['menupath'] = implode('/', $trail); - $values['menupath-raw'] = implode('/', $trail_raw); - $values['menu'] = check_plain($menu_title); - $values['menu-raw'] = $menu_title; + + // pop the link title off the end + $link_title = array_pop($trail); + $link_title_raw = array_pop($trail_raw); + + $values['menupath'] = implode('/', $trail); + $values['menupath-raw'] = implode('/', $trail_raw); + $values['menu'] = check_plain($menu_title); + $values['menu-raw'] = $menu_title; + $values['menu-link-title'] = $link_title; + $values['menu-link-title-raw'] = $link_title_raw; } else { - $values['menu'] = ''; - $values['menu-raw'] = ''; - $values['menupath'] = ''; - $values['menupath-raw'] = ''; + $values['menu'] = ''; + $values['menu-raw'] = ''; + $values['menupath'] = ''; + $values['menupath-raw'] = ''; + $values['menu-link-title'] = $link_title; + $values['menu-link-title-raw'] = $link_title_raw; } // And now taxonomy, which is a bit more work. This code is adapted from @@ -140,6 +149,33 @@ return $values; } + +/** +* Helper function to extract the titles between $nid and the root in a particular menu +*/ +function _menu_titles($menu_name, $nid) { + // get the plid of our target node + $item = db_fetch_array(db_query("SELECT mlid, plid, link_title, menu_name FROM {menu_links} WHERE menu_name = '%s' AND link_path = '%s'", $menu_name, 'node/' . $nid)); + + if(!(bool)$item['mlid']){ + // not in this menu, or the item was just dissasociated + return array(); + } + + $titles = array(); + $titles[] = $item['link_title']; // include the node link title as well + while($item['plid']){ + $item = db_fetch_array(db_query("SELECT mlid, plid, link_title FROM {menu_links} WHERE mlid = %d", $item['plid'])); + $titles[] = $item['link_title']; + } + + // invert the array to return it to path order + $titles = array_reverse($titles); + + return $titles; +} + + /** * Implementation of hook_token_list() */ @@ -184,38 +220,13 @@ $tokens['node']['menu-raw'] = t("The name of the menu the node belongs to. WARNING - raw user input."); $tokens['node']['menupath'] = t("The menu path (as reflected in the breadcrumb), not including Home or [menu]. Separated by /."); $tokens['node']['menupath-raw'] = t("The unfiltered menu path (as reflected in the breadcrumb), not including Home or [menu]. Separated by /. WARNING - raw user input."); + $tokens['node']['menu-link-title'] = t("The text used in the menu as link text for this item."); + $tokens['node']['menu-link-title-raw'] = t("The unfiltered text used in the menu as link text for this item. WARNING - raw user input."); return $tokens; } } /** - * Return an array of titles for a menu, from the top down to the specified node - * - * @param $menu_name - * The name of the menu. - * @param $nid - * Id of the node at the bottom - * @return - * An array of titles through the specified node - */ -function _menu_titles($menu_name, $nid) { - // Get the menu hierarchy for the specified page. - $item = array_shift(menu_tree_all_data($menu_name)); - $titles = array(); - // Go down the active trail until the right level is reached. - while ($item) { - $titles[] = $item['link']['title']; - // Break AFTER getting the desired node's title - if ($item['link']['href'] == "node/$nid" || !$item['below']) { - break; - } - $item = array_shift($item['below']); - } - - return $titles; -} - -/** * Implementation of hook_token_values() for book nodes */ function book_token_values($type, $object = NULL, $options = array()) {