aboutsummaryrefslogtreecommitdiff
path: root/views/default/core
diff options
context:
space:
mode:
Diffstat (limited to 'views/default/core')
-rw-r--r--views/default/core/likes/display.php61
-rw-r--r--views/default/core/river/controls.php24
2 files changed, 83 insertions, 2 deletions
diff --git a/views/default/core/likes/display.php b/views/default/core/likes/display.php
new file mode 100644
index 000000000..bd0a8fa95
--- /dev/null
+++ b/views/default/core/likes/display.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Elgg likes display
+ *
+ * @package Elgg
+ *
+ * @uses $vars['entity']
+ */
+
+if (!isset($vars['entity'])) {
+ return true;
+}
+
+$guid = $vars['entity']->getGUID();
+
+// check to see if the user has already liked this
+if (!elgg_annotation_exists($guid, 'likes')) {
+ $url = elgg_get_site_url() . "action/likes/add?guid={$guid}";
+ $params = array(
+ 'href' => $url,
+ 'text' => '<span class="elgg-icon elgg-icon-likes"></span>',
+ 'title' => elgg_echo('likes:likethis'),
+ 'is_action' => true,
+ 'encode_text' => false,
+ );
+ $likes_button = elgg_view('output/url', $params);
+} else {
+ $likes = get_annotations($guid, '', '', 'likes', '', get_loggedin_userid());
+ $url = elgg_get_site_url() . "action/likes/delete?annotation_id={$likes[0]->id}";
+ $params = array(
+ 'href' => $url,
+ 'text' => "<span class=\"elgg-icon elgg-icon-liked\"></span>",
+ 'title' => elgg_echo('likes:remove'),
+ 'is_action' => true,
+ 'encode_text' => false,
+ );
+ $likes_button = elgg_view('output/url', $params);
+}
+
+$list = '';
+$num_of_likes = elgg_count_likes($vars['entity']);
+if ($num_of_likes) {
+ // display the number of likes
+ if ($num_of_likes == 1) {
+ $likes_string = elgg_echo('likes:userlikedthis');
+ } else {
+ $likes_string = elgg_echo('likes:userslikedthis');
+ }
+ $params = array(
+ 'text' => "$num_of_likes $likes_string",
+ 'title' => elgg_echo('likes:see'),
+ 'class' => 'elgg-like-toggle',
+ );
+ $list = elgg_view('output/url', $params);
+ $list .= "<div class='elgg-likes-list hidden clearfix'>";
+ $list .= list_annotations($guid, 'likes', 99);
+ $list .= "</div>";
+}
+
+echo $likes_button;
+echo $list;
diff --git a/views/default/core/river/controls.php b/views/default/core/river/controls.php
index e239a2adb..66fbc5059 100644
--- a/views/default/core/river/controls.php
+++ b/views/default/core/river/controls.php
@@ -9,7 +9,7 @@
$object = $vars['item']->getObjectEntity();
if (isloggedin()) {
- // comments and non-objects cannot be commented on
+ // comments and non-objects cannot be commented on or liked
if ($object->getType() == 'object' && $vars['item']->annotation_id == 0) {
$params = array(
'href' => '#',
@@ -18,6 +18,26 @@ if (isloggedin()) {
'internalid' => "elgg-toggler-{$object->getGUID()}",
);
echo elgg_view('output/url', $params);
- //echo elgg_view('forms/likes/link', array('entity' => $object));
+
+ // 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 {
+ $likes = get_annotations($guid, '', '', 'likes', '', get_loggedin_userid());
+ $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);
+ }
}
+
} \ No newline at end of file