From aa011b14603ba807121c811399685895a9c75d67 Mon Sep 17 00:00:00 2001 From: brettp Date: Sat, 8 May 2010 03:42:23 +0000 Subject: Added new submenu system. Added elgg_http_url_is_identical(). Moved canvas_header/submenu* to navigation/submenu*. Added UI test for submenu. git-svn-id: http://code.elgg.org/elgg/trunk@5982 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 477 ++++++++++++++++++----- engine/tests/ui/submenu.php | 97 +++++ views/default/canvas_header/submenu_group.php | 19 - views/default/canvas_header/submenu_template.php | 24 -- views/default/css.php | 10 +- views/default/navigation/submenu_group.php | 42 ++ views/default/navigation/submenu_item.php | 41 ++ views/default/navigation/submenu_js.php | 31 ++ 8 files changed, 595 insertions(+), 146 deletions(-) create mode 100644 engine/tests/ui/submenu.php delete mode 100644 views/default/canvas_header/submenu_group.php delete mode 100644 views/default/canvas_header/submenu_template.php create mode 100644 views/default/navigation/submenu_group.php create mode 100644 views/default/navigation/submenu_item.php create mode 100644 views/default/navigation/submenu_js.php diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 1f51d7cb2..16ace68be 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -249,10 +249,10 @@ function elgg_view($view, $vars = array(), $bypass = false, $debug = false, $vie $viewtype = elgg_get_viewtype(); } - // Viewtypes can only be alphanumeric + // Viewtypes can only be alphanumeric if (preg_match('[\W]', $viewtype)) { - return ''; - } + return ''; + } // Set up any extensions to the requested view if (isset($CONFIG->views->extensions[$view])) { @@ -757,7 +757,7 @@ function elgg_view_annotation(ElggAnnotation $annotation, $bypass = true, $debug function elgg_view_entity_list($entities, $count, $offset, $limit, $fullview = true, $viewtypetoggle = true, $pagination = true) { $count = (int) $count; $limit = (int) $limit; - + // do not require views to explicitly pass in the offset if (!$offset = (int) $offset) { $offset = sanitise_int(get_input('offset', 0)); @@ -900,131 +900,317 @@ function elgg_view_title($title, $submenu = false) { } /** - * Adds an item to the submenu + * Deprecated by elgg_add_submenu_item() + * + * @see elgg_add_submenu_item() + * @deprecated 1.8 + */ +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); + + $item = array( + 'text' => $label, + 'url' => $link, + 'selected' => $selected + ); + + if (!$group) { + $group = 'default'; + } + + if ($onclick) { + $js = "onclick=\"javascript:return confirm('". elgg_echo('deleteconfirm') . "')\""; + $item['vars'] = array('js' => $js); + } + // submenu items were added in the page setup hook usually by checking + // the context. We'll pass in the current context here, which will + // emulate that effect. + // if context == 'main' (default) it probably means they always wanted + // the menu item to show up everywhere. + $context = get_context(); + + if ($context == 'main') { + $context = 'all'; + } + return elgg_add_submenu_item($item, $context, $group); +} + +/** + * Add an entry to the submenu. + * + * @param array $item The item as 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 + * ) * - * @param string $label The human-readable label - * @param string $link The URL of the submenu item - * @param boolean $onclick Used to provide a JS popup to confirm delete - * @param mixed $selected BOOL to force on/off, NULL to allow auto selection + * @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 "; - echo $submenu; -} \ No newline at end of file diff --git a/views/default/canvas_header/submenu_template.php b/views/default/canvas_header/submenu_template.php deleted file mode 100644 index 0210e865f..000000000 --- a/views/default/canvas_header/submenu_template.php +++ /dev/null @@ -1,24 +0,0 @@ - -
  • >>
  • \ No newline at end of file diff --git a/views/default/css.php b/views/default/css.php index b81945eb4..bdef42982 100644 --- a/views/default/css.php +++ b/views/default/css.php @@ -684,6 +684,11 @@ li.navigation_more ul li { color:white; text-decoration:none; } +.submenu .child li a{ + margin-left:15px; + background-color:white; + color:#4690D6; +} @@ -1630,11 +1635,6 @@ form.admin_plugins_simpleview .submit_button { .admin_settings.menuitems li.custom_menuitem { margin-bottom:20px; } -.admin .child_submenu li a{ - margin-left: 15px; - background-color: white; - color: #4690D6; -} .admin_notices { padding-bottom: 15px; } diff --git a/views/default/navigation/submenu_group.php b/views/default/navigation/submenu_group.php new file mode 100644 index 000000000..08e417494 --- /dev/null +++ b/views/default/navigation/submenu_group.php @@ -0,0 +1,42 @@ + for a submenu and passes items one by one + * to navigation/submenu_item + * + * @uses $vars['group_name'] + * @uses $vars['items'] + * @package Elgg + * @subpackage Core + * @author Curverider Ltd + * @link http://elgg.org/ + */ + +$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 "\n"; \ No newline at end of file diff --git a/views/default/navigation/submenu_item.php b/views/default/navigation/submenu_item.php new file mode 100644 index 000000000..c64f8a679 --- /dev/null +++ b/views/default/navigation/submenu_item.php @@ -0,0 +1,41 @@ + part of a submenu. + * + * @uses $vars['group'] + * @uses $vars['item'] + * @uses $vars['children_html'] + * @package Elgg + * @subpackage Core + * @author Curverider Ltd + * @link http://elgg.org/ + */ + +$group = (isset($vars['group'])) ? $vars['group'] : 'default'; +$item = (isset($vars['item'])) ? $vars['item'] : FALSE; +$children_html = (isset($vars['children_html'])) ? $vars['children_html'] : FALSE; + + +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 = '-'; + $child_indicator .= ''; + } else { + $child_indicator = ''; + $child_indicator .= '+'; + } + + $child_indicator = "$child_indicator "; + } + + $url = htmlentities($item->url); + $text = $child_indicator . htmlentities($item->text); +} +?> +
  • >>
  • diff --git a/views/default/navigation/submenu_js.php b/views/default/navigation/submenu_js.php new file mode 100644 index 000000000..0f0c88888 --- /dev/null +++ b/views/default/navigation/submenu_js.php @@ -0,0 +1,31 @@ + + + \ No newline at end of file -- cgit v1.2.3