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