comparison includes/menu.inc @ 11:589fb7c02327 6.5

Drupal 6.5
author Franck Deroche <webmaster@defr.org>
date Tue, 23 Dec 2008 14:32:19 +0100
parents fff6d4c8c043
children 8b6c45761e01
comparison
equal deleted inserted replaced
10:6f15c9d74937 11:589fb7c02327
1 <?php 1 <?php
2 // $Id: menu.inc,v 1.255.2.17 2008/07/09 15:23:50 goba Exp $ 2 // $Id: menu.inc,v 1.255.2.21 2008/10/08 12:33:55 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 */
333 */ 333 */
334 function menu_execute_active_handler($path = NULL) { 334 function menu_execute_active_handler($path = NULL) {
335 if (_menu_site_is_offline()) { 335 if (_menu_site_is_offline()) {
336 return MENU_SITE_OFFLINE; 336 return MENU_SITE_OFFLINE;
337 } 337 }
338 if (variable_get('menu_rebuild_needed', FALSE)) { 338 // Rebuild if we know it's needed, or if the menu masks are missing which
339 // occurs rarely, likely due to a race condition of multiple rebuilds.
340 if (variable_get('menu_rebuild_needed', FALSE) || !variable_get('menu_masks', array())) {
339 menu_rebuild(); 341 menu_rebuild();
340 } 342 }
341 if ($router_item = menu_get_item($path)) { 343 if ($router_item = menu_get_item($path)) {
342 if ($router_item['access']) { 344 if ($router_item['access']) {
343 if ($router_item['file']) { 345 if ($router_item['file']) {
360 * @param $map 362 * @param $map
361 * An array of path arguments (ex: array('node', '5')) 363 * An array of path arguments (ex: array('node', '5'))
362 * @return 364 * @return
363 * Returns TRUE for success, FALSE if an object cannot be loaded. 365 * Returns TRUE for success, FALSE if an object cannot be loaded.
364 * Names of object loading functions are placed in $item['load_functions']. 366 * Names of object loading functions are placed in $item['load_functions'].
365 * Loaded objects are placed in $map[]; keys are the same as keys in the 367 * Loaded objects are placed in $map[]; keys are the same as keys in the
366 * $item['load_functions'] array. 368 * $item['load_functions'] array.
367 * $item['access'] is set to FALSE if an object cannot be loaded. 369 * $item['access'] is set to FALSE if an object cannot be loaded.
368 */ 370 */
369 function _menu_load_objects(&$item, &$map) { 371 function _menu_load_objects(&$item, &$map) {
370 if ($load_functions = $item['load_functions']) { 372 if ($load_functions = $item['load_functions']) {
469 * TRUE if we are translating a menu link item; FALSE if we are 471 * TRUE if we are translating a menu link item; FALSE if we are
470 * translating a menu router item. 472 * translating a menu router item.
471 * @return 473 * @return
472 * No return value. 474 * No return value.
473 * $item['title'] is localized according to $item['title_callback']. 475 * $item['title'] is localized according to $item['title_callback'].
474 * If an item's callback is check_plain(), $item['options']['html'] becomes 476 * If an item's callback is check_plain(), $item['options']['html'] becomes
475 * TRUE. 477 * TRUE.
476 * $item['description'] is translated using t(). 478 * $item['description'] is translated using t().
477 * When doing link translation and the $item['options']['attributes']['title'] 479 * When doing link translation and the $item['options']['attributes']['title']
478 * (link title attribute) matches the description, it is translated as well. 480 * (link title attribute) matches the description, it is translated as well.
479 */ 481 */
480 function _menu_item_localize(&$item, $map, $link_translate = FALSE) { 482 function _menu_item_localize(&$item, $map, $link_translate = FALSE) {
481 $callback = $item['title_callback']; 483 $callback = $item['title_callback'];
482 $item['localized_options'] = $item['options']; 484 $item['localized_options'] = $item['options'];
655 // For performance, don't localize a link the user can't access. 657 // For performance, don't localize a link the user can't access.
656 if ($item['access']) { 658 if ($item['access']) {
657 _menu_item_localize($item, $map, TRUE); 659 _menu_item_localize($item, $map, TRUE);
658 } 660 }
659 } 661 }
660 662
661 // Allow other customizations - e.g. adding a page-specific query string to the 663 // Allow other customizations - e.g. adding a page-specific query string to the
662 // options array. For performance reasons we only invoke this hook if the link 664 // options array. For performance reasons we only invoke this hook if the link
663 // has the 'alter' flag set in the options array. 665 // has the 'alter' flag set in the options array.
664 if (!empty($item['options']['alter'])) { 666 if (!empty($item['options']['alter'])) {
665 drupal_alter('translated_menu_link', $item, $map); 667 drupal_alter('translated_menu_link', $item, $map);
666 } 668 }
667 669
668 return $map; 670 return $map;
669 } 671 }
670 672
671 /** 673 /**
672 * Get a loaded object from a router item. 674 * Get a loaded object from a router item.
1157 * Returns the help associated with the active menu item. 1159 * Returns the help associated with the active menu item.
1158 */ 1160 */
1159 function menu_get_active_help() { 1161 function menu_get_active_help() {
1160 $output = ''; 1162 $output = '';
1161 $router_path = menu_tab_root_path(); 1163 $router_path = menu_tab_root_path();
1164 // We will always have a path unless we are on a 403 or 404.
1165 if (!$router_path) {
1166 return '';
1167 }
1162 1168
1163 $arg = drupal_help_arg(arg(NULL)); 1169 $arg = drupal_help_arg(arg(NULL));
1164 $empty_arg = drupal_help_arg(); 1170 $empty_arg = drupal_help_arg();
1165 1171
1166 foreach (module_list() as $name) { 1172 foreach (module_list() as $name) {
1555 /** 1561 /**
1556 * Get the breadcrumb for the current page, as determined by the active trail. 1562 * Get the breadcrumb for the current page, as determined by the active trail.
1557 */ 1563 */
1558 function menu_get_active_breadcrumb() { 1564 function menu_get_active_breadcrumb() {
1559 $breadcrumb = array(); 1565 $breadcrumb = array();
1560 1566
1561 // No breadcrumb for the front page. 1567 // No breadcrumb for the front page.
1562 if (drupal_is_front_page()) { 1568 if (drupal_is_front_page()) {
1563 return $breadcrumb; 1569 return $breadcrumb;
1564 } 1570 }
1565 1571
1733 1739
1734 foreach ($menu_links as $item) { 1740 foreach ($menu_links as $item) {
1735 $existing_item = db_fetch_array(db_query("SELECT mlid, menu_name, plid, customized, has_children, updated FROM {menu_links} WHERE link_path = '%s' AND module = '%s'", $item['link_path'], 'system')); 1741 $existing_item = db_fetch_array(db_query("SELECT mlid, menu_name, plid, customized, has_children, updated FROM {menu_links} WHERE link_path = '%s' AND module = '%s'", $item['link_path'], 'system'));
1736 if ($existing_item) { 1742 if ($existing_item) {
1737 $item['mlid'] = $existing_item['mlid']; 1743 $item['mlid'] = $existing_item['mlid'];
1738 $item['menu_name'] = $existing_item['menu_name']; 1744 // A change in hook_menu may move the link to a different menu
1739 $item['plid'] = $existing_item['plid']; 1745 if (empty($item['menu_name']) || ($item['menu_name'] == $existing_item['menu_name'])) {
1746 $item['menu_name'] = $existing_item['menu_name'];
1747 $item['plid'] = $existing_item['plid'];
1748 }
1740 $item['has_children'] = $existing_item['has_children']; 1749 $item['has_children'] = $existing_item['has_children'];
1741 $item['updated'] = $existing_item['updated']; 1750 $item['updated'] = $existing_item['updated'];
1742 } 1751 }
1743 if (!$existing_item || !$existing_item['customized']) { 1752 if (!$existing_item || !$existing_item['customized']) {
1744 menu_link_save($item); 1753 menu_link_save($item);
1826 * - expanded whether the item is expanded. 1835 * - expanded whether the item is expanded.
1827 * - options An array of options, @see l for more. 1836 * - options An array of options, @see l for more.
1828 * - mlid Set to an existing value, or 0 or NULL to insert a new link. 1837 * - mlid Set to an existing value, or 0 or NULL to insert a new link.
1829 * - plid The mlid of the parent. 1838 * - plid The mlid of the parent.
1830 * - router_path The path of the relevant router item. 1839 * - router_path The path of the relevant router item.
1840 * @return
1841 * The mlid of the saved menu link, or FALSE if the menu link could not be
1842 * saved.
1831 */ 1843 */
1832 function menu_link_save(&$item) { 1844 function menu_link_save(&$item) {
1833 $menu = menu_router_build(); 1845 $menu = menu_router_build();
1834 1846
1835 drupal_alter('menu_link', $item, $menu); 1847 drupal_alter('menu_link', $item, $menu);
2058 ); 2070 );
2059 return menu_link_save($menu_link); 2071 return menu_link_save($menu_link);
2060 break; 2072 break;
2061 case 'update': 2073 case 'update':
2062 db_query("UPDATE {menu_links} SET link_title = '%s' WHERE link_path = '%s' AND customized = 0 AND module = '%s'", $link_title, $link_path, $module); 2074 db_query("UPDATE {menu_links} SET link_title = '%s' WHERE link_path = '%s' AND customized = 0 AND module = '%s'", $link_title, $link_path, $module);
2063 menu_cache_clear(); 2075 $result = db_query("SELECT menu_name FROM {menu_links} WHERE link_path = '%s' AND customized = 0 AND module = '%s'", $link_path, $module);
2076 while ($item = db_fetch_array($result)) {
2077 menu_cache_clear($item['menu_name']);
2078 }
2064 break; 2079 break;
2065 case 'delete': 2080 case 'delete':
2066 menu_link_delete(NULL, $link_path); 2081 menu_link_delete(NULL, $link_path);
2067 break; 2082 break;
2068 } 2083 }