From: cash Date: Wed, 9 Mar 2011 03:07:40 +0000 (+0000) Subject: Fixes #3058 pulls likes out as a plugin X-Git-Url: https://gitweb.fluxo.info/?a=commitdiff_plain;h=bdb5d2b95792782ebc379e3348cad1812c1980b4;p=lorea%2Felgg.git Fixes #3058 pulls likes out as a plugin git-svn-id: http://code.elgg.org/elgg/trunk@8639 36083f99-b078-4883-b0ff-0f9b5a30f544 --- 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 @@ -843,24 +843,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. * 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 @@ -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 @@ -1124,26 +1124,6 @@ function elgg_view_latest_comments($owner_guid, $type = 'object', $subtype = '', return elgg_view_module('aside', $title, $body); } -/** - * 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. * 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', @@ -986,25 +985,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 similarity index 97% rename from actions/likes/add.php rename to 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 similarity index 89% rename from actions/likes/delete.php rename to 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 @@ + '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 @@ + + + Likes + Core developers + 1.8 + bundled + Enables users to like content on the site. + http://www.elgg.org/ + See COPYRIGHT.txt + GNU Public License version 2 + + elgg_version + 2010030101 + + true + advanced + \ 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 @@ + '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 similarity index 100% rename from views/default/annotation/likes.php rename to 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 @@ + + +/* *************************************** + 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 similarity index 90% rename from views/default/core/likes/display.php rename to 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 similarity index 95% rename from views/default/river/annotation/likes/create.php rename to 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 @@ 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 @@ -251,14 +251,6 @@ margin: 0 0 0 10px; } -/* *************************************** - Likes -*************************************** */ -.elgg-likes-list { - width: 345px; - position: absolute; -} - /* *************************************** 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; }