diff options
-rw-r--r-- | engine/lib/elgglib.php | 10 | ||||
-rw-r--r-- | engine/lib/navigation.php | 532 | ||||
-rw-r--r-- | engine/tests/ui/submenu.php | 6 | ||||
-rw-r--r-- | views/default/layout/elements/sidebar.php | 1 | ||||
-rw-r--r-- | views/default/layout/elements/title.php | 13 | ||||
-rw-r--r-- | views/default/navigation/sidebar_menu.php | 13 | ||||
-rw-r--r-- | views/default/navigation/submenu_group.php | 40 | ||||
-rw-r--r-- | views/default/navigation/submenu_item.php | 46 | ||||
-rw-r--r-- | views/default/navigation/submenu_js.php | 29 |
9 files changed, 78 insertions, 612 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index f925429de..e8d47eaca 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -476,11 +476,11 @@ function sanitise_filepath($path, $append_slash = TRUE) { * @param array $children_array Optionally, an array of children * * @return true|false Depending on success - * @todo Can be deprecated when the new menu system is introduced. + * @deprecated 1.8 */ function add_to_register($register_name, $subregister_name, $subregister_value, $children_array = array()) { - + elgg_deprecated_notice("add_to_register() has been deprecated", 1.8); global $CONFIG; if (empty($register_name) || empty($subregister_name)) { @@ -517,9 +517,10 @@ $children_array = array()) { * * @return true|false Depending on success * @since 1.7.0 - * @todo Can be deprecated when the new menu system is introduced. + * @deprecated 1.8 */ function remove_from_register($register_name, $subregister_name) { + elgg_deprecated_notice("remove_from_register() has been deprecated", 1.8); global $CONFIG; if (empty($register_name) || empty($subregister_name)) { @@ -572,9 +573,10 @@ function make_register_object($register_name, $register_value, $children_array = * @param string $register_name The name of the register * * @return array|false Depending on success - * @todo Can be deprecated when the new menu system is introduced. + * @deprecated 1.8 */ function get_register($register_name) { + elgg_deprecated_notice("get_register() has been deprecated", 1.8); global $CONFIG; if (isset($CONFIG->registers[$register_name])) { diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php index a6554fd99..155392645 100644 --- a/engine/lib/navigation.php +++ b/engine/lib/navigation.php @@ -72,9 +72,61 @@ function elgg_unregister_menu_item($menu_name, $item_name) { } /** - * Deprecated by elgg_add_submenu_item() + * Adds a breadcrumb to the breadcrumbs stack. + * + * @param string $title The title to display + * @param string $link Optional. The link for the title. + * + * @return void + * @since 1.8.0 + * + * @link http://docs.elgg.org/Tutorials/UI/Breadcrumbs + */ +function elgg_push_breadcrumb($title, $link = NULL) { + global $CONFIG; + if (!is_array($CONFIG->breadcrumbs)) { + $CONFIG->breadcrumbs = array(); + } + + // avoid key collisions. + $CONFIG->breadcrumbs[] = array('title' => $title, 'link' => $link); +} + +/** + * Removes last breadcrumb entry. + * + * @return array popped item. + * @since 1.8.0 + * @link http://docs.elgg.org/Tutorials/UI/Breadcrumbs + */ +function elgg_pop_breadcrumb() { + global $CONFIG; + + if (is_array($CONFIG->breadcrumbs)) { + array_pop($CONFIG->breadcrumbs); + } + + return FALSE; +} + +/** + * Returns all breadcrumbs as an array of array('title' => 'Readable Title', 'link' => 'URL') * - * @see elgg_add_submenu_item() + * @return array Breadcrumbs + * @since 1.8.0 + * @link http://docs.elgg.org/Tutorials/UI/Breadcrumbs + */ +function elgg_get_breadcrumbs() { + global $CONFIG; + + return (is_array($CONFIG->breadcrumbs)) ? $CONFIG->breadcrumbs : array(); +} + + +/** + * Deprecated by elgg_register_menu_item(). Set $menu_name to 'page'. + * + * @see elgg_register_menu_item() * @deprecated 1.8 * * @param string $label The label @@ -86,7 +138,7 @@ function elgg_unregister_menu_item($menu_name, $item_name) { * @return bool */ function add_submenu_item($label, $link, $group = 'default', $onclick = false, $selected = NULL) { - elgg_deprecated_notice('add_submenu_item was deprecated by elgg_add_submenu_item', 1.8); + elgg_deprecated_notice('add_submenu_item was deprecated by elgg_register_menu_item', 1.8); // submenu items were added in the page setup hook usually by checking // the context. We'll pass in the current context here, which will @@ -117,364 +169,22 @@ function add_submenu_item($label, $link, $group = 'default', $onclick = false, $ } return elgg_register_menu_item('page', $item); -/* - $item = array( - 'text' => $label, - 'href' => $link, - 'selected' => $selected - ); - - return elgg_add_submenu_item($item, $context, $group); - * - */ -} - -/** - * Add an entry to the submenu. - * - * @param array $item The item as: - * <code> - * array( - * 'title' => 'Text to display', - * 'url' => 'URL of the link', - * 'id' => 'entry_unique_id' //used by children items to identify parents - * 'parent_id' => 'id_of_parent', - * 'selected' => BOOL // Is this item selected? (If NULL or unset will attempt to guess) - * 'vars' => array() // Array of vars to pass to the navigation/submenu_item view - * ) - * </code> - * - * @param string $context Context in which to display this menu item. 'all' - * will make it show up all the time. Use sparingly. - * @param string $group Group for the item. Each submenu group has its own <ul> - * - * @return BOOL - * @since 1.8 - * @see elgg_prepare_submenu - */ -function elgg_add_submenu_item(array $item, $context = 'all', $group = 'default') { - global $CONFIG; - - if (!isset($CONFIG->submenu_items)) { - $CONFIG->submenu_items = array(); - } - - if (!isset($CONFIG->submenu_items[$context])) { - $CONFIG->submenu_items[$context] = array(); - } - - if (!isset($CONFIG->submenu_items[$context][$group])) { - $CONFIG->submenu_items[$context][$group] = array(); - } - - if (!isset($item['text'])) { - return FALSE; - } - - if (!empty($item['href'])) { - $item['href'] = elgg_normalize_url($item['href']); - } - - // we use persistent object properties in the submenu - // setup function, so normalize the array to an object. - // we pass it in as an array because this would be the only - // place in elgg that we ask for an object like this. - // consistency ftw. - $item_obj = new StdClass(); - - foreach ($item as $k => $v) { - switch ($k) { - case 'parent_id': - case 'id': - // make sure '' and false make sense - $v = (empty($v)) ? NULL : $v; - - default: - $item_obj->$k = $v; - break; - } - } - - $CONFIG->submenu_items[$context][$group][] = $item_obj; - - return TRUE; -} - -/** - * Properly nest all submenu entries for contexts $context and 'all' - * - * @param string $context Context for menus - * @param bool $sort Sort the menu items alphabetically - * - * @since 1.8 - * @see elgg_add_submenu_item - * - * @return true - */ -function elgg_prepare_submenu($context = 'main', $sort = FALSE) { - global $CONFIG; - - if (!isset($CONFIG->submenu_items) || !($CONFIG->submenu_items)) { - return FALSE; - } - - $groups = array(); - - if (isset($CONFIG->submenu_items['all'])) { - $groups = $CONFIG->submenu_items['all']; - } - - if (isset($CONFIG->submenu_items[$context])) { - $groups = array_merge_recursive($groups, $CONFIG->submenu_items[$context]); - } - - if (!$groups) { - return FALSE; - } - - foreach ($groups as $group => $items) { - if ($sort) { - usort($items, 'elgg_submenu_item_cmp'); - } - - $parsed_menu = array(); - // determin which children need to go in this item. - foreach ($items as $i => $item) { - // can only support children if there's an id - if (isset($item->id)) { - foreach ($items as $child_i => $child_item) { - // don't check ourselves or used children. - if ($child_i == $i || $child_item->used == TRUE) { - continue; - } - - if (isset($child_item->parent_id) && $child_item->parent_id == $item->id) { - if (!isset($item->children)) { - $item->children = array(); - } - $item->children[] = $child_item; - $child_item->parent = $item; - // don't unset because we still need to check this item for children - $child_item->used = TRUE; - } - } - - // if the parent doesn't have a url, make it the first child item. - if (isset($item->children) && $item->children && !$item->href) { - $child = $item->children[0]; - while ($child && !isset($child->href)) { - if (isset($child->children) && isset($child->children[0])) { - $child = $child->children[0]; - } else { - $child = NULL; - } - } - - if ($child && isset($child->href)) { - $item->href = $child->href; - } else { - // @todo There are no URLs anywhere in this tree. - $item->href = elgg_get_site_url(); - } - } - } - - // only add top-level elements to the menu. - // the rest are children. - if (!isset($item->parent_id)) { - $parsed_menu[] = $item; - } - } - - $CONFIG->submenu[$context][$group] = $parsed_menu; - } - - return TRUE; -} - -/** - * Helper function used to sort submenu items by their display text. - * - * @param object $a First object - * @param object $b Second object - * - * @return int - * @since 1.8 - * @see elgg_prepare_submenu - */ -function elgg_submenu_item_cmp($a, $b) { - $a = $a->text; - $b = $b->text; - - return strnatcmp($a, $b); } /** - * Use elgg_get_submenu(). + * Use elgg_view_menu(). Set $menu_name to 'owner_block'. * - * @see elgg_get_submenu() + * @see elgg_view_menu() * @deprecated 1.8 * * @return string */ function get_submenu() { - elgg_deprecated_notice("get_submenu() has been deprecated by elgg_get_submenu()", 1.8); - return elgg_get_submenu(); -} - -/** - * Return the HTML for a sidemenu. - * - * @param string $context The context of the submenu (defaults to main) - * @param BOOL $sort Sort by display name? - * - * @return string Formatted HTML. - * @since 1.8 - * @todo Rename to a view function. See {@trac #2320}. - */ -function elgg_get_submenu($context = NULL, $sort = FALSE) { - global $CONFIG; - - if (!$context) { - $context = elgg_get_context(); - } - - if (!elgg_prepare_submenu($context, $sort)) { - return ''; - } - - $groups = $CONFIG->submenu[$context]; - $submenu_html = ''; - - foreach ($groups as $group => $items) { - // how far down we are in children arrays - $depth = 0; - // push and pop parent items - $temp_items = array(); - - while ($item = current($items)) { - // ignore parents created by a child but parent never defined properly - if (!isset($item->text) || !($item->text)) { - next($items); - continue; - } - - // try to guess if this should be selected if they don't specify - if ((!isset($item->selected) || $item->selected === NULL) && isset($item->href)) { - $item->selected = elgg_http_url_is_identical(full_url(), $item->href); - } - - // traverse up the parent tree if matached to mark all parents as selected/expanded. - if ($item->selected && isset($item->parent)) { - $parent = $item->parent; - while ($parent) { - $parent->selected = TRUE; - if (isset($parent->parent)) { - $parent = $parent->parent; - } else { - $parent = NULL; - } - } - } - - // get the next item - if (isset($item->children) && $item->children) { - $depth++; - array_push($temp_items, $items); - $items = $item->children; - } elseif ($depth > 0) { - // check if there are more children elements in the current items - // pop back up to the parent(s) if not - if ($item = next($items)) { - continue; - } else { - while ($depth > 0) { - $depth--; - $items = array_pop($temp_items); - if ($item = next($items)) { - break; - } - } - } - } else { - next($items); - } - } - - $vars = array('group' => $group, 'items' => $items); - $submenu_html .= elgg_view('navigation/submenu_group', $vars); - } - - // include the JS for the expand menus too - return elgg_view('navigation/submenu_js') . $submenu_html; -} - -/** - * Registers any custom menu items with the main Site Menu. - * - * @note Custom menu items are added through the admin interface. Plugins - * can add standard menu items by using {@link add_menu()}. - * - * @since 1.8 - * @link http://docs.elgg.org/Tutorials/UI/SiteMenu - * @elgg_event_handler init system - * @return void - */ -function add_custom_menu_items() { - if ($custom_items = get_config('menu_items_custom_items')) { - foreach ($custom_items as $url => $name) { - add_menu($name, $url); - } - } -} - -/** - * Returns the main site menu. - * - * @note The main site menu is split into "featured" links and - * "more" links. - * - * @return array ('featured_urls' and 'more') - * @since 1.8 - * @link http://docs.elgg.org/Tutorials/UI/SiteMenu - */ -function elgg_get_nav_items() { - $menu_items = get_register('menu'); - $featured_urls_info = get_config('menu_items_featured_urls'); - - $more = 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 not using a pagehandler. - if ($featured_urls_info) { - 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 (!in_array($info->value->url, $featured_urls)) { - $more[] = $info; - } - } - - return array( - 'featured' => $featured_urls_sanitised, - 'more' => $more - ); + elgg_deprecated_notice("get_submenu() has been deprecated by elgg_view_menu()", 1.8); + return elgg_view_menu('owner_block', array( + 'entity' => $owner, + 'class' => 'elgg-owner-block-menu', + )); } /** @@ -506,9 +216,11 @@ function add_menu($menu_name, $menu_url, $menu_children = array(), $context = "" * @param string $menu_name The name of the menu item * * @return true|false Depending on success + * @deprecated 1.8 */ function remove_menu($menu_name) { - return remove_from_register('menu', $menu_name); + elgg_deprecated_notice("remove_menu() deprecated by elgg_unregister_menu_item()", 1.8); + return elgg_unregister_menu_item('site', $menu_name); } /** @@ -519,121 +231,9 @@ function remove_menu($menu_name) { * @param string $menu_url Its URL * * @return stdClass|false Depending on success - * @todo Can be deprecated when the new menu system is introduced. + * @deprecated 1.7 */ function menu_item($menu_name, $menu_url) { elgg_deprecated_notice('menu_item() is deprecated by add_submenu_item', 1.7); return make_register_object($menu_name, $menu_url); } - -/** - * Adds a breadcrumb to the breadcrumbs stack. - * - * @param string $title The title to display - * @param string $link Optional. The link for the title. - * - * @return void - * - * @link http://docs.elgg.org/Tutorials/UI/Breadcrumbs - */ -function elgg_push_breadcrumb($title, $link = NULL) { - global $CONFIG; - if (!is_array($CONFIG->breadcrumbs)) { - $CONFIG->breadcrumbs = array(); - } - - // avoid key collisions. - $CONFIG->breadcrumbs[] = array('title' => $title, 'link' => $link); -} - -/** - * Removes last breadcrumb entry. - * - * @return array popped item. - * @link http://docs.elgg.org/Tutorials/UI/Breadcrumbs - */ -function elgg_pop_breadcrumb() { - global $CONFIG; - - if (is_array($CONFIG->breadcrumbs)) { - array_pop($CONFIG->breadcrumbs); - } - - return FALSE; -} - -/** - * Returns all breadcrumbs as an array of array('title' => 'Readable Title', 'link' => 'URL') - * - * @return array Breadcrumbs - * @link http://docs.elgg.org/Tutorials/UI/Breadcrumbs - */ -function elgg_get_breadcrumbs() { - global $CONFIG; - - 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/tests/ui/submenu.php b/engine/tests/ui/submenu.php index d5d188194..7fb000c4d 100644 --- a/engine/tests/ui/submenu.php +++ b/engine/tests/ui/submenu.php @@ -13,6 +13,10 @@ * */ +/* + * Tests need to be ported to new menu system + * + require_once('../../start.php'); $url = "engine/tests/ui/submenu.php"; @@ -95,3 +99,5 @@ elgg_add_submenu_item(array('text' => 'All test', 'href' => "$url?all"), 'all'); $body = elgg_view_layout('one_column_with_sidebar', array('content' => 'Look right.')); echo elgg_view_page('Submenu Test', $body); + +*/
\ No newline at end of file diff --git a/views/default/layout/elements/sidebar.php b/views/default/layout/elements/sidebar.php index 93dd659f5..9a8a08723 100644 --- a/views/default/layout/elements/sidebar.php +++ b/views/default/layout/elements/sidebar.php @@ -9,7 +9,6 @@ echo elgg_view('layout/elements/page_links', $vars); echo elgg_view('layout/elements/owner_block', $vars); -echo elgg_view('navigation/sidebar_menu'); echo elgg_view_menu('page', array('sort_by' => 'name')); // optional 'sidebar' parameter diff --git a/views/default/layout/elements/title.php b/views/default/layout/elements/title.php index c5eeb9e0e..5354352c9 100644 --- a/views/default/layout/elements/title.php +++ b/views/default/layout/elements/title.php @@ -4,19 +4,6 @@ * @uses $vars['title'] The page title */ -$page_owner = elgg_get_page_owner_guid(); -$page_owner_entity = get_entity($page_owner); - $display = "<h2>" . $vars['title'] . "</h2>"; -$submenu = elgg_get_submenu(); -if (!empty($submenu)) { - $submenu = "<ul class='submenu extended'>" . $submenu . "</ul>"; -} - -if (!empty($submenu) && $vars['submenu'] == true) { - // plugins can extend this to add menu options - $display .= $submenu; -} - echo $display;
\ No newline at end of file diff --git a/views/default/navigation/sidebar_menu.php b/views/default/navigation/sidebar_menu.php deleted file mode 100644 index 75fe7c743..000000000 --- a/views/default/navigation/sidebar_menu.php +++ /dev/null @@ -1,13 +0,0 @@ -<?php -/** - * Elgg sidebar menu - * - * @package Elgg - * @subpackage Core - * - */ - -// Plugins can add to the sidebar menu by calling elgg_add_submenu_item() -$submenu = elgg_get_submenu(); - -echo $submenu; diff --git a/views/default/navigation/submenu_group.php b/views/default/navigation/submenu_group.php deleted file mode 100644 index df750aff7..000000000 --- a/views/default/navigation/submenu_group.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php -/** - * Elgg submenu group. Writes the <ul> for a submenu and passes items one by one - * to navigation/submenu_item - * - * @uses $vars['group_name'] - * @uses $vars['items'] - * @package Elgg - * @subpackage Core - */ - -$group = (isset($vars['group'])) ? $vars['group'] : 'default'; -$items = (isset($vars['items'])) ? $vars['items'] : array(); -$hidden = (isset($vars['hidden']) && $vars['hidden']) ? 'hidden' : ''; -$child = (isset($vars['child']) && $vars['child']) ? 'child' : ''; - -echo "<ul class='submenu $group $hidden $child'>\n"; - -foreach ($items as $item) { - $item_vars = array('item' => $item, 'group' => $group); - if (isset($item->vars) && is_array($item->vars)) { - $item_vars = array_merge($item->vars, $item_vars); - } - - if (isset($item->children)) { - $child_vars = array( - 'group' => $group, - 'items' => $item->children, - // if this menu item is selected, make sure to display the full tree - // ie, don't hide it. - 'hidden' => !$item->selected, - 'child' => TRUE - ); - $item_vars['children_html'] = elgg_view('navigation/submenu_group', $child_vars); - } - - echo elgg_view('navigation/submenu_item', $item_vars); -} - -echo "</ul>\n";
\ No newline at end of file diff --git a/views/default/navigation/submenu_item.php b/views/default/navigation/submenu_item.php deleted file mode 100644 index 09aa24a8e..000000000 --- a/views/default/navigation/submenu_item.php +++ /dev/null @@ -1,46 +0,0 @@ -<?php -/** - * Elgg submenu item. Displays the <li> part of a submenu. - * - * @uses $vars['group'] - * @uses $vars['item'] - * @uses $vars['children_html'] - * @package Elgg - * @subpackage Core - */ - -$group = (isset($vars['group'])) ? $vars['group'] : 'default'; -$item = (isset($vars['item'])) ? $vars['item'] : FALSE; -$children_html = (isset($vars['children_html'])) ? $vars['children_html'] : ''; - -if ($item) { - $has_children = (isset($item->children) && $item->children) ? TRUE : FALSE; - $selected = (isset($item->selected) && $item->selected == TRUE) ? 'class="selected"' : ''; - $js = (isset($vars['js'])) ? $vars['js'] : ''; - - $child_indicator = ''; - if ($has_children) { - if ($selected) { - $child_indicator = '<span class="close_child">-</span>'; - $child_indicator .= '<span class="hidden open_child">+</span>'; - } else { - $child_indicator = '<span class="hidden close_child">-</span>'; - $child_indicator .= '<span class="open_child">+</span>'; - } - - $child_indicator = "<span class=\"child_indicator\">$child_indicator </span>"; - } - - $url = htmlentities($item->href); - $text = $child_indicator . htmlentities($item->text); - - $link_vars = array_merge($vars, array( - 'href' => $item->href, - 'text' => $text, - 'encode_text' => FALSE - )); - - $link = elgg_view('output/url', $link_vars); -} - -echo "<li $selected>$link$children_html</li>"; diff --git a/views/default/navigation/submenu_js.php b/views/default/navigation/submenu_js.php deleted file mode 100644 index 1ed710b2b..000000000 --- a/views/default/navigation/submenu_js.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php -/** - * Javascript to expand submenu items. - * - * @package Elgg - * @subpackage Core - */ -?> - -<script type="text/javascript"> -$(document).ready(function() { - $('.submenu span.child_indicator').click(function() { - var submenu = $(this).parent().parent().find('ul.submenu.child:first'); - var closeChild = $($(this).find('.close_child')); - var openChild = $($(this).find('.open_child')); - - if (submenu.is(':visible')) { - closeChild.addClass('hidden'); - openChild.removeClass('hidden'); - } else { - closeChild.removeClass('hidden'); - openChild.addClass('hidden'); - } - - submenu.slideToggle(); - return false; - }); -}); -</script>
\ No newline at end of file |