]> git.mxchange.org Git - friendica.git/blob - mod/notifications.php
some more zot changes migrating back to f9a mainline
[friendica.git] / mod / notifications.php
1 <?php
2
3 function notifications_post(&$a) {
4
5         if(! local_user()) {
6                 goaway(z_root());
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` WHERE `id` = %d  AND `uid` = %d LIMIT 1",
17                         intval($request_id),
18                         intval(local_user())
19                 );
20         
21                 if(count($r)) {
22                         $intro_id = $r[0]['id'];
23                         $contact_id = $r[0]['contact-id'];
24                 }
25                 else {
26                         notice( t('Invalid request identifier.') . EOL);
27                         return;
28                 }
29
30                 // If it is a friend suggestion, the contact is not a new friend but an existing friend
31                 // that should not be deleted.
32
33                 $fid = $r[0]['fid'];
34
35                 if($_POST['submit'] == t('Discard')) {
36                         $r = q("DELETE FROM `intro` WHERE `id` = %d LIMIT 1", 
37                                 intval($intro_id)
38                         );      
39                         if(! $fid) {
40                                 $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1", 
41                                         intval($contact_id),
42                                         intval(local_user())
43                                 );
44                         }
45                         return;
46                 }
47                 if($_POST['submit'] == t('Ignore')) {
48                         $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d LIMIT 1",
49                                 intval($intro_id));
50                         return;
51                 }
52         }
53 }
54
55
56
57
58
59 function notifications_content(&$a) {
60
61         if(! local_user()) {
62                 notice( t('Permission denied.') . EOL);
63                 return;
64         }
65
66         $o = '';
67         $o .= '<script> $(document).ready(function() { $(\'#nav-notify-link\').addClass(\'nav-selected\'); });</script>';
68
69         if(($a->argc > 1) && ($a->argv[1] == 'all'))
70                 $sql_extra = '';
71         else
72                 $sql_extra = " AND `ignore` = 0 ";
73
74         $o .= '<h1>' . t('Pending Friend/Connect Notifications') . '</h1>' . "\r\n";
75         
76         $o .= '<div id="notification-show-hide-wrapper" >';
77         $o .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/all' : 'notifications' ) . '" id="notifications-show-hide-link" >'
78                 . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
79
80
81         $r = q("SELECT COUNT(*) AS `total` FROM `intro` 
82                 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
83                         intval($_SESSION['uid'])
84         );
85         if($r && count($r)) {
86                 $a->set_pager_total($r[0]['total']);
87                 $a->set_pager_itemspage(20);
88         }
89
90         $r = q("SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*, `fcontact`.`name` AS `fname`,`fcontact`.`url` AS `furl`,`fcontact`.`photo` AS `fphoto`,`fcontact`.`request` AS `frequest`
91                 FROM `intro` LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
92                 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
93                         intval($_SESSION['uid']));
94
95         if(($r !== false) && (count($r))) {
96
97                 $sugg = get_markup_template('suggestions.tpl');
98                 $tpl = get_markup_template("intros.tpl");
99
100                 foreach($r as $rr) {
101                         if($rr['fid']) {
102
103                                 $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
104                                 $o .= replace_macros($sugg,array(
105                                         '$str_notifytype' => t('Notification type: '),
106                                         '$notify_type' => t('Friend Suggestion'),
107                                         '$intro_id' => $rr['intro_id'],
108                                         '$madeby' => sprintf( t('suggested by %s'),$rr['name']),
109                                         '$contact_id' => $rr['contact-id'],
110                                         '$photo' => ((x($rr,'fphoto')) ? $rr['fphoto'] : "images/default-profile.jpg"),
111                                         '$fullname' => $rr['fname'],
112                                         '$url' => $rr['furl'],
113                                         '$knowyou' => $knowyou,
114                                         '$approve' => t('Approve'),
115                                         '$note' => $rr['note'],
116                                         '$request' => $rr['frequest'] . '?addr=' . $return_addr,
117                                         '$ignore' => t('Ignore'),
118                                         '$discard' => t('Discard')
119
120                                 ));
121
122                                 continue;
123
124                         }
125                         $friend_selected = (($rr['network'] !== 'stat') ? ' checked="checked" ' : ' disabled ');
126                         $fan_selected = (($rr['network'] === 'stat') ? ' checked="checked" disabled ' : '');
127                         $dfrn_tpl = get_markup_template('netfriend.tpl');
128
129                         $knowyou   = '';
130                         $dfrn_text = '';
131                                                 
132                         if($rr['network'] !== 'stat') {
133                                 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
134
135                                 $dfrn_text = replace_macros($dfrn_tpl,array(
136                                         '$intro_id' => $rr['intro_id'],
137                                         '$friend_selected' => $friend_selected,
138                                         '$fan_selected' => $fan_selected,
139                                         '$approve_as' => t('Approve as: '),
140                                         '$as_friend' => t('Friend'),
141                                         '$as_fan' => t('Fan/Admirer')
142                                 ));
143                         }                       
144
145
146
147                         $o .= replace_macros($tpl,array(
148                                 '$str_notifytype' => t('Notification type: '),
149                                 '$notify_type' => (($rr['network'] !== 'stat') ? t('Friend/Connect Request') : t('New Follower')),
150                                 '$dfrn_text' => $dfrn_text,     
151                                 '$dfrn_id' => $rr['issued-id'],
152                                 '$uid' => $_SESSION['uid'],
153                                 '$intro_id' => $rr['intro_id'],
154                                 '$contact_id' => $rr['contact-id'],
155                                 '$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/default-profile.jpg"),
156                                 '$fullname' => $rr['name'],
157                                 '$url' => $rr['url'],
158                                 '$knowyou' => $knowyou,
159                                 '$approve' => t('Approve'),
160                                 '$note' => $rr['note'],
161                                 '$ignore' => t('Ignore'),
162                                 '$discard' => t('Discard')
163
164                         ));
165                 }
166         }
167         else
168                 info( t('No notifications.') . EOL);
169
170         $o .= paginate($a);
171         return $o;
172 }