From 64be91148a881f65224c583b92c407205db24634 Mon Sep 17 00:00:00 2001 From: dave Date: Sun, 21 Mar 2010 16:22:19 +0000 Subject: generic like this functionality added git-svn-id: http://code.elgg.org/elgg/trunk@5456 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/annotations.php | 23 +++++++++++++++++++++++ engine/lib/elgglib.php | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) (limited to 'engine/lib') 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'); -- cgit v1.2.3