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