]> git.mxchange.org Git - friendica.git/blob - mod/notify.php
new api for notifications
[friendica.git] / mod / notify.php
1 <?php
2 require_once('include/NotificationsManager.php');
3 if(! function_exists('notify_init')) {
4 function notify_init(&$a) {
5         if(! local_user()) return;
6
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 if(! function_exists('notify_content')) {
40 function notify_content(&$a) {
41         if(! local_user()) return login();
42
43         $nm = new NotificationsManager();
44         
45         $notif_tpl = get_markup_template('notifications.tpl');
46
47         $not_tpl = get_markup_template('notify.tpl');
48         require_once('include/bbcode.php');
49
50         $r = $nm->getAll(array('seen'=>0));
51         if ($r!==false && count($r) > 0) {
52                 foreach ($r as $it) {
53                         $notif_content .= replace_macros($not_tpl,array(
54                                 '$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'],
55                                 '$item_image' => $it['photo'],
56                                 '$item_text' => strip_tags(bbcode($it['msg'])),
57                                 '$item_when' => relative_date($it['date'])
58                         ));
59                 }
60         } else {
61                 $notif_content .= t('No more system notifications.');
62         }
63
64         $o .= replace_macros($notif_tpl, array(
65                 '$notif_header' => t('System Notifications'),
66                 '$tabs' => false, // $tabs,
67                 '$notif_content' => $notif_content,
68         ));
69
70         return $o;
71
72 }
73 }
74