function _power_menu_get_node_location_taxonomy in Power Menu 6
Same name and namespace in other branches
- 7 power_menu.module \_power_menu_get_node_location_taxonomy()
Parameters
$node:
$current_menu:
2 calls to _power_menu_get_node_location_taxonomy()
- power_menu_node_location in ./
power_menu.module - Determine the menu location of a node.
- power_menu_token_values in ./
power_menu.module - Implementation of hook_token_values().
File
- ./
power_menu.module, line 323 - This module provides some additional menu features. The features are not actually new, but are part of other modules. it's though very cumbersome to creating a new menu item, because one has to go to all the different places to configure these…
Code
function _power_menu_get_node_location_taxonomy($node, $current_power_menu) {
// We are going to reorder the term tree so that we know if a given term
// is a leaf or not.
if ($cache = cache_get('power_menu_taxonomy') && !empty($cache->data)) {
$leaf_tree = $cache->data;
}
else {
$tree = taxonomy_get_tree(variable_get('power_menu_taxonomy_navigation', ''));
$leaf_tree = array();
foreach ($tree as $el) {
$has_parent = FALSE;
for ($i = 1; $i < count($tree); $i++) {
if (in_array($el->tid, $tree[$i]->parents)) {
$has_parent = TRUE;
break;
}
}
if ($has_parent) {
$leaf_tree[$el->tid] = FALSE;
}
else {
$leaf_tree[$el->tid] = TRUE;
}
}
cache_set('power_menu_taxonomy', $leaf_tree, 'cache', time() + 60 * 60);
}
$counter = 0;
$tid = 0;
foreach ($node->taxonomy as $taxo) {
if (!is_array($taxo)) {
//we have all terms in a flat structure
if (!isset($taxo->vid)) {
//incase we don't have the whole term structure
$taxo = taxonomy_get_term($taxo);
}
if ($taxo->vid == variable_get('power_menu_taxonomy_navigation', '')) {
if ($leaf_tree[$taxo->tid] || $counter == 0) {
//incase a node is not in the leave
$tid = $taxo->tid;
$counter++;
}
}
}
elseif (is_array($node->taxonomy[power_menu_get_navigation_taxonomy()])) {
// our terms are grouped by vid and have a different structure
foreach ($node->taxonomy[power_menu_get_navigation_taxonomy()] as $tid) {
if ($leaf_tree[$taxo->tid] || $counter == 0) {
//incase a node is not in the leave
$tid = $taxo->tid;
$counter++;
}
}
}
}
if ($tid == 0) {
return NULL;
}
return db_result(db_query("SELECT path FROM {power_menu} WHERE tid=%d AND menu_name='%s'", array(
$tid,
$current_power_menu,
)));
}