streams/Zotlabs/Widget/Rating.php

75 lines
1.9 KiB
PHP
Raw Normal View History

<?php
namespace Zotlabs\Widget;
2021-12-02 22:33:36 +00:00
use App;
2022-02-12 21:54:06 +00:00
use Zotlabs\Lib\Head;
2021-12-02 23:02:31 +00:00
class Rating
{
2021-12-02 23:02:31 +00:00
public function widget($arr)
{
2021-12-02 23:02:31 +00:00
$rating_enabled = get_config('system', 'rating_enabled');
if (!$rating_enabled) {
return;
}
2021-12-03 03:01:39 +00:00
if ($arr['target']) {
2021-12-02 23:02:31 +00:00
$hash = $arr['target'];
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
$hash = App::$poi['xchan_hash'];
2021-12-03 03:01:39 +00:00
}
2021-12-03 03:01:39 +00:00
if (!$hash) {
2021-12-02 23:02:31 +00:00
return;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$url = '';
$remote = false;
2021-12-02 23:02:31 +00:00
if (remote_channel() && !local_channel()) {
$ob = App::get_observer();
if ($ob && $ob['xchan_url']) {
$p = parse_url($ob['xchan_url']);
if ($p) {
$url = $p['scheme'] . '://' . $p['host'] . (($p['port']) ? ':' . $p['port'] : '');
$url .= '/rate?f=&target=' . urlencode($hash);
}
$remote = true;
}
}
2021-12-02 23:02:31 +00:00
$self = false;
2021-12-02 23:02:31 +00:00
if (local_channel()) {
$channel = App::get_channel();
2021-12-03 03:01:39 +00:00
if ($hash == $channel['channel_hash']) {
2021-12-02 23:02:31 +00:00
$self = true;
2021-12-03 03:01:39 +00:00
}
2022-02-12 21:54:06 +00:00
Head::add_js('ratings.js');
2021-12-02 23:02:31 +00:00
}
2021-12-02 23:02:31 +00:00
$o = '<div class="widget">';
$o .= '<h3>' . t('Rating Tools') . '</h3>';
2021-12-02 23:02:31 +00:00
if ((($remote) || (local_channel())) && (!$self)) {
2021-12-03 03:01:39 +00:00
if ($remote) {
2021-12-02 23:02:31 +00:00
$o .= '<a class="btn btn-block btn-primary btn-sm" href="' . $url . '"><i class="fa fa-pencil"></i> ' . t('Rate Me') . '</a>';
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
$o .= '<div class="btn btn-block btn-primary btn-sm" onclick="doRatings(\'' . $hash . '\'); return false;"><i class="fa fa-pencil"></i> ' . t('Rate Me') . '</div>';
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
}
2021-12-02 23:02:31 +00:00
$o .= '<a class="btn btn-block btn-default btn-sm" href="ratings/' . $hash . '"><i class="fa fa-eye"></i> ' . t('View Ratings') . '</a>';
$o .= '</div>';
2021-12-02 23:02:31 +00:00
return $o;
}
}