}
// 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);
}
}
/**
- * 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)
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.
*
'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',
$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(
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' => '#',
}
// 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);
+ }
}
}