aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/annotations.php23
-rw-r--r--engine/lib/elgglib.php35
2 files changed, 57 insertions, 1 deletions
diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php
index b18475d57..b7dc1b9d3 100644
--- a/engine/lib/annotations.php
+++ b/engine/lib/annotations.php
@@ -1250,6 +1250,29 @@ function get_annotation_url($id) {
return false;
}
+/**
+ * Check to see if a user has already created an annotation on an object
+ *
+ * @param ElggEntity $entity
+ * @return true | false
+ */
+function elgg_already_created_annotation($entity_guid, $annotation_type) {
+ global $CONFIG;
+ $entity_guid = (int)$entity_guid;
+ $annotation_type = sanitise_string($annotation_type);
+ $owner_guid = get_loggedin_userid();
+ $sql = "select a.id" .
+ " FROM {$CONFIG->dbprefix}annotations a, {$CONFIG->dbprefix}metastrings m " .
+ " WHERE a.owner_guid={$owner_guid} AND a.entity_guid={$entity_guid} " .
+ " AND a.name_id=m.id AND m.string='{$annotation_type}'";
+ //get the annotation type id
+ $check_annotation = get_data_row($sql);
+ //check to see if the user has already liked
+ if($check_annotation)
+ return true;
+ else
+ return false;
+}
/**
* Register an annotation url handler.
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index 7691ca5bb..fb61b7d10 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -1002,7 +1002,38 @@ function get_submenu() {
return $submenu_total;
}
-
+/**
+ * Automatically views likes and a like input relating to the given entity
+ *
+ * @param ElggEntity $entity The entity to like
+ * @return string|false The HTML (etc) for the likes, or false on failure
+ */
+function elgg_view_likes($entity){
+ if (!($entity instanceof ElggEntity)) {
+ return false;
+ }
+ if ($likes = trigger_plugin_hook('likes',$entity->getType(),array('entity' => $entity),false)) {
+ return $likes;
+ } else {
+ //display the form
+ $likes = elgg_view('likes/forms/edit',array('entity' => $entity));
+ return $likes;
+ }
+}
+/**
+ * Count the number of likes attached to an entity
+ *
+ * @param ElggEntity $entity
+ * @return int Number of likes
+ */
+function elgg_count_likes($entity) {
+ if ($likeno = trigger_plugin_hook('likes:count', $entity->getType(),
+ array('entity' => $entity), false)) {
+ return $likeno;
+ } else {
+ return count_annotations($entity->getGUID(), "", "", "likes");
+ }
+}
/**
* Automatically views comments and a comment form relating to the given entity
@@ -2901,6 +2932,8 @@ function elgg_boot() {
// Actions
register_action('comments/add');
register_action('comments/delete');
+ register_action('likes/add');
+ register_action('likes/delete');
elgg_view_register_simplecache('css');
elgg_view_register_simplecache('js/friendsPickerv1');