]> git.mxchange.org Git - friendica.git/blob - mod/notify.php
Merge pull request #6977 from annando/fix-reshare
[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                 exit();
52         }
53 }
54
55 function notify_content(App $a)
56 {
57         if (! local_user()) {
58                 return Login::form();
59         }
60
61         $notif_content = '';
62
63         $nm = new NotificationsManager();
64
65         $notif_tpl = Renderer::getMarkupTemplate('notifications.tpl');
66
67         $not_tpl = Renderer::getMarkupTemplate('notify.tpl');
68
69         $r = $nm->getAll(['seen'=>0]);
70         if (DBA::isResult($r) > 0) {
71                 foreach ($r as $it) {
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'])
77                         ]);
78                 }
79         } else {
80                 $notif_content .= L10n::t('No more system notifications.');
81         }
82
83         $o = Renderer::replaceMacros($notif_tpl, [
84                 '$notif_header' => L10n::t('System Notifications'),
85                 '$tabs' => false, // $tabs,
86                 '$notif_content' => $notif_content,
87         ]);
88
89         return $o;
90 }