aboutsummaryrefslogtreecommitdiff
path: root/mod/likes
diff options
context:
space:
mode:
authorBrett Profitt <brett.profitt@gmail.com>2011-06-18 19:56:33 -0400
committerBrett Profitt <brett.profitt@gmail.com>2011-06-18 19:56:33 -0400
commitec7b94a64aef23b85866ecdac8e8acc712d29bb6 (patch)
treea108205c3fa0b694d8ce0ebaafd259480d6b530a /mod/likes
parentc80ba5aa03264dd64c20ed8ae222e87f9371a44d (diff)
parent2b68a4d217c35a5587c462620789493cf2804ba2 (diff)
downloadelgg-ec7b94a64aef23b85866ecdac8e8acc712d29bb6.tar.gz
elgg-ec7b94a64aef23b85866ecdac8e8acc712d29bb6.tar.bz2
Merge branch 'master' of github.com:Elgg/Elgg
Diffstat (limited to 'mod/likes')
-rw-r--r--mod/likes/actions/likes/add.php2
-rw-r--r--mod/likes/actions/likes/delete.php26
-rw-r--r--mod/likes/manifest.xml1
-rw-r--r--mod/likes/start.php37
-rw-r--r--mod/likes/views/default/likes/display.php3
5 files changed, 21 insertions, 48 deletions
diff --git a/mod/likes/actions/likes/add.php b/mod/likes/actions/likes/add.php
index f56493864..7ccb19d92 100644
--- a/mod/likes/actions/likes/add.php
+++ b/mod/likes/actions/likes/add.php
@@ -18,7 +18,7 @@ if (!$entity) {
forward(REFERER);
}
-// cannot like your own stuff
+// limit likes through a plugin hook (to prevent liking your own content for example)
if (!$entity->canAnnotate(0, 'likes')) {
// plugins should register the error message to explain why liking isn't allowed
forward(REFERER);
diff --git a/mod/likes/actions/likes/delete.php b/mod/likes/actions/likes/delete.php
index 867d5dfef..db3036bb4 100644
--- a/mod/likes/actions/likes/delete.php
+++ b/mod/likes/actions/likes/delete.php
@@ -4,26 +4,18 @@
*
*/
-// Ensure we're logged in
-if (!elgg_is_logged_in()) {
- forward();
-}
-
-// Make sure we can get the comment in question
-$annotation_id = (int) get_input('annotation_id');
-if ($likes = elgg_get_annotation_from_id($annotation_id)) {
-
- $entity = get_entity($likes->entity_guid);
-
- if ($likes->canEdit()) {
- $likes->delete();
+$likes = elgg_get_annotations(array(
+ 'guid' => (int) get_input('guid'),
+ 'annotation_owner_guid' => elgg_get_logged_in_user_guid(),
+ 'annotation_name' => 'likes',
+));
+if ($likes) {
+ if ($likes[0]->canEdit()) {
+ $likes[0]->delete();
system_message(elgg_echo("likes:deleted"));
forward(REFERER);
}
-
-} else {
- $url = "";
}
register_error(elgg_echo("likes:notdeleted"));
-forward(REFERER); \ No newline at end of file
+forward(REFERER);
diff --git a/mod/likes/manifest.xml b/mod/likes/manifest.xml
index abd3f7c76..f63c643a6 100644
--- a/mod/likes/manifest.xml
+++ b/mod/likes/manifest.xml
@@ -4,6 +4,7 @@
<author>Core developers</author>
<version>1.8</version>
<category>bundled</category>
+ <category>social</category>
<description>Enables users to like content on the site.</description>
<website>http://www.elgg.org/</website>
<copyright>See COPYRIGHT.txt</copyright>
diff --git a/mod/likes/start.php b/mod/likes/start.php
index 435e7a3ab..b2aa83260 100644
--- a/mod/likes/start.php
+++ b/mod/likes/start.php
@@ -1,7 +1,7 @@
<?php
/**
* Likes plugin
- *
+ *
*/
elgg_register_event_handler('init', 'system', 'likes_init');
@@ -50,32 +50,13 @@ function likes_river_menu_setup($hook, $type, $return, $params) {
$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_view('likes/display', array('entity' => $object)),
- 'is_action' => true,
- 'priority' => 100,
- );
- } else {
- // user has liked this
- $likes = elgg_get_annotations(array(
- 'guid' => $object->getGUID(),
- 'annotation_name' => 'likes',
- 'annotation_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_view('likes/display', array('entity' => $object)),
- 'is_action' => true,
- 'priority' => 100,
- );
- }
+ $options = array(
+ 'name' => 'likes',
+ 'href' => false,
+ 'text' => elgg_view('likes/display', array('entity' => $object)),
+ 'is_action' => true,
+ 'priority' => 100,
+ );
$return[] = ElggMenuItem::factory($options);
}
}
@@ -87,7 +68,7 @@ function likes_river_menu_setup($hook, $type, $return, $params) {
/**
* Count how many people have liked an entity.
*
- * @param ElggEntity $entity
+ * @param ElggEntity $entity
*
* @return int Number of likes
*/
diff --git a/mod/likes/views/default/likes/display.php b/mod/likes/views/default/likes/display.php
index cbfe46078..2dc50ddd0 100644
--- a/mod/likes/views/default/likes/display.php
+++ b/mod/likes/views/default/likes/display.php
@@ -28,8 +28,7 @@ if (elgg_is_logged_in() && $vars['entity']->canAnnotate(0, 'likes')) {
'annotation_name' => 'likes',
'owner_guid' => elgg_get_logged_in_user_guid()
);
- $likes = elgg_get_annotations($options);
- $url = elgg_get_site_url() . "action/likes/delete?annotation_id={$likes[0]->id}";
+ $url = elgg_get_site_url() . "action/likes/delete?guid={$guid}";
$params = array(
'href' => $url,
'text' => elgg_view_icon('thumbs-up-alt'),