]> git.mxchange.org Git - friendica.git/blob - mod/notifications.php
b5b97cc949aaa1f3d6f9ed9ba6eb25d111361e5b
[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($_SESSION['uid'])
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", intval($intro_id));       
32                         $r = q("DELETE `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", 
33                                 intval($request_id),
34                                 intval($_SESSION['uid']));
35                         return;
36                 }
37                 if($_POST['submit'] == t('Ignore')) {
38                         $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d LIMIT 1",
39                                 intval($intro_id));
40                         return;
41                 }
42         }
43 }
44
45
46
47
48
49 function notifications_content(&$a) {
50
51         if(! local_user()) {
52                 notice( t('Permission denied.') . EOL);
53                 goaway($a->get_baseurl());
54         }
55
56         $o = '';
57
58         if(($a->argc > 1) && ($a->argv[1] == 'all'))
59                 $sql_extra = '';
60         else
61                 $sql_extra = " AND `ignore` = 0 ";
62
63
64         $tpl = file_get_contents('view/intros-top.tpl');
65         $o .= replace_macros($tpl,array(
66                 '$hide_url' => ((strlen($sql_extra)) ? 'notifications/all' : 'notifications' ),
67                 '$hide_text' => ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests'))
68         )); 
69
70         $r = q("SELECT `intro`.`id` AS `intro-id`, `intro`.*, `contact`.* 
71                 FROM `intro` LEFT JOIN `contact` ON `intro`.`contact-id` = `contact`.`id`
72                 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
73                         intval($_SESSION['uid']));
74
75         if(($r !== false) && (count($r))) {
76
77
78                 $tpl = file_get_contents("view/intros.tpl");
79
80                 foreach($r as $rr) {
81
82                         $o .= replace_macros($tpl,array(
83                                 '$intro_id' => $rr['intro-id'],
84                                 '$dfrn-id' => $rr['issued-id'],
85                                 '$uid' => $_SESSION['uid'],
86                                 '$contact-id' => $rr['contact-id'],
87                                 '$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/default-profile.jpg"),
88                                 '$fullname' => $rr['name'],
89                                 '$knowyou' => (($rr['knowyou']) ? t('yes') : t('no')),
90                                 '$url' => $rr['url'],
91                                 '$note' => $rr['note']
92                         ));
93                 }
94         }
95         else
96                 notice( t('No notifications.') . EOL);
97
98         return $o;
99 }