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