streams/Code/Module/Notifications.php

83 lines
2.3 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
2021-12-03 03:01:39 +00:00
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2016-04-19 03:38:38 +00:00
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
use Code\Lib\Navbar;
use Code\Render\Theme;
2022-02-12 20:43:29 +00:00
2021-12-02 22:33:36 +00:00
2016-10-04 04:48:53 +00:00
require_once('include/bbcode.php');
2016-04-19 03:38:38 +00:00
2021-12-02 23:02:31 +00:00
class Notifications extends Controller
{
2016-04-19 03:38:38 +00:00
2021-12-02 23:02:31 +00:00
public function get()
{
2021-12-02 23:02:31 +00:00
if (!local_channel()) {
notice(t('Permission denied.') . EOL);
2022-09-04 00:01:52 +00:00
return '';
2021-12-02 23:02:31 +00:00
}
2021-12-02 23:02:31 +00:00
2022-01-25 04:16:38 +00:00
Navbar::set_selected('Notifications');
2021-12-02 23:02:31 +00:00
$o = '';
$notif_content = '';
$notifications_available = false;
2021-12-03 03:01:39 +00:00
$n = q(
"select count(*) as total from notify where uid = %d and seen = 0",
2021-12-02 23:02:31 +00:00
intval(local_channel())
);
if ($n && intval($n[0]['total']) > 49) {
2021-12-03 03:01:39 +00:00
$r = q(
"select * from notify where uid = %d
and seen = 0 order by created desc limit 50",
2021-12-02 23:02:31 +00:00
intval(local_channel())
);
} else {
2021-12-03 03:01:39 +00:00
$r1 = q(
"select * from notify where uid = %d
and seen = 0 order by created desc limit 50",
2021-12-02 23:02:31 +00:00
intval(local_channel())
);
2021-12-03 03:01:39 +00:00
$r2 = q(
"select * from notify where uid = %d
and seen = 1 order by created desc limit %d",
2021-12-02 23:02:31 +00:00
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']));
2022-09-04 01:35:50 +00:00
$notif_content .= replace_macros(Theme::get_template('notify.tpl'), [
2021-12-02 23:02:31 +00:00
'$item_link' => z_root() . '/notify/view/' . $rr['id'],
'$item_image' => $rr['photo'],
'$item_text' => $x,
'$item_when' => relative_date($rr['created']),
2022-09-04 01:35:50 +00:00
'$item_seen' => (bool)$rr['seen'],
2021-12-02 23:02:31 +00:00
'$new' => t('New')
2022-09-04 01:35:50 +00:00
]);
2021-12-02 23:02:31 +00:00
}
} else {
$notif_content = t('No more system notifications.');
}
2022-09-04 01:35:50 +00:00
$o .= replace_macros(Theme::get_template('notifications.tpl'), [
2021-12-02 23:02:31 +00:00
'$notif_header' => t('System Notifications'),
'$notif_link_mark_seen' => t('Mark all seen'),
'$notif_content' => $notif_content,
'$notifications_available' => $notifications_available,
2022-09-04 01:35:50 +00:00
]);
2021-12-02 23:02:31 +00:00
return $o;
}
2016-04-19 03:38:38 +00:00
}