aboutsummaryrefslogtreecommitdiff
path: root/views/default/core/likes/display.php
blob: 01479692865c3d3fe66da03825c9abfa2c27a561 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?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_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(
			'href' => $url,
			'text' => elgg_view_icon('likes'),
			'title' => elgg_echo('likes:likethis'),
			'is_action' => true,
		);
		$likes_button = 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_view_icon('liked'),
			'title' => elgg_echo('likes:remove'),
			'is_action' => true,
		);
		$likes_button = elgg_view('output/url', $params);
	}
}

$list = '';
$num_of_likes = $vars['entity']->countLikes();
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-module elgg-module-popup elgg-likes-list hidden clearfix'>";
	$list .= elgg_list_annotations(array('guid' => $guid, 'annotation_name' => 'likes', 'limit' => 99));
	$list .= "</div>";
}

echo elgg_view_image_block($likes_button, $list);