]> git.mxchange.org Git - friendica.git/blob - mod/notify.php
Catch HTTPExceptions in App::runFrontend()
[friendica.git] / mod / notify.php
1 <?php
2 /**
3  * @file mod/notify.php
4  */
5
6 use Friendica\App;
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;
16
17 function notify_init(App $a)
18 {
19         if (! local_user()) {
20                 return;
21         }
22
23         $nm = new NotificationsManager();
24
25         if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {
26                 $note = $nm->getByID($a->argv[2]);
27                 if ($note) {
28                         $nm->setSeen($note);
29
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"];
38                                 }
39                         }
40
41                         System::externalRedirect($note['link']);
42                 }
43
44                 $a->internalRedirect();
45         }
46
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']);
50                 echo $j;
51                 killme();
52         }
53 }
54
55 function notify_content(App $a)
56 {
57         if (! local_user()) {
58                 return Login::form();
59         }
60
61         $nm = new NotificationsManager();
62
63         $notif_tpl = Renderer::getMarkupTemplate('notifications.tpl');
64
65         $not_tpl = Renderer::getMarkupTemplate('notify.tpl');
66
67         $r = $nm->getAll(['seen'=>0]);
68         if (DBA::isResult($r) > 0) {
69                 foreach ($r as $it) {
70                         $notif_content .= Renderer::replaceMacros($not_tpl, [
71                                 '$item_link' => System::baseUrl(true).'/notify/view/'. $it['id'],
72                                 '$item_image' => $it['photo'],
73                                 '$item_text' => strip_tags(BBCode::convert($it['msg'])),
74                                 '$item_when' => Temporal::getRelativeDate($it['date'])
75                         ]);
76                 }
77         } else {
78                 $notif_content .= L10n::t('No more system notifications.');
79         }
80
81         $o = Renderer::replaceMacros($notif_tpl, [
82                 '$notif_header' => L10n::t('System Notifications'),
83                 '$tabs' => false, // $tabs,
84                 '$notif_content' => $notif_content,
85         ]);
86
87         return $o;
88 }