]> git.mxchange.org Git - friendica.git/blob - mod/notifications.php
our implementation of "aspects" functionally complete
[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(get_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", 
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(get_uid())
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
61         if(($a->argc > 1) && ($a->argv[1] == 'all'))
62                 $sql_extra = '';
63         else
64                 $sql_extra = " AND `ignore` = 0 ";
65
66
67         $tpl = file_get_contents('view/intros-top.tpl');
68         $o .= replace_macros($tpl,array(
69                 '$hide_url' => ((strlen($sql_extra)) ? 'notifications/all' : 'notifications' ),
70                 '$hide_text' => ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests'))
71         )); 
72
73         $r = q("SELECT `intro`.`id` AS `intro-id`, `intro`.*, `contact`.* 
74                 FROM `intro` LEFT JOIN `contact` ON `intro`.`contact-id` = `contact`.`id`
75                 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
76                         intval($_SESSION['uid']));
77
78         if(($r !== false) && (count($r))) {
79
80
81                 $tpl = file_get_contents("view/intros.tpl");
82
83                 foreach($r as $rr) {
84
85                         $o .= replace_macros($tpl,array(
86                                 '$intro_id' => $rr['intro-id'],
87                                 '$dfrn-id' => $rr['issued-id'],
88                                 '$uid' => $_SESSION['uid'],
89                                 '$contact-id' => $rr['contact-id'],
90                                 '$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/default-profile.jpg"),
91                                 '$fullname' => $rr['name'],
92                                 '$knowyou' => (($rr['knowyou']) ? t('yes') : t('no')),
93                                 '$url' => $rr['url'],
94                                 '$note' => $rr['note']
95                         ));
96                 }
97         }
98         else
99                 notice( t('No notifications.') . EOL);
100
101         return $o;
102 }