7 use Friendica\Content\Text\BBCode;
8 use Friendica\Core\L10n;
9 use Friendica\Core\NotificationsManager;
10 use Friendica\Core\Renderer;
11 use Friendica\Core\System;
12 use Friendica\Database\DBA;
13 use Friendica\Model\Item;
14 use Friendica\Module\Login;
15 use Friendica\Util\Temporal;
17 function notify_init(App $a)
23 $nm = new NotificationsManager();
25 if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {
26 $note = $nm->getByID($a->argv[2]);
30 // The friendica client has problems with the GUID. this is some workaround
31 if ($a->isFriendicaApp()) {
32 require_once("include/items.php");
33 $urldata = parse_url($note['link']);
34 $guid = basename($urldata["path"]);
35 $itemdata = Item::getIdAndNickByGuid($guid, local_user());
36 if ($itemdata["id"] != 0) {
37 $note['link'] = System::baseUrl().'/display/'.$itemdata["nick"].'/'.$itemdata["id"];
41 System::externalRedirect($note['link']);
44 $a->internalRedirect();
47 if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all') {
48 $r = $nm->setAllSeen();
49 $j = json_encode(['result' => ($r) ? 'success' : 'fail']);
55 function notify_content(App $a)
63 $nm = new NotificationsManager();
65 $notif_tpl = Renderer::getMarkupTemplate('notifications.tpl');
67 $not_tpl = Renderer::getMarkupTemplate('notify.tpl');
69 $r = $nm->getAll(['seen'=>0]);
70 if (DBA::isResult($r) > 0) {
72 $notif_content .= Renderer::replaceMacros($not_tpl, [
73 '$item_link' => System::baseUrl(true).'/notify/view/'. $it['id'],
74 '$item_image' => $it['photo'],
75 '$item_text' => strip_tags(BBCode::convert($it['msg'])),
76 '$item_when' => Temporal::getRelativeDate($it['date'])
80 $notif_content .= L10n::t('No more system notifications.');
83 $o = Renderer::replaceMacros($notif_tpl, [
84 '$notif_header' => L10n::t('System Notifications'),
85 '$tabs' => false, // $tabs,
86 '$notif_content' => $notif_content,