]> git.mxchange.org Git - friendica-addons.git/blob - widgets/widget_like.php
1fcc96b997116f9e6c70f80216e4c9ddd789f74b
[friendica-addons.git] / widgets / widget_like.php
1 <?php
2
3 use Friendica\Core\L10n;
4 use Friendica\Core\Renderer;
5 use Friendica\Database\DBA;
6
7 function like_widget_name() {
8         return "Shows likes";
9 }
10 function like_widget_help() {
11         return "Search first item which contains <em>KEY</em> and print like/dislike count";
12 }
13
14 function like_widget_args(){
15         return ["KEY"];
16 }
17
18 function like_widget_size(){
19         return ['60px','20px'];
20 }
21
22
23 function like_widget_content(&$a, $conf){
24         $args = explode(",",$_GET['a']);
25
26
27         $baseq="SELECT COUNT(`item`.`id`) as `c`, `p`.`id`
28                                         FROM `item`,
29                                                 (SELECT `i`.`id` FROM `item` as `i` WHERE
30                                                         `i`.`visible` = 1 AND `i`.`deleted` = 0
31                                                         AND (( `i`.`wall` = 1 AND `i`.`allow_cid` = ''
32                                                                         AND `i`.`allow_gid` = ''
33                                                                         AND `i`.`deny_cid`  = ''
34                                                                         AND `i`.`deny_gid`  = '' )
35                                                                   OR `i`.`uid` = %d )
36                                                         AND `i`.`body` LIKE '%%%s%%' LIMIT 1) as `p`
37                                         WHERE `item`.`parent` = `p`.`id` ";
38
39         // count likes
40         $r = q( $baseq . "AND `item`.`verb` = 'http://activitystrea.ms/schema/1.0/like'",
41                         intval($conf['uid']),
42                         DBA::escape($args[0])
43         );
44         $likes = $r[0]['c'];
45         $iid = $r[0]['id'];
46
47         // count dislikes
48         $r = q( $baseq . "AND `item`.`verb` = 'http://purl.org/macgirvin/dfrn/1.0/dislike'",
49                         intval($conf['uid']),
50                         DBA::escape($args[0])
51         );
52         $dislikes = $r[0]['c'];
53
54
55         $o = "";
56
57 #       $t = file_get_contents( dirname(__file__). "/widget_like.tpl" );
58         $t = Renderer::getMarkupTemplate("widget_like.tpl", "addon/widgets/");
59         $o .= Renderer::replaceMacros($t, [
60                 '$like'         => $likes,
61                 '$strlike'      => L10n::tt("%d person likes this", "%d people like this", $likes),
62
63                 '$dislike'      => $dislikes,
64                 '$strdislike'=> L10n::tt("%d person doesn't like this", "%d people don't like this", $dislikes),
65         ]);
66
67         return $o;
68 }