]> git.mxchange.org Git - friendica.git/blob - mod/contacts.php
mucho progress on notifier, email style dfrn url's
[friendica.git] / mod / contacts.php
1 <?php
2 function edit_contact(&$a,$contact_id) {
3
4 }
5
6 function contacts_post(&$a) {
7
8         
9         if(($a->argc != 3) || (! local_user()))
10                 return;
11
12         $contact_id = intval($a->argv[1]);
13         if(! $contact_id)
14                 return;
15
16         $cmd = $a->argv[2];
17
18         $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
19                 intval($contact_id),
20                 intval($_SESSION['uid'])
21         );
22
23         if(! count($r))
24                 return;
25         $photo = str_replace('-4.jpg', '' , $r[0]['photo']);
26         $photos = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d",
27                         dbesc($photo),
28                         intval($_SESSION['uid'])
29         );
30         
31
32         switch($cmd) {
33                 case 'edit':
34                                 edit_contact($a,$contact_id);
35                         break;
36                 case 'block':
37                         $r = q("UPDATE `contact` SET `blocked` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1",
38                                 intval($contact_id),
39                                 intval($_SESSION['uid'])
40                         );
41                         if($r)
42                                 $_SESSION['sysmsg'] .= "Contact has been blocked." . EOL;
43                         break;
44                 case 'drop':
45                         $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
46                                 intval($contact_id),
47                                 intval($_SESSION['uid']));
48                         if(count($photos)) {
49                                 foreach($photos as $p) {
50                                         q("DELETE FROM `photos` WHERE `id` = %d LIMIT 1",
51                                                 $p['id']);
52                                 }
53                         }
54                         if($intval($contact_id))
55                                 q("DELETE FROM `item` WHERE `contact-id` = %d LIMIT 1",
56                                         intval($contact_id)
57                                 );
58
59                         break;
60                 default:
61                         return;
62                         break;
63         }
64
65 }
66
67
68
69
70
71
72
73
74
75
76
77 function contacts_content(&$a) {
78         if(! local_user()) {
79                 $_SESSION['sysmsg'] .= "Permission denied." . EOL;
80                 return;
81         }
82
83
84
85
86         if(($a->argc == 2) && intval($a->argv[1])) {
87
88                 $contact_id = intval($a->argv[1]);
89                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
90                         $_SESSION['uid'],
91                         intval($contact_id)
92                 );
93                 if(! count($r)) {
94                         notice("Contact not found.");
95                         return;
96                 }
97
98                 require_once('view/contact_selectors.php');
99
100                 $tpl = file_get_contents("view/contact_edit.tpl");
101
102                 $o .= replace_macros($tpl,array(
103                         '$profile_select' => contact_profile_assign($r[0]['profile-id']),
104                         '$contact_id' => $r[0]['id'],
105                         '$blocked' => $r[0]['blocked'],
106                         '$rating' => $r[0]['rating'],
107                         '$reason' => $r[0]['reason'],
108         //              '$groups' => group_selector(),
109                         '$photo' => $r[0]['photo'],
110                         '$name' => $r[0]['name'],
111                         '$dir_icon' => $dir_icon,
112                         '$alt_text' => $alt_text
113
114                 ));
115
116                 return $o;
117
118         }
119
120         if(($a->argc == 2) && ($a->argv[1] == 'all'))
121                 $sql_extra = '';
122         else
123                 $sql_extra = " AND `blocked` = 0 ";
124
125         $tpl = file_get_contents("view/contacts-top.tpl");
126         $o .= replace_macros($tpl,array(
127                 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
128                 '$hide_text' => ((strlen($sql_extra)) ? 'Show Blocked Connections' : 'Hide Blocked Connections')
129         )); 
130
131         switch($sort_type) {
132                 case DIRECTION_BOTH :
133                         $sql_extra = " AND `dfrn-id` != '' AND `issued-id` != '' ";
134                         break;
135                 case DIRECTION_IN :
136                         $sql_extra = " AND `dfrn-id` = '' AND `issued-id` != '' ";
137                         break;
138                 case DIRECTION_OUT :
139                         $sql_extra = " AND `dfrn-id` != '' AND `issued-id` = '' ";
140                         break;
141                 case DIRECTION_ANY :
142                 default:
143                         $sql_extra = '';
144                         break;
145         }
146
147         $r = q("SELECT * FROM `contact` WHERE `uid` = %d $sql_extra",
148                 intval($_SESSION['uid']));
149
150         if(count($r)) {
151
152                 $tpl = file_get_contents("view/contact_template.tpl");
153
154                 foreach($r as $rr) {
155                         if($rr['self'])
156                                 continue;
157                         $direction = '';
158                         if(strlen($rr['issued-id'])) {
159                                 if(strlen($rr['dfrn-id'])) {
160                                         $direction = DIRECTION_BOTH;
161                                         $dir_icon = 'images/lrarrow.gif';
162                                         $alt_text = 'Mutual Friendship';
163                                 }
164                                 else {
165                                         $direction = DIRECTION_IN;
166                                         $dir_icon = 'images/larrow.gif';
167                                         $alt_text = 'is a fan of yours';
168                                 }
169                         }
170                         else {
171                                 $direction = DIRECTION_OUT;
172                                 $dir_icon = 'images/rarrow.gif';
173                                 $alt_text = 'you are a fan of';
174                         }
175
176                         $o .= replace_macros($tpl, array(
177                                 '$id' => $rr['id'],
178                                 '$alt_text' => $alt_text,
179                                 '$dir_icon' => $dir_icon,
180                                 '$thumb' => $rr['thumb'], 
181                                 '$name' => $rr['name'],
182                                 '$url' => (($direction != DIRECTION_IN) ? "redir/{$rr['id']}" : $rr['url'] )
183                         ));
184                 }
185         }
186         return $o;
187
188
189 }