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