You are here

function taxonomy_menu_trails_init in Taxonomy Menu Trails 6.x

Same name and namespace in other branches
  1. 6 taxonomy_menu_trails.module \taxonomy_menu_trails_init()
  2. 7.2 taxonomy_menu_trails.module \taxonomy_menu_trails_init()
  3. 7 taxonomy_menu_trails.module \taxonomy_menu_trails_init()

Implementation of hook_init().

File

./taxonomy_menu_trails.module, line 14
Changes menu trail of current node to its lightest term's menu item (only if node doesn't belong to any menu)

Code

function taxonomy_menu_trails_init() {
  if (arg(0) == 'node' && is_numeric(arg(1))) {
    $node = node_load(arg(1));
  }
  else {
    $exprs = variable_get('taxonomy_menu_trails_node_paths', array());
    $match = FALSE;
    foreach ($exprs as $kind => $patterns) {
      foreach ($patterns as $pattern) {
        if (preg_match($pattern, $_GET['q'], $m)) {
          $node = node_load(array(
            $kind => $m[1],
          ));
          $match = TRUE;
          break 2;
        }
      }
    }
    if (!$match) {
      return;
    }
  }
  $enabled_types = variable_get('taxonomy_menu_trails_node_types', array());
  $item = menu_get_item();
  if (!empty($node->taxonomy) && !empty($enabled_types[$node->type]) && (!variable_get('taxonomy_menu_trails_only_without_menu', TRUE) || db_result(db_query('SELECT mlid FROM {menu_links} WHERE link_path = "%s" AND hidden = 0 LIMIT 1', $item['href'])) == 0)) {
    module_load_include('inc', 'taxonomy_menu_trails');
    _taxonomy_menu_trails_process($node, $item);
  }
}