]> git.mxchange.org Git - friendica.git/blob - mod/notify.php
rev update
[friendica.git] / mod / notify.php
1 <?php
2
3
4 function notify_init(&$a) {
5         if(! local_user())
6                 return;
7
8         if($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {
9                 $r = q("select * from notify where id = %d and uid = %d limit 1",
10                         intval($a->argv[2]),
11                         intval(local_user())
12                 );
13                 if(count($r)) {
14                         q("update notify set seen = 1 where ( link = '%s' or ( parent != 0 and parent = %d and otype = '%s' )) and uid = %d",
15                                 dbesc($r[0]['link']),
16                                 intval($r[0]['parent']),
17                                 dbesc($r[0]['otype']),
18                                 intval(local_user())
19                         );
20                         goaway($r[0]['link']);
21                 }
22
23                 goaway($a->get_baseurl(true));
24         }
25
26         if($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all' ) {
27                 $r = q("update notify set seen = 1 where uid = %d",
28                         intval(local_user())
29                 );
30                 $j = json_encode(array('result' => ($r) ? 'success' : 'fail'));
31                 echo $j;
32                 killme();
33         }
34
35 }
36
37
38 function notify_content(&$a) {
39         if(! local_user())
40                 return login();
41
42                 $notif_tpl = get_markup_template('notifications.tpl');
43                 
44                 $not_tpl = get_markup_template('notify.tpl');
45                 require_once('include/bbcode.php');
46
47                 $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc",
48                         intval(local_user())
49                 );
50                 
51                 if (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' => '', // $tabs,
67                         '$notif_content' => $notif_content,
68                 ));
69
70         return $o;
71
72
73 }