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