Mercurial > defr > drupal > core
comparison includes/menu.inc @ 5:2427550111ae 6.2
Drupal 6.2
| author | Franck Deroche <webmaster@defr.org> |
|---|---|
| date | Tue, 23 Dec 2008 14:30:08 +0100 |
| parents | 165d43f946a8 |
| children | fff6d4c8c043 |
comparison
equal
deleted
inserted
replaced
| 4:d94886ac61a0 | 5:2427550111ae |
|---|---|
| 1 <?php | 1 <?php |
| 2 // $Id: menu.inc,v 1.255.2.9 2008/02/27 12:12:01 goba Exp $ | 2 // $Id: menu.inc,v 1.255.2.11 2008/04/09 21:11:44 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 */ |
| 770 function menu_tree_all_data($menu_name = 'navigation', $item = NULL) { | 770 function menu_tree_all_data($menu_name = 'navigation', $item = NULL) { |
| 771 static $tree = array(); | 771 static $tree = array(); |
| 772 | 772 |
| 773 // Use $mlid as a flag for whether the data being loaded is for the whole tree. | 773 // Use $mlid as a flag for whether the data being loaded is for the whole tree. |
| 774 $mlid = isset($item['mlid']) ? $item['mlid'] : 0; | 774 $mlid = isset($item['mlid']) ? $item['mlid'] : 0; |
| 775 // Generate the cache ID. | 775 // Generate a cache ID (cid) specific for this $menu_name and $item. |
| 776 $cid = 'links:'. $menu_name .':all:'. $mlid; | 776 $cid = 'links:'. $menu_name .':all-cid:'. $mlid; |
| 777 | 777 |
| 778 if (!isset($tree[$cid])) { | 778 if (!isset($tree[$cid])) { |
| 779 // If the static variable doesn't have the data, check {cache_menu}. | 779 // If the static variable doesn't have the data, check {cache_menu}. |
| 780 $cache = cache_get($cid, 'cache_menu'); | 780 $cache = cache_get($cid, 'cache_menu'); |
| 781 if ($cache && isset($cache->data)) { | 781 if ($cache && isset($cache->data)) { |
| 782 $data = $cache->data; | 782 // If the cache entry exists, it will just be the cid for the actual data. |
| 783 } | 783 // This avoids duplication of large amounts of data. |
| 784 else { | 784 $cache = cache_get($cache->data, 'cache_menu'); |
| 785 if ($cache && isset($cache->data)) { | |
| 786 $data = $cache->data; | |
| 787 } | |
| 788 } | |
| 789 // If the tree data was not in the cache, $data will be NULL. | |
| 790 if (!isset($data)) { | |
| 785 // Build and run the query, and build the tree. | 791 // Build and run the query, and build the tree. |
| 786 if ($mlid) { | 792 if ($mlid) { |
| 787 // The tree is for a single item, so we need to match the values in its | 793 // The tree is for a single item, so we need to match the values in its |
| 788 // p columns and 0 (the top level) with the plid values of other links. | 794 // p columns and 0 (the top level) with the plid values of other links. |
| 789 $args = array(0); | 795 $args = array(0); |
| 811 FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path | 817 FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path |
| 812 WHERE ml.menu_name = '%s'". $where ." | 818 WHERE ml.menu_name = '%s'". $where ." |
| 813 ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC", $args), $parents); | 819 ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC", $args), $parents); |
| 814 $data['node_links'] = array(); | 820 $data['node_links'] = array(); |
| 815 menu_tree_collect_node_links($data['tree'], $data['node_links']); | 821 menu_tree_collect_node_links($data['tree'], $data['node_links']); |
| 816 // Cache the data. | 822 // Cache the data, if it is not already in the cache. |
| 817 cache_set($cid, $data, 'cache_menu'); | 823 $tree_cid = _menu_tree_cid($menu_name, $data); |
| 824 if (!cache_get($tree_cid, 'cache_menu')) { | |
| 825 cache_set($tree_cid, $data, 'cache_menu'); | |
| 826 } | |
| 827 // Cache the cid of the (shared) data using the menu and item-specific cid. | |
| 828 cache_set($cid, $tree_cid, 'cache_menu'); | |
| 818 } | 829 } |
| 819 // Check access for the current user to each item in the tree. | 830 // Check access for the current user to each item in the tree. |
| 820 menu_tree_check_access($data['tree'], $data['node_links']); | 831 menu_tree_check_access($data['tree'], $data['node_links']); |
| 821 $tree[$cid] = $data['tree']; | 832 $tree[$cid] = $data['tree']; |
| 822 } | 833 } |
| 842 function menu_tree_page_data($menu_name = 'navigation') { | 853 function menu_tree_page_data($menu_name = 'navigation') { |
| 843 static $tree = array(); | 854 static $tree = array(); |
| 844 | 855 |
| 845 // Load the menu item corresponding to the current page. | 856 // Load the menu item corresponding to the current page. |
| 846 if ($item = menu_get_item()) { | 857 if ($item = menu_get_item()) { |
| 847 // Generate the cache ID. | 858 // Generate a cache ID (cid) specific for this page. |
| 848 $cid = 'links:'. $menu_name .':page:'. $item['href'] .':'. (int)$item['access']; | 859 $cid = 'links:'. $menu_name .':page-cid:'. $item['href'] .':'. (int)$item['access']; |
| 849 | 860 |
| 850 if (!isset($tree[$cid])) { | 861 if (!isset($tree[$cid])) { |
| 851 // If the static variable doesn't have the data, check {cache_menu}. | 862 // If the static variable doesn't have the data, check {cache_menu}. |
| 852 $cache = cache_get($cid, 'cache_menu'); | 863 $cache = cache_get($cid, 'cache_menu'); |
| 853 if ($cache && isset($cache->data)) { | 864 if ($cache && isset($cache->data)) { |
| 854 $data = $cache->data; | 865 // If the cache entry exists, it will just be the cid for the actual data. |
| 855 } | 866 // This avoids duplication of large amounts of data. |
| 856 else { | 867 $cache = cache_get($cache->data, 'cache_menu'); |
| 868 if ($cache && isset($cache->data)) { | |
| 869 $data = $cache->data; | |
| 870 } | |
| 871 } | |
| 872 // If the tree data was not in the cache, $data will be NULL. | |
| 873 if (!isset($data)) { | |
| 857 // Build and run the query, and build the tree. | 874 // Build and run the query, and build the tree. |
| 858 if ($item['access']) { | 875 if ($item['access']) { |
| 859 // Check whether a menu link exists that corresponds to the current path. | 876 // Check whether a menu link exists that corresponds to the current path. |
| 860 $args = array($menu_name, $item['href']); | 877 $args = array($menu_name, $item['href']); |
| 861 $placeholders = "'%s'"; | 878 $placeholders = "'%s'"; |
| 907 FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path | 924 FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path |
| 908 WHERE ml.menu_name = '%s' AND ml.plid IN (". $placeholders .") | 925 WHERE ml.menu_name = '%s' AND ml.plid IN (". $placeholders .") |
| 909 ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC", $args), $parents); | 926 ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC", $args), $parents); |
| 910 $data['node_links'] = array(); | 927 $data['node_links'] = array(); |
| 911 menu_tree_collect_node_links($data['tree'], $data['node_links']); | 928 menu_tree_collect_node_links($data['tree'], $data['node_links']); |
| 912 // Cache the data. | 929 // Cache the data, if it is not already in the cache. |
| 913 cache_set($cid, $data, 'cache_menu'); | 930 $tree_cid = _menu_tree_cid($menu_name, $data); |
| 931 if (!cache_get($tree_cid, 'cache_menu')) { | |
| 932 cache_set($tree_cid, $data, 'cache_menu'); | |
| 933 } | |
| 934 // Cache the cid of the (shared) data using the page-specific cid. | |
| 935 cache_set($cid, $tree_cid, 'cache_menu'); | |
| 914 } | 936 } |
| 915 // Check access for the current user to each item in the tree. | 937 // Check access for the current user to each item in the tree. |
| 916 menu_tree_check_access($data['tree'], $data['node_links']); | 938 menu_tree_check_access($data['tree'], $data['node_links']); |
| 917 $tree[$cid] = $data['tree']; | 939 $tree[$cid] = $data['tree']; |
| 918 } | 940 } |
| 919 return $tree[$cid]; | 941 return $tree[$cid]; |
| 920 } | 942 } |
| 921 | 943 |
| 922 return array(); | 944 return array(); |
| 945 } | |
| 946 | |
| 947 /** | |
| 948 * Helper function - compute the real cache ID for menu tree data. | |
| 949 */ | |
| 950 function _menu_tree_cid($menu_name, $data) { | |
| 951 return 'links:'. $menu_name .':tree-data:'. md5(serialize($data)); | |
| 923 } | 952 } |
| 924 | 953 |
| 925 /** | 954 /** |
| 926 * Recursive helper function - collect node links. | 955 * Recursive helper function - collect node links. |
| 927 */ | 956 */ |
| 2244 $item['tab_parent'] = $parent_path; | 2273 $item['tab_parent'] = $parent_path; |
| 2245 } | 2274 } |
| 2246 if (!isset($item['tab_root']) && !$parent['_tab']) { | 2275 if (!isset($item['tab_root']) && !$parent['_tab']) { |
| 2247 $item['tab_root'] = $parent_path; | 2276 $item['tab_root'] = $parent_path; |
| 2248 } | 2277 } |
| 2249 // If a callback is not found, we try to find the first parent that | 2278 // If an access callback is not found for a default local task we use |
| 2250 // has a callback. | 2279 // the callback from the parent, since we expect them to be identical. |
| 2251 if (!isset($item['access callback']) && isset($parent['access callback'])) { | 2280 // In all other cases, the access parameters must be specified. |
| 2281 if (($item['type'] == MENU_DEFAULT_LOCAL_TASK) && !isset($item['access callback']) && isset($parent['access callback'])) { | |
| 2252 $item['access callback'] = $parent['access callback']; | 2282 $item['access callback'] = $parent['access callback']; |
| 2253 if (!isset($item['access arguments']) && isset($parent['access arguments'])) { | 2283 if (!isset($item['access arguments']) && isset($parent['access arguments'])) { |
| 2254 $item['access arguments'] = $parent['access arguments']; | 2284 $item['access arguments'] = $parent['access arguments']; |
| 2255 } | 2285 } |
| 2256 } | 2286 } |
