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