]> git.mxchange.org Git - friendica.git/blob - mod/notifications.php
preserve utf-8 on notification emails
[friendica.git] / mod / notifications.php
1 <?php
2
3 function notifications_post(&$a) {
4
5         if(! local_user()) {
6                 goaway($a->get_baseurl());
7         }
8         
9         $request_id = (($a->argc > 1) ? $a->argv[1] : 0);
10         
11         if($request_id === "all")
12                 return;
13
14         if($request_id) {
15
16                 $r = q("SELECT `id` FROM `intro` 
17                         WHERE `request-id` = %d 
18                         AND `uid` = %d LIMIT 1",
19                                 intval($request_id),
20                                 intval(local_user())
21                 );
22         
23                 if(count($r)) {
24                         $intro_id = $r[0]['id'];
25                 }
26                 else {
27                         notice( t('Invalid request identifier.') . EOL);
28                         return;
29                 }
30                 if($_POST['submit'] == t('Discard')) {
31                         $r = q("DELETE FROM `intro` WHERE `id` = %d LIMIT 1", 
32                                 intval($intro_id)
33                         );      
34                         $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", 
35                                 intval($request_id),
36                                 intval(local_user())
37                         );
38                         return;
39                 }
40                 if($_POST['submit'] == t('Ignore')) {
41                         $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d LIMIT 1",
42                                 intval($intro_id));
43                         return;
44                 }
45         }
46 }
47
48
49
50
51
52 function notifications_content(&$a) {
53
54         if(! local_user()) {
55                 notice( t('Permission denied.') . EOL);
56                 goaway($a->get_baseurl());
57         }
58
59         $o = '';
60         $o .= '<script> $(document).ready(function() { $(\'#nav-notify-link\').addClass(\'nav-selected\'); });</script>';
61
62         if(($a->argc > 1) && ($a->argv[1] == 'all'))
63                 $sql_extra = '';
64         else
65                 $sql_extra = " AND `ignore` = 0 ";
66
67
68         $tpl = load_view_file('view/intros-top.tpl');
69         $o .= replace_macros($tpl,array(
70                 '$hide_url' => ((strlen($sql_extra)) ? 'notifications/all' : 'notifications' ),
71                 '$hide_text' => ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests'))
72         )); 
73
74         $r = q("SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.* 
75                 FROM `intro` LEFT JOIN `contact` ON `intro`.`contact-id` = `contact`.`id`
76                 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
77                         intval($_SESSION['uid']));
78
79         if(($r !== false) && (count($r))) {
80
81
82                 $tpl = load_view_file("view/intros.tpl");
83
84                 foreach($r as $rr) {
85
86                         $friend_selected = (($rr['network'] === 'dfrn') ? ' checked="checked" ' : ' disabled ');
87                         $fan_selected = (($rr['network'] === 'stat') ? ' checked="checked" disabled ' : '');
88                         $dfrn_tpl = load_view_file('view/netfriend.tpl');
89
90                         $knowyou   = '';
91                         $dfrn_text = '';
92                                                 
93                         if($rr['network'] === 'dfrn') {
94                                 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
95
96                                 $dfrn_text = replace_macros($dfrn_tpl,array(
97                                         '$intro_id' => $rr['intro_id'],
98                                         '$friend_selected' => $friend_selected,
99                                         '$fan_selected' => $fan_selected,
100                                 ));
101                         }                       
102
103
104
105                         $o .= replace_macros($tpl,array(
106                                 '$notify_type' => (($rr['network'] === 'dfrn') ? t('Friend/Connect Request') : t('New Follower')),
107                                 '$dfrn_text' => $dfrn_text,     
108                                 '$dfrn_id' => $rr['issued-id'],
109                                 '$uid' => $_SESSION['uid'],
110                                 '$intro_id' => $rr['intro_id'],
111                                 '$contact_id' => $rr['contact-id'],
112                                 '$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/default-profile.jpg"),
113                                 '$fullname' => $rr['name'],
114                                 '$url' => $rr['url'],
115                                 '$knowyou' => $knowyou,
116                                 '$note' => $rr['note']
117                         ));
118                 }
119         }
120         else
121                 notice( t('No notifications.') . EOL);
122
123         return $o;
124 }