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