diff options
author | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-03-09 03:07:40 +0000 |
---|---|---|
committer | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-03-09 03:07:40 +0000 |
commit | bdb5d2b95792782ebc379e3348cad1812c1980b4 (patch) | |
tree | c923d740327b3aeb62a24246f3725ced8677a5f7 | |
parent | 9ea30ea494cea4c950894a0ac1131eefda10868b (diff) | |
download | elgg-bdb5d2b95792782ebc379e3348cad1812c1980b4.tar.gz elgg-bdb5d2b95792782ebc379e3348cad1812c1980b4.tar.bz2 |
Fixes #3058 pulls likes out as a plugin
git-svn-id: http://code.elgg.org/elgg/trunk@8639 36083f99-b078-4883-b0ff-0f9b5a30f544
20 files changed, 174 insertions, 136 deletions
diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php index 69401a7e5..bfb7ce063 100644 --- a/engine/classes/ElggEntity.php +++ b/engine/classes/ElggEntity.php @@ -844,24 +844,6 @@ abstract class ElggEntity extends ElggData implements } /** - * Count how many people have liked this entity. - * - * @return int Number of likes - * @since 1.8.0 - */ - function countLikes() { - $type = $this->getType(); - $params = array('entity' => $this); - $number = elgg_trigger_plugin_hook('likes:count', $type, $params, false); - - if ($number) { - return $number; - } else { - return $this->getAnnotationCalculation('likes', 'count'); - } - } - - /** * Gets an array of entities with a relationship to this entity. * * @param string $relationship Relationship type (eg "friends") diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 3cc4ddb1d..c97fa433c 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -1795,7 +1795,7 @@ function elgg_walled_garden() { /** * Elgg's main init. * - * Handles core actions for comments and likes, the JS pagehandler, and the shutdown function. + * Handles core actions for comments, the JS pagehandler, and the shutdown function. * * @elgg_event_handler init system * @return void @@ -1805,8 +1805,6 @@ function elgg_init() { elgg_register_action('comments/add'); elgg_register_action('comments/delete'); - elgg_register_action('likes/add'); - elgg_register_action('likes/delete'); elgg_register_page_handler('js', 'js_page_handler'); elgg_register_page_handler('css', 'css_page_handler'); diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php index b79156986..8c71de03a 100644 --- a/engine/lib/navigation.php +++ b/engine/lib/navigation.php @@ -226,35 +226,6 @@ function elgg_river_menu_setup($hook, $type, $return, $params) { ); $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, - 'priority' => 100, - ); - } 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, - 'priority' => 100, - ); - } - $return[] = ElggMenuItem::factory($options); - } } } @@ -303,15 +274,6 @@ function elgg_entity_menu_setup($hook, $type, $return, $params) { $return[] = ElggMenuItem::factory($options); } - // likes - $options = array( - 'name' => 'likes', - 'text' => elgg_view_likes($entity), - 'href' => false, - 'priority' => 1000, - ); - $return[] = ElggMenuItem::factory($options); - return $return; } diff --git a/engine/lib/upgrades/2010121702.php b/engine/lib/upgrades/2010121702.php deleted file mode 100644 index 1c4a931b1..000000000 --- a/engine/lib/upgrades/2010121702.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Change the location of the likes river view - */ - -$query = "UPDATE {$CONFIG->dbprefix}river - SET view='river/annotation/likes/create', action_type='create' - WHERE view='annotation/annotatelike' AND action_type='likes'"; -update_data($query); - diff --git a/engine/lib/views.php b/engine/lib/views.php index 09325c2c0..905458a9a 100644 --- a/engine/lib/views.php +++ b/engine/lib/views.php @@ -1125,26 +1125,6 @@ function elgg_view_latest_comments($owner_guid, $type = 'object', $subtype = '', } /** - * Returns the HTML for "likes" on entities. - * - * @param ElggEntity $entity The entity to like - * - * @return string|false The HTML for the likes, or false on failure - * - * @since 1.8.0 - * @see @elgg_view core/likes/display - */ -function elgg_view_likes($entity) { - if (!($entity instanceof ElggEntity)) { - return false; - } - - $params = array('entity' => $entity); - - return elgg_view('core/likes/display', $params); -} - -/** * Wrapper function for the image block display pattern. * * Fixed width media on the side (image, icon, flash, etc.). diff --git a/languages/en.php b/languages/en.php index f827c6d51..5393c356a 100644 --- a/languages/en.php +++ b/languages/en.php @@ -708,7 +708,6 @@ $english = array( 'river:select' => 'Show %s', 'river:comments:more' => '+%u more', 'river:generic_comment' => 'commented on %s %s', - 'river:likes' => 'likes %s %s', 'members:label:newest' => 'Newest', 'members:label:popular' => 'Popular', @@ -987,25 +986,6 @@ If you requested this click on the link below, otherwise ignore this email. 'xmlrpc:noinputdata' => "Input data missing", /** - * Likes - **/ - 'likes:this' => 'liked this', - 'likes:deleted' => 'Your like has been removed', - 'likes:see' => 'See who liked this', - 'likes:remove' => 'Unlike this', - 'likes:notdeleted' => 'There was a problem removing your like', - 'likes:likes' => 'You now like this item', - 'likes:failure' => 'There was a problem liking this item', - 'likes:alreadyliked' => 'You have already liked this item', - 'likes:notfound' => 'The item you are trying to like cannot be found', - 'likes:likethis' => 'Like this', - 'likes:userlikedthis' => 'user liked this', - 'likes:userslikedthis' => 'users like this', - 'likes:river:annotate' => 'likes', - 'likes:email:body' => '%s liked %s', - 'likes:email:subject' => 'A user liked one of your objects', - -/** * Comments */ diff --git a/mod/developers/views/default/theme_preview/icons.php b/mod/developers/views/default/theme_preview/icons.php index be444adb8..8178a9da7 100644 --- a/mod/developers/views/default/theme_preview/icons.php +++ b/mod/developers/views/default/theme_preview/icons.php @@ -15,8 +15,8 @@ 'friends' => 'Friends', 'help' => 'Help', 'delete' => 'Delete', - 'likes' => 'Likes', - 'liked' => 'Liked', + 'thumbs-up' => 'Thumbs Up', + 'thumbs-up-alt' => 'Thumbs Up Alternate', 'following' => 'Following', 'dragger' => 'Dragger', 'rss' => 'RSS', diff --git a/actions/likes/add.php b/mod/likes/actions/likes/add.php index 12eed2427..f56493864 100644 --- a/actions/likes/add.php +++ b/mod/likes/actions/likes/add.php @@ -2,8 +2,6 @@ /** * Elgg add like action * - * @package Elgg.Core - * @subpackage Likes */ $entity_guid = (int) get_input('guid'); diff --git a/actions/likes/delete.php b/mod/likes/actions/likes/delete.php index 7d535052d..867d5dfef 100644 --- a/actions/likes/delete.php +++ b/mod/likes/actions/likes/delete.php @@ -2,8 +2,6 @@ /** * Elgg delete like action * - * @package Elgg.Core - * @subpackage Likes */ // Ensure we're logged in diff --git a/mod/likes/languages/en.php b/mod/likes/languages/en.php new file mode 100644 index 000000000..52e2d4160 --- /dev/null +++ b/mod/likes/languages/en.php @@ -0,0 +1,25 @@ +<?php +/** + * Likes English language file + */ + +$english = array( + 'likes:this' => 'liked this', + 'likes:deleted' => 'Your like has been removed', + 'likes:see' => 'See who liked this', + 'likes:remove' => 'Unlike this', + 'likes:notdeleted' => 'There was a problem removing your like', + 'likes:likes' => 'You now like this item', + 'likes:failure' => 'There was a problem liking this item', + 'likes:alreadyliked' => 'You have already liked this item', + 'likes:notfound' => 'The item you are trying to like cannot be found', + 'likes:likethis' => 'Like this', + 'likes:userlikedthis' => 'user liked this', + 'likes:userslikedthis' => 'users like this', + 'likes:river:annotate' => 'likes', + 'likes:email:body' => '%s liked %s', + 'likes:email:subject' => 'A user liked one of your objects', + 'river:likes' => 'likes %s %s', +); + +add_translation('en', $english); diff --git a/mod/likes/manifest.xml b/mod/likes/manifest.xml new file mode 100644 index 000000000..abd3f7c76 --- /dev/null +++ b/mod/likes/manifest.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8"> + <name>Likes</name> + <author>Core developers</author> + <version>1.8</version> + <category>bundled</category> + <description>Enables users to like content on the site.</description> + <website>http://www.elgg.org/</website> + <copyright>See COPYRIGHT.txt</copyright> + <license>GNU Public License version 2</license> + <requires> + <type>elgg_version</type> + <version>2010030101</version> + </requires> + <activate_on_install>true</activate_on_install> + <admin_interface>advanced</admin_interface> +</plugin_manifest>
\ No newline at end of file diff --git a/mod/likes/start.php b/mod/likes/start.php new file mode 100644 index 000000000..97823087a --- /dev/null +++ b/mod/likes/start.php @@ -0,0 +1,104 @@ +<?php +/** + * Likes plugin + * + */ + +elgg_register_event_handler('init', 'system', 'likes_init'); + +function likes_init() { + + elgg_extend_view('css/elgg', 'likes/css'); + + // registered with priority < 500 so other plugins can remove likes + elgg_register_plugin_hook_handler('register', 'menu:river', 'likes_river_menu_setup', 400); + elgg_register_plugin_hook_handler('register', 'menu:entity', 'likes_entity_menu_setup', 400); + + $actions_base = elgg_get_plugins_path() . 'likes/actions/likes'; + elgg_register_action('likes/add', "$actions_base/add.php"); + elgg_register_action('likes/delete', "$actions_base/delete.php"); +} + +/** + * Add likes to entity menu at end of the menu + */ +function likes_entity_menu_setup($hook, $type, $return, $params) { + if (elgg_in_context('widgets')) { + return $return; + } + + $entity = $params['entity']; + + // likes + $options = array( + 'name' => 'likes', + 'text' => elgg_view('likes/display', array('entity' => $entity)), + 'href' => false, + 'priority' => 1000, + ); + $return[] = ElggMenuItem::factory($options); + + return $return; +} + +/** + * Add a like button to river actions + */ +function likes_river_menu_setup($hook, $type, $return, $params) { + if (elgg_is_logged_in()) { + $item = $params['item']; + $object = $item->getObjectEntity(); + if (!elgg_in_context('widgets') && $item->annotation_id == 0) { + if ($object->canAnnotate(0, 'likes')) { + if (!elgg_annotation_exists($object->getGUID(), 'likes')) { + // user has not liked this yet + $url = "action/likes/add?guid={$object->getGUID()}"; + $options = array( + 'name' => 'like', + 'href' => $url, + 'text' => elgg_echo('likes:likethis'), + 'is_action' => true, + 'priority' => 100, + ); + } else { + // user has liked this + $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, + 'priority' => 100, + ); + } + $return[] = ElggMenuItem::factory($options); + } + } + } + + return $return; +} + +/** + * Count how many people have liked an entity. + * + * @param ElggEntity $entity + * + * @return int Number of likes + */ +function likes_count($entity) { + $type = $entity->getType(); + $params = array('entity' => $entity); + $number = elgg_trigger_plugin_hook('likes:count', $type, $params, false); + + if ($number) { + return $number; + } else { + return $entity->countAnnotations('likes'); + } +} diff --git a/views/default/annotation/likes.php b/mod/likes/views/default/annotation/likes.php index e1ae20818..e1ae20818 100644 --- a/views/default/annotation/likes.php +++ b/mod/likes/views/default/annotation/likes.php diff --git a/mod/likes/views/default/likes/css.php b/mod/likes/views/default/likes/css.php new file mode 100644 index 000000000..cb0334b7c --- /dev/null +++ b/mod/likes/views/default/likes/css.php @@ -0,0 +1,13 @@ +<?php +/** + * Likes CSS + */ +?> + +/* *************************************** + Likes +*************************************** */ +.elgg-likes-list { + width: 345px; + position: absolute; +} diff --git a/views/default/core/likes/display.php b/mod/likes/views/default/likes/display.php index b04630e95..00f6c5a34 100644 --- a/views/default/core/likes/display.php +++ b/mod/likes/views/default/likes/display.php @@ -19,7 +19,7 @@ if (elgg_is_logged_in() && $vars['entity']->canAnnotate(0, 'likes')) { $url = elgg_get_site_url() . "action/likes/add?guid={$guid}"; $params = array( 'href' => $url, - 'text' => elgg_view_icon('likes'), + 'text' => elgg_view_icon('thumbs-up'), 'title' => elgg_echo('likes:likethis'), 'is_action' => true, ); @@ -34,7 +34,7 @@ if (elgg_is_logged_in() && $vars['entity']->canAnnotate(0, 'likes')) { $url = elgg_get_site_url() . "action/likes/delete?annotation_id={$likes[0]->id}"; $params = array( 'href' => $url, - 'text' => elgg_view_icon('liked'), + 'text' => elgg_view_icon('thumbs-up-alt'), 'title' => elgg_echo('likes:remove'), 'is_action' => true, ); @@ -43,7 +43,7 @@ if (elgg_is_logged_in() && $vars['entity']->canAnnotate(0, 'likes')) { } $list = ''; -$num_of_likes = $vars['entity']->countLikes(); +$num_of_likes = likes_count($vars['entity']); if ($num_of_likes) { // display the number of likes if ($num_of_likes == 1) { diff --git a/views/default/river/annotation/likes/create.php b/mod/likes/views/default/river/annotation/likes/create.php index 374f4a381..463fe5049 100644 --- a/views/default/river/annotation/likes/create.php +++ b/mod/likes/views/default/river/annotation/likes/create.php @@ -1,7 +1,10 @@ <?php /** * Likes river view + * + * @todo not finished */ + $object = $vars['item']->getObjectEntity(); $comment = $vars['item']->getAnnotation(); diff --git a/views/default/css/admin.php b/views/default/css/admin.php index 0da86967b..5d921021a 100644 --- a/views/default/css/admin.php +++ b/views/default/css/admin.php @@ -1169,15 +1169,15 @@ ul.admin_plugins { .elgg-icon-delete:hover { background-position: -199px -15px; } -.elgg-icon-likes { +.elgg-icon-thumbs-up { background-position: 0px -101px; width: 20px; height: 20px; } -.elgg-icon-likes:hover { +.elgg-icon-thumbs-up:hover { background-position: 0px -131px; } -.elgg-icon-liked { +.elgg-icon-thumbs-up-alt { background-position: 0px -131px; width: 20px; height: 20px; diff --git a/views/default/css/elements/components.php b/views/default/css/elements/components.php index 5818c4bf9..f44d1ce7d 100644 --- a/views/default/css/elements/components.php +++ b/views/default/css/elements/components.php @@ -252,14 +252,6 @@ } /* *************************************** - Likes -*************************************** */ -.elgg-likes-list { - width: 345px; - position: absolute; -} - -/* *************************************** Tags *************************************** */ .elgg-tags { diff --git a/views/default/css/elements/icons.php b/views/default/css/elements/icons.php index 68a38ed9a..64a1d78ca 100644 --- a/views/default/css/elements/icons.php +++ b/views/default/css/elements/icons.php @@ -38,15 +38,15 @@ .elgg-icon-delete:hover { background-position: -199px -15px; } -.elgg-icon-likes { +.elgg-icon-thumbs-up { background-position: 0px -101px; width: 20px; height: 20px; } -.elgg-icon-likes:hover { +.elgg-icon-thumbs-up:hover { background-position: 0px -131px; } -.elgg-icon-liked { +.elgg-icon-thumbs-up-alt { background-position: 0px -131px; width: 20px; height: 20px; diff --git a/views/default/css/ie.php b/views/default/css/ie.php index 32e7a77aa..6760d3886 100644 --- a/views/default/css/ie.php +++ b/views/default/css/ie.php @@ -24,10 +24,6 @@ text-align: right; } -.likes-list {display:none;} -.likes-list-holder .likes-list {top:20px !important;} /* position likes list below link in IE to prevent clipping */ -.elgg-likes-user .entity-metadata .elgg-button-delete {float:none;} - /* profile */ .elgg-tabs.profile .profile_name {margin-left: -260px;} #profile_content .river_comment_form.hidden .input-text { width:510px; } |