2011-09-25 04:56:03 -04:00
|
|
|
<?php
|
|
|
|
|
2018-01-22 14:03:11 -05:00
|
|
|
use Friendica\Core\L10n;
|
2018-10-31 10:55:15 -04:00
|
|
|
use Friendica\Core\Renderer;
|
2018-07-23 18:46:16 -04:00
|
|
|
use Friendica\Database\DBA;
|
2020-01-18 17:00:52 -05:00
|
|
|
use Friendica\DI;
|
2018-01-22 14:03:11 -05:00
|
|
|
|
2011-09-25 04:56:03 -04: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 08:15:33 -05:00
|
|
|
return ["KEY"];
|
2011-09-25 04:56:03 -04:00
|
|
|
}
|
|
|
|
|
2011-10-19 05:43:45 -04:00
|
|
|
function like_widget_size(){
|
2018-01-15 08:15:33 -05:00
|
|
|
return ['60px','20px'];
|
2011-10-19 05:43:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-25 04:56:03 -04:00
|
|
|
function like_widget_content(&$a, $conf){
|
|
|
|
$args = explode(",",$_GET['a']);
|
2018-01-15 08:15:33 -05:00
|
|
|
|
|
|
|
|
2011-10-18 11:18:58 -04:00
|
|
|
$baseq="SELECT COUNT(`item`.`id`) as `c`, `p`.`id`
|
2018-01-15 08:15:33 -05:00
|
|
|
FROM `item`,
|
|
|
|
(SELECT `i`.`id` FROM `item` as `i` WHERE
|
2011-10-18 11:18:58 -04:00
|
|
|
`i`.`visible` = 1 AND `i`.`deleted` = 0
|
2018-01-15 08:15:33 -05:00
|
|
|
AND (( `i`.`wall` = 1 AND `i`.`allow_cid` = ''
|
|
|
|
AND `i`.`allow_gid` = ''
|
|
|
|
AND `i`.`deny_cid` = ''
|
|
|
|
AND `i`.`deny_gid` = '' )
|
2011-10-18 11:18:58 -04:00
|
|
|
OR `i`.`uid` = %d )
|
|
|
|
AND `i`.`body` LIKE '%%%s%%' LIMIT 1) as `p`
|
|
|
|
WHERE `item`.`parent` = `p`.`id` ";
|
2018-01-15 08:15:33 -05:00
|
|
|
|
2011-10-18 11:18:58 -04:00
|
|
|
// count likes
|
|
|
|
$r = q( $baseq . "AND `item`.`verb` = 'http://activitystrea.ms/schema/1.0/like'",
|
|
|
|
intval($conf['uid']),
|
2018-07-21 09:13:02 -04:00
|
|
|
DBA::escape($args[0])
|
2011-10-18 11:18:58 -04:00
|
|
|
);
|
|
|
|
$likes = $r[0]['c'];
|
2018-01-15 08:15:33 -05:00
|
|
|
|
2020-02-25 07:46:08 -05:00
|
|
|
$dislikes = 0;
|
|
|
|
$strdislike = '';
|
|
|
|
if (!DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
|
|
|
|
// count dislikes
|
|
|
|
$r = q( $baseq . "AND `item`.`verb` = 'http://purl.org/macgirvin/dfrn/1.0/dislike'",
|
|
|
|
intval($conf['uid']),
|
|
|
|
DBA::escape($args[0])
|
|
|
|
);
|
|
|
|
$dislikes = $r[0]['c'];
|
|
|
|
$strdislike = DI::l10n()->tt("%d person doesn't like this", "%d people don't like this", $dislikes);
|
|
|
|
}
|
2018-01-15 08:15:33 -05:00
|
|
|
|
|
|
|
|
2011-10-18 11:18:58 -04:00
|
|
|
$o = "";
|
2018-01-15 08:15:33 -05:00
|
|
|
|
2012-12-22 15:36:35 -05:00
|
|
|
# $t = file_get_contents( dirname(__file__). "/widget_like.tpl" );
|
2018-10-31 10:55:15 -04:00
|
|
|
$t = Renderer::getMarkupTemplate("widget_like.tpl", "addon/widgets/");
|
|
|
|
$o .= Renderer::replaceMacros($t, [
|
2011-10-18 11:18:58 -04:00
|
|
|
'$like' => $likes,
|
2020-01-18 14:53:00 -05:00
|
|
|
'$strlike' => DI::l10n()->tt("%d person likes this", "%d people like this", $likes),
|
2018-01-15 08:15:33 -05:00
|
|
|
|
2011-10-18 11:18:58 -04:00
|
|
|
'$dislike' => $dislikes,
|
2020-02-25 07:46:08 -05:00
|
|
|
'$strdislike'=> $strdislike,
|
2018-01-15 08:15:33 -05:00
|
|
|
]);
|
|
|
|
|
2011-10-18 11:18:58 -04:00
|
|
|
return $o;
|
2011-09-25 04:56:03 -04:00
|
|
|
}
|