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