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