]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #3025 added back thewire's entity menu items
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sun, 20 Mar 2011 19:47:57 +0000 (19:47 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sun, 20 Mar 2011 19:47:57 +0000 (19:47 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8782 36083f99-b078-4883-b0ff-0f9b5a30f544

mod/thewire/start.php

index c87831beef0b5998011fce36b47c9ed2d143c8d6..0b2265082f1f4426be39525eea61e0f4d7a2746f 100644 (file)
@@ -27,8 +27,8 @@ function thewire_init() {
        $item = new ElggMenuItem('thewire', elgg_echo('thewire'), 'thewire/all');\r
        elgg_register_menu_item('site', $item);\r
 \r
-       // remove entity menu items edit and access because they don't apply here.\r
-       elgg_register_plugin_hook_handler('prepare', 'menu:entity', 'thewire_remove_entity_menu_items');\r
+       // remove edit and access and add thread, reply, view previous\r
+       elgg_register_plugin_hook_handler('register', 'menu:entity', 'thewire_setup_entity_menu_items');\r
        \r
        // Extend system CSS with our own styles, which are defined in the thewire/css view\r
        elgg_extend_view('css', 'thewire/css');\r
@@ -354,6 +354,63 @@ function thewire_get_parent($post_guid) {
        return null;\r
 }\r
 \r
+/**\r
+ * Sets up the entity menu for thewire\r
+ *\r
+ * Adds reply, thread, and view previous links. Removes edit and access.\r
+ *\r
+ * @param string $hook\r
+ * @param string $type\r
+ * @param array $value\r
+ * @param array $params\r
+ * @return array\r
+ */\r
+function thewire_setup_entity_menu_items($hook, $type, $value, $params) {\r
+       $handler = elgg_extract('handler', $params, false);\r
+       if ($handler != 'thewire') {\r
+               return $value;\r
+       }\r
+\r
+       foreach ($value as $index => $item) {\r
+               $name = $item->getName();\r
+               if ($name == 'access' || $name == 'edit') {\r
+                       unset($value[$index]);\r
+               }\r
+       }\r
+\r
+       $entity = $params['entity'];\r
+\r
+       if (elgg_is_logged_in()) {\r
+               $options = array(\r
+                       'name' => 'reply',\r
+                       'text' => elgg_echo('thewire:reply'),\r
+                       'href' => "thewire/reply/$entity->guid",\r
+                       'priority' => 150,\r
+               );\r
+               $value[] = ElggMenuItem::factory($options);\r
+       }\r
+\r
+       if ($entity->reply) {\r
+               $options = array(\r
+                       'name' => 'previous',\r
+                       'text' => elgg_echo('thewire:previous'),\r
+                       'href' => "thewire/previous/$entity->guid",\r
+                       'priority' => 160,\r
+               );\r
+               $value[] = ElggMenuItem::factory($options);\r
+       }\r
+\r
+       $options = array(\r
+               'name' => 'thread',\r
+               'text' => elgg_echo('thewire:thread'),\r
+               'href' => "thewire/thread/$entity->wire_thread",\r
+               'priority' => 170,\r
+       );\r
+       $value[] = ElggMenuItem::factory($options);\r
+\r
+       return $value;\r
+}\r
+\r
 /**\r
  * Runs unit tests for the wire\r
  */\r
@@ -362,25 +419,3 @@ function thewire_test($hook, $type, $value, $params) {
        $value[] = $CONFIG->pluginspath . 'thewire/tests/regex.php';\r
        return $value;\r
 }\r
-\r
-/**\r
- * Removes the access and edit items from the entity menu\r
- *\r
- * @param type $hook\r
- * @param type $type\r
- * @param type $value\r
- * @param type $params\r
- * @return array\r
- */\r
-function thewire_remove_entity_menu_items($hook, $type, $value, $params) {\r
-       if (elgg_in_context('thewire')) {\r
-               $menu = elgg_extract('default', $value, array());\r
-               foreach ($menu as $i => $entry) {\r
-                       $name = $entry->getName();\r
-                       if ($name == 'access' || $name == 'edit') {\r
-                               unset($value['default'][$i]);\r
-                       }\r
-               }\r
-               return $value;\r
-       }\r
-}
\ No newline at end of file