2012-02-21 03:50:05 +00:00
|
|
|
<?php
|
2018-01-22 14:16:25 +00:00
|
|
|
/**
|
|
|
|
* @file mod/notify.php
|
|
|
|
*/
|
2018-02-03 17:25:58 +00:00
|
|
|
|
2017-04-30 04:07:00 +00:00
|
|
|
use Friendica\App;
|
2018-02-15 02:33:55 +00:00
|
|
|
use Friendica\Content\Text\BBCode;
|
2018-01-22 14:16:25 +00:00
|
|
|
use Friendica\Core\L10n;
|
2018-02-03 17:25:58 +00:00
|
|
|
use Friendica\Core\NotificationsManager;
|
2018-10-31 14:35:50 +00:00
|
|
|
use Friendica\Core\Renderer;
|
2017-08-26 06:04:21 +00:00
|
|
|
use Friendica\Core\System;
|
2018-07-21 12:40:21 +00:00
|
|
|
use Friendica\Database\DBA;
|
2018-01-28 11:18:08 +00:00
|
|
|
use Friendica\Model\Item;
|
2018-02-03 17:25:58 +00:00
|
|
|
use Friendica\Module\Login;
|
|
|
|
use Friendica\Util\Temporal;
|
2017-04-30 04:07:00 +00:00
|
|
|
|
2018-01-22 14:16:25 +00:00
|
|
|
function notify_init(App $a)
|
|
|
|
{
|
2016-12-20 10:27:40 +00:00
|
|
|
if (! local_user()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-12-20 10:27:40 +00:00
|
|
|
|
2016-02-07 13:27:13 +00:00
|
|
|
$nm = new NotificationsManager();
|
2016-12-20 10:27:40 +00:00
|
|
|
|
|
|
|
if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {
|
2016-02-07 13:27:13 +00:00
|
|
|
$note = $nm->getByID($a->argv[2]);
|
|
|
|
if ($note) {
|
|
|
|
$nm->setSeen($note);
|
2018-10-19 18:11:27 +00:00
|
|
|
System::externalRedirect($note['link']);
|
2012-02-21 03:50:05 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 18:11:27 +00:00
|
|
|
$a->internalRedirect();
|
2012-02-21 03:50:05 +00:00
|
|
|
}
|
2012-02-22 00:59:57 +00:00
|
|
|
|
2018-01-22 14:16:25 +00:00
|
|
|
if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all') {
|
2016-02-07 13:27:13 +00:00
|
|
|
$r = $nm->setAllSeen();
|
2018-01-15 13:05:12 +00:00
|
|
|
$j = json_encode(['result' => ($r) ? 'success' : 'fail']);
|
2012-02-22 00:59:57 +00:00
|
|
|
echo $j;
|
2018-12-26 05:40:12 +00:00
|
|
|
exit();
|
2012-02-22 00:59:57 +00:00
|
|
|
}
|
2012-02-21 03:50:05 +00:00
|
|
|
}
|
|
|
|
|
2018-01-22 14:16:25 +00:00
|
|
|
function notify_content(App $a)
|
|
|
|
{
|
2016-12-20 10:27:40 +00:00
|
|
|
if (! local_user()) {
|
2017-12-17 16:40:59 +00:00
|
|
|
return Login::form();
|
2016-12-20 10:27:40 +00:00
|
|
|
}
|
2014-02-16 16:36:52 +00:00
|
|
|
|
2019-01-07 17:51:48 +00:00
|
|
|
$notif_content = '';
|
|
|
|
|
2016-02-07 13:27:13 +00:00
|
|
|
$nm = new NotificationsManager();
|
2017-01-09 12:14:25 +00:00
|
|
|
|
2018-10-31 14:44:06 +00:00
|
|
|
$notif_tpl = Renderer::getMarkupTemplate('notifications.tpl');
|
2012-02-24 01:37:03 +00:00
|
|
|
|
2018-10-31 14:44:06 +00:00
|
|
|
$not_tpl = Renderer::getMarkupTemplate('notify.tpl');
|
2014-02-16 16:36:52 +00:00
|
|
|
|
2018-01-15 13:05:12 +00:00
|
|
|
$r = $nm->getAll(['seen'=>0]);
|
2018-07-21 12:46:04 +00:00
|
|
|
if (DBA::isResult($r) > 0) {
|
2016-02-07 13:27:13 +00:00
|
|
|
foreach ($r as $it) {
|
2018-10-31 14:35:50 +00:00
|
|
|
$notif_content .= Renderer::replaceMacros($not_tpl, [
|
2017-08-26 07:32:10 +00:00
|
|
|
'$item_link' => System::baseUrl(true).'/notify/view/'. $it['id'],
|
2016-02-07 13:27:13 +00:00
|
|
|
'$item_image' => $it['photo'],
|
2018-02-15 02:33:55 +00:00
|
|
|
'$item_text' => strip_tags(BBCode::convert($it['msg'])),
|
2018-02-03 17:25:58 +00:00
|
|
|
'$item_when' => Temporal::getRelativeDate($it['date'])
|
2018-01-15 13:05:12 +00:00
|
|
|
]);
|
2012-02-24 01:37:03 +00:00
|
|
|
}
|
2016-02-07 13:27:13 +00:00
|
|
|
} else {
|
2018-01-22 14:16:25 +00:00
|
|
|
$notif_content .= L10n::t('No more system notifications.');
|
2016-02-07 13:27:13 +00:00
|
|
|
}
|
2014-02-16 16:36:52 +00:00
|
|
|
|
2018-10-31 14:35:50 +00:00
|
|
|
$o = Renderer::replaceMacros($notif_tpl, [
|
2018-01-22 14:16:25 +00:00
|
|
|
'$notif_header' => L10n::t('System Notifications'),
|
2016-02-07 13:27:13 +00:00
|
|
|
'$tabs' => false, // $tabs,
|
|
|
|
'$notif_content' => $notif_content,
|
2018-01-15 13:05:12 +00:00
|
|
|
]);
|
2012-02-24 01:37:03 +00:00
|
|
|
|
|
|
|
return $o;
|
2012-12-22 19:57:29 +00:00
|
|
|
}
|