You are here

function power_menu_get_menu in Power Menu 7

Same name and namespace in other branches
  1. 6 power_menu.module \power_menu_get_menu()

Get the menu which is defined as the power menu

5 calls to power_menu_get_menu()
power_menu_get_breadcrumbs in ./power_menu.module
Set Breadcrumbs based on active menu trail. I borrowed this function from the menutrails module
power_menu_get_menu_tree in ./power_menu.module
@todo Please document this function.
power_menu_get_mlid in ./power_menu.module
@todo Please document this function.
power_menu_node_location in ./power_menu.module
Determine the menu location of a node.
power_menu_node_view in ./power_menu.module
Implements hook_node_view().

File

./power_menu.module, line 236
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_menu() {
  global $user, $language, $theme_key;
  $menus = array_filter(variable_get('power_menu_menu', array()));
  if (empty($menus)) {
    drupal_set_message(t("You have not chosen any power menu. Please visit the power menu settings"));
    return NULL;
  }
  $rids = array_keys($user->roles);
  $current_theme = variable_get('theme_default', 'none');
  $result = db_query("SELECT b.* FROM {block} AS b LEFT JOIN {block_role} AS r ON b.delta = r.delta\n    WHERE b.module IN ('menu', 'system') \n    AND b.theme = :theme AND b.delta IN (:delta)\n    AND (r.rid IN (:rids) OR r.rid IS NULL)", array(
    ':theme' => $current_theme,
    ':delta' => array_values($menus),
    ':rids' => $rids,
  ));
  foreach ($result as $block) {

    // Filter menu blocks by language
    if (module_exists('i18n_block')) {

      // Fake status and theme. Otherwise the i18n_block module would not check the
      // language definition on the menu block in i18n_block_block_list_alter().
      $block->status = 1;
      $block->theme = $theme_key;
      $lang_block = array(
        $block->bid => $block,
      );
      i18n_block_block_list_alter($lang_block);

      // Is the block removed, continue with the next power menu block
      if (count($lang_block) == 0) {
        continue;
      }
    }

    // Match path if necessary
    if ($block->pages) {
      if ($block->visibility < 2) {
        $path = drupal_get_path_alias($_GET['q']);

        // Compare with the internal and path alias (if any).
        $page_match = drupal_match_path($path, $block->pages);
        if ($path != $_GET['q']) {
          $page_match = $page_match || drupal_match_path($_GET['q'], $block->pages);
        }

        // When $block->visibility has a value of 0, the block is displayed on
        // all pages except those listed in $block->pages. When set to 1, it
        // is displayed only on those pages listed in $block->pages.
        $page_match = !($block->visibility xor $page_match);
        if ($page_match) {
          return $block->delta;
        }
      }
      else {
        if (module_exists('php')) {
          $page_match = php_eval($block->pages);
        }
      }
    }
    else {
      $page_match = TRUE;
      return $block->delta;
    }
  }
}