All pastes #426492 Raw Edit

Untitled

public text v1 · immutable
·published 2007-04-06 05:10 UTC
rendered paste body
function menu_menu($caller = NULL) {
  static $custom_items;
  if (isset($custom_items) && isset($caller) && $caller == 'menu_menu_alter') {
    return $custom_items;
  }
  $custom_items = array();
  $result = db_query('SELECT * FROM {menu_edit} WHERE admin = 1');
  while ($item = db_fetch_array($result)) {
    $custom_items[] = $item['path'];
    $items[$item['path']] = $item;
  }
}

function menu_menu_alter(&$menu, $phase) {
  switch ($phase) {
    case MENU_ALTER_MODULE_DEFINED:
      foreach (menu_menu('menu_menu_alter') as $path => $item) {
        list($ancestors, $placeholders) = menu_get_ancestors(explode('/', $path, 6));
        $inherit_path = db_result(db_query_range('SELECT path FROM {menu} WHERE path IN ('. implode (',', $placeholders) .') ORDER BY fit DESC', $ancestors, 0, 1));
        foreach (array('access callback', 'access arguments', 'page callback', 'page arguments') as $key) {
          $menu[$path][$key] = $menu[$inherit_path][$key];
        }
      }
      break;
    case MENU_ALTER_PREPROCESSED:
      $result = db_query('SELECT * FROM {menu_edit} me WHERE admin = 0');
      while ($item = db_fetch_array($result)) {
        $menu[$item['path']] = $item + $menu[$item['path']];
      }
      break;
  }
}