? token_profile.inc Index: token_node.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/token/Attic/token_node.inc,v retrieving revision 1.5.4.26 diff -u -p -r1.5.4.26 token_node.inc --- token_node.inc 21 Jun 2010 23:24:27 -0000 1.5.4.26 +++ token_node.inc 5 Jul 2010 16:14:49 -0000 @@ -66,30 +66,8 @@ function node_token_values($type, $objec } // Try to get the menu data. - $mlid = db_result(db_query("SELECT mlid FROM {menu_links} WHERE link_path = '%s'", 'node/'. $node->nid)); - - // Now get the menu related information. - if (!empty($mlid) || !empty($node->menu['mlid']) || !empty($node->menu['plid'])) { - $menu_link = menu_link_load($mlid); - $menus = menu_get_menus(); - $menu = isset($menus[$menu_link['menu_name']]) ? $menus[$menu_link['menu_name']] : ''; - $trail_raw = _menu_titles($menu_link, $node->nid); - - $trail = array(); - foreach ($trail_raw as $title) { - $trail[] = check_plain($title); - } - - $values['menupath'] = implode('/', $trail); - $values['menupath-raw'] = implode('/', $trail_raw); - $values['menu'] = check_plain($menu); - $values['menu-raw'] = $menu; - $values['menu-link-title'] = check_plain($menu_link['title']); - $values['menu-link-title-raw'] = $menu_link['link_title']; - $values['menu-link-mlid'] = $menu_link['mlid']; - $values['menu-link-plid'] = $menu_link['plid']; - } - else { + if (module_exists('menu')) { + // Put in blank token values in-case the below code fails. $values['menu'] = ''; $values['menu-raw'] = ''; $values['menupath'] = ''; @@ -98,6 +76,31 @@ function node_token_values($type, $objec $values['menu-link-title-raw'] = ''; $values['menu-link-mlid'] = ''; $values['menu-link-plid'] = ''; + + if (!isset($node->menu)) { + // Load the menu item if not already available. + menu_nodeapi($node, 'prepare'); + } + + if (!empty($node->menu['mlid'])) { + $menus = menu_get_menus(); + $menu = isset($menus[$node->menu['menu_name']]) ? $menus[$node->menu['menu_name']] : ''; + + $trail_raw = _menu_titles($node->menu, $node->nid); + $trail = array(); + foreach ($trail_raw as $title) { + $trail[] = check_plain($title); + } + + $values['menupath'] = implode('/', $trail); + $values['menupath-raw'] = implode('/', $trail_raw); + $values['menu'] = check_plain($menu); + $values['menu-raw'] = $menu; + $values['menu-link-title'] = check_plain($node->menu['title']); + $values['menu-link-title-raw'] = $node->menu['link_title']; + $values['menu-link-mlid'] = $node->menu['mlid']; + $values['menu-link-plid'] = $node->menu['plid']; + } } // And now taxonomy, which is a bit more work. This code is adapted from @@ -188,33 +191,40 @@ function node_token_list($type = 'all') $tokens['node']['author-name-raw'] = t("Node author's user name."); $tokens['node']['author-mail'] = t("Node author's e-mail."); $tokens['node']['author-mail-raw'] = t("Node author's e-mail."); - $tokens['node']['node_comment_count'] = t("The number of comments on a node."); - $tokens['node']['unread_comment_count'] = t("The number of new comments on a node."); + + if (module_exists('comment')) { + $tokens['node']['node_comment_count'] = t("The number of comments on a node."); + $tokens['node']['unread_comment_count'] = t("The number of new comments on a node."); + } $tokens['node']['log'] = t('The node revision log message.'); $tokens['node']['log-raw'] = t('The node revision log message.'); - $tokens['node']['term'] = t("Name of top taxonomy term"); - $tokens['node']['term-raw'] = t("Unfiltered name of top taxonomy term."); - $tokens['node']['term-id'] = t("ID of top taxonomy term"); - $tokens['node']['vocab'] = t("Name of top term's vocabulary"); - $tokens['node']['vocab-raw'] = t("Unfiltered name of top term's vocabulary."); - $tokens['node']['vocab-id'] = t("ID of top term's vocabulary"); + if (module_exists('taxonomy')) { + $tokens['node']['term'] = t("Name of top taxonomy term"); + $tokens['node']['term-raw'] = t("Unfiltered name of top taxonomy term."); + $tokens['node']['term-id'] = t("ID of top taxonomy term"); + $tokens['node']['vocab'] = t("Name of top term's vocabulary"); + $tokens['node']['vocab-raw'] = t("Unfiltered name of top term's vocabulary."); + $tokens['node']['vocab-id'] = t("ID of top term's vocabulary"); - // Temporarily disabled -- see notes in node_token_values. - // $tokens['node']['catpath'] = t("Full taxonomy tree for the topmost term"); + // Temporarily disabled -- see notes in node_token_values. + // $tokens['node']['catpath'] = t("Full taxonomy tree for the topmost term"); + } $tokens['node'] += token_get_date_token_info(t('Node creation')); $tokens['node'] += token_get_date_token_info(t('Node modification'), 'mod-'); - $tokens['node']['menu'] = t("The name of the menu the node belongs to."); - $tokens['node']['menu-raw'] = t("The name of the menu the node belongs to."); - $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 /."); - $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."); - $tokens['node']['menu-link-mlid'] = t("The unique ID of the node's menu link."); - $tokens['node']['menu-link-plid'] = t("The unique ID of the node's menu link parent."); + if (module_exists('menu')) { + $tokens['node']['menu'] = t("The name of the menu the node belongs to."); + $tokens['node']['menu-raw'] = t("The name of the menu the node belongs to."); + $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 /."); + $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."); + $tokens['node']['menu-link-mlid'] = t("The unique ID of the node's menu link."); + $tokens['node']['menu-link-plid'] = t("The unique ID of the node's menu link parent."); + } return $tokens; }