streams/Code/Module/Notifications.php
Mike Macgirvin 3dd89f71d5 cleanup
2022-09-04 11:35:50 +10:00

82 lines
2.3 KiB
PHP

<?php
namespace Code\Module;
use Code\Web\Controller;
use Code\Lib\Navbar;
use Code\Render\Theme;
require_once('include/bbcode.php');
class Notifications extends Controller
{
public function get()
{
if (!local_channel()) {
notice(t('Permission denied.') . EOL);
return '';
}
Navbar::set_selected('Notifications');
$o = '';
$notif_content = '';
$notifications_available = false;
$n = q(
"select count(*) as total from notify where uid = %d and seen = 0",
intval(local_channel())
);
if ($n && intval($n[0]['total']) > 49) {
$r = q(
"select * from notify where uid = %d
and seen = 0 order by created desc limit 50",
intval(local_channel())
);
} else {
$r1 = q(
"select * from notify where uid = %d
and seen = 0 order by created desc limit 50",
intval(local_channel())
);
$r2 = q(
"select * from notify where uid = %d
and seen = 1 order by created desc limit %d",
intval(local_channel()),
intval(50 - intval($n[0]['total']))
);
$r = array_merge($r1, $r2);
}
if ($r) {
$notifications_available = true;
foreach ($r as $rr) {
$x = strip_tags(bbcode($rr['msg']));
$notif_content .= replace_macros(Theme::get_template('notify.tpl'), [
'$item_link' => z_root() . '/notify/view/' . $rr['id'],
'$item_image' => $rr['photo'],
'$item_text' => $x,
'$item_when' => relative_date($rr['created']),
'$item_seen' => (bool)$rr['seen'],
'$new' => t('New')
]);
}
} else {
$notif_content = t('No more system notifications.');
}
$o .= replace_macros(Theme::get_template('notifications.tpl'), [
'$notif_header' => t('System Notifications'),
'$notif_link_mark_seen' => t('Mark all seen'),
'$notif_content' => $notif_content,
'$notifications_available' => $notifications_available,
]);
return $o;
}
}