]> git.mxchange.org Git - friendica.git/blob - mod/notify.php
The central item fetch does work now and the API now uses these functions
[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\System;
11 use Friendica\Database\DBM;
12 use Friendica\Model\Item;
13 use Friendica\Module\Login;
14 use Friendica\Util\Temporal;
15
16 function notify_init(App $a)
17 {
18         if (! local_user()) {
19                 return;
20         }
21
22         $nm = new NotificationsManager();
23
24         if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {
25                 $note = $nm->getByID($a->argv[2]);
26                 if ($note) {
27                         $nm->setSeen($note);
28
29                         // The friendica client has problems with the GUID. this is some workaround
30                         if ($a->is_friendica_app()) {
31                                 require_once("include/items.php");
32                                 $urldata = parse_url($note['link']);
33                                 $guid = basename($urldata["path"]);
34                                 $itemdata = Item::getIdAndNickByGuid($guid, local_user());
35                                 if ($itemdata["id"] != 0) {
36                                         $note['link'] = System::baseUrl().'/display/'.$itemdata["nick"].'/'.$itemdata["id"];
37                                 }
38                         }
39
40                         goaway($note['link']);
41                 }
42
43                 goaway(System::baseUrl(true));
44         }
45
46         if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all') {
47                 $r = $nm->setAllSeen();
48                 $j = json_encode(['result' => ($r) ? 'success' : 'fail']);
49                 echo $j;
50                 killme();
51         }
52 }
53
54 function notify_content(App $a)
55 {
56         if (! local_user()) {
57                 return Login::form();
58         }
59
60         $nm = new NotificationsManager();
61
62         $notif_tpl = get_markup_template('notifications.tpl');
63
64         $not_tpl = get_markup_template('notify.tpl');
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::convert($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 }