2017-03-16 01:31:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Zotlabs\Widget;
|
|
|
|
|
2019-08-14 02:42:32 +00:00
|
|
|
use App;
|
2019-04-30 23:52:07 +00:00
|
|
|
use Zotlabs\Lib\Apps;
|
2022-02-12 20:43:29 +00:00
|
|
|
use Zotlabs\Render\Theme;
|
|
|
|
|
2019-04-30 23:52:07 +00:00
|
|
|
|
2017-03-16 01:31:34 +00:00
|
|
|
require_once('include/socgraph.php');
|
|
|
|
|
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
class Suggestions
|
|
|
|
{
|
|
|
|
|
|
|
|
public function widget($arr)
|
|
|
|
{
|
|
|
|
|
|
|
|
if ((!local_channel()) || (!Apps::system_app_installed(local_channel(), 'Suggest Channels'))) {
|
|
|
|
return EMPTY_STR;
|
|
|
|
}
|
|
|
|
|
|
|
|
$r = suggestion_query(local_channel(), get_observer_hash(), 0, 20);
|
|
|
|
|
|
|
|
if (!$r) {
|
|
|
|
return EMPTY_STR;
|
|
|
|
}
|
|
|
|
|
|
|
|
$arr = [];
|
|
|
|
|
|
|
|
// Get two random entries from the top 20 returned.
|
|
|
|
// We'll grab the first one and the one immediately following.
|
|
|
|
// This will throw some entropy into the situation so you won't
|
|
|
|
// be looking at the same two mug shots every time the widget runs
|
|
|
|
|
|
|
|
$index = ((count($r) > 2) ? mt_rand(0, count($r) - 2) : 0);
|
|
|
|
|
|
|
|
for ($x = $index; $x <= ($index + 1); $x++) {
|
|
|
|
$rr = $r[$x];
|
2021-12-03 03:01:39 +00:00
|
|
|
if (!$rr['xchan_url']) {
|
2021-12-02 23:02:31 +00:00
|
|
|
break;
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|
2021-12-02 23:02:31 +00:00
|
|
|
|
|
|
|
$connlnk = z_root() . '/follow/?url=' . $rr['xchan_addr'];
|
|
|
|
|
|
|
|
$arr[] = [
|
|
|
|
'url' => chanlink_url($rr['xchan_url']),
|
|
|
|
'profile' => $rr['xchan_url'],
|
|
|
|
'name' => $rr['xchan_name'],
|
|
|
|
'photo' => $rr['xchan_photo_m'],
|
|
|
|
'ignlnk' => z_root() . '/directory?return=' . base64_encode(App::$query_string) . '&ignore=' . $rr['xchan_hash'],
|
|
|
|
'conntxt' => t('Connect'),
|
|
|
|
'connlnk' => $connlnk,
|
|
|
|
'ignore' => t('Ignore/Hide')
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-02-12 20:43:29 +00:00
|
|
|
$o = replace_macros(Theme::get_template('suggest_widget.tpl'), [
|
2021-12-02 23:02:31 +00:00
|
|
|
'$title' => t('Suggestions'),
|
|
|
|
'$more' => t('See more...'),
|
|
|
|
'$entries' => $arr
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
2017-03-16 01:31:34 +00:00
|
|
|
}
|