}
}
- /**
- * 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.
*
/**
* 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
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');
);
$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);
- }
}
}
$return[] = ElggMenuItem::factory($options);
}
- // likes
- $options = array(
- 'name' => 'likes',
- 'text' => elgg_view_likes($entity),
- 'href' => false,
- 'priority' => 1000,
- );
- $return[] = ElggMenuItem::factory($options);
-
return $return;
}
+++ /dev/null
-<?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);
-
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.
*
'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',
*/
'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
*/
'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',
/**
* Elgg add like action
*
- * @package Elgg.Core
- * @subpackage Likes
*/
$entity_guid = (int) get_input('guid');
/**
* Elgg delete like action
*
- * @package Elgg.Core
- * @subpackage Likes
*/
// Ensure we're logged in
--- /dev/null
+<?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);
--- /dev/null
+<?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
--- /dev/null
+<?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');
+ }
+}
--- /dev/null
+<?php
+/**
+ * Likes CSS
+ */
+?>
+
+/* ***************************************
+ Likes
+*************************************** */
+.elgg-likes-list {
+ width: 345px;
+ position: absolute;
+}
$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,
);
$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,
);
}
$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) {
<?php
/**
* Likes river view
+ *
+ * @todo not finished
*/
+
$object = $vars['item']->getObjectEntity();
$comment = $vars['item']->getAnnotation();
.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;
margin: 0 0 0 10px;
}
-/* ***************************************
- Likes
-*************************************** */
-.elgg-likes-list {
- width: 345px;
- position: absolute;
-}
-
/* ***************************************
Tags
*************************************** */
.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;
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; }