diff options
-rw-r--r-- | engine/lib/river.php | 54 | ||||
-rw-r--r-- | views/default/river/item/controls.php | 44 |
2 files changed, 55 insertions, 43 deletions
diff --git a/engine/lib/river.php b/engine/lib/river.php index 3a351805e..656b496b5 100644 --- a/engine/lib/river.php +++ b/engine/lib/river.php @@ -506,6 +506,58 @@ function update_river_access_by_object($object_guid, $access_id) { } /** + * Add the comment and like links to river actions menu + */ +function elgg_river_add_menu_items($hook, $type, $return, $params) { + if (elgg_is_logged_in()) { + $item = $params['item']; + $object = $item->getObjectEntity(); + // comments and non-objects cannot be commented on or liked + if ($item->annotation_id == 0) { + // comments + if ($object->canComment()) { + $options = array( + 'name' => 'comment', + 'href' => "#comments-add-$object->guid", + 'text' => elgg_echo('generic_comments:text'), + 'class' => "elgg-toggler", + ); + $return[] = ElggMenuItem::factory($options); + } + + // like this + if ($object->canAnnotate(0, 'likes')) { + if (!elgg_annotation_exists($object->getGUID(), 'likes')) { + $url = "action/likes/add?guid={$object->getGUID()}"; + $options = array( + 'name' => 'like', + 'href' => $url, + 'text' => elgg_echo('likes:likethis'), + 'is_action' => true, + ); + } else { + $likes = elgg_get_annotations(array( + 'guid' => $guid, + 'annotation_name' => 'likes', + 'owner_guid' => elgg_get_logged_in_user_guid() + )); + $url = elgg_get_site_url() . "action/likes/delete?annotation_id={$likes[0]->id}"; + $options = array( + 'name' => 'like', + 'href' => $url, + 'text' => elgg_echo('likes:remove'), + 'is_action' => true, + ); + } + $return[] = ElggMenuItem::factory($options); + } + } + } + + return $return; +} + +/** * Page handler for activiy * * @param array $page @@ -534,6 +586,8 @@ function elgg_river_init() { elgg_register_page_handler('activity', 'elgg_river_page_handler'); $item = new ElggMenuItem('activity', elgg_echo('activity'), 'pg/activity'); elgg_register_menu_item('site', $item); + + elgg_register_plugin_hook_handler('register', 'menu:river', 'elgg_river_add_menu_items'); } elgg_register_event_handler('init', 'system', 'elgg_river_init'); diff --git a/views/default/river/item/controls.php b/views/default/river/item/controls.php index 468983329..d3f8c6fc0 100644 --- a/views/default/river/item/controls.php +++ b/views/default/river/item/controls.php @@ -2,49 +2,7 @@ /** * Controls on an river item * - * * @uses $vars['item'] */ -$object = $vars['item']->getObjectEntity(); - -if (elgg_is_logged_in()) { - // comments and non-objects cannot be commented on or liked - if ($vars['item']->annotation_id == 0) { - // comments - if ($object->canComment()) { - $params = array( - 'href' => "#comments-add-$object->guid", - 'text' => elgg_echo('generic_comments:text'), - 'class' => "elgg-toggler", - ); - echo elgg_view('output/url', $params); - } - - // like this - if ($object->canAnnotate(0, 'likes')) { - if (!elgg_annotation_exists($object->getGUID(), 'likes')) { - $url = "action/likes/add?guid={$object->getGUID()}"; - $params = array( - 'href' => $url, - 'text' => elgg_echo('likes:likethis'), - 'is_action' => true, - ); - } else { - $likes = elgg_get_annotations(array( - 'guid' => $guid, - 'annotation_name' => 'likes', - 'owner_guid' => elgg_get_logged_in_user_guid() - )); - $url = elgg_get_site_url() . "action/likes/delete?annotation_id={$likes[0]->id}"; - $params = array( - 'href' => $url, - 'text' => elgg_echo('likes:remove'), - 'is_action' => true, - ); - } - echo elgg_view('output/url', $params); - } - } - -}
\ No newline at end of file +echo elgg_view_menu('river', array('item' => $vars['item'])); |