]> git.mxchange.org Git - friendica.git/blob - mod/notify.php
Bugfix: The user id wasn't fetched correctly.
[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
21                         // Friendica-Client
22                         $friendicamobile = ($_SERVER['HTTP_USER_AGENT'] == "Apache-HttpClient/UNAVAILABLE (java 1.4)");
23
24                         // The friendica client has problems with the GUID. this is some workaround
25                         if ($friendicamobile) {
26                                 require_once("include/items.php");
27                                 $urldata = parse_url($r[0]['link']);
28                                 $guid = basename($urldata["path"]);
29                                 $itemdata = get_item_id($guid, local_user());
30                                 if ($itemdata["id"] != 0)
31                                         $r[0]['link'] = $a->get_baseurl().'/display/'.$itemdata["nick"].'/'.$itemdata["id"];
32                         }
33
34                         goaway($r[0]['link']);
35                 }
36
37                 goaway($a->get_baseurl(true));
38         }
39
40         if($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all' ) {
41                 $r = q("update notify set seen = 1 where uid = %d",
42                         intval(local_user())
43                 );
44                 $j = json_encode(array('result' => ($r) ? 'success' : 'fail'));
45                 echo $j;
46                 killme();
47         }
48
49 }
50
51
52 function notify_content(&$a) {
53         if(! local_user())
54                 return login();
55
56                 $notif_tpl = get_markup_template('notifications.tpl');
57
58                 $not_tpl = get_markup_template('notify.tpl');
59                 require_once('include/bbcode.php');
60
61                 $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc",
62                         intval(local_user())
63                 );
64
65                 if (count($r) > 0) {
66                         foreach ($r as $it) {
67                                 $notif_content .= replace_macros($not_tpl,array(
68                                         '$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'],
69                                         '$item_image' => $it['photo'],
70                                         '$item_text' => strip_tags(bbcode($it['msg'])),
71                                         '$item_when' => relative_date($it['date'])
72                                 ));
73                         }
74                 } else {
75                         $notif_content .= t('No more system notifications.');
76                 }
77
78                 $o .= replace_macros($notif_tpl, array(
79                         '$notif_header' => t('System Notifications'),
80                         '$tabs' => '', // $tabs,
81                         '$notif_content' => $notif_content,
82                 ));
83
84         return $o;
85
86
87 }