streams/Zotlabs/Module/Notifications.php

81 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
2016-04-19 03:38:38 +00:00
namespace Zotlabs\Module;
2021-12-02 22:33:36 +00:00
use Zotlabs\Web\Controller;
2022-01-25 04:15:58 +00:00
use Zotlabs\Lib\Navbar;
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);
return;
}
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']));
$notif_content .= replace_macros(get_markup_template('notify.tpl'), array(
'$item_link' => z_root() . '/notify/view/' . $rr['id'],
'$item_image' => $rr['photo'],
'$item_text' => $x,
'$item_when' => relative_date($rr['created']),
'$item_seen' => (($rr['seen']) ? true : false),
'$new' => t('New')
));
}
} else {
$notif_content = t('No more system notifications.');
}
$o .= replace_macros(get_markup_template('notifications.tpl'), array(
'$notif_header' => t('System Notifications'),
'$notif_link_mark_seen' => t('Mark all seen'),
'$notif_content' => $notif_content,
'$notifications_available' => $notifications_available,
));
return $o;
}
2016-04-19 03:38:38 +00:00
}