From ff6f2152bb6f0a759bffbcc213a82aecc0237ae6 Mon Sep 17 00:00:00 2001 From: brettp Date: Wed, 17 Mar 2010 19:09:09 +0000 Subject: Added config options for tabs and menu items. git-svn-id: http://code.elgg.org/elgg/trunk@5431 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 57 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) (limited to 'engine/lib/elgglib.php') diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 95292a2d7..5a7fca837 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -1453,11 +1453,12 @@ function get_register($register_name) { * @param string $menu_name The name of the menu item * @param string $menu_url The URL of the page * @param array $menu_children Optionally, an array of submenu items (not currently used) - * @param string $context (not used and will likely be deprecated) + * @param string $context * @return true|false Depending on success */ function add_menu($menu_name, $menu_url, $menu_children = array(), $context = "") { global $CONFIG; + if (!isset($CONFIG->menucontexts)) { $CONFIG->menucontexts = array(); } @@ -1466,8 +1467,12 @@ function add_menu($menu_name, $menu_url, $menu_children = array(), $context = "" $context = get_plugin_name(); } + $value = new stdClass(); + $value->url = $menu_url; + $value->context = $context; + $CONFIG->menucontexts[] = $context; - return add_to_register('menu', $menu_name, $menu_url, $menu_children); + return add_to_register('menu', $menu_name, $value, $menu_children); } /** @@ -2884,6 +2889,50 @@ function elgg_api_test($hook, $type, $value, $params) { return $value; } +/** + * Sorts out the topbar menu and the featured URLs + * and saves them to $CONFIG->menu_items = array ('featured_urls' and 'toolbar') + * + */ +function ui_page_setup() { + global $CONFIG; + + $hide_toolbar_dupes = get_config('menu_items_hide_toolbar_entries') == 'yes' ? TRUE : FALSE; + $menu_items = get_register('menu'); + $featured_urls_info = get_config('menu_items_featured_urls'); + $toolbar = array(); + $featured_urls = array(); + $featured_urls_sanitised = array(); + + // easier to compare with in_array() than embedded foreach()es + $valid_urls = array(); + foreach ($menu_items as $info) { + $valid_urls[] = $info->value->url; + } + + // make sure the url is a valid link. + // this prevents disabled plugins leaving behind + // valid links when no using a pagehandler. + foreach ($featured_urls_info as $info) { + if (in_array($info->value->url, $valid_urls)) { + $featured_urls[] = $info->value->url; + $featured_urls_sanitised[] = $info; + } + } + + // add toolbar entries if not hiding dupes. + foreach ($menu_items as $name => $info) { + if (!($hide_toolbar_dupes && in_array($info->value->url, $featured_urls))) { + $toolbar[] = $info; + } + } + + $CONFIG->menu_items = array( + 'featured_urls' => $featured_urls_sanitised, + 'toolbar' => $toolbar + ); +} + /** * Some useful constant definitions */ @@ -2898,4 +2947,6 @@ define('ELGG_ENTITIES_NO_VALUE', 0); register_elgg_event_handler('init', 'system', 'elgg_init'); register_elgg_event_handler('boot', 'system', 'elgg_boot', 1000); -register_plugin_hook('unit_test', 'system', 'elgg_api_test'); \ No newline at end of file +register_plugin_hook('unit_test', 'system', 'elgg_api_test'); + +register_elgg_event_handler('pagesetup', 'system', 'ui_page_setup', 1000); \ No newline at end of file -- cgit v1.2.3