diff options
author | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-12-18 16:37:16 +0000 |
---|---|---|
committer | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-12-18 16:37:16 +0000 |
commit | 8ec093ecc1bf28c09f5d2dbe3c7bc8e6a2485ac6 (patch) | |
tree | 2b0c0454d9305cd61b92f57d02be06deccaf5d9b | |
parent | fc0fb6ec66aca4e439f434ce0d97df6d09388ef4 (diff) | |
download | elgg-8ec093ecc1bf28c09f5d2dbe3c7bc8e6a2485ac6.tar.gz elgg-8ec093ecc1bf28c09f5d2dbe3c7bc8e6a2485ac6.tar.bz2 |
site nav menu now uses new menu code (and finished the implementation of custom menu items while I was at it - not backward compatible with the previous half finished version)
git-svn-id: http://code.elgg.org/elgg/trunk@7668 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | actions/admin/menu/save.php | 35 | ||||
-rw-r--r-- | actions/admin/menu_items.php | 50 | ||||
-rw-r--r-- | engine/classes/ElggMenuItem.php | 2 | ||||
-rw-r--r-- | engine/lib/admin.php | 2 | ||||
-rw-r--r-- | engine/lib/navigation.php | 64 | ||||
-rw-r--r-- | engine/lib/river.php | 3 | ||||
-rw-r--r-- | engine/lib/users.php | 3 | ||||
-rw-r--r-- | mod/blog/start.php | 3 | ||||
-rw-r--r-- | mod/bookmarks/start.php | 3 | ||||
-rw-r--r-- | mod/file/start.php | 3 | ||||
-rw-r--r-- | mod/groups/start.php | 3 | ||||
-rw-r--r-- | mod/pages/start.php | 3 | ||||
-rw-r--r-- | mod/riverdashboard/start.php | 1 | ||||
-rw-r--r-- | mod/thewire/start.php | 5 | ||||
-rw-r--r-- | views/default/admin/appearance/menu_items.php | 43 | ||||
-rw-r--r-- | views/default/navigation/menu/elements/item.php | 10 | ||||
-rw-r--r-- | views/default/navigation/menu/site.php | 25 | ||||
-rw-r--r-- | views/default/navigation/site_nav.php | 83 | ||||
-rw-r--r-- | views/default/page/elements/header.php | 2 |
19 files changed, 175 insertions, 168 deletions
diff --git a/actions/admin/menu/save.php b/actions/admin/menu/save.php new file mode 100644 index 000000000..3fdce8c45 --- /dev/null +++ b/actions/admin/menu/save.php @@ -0,0 +1,35 @@ +<?php +/** + * Save menu items. + * + * @package Elgg + * @subpackage Core + */ + +// featured menu items +$featured_names = get_input('featured_menu_names', array()); +$featured_names = array_unique($featured_names); +if (in_array('', $featured_names)) { + unset($featured_names[array_search('', $featured_names)]); +} +elgg_save_config('site_featured_menu_names', $featured_names); + + +// custom menu items +$custom_menu_titles = get_input('custom_menu_titles', array()); +$custom_menu_urls = get_input('custom_menu_urls', array()); +$num_menu_items = count($custom_menu_titles); +$custom_menu_items = array(); +for ($i = 0; $i < $num_menu_items; $i++) { + if (trim($custom_menu_urls[$i]) && trim($custom_menu_titles[$i])) { + $url = $custom_menu_urls[$i]; + $title = $custom_menu_titles[$i]; + $custom_menu_items[$title] = $url; + } +} +elgg_save_config('site_custom_menu_items', $custom_menu_items); + + +system_message(elgg_echo('admin:menu_items:saved')); + +forward(REFERER); diff --git a/actions/admin/menu_items.php b/actions/admin/menu_items.php deleted file mode 100644 index c9efb8bee..000000000 --- a/actions/admin/menu_items.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php -/** - * Save menu items. - * - * @package Elgg - * @subpackage Core - */ - -$featured_urls = get_input('featured_urls', array()); -$custom_item_names = get_input('custom_item_names', array()); -$custom_item_urls = get_input('custom_item_urls', array()); - -// save the full information from the menu item into the config table -// this will be checked upon display that it is still valid (based upon url) -$menu_items = get_register('menu'); -$menu_urls = array(); -$featured_url_info = array(); - -foreach ($menu_items as $name => $info) { - $menu_urls[$info->value->url] = $info; -} - -foreach ($featured_urls as $url) { - if (array_key_exists($url, $menu_urls)) { - $featured_url_info[] = $menu_urls[$url]; - } -} - -// save the custom items -$custom_count = count($custom_item_names); -$custom_items = array(); -for ($i = 0; $i < $custom_count; $i++) { - if (isset($custom_item_names[$i]) && isset($custom_item_names[$i])) { - $name = $custom_item_names[$i]; - $url = $custom_item_urls[$i]; - - if ($name && $url) { - $custom_items[$url] = $name; - } - } -} - - -// set_config() always returns 0 so can't check for failures -set_config('menu_items_featured_urls', $featured_url_info); -set_config('menu_items_custom_items', $custom_items); - -system_message(elgg_echo('admin:menu_items:saved')); - -forward(REFERER); diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php index 97dabe62a..af7bbc9c2 100644 --- a/engine/classes/ElggMenuItem.php +++ b/engine/classes/ElggMenuItem.php @@ -68,7 +68,7 @@ class ElggMenuItem { public function __construct($name, $title, $url) { $this->name = $name; $this->title = $title; - $this->url = $url; + $this->url = elgg_normalize_url($url); } /** diff --git a/engine/lib/admin.php b/engine/lib/admin.php index aab4b3aea..a5f7e1f88 100644 --- a/engine/lib/admin.php +++ b/engine/lib/admin.php @@ -122,7 +122,7 @@ function admin_init() { elgg_register_action('admin/site/update_basic', '', 'admin'); elgg_register_action('admin/site/update_advanced', '', 'admin'); - elgg_register_action('admin/menu_items', '', 'admin'); + elgg_register_action('admin/menu/save', '', 'admin'); elgg_register_action('admin/plugins/simple_update_states', '', 'admin'); diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php index 7b8c32f02..ed19976cd 100644 --- a/engine/lib/navigation.php +++ b/engine/lib/navigation.php @@ -568,3 +568,67 @@ function elgg_get_breadcrumbs() { return (is_array($CONFIG->breadcrumbs)) ? $CONFIG->breadcrumbs : array(); } + +/** + * Set up the site menu + * + * Handles default, featured, and custom menu items + * + * @param string $hook + * @param string $type + * @param array $return Menu array + * @param array $params + * @return array + */ +function elgg_site_menu_setup($hook, $type, $return, $params) { + + $featured_menu_names = elgg_get_config('site_featured_menu_names'); + $custom_menu_items = elgg_get_config('site_custom_menu_items'); + if ($featured_menu_names || $custom_menu_items) { + // we have featured or custom menu items + + $registered = $return['default']; + + // set up featured menu items + $featured = array(); + foreach ($featured_menu_names as $name) { + foreach ($registered as $index => $item) { + if ($item->getName() == $name) { + $featured[] = $item; + unset($registered[$index]); + } + } + } + + // add custom menu items + $n = 1; + foreach ($custom_menu_items as $title => $url) { + $item = new ElggMenuItem("custom$n", $title, $url); + $featured[] = $item; + $n++; + } + + $return['default'] = $featured; + $return['more'] = $registered; + } else { + // no featured menu items set + $max_display_items = 5; + + // the first n are shown, rest added to more list + $num_menu_items = count($return['default']); + if ($num_menu_items > $max_display_items) { + $return['more'] = array_splice($return['default'], $max_display_items); + } + } + + return $return; +} + +/** + * Navigation initialization + */ +function elgg_nav_init() { + elgg_register_plugin_hook_handler('prepare', 'menu:site', 'elgg_site_menu_setup'); +} + +elgg_register_event_handler('init', 'system', 'elgg_nav_init');
\ No newline at end of file diff --git a/engine/lib/river.php b/engine/lib/river.php index 46f11da46..459d351c1 100644 --- a/engine/lib/river.php +++ b/engine/lib/river.php @@ -806,7 +806,8 @@ function elgg_river_page_handler($page) { */ function elgg_river_init() { register_page_handler('activity', 'elgg_river_page_handler'); - add_menu(elgg_echo('activity'), "pg/activity/"); + $item = new ElggMenuItem('activity', elgg_echo('activity'), 'pg/activity'); + elgg_register_menu_item('site', $item); } elgg_register_event_handler('init', 'system', 'elgg_river_init'); diff --git a/engine/lib/users.php b/engine/lib/users.php index 4e34586a3..d22e42ebf 100644 --- a/engine/lib/users.php +++ b/engine/lib/users.php @@ -1526,7 +1526,8 @@ function users_init() { register_page_handler('members', 'elgg_members_page_handler'); //register_page_handler('collections', 'collections_page_handler'); - add_menu(elgg_echo('members'), 'pg/members/'); + $item = new ElggMenuItem('members', elgg_echo('members'), 'pg/members'); + elgg_register_menu_item('site', $item); elgg_register_action("register", '', 'public'); elgg_register_action("useradd", '', 'public'); diff --git a/mod/blog/start.php b/mod/blog/start.php index 374fe22d2..fb9e7d6ef 100644 --- a/mod/blog/start.php +++ b/mod/blog/start.php @@ -22,7 +22,8 @@ function blog_init() { elgg_register_library('elgg:blog', elgg_get_plugin_path() . 'blog/lib/blog.php'); - add_menu(elgg_echo('blog:blogs'), "pg/blog/all/", array()); + $item = new ElggMenuItem('blog', elgg_echo('blog:blogs'), 'pg/blog/all'); + elgg_register_menu_item('site', $item); // run the setup upon activations or to upgrade old installations. run_function_once('blog_runonce', '1269370108'); diff --git a/mod/bookmarks/start.php b/mod/bookmarks/start.php index 8e33991c9..30272bb69 100644 --- a/mod/bookmarks/start.php +++ b/mod/bookmarks/start.php @@ -11,7 +11,8 @@ function bookmarks_init() { global $CONFIG; //add a tools menu option - add_menu(elgg_echo('bookmarks'), 'pg/bookmarks'); + $item = new ElggMenuItem('bookmarks', elgg_echo('bookmarks'), 'pg/bookmarks'); + elgg_register_menu_item('site', $item); // Register a page handler, so we can have nice URLs register_page_handler('bookmarks', 'bookmarks_page_handler'); diff --git a/mod/file/start.php b/mod/file/start.php index c939877f5..227a5c33c 100644 --- a/mod/file/start.php +++ b/mod/file/start.php @@ -28,7 +28,8 @@ global $CONFIG; // Set up menu (tools dropdown) - add_menu(elgg_echo('files'), "pg/file/"); + $item = new ElggMenuItem('file', elgg_echo('file'), 'pg/file'); + elgg_register_menu_item('site', $item); // Extend CSS elgg_extend_view('css/screen', 'file/css'); diff --git a/mod/groups/start.php b/mod/groups/start.php index 36a1964ba..aaaaa3f45 100644 --- a/mod/groups/start.php +++ b/mod/groups/start.php @@ -14,7 +14,8 @@ global $CONFIG; // Set up the menu - add_menu(elgg_echo('groups'), "pg/groups/world/"); + $item = new ElggMenuItem('groups', elgg_echo('groups'), 'pg/groups/world'); + elgg_register_menu_item('site', $item); // Register a page handler, so we can have nice URLs register_page_handler('groups','groups_page_handler'); diff --git a/mod/pages/start.php b/mod/pages/start.php index 1e0c5bdc2..e90c6db54 100644 --- a/mod/pages/start.php +++ b/mod/pages/start.php @@ -12,7 +12,8 @@ function pages_init() { global $CONFIG; - add_menu(elgg_echo('pages'), "mod/pages/world.php"); + $item = new ElggMenuItem('pages', elgg_echo('pages'), 'mod/pages/world.php'); + elgg_register_menu_item('site', $item); // Register a page handler, so we can have nice URLs register_page_handler('pages','pages_page_handler'); diff --git a/mod/riverdashboard/start.php b/mod/riverdashboard/start.php index cc0c4abac..6d1581873 100644 --- a/mod/riverdashboard/start.php +++ b/mod/riverdashboard/start.php @@ -11,7 +11,6 @@ function riverdashboard_init() { global $CONFIG; // Register and optionally replace the dashboard register_page_handler('dashboard', 'riverdashboard_page_handler'); - add_menu(elgg_echo('activity'), "pg/activity/"); // Page handler register_page_handler('activity', 'riverdashboard_page_handler'); diff --git a/mod/thewire/start.php b/mod/thewire/start.php index 3eb172360..abb0cb019 100644 --- a/mod/thewire/start.php +++ b/mod/thewire/start.php @@ -20,8 +20,9 @@ function thewire_init() { // Set up menu for logged in users - add_menu(elgg_echo('thewire:title'), "pg/thewire"); - + $item = new ElggMenuItem('thewire', elgg_echo('thewire:title'), 'pg/thewire'); + elgg_register_menu_item('site', $item); + // Extend system CSS with our own styles, which are defined in the thewire/css view elgg_extend_view('css/screen', 'thewire/css'); diff --git a/views/default/admin/appearance/menu_items.php b/views/default/admin/appearance/menu_items.php index 9bed69a06..7572d2e0c 100644 --- a/views/default/admin/appearance/menu_items.php +++ b/views/default/admin/appearance/menu_items.php @@ -6,18 +6,17 @@ * @subpackage Core */ -$menu_items = get_register('menu'); -$featured_urls = get_config('menu_items_featured_urls'); +$builder = new ElggMenuBuilder('site'); +$menu = $builder->getMenu('name'); +$menu_items = $menu['default']; -// get an alphabetical sort of the items + urls -foreach ($menu_items as $name => $info) { - $menu_sorted[$info->name] = $info->value->url; -} - -ksort($menu_sorted); +$featured_menu_names = elgg_get_config('site_featured_menu_names'); -$pulldown_values = array_flip($menu_sorted); -$pulldown_values[''] = elgg_echo('none'); +$dropdown_values = array(); +foreach ($menu_items as $item) { + $dropdown_values[$item->getName()] = $item->getTitle(); +} +$dropdown_values[''] = elgg_echo('none'); echo elgg_view_title(elgg_echo('admin:menu_items')); echo "<div class='admin_settings menuitems'><h3>".elgg_echo('admin:menu_items:configure')."</h3>"; @@ -26,15 +25,15 @@ $form_body = ''; // @todo Could probably make this number configurable for ($i=0; $i<6; $i++) { - if (array_key_exists($i, $featured_urls)) { - $current_value = $featured_urls[$i]->value->url; + if (array_key_exists($i, $featured_menu_names)) { + $current_value = $featured_menu_names[$i]; } else { $current_value = ''; } $form_body .= elgg_view('input/pulldown', array( - 'options_values' => $pulldown_values, - 'internalname' => 'featured_urls[]', + 'options_values' => $dropdown_values, + 'internalname' => 'featured_menu_names[]', 'value' => $current_value )); } @@ -43,7 +42,7 @@ for ($i=0; $i<6; $i++) { $form_body .= "<h3>".elgg_echo('admin:add_menu_item')."</h3>"; $form_body .= elgg_view('output/longtext', array('value' => elgg_echo("admin:add_menu_item:description"))); -$custom_items = get_config('menu_items_custom_items'); +$custom_items = elgg_get_config('site_custom_menu_items'); $name_str = elgg_echo('name'); $url_str = elgg_echo('admin:plugins:label:website'); @@ -51,14 +50,14 @@ $url_str = elgg_echo('admin:plugins:label:website'); $form_body .= '<ul class="custom_menuitems">'; if (is_array($custom_items)) { - foreach ($custom_items as $url => $name) { + foreach ($custom_items as $title => $url) { $name_input = elgg_view('input/text', array( - 'internalname' => 'custom_item_names[]', - 'value' => $name + 'internalname' => 'custom_menu_titles[]', + 'value' => $title )); $url_input = elgg_view('input/text', array( - 'internalname' => 'custom_item_urls[]', + 'internalname' => 'custom_menu_urls[]', 'value' => $url )); @@ -68,11 +67,11 @@ if (is_array($custom_items)) { $new = elgg_echo('new'); $name_input = elgg_view('input/text', array( - 'internalname' => 'custom_item_names[]', + 'internalname' => 'custom_menu_titles[]', )); $url_input = elgg_view('input/text', array( - 'internalname' => 'custom_item_urls[]', + 'internalname' => 'custom_menu_urls[]', )); $form_body .= "<li class='custom_menuitem'>$name_str: $name_input $url_str: $url_input</li> @@ -82,6 +81,6 @@ $form_body .= elgg_view('input/submit', array('value' => elgg_echo('save'))); echo elgg_view('input/form', array( 'body' => $form_body, - 'action' => "action/admin/menu_items" + 'action' => "action/admin/menu/save" )); echo "</div>";
\ No newline at end of file diff --git a/views/default/navigation/menu/elements/item.php b/views/default/navigation/menu/elements/item.php new file mode 100644 index 000000000..f6959b2f4 --- /dev/null +++ b/views/default/navigation/menu/elements/item.php @@ -0,0 +1,10 @@ +<?php + +$item = $vars['item']; + +$class = ''; +if ($item->getSelected()) { + $class = 'class="selected"'; +} + +echo "<li $class>{$item->getLink()}</li>"; diff --git a/views/default/navigation/menu/site.php b/views/default/navigation/menu/site.php new file mode 100644 index 000000000..c2b00fd72 --- /dev/null +++ b/views/default/navigation/menu/site.php @@ -0,0 +1,25 @@ +<?php +/** + * Site navigation menu + * + * @uses $vars['menu']['default'] + * @uses $vars['menu']['more'] + */ + +echo '<ul class="elgg-site-menu">'; +foreach ($vars['menu']['default'] as $menu_item) { + echo elgg_view('navigation/menu/elements/item', array('item' => $menu_item)); +} + +if (isset($vars['menu']['more'])) { + $more = elgg_echo('more'); + echo '<li class="elgg-more">'; + echo "<a class='subnav' title=\"$more\"><span class=\"elgg-icon elgg-icon-arrow-s\"></span>$more</a>"; + echo '<ul>'; + foreach ($vars['menu']['more'] as $menu_item) { + echo elgg_view('navigation/menu/elements/item', array('item' => $menu_item)); + } + echo '</ul>'; + echo '</li>'; +} +echo '</ul>'; diff --git a/views/default/navigation/site_nav.php b/views/default/navigation/site_nav.php deleted file mode 100644 index aaf596b93..000000000 --- a/views/default/navigation/site_nav.php +++ /dev/null @@ -1,83 +0,0 @@ -<?php -/** - * Site-wide navigation - * - */ - -$nav_items = elgg_get_nav_items(); -$featured = $nav_items['featured']; -$more = $nav_items['more']; - -$nav_html = ''; -$more_nav_html = ''; -$context = elgg_get_context(); - -// sort more links alphabetically -$more_sorted = array(); -foreach ($more as $info) { - $more_sorted[] = $info->name; -} - -// required because array multisort is case sensitive -$more_sorted_lower = array_map('elgg_strtolower', $more_sorted); -array_multisort($more_sorted_lower, $more); - -$item_count = 0; - -// if there are no featured items, display the standard tools in alphabetical order -if ($featured) { - foreach ($featured as $info) { - $selected = ($info->value->context == $context) ? 'class="selected"' : ''; - $title = htmlentities($info->name, ENT_QUOTES, 'UTF-8'); - $url = htmlentities($info->value->url, ENT_QUOTES, 'UTF-8'); - - $nav_html .= "<li $selected><a href=\"$url\" title=\"$title\"><span>$title</span></a></li>"; - } -} elseif ($more) { - for ($i=0; $i<5; $i++) { - if (!array_key_exists($i, $more)) { - break; - } - $info = $more[$i]; - - $selected = ($info->value->context == $context) ? 'class="selected"' : ''; - $title = htmlentities($info->name, ENT_QUOTES, 'UTF-8'); - $url = htmlentities($info->value->url, ENT_QUOTES, 'UTF-8'); - - $nav_html .= "<li $selected><a href=\"$url\" title=\"$title\">$title</a></li>"; - $more[$i]->used = TRUE; - $item_count++; - } -} - -// display the rest. -foreach ($more as $info) { - if ($info->used) { - continue; - } - $selected = ($info->value->context == $context) ? 'class="selected"' : ''; - $title = htmlentities($info->name, ENT_QUOTES, 'UTF-8'); - $url = htmlentities($info->value->url, ENT_QUOTES, 'UTF-8'); - - $more_nav_html .= "<li $selected><a href=\"$url\" title=\"$title\">$title</a></li>\n"; - $item_count++; -} - -if ($more_nav_html) { - $more = elgg_echo('more'); - $nav_html .= "<li class='elgg-more'><a class='subnav' title=\"$more\"><span class=\"elgg-icon elgg-icon-arrow-s\"></span>$more</a> - <ul> - $more_nav_html - </ul> - </li>"; -} - -// only display, if there are nav items to display -if ($nav_html) { - echo <<<___END - <ul class="elgg-site-menu"> - $nav_html - </ul> -___END; -} - diff --git a/views/default/page/elements/header.php b/views/default/page/elements/header.php index 0cedd33e2..125d80bfa 100644 --- a/views/default/page/elements/header.php +++ b/views/default/page/elements/header.php @@ -15,7 +15,7 @@ echo elgg_view('core/account/login_dropdown'); // insert site-wide navigation - echo elgg_view('navigation/site_nav'); + echo elgg_view_menu('site'); // insert a view which can be extended echo elgg_view('header/extend'); |