From 7c6ed461cf474739c5634a9fe050421c56a822bc Mon Sep 17 00:00:00 2001 From: cash Date: Sun, 20 Mar 2011 19:47:57 +0000 Subject: Fixes #3025 added back thewire's entity menu items git-svn-id: http://code.elgg.org/elgg/trunk@8782 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/thewire/start.php | 83 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 24 deletions(-) diff --git a/mod/thewire/start.php b/mod/thewire/start.php index c87831bee..0b2265082 100644 --- a/mod/thewire/start.php +++ b/mod/thewire/start.php @@ -27,8 +27,8 @@ function thewire_init() { $item = new ElggMenuItem('thewire', elgg_echo('thewire'), 'thewire/all'); elgg_register_menu_item('site', $item); - // remove entity menu items edit and access because they don't apply here. - elgg_register_plugin_hook_handler('prepare', 'menu:entity', 'thewire_remove_entity_menu_items'); + // remove edit and access and add thread, reply, view previous + elgg_register_plugin_hook_handler('register', 'menu:entity', 'thewire_setup_entity_menu_items'); // Extend system CSS with our own styles, which are defined in the thewire/css view elgg_extend_view('css', 'thewire/css'); @@ -354,6 +354,63 @@ function thewire_get_parent($post_guid) { return null; } +/** + * Sets up the entity menu for thewire + * + * Adds reply, thread, and view previous links. Removes edit and access. + * + * @param string $hook + * @param string $type + * @param array $value + * @param array $params + * @return array + */ +function thewire_setup_entity_menu_items($hook, $type, $value, $params) { + $handler = elgg_extract('handler', $params, false); + if ($handler != 'thewire') { + return $value; + } + + foreach ($value as $index => $item) { + $name = $item->getName(); + if ($name == 'access' || $name == 'edit') { + unset($value[$index]); + } + } + + $entity = $params['entity']; + + if (elgg_is_logged_in()) { + $options = array( + 'name' => 'reply', + 'text' => elgg_echo('thewire:reply'), + 'href' => "thewire/reply/$entity->guid", + 'priority' => 150, + ); + $value[] = ElggMenuItem::factory($options); + } + + if ($entity->reply) { + $options = array( + 'name' => 'previous', + 'text' => elgg_echo('thewire:previous'), + 'href' => "thewire/previous/$entity->guid", + 'priority' => 160, + ); + $value[] = ElggMenuItem::factory($options); + } + + $options = array( + 'name' => 'thread', + 'text' => elgg_echo('thewire:thread'), + 'href' => "thewire/thread/$entity->wire_thread", + 'priority' => 170, + ); + $value[] = ElggMenuItem::factory($options); + + return $value; +} + /** * Runs unit tests for the wire */ @@ -362,25 +419,3 @@ function thewire_test($hook, $type, $value, $params) { $value[] = $CONFIG->pluginspath . 'thewire/tests/regex.php'; return $value; } - -/** - * Removes the access and edit items from the entity menu - * - * @param type $hook - * @param type $type - * @param type $value - * @param type $params - * @return array - */ -function thewire_remove_entity_menu_items($hook, $type, $value, $params) { - if (elgg_in_context('thewire')) { - $menu = elgg_extract('default', $value, array()); - foreach ($menu as $i => $entry) { - $name = $entry->getName(); - if ($name == 'access' || $name == 'edit') { - unset($value['default'][$i]); - } - } - return $value; - } -} \ No newline at end of file -- cgit v1.2.3