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