]> git.mxchange.org Git - friendica.git/blob - mod/notify.php
system notifications to notify module, untranslated string in notifications.tpl
[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 id = %d and uid = %d limit 1",
15                                 intval($a->argv[2]),
16                                 intval(local_user())
17                         );
18                         goaway($r[0]['link']);
19                 }
20
21                 goaway($a->get_baseurl());
22         }
23
24         if($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all' ) {
25                 $r = q("update notify set seen = 1 where uid = %d",
26                         intval(local_user())
27                 );
28                 $j = json_encode(array('result' => ($r) ? 'success' : 'fail'));
29                 echo $j;
30                 killme();
31         }
32
33 }
34
35
36 function notify_content(&$a) {
37         if(! local_user())
38                 return login();
39
40                 $notif_tpl = get_markup_template('notifications.tpl');
41                 
42                 $not_tpl = get_markup_template('notify.tpl');
43                 require_once('include/bbcode.php');
44
45                 $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc",
46                         intval(local_user())
47                 );
48                 
49                 if (count($r) > 0) {
50                         foreach ($r as $it) {
51                                 $notif_content .= replace_macros($not_tpl,array(
52                                         '$item_link' => $a->get_baseurl().'/notify/view/'. $it['id'],
53                                         '$item_image' => $it['photo'],
54                                         '$item_text' => strip_tags(bbcode($it['msg'])),
55                                         '$item_when' => relative_date($it['date'])
56                                 ));
57                         }
58                 } else {
59                         $notif_content .= t('No more system notifications.');
60                 }
61                 
62                 $o .= replace_macros($notif_tpl,array(
63                         '$notif_header' => t('System Notifications'),
64                         '$tabs' => '', // $tabs,
65                         '$notif_content' => $notif_content,
66                 ));
67
68         return $o;
69
70
71 }