friendica-addons/widgets/widget_like.php

71 lines
1.7 KiB
PHP
Raw Normal View History

2011-09-25 08:56:03 +00:00
<?php
2018-01-22 19:03:11 +00:00
use Friendica\Core\L10n;
2011-09-25 08:56:03 +00:00
function like_widget_name() {
return "Shows likes";
}
function like_widget_help() {
return "Search first item which contains <em>KEY</em> and print like/dislike count";
}
function like_widget_args(){
2018-01-15 13:15:33 +00:00
return ["KEY"];
2011-09-25 08:56:03 +00:00
}
function like_widget_size(){
2018-01-15 13:15:33 +00:00
return ['60px','20px'];
}
2011-09-25 08:56:03 +00:00
function like_widget_content(&$a, $conf){
$args = explode(",",$_GET['a']);
2018-01-15 13:15:33 +00:00
$baseq="SELECT COUNT(`item`.`id`) as `c`, `p`.`id`
2018-01-15 13:15:33 +00:00
FROM `item`,
(SELECT `i`.`id` FROM `item` as `i` WHERE
`i`.`visible` = 1 AND `i`.`deleted` = 0
2018-01-15 13:15:33 +00:00
AND (( `i`.`wall` = 1 AND `i`.`allow_cid` = ''
AND `i`.`allow_gid` = ''
AND `i`.`deny_cid` = ''
AND `i`.`deny_gid` = '' )
OR `i`.`uid` = %d )
AND `i`.`body` LIKE '%%%s%%' LIMIT 1) as `p`
WHERE `item`.`parent` = `p`.`id` ";
2018-01-15 13:15:33 +00:00
// count likes
$r = q( $baseq . "AND `item`.`verb` = 'http://activitystrea.ms/schema/1.0/like'",
intval($conf['uid']),
dbesc($args[0])
);
$likes = $r[0]['c'];
$iid = $r[0]['id'];
2018-01-15 13:15:33 +00:00
// count dislikes
$r = q( $baseq . "AND `item`.`verb` = 'http://purl.org/macgirvin/dfrn/1.0/dislike'",
intval($conf['uid']),
dbesc($args[0])
);
$dislikes = $r[0]['c'];
2018-01-15 13:15:33 +00:00
require_once("include/conversation.php");
2018-01-15 13:15:33 +00:00
$o = "";
2018-01-15 13:15:33 +00:00
2012-12-22 20:36:35 +00:00
# $t = file_get_contents( dirname(__file__). "/widget_like.tpl" );
$t = get_markup_template("widget_like.tpl", "addon/widgets/");
2018-01-15 13:15:33 +00:00
$o .= replace_macros($t, [
'$like' => $likes,
2018-01-22 19:03:11 +00:00
'$strlike' => sprintf(L10n::tt("%d person likes this", "%d people like this", $likes), $likes),
2018-01-15 13:15:33 +00:00
'$dislike' => $dislikes,
2018-01-22 19:03:11 +00:00
'$strdislike'=> sprintf(L10n::tt("%d person doesn't like this", "%d people don't like this", $dislikes), $dislikes),
2018-01-15 13:15:33 +00:00
'$baseurl' => $a->get_baseurl(),
2018-01-15 13:15:33 +00:00
]);
return $o;
2011-09-25 08:56:03 +00:00
}