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