]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
fixes #2885 #2569 likes controlled by canAnnotate() with plugin hook
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Mon, 21 Feb 2011 02:35:43 +0000 (02:35 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Mon, 21 Feb 2011 02:35:43 +0000 (02:35 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8382 36083f99-b078-4883-b0ff-0f9b5a30f544

actions/likes/add.php
engine/classes/ElggEntity.php
languages/en.php
views/default/core/likes/display.php
views/default/core/river/controls.php

index a59ccae2bdcd84ecfaad712d43864bb728d05de8..12eed2427a25eb8d4588d679d38fe2833a969f1d 100644 (file)
@@ -21,8 +21,8 @@ if (!$entity) {
 }
 
 // cannot like your own stuff
-if (elgg_get_logged_in_user_guid() == $entity->getOwnerGUID()) {
-       register_error(elgg_echo("likes:no_self_like"));
+if (!$entity->canAnnotate(0, 'likes')) {
+       // plugins should register the error message to explain why liking isn't allowed
        forward(REFERER);
 }
 
index 0298d6d6e6fec1218d2804e48d15f2bd46784e83..69401a7e5a10e8009bcfd7f7353c79efc885a1a2 100644 (file)
@@ -935,9 +935,9 @@ abstract class ElggEntity extends ElggData implements
        }
 
        /**
-        * Can a user comment on an entity
+        * Can a user comment on an entity?
         *
-        * @tip Can be overridden vy registering for the permissions_check:comment,
+        * @tip Can be overridden by registering for the permissions_check:comment,
         * <entity type> plugin hook.
         * 
         * @param int $user_guid User guid (default is logged in user)
@@ -956,6 +956,39 @@ abstract class ElggEntity extends ElggData implements
                return elgg_trigger_plugin_hook('permissions_check:comment', $this->type, $params, null);
        }
 
+       /**
+        * Can a user annotate an entity?
+        *
+        * @tip Can be overridden by registering for the permissions_check:annotate,
+        * <entity type> plugin hook.
+        *
+        * @tip If you want logged out users to annotate an object, do not call
+        * canAnnotate(). It's easier than using the plugin hook.
+        *
+        * @param int    $user_guid       User guid (default is logged in user)
+        * @param string $annotation_name The name of the annotation (default is unspecified)
+        *
+        * @return bool
+        */
+       public function canAnnotate($user_guid = 0, $annotation_name = '') {
+               if ($user_guid == 0) {
+                       $user_guid = elgg_get_logged_in_user_guid();
+               }
+               $user = get_entity($user_guid);
+
+               $return = true;
+               if (!$user) {
+                       $return = false;
+               }
+
+               $params = array(
+                       'entity' => $this,
+                       'user' => $user,
+                       'annotation_name' => $annotation_name,
+               );
+               return elgg_trigger_plugin_hook('permissions_check:annotate', $this->type, $params, $return);
+       }
+
        /**
         * Returns the access_id.
         *
index 59eedb9e1166437a92f96caeb35a8f907e8f4084..60eea1a651ddb135c3de8008958585a5b79d4393 100644 (file)
@@ -973,7 +973,6 @@ If you requested this click on the link below, otherwise ignore this email.
        'likes:deleted' => 'Your like has been removed',
        'likes:see' => 'See who else liked this',
        'likes:remove' => 'Unlike this',
-       'likes:no_self_like' => 'You cannot like your own content',
        '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',
index 28ffafcb4b72749531dfc3bdb265d9b39bf84d52..570c4d1ff8c59ff057e2113221f2867722d69ba8 100644 (file)
@@ -14,7 +14,7 @@ if (!isset($vars['entity'])) {
 $guid = $vars['entity']->getGUID();
 
 // check to see if the user has already liked this
-if (elgg_is_logged_in()) {
+if (elgg_is_logged_in() && $vars['entity']->canAnnotate(0, 'likes')) {
        if (!elgg_annotation_exists($guid, 'likes')) {
                $url = elgg_get_site_url() . "action/likes/add?guid={$guid}";
                $params = array(
index 615da7f9603cd4e50221a27820b50453bb68b94f..21ce8414ccfabca3c13af754d6943eb1e365c7f9 100644 (file)
@@ -11,6 +11,7 @@ $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' => '#',
@@ -22,28 +23,30 @@ if (elgg_is_logged_in()) {
                }
 
                // like this
-               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,
-                       );
-                       echo elgg_view('output/url', $params);
-               } else {
-                       $options = array(
-                               'guid' => $guid,
-                               '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}";
-                       $params = array(
-                               'href' => $url,
-                               'text' => elgg_echo('likes:remove'),
-                               'is_action' => true,
-                       );
-                       echo elgg_view('output/url', $params);
+               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,
+                               );
+                               echo elgg_view('output/url', $params);
+                       } else {
+                               $options = array(
+                                       'guid' => $guid,
+                                       '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}";
+                               $params = array(
+                                       'href' => $url,
+                                       'text' => elgg_echo('likes:remove'),
+                                       'is_action' => true,
+                               );
+                               echo elgg_view('output/url', $params);
+                       }
                }
        }