2012-02-21 04:50:05 +01:00
|
|
|
<?php
|
2018-01-22 15:16:25 +01:00
|
|
|
/**
|
|
|
|
* @file mod/notify.php
|
|
|
|
*/
|
2018-02-03 18:25:58 +01:00
|
|
|
|
2017-04-30 06:07:00 +02:00
|
|
|
use Friendica\App;
|
2018-01-22 15:16:25 +01:00
|
|
|
use Friendica\Core\L10n;
|
2018-02-03 18:25:58 +01:00
|
|
|
use Friendica\Core\NotificationsManager;
|
2017-08-26 08:04:21 +02:00
|
|
|
use Friendica\Core\System;
|
2017-11-08 04:57:46 +01:00
|
|
|
use Friendica\Database\DBM;
|
2018-01-28 12:18:08 +01:00
|
|
|
use Friendica\Model\Item;
|
2018-02-03 18:25:58 +01:00
|
|
|
use Friendica\Module\Login;
|
|
|
|
use Friendica\Util\Temporal;
|
2017-04-30 06:07:00 +02:00
|
|
|
|
2018-01-22 15:16:25 +01:00
|
|
|
function notify_init(App $a)
|
|
|
|
{
|
2016-12-20 11:27:40 +01:00
|
|
|
if (! local_user()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-12-20 11:27:40 +01:00
|
|
|
|
2016-02-07 14:27:13 +01:00
|
|
|
$nm = new NotificationsManager();
|
2016-12-20 11:27:40 +01:00
|
|
|
|
|
|
|
if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {
|
2016-02-07 14:27:13 +01:00
|
|
|
$note = $nm->getByID($a->argv[2]);
|
|
|
|
if ($note) {
|
|
|
|
$nm->setSeen($note);
|
2017-01-09 13:14:25 +01:00
|
|
|
|
2014-07-26 15:01:01 +02:00
|
|
|
// The friendica client has problems with the GUID. this is some workaround
|
2015-06-13 20:23:26 +02:00
|
|
|
if ($a->is_friendica_app()) {
|
2014-07-26 15:01:01 +02:00
|
|
|
require_once("include/items.php");
|
2016-02-07 14:27:13 +01:00
|
|
|
$urldata = parse_url($note['link']);
|
2014-07-26 15:01:01 +02:00
|
|
|
$guid = basename($urldata["path"]);
|
2018-01-28 12:18:08 +01:00
|
|
|
$itemdata = Item::getIdAndNickByGuid($guid, local_user());
|
2016-12-20 11:27:40 +01:00
|
|
|
if ($itemdata["id"] != 0) {
|
2017-08-26 09:32:10 +02:00
|
|
|
$note['link'] = System::baseUrl().'/display/'.$itemdata["nick"].'/'.$itemdata["id"];
|
2016-12-20 11:27:40 +01:00
|
|
|
}
|
2014-07-26 15:01:01 +02:00
|
|
|
}
|
|
|
|
|
2016-02-07 14:27:13 +01:00
|
|
|
goaway($note['link']);
|
2012-02-21 04:50:05 +01:00
|
|
|
}
|
|
|
|
|
2017-08-26 09:32:10 +02:00
|
|
|
goaway(System::baseUrl(true));
|
2012-02-21 04:50:05 +01:00
|
|
|
}
|
2012-02-22 01:59:57 +01:00
|
|
|
|
2018-01-22 15:16:25 +01:00
|
|
|
if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all') {
|
2016-02-07 14:27:13 +01:00
|
|
|
$r = $nm->setAllSeen();
|
2018-01-15 14:05:12 +01:00
|
|
|
$j = json_encode(['result' => ($r) ? 'success' : 'fail']);
|
2012-02-22 01:59:57 +01:00
|
|
|
echo $j;
|
|
|
|
killme();
|
|
|
|
}
|
2012-02-21 04:50:05 +01:00
|
|
|
}
|
|
|
|
|
2018-01-22 15:16:25 +01:00
|
|
|
function notify_content(App $a)
|
|
|
|
{
|
2016-12-20 11:27:40 +01:00
|
|
|
if (! local_user()) {
|
2017-12-17 17:40:59 +01:00
|
|
|
return Login::form();
|
2016-12-20 11:27:40 +01:00
|
|
|
}
|
2014-02-16 17:36:52 +01:00
|
|
|
|
2016-02-07 14:27:13 +01:00
|
|
|
$nm = new NotificationsManager();
|
2017-01-09 13:14:25 +01:00
|
|
|
|
2016-02-07 14:27:13 +01:00
|
|
|
$notif_tpl = get_markup_template('notifications.tpl');
|
2012-02-24 02:37:03 +01:00
|
|
|
|
2016-02-07 14:27:13 +01:00
|
|
|
$not_tpl = get_markup_template('notify.tpl');
|
|
|
|
require_once('include/bbcode.php');
|
2014-02-16 17:36:52 +01:00
|
|
|
|
2018-01-15 14:05:12 +01:00
|
|
|
$r = $nm->getAll(['seen'=>0]);
|
2017-11-08 04:57:46 +01:00
|
|
|
if (DBM::is_result($r) > 0) {
|
2016-02-07 14:27:13 +01:00
|
|
|
foreach ($r as $it) {
|
2018-01-22 15:16:25 +01:00
|
|
|
$notif_content .= replace_macros($not_tpl, [
|
2017-08-26 09:32:10 +02:00
|
|
|
'$item_link' => System::baseUrl(true).'/notify/view/'. $it['id'],
|
2016-02-07 14:27:13 +01:00
|
|
|
'$item_image' => $it['photo'],
|
|
|
|
'$item_text' => strip_tags(bbcode($it['msg'])),
|
2018-02-03 18:25:58 +01:00
|
|
|
'$item_when' => Temporal::getRelativeDate($it['date'])
|
2018-01-15 14:05:12 +01:00
|
|
|
]);
|
2012-02-24 02:37:03 +01:00
|
|
|
}
|
2016-02-07 14:27:13 +01:00
|
|
|
} else {
|
2018-01-22 15:16:25 +01:00
|
|
|
$notif_content .= L10n::t('No more system notifications.');
|
2016-02-07 14:27:13 +01:00
|
|
|
}
|
2014-02-16 17:36:52 +01:00
|
|
|
|
2018-01-15 14:05:12 +01:00
|
|
|
$o .= replace_macros($notif_tpl, [
|
2018-01-22 15:16:25 +01:00
|
|
|
'$notif_header' => L10n::t('System Notifications'),
|
2016-02-07 14:27:13 +01:00
|
|
|
'$tabs' => false, // $tabs,
|
|
|
|
'$notif_content' => $notif_content,
|
2018-01-15 14:05:12 +01:00
|
|
|
]);
|
2012-02-24 02:37:03 +01:00
|
|
|
|
|
|
|
return $o;
|
2012-12-22 20:57:29 +01:00
|
|
|
}
|