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