streams/Code/Module/Notify.php

89 lines
2.5 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
2021-10-24 21:45:20 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
use Code\Extend\Hook;
use Code\Render\Theme;
2022-02-12 20:43:29 +00:00
2016-04-19 03:38:38 +00:00
2021-12-02 23:02:31 +00:00
class Notify extends Controller
{
public function init()
{
if (!local_channel()) {
return;
}
$channel = App::get_channel();
if (!$channel) {
return;
}
if (argc() > 2 && argv(1) === 'view' && intval(argv(2))) {
2021-12-03 03:01:39 +00:00
$r = q(
"select * from notify where id = %d and uid = %d limit 1",
2021-12-02 23:02:31 +00:00
intval(argv(2)),
intval(local_channel())
);
if ($r) {
$x = ['channel_id' => local_channel(), 'update' => 'unset'];
Hook::call('update_unseen', $x);
2021-12-02 23:02:31 +00:00
if ((!$_SESSION['sudo']) && ($x['update'] === 'unset' || intval($x['update']))) {
2021-12-03 03:01:39 +00:00
q(
"update notify set seen = 1 where (( parent != '' and parent = '%s' and otype = '%s' ) or link = '%s' ) and uid = %d",
2021-12-02 23:02:31 +00:00
dbesc($r[0]['parent']),
dbesc($r[0]['otype']),
dbesc($r[0]['link']),
intval(local_channel())
);
}
goaway($r[0]['link']);
}
notice(sprintf(t('A notification with that id was not found for channel \'%s\''), $channel['channel_name']));
goaway(z_root());
}
}
public function get()
{
if (!local_channel()) {
return login();
}
2022-02-12 20:43:29 +00:00
$notif_tpl = Theme::get_template('notifications.tpl');
2021-12-02 23:02:31 +00:00
2022-02-12 20:43:29 +00:00
$not_tpl = Theme::get_template('notify.tpl');
2021-12-02 23:02:31 +00:00
2021-12-03 03:01:39 +00:00
$r = q(
"SELECT * from notify where uid = %d and seen = 0 order by created desc",
2021-12-02 23:02:31 +00:00
intval(local_channel())
);
2022-09-03 05:23:54 +00:00
$notif_content = '';
2021-12-02 23:02:31 +00:00
if ($r) {
foreach ($r as $it) {
2022-09-03 05:23:54 +00:00
$notif_content .= replace_macros($not_tpl, [
2021-12-02 23:02:31 +00:00
'$item_link' => z_root() . '/notify/view/' . $it['id'],
'$item_image' => $it['photo'],
'$item_text' => strip_tags(bbcode($it['msg'])),
'$item_when' => relative_date($it['created'])
2022-09-03 05:23:54 +00:00
]);
2021-12-02 23:02:31 +00:00
}
} else {
$notif_content .= t('No more system notifications.');
}
2022-09-03 05:23:54 +00:00
return replace_macros($notif_tpl, [
2021-12-02 23:02:31 +00:00
'$notif_header' => t('System Notifications'),
'$tabs' => '', // $tabs,
'$notif_content' => $notif_content,
2022-09-03 05:23:54 +00:00
]);
2021-12-02 23:02:31 +00:00
}
2016-04-19 03:38:38 +00:00
}