aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/navigation.php
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib/navigation.php')
-rw-r--r--engine/lib/navigation.php789
1 files changed, 334 insertions, 455 deletions
diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php
index 773e6f25b..ab9cc05e8 100644
--- a/engine/lib/navigation.php
+++ b/engine/lib/navigation.php
@@ -3,6 +3,45 @@
* Elgg navigation library
* Functions for managing menus and other navigational elements
*
+ * Breadcrumbs
+ * Elgg uses a breadcrumb stack. The page handlers (controllers in MVC terms)
+ * push the breadcrumb links onto the stack. @see elgg_push_breadcrumb()
+ *
+ *
+ * Pagination
+ * Automatically handled by Elgg when using elgg_list_entities* functions.
+ * @see elgg_list_entities()
+ *
+ *
+ * Tabs
+ * @see navigation/tabs view
+ *
+ *
+ * Menus
+ * Elgg uses a single interface to manage its menus. Menu items are added with
+ * {@link elgg_register_menu_item()}. This is generally used for menus that
+ * appear only once per page. For dynamic menus (such as the hover
+ * menu for user's avatar), a plugin hook is emitted when the menu is being
+ * created. The hook is 'register', 'menu:<menu_name>'. For more details on this,
+ * @see elgg_view_menu().
+ *
+ * Menus supported by the Elgg core
+ * Standard menus:
+ * site Site navigation shown on every page.
+ * page Page menu usually shown in a sidebar. Uses Elgg's context.
+ * topbar Topbar menu shown on every page. The default has two sections.
+ * footer Like the topbar but in the footer.
+ * extras Links about content on the page. The RSS link is added to this.
+ *
+ * Dynamic menus (also called just-in-time menus):
+ * user_hover Avatar hover menu. The user entity is passed as a parameter.
+ * entity The set of links shown in the summary of an entity.
+ * river Links shown on river items.
+ * owner_block Links shown for a user or group in their owner block.
+ * filter The tab filter for content (all, mine, friends)
+ * title The buttons shown next to a content title.
+ * long-text The links shown above the input/longtext view.
+ *
* @package Elgg.Core
* @subpackage Navigation
*/
@@ -10,19 +49,40 @@
/**
* Register an item for an Elgg menu
*
+ * @warning Generally you should not use this in response to the plugin hook:
+ * 'register', 'menu:<menu_name>'. If you do, you may end up with many incorrect
+ * links on a dynamic menu.
+ *
+ * @warning A menu item's name must be unique per menu. If more than one menu
+ * item with the same name are registered, the last menu item takes priority.
+ *
+ * @see elgg_view_menu() for the plugin hooks available for modifying a menu as
+ * it is being rendered.
+ *
* @param string $menu_name The name of the menu: site, page, userhover,
* userprofile, groupprofile, or any custom menu
* @param mixed $menu_item A ElggMenuItem object or an array of options in format:
* name => STR Menu item identifier (required)
- * title => STR Menu item title (required)
- * url => STR Menu item URL (required)
+ * text => STR Menu item display text (required)
+ * href => STR Menu item URL (required) (false for non-links.
+ * @warning If you disable the href the <a> tag will
+ * not appear, so the link_class will not apply. If you
+ * put <a> tags in manually through the 'text' option
+ * the default CSS selector .elgg-menu-$menu > li > a
+ * may affect formatting. Wrap in a <span> if it does.)
* contexts => ARR Page context strings
* section => STR Menu section identifier
- * tooltip => STR Menu item tooltip
+ * title => STR Menu item tooltip
* selected => BOOL Is this menu item currently selected
* parent_name => STR Identifier of the parent menu item
+ * link_class => STR A class or classes for the <a> tag
+ * item_class => STR A class or classes for the <li> tag
*
- * Custom options can be added as key value pairs.
+ * Additional options that the view output/url takes can be
+ * passed in the array. If the 'confirm' key is passed, the
+ * menu link uses the 'output/confirmlink' view. Custom
+ * options can be added by using the 'data' key with the
+ * value being an associative array.
*
* @return bool
* @since 1.8.0
@@ -35,13 +95,17 @@ function elgg_register_menu_item($menu_name, $menu_item) {
}
if (is_array($menu_item)) {
- $menu_item = ElggMenuItem::factory($menu_item);
- if (!$menu_item) {
+ $item = ElggMenuItem::factory($menu_item);
+ if (!$item) {
+ elgg_log("Unable to add menu item '{$menu_item['name']}' to '$menu_name' menu", 'WARNING');
+ elgg_log(print_r($menu_item, true), 'DEBUG');
return false;
}
+ } else {
+ $item = $menu_item;
}
- $CONFIG->menus[$menu_name][] = $menu_item;
+ $CONFIG->menus[$menu_name][] = $item;
return true;
}
@@ -62,7 +126,8 @@ function elgg_unregister_menu_item($menu_name, $item_name) {
}
foreach ($CONFIG->menus[$menu_name] as $index => $menu_object) {
- if ($menu_object->name == $item_name) {
+ /* @var ElggMenuItem $menu_object */
+ if ($menu_object->getName() == $item_name) {
unset($CONFIG->menus[$menu_name][$index]);
return true;
}
@@ -72,467 +137,67 @@ function elgg_unregister_menu_item($menu_name, $item_name) {
}
/**
- * Deprecated by elgg_add_submenu_item()
- *
- * @see elgg_add_submenu_item()
- * @deprecated 1.8
- *
- * @param string $label The label
- * @param string $link The link
- * @param string $group The group to store item in
- * @param boolean $onclick Add a confirmation when clicked?
- * @param boolean $selected Is menu item selected
+ * Check if a menu item has been registered
*
- * @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);
-
- // 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 = elgg_get_context();
-
- if ($context == 'main') {
- $context = 'all';
- }
-
- $item = array(
- 'name' => $label,
- 'title' => $label,
- 'url' => $link,
- 'context' => $context,
- 'section' => $group,
- );
-
- if ($selected) {
- $item['selected'] = true;
- }
-
- if ($onclick) {
- $js = "onclick=\"javascript:return confirm('" . elgg_echo('deleteconfirm') . "')\"";
- $item['vars'] = array('js' => $js);
- }
-
- return elgg_register_menu_item('page', $item);
-/*
- $item = array(
- 'text' => $label,
- 'href' => $link,
- 'selected' => $selected
- );
-
- return elgg_add_submenu_item($item, $context, $group);
+ * @param string $menu_name The name of the menu
+ * @param string $item_name The unique identifier for this menu item
*
+ * @return bool
+ * @since 1.8.0
*/
-}
-
-/**
- * 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) {
+function elgg_is_menu_item_registered($menu_name, $item_name) {
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;
+ if (!isset($CONFIG->menus[$menu_name])) {
+ 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;
- }
+ foreach ($CONFIG->menus[$menu_name] as $menu_object) {
+ /* @var ElggMenuItem $menu_object */
+ if ($menu_object->getName() == $item_name) {
+ return true;
}
-
- $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().
- *
- * @see elgg_get_submenu()
- * @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 false;
}
/**
- * Return the HTML for a sidemenu.
- *
- * @param string $context The context of the submenu (defaults to main)
- * @param BOOL $sort Sort by display name?
+ * Convenience function for registering a button to title menu
*
- * @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.
+ * The URL must be $handler/$name/$guid where $guid is the guid of the page owner.
+ * The label of the button is "$handler:$name" so that must be defined in a
+ * language file.
*
- * @note Custom menu items are added through the admin interface. Plugins
- * can add standard menu items by using {@link add_menu()}.
+ * This is used primarily to support adding an add content button
*
- * @since 1.8
- * @link http://docs.elgg.org/Tutorials/UI/SiteMenu
- * @elgg_event_handler init system
+ * @param string $handler The handler to use or null to autodetect from context
+ * @param string $name Name of the button
* @return void
+ * @since 1.8.0
*/
-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;
- }
+function elgg_register_title_button($handler = null, $name = 'add') {
+ if (elgg_is_logged_in()) {
- // 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;
- }
+ if (!$handler) {
+ $handler = elgg_get_context();
}
- }
- // add toolbar entries if not hiding dupes.
- foreach ($menu_items as $name => $info) {
- if (!in_array($info->value->url, $featured_urls)) {
- $more[] = $info;
+ $owner = elgg_get_page_owner_entity();
+ if (!$owner) {
+ // no owns the page so this is probably an all site list page
+ $owner = elgg_get_logged_in_user_entity();
+ }
+ if ($owner && $owner->canWriteToContainer()) {
+ $guid = $owner->getGUID();
+ elgg_register_menu_item('title', array(
+ 'name' => $name,
+ 'href' => "$handler/$name/$guid",
+ 'text' => elgg_echo("$handler:$name"),
+ 'link_class' => 'elgg-button elgg-button-action',
+ ));
}
}
-
- return array(
- 'featured' => $featured_urls_sanitised,
- 'more' => $more
- );
-}
-
-/**
- * Adds an item to the site-wide menu.
- *
- * You can obtain the menu array by calling {@link get_register('menu')}
- *
- * @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 The context of the menu
- *
- * @return true|false Depending on success
- * @todo Can be deprecated when the new menu system is introduced.
- */
-function add_menu($menu_name, $menu_url, $menu_children = array(), $context = "") {
- global $CONFIG;
-
- if (!isset($CONFIG->menucontexts)) {
- $CONFIG->menucontexts = array();
- }
-
- if (empty($context)) {
- $context = get_plugin_name();
- }
-
- $value = new stdClass();
- $value->url = elgg_normalize_url($menu_url);
- $value->context = $context;
-
- $CONFIG->menucontexts[] = $context;
- return add_to_register('menu', $menu_name, $value, $menu_children);
-}
-
-/**
- * Removes an item from the menu register
- *
- * @param string $menu_name The name of the menu item
- *
- * @return true|false Depending on success
- */
-function remove_menu($menu_name) {
- return remove_from_register('menu', $menu_name);
-}
-
-/**
- * Returns a menu item for use in the children section of add_menu()
- * This is not currently used in the Elgg core.
- *
- * @param string $menu_name The name of the menu item
- * @param string $menu_url Its URL
- *
- * @return stdClass|false Depending on success
- * @todo Can be deprecated when the new menu system is introduced.
- */
-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);
}
/**
@@ -542,30 +207,32 @@ function menu_item($menu_name, $menu_url) {
* @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)) {
+ if (!isset($CONFIG->breadcrumbs)) {
$CONFIG->breadcrumbs = array();
}
// avoid key collisions.
- $CONFIG->breadcrumbs[] = array('title' => $title, 'link' => $link);
+ $CONFIG->breadcrumbs[] = array('title' => elgg_get_excerpt($title, 100), '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 array_pop($CONFIG->breadcrumbs);
}
return FALSE;
@@ -575,12 +242,17 @@ function elgg_pop_breadcrumb() {
* Returns all breadcrumbs as an array of array('title' => 'Readable Title', 'link' => 'URL')
*
* @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();
+ if (isset($CONFIG->breadcrumbs) && is_array($CONFIG->breadcrumbs)) {
+ return $CONFIG->breadcrumbs;
+ }
+
+ return array();
}
/**
@@ -593,6 +265,7 @@ function elgg_get_breadcrumbs() {
* @param array $return Menu array
* @param array $params
* @return array
+ * @access private
*/
function elgg_site_menu_setup($hook, $type, $return, $params) {
@@ -600,7 +273,7 @@ function elgg_site_menu_setup($hook, $type, $return, $params) {
$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
@@ -623,26 +296,232 @@ function elgg_site_menu_setup($hook, $type, $return, $params) {
}
$return['default'] = $featured;
- $return['more'] = $registered;
+ if (count($registered) > 0) {
+ $return['more'] = $registered;
+ }
} else {
// no featured menu items set
$max_display_items = 5;
// the first n are shown, rest added to more list
+ // if only one item on more menu, stick it with the rest
$num_menu_items = count($return['default']);
- if ($num_menu_items > $max_display_items) {
- $return['more'] = array_splice($return['default'], $max_display_items);
+ if ($num_menu_items > ($max_display_items + 1)) {
+ $return['more'] = array_splice($return['default'], $max_display_items);
+ }
+ }
+
+ // check if we have anything selected
+ $selected = false;
+ foreach ($return as $section) {
+ foreach ($section as $item) {
+ if ($item->getSelected()) {
+ $selected = true;
+ break 2;
+ }
+ }
+ }
+
+ if (!$selected) {
+ // nothing selected, match name to context or match url
+ $current_url = current_page_url();
+ foreach ($return as $section_name => $section) {
+ foreach ($section as $key => $item) {
+ // only highlight internal links
+ if (strpos($item->getHref(), elgg_get_site_url()) === 0) {
+ if ($item->getName() == elgg_get_context()) {
+ $return[$section_name][$key]->setSelected(true);
+ break 2;
+ }
+ if ($item->getHref() == $current_url) {
+ $return[$section_name][$key]->setSelected(true);
+ break 2;
+ }
+ }
+ }
+ }
+ }
+
+ return $return;
+}
+
+/**
+ * Add the comment and like links to river actions menu
+ * @access private
+ */
+function elgg_river_menu_setup($hook, $type, $return, $params) {
+ if (elgg_is_logged_in()) {
+ $item = $params['item'];
+ /* @var ElggRiverItem $item */
+ $object = $item->getObjectEntity();
+ // comments and non-objects cannot be commented on or liked
+ if (!elgg_in_context('widgets') && $item->annotation_id == 0) {
+ // comments
+ if ($object->canComment()) {
+ $options = array(
+ 'name' => 'comment',
+ 'href' => "#comments-add-$object->guid",
+ 'text' => elgg_view_icon('speech-bubble'),
+ 'title' => elgg_echo('comment:this'),
+ 'rel' => 'toggle',
+ 'priority' => 50,
+ );
+ $return[] = ElggMenuItem::factory($options);
+ }
+ }
+
+ if (elgg_is_admin_logged_in()) {
+ $options = array(
+ 'name' => 'delete',
+ 'href' => elgg_add_action_tokens_to_url("action/river/delete?id=$item->id"),
+ 'text' => elgg_view_icon('delete'),
+ 'title' => elgg_echo('delete'),
+ 'confirm' => elgg_echo('deleteconfirm'),
+ 'priority' => 200,
+ );
+ $return[] = ElggMenuItem::factory($options);
}
}
+
+ return $return;
+}
+
+/**
+ * Entity menu is list of links and info on any entity
+ * @access private
+ */
+function elgg_entity_menu_setup($hook, $type, $return, $params) {
+ if (elgg_in_context('widgets')) {
+ return $return;
+ }
+ $entity = $params['entity'];
+ /* @var ElggEntity $entity */
+ $handler = elgg_extract('handler', $params, false);
+
+ // access
+ $access = elgg_view('output/access', array('entity' => $entity));
+ $options = array(
+ 'name' => 'access',
+ 'text' => $access,
+ 'href' => false,
+ 'priority' => 100,
+ );
+ $return[] = ElggMenuItem::factory($options);
+
+ if ($entity->canEdit() && $handler) {
+ // edit link
+ $options = array(
+ 'name' => 'edit',
+ 'text' => elgg_echo('edit'),
+ 'title' => elgg_echo('edit:this'),
+ 'href' => "$handler/edit/{$entity->getGUID()}",
+ 'priority' => 200,
+ );
+ $return[] = ElggMenuItem::factory($options);
+
+ // delete link
+ $options = array(
+ 'name' => 'delete',
+ 'text' => elgg_view_icon('delete'),
+ 'title' => elgg_echo('delete:this'),
+ 'href' => "action/$handler/delete?guid={$entity->getGUID()}",
+ 'confirm' => elgg_echo('deleteconfirm'),
+ 'priority' => 300,
+ );
+ $return[] = ElggMenuItem::factory($options);
+ }
+
+ return $return;
+}
+
+/**
+ * Widget menu is a set of widget controls
+ * @access private
+ */
+function elgg_widget_menu_setup($hook, $type, $return, $params) {
+
+ $widget = $params['entity'];
+ /* @var ElggWidget $widget */
+ $show_edit = elgg_extract('show_edit', $params, true);
+
+ $collapse = array(
+ 'name' => 'collapse',
+ 'text' => ' ',
+ 'href' => "#elgg-widget-content-$widget->guid",
+ 'class' => 'elgg-widget-collapse-button',
+ 'rel' => 'toggle',
+ 'priority' => 1
+ );
+ $return[] = ElggMenuItem::factory($collapse);
+
+ if ($widget->canEdit()) {
+ $delete = array(
+ 'name' => 'delete',
+ 'text' => elgg_view_icon('delete-alt'),
+ 'title' => elgg_echo('widget:delete', array($widget->getTitle())),
+ 'href' => "action/widgets/delete?widget_guid=$widget->guid",
+ 'is_action' => true,
+ 'class' => 'elgg-widget-delete-button',
+ 'id' => "elgg-widget-delete-button-$widget->guid",
+ 'priority' => 900
+ );
+ $return[] = ElggMenuItem::factory($delete);
+
+ if ($show_edit) {
+ $edit = array(
+ 'name' => 'settings',
+ 'text' => elgg_view_icon('settings-alt'),
+ 'title' => elgg_echo('widget:edit'),
+ 'href' => "#widget-edit-$widget->guid",
+ 'class' => "elgg-widget-edit-button",
+ 'rel' => 'toggle',
+ 'priority' => 800,
+ );
+ $return[] = ElggMenuItem::factory($edit);
+ }
+ }
+
+ return $return;
+}
+
+/**
+ * Adds a delete link to "generic_comment" annotations
+ * @access private
+ */
+function elgg_annotation_menu_setup($hook, $type, $return, $params) {
+ $annotation = $params['annotation'];
+ /* @var ElggAnnotation $annotation */
+
+ if ($annotation->name == 'generic_comment' && $annotation->canEdit()) {
+ $url = elgg_http_add_url_query_elements('action/comments/delete', array(
+ 'annotation_id' => $annotation->id,
+ ));
+
+ $options = array(
+ 'name' => 'delete',
+ 'href' => $url,
+ 'text' => "<span class=\"elgg-icon elgg-icon-delete\"></span>",
+ 'confirm' => elgg_echo('deleteconfirm'),
+ 'encode_text' => false
+ );
+ $return[] = ElggMenuItem::factory($options);
+ }
+
return $return;
}
+
/**
* Navigation initialization
+ * @access private
*/
function elgg_nav_init() {
elgg_register_plugin_hook_handler('prepare', 'menu:site', 'elgg_site_menu_setup');
+ elgg_register_plugin_hook_handler('register', 'menu:river', 'elgg_river_menu_setup');
+ elgg_register_plugin_hook_handler('register', 'menu:entity', 'elgg_entity_menu_setup');
+ elgg_register_plugin_hook_handler('register', 'menu:widget', 'elgg_widget_menu_setup');
+ elgg_register_plugin_hook_handler('register', 'menu:annotation', 'elgg_annotation_menu_setup');
}
-elgg_register_event_handler('init', 'system', 'elgg_nav_init'); \ No newline at end of file
+elgg_register_event_handler('init', 'system', 'elgg_nav_init');