From 32387e6db0c56935e93314217b52eab4d9dca016 Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Sun, 26 Jun 2011 08:16:19 -0400 Subject: Fixes #3470 using rel=toggle now --- engine/lib/navigation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engine/lib/navigation.php') diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php index b51c63b49..4b2c998a2 100644 --- a/engine/lib/navigation.php +++ b/engine/lib/navigation.php @@ -276,7 +276,7 @@ function elgg_river_menu_setup($hook, $type, $return, $params) { 'href' => "#comments-add-$object->guid", 'text' => elgg_view_icon('speech-bubble'), 'title' => elgg_echo('comment:this'), - 'link_class' => "elgg-toggler", + 'link_rel' => 'toggle', 'priority' => 50, ); $return[] = ElggMenuItem::factory($options); -- cgit v1.2.3 From e43d4443e6e9718433496b739f0af6630aad9e95 Mon Sep 17 00:00:00 2001 From: cash Date: Sun, 26 Jun 2011 14:02:36 -0400 Subject: added a data array to ElggMenuItem. Now by default options end up being passed to output/url. --- engine/classes/ElggMenuItem.php | 273 ++++++++++++++++++++++------------------ engine/lib/navigation.php | 2 +- mod/groups/start.php | 2 +- 3 files changed, 152 insertions(+), 125 deletions(-) (limited to 'engine/lib/navigation.php') diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php index 1181583f2..36c21b8b4 100644 --- a/engine/classes/ElggMenuItem.php +++ b/engine/classes/ElggMenuItem.php @@ -10,75 +10,62 @@ * @since 1.8.0 */ class ElggMenuItem { - /** - * @var string Identifier of the menu - */ - protected $name; /** - * @var string The menu display string + * @var array Non-rendered data about the menu item */ - protected $text; + protected $data = array( + // string Identifier of the menu + 'name' => '', - /** - * @var string The menu url - */ - protected $href = null; + // array Page contexts this menu item should appear on + 'contexts' => array('all'), - /** - * @var string The string to display if link is clicked - */ - protected $confirm = ''; + // string Menu section identifier + 'section' => 'default', - /** - * @var array Classes to apply to the anchor tag. - */ - protected $linkClass = array(); + // int Smaller priorities float to the top + 'priority' => 100, - /** - * @var array Classes to apply to the li tag. - */ - protected $itemClass = array(); + // bool Is this the currently selected menu item + 'selected' => false, - /** - * @var array Page context array - */ - protected $contexts = array('all'); + // string Identifier of this item's parent + 'parent_name' => '', - /** - * @var string Menu section identifier - */ - protected $section = 'default'; + // ElggMenuItem The parent object or null + 'parent' => null, - /** - * @var string Tooltip - */ - protected $title = ''; + // array Array of children objects or empty array + 'children' => array(), - /** - * @var int Menu priority - smaller prioritys float to the top - */ - protected $priority = 100; + // array Classes to apply to the li tag + 'itemClass' => array(), + + // array Classes to apply to the anchor tag + 'linkClass' => array(), + ); /** - * @var bool Is this the currently selected menu item + * @var string The menu display string */ - protected $selected = false; + protected $text; /** - * @var string Identifier of this item's parent + * @var string The menu url */ - protected $parent_name = ''; + protected $href = null; /** - * @var ElggMenuItem The parent object or null + * @var string Tooltip */ - protected $parent = null; + protected $title = ''; /** - * @var array Array of children objects or empty array + * @var string The string to display if link is clicked */ - protected $children = array(); + protected $confirm = ''; + /** * ElggMenuItem constructor @@ -88,13 +75,15 @@ class ElggMenuItem { * @param string $href URL of the menu item (false if not a link) */ public function __construct($name, $text, $href) { - $this->name = $name; + //$this->name = $name; $this->text = $text; if ($href) { $this->href = elgg_normalize_url($href); } else { $this->href = $href; } + + $this->data['name'] = $name; } /** @@ -122,6 +111,12 @@ class ElggMenuItem { $options['contexts'] = $options['context']; unset($options['context']); } + + // make sure contexts is set correctly + if (isset($options['contexts'])) { + $item->setContext($options['contexts']); + unset($options['contexts']); + } if (isset($options['link_class'])) { $item->setLinkClass($options['link_class']); @@ -133,16 +128,62 @@ class ElggMenuItem { unset($options['item_class']); } + if (isset($options['data']) && is_array($options['data'])) { + $item->setData($options['data']); + unset($options['data']); + } + foreach ($options as $key => $value) { - $item->$key = $value; + if (isset($item->data[$key])) { + $item->data[$key] = $value; + } else { + $item->$key = $value; + } } - // make sure contexts is set correctly - if (isset($options['contexts'])) { - $item->setContext($options['contexts']); + return $item; + } + + /** + * Set a data key/value pair or a set of key/value pairs + * + * This method allows storage of arbitrary data with this menu item. The + * data can be used for sorting, custom rendering, or any other use. + * + * @param mixed $key String key or an associative array of key/value pairs + * @param mixed $value The value if $key is a string + * @return void + */ + public function setData($key, $value = null) { + if (is_array($key)) { + $this->data += $key; + } else { + $this->data[$key] = $value; } + } - return $item; + /** + * Get stored data + * + * @param string $key The key for the requested key/value pair + * @return mixed + */ + public function getData($key) { + if (isset($this->data[$key])) { + return $this->data[$key]; + } else { + return null; + } + } + + /** + * Set the identifier of the menu item + * + * @param string Unique identifier + * @return void + */ + public function setName($name) { + $this->data['name'] = $name; } /** @@ -151,14 +192,13 @@ class ElggMenuItem { * @return string */ public function getName() { - return $this->name; + return $this->data['name']; } - + /** * Set the display text of the menu item * * @param string $text The display text - * * @return void */ public function setText($text) { @@ -177,6 +217,7 @@ class ElggMenuItem { /** * Set the URL of the menu item * + * @param string $href URL or false if not a link * @return void */ public function setHref($href) { @@ -196,14 +237,13 @@ class ElggMenuItem { * Set the contexts that this menu item is available for * * @param array $contexts An array of context strings - * * @return void */ public function setContext($contexts) { if (is_string($contexts)) { $contexts = array($contexts); } - $this->contexts = $contexts; + $this->data['contexts'] = $contexts; } /** @@ -212,27 +252,26 @@ class ElggMenuItem { * @return array */ public function getContext() { - return $this->contexts; + return $this->data['contexts']; } /** * Should this menu item be used given the current context * * @param string $context A context string (default is empty string for - * current context stack. - * + * current context stack). * @return bool */ public function inContext($context = '') { if ($context) { - return in_array($context, $this->contexts); + return in_array($context, $this->data['contexts']); } - if (in_array('all', $this->contexts)) { + if (in_array('all', $this->data['contexts'])) { return true; } - foreach ($this->contexts as $context) { + foreach ($this->data['contexts'] as $context) { if (elgg_in_context($context)) { return true; } @@ -244,11 +283,10 @@ class ElggMenuItem { * Set the selected flag * * @param bool $state Selected state (default is true) - * * @return void */ public function setSelected($state = true) { - $this->selected = $state; + $this->data['selected'] = $state; } /** @@ -257,14 +295,13 @@ class ElggMenuItem { * @return bool */ public function getSelected() { - return $this->selected; + return $this->data['selected']; } /** * Set the tool tip text * * @param string $text The text of the tool tip - * * @return void */ public function setTooltip($text) { @@ -284,7 +321,6 @@ class ElggMenuItem { * Set the confirm text shown when link is clicked * * @param string $text The text to show - * * @return void */ public function setConfirmText($text) { @@ -304,14 +340,13 @@ class ElggMenuItem { * Set the anchor class * * @param mixed $class An array of class names, or a single string class name. - * * @return void */ public function setLinkClass($class) { if (!is_array($class)) { - $this->linkClass[] = $class; + $this->data['linkClass'] = array($class); } else { - $this->linkClass = $class; + $this->data['linkClass'] = $class; } } @@ -321,21 +356,34 @@ class ElggMenuItem { * @return string */ public function getLinkClass() { - return implode(' ', $this->linkClass); + return implode(' ', $this->data['linkClass']); } /** - * Set the li classes + * Add a link class * * @param mixed $class An array of class names, or a single string class name. + * @return void + */ + public function addLinkClass($class) { + if (!is_array($class)) { + $this->data['linkClass'][] = $class; + } else { + $this->data['linkClass'] += $class; + } + } + + /** + * Set the li classes * + * @param mixed $class An array of class names, or a single string class name. * @return void */ public function setItemClass($class) { if (!is_array($class)) { - $this->itemClass[] = $class; + $this->data['itemClass'] = array($class); } else { - $this->itemClass = $class; + $this->data['itemClass'] = $class; } } @@ -345,11 +393,11 @@ class ElggMenuItem { * @return string */ public function getItemClass() { - //allow people to specify name with underscores and colons + // allow people to specify name with underscores and colons $name = str_replace('_', '-', $this->getName()); $name = str_replace(':', '-', $name); - $class = implode(' ', $this->itemClass); + $class = implode(' ', $this->data['itemClass']); if ($class) { return "elgg-menu-item-$name $class"; } else { @@ -361,11 +409,10 @@ class ElggMenuItem { * Set the priority of the menu item * * @param int $priority The smaller numbers mean higher priority (1 before 100) - * * @return void */ public function setWeight($priority) { - $this->priority = $priority; + $this->data['priority'] = $priority; } /** @@ -374,18 +421,17 @@ class ElggMenuItem { * @return int */ public function getWeight() { - return $this->priority; + return $this->data['priority']; } /** * Set the section identifier * * @param string $section The identifier of the section - * * @return void */ public function setSection($section) { - $this->section = $section; + $this->data['section'] = $section; } /** @@ -394,18 +440,17 @@ class ElggMenuItem { * @return string */ public function getSection() { - return $this->section; + return $this->data['section']; } /** * Set the parent identifier * - * @param string $parent_name The identifier of the parent ElggMenuItem - * + * @param string $name The identifier of the parent ElggMenuItem * @return void */ - public function setParentName($parent_name) { - $this->parent_name = $parent_name; + public function setParentName($name) { + $this->data['parent_name'] = $name; } /** @@ -414,18 +459,17 @@ class ElggMenuItem { * @return string */ public function getParentName() { - return $this->parent_name; + return $this->data['parent_name']; } /** * Set the parent menu item * * @param ElggMenuItem $parent - * * @return void */ public function setParent($parent) { - $this->parent = $parent; + $this->data['parent'] = $parent; } /** @@ -434,29 +478,27 @@ class ElggMenuItem { * @return ElggMenuItem or null */ public function getParent() { - return $this->parent; + return $this->data['parent']; } /** * Add a child menu item * * @param ElggMenuItem $item - * * @return void */ public function addChild($item) { - $this->children[] = $item; + $this->data['children'][] = $item; } /** * Set the menu item's children * * @param array $children Array of ElggMenuItems - * * @return void */ public function setChildren($children) { - $this->children = $children; + $this->data['children'] = $children; } /** @@ -465,25 +507,23 @@ class ElggMenuItem { * @return array */ public function getChildren() { - return $this->children; + return $this->data['children']; } /** * Sort the children * - * @param string $sort_function - * + * @param string $sortFunction A function that is passed to usort() * @return void */ - public function sortChildren($sort_function) { - usort($this->children, $sort_function); + public function sortChildren($sortFunction) { + usort($this->data['children'], $sortFunction); } /** * Get the menu item content (usually a link) * * @params array $vars Options to pass to output/url if a link - * * @return string * * @todo View code in a model. How do we feel about that? @@ -494,30 +534,17 @@ class ElggMenuItem { return $this->text; } - $vars['text'] = $this->text; + $defaults = get_object_vars($this); + unset($defaults['data']); - if ($this->href) { - $vars['href'] = $this->href; - } + $vars += $defaults; - if ($this->linkClass) { - $vars['class'] = $this->getLinkClass(); - } - - if ($this->link_rel) { - $vars['rel'] = $this->link_rel; - } - - if ($this->rel) { - $vars['rel'] = $this->rel; - } - - if ($this->title) { - $vars['title'] = $this->title; - } - - if ($this->is_action) { - $vars['is_action'] = $this->is_action; + if ($this->data['linkClass']) { + if (isset($vars['class'])) { + $vars['class'] += $this->getLinkClass(); + } else { + $vars['class'] = $this->getLinkClass(); + } } if ($this->confirm) { diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php index 4b2c998a2..48a3659f6 100644 --- a/engine/lib/navigation.php +++ b/engine/lib/navigation.php @@ -276,7 +276,7 @@ function elgg_river_menu_setup($hook, $type, $return, $params) { 'href' => "#comments-add-$object->guid", 'text' => elgg_view_icon('speech-bubble'), 'title' => elgg_echo('comment:this'), - 'link_rel' => 'toggle', + 'rel' => 'toggle', 'priority' => 50, ); $return[] = ElggMenuItem::factory($options); diff --git a/mod/groups/start.php b/mod/groups/start.php index 57c40af5d..83353bae5 100644 --- a/mod/groups/start.php +++ b/mod/groups/start.php @@ -776,7 +776,7 @@ function discussion_add_to_river_menu($hook, $type, $return, $params) { 'href' => "#groups-reply-$object->guid", 'text' => elgg_view_icon('speech-bubble'), 'title' => elgg_echo('reply:this'), - 'link_rel' => 'toggle', + 'rel' => 'toggle', 'priority' => 50, ); $return[] = ElggMenuItem::factory($options); -- cgit v1.2.3 From 3c34ddf59804767e6a7deea3e3ee6c81d4a09601 Mon Sep 17 00:00:00 2001 From: cash Date: Sun, 26 Jun 2011 15:13:50 -0400 Subject: removed buttons logic from content header view, created convenience function rather than copying and pasting, and updated the blog plugin --- engine/lib/navigation.php | 35 +++++++++++++++++++++++++++ mod/blog/lib/blog.php | 6 +++-- views/default/page/layouts/content.php | 1 - views/default/page/layouts/content/header.php | 30 ++++++++--------------- 4 files changed, 49 insertions(+), 23 deletions(-) (limited to 'engine/lib/navigation.php') diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php index 4b2c998a2..1cb289654 100644 --- a/engine/lib/navigation.php +++ b/engine/lib/navigation.php @@ -153,6 +153,41 @@ function elgg_is_menu_item_registered($menu_name, $item_name) { return false; } +/** + * Convenience function for registering an add content button to title menu + * + * The add URL must be $handler/add/$guid where $guid is the guid of the page owner. + * The label of the button is "$handler:add" so that must be defined in a + * language file. + * + * @param string $handler The handler to use or null to autodetect from context + * @return void + * @since 1.8.0 + */ +function elgg_register_add_button($handler = null) { + if (elgg_is_logged_in()) { + + if (!$handler) { + $handler = elgg_get_context(); + } + + $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' => 'add', + 'href' => "$handler/add/$guid", + 'text' => elgg_echo("$handler:add"), + 'link_class' => 'elgg-button elgg-button-action', + )); + } + } +} + /** * Adds a breadcrumb to the breadcrumbs stack. * diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php index 4d1edd50e..d13b2244e 100644 --- a/mod/blog/lib/blog.php +++ b/mod/blog/lib/blog.php @@ -92,6 +92,8 @@ function blog_get_page_content_list($container_guid = NULL) { elgg_push_breadcrumb(elgg_echo('blog:blogs')); } + elgg_register_add_button(); + // show all posts for admin or users looking at their own blogs // show only published posts for other users. if (!(elgg_is_admin_logged_in() || (elgg_is_logged_in() && $container_guid == $loggedin_userid))) { @@ -129,6 +131,8 @@ function blog_get_page_content_friends($user_guid) { elgg_push_breadcrumb($crumbs_title, "blog/owner/{$user->username}"); elgg_push_breadcrumb(elgg_echo('friends')); + elgg_register_add_button(); + if (!$friends = get_user_friends($user_guid, ELGG_ENTITIES_ANY_VALUE, 0)) { $return['content'] .= elgg_echo('friends:none:you'); return $return; @@ -235,7 +239,6 @@ function blog_get_page_content_archive($owner_guid, $lower = 0, $upper = 0) { return array( 'content' => $content, 'title' => $title, - 'buttons' => '', 'filter' => '', ); } @@ -253,7 +256,6 @@ function blog_get_page_content_edit($page, $guid = 0, $revision = NULL) { elgg_load_js('elgg.blog'); $return = array( - 'buttons' => '', 'filter' => '', ); diff --git a/views/default/page/layouts/content.php b/views/default/page/layouts/content.php index 35d695f0a..c406c9faf 100644 --- a/views/default/page/layouts/content.php +++ b/views/default/page/layouts/content.php @@ -10,7 +10,6 @@ * @uses $vars['filter'] HTML of the content area filter (override) * @uses $vars['title'] Title text (override) * @uses $vars['context'] Page context (override) - * @uses $vars['buttons'] Content header buttons (override) * @uses $vars['filter_context'] Filter context: everyone, friends, mine * @uses $vars['class'] Additional class to apply to layout */ diff --git a/views/default/page/layouts/content/header.php b/views/default/page/layouts/content/header.php index 403da8a0a..345163bdd 100644 --- a/views/default/page/layouts/content/header.php +++ b/views/default/page/layouts/content/header.php @@ -7,9 +7,13 @@ * @uses $vars['header_override'] HTML for overriding the default header (override) * @uses $vars['title'] Title text (override) * @uses $vars['context'] Page context (override) - * @uses $vars['buttons'] Content header buttons (override) */ +if (isset($vars['buttons'])) { + // it was a bad idea to implement buttons with a pass through + elgg_deprecated_notice("Use elgg_register_menu_item() to register for the title menu", 1.0); +} + if (isset($vars['header_override'])) { echo $vars['header_override']; return true; @@ -22,27 +26,13 @@ if ($context) { $title = elgg_echo($context); } - if (isset($vars['buttons'])) { + if (isset($vars['buttons']) && $vars['buttons']) { $buttons = $vars['buttons']; } else { - if (elgg_is_logged_in() && $context) { - $owner = elgg_get_page_owner_entity(); - if (!$owner) { - // this is probably an all page - $owner = elgg_get_logged_in_user_entity(); - } - if ($owner && $owner->canWriteToContainer()) { - $guid = $owner->getGUID(); - elgg_register_menu_item('title', array( - 'name' => 'add', - 'href' => elgg_extract('new_link', $vars, "$context/add/$guid"), - 'text' => elgg_echo("$context:add"), - 'link_class' => 'elgg-button elgg-button-action', - )); - } - } - - $buttons = elgg_view_menu('title', array('sort_by' => 'priority', 'class' => 'elgg-menu-hz')); + $buttons = elgg_view_menu('title', array( + 'sort_by' => 'priority', + 'class' => 'elgg-menu-hz', + )); } echo << -- cgit v1.2.3 From d15c4bdf3388b7eca709bd81c522ac1ebf087f0a Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Wed, 6 Jul 2011 06:51:53 -0400 Subject: changed new convenience function from elgg_register_add_button() to elgg_register_title_button() --- engine/lib/navigation.php | 17 ++++++++++------- mod/blog/lib/blog.php | 4 ++-- mod/bookmarks/pages/bookmarks/all.php | 2 +- mod/bookmarks/pages/bookmarks/friends.php | 2 +- mod/bookmarks/pages/bookmarks/owner.php | 2 +- mod/file/pages/file/friends.php | 2 +- mod/file/pages/file/owner.php | 2 +- mod/file/pages/file/world.php | 2 +- mod/groups/lib/discussion.php | 2 +- mod/groups/lib/groups.php | 6 +++--- mod/messages/pages/messages/inbox.php | 2 +- mod/messages/pages/messages/sent.php | 2 +- mod/pages/pages/pages/friends.php | 2 +- mod/pages/pages/pages/owner.php | 2 +- mod/pages/pages/pages/world.php | 2 +- 15 files changed, 27 insertions(+), 24 deletions(-) (limited to 'engine/lib/navigation.php') diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php index cdf3d0f67..1305ee3de 100644 --- a/engine/lib/navigation.php +++ b/engine/lib/navigation.php @@ -154,17 +154,20 @@ function elgg_is_menu_item_registered($menu_name, $item_name) { } /** - * Convenience function for registering an add content button to title menu + * Convenience function for registering a button to title menu * - * The add URL must be $handler/add/$guid where $guid is the guid of the page owner. - * The label of the button is "$handler:add" so that must be defined in a + * 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. * + * This is used primarily to support adding an add content button + * * @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 elgg_register_add_button($handler = null) { +function elgg_register_title_button($handler = null, $name = 'add') { if (elgg_is_logged_in()) { if (!$handler) { @@ -179,9 +182,9 @@ function elgg_register_add_button($handler = null) { if ($owner && $owner->canWriteToContainer()) { $guid = $owner->getGUID(); elgg_register_menu_item('title', array( - 'name' => 'add', - 'href' => "$handler/add/$guid", - 'text' => elgg_echo("$handler:add"), + 'name' => $name, + 'href' => "$handler/$name/$guid", + 'text' => elgg_echo("$handler:$name"), 'link_class' => 'elgg-button elgg-button-action', )); } diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php index 0f81597eb..b7b1a2baa 100644 --- a/mod/blog/lib/blog.php +++ b/mod/blog/lib/blog.php @@ -92,7 +92,7 @@ function blog_get_page_content_list($container_guid = NULL) { elgg_push_breadcrumb(elgg_echo('blog:blogs')); } - elgg_register_add_button(); + elgg_register_title_button(); // show all posts for admin or users looking at their own blogs // show only published posts for other users. @@ -131,7 +131,7 @@ function blog_get_page_content_friends($user_guid) { elgg_push_breadcrumb($crumbs_title, "blog/owner/{$user->username}"); elgg_push_breadcrumb(elgg_echo('friends')); - elgg_register_add_button(); + elgg_register_title_button(); if (!$friends = get_user_friends($user_guid, ELGG_ENTITIES_ANY_VALUE, 0)) { $return['content'] .= elgg_echo('friends:none:you'); diff --git a/mod/bookmarks/pages/bookmarks/all.php b/mod/bookmarks/pages/bookmarks/all.php index 7b3f2059c..d9ac2767f 100644 --- a/mod/bookmarks/pages/bookmarks/all.php +++ b/mod/bookmarks/pages/bookmarks/all.php @@ -8,7 +8,7 @@ elgg_pop_breadcrumb(); elgg_push_breadcrumb(elgg_echo('bookmarks')); -elgg_register_add_button(); +elgg_register_title_button(); $offset = (int)get_input('offset', 0); $content = elgg_list_entities(array( diff --git a/mod/bookmarks/pages/bookmarks/friends.php b/mod/bookmarks/pages/bookmarks/friends.php index ef5f078f5..3491090a5 100644 --- a/mod/bookmarks/pages/bookmarks/friends.php +++ b/mod/bookmarks/pages/bookmarks/friends.php @@ -10,7 +10,7 @@ $owner = elgg_get_page_owner_entity(); elgg_push_breadcrumb($owner->name, "bookmarks/owner/$owner->username"); elgg_push_breadcrumb(elgg_echo('friends')); -elgg_register_add_button(); +elgg_register_title_button(); $title = elgg_echo('bookmarks:friends'); diff --git a/mod/bookmarks/pages/bookmarks/owner.php b/mod/bookmarks/pages/bookmarks/owner.php index 46a22080d..679c986be 100644 --- a/mod/bookmarks/pages/bookmarks/owner.php +++ b/mod/bookmarks/pages/bookmarks/owner.php @@ -9,7 +9,7 @@ $page_owner = elgg_get_page_owner_entity(); elgg_push_breadcrumb($page_owner->name); -elgg_register_add_button(); +elgg_register_title_button(); $offset = (int)get_input('offset', 0); $content .= elgg_list_entities(array( diff --git a/mod/file/pages/file/friends.php b/mod/file/pages/file/friends.php index 7bde42962..0b351efaf 100644 --- a/mod/file/pages/file/friends.php +++ b/mod/file/pages/file/friends.php @@ -11,7 +11,7 @@ elgg_push_breadcrumb(elgg_echo('file'), "file/all"); elgg_push_breadcrumb($owner->name, "file/owner/$owner->username"); elgg_push_breadcrumb(elgg_echo('friends')); -elgg_register_add_button(); +elgg_register_title_button(); $title = elgg_echo("file:friends"); diff --git a/mod/file/pages/file/owner.php b/mod/file/pages/file/owner.php index 2244de095..4e2ec89d4 100644 --- a/mod/file/pages/file/owner.php +++ b/mod/file/pages/file/owner.php @@ -13,7 +13,7 @@ $owner = elgg_get_page_owner_entity(); elgg_push_breadcrumb(elgg_echo('file'), "file/all"); elgg_push_breadcrumb($owner->name); -elgg_register_add_button(); +elgg_register_title_button(); $params = array(); diff --git a/mod/file/pages/file/world.php b/mod/file/pages/file/world.php index 560743bed..e438ca2f0 100644 --- a/mod/file/pages/file/world.php +++ b/mod/file/pages/file/world.php @@ -7,7 +7,7 @@ elgg_push_breadcrumb(elgg_echo('file')); -elgg_register_add_button(); +elgg_register_title_button(); $limit = get_input("limit", 10); diff --git a/mod/groups/lib/discussion.php b/mod/groups/lib/discussion.php index 52df7e18d..e129e0f9d 100644 --- a/mod/groups/lib/discussion.php +++ b/mod/groups/lib/discussion.php @@ -45,7 +45,7 @@ function discussion_handle_list_page($guid) { } elgg_push_breadcrumb($group->name); - elgg_register_add_button(); + elgg_register_title_button(); group_gatekeeper(); diff --git a/mod/groups/lib/groups.php b/mod/groups/lib/groups.php index 2747f360b..126738566 100644 --- a/mod/groups/lib/groups.php +++ b/mod/groups/lib/groups.php @@ -12,7 +12,7 @@ function groups_handle_all_page() { elgg_pop_breadcrumb(); elgg_push_breadcrumb(elgg_echo('groups')); - elgg_register_add_button(); + elgg_register_title_button(); $selected_tab = get_input('filter', 'newest'); @@ -100,7 +100,7 @@ function groups_handle_owned_page() { $title = elgg_echo('groups:owned'); elgg_push_breadcrumb($title); - elgg_register_add_button(); + elgg_register_title_button(); $content = elgg_list_entities(array( 'type' => 'group', @@ -128,7 +128,7 @@ function groups_handle_mine_page() { $title = elgg_echo('groups:yours'); elgg_push_breadcrumb($title); - elgg_register_add_button(); + elgg_register_title_button(); $content = elgg_list_entities_from_relationship_count(array( 'type' => 'group', diff --git a/mod/messages/pages/messages/inbox.php b/mod/messages/pages/messages/inbox.php index 96712a193..fdfc20c43 100644 --- a/mod/messages/pages/messages/inbox.php +++ b/mod/messages/pages/messages/inbox.php @@ -15,7 +15,7 @@ if (!$page_owner) { elgg_push_breadcrumb(elgg_echo('messages:inbox')); -elgg_register_add_button(); +elgg_register_title_button(); $title = elgg_echo('messages:user', array($page_owner->name)); diff --git a/mod/messages/pages/messages/sent.php b/mod/messages/pages/messages/sent.php index edf2b29fb..af06ab273 100644 --- a/mod/messages/pages/messages/sent.php +++ b/mod/messages/pages/messages/sent.php @@ -15,7 +15,7 @@ if (!$page_owner) { elgg_push_breadcrumb(elgg_echo('messages:sent')); -elgg_register_add_button(); +elgg_register_title_button(); $title = elgg_echo('messages:sentmessages', array($page_owner->name)); diff --git a/mod/pages/pages/pages/friends.php b/mod/pages/pages/pages/friends.php index 88f26c45d..c55b27466 100644 --- a/mod/pages/pages/pages/friends.php +++ b/mod/pages/pages/pages/friends.php @@ -13,7 +13,7 @@ if (!$owner) { elgg_push_breadcrumb($owner->name, "pages/owner/$owner->username"); elgg_push_breadcrumb(elgg_echo('friends')); -elgg_register_add_button(); +elgg_register_title_button(); $title = elgg_echo('pages:friends'); diff --git a/mod/pages/pages/pages/owner.php b/mod/pages/pages/pages/owner.php index 312b56a54..2ff310ac8 100644 --- a/mod/pages/pages/pages/owner.php +++ b/mod/pages/pages/pages/owner.php @@ -17,7 +17,7 @@ $title = elgg_echo('pages:owner', array($owner->name)); elgg_push_breadcrumb($owner->name); -elgg_register_add_button(); +elgg_register_title_button(); $content = elgg_list_entities(array( 'types' => 'object', diff --git a/mod/pages/pages/pages/world.php b/mod/pages/pages/pages/world.php index 9237a820e..e6a705b6b 100644 --- a/mod/pages/pages/pages/world.php +++ b/mod/pages/pages/pages/world.php @@ -10,7 +10,7 @@ $title = elgg_echo('pages:all'); elgg_pop_breadcrumb(); elgg_push_breadcrumb(elgg_echo('pages')); -elgg_register_add_button(); +elgg_register_title_button(); $content = elgg_list_entities(array( 'types' => 'object', -- cgit v1.2.3 From 946a4a008ab2bc3f3a530558ae47581f9d8fbbcb Mon Sep 17 00:00:00 2001 From: Brett Profitt Date: Wed, 24 Aug 2011 17:06:39 -0700 Subject: Refs #3750. Added annotation menu for generic comments (delete) and default annotations (empty). --- engine/lib/navigation.php | 26 ++++++++++++++++++++++++++ views/default/annotation/default.php | 25 ++++++++----------------- views/default/annotation/generic_comment.php | 18 ++++++------------ views/default/css/elements/navigation.php | 12 ++++++------ 4 files changed, 46 insertions(+), 35 deletions(-) (limited to 'engine/lib/navigation.php') diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php index 1305ee3de..cefe40ecf 100644 --- a/engine/lib/navigation.php +++ b/engine/lib/navigation.php @@ -372,6 +372,31 @@ function elgg_entity_menu_setup($hook, $type, $return, $params) { return $return; } +/** + * Adds a delete link to "generic_comment" annotations + */ +function elgg_annotation_menu_setup($hook, $type, $return, $params) { + $annotation = $params['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' => "", + 'confirm' => elgg_echo('deleteconfirm'), + 'text_encode' => false + ); + $return[] = ElggMenuItem::factory($options); + } + + return $return; +} + + /** * Navigation initialization */ @@ -379,6 +404,7 @@ 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:annotation', 'elgg_annotation_menu_setup'); } elgg_register_event_handler('init', 'system', 'elgg_nav_init'); diff --git a/views/default/annotation/default.php b/views/default/annotation/default.php index a21fdee51..0e626ad9a 100644 --- a/views/default/annotation/default.php +++ b/views/default/annotation/default.php @@ -2,9 +2,9 @@ /** * Elgg default annotation view * + * @note To add or remove from the annotation menu, register handlers for the menu:annotation hook. + * * @uses $vars['annotation'] - * @uses $vars['delete_action'] A custom action for the delete button. - * The annotation ID is passed as 'annotation_id'. */ $annotation = $vars['annotation']; @@ -16,28 +16,19 @@ if (!$owner) { $icon = elgg_view_entity_icon($owner, 'tiny'); $owner_link = "getURL()}\">$owner->name"; -$delete_action = elgg_extract('delete_action', $vars, ''); +$menu = elgg_view_menu('annotation', array( + 'annotation' => $annotation, + 'sort_by' => 'priority', + 'class' => 'elgg-menu-hz right', +)); $text = elgg_view("output/longtext", array("value" => $annotation->value)); $friendlytime = elgg_view_friendly_time($annotation->time_created); -$delete_button = ''; -if ($delete_action && $annotation->canEdit()) { - $url = elgg_http_add_url_query_elements($delete_action, array( - 'annotation_id' => $annotation->id, - )); - $delete_button = elgg_view("output/confirmlink", array( - 'href' => $url, - 'text' => "", - 'confirm' => elgg_echo('deleteconfirm'), - 'text_encode' => false, - )); -} - $body = << - $delete_button + $menu $owner_link $friendlytime diff --git a/views/default/annotation/generic_comment.php b/views/default/annotation/generic_comment.php index 69520d102..a4fbf904e 100644 --- a/views/default/annotation/generic_comment.php +++ b/views/default/annotation/generic_comment.php @@ -29,23 +29,17 @@ $entity_title = $entity->title ? $entity->title : elgg_echo('untitled'); $entity_link = "getURL()}\">$entity_title"; if ($full_view) { - - $delete_button = ''; - if ($comment->canEdit()) { - $url = "action/comments/delete?annotation_id=$comment->id"; - $delete_button = elgg_view("output/confirmlink", array( - 'href' => $url, - 'text' => "", - 'confirm' => elgg_echo('deleteconfirm'), - 'text_encode' => false, - )); - } + $menu = elgg_view_menu('annotation', array( + 'annotation' => $comment, + 'sort_by' => 'priority', + 'class' => 'elgg-menu-hz right', + )); $comment_text = elgg_view("output/longtext", array("value" => $comment->value)); $body = << - $delete_button + $menu $commenter_link $friendlytime diff --git a/views/default/css/elements/navigation.php b/views/default/css/elements/navigation.php index 64b7c47b4..b5388715e 100644 --- a/views/default/css/elements/navigation.php +++ b/views/default/css/elements/navigation.php @@ -424,10 +424,10 @@ li:hover > .elgg-menu-site-more { } /* *************************************** - ENTITY + ENTITY AND ANNOTATION *************************************** */ -.elgg-menu-entity { +.elgg-menu-entity, elgg-menu-annotation { float: right; margin-left: 15px; font-size: 90%; @@ -435,17 +435,17 @@ li:hover > .elgg-menu-site-more { line-height: 16px; height: 16px; } -.elgg-menu-entity > li { +.elgg-menu-entity > li, .elgg-menu-annotation > li { margin-left: 15px; } -.elgg-menu-entity > li > a { +.elgg-menu-entity > li > a, .elgg-menu-annotation > li > a { color: #aaa; } -.elgg-menu-entity > li > a { +.elgg-menu-entity > li > a, .elgg-menu-annotation > li > a { display: block; } -.elgg-menu-entity > li > span { +.elgg-menu-entity > li > span, .elgg-menu-annotation > li > span { vertical-align: baseline; } -- cgit v1.2.3