streams/Code/Widget/Activity.php

69 lines
2.1 KiB
PHP
Raw Normal View History

<?php
2022-02-16 04:08:28 +00:00
namespace Code\Widget;
2022-02-16 04:08:28 +00:00
use Code\Lib\LibBlock;
use Code\Extend\Hook;
2020-03-20 04:08:50 +00:00
2022-10-23 21:18:44 +00:00
class Activity implements WidgetInterface
2021-12-02 23:02:31 +00:00
{
2022-10-24 03:39:49 +00:00
public function widget(array $arguments): string
2021-12-02 23:02:31 +00:00
{
if (!local_channel()) {
return '';
}
$o = EMPTY_STR;
2022-10-24 03:39:49 +00:00
if (is_array($arguments) && array_key_exists('limit', $arguments)) {
$limit = " limit " . intval($arguments['limit']) . " ";
2021-12-02 23:02:31 +00:00
} else {
$limit = EMPTY_STR;
}
$perms_sql = item_permissions_sql(local_channel()) . item_normal();
2022-10-24 03:39:49 +00:00
$items = q(
2021-12-03 03:01:39 +00:00
"select author_xchan from item where item_unseen = 1 and uid = %d $perms_sql",
2021-12-02 23:02:31 +00:00
intval(local_channel())
);
$contributors = [];
2022-10-24 03:39:49 +00:00
$tmpArray = [];
2021-12-02 23:02:31 +00:00
2022-10-24 03:39:49 +00:00
if ($items) {
foreach ($items as $item) {
if (array_key_exists($item['author_xchan'], $contributors)) {
$contributors[$item['author_xchan']]++;
2021-12-02 23:02:31 +00:00
} else {
2022-10-24 03:39:49 +00:00
$contributors[$item['author_xchan']] = 1;
2021-12-02 23:02:31 +00:00
}
}
foreach ($contributors as $k => $v) {
if (!LibBlock::fetch_by_entity(local_channel(), $k)) {
2022-10-24 03:39:49 +00:00
$tmpArray[] = ['author_xchan' => $k, 'total' => $v];
2021-12-02 23:02:31 +00:00
}
}
2022-10-24 03:39:49 +00:00
usort($tmpArray, 'total_sort');
xchan_query($tmpArray);
2021-12-02 23:02:31 +00:00
}
2022-10-24 03:39:49 +00:00
$x = ['entries' => $tmpArray];
Hook::call('activity_widget', $x);
2022-10-24 03:39:49 +00:00
$tmpArray = $x['entries'];
2021-12-02 23:02:31 +00:00
2022-10-24 03:39:49 +00:00
if ($tmpArray) {
2021-12-02 23:02:31 +00:00
$o .= '<div class="widget">';
$o .= '<h3>' . t('Activity', 'widget') . '</h3><ul class="nav nav-pills flex-column">';
2022-10-24 03:39:49 +00:00
foreach ($tmpArray as $value) {
$o .= '<li class="nav-item"><a class="nav-link" href="stream?f=&xchan=' . urlencode($value['author_xchan']) . '" ><span class="badge bg-secondary float-end">' . ((intval($value['total'])) ? intval($value['total']) : '') . '</span><img src="' . $value['author']['xchan_photo_s'] . '" class="menu-img-1" /> ' . $value['author']['xchan_name'] . '</a></li>';
2021-12-02 23:02:31 +00:00
}
$o .= '</ul></div>';
}
return $o;
}
2021-12-03 03:01:39 +00:00
}