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