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