7 use Friendica\Core\L10n;
8 use Friendica\Core\NotificationsManager;
9 use Friendica\Core\System;
10 use Friendica\Database\DBM;
11 use Friendica\Model\Item;
12 use Friendica\Module\Login;
13 use Friendica\Util\Temporal;
15 function notify_init(App $a)
21 $nm = new NotificationsManager();
23 if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {
24 $note = $nm->getByID($a->argv[2]);
28 // The friendica client has problems with the GUID. this is some workaround
29 if ($a->is_friendica_app()) {
30 require_once("include/items.php");
31 $urldata = parse_url($note['link']);
32 $guid = basename($urldata["path"]);
33 $itemdata = Item::getIdAndNickByGuid($guid, local_user());
34 if ($itemdata["id"] != 0) {
35 $note['link'] = System::baseUrl().'/display/'.$itemdata["nick"].'/'.$itemdata["id"];
39 goaway($note['link']);
42 goaway(System::baseUrl(true));
45 if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all') {
46 $r = $nm->setAllSeen();
47 $j = json_encode(['result' => ($r) ? 'success' : 'fail']);
53 function notify_content(App $a)
59 $nm = new NotificationsManager();
61 $notif_tpl = get_markup_template('notifications.tpl');
63 $not_tpl = get_markup_template('notify.tpl');
64 require_once('include/bbcode.php');
66 $r = $nm->getAll(['seen'=>0]);
67 if (DBM::is_result($r) > 0) {
69 $notif_content .= replace_macros($not_tpl, [
70 '$item_link' => System::baseUrl(true).'/notify/view/'. $it['id'],
71 '$item_image' => $it['photo'],
72 '$item_text' => strip_tags(bbcode($it['msg'])),
73 '$item_when' => Temporal::getRelativeDate($it['date'])
77 $notif_content .= L10n::t('No more system notifications.');
80 $o = replace_macros($notif_tpl, [
81 '$notif_header' => L10n::t('System Notifications'),
82 '$tabs' => false, // $tabs,
83 '$notif_content' => $notif_content,