Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added web service to like an entity

  • Loading branch information...
commit 05f85a5c171ab757653a186401057a069f5b895b 1 parent fec9022
@Tachyon authored
View
2  web_services/languages/en.php
@@ -22,6 +22,8 @@
'admin:utilities:web_services' => 'Web Services Tests',
'web_services:tests:instructions' => 'Run the unit tests for the web services plugin',
'web_services:tests:run' => 'Run tests',
+ 'web_services:likes' => 'Likes',
+ 'likes:notallowed' => 'Not allowed to like',
);
add_translation("en", $english);
View
56 web_services/lib/likes.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Elgg Webservices plugin
+ *
+ * @package Webservice
+ * @author Saket Saurabh
+ *
+ */
+
+ /**
+ * Web service to like an entity
+ *
+ * @param string $entity_guid guid of object to like
+ *
+ * @return bool
+ */
+function rest_likes_add($entity_guid) {
+ if (elgg_annotation_exists($entity_guid, 'likes')) {
+ return elgg_echo("likes:alreadyliked");
+ }
+ // Let's see if we can get an entity with the specified GUID
+ $entity = get_entity($entity_guid);
+ if (!$entity) {
+ return elgg_echo("likes:notfound");
+ }
+
+ // limit likes through a plugin hook (to prevent liking your own content for example)
+ if (!$entity->canAnnotate(0, 'likes')) {
+ return elgg_echo("likes:notallowed");
+ }
+
+ $user = elgg_get_logged_in_user_entity();
+ $annotation = create_annotation($entity->guid,
+ 'likes',
+ "likes",
+ "",
+ $user->guid,
+ $entity->access_id);
+
+ // tell user annotation didn't work if that is the case
+ if (!$annotation) {
+ return elgg_echo("likes:failure");
+ }
+ add_to_river('annotation/annotatelike', 'likes', $user->guid, $entity->guid, "", 0, $annotation);
+ return elgg_echo("likes:likes");
+}
+
+expose_function('likes.add',
+ "rest_likes_add",
+ array('entity_guid' => array ('type' => 'int'),
+ ),
+ "Add a like",
+ 'POST',
+ true,
+ false);
+
View
3  web_services/views/default/settings/web_services/edit.php
@@ -14,7 +14,8 @@
elgg_echo("web_services:wire") => 'wire',
elgg_echo("web_services:core") => 'core',
elgg_echo("web_services:group") => 'group',
- elgg_echo("web_services:file") => 'file')
+ elgg_echo("web_services:file") => 'file',
+ elgg_echo("web_services:likes") => 'likes'),
));
echo '</div>';
Please sign in to comment.
Something went wrong with that request. Please try again.