]> git.mxchange.org Git - friendica.git/blob - mod/notify.php
fix undeclared variables or wrong variable names (/mod)
[friendica.git] / mod / notify.php
1 <?php
2 /**
3  * @file mod/notify.php
4  */
5
6 use Friendica\App;
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;
14
15 function notify_init(App $a)
16 {
17         if (! local_user()) {
18                 return;
19         }
20
21         $nm = new NotificationsManager();
22
23         if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {
24                 $note = $nm->getByID($a->argv[2]);
25                 if ($note) {
26                         $nm->setSeen($note);
27
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"];
36                                 }
37                         }
38
39                         goaway($note['link']);
40                 }
41
42                 goaway(System::baseUrl(true));
43         }
44
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']);
48                 echo $j;
49                 killme();
50         }
51 }
52
53 function notify_content(App $a)
54 {
55         if (! local_user()) {
56                 return Login::form();
57         }
58
59         $nm = new NotificationsManager();
60
61         $notif_tpl = get_markup_template('notifications.tpl');
62
63         $not_tpl = get_markup_template('notify.tpl');
64         require_once('include/bbcode.php');
65
66         $r = $nm->getAll(['seen'=>0]);
67         if (DBM::is_result($r) > 0) {
68                 foreach ($r as $it) {
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'])
74                         ]);
75                 }
76         } else {
77                 $notif_content .= L10n::t('No more system notifications.');
78         }
79
80         $o = replace_macros($notif_tpl, [
81                 '$notif_header' => L10n::t('System Notifications'),
82                 '$tabs' => false, // $tabs,
83                 '$notif_content' => $notif_content,
84         ]);
85
86         return $o;
87 }