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