]> git.mxchange.org Git - friendica.git/blob - mod/contacts.php
dcbadd2bac5def3ddc6f80616ff10da2c5092333
[friendica.git] / mod / contacts.php
1 <?php
2
3 function contacts_init(&$a) {
4         require_once('include/group.php');
5         $a->page['aside'] .= group_side();
6 }
7
8 function contacts_post(&$a) {
9
10         
11         if(! local_user())
12                 return;
13
14         $contact_id = intval($a->argv[1]);
15         if(! $contact_id)
16                 return;
17
18         $orig_record = 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($orig_record)) {
24                 notice("Could not access contact record." . EOL);
25                 goaway($a->get_baseurl() . '/contacts');
26                 return; // NOTREACHED
27         }
28
29         $profile_id = intval($_POST['profile-assign']);
30         if($profile_id) {
31                 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
32                         intval($profile_id),
33                         intval($_SESSION['uid'])
34                 );
35                 if(! count($r)) {
36                         notice("Cannot locate selected profile." . EOL);
37                         return;
38                 }
39         }
40         $rating = intval($_POST['reputation']);
41         if($rating > 5 || $rating < 0)
42                 $rating = 0;
43
44         $reason = notags(trim($_POST['reason']));
45
46         $r = q("UPDATE `contact` SET `profile-id` = %d, `rating` = %d, `reason` = '%s'
47                 WHERE `id` = %d AND `uid` = %d LIMIT 1",
48                 intval($profile_id),
49                 intval($rating),
50                 dbesc($reason),
51                 intval($contact_id),
52                 intval($_SESSION['uid'])
53         );
54         if($r)
55                 notice("Contact updated." . EOL);
56         else
57                 notice("Failed to update contact record." . EOL);
58         return;
59
60 }
61
62
63
64 function contacts_content(&$a) {
65
66         if(! local_user()) {
67                 $_SESSION['sysmsg'] .= "Permission denied." . EOL;
68                 return;
69         }
70
71         if($a->argc == 3) {
72
73                 $contact_id = intval($a->argv[1]);
74                 if(! $contact_id)
75                         return;
76
77                 $cmd = $a->argv[2];
78
79                 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
80                         intval($contact_id),
81                         intval($_SESSION['uid'])
82                 );
83
84                 if(! count($orig_record)) {
85                         notice("Could not access contact record." . EOL);
86                         goaway($a->get_baseurl() . '/contacts');
87                         return; // NOTREACHED
88                 }
89
90
91 //              $photo = str_replace('-4.jpg', '' , $r[0]['photo']);
92 //              $photos = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d",
93 //                              dbesc($photo),
94 //                              intval($_SESSION['uid'])
95 //              );
96         
97                 if($cmd == 'block') {
98                         $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
99                         $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
100                                         intval($blocked),
101                                         intval($contact_id),
102                                         intval($_SESSION['uid'])
103                         );
104                         if($r) {
105                                 $msg = "Contact has been " . (($blocked) ? '' : 'un') . "blocked." . EOL ;
106                                 notice($msg);
107                         }
108                         goaway($a->get_baseurl() ."/contacts/$contact_id");
109                         return; // NOTREACHED
110                 }
111
112                 if($cmd == 'drop') {
113                         $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
114                                 intval($contact_id),
115                                 intval($_SESSION['uid']));
116
117 //                      if(count($photos)) {
118 //                              foreach($photos as $p) {
119 //                                      q("DELETE FROM `photos` WHERE `id` = %d LIMIT 1",
120 //                                              $p['id']);
121 //                              }
122 //                      }
123
124                         if(intval($contact_id))
125                                 q("DELETE FROM `item` WHERE `contact-id` = %d LIMIT 1",
126                                         intval($contact_id)
127                                 );
128         
129                         notice("Contact has been removed." . EOL );
130                         goaway($a->get_baseurl() . '/contacts');
131                         return; // NOTREACHED
132                 }
133         }
134
135         if(($a->argc == 2) && intval($a->argv[1])) {
136
137                 $contact_id = intval($a->argv[1]);
138                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
139                         $_SESSION['uid'],
140                         intval($contact_id)
141                 );
142                 if(! count($r)) {
143                         notice("Contact not found.");
144                         return;
145                 }
146
147                 require_once('view/contact_selectors.php');
148
149                 $tpl = file_get_contents("view/contact_edit.tpl");
150
151                 $direction = '';
152                 if(strlen($r[0]['issued-id'])) {
153                         if(strlen($r[0]['dfrn-id'])) {
154                                 $direction = DIRECTION_BOTH;
155                                 $dir_icon = 'images/lrarrow.gif';
156                                 $alt_text = 'Mutual Friendship';
157                         }
158                         else {
159                                 $direction = DIRECTION_IN;
160                                 $dir_icon = 'images/larrow.gif';
161                                 $alt_text = 'is a fan of yours';
162                         }
163                 }
164                 else {
165                         $direction = DIRECTION_OUT;
166                         $dir_icon = 'images/rarrow.gif';
167                         $alt_text = 'you are a fan of';
168                 }
169
170                 $o .= replace_macros($tpl,array(
171                         '$profile_select' => contact_profile_assign($r[0]['profile-id']),
172                         '$contact_id' => $r[0]['id'],
173                         '$block_text' => (($r[0]['blocked']) ? 'Unblock this contact' : 'Block this contact' ),
174                         '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">Currently blocked</div>' : ''),
175                         '$rating' => contact_reputation($r[0]['rating']),
176                         '$reason' => $r[0]['reason'],
177                         '$groups' => '', // group_selector(),
178                         '$photo' => $r[0]['photo'],
179                         '$name' => $r[0]['name'],
180                         '$dir_icon' => $dir_icon,
181                         '$alt_text' => $alt_text,
182                         '$url' => (($direction != DIRECTION_IN) ? "redir/{$r[0]['id']}" : $r[0]['url'] )
183
184                 ));
185
186                 return $o;
187
188         }
189
190         if(($a->argc == 2) && ($a->argv[1] == 'all'))
191                 $sql_extra = '';
192         else
193                 $sql_extra = " AND `blocked` = 0 ";
194
195         $tpl = file_get_contents("view/contacts-top.tpl");
196         $o .= replace_macros($tpl,array(
197                 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
198                 '$hide_text' => ((strlen($sql_extra)) ? 'Show Blocked Connections' : 'Hide Blocked Connections')
199         )); 
200
201         switch($sort_type) {
202                 case DIRECTION_BOTH :
203                         $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` != '' ";
204                         break;
205                 case DIRECTION_IN :
206                         $sql_extra2 = " AND `dfrn-id` = '' AND `issued-id` != '' ";
207                         break;
208                 case DIRECTION_OUT :
209                         $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` = '' ";
210                         break;
211                 case DIRECTION_ANY :
212                 default:
213                         $sql_extra2 = '';
214                         break;
215         }
216
217         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
218                 intval($_SESSION['uid']));
219
220         if(count($r)) {
221
222                 $tpl = file_get_contents("view/contact_template.tpl");
223
224                 foreach($r as $rr) {
225                         if($rr['self'])
226                                 continue;
227                         $direction = '';
228                         if(strlen($rr['issued-id'])) {
229                                 if(strlen($rr['dfrn-id'])) {
230                                         $direction = DIRECTION_BOTH;
231                                         $dir_icon = 'images/lrarrow.gif';
232                                         $alt_text = 'Mutual Friendship';
233                                 }
234                                 else {
235                                         $direction = DIRECTION_IN;
236                                         $dir_icon = 'images/larrow.gif';
237                                         $alt_text = 'is a fan of yours';
238                                 }
239                         }
240                         else {
241                                 $direction = DIRECTION_OUT;
242                                 $dir_icon = 'images/rarrow.gif';
243                                 $alt_text = 'you are a fan of';
244                         }
245
246                         $o .= replace_macros($tpl, array(
247                                 '$id' => $rr['id'],
248                                 '$alt_text' => $alt_text,
249                                 '$dir_icon' => $dir_icon,
250                                 '$thumb' => $rr['thumb'], 
251                                 '$name' => $rr['name'],
252                                 '$url' => (($direction != DIRECTION_IN) ? "redir/{$rr['id']}" : $rr['url'] )
253                         ));
254                 }
255         }
256         return $o;
257 }