Mercurial > defr > drupal > core
comparison includes/menu.inc @ 7:fff6d4c8c043 6.3
Drupal 6.3
| author | Franck Deroche <webmaster@defr.org> |
|---|---|
| date | Tue, 23 Dec 2008 14:30:28 +0100 |
| parents | 2427550111ae |
| children | 589fb7c02327 |
comparison
equal
deleted
inserted
replaced
| 6:2cfdc3c92142 | 7:fff6d4c8c043 |
|---|---|
| 1 <?php | 1 <?php |
| 2 // $Id: menu.inc,v 1.255.2.11 2008/04/09 21:11:44 goba Exp $ | 2 // $Id: menu.inc,v 1.255.2.17 2008/07/09 15:23:50 goba Exp $ |
| 3 | 3 |
| 4 /** | 4 /** |
| 5 * @file | 5 * @file |
| 6 * API for the Drupal menu system. | 6 * API for the Drupal menu system. |
| 7 */ | 7 */ |
| 512 | 512 |
| 513 // Translate description, see the motivation above. | 513 // Translate description, see the motivation above. |
| 514 if (!empty($item['description'])) { | 514 if (!empty($item['description'])) { |
| 515 $original_description = $item['description']; | 515 $original_description = $item['description']; |
| 516 $item['description'] = t($item['description']); | 516 $item['description'] = t($item['description']); |
| 517 if ($link_translate && $item['options']['attributes']['title'] == $original_description) { | 517 if ($link_translate && isset($item['options']['attributes']['title']) && $item['options']['attributes']['title'] == $original_description) { |
| 518 $item['localized_options']['attributes']['title'] = $item['description']; | 518 $item['localized_options']['attributes']['title'] = $item['description']; |
| 519 } | 519 } |
| 520 } | 520 } |
| 521 } | 521 } |
| 522 | 522 |
| 568 } | 568 } |
| 569 } | 569 } |
| 570 $router_item['href'] = implode('/', $link_map); | 570 $router_item['href'] = implode('/', $link_map); |
| 571 $router_item['options'] = array(); | 571 $router_item['options'] = array(); |
| 572 _menu_check_access($router_item, $map); | 572 _menu_check_access($router_item, $map); |
| 573 | 573 |
| 574 _menu_item_localize($router_item, $map); | 574 // For performance, don't localize an item the user can't access. |
| 575 if ($router_item['access']) { | |
| 576 _menu_item_localize($router_item, $map); | |
| 577 } | |
| 575 | 578 |
| 576 return $map; | 579 return $map; |
| 577 } | 580 } |
| 578 | 581 |
| 579 /** | 582 /** |
| 647 $item['access'] = FALSE; | 650 $item['access'] = FALSE; |
| 648 return FALSE; | 651 return FALSE; |
| 649 } | 652 } |
| 650 _menu_check_access($item, $map); | 653 _menu_check_access($item, $map); |
| 651 } | 654 } |
| 652 | 655 // For performance, don't localize a link the user can't access. |
| 653 _menu_item_localize($item, $map, TRUE); | 656 if ($item['access']) { |
| 657 _menu_item_localize($item, $map, TRUE); | |
| 658 } | |
| 654 } | 659 } |
| 655 | 660 |
| 656 // Allow other customizations - e.g. adding a page-specific query string to the | 661 // Allow other customizations - e.g. adding a page-specific query string to the |
| 657 // options array. For performance reasons we only invoke this hook if the link | 662 // options array. For performance reasons we only invoke this hook if the link |
| 658 // has the 'alter' flag set in the options array. | 663 // has the 'alter' flag set in the options array. |
| 1255 foreach ($tree as $item) { | 1260 foreach ($tree as $item) { |
| 1256 if (!$item['link']['hidden']) { | 1261 if (!$item['link']['hidden']) { |
| 1257 $l = $item['link']['localized_options']; | 1262 $l = $item['link']['localized_options']; |
| 1258 $l['href'] = $item['link']['href']; | 1263 $l['href'] = $item['link']['href']; |
| 1259 $l['title'] = $item['link']['title']; | 1264 $l['title'] = $item['link']['title']; |
| 1265 if ($item['link']['in_active_trail']) { | |
| 1266 if (empty($l['attributes']['class'])) { | |
| 1267 $l['attributes']['class'] = 'active-trail'; | |
| 1268 } | |
| 1269 else { | |
| 1270 $l['attributes']['class'] .= ' active-trail'; | |
| 1271 } | |
| 1272 } | |
| 1260 // Keyed with unique menu id to generate classes from theme_links(). | 1273 // Keyed with unique menu id to generate classes from theme_links(). |
| 1261 $links['menu-'. $item['link']['mlid']] = $l; | 1274 $links['menu-'. $item['link']['mlid']] = $l; |
| 1262 } | 1275 } |
| 1263 } | 1276 } |
| 1264 return $links; | 1277 return $links; |
| 1512 if ($curr['link']['href'] == $item['href']) { | 1525 if ($curr['link']['href'] == $item['href']) { |
| 1513 $trail[] = $curr['link']; | 1526 $trail[] = $curr['link']; |
| 1514 $curr = FALSE; | 1527 $curr = FALSE; |
| 1515 } | 1528 } |
| 1516 else { | 1529 else { |
| 1517 // Move to the child link if it's in the active trail. | 1530 // Add the link if it's in the active trail, then move to the link below. |
| 1518 if ($curr['below'] && $curr['link']['in_active_trail']) { | 1531 if ($curr['link']['in_active_trail']) { |
| 1519 $trail[] = $curr['link']; | 1532 $trail[] = $curr['link']; |
| 1520 $tree = $curr['below']; | 1533 $tree = $curr['below'] ? $curr['below'] : array(); |
| 1521 } | 1534 } |
| 1522 list($key, $curr) = each($tree); | 1535 list($key, $curr) = each($tree); |
| 1523 } | 1536 } |
| 1524 } | 1537 } |
| 1525 // Make sure the current page is in the trail (needed for the page title), | 1538 // Make sure the current page is in the trail (needed for the page title), |
| 1656 if (!isset($menu) || $reset) { | 1669 if (!isset($menu) || $reset) { |
| 1657 if (!$reset && ($cache = cache_get('router:', 'cache_menu')) && isset($cache->data)) { | 1670 if (!$reset && ($cache = cache_get('router:', 'cache_menu')) && isset($cache->data)) { |
| 1658 $menu = $cache->data; | 1671 $menu = $cache->data; |
| 1659 } | 1672 } |
| 1660 else { | 1673 else { |
| 1661 db_query('DELETE FROM {menu_router}'); | |
| 1662 // We need to manually call each module so that we can know which module | 1674 // We need to manually call each module so that we can know which module |
| 1663 // a given item came from. | 1675 // a given item came from. |
| 1664 $callbacks = array(); | 1676 $callbacks = array(); |
| 1665 foreach (module_implements('menu') as $module) { | 1677 foreach (module_implements('menu') as $module) { |
| 1666 $router_items = call_user_func($module .'_menu'); | 1678 $router_items = call_user_func($module .'_menu'); |
| 1672 } | 1684 } |
| 1673 } | 1685 } |
| 1674 // Alter the menu as defined in modules, keys are like user/%user. | 1686 // Alter the menu as defined in modules, keys are like user/%user. |
| 1675 drupal_alter('menu', $callbacks); | 1687 drupal_alter('menu', $callbacks); |
| 1676 $menu = _menu_router_build($callbacks); | 1688 $menu = _menu_router_build($callbacks); |
| 1677 cache_set('router:', $menu, 'cache_menu'); | |
| 1678 } | 1689 } |
| 1679 } | 1690 } |
| 1680 return $menu; | 1691 return $menu; |
| 1681 } | 1692 } |
| 1682 | 1693 |
| 2252 $sort[$path] = $number_parts; | 2263 $sort[$path] = $number_parts; |
| 2253 } | 2264 } |
| 2254 } | 2265 } |
| 2255 array_multisort($sort, SORT_NUMERIC, $menu); | 2266 array_multisort($sort, SORT_NUMERIC, $menu); |
| 2256 | 2267 |
| 2268 if (!$menu) { | |
| 2269 // We must have a serious error - there is no data to save. | |
| 2270 watchdog('php', 'Menu router rebuild failed - some paths may not work correctly.', array(), WATCHDOG_ERROR); | |
| 2271 return array(); | |
| 2272 } | |
| 2273 // Delete the existing router since we have some data to replace it. | |
| 2274 db_query('DELETE FROM {menu_router}'); | |
| 2257 // Apply inheritance rules. | 2275 // Apply inheritance rules. |
| 2258 foreach ($menu as $path => $v) { | 2276 foreach ($menu as $path => $v) { |
| 2259 $item = &$menu[$path]; | 2277 $item = &$menu[$path]; |
| 2260 if (!$item['_tab']) { | 2278 if (!$item['_tab']) { |
| 2261 // Non-tab items. | 2279 // Non-tab items. |
| 2354 } | 2372 } |
| 2355 // Sort the masks so they are in order of descending fit, and store them. | 2373 // Sort the masks so they are in order of descending fit, and store them. |
| 2356 $masks = array_keys($masks); | 2374 $masks = array_keys($masks); |
| 2357 rsort($masks); | 2375 rsort($masks); |
| 2358 variable_set('menu_masks', $masks); | 2376 variable_set('menu_masks', $masks); |
| 2377 cache_set('router:', $menu, 'cache_menu'); | |
| 2359 return $menu; | 2378 return $menu; |
| 2360 } | 2379 } |
| 2361 | 2380 |
| 2362 /** | 2381 /** |
| 2363 * Returns TRUE if a path is external (e.g. http://example.com). | 2382 * Returns TRUE if a path is external (e.g. http://example.com). |
