]> git.mxchange.org Git - friendica.git/blob - mod/notify.php
Merge pull request #4323 from MrPetovan/bug/fix-removeme-auth
[friendica.git] / mod / notify.php
1 <?php
2 /**
3  * @file mod/notify.php
4  */
5 use Friendica\App;
6 use Friendica\Core\NotificationsManager;
7 use Friendica\Core\L10n;
8 use Friendica\Core\System;
9 use Friendica\Database\DBM;
10 use Friendica\Module\Login;
11
12 function notify_init(App $a)
13 {
14         if (! local_user()) {
15                 return;
16         }
17
18         $nm = new NotificationsManager();
19
20         if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {
21                 $note = $nm->getByID($a->argv[2]);
22                 if ($note) {
23                         $nm->setSeen($note);
24
25                         // The friendica client has problems with the GUID. this is some workaround
26                         if ($a->is_friendica_app()) {
27                                 require_once("include/items.php");
28                                 $urldata = parse_url($note['link']);
29                                 $guid = basename($urldata["path"]);
30                                 $itemdata = get_item_id($guid, local_user());
31                                 if ($itemdata["id"] != 0) {
32                                         $note['link'] = System::baseUrl().'/display/'.$itemdata["nick"].'/'.$itemdata["id"];
33                                 }
34                         }
35
36                         goaway($note['link']);
37                 }
38
39                 goaway(System::baseUrl(true));
40         }
41
42         if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all') {
43                 $r = $nm->setAllSeen();
44                 $j = json_encode(['result' => ($r) ? 'success' : 'fail']);
45                 echo $j;
46                 killme();
47         }
48 }
49
50 function notify_content(App $a)
51 {
52         if (! local_user()) {
53                 return Login::form();
54         }
55
56         $nm = new NotificationsManager();
57
58         $notif_tpl = get_markup_template('notifications.tpl');
59
60         $not_tpl = get_markup_template('notify.tpl');
61         require_once('include/bbcode.php');
62
63         $r = $nm->getAll(['seen'=>0]);
64         if (DBM::is_result($r) > 0) {
65                 foreach ($r as $it) {
66                         $notif_content .= replace_macros($not_tpl, [
67                                 '$item_link' => System::baseUrl(true).'/notify/view/'. $it['id'],
68                                 '$item_image' => $it['photo'],
69                                 '$item_text' => strip_tags(bbcode($it['msg'])),
70                                 '$item_when' => relative_date($it['date'])
71                         ]);
72                 }
73         } else {
74                 $notif_content .= L10n::t('No more system notifications.');
75         }
76
77         $o .= replace_macros($notif_tpl, [
78                 '$notif_header' => L10n::t('System Notifications'),
79                 '$tabs' => false, // $tabs,
80                 '$notif_content' => $notif_content,
81         ]);
82
83         return $o;
84 }