Mercurial > defr > drupal > core
comparison includes/menu.inc @ 3:165d43f946a8 6.1
Drupal 6.1
author | Franck Deroche <webmaster@defr.org> |
---|---|
date | Tue, 23 Dec 2008 14:29:21 +0100 |
parents | c1f4ac30525a |
children | 2427550111ae |
comparison
equal
deleted
inserted
replaced
2:85b5b336180c | 3:165d43f946a8 |
---|---|
1 <?php | 1 <?php |
2 // $Id: menu.inc,v 1.255.2.7 2008/02/12 22:33:51 goba Exp $ | 2 // $Id: menu.inc,v 1.255.2.9 2008/02/27 12:12:01 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 */ |
173 | 173 |
174 /** | 174 /** |
175 * Returns the ancestors (and relevant placeholders) for any given path. | 175 * Returns the ancestors (and relevant placeholders) for any given path. |
176 * | 176 * |
177 * For example, the ancestors of node/12345/edit are: | 177 * For example, the ancestors of node/12345/edit are: |
178 * | 178 * - node/12345/edit |
179 * node/12345/edit | 179 * - node/12345/% |
180 * node/12345/% | 180 * - node/%/edit |
181 * node/%/edit | 181 * - node/%/% |
182 * node/%/% | 182 * - node/12345 |
183 * node/12345 | 183 * - node/% |
184 * node/% | 184 * - node |
185 * node | |
186 * | 185 * |
187 * To generate these, we will use binary numbers. Each bit represents a | 186 * To generate these, we will use binary numbers. Each bit represents a |
188 * part of the path. If the bit is 1, then it represents the original | 187 * part of the path. If the bit is 1, then it represents the original |
189 * value while 0 means wildcard. If the path is node/12/edit/foo | 188 * value while 0 means wildcard. If the path is node/12/edit/foo |
190 * then the 1011 bitstring represents node/%/edit/foo where % means that | 189 * then the 1011 bitstring represents node/%/edit/foo where % means that |
607 return implode('/', array_slice($map, $index)); | 606 return implode('/', array_slice($map, $index)); |
608 } | 607 } |
609 | 608 |
610 /** | 609 /** |
611 * This function is similar to _menu_translate() but does link-specific | 610 * This function is similar to _menu_translate() but does link-specific |
612 * preparation such as always calling to_arg functions | 611 * preparation such as always calling to_arg functions. |
613 * | 612 * |
614 * @param $item | 613 * @param $item |
615 * A menu link | 614 * A menu link |
616 * @return | 615 * @return |
617 * Returns the map of path arguments with objects loaded as defined in the | 616 * Returns the map of path arguments with objects loaded as defined in the |
618 * $item['load_functions']. | 617 * $item['load_functions']: |
619 * $item['access'] becomes TRUE if the item is accessible, FALSE otherwise. | 618 * - $item['access'] becomes TRUE if the item is accessible, FALSE otherwise. |
620 * $item['href'] is generated from link_path, possibly by to_arg functions. | 619 * - $item['href'] is generated from link_path, possibly by to_arg functions. |
621 * $item['title'] is generated from link_title, and may be localized. | 620 * - $item['title'] is generated from link_title, and may be localized. |
622 * $item['options'] is unserialized; it is also changed within the call here | 621 * - $item['options'] is unserialized; it is also changed within the call |
623 * to $item['localized_options'] by _menu_item_localize(). | 622 * here to $item['localized_options'] by _menu_item_localize(). |
624 */ | 623 */ |
625 function _menu_link_translate(&$item) { | 624 function _menu_link_translate(&$item) { |
626 $item['options'] = unserialize($item['options']); | 625 $item['options'] = unserialize($item['options']); |
627 if ($item['external']) { | 626 if ($item['external']) { |
628 $item['access'] = 1; | 627 $item['access'] = 1; |
680 * relevant {$type}_load function for more on each. Defaults to node. | 679 * relevant {$type}_load function for more on each. Defaults to node. |
681 * @param $position | 680 * @param $position |
682 * The expected position for $type object. For node/%node this is 1, for | 681 * The expected position for $type object. For node/%node this is 1, for |
683 * comment/reply/%node this is 2. Defaults to 1. | 682 * comment/reply/%node this is 2. Defaults to 1. |
684 * @param $path | 683 * @param $path |
685 * See @menu_get_item for more on this. Defaults to the current path. | 684 * See menu_get_item() for more on this. Defaults to the current path. |
686 */ | 685 */ |
687 function menu_get_object($type = 'node', $position = 1, $path = NULL) { | 686 function menu_get_object($type = 'node', $position = 1, $path = NULL) { |
688 $router_item = menu_get_item($path); | 687 $router_item = menu_get_item($path); |
689 if (isset($router_item['load_functions'][$position]) && !empty($router_item['map'][$position]) && $router_item['load_functions'][$position] == $type .'_load') { | 688 if (isset($router_item['load_functions'][$position]) && !empty($router_item['map'][$position]) && $router_item['load_functions'][$position] == $type .'_load') { |
690 return $router_item['map'][$position]; | 689 return $router_item['map'][$position]; |
1706 } | 1705 } |
1707 } | 1706 } |
1708 } | 1707 } |
1709 $placeholders = db_placeholders($menu, 'varchar'); | 1708 $placeholders = db_placeholders($menu, 'varchar'); |
1710 $paths = array_keys($menu); | 1709 $paths = array_keys($menu); |
1711 // Updated items and customized items which router paths are gone need new | 1710 // Updated and customized items whose router paths are gone need new ones. |
1712 // router paths. | |
1713 $result = db_query("SELECT ml.link_path, ml.mlid, ml.router_path, ml.updated FROM {menu_links} ml WHERE ml.updated = 1 OR (router_path NOT IN ($placeholders) AND external = 0 AND customized = 1)", $paths); | 1711 $result = db_query("SELECT ml.link_path, ml.mlid, ml.router_path, ml.updated FROM {menu_links} ml WHERE ml.updated = 1 OR (router_path NOT IN ($placeholders) AND external = 0 AND customized = 1)", $paths); |
1714 while ($item = db_fetch_array($result)) { | 1712 while ($item = db_fetch_array($result)) { |
1715 $router_path = _menu_find_router_path($menu, $item['link_path']); | 1713 $router_path = _menu_find_router_path($menu, $item['link_path']); |
1716 if (!empty($router_path) && ($router_path != $item['router_path'] || $item['updated'])) { | 1714 if (!empty($router_path) && ($router_path != $item['router_path'] || $item['updated'])) { |
1717 // If the router path and the link path matches, it's surely a working | 1715 // If the router path and the link path matches, it's surely a working |
1718 // item, so we clear the updated flag. | 1716 // item, so we clear the updated flag. |
1719 $updated = $item['updated'] && $router_path != $item['link_path']; | 1717 $updated = $item['updated'] && $router_path != $item['link_path']; |
1720 db_query("UPDATE {menu_links} SET router_path = '%s', updated = %d WHERE mlid = %d", $router_path, $updated, $item['mlid']); | 1718 db_query("UPDATE {menu_links} SET router_path = '%s', updated = %d WHERE mlid = %d", $router_path, $updated, $item['mlid']); |
1721 } | 1719 } |
1722 } | 1720 } |
1723 // Find any items where their router path does not exist any more. | 1721 // Find any item whose router path does not exist any more. |
1724 $result = db_query("SELECT * FROM {menu_links} WHERE router_path NOT IN ($placeholders) AND external = 0 AND updated = 0 AND customized = 0 ORDER BY depth DESC", $paths); | 1722 $result = db_query("SELECT * FROM {menu_links} WHERE router_path NOT IN ($placeholders) AND external = 0 AND updated = 0 AND customized = 0 ORDER BY depth DESC", $paths); |
1725 // Remove all such items. Starting from those with the greatest depth will | 1723 // Remove all such items. Starting from those with the greatest depth will |
1726 // minimize the amount of re-parenting done by menu_link_delete(). | 1724 // minimize the amount of re-parenting done by menu_link_delete(). |
1727 while ($item = db_fetch_array($result)) { | 1725 while ($item = db_fetch_array($result)) { |
1728 _menu_delete_item($item, TRUE); | 1726 _menu_delete_item($item, TRUE); |
1780 /** | 1778 /** |
1781 * Save a menu link. | 1779 * Save a menu link. |
1782 * | 1780 * |
1783 * @param $item | 1781 * @param $item |
1784 * An array representing a menu link item. The only mandatory keys are | 1782 * An array representing a menu link item. The only mandatory keys are |
1785 * link_path and link_title. Possible keys are | 1783 * link_path and link_title. Possible keys are: |
1786 * menu_name default is navigation | 1784 * - menu_name default is navigation |
1787 * weight default is 0 | 1785 * - weight default is 0 |
1788 * expanded whether the item is expanded. | 1786 * - expanded whether the item is expanded. |
1789 * options An array of options, @see l for more. | 1787 * - options An array of options, @see l for more. |
1790 * mlid Set to an existing value, or 0 or NULL to insert a new link. | 1788 * - mlid Set to an existing value, or 0 or NULL to insert a new link. |
1791 * plid The mlid of the parent. | 1789 * - plid The mlid of the parent. |
1792 * router_path The path of the relevant router item. | 1790 * - router_path The path of the relevant router item. |
1793 */ | 1791 */ |
1794 function menu_link_save(&$item) { | 1792 function menu_link_save(&$item) { |
1795 $menu = menu_router_build(); | 1793 $menu = menu_router_build(); |
1796 | 1794 |
1797 drupal_alter('menu_link', $item, $menu); | 1795 drupal_alter('menu_link', $item, $menu); |