]> git.mxchange.org Git - friendica.git/blob - mod/contacts.php
Merge branch 'master' into develop
[friendica.git] / mod / contacts.php
1 <?php
2
3 require_once('include/Contact.php');
4 require_once('include/socgraph.php');
5 require_once('include/contact_selectors.php');
6 require_once('mod/proxy.php');
7
8 function contacts_init(&$a) {
9         if(! local_user())
10                 return;
11
12         $contact_id = 0;
13
14         if(($a->argc == 2) && intval($a->argv[1])) {
15                 $contact_id = intval($a->argv[1]);
16                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
17                         intval(local_user()),
18                         intval($contact_id)
19                 );
20                 if(! count($r)) {
21                         $contact_id = 0;
22                 }
23         }
24
25         require_once('include/group.php');
26         require_once('include/contact_widgets.php');
27
28         if(! x($a->page,'aside'))
29                 $a->page['aside'] = '';
30
31         if($contact_id) {
32                         $a->data['contact'] = $r[0];
33                         $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
34                                 '$name' => $a->data['contact']['name'],
35                                 '$photo' => $a->data['contact']['photo']
36                         ));
37                         $follow_widget = '';
38         }
39         else {
40                 $vcard_widget = '';
41                 if (isset($_GET['add']))
42                         $follow_widget = follow_widget($_GET['add']);
43                 else
44                         $follow_widget = follow_widget();
45         }
46
47         if ($_GET['nets'] == "all")
48                 $_GET['nets'] = "";
49
50         $groups_widget .= group_side('contacts','group',false,0,$contact_id);
51         $findpeople_widget .= findpeople_widget();
52         $networks_widget .= networks_widget('contacts',$_GET['nets']);
53         $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
54                 '$vcard_widget' => $vcard_widget,
55                 '$follow_widget' => $follow_widget,
56                 '$groups_widget' => $groups_widget,
57                 '$findpeople_widget' => $findpeople_widget,
58                 '$networks_widget' => $networks_widget
59         ));
60
61         $base = $a->get_baseurl();
62         $tpl = get_markup_template("contacts-head.tpl");
63         $a->page['htmlhead'] .= replace_macros($tpl,array(
64                 '$baseurl' => $a->get_baseurl(true),
65                 '$base' => $base
66         ));
67
68         $tpl = get_markup_template("contacts-end.tpl");
69         $a->page['end'] .= replace_macros($tpl,array(
70                 '$baseurl' => $a->get_baseurl(true),
71                 '$base' => $base
72         ));
73
74
75 }
76
77 function contacts_batch_actions(&$a){
78         $contacts_id = $_POST['contact_batch'];
79         if (!is_array($contacts_id)) return;
80
81         $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
82                 implode(",", $contacts_id),
83                 intval(local_user())
84         );
85
86         $count_actions=0;
87         foreach($orig_records as $orig_record) {
88                 $contact_id = $orig_record['id'];
89                 if (x($_POST, 'contacts_batch_update')) {
90                         _contact_update($contact_id);
91                         $count_actions++;
92                 }
93                 if (x($_POST, 'contacts_batch_block')) {
94                         $r  = _contact_block($contact_id, $orig_record);
95                         if ($r) $count_actions++;
96                 }
97                 if (x($_POST, 'contacts_batch_ignore')) {
98                         $r = _contact_ignore($contact_id, $orig_record);
99                         if ($r) $count_actions++;
100                 }
101                 if (x($_POST, 'contacts_batch_archive')) {
102                         $r = _contact_archive($contact_id, $orig_record);
103                         if ($r) $count_actions++;
104                 }
105                 if (x($_POST, 'contacts_batch_drop')) {
106                         _contact_drop($contact_id, $orig_record);
107                         $count_actions++;
108                 }
109         }
110         if ($count_actions>0) {
111                 info ( sprintf( tt("%d contact edited.", "%d contacts edited", $count_actions), $count_actions) );
112         }
113
114         if(x($_SESSION,'return_url'))
115                 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
116         else
117                 goaway($a->get_baseurl(true) . '/contacts');
118
119 }
120
121
122 function contacts_post(&$a) {
123
124         if(! local_user())
125                 return;
126
127         if ($a->argv[1]==="batch") {
128                 contacts_batch_actions($a);
129                 return;
130         }
131
132         $contact_id = intval($a->argv[1]);
133         if(! $contact_id)
134                 return;
135
136         $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
137                 intval($contact_id),
138                 intval(local_user())
139         );
140
141         if(! count($orig_record)) {
142                 notice( t('Could not access contact record.') . EOL);
143                 goaway($a->get_baseurl(true) . '/contacts');
144                 return; // NOTREACHED
145         }
146
147         call_hooks('contact_edit_post', $_POST);
148
149         $profile_id = intval($_POST['profile-assign']);
150         if($profile_id) {
151                 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
152                         intval($profile_id),
153                         intval(local_user())
154                 );
155                 if(! count($r)) {
156                         notice( t('Could not locate selected profile.') . EOL);
157                         return;
158                 }
159         }
160
161         $hidden = intval($_POST['hidden']);
162
163         $notify = intval($_POST['notify']);
164
165         $fetch_further_information = intval($_POST['fetch_further_information']);
166
167         $ffi_keyword_blacklist = fix_mce_lf(escape_tags(trim($_POST['ffi_keyword_blacklist'])));
168
169         $priority = intval($_POST['poll']);
170         if($priority > 5 || $priority < 0)
171                 $priority = 0;
172
173         $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
174
175         $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
176                 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
177                 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
178                 intval($profile_id),
179                 intval($priority),
180                 dbesc($info),
181                 intval($hidden),
182                 intval($notify),
183                 intval($fetch_further_information),
184                 dbesc($ffi_keyword_blacklist),
185                 intval($contact_id),
186                 intval(local_user())
187         );
188         if($r)
189                 info( t('Contact updated.') . EOL);
190         else
191                 notice( t('Failed to update contact record.') . EOL);
192
193         $r = q("select * from contact where id = %d and uid = %d limit 1",
194                 intval($contact_id),
195                 intval(local_user())
196         );
197         if($r && count($r))
198                 $a->data['contact'] = $r[0];
199
200         return;
201
202 }
203
204 /*contact actions*/
205 function _contact_update($contact_id) {
206         // pull feed and consume it, which should subscribe to the hub.
207         proc_run('php',"include/poller.php","$contact_id"); 
208 }
209 function _contact_block($contact_id, $orig_record) {
210         $blocked = (($orig_record['blocked']) ? 0 : 1);
211         $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
212                 intval($blocked),
213                 intval($contact_id),
214                 intval(local_user())
215         );
216         return $r;
217
218 }
219 function _contact_ignore($contact_id, $orig_record) {
220         $readonly = (($orig_record['readonly']) ? 0 : 1);
221         $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
222                 intval($readonly),
223                 intval($contact_id),
224                 intval(local_user())
225         );
226         return $r;
227 }
228 function _contact_archive($contact_id, $orig_record) {
229         $archived = (($orig_record['archive']) ? 0 : 1);
230         $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
231                 intval($archived),
232                 intval($contact_id),
233                 intval(local_user())
234         );
235         if ($archived) {
236                 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
237         }
238         return $r;
239 }
240 function _contact_drop($contact_id, $orig_record) {
241         require_once('include/Contact.php');
242         $a = get_app();
243
244         terminate_friendship($a->user,$a->contact,$orig_record);
245         contact_remove($orig_record['id']);
246 }
247
248
249 function contacts_content(&$a) {
250
251         $sort_type = 0;
252         $o = '';
253         nav_set_selected('contacts');
254
255
256         if(! local_user()) {
257                 notice( t('Permission denied.') . EOL);
258                 return;
259         }
260
261         if($a->argc == 3) {
262
263                 $contact_id = intval($a->argv[1]);
264                 if(! $contact_id)
265                         return;
266
267                 $cmd = $a->argv[2];
268
269                 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
270                         intval($contact_id),
271                         intval(local_user())
272                 );
273
274                 if(! count($orig_record)) {
275                         notice( t('Could not access contact record.') . EOL);
276                         goaway($a->get_baseurl(true) . '/contacts');
277                         return; // NOTREACHED
278                 }
279
280                 if($cmd === 'update') {
281                         _contact_update($contact_id);
282                         goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
283                         // NOTREACHED
284                 }
285
286                 if($cmd === 'block') {
287                         $r = _contact_block($contact_id, $orig_record[0]);
288                         if($r) {
289                                 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
290                                 info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL);
291                         }
292
293                         goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
294                         return; // NOTREACHED
295                 }
296
297                 if($cmd === 'ignore') {
298                         $r = _contact_ignore($contact_id, $orig_record[0]);
299                         if($r) {
300                                 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
301                                 info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL);
302                         }
303
304                         goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
305                         return; // NOTREACHED
306                 }
307
308
309                 if($cmd === 'archive') {
310                         $r = _contact_archive($contact_id, $orig_record[0]);
311                         if($r) {
312                                 $archived = (($orig_record[0]['archive']) ? 0 : 1);
313                                 info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL);
314                         }
315
316                         goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
317                         return; // NOTREACHED
318                 }
319
320                 if($cmd === 'drop') {
321
322                         // Check if we should do HTML-based delete confirmation
323                         if($_REQUEST['confirm']) {
324                                 // <form> can't take arguments in its "action" parameter
325                                 // so add any arguments as hidden inputs
326                                 $query = explode_querystring($a->query_string);
327                                 $inputs = array();
328                                 foreach($query['args'] as $arg) {
329                                         if(strpos($arg, 'confirm=') === false) {
330                                                 $arg_parts = explode('=', $arg);
331                                                 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
332                                         }
333                                 }
334
335                                 $a->page['aside'] = '';
336                                 return replace_macros(get_markup_template('confirm.tpl'), array(
337                                         '$method' => 'get',
338                                         '$message' => t('Do you really want to delete this contact?'),
339                                         '$extra_inputs' => $inputs,
340                                         '$confirm' => t('Yes'),
341                                         '$confirm_url' => $query['base'],
342                                         '$confirm_name' => 'confirmed',
343                                         '$cancel' => t('Cancel'),
344                                 ));
345                         }
346                         // Now check how the user responded to the confirmation query
347                         if($_REQUEST['canceled']) {
348                                 if(x($_SESSION,'return_url'))
349                                         goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
350                                 else
351                                         goaway($a->get_baseurl(true) . '/contacts');
352                         }
353
354                         _contact_drop($contact_id, $orig_record[0]);
355                         info( t('Contact has been removed.') . EOL );
356                         if(x($_SESSION,'return_url'))
357                                 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
358                         else
359                                 goaway($a->get_baseurl(true) . '/contacts');
360                         return; // NOTREACHED
361                 }
362         }
363
364
365
366         $_SESSION['return_url'] = $a->query_string;
367
368         if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
369
370                 $contact_id = $a->data['contact']['id'];
371                 $contact = $a->data['contact'];
372
373                 $editselect = 'none';
374                 if( feature_enabled(local_user(),'richtext') )
375                         $editselect = 'exact';
376
377                 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
378                         '$baseurl' => $a->get_baseurl(true),
379                         '$editselect' => $editselect,
380                 ));
381                 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
382                         '$baseurl' => $a->get_baseurl(true),
383                         '$editselect' => $editselect,
384                 ));
385
386                 require_once('include/contact_selectors.php');
387
388                 $tpl = get_markup_template("contact_edit.tpl");
389
390                 switch($contact['rel']) {
391                         case CONTACT_IS_FRIEND:
392                                 $dir_icon = 'images/lrarrow.gif';
393                                 $relation_text = t('You are mutual friends with %s');
394                                 break;
395                         case CONTACT_IS_FOLLOWER;
396                                 $dir_icon = 'images/larrow.gif';
397                                 $relation_text = t('You are sharing with %s');
398                                 break;
399
400                         case CONTACT_IS_SHARING;
401                                 $dir_icon = 'images/rarrow.gif';
402                                 $relation_text = t('%s is sharing with you');
403                                 break;
404                         default:
405                                 break;
406                 }
407
408                 if(!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
409                                 $relation_text = "";
410
411                 $relation_text = sprintf($relation_text,$contact['name']);
412
413                 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
414                         $url = "redir/{$contact['id']}";
415                         $sparkle = ' class="sparkle" ';
416                 }
417                 else {
418                         $url = $contact['url'];
419                         $sparkle = '';
420                 }
421
422                 $insecure = t('Private communications are not available for this contact.');
423
424                 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
425                                 ? t('Never')
426                                 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
427
428                 if($contact['last-update'] !== '0000-00-00 00:00:00')
429                         $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
430
431                 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
432
433                 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
434
435                 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
436
437                 $common = count_common_friends(local_user(),$contact['id']);
438                 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
439
440                 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
441
442                 $x = count_all_friends(local_user(), $contact['id']);
443                 $all_friends = (($x) ? t('View all contacts') : '');
444
445                 // tabs
446                 $tabs = array(
447                         array(
448                                 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
449                                 'url'   => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
450                                 'sel'   => '',
451                                 'title' => t('Toggle Blocked status'),
452                         ),
453                         array(
454                                 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
455                                 'url'   => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
456                                 'sel'   => '',
457                                 'title' => t('Toggle Ignored status'),
458                         ),
459
460                         array(
461                                 'label' => (($contact['archive']) ? t('Unarchive') : t('Archive') ),
462                                 'url'   => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive',
463                                 'sel'   => '',
464                                 'title' => t('Toggle Archive status'),
465                         ),
466                         array(
467                                 'label' => t('Repair'),
468                                 'url'   => $a->get_baseurl(true) . '/crepair/' . $contact_id,
469                                 'sel'   => '',
470                                 'title' => t('Advanced Contact Settings'),
471                         )
472                 );
473                 $tab_tpl = get_markup_template('common_tabs.tpl');
474                 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
475
476                 $lost_contact = (($contact['archive'] && $contact['term-date'] != '0000-00-00 00:00:00' && $contact['term-date'] < datetime_convert('','','now')) ? t('Communications lost with this contact!') : '');
477
478                 if ($contact['network'] == NETWORK_FEED)
479                         $fetch_further_information = array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
480                                                                         array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords')));
481
482                 if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)))
483                         $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
484
485                 if ($contact['network'] == NETWORK_DFRN)
486                         $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
487
488                 $o .= replace_macros($tpl, array(
489                         '$header' => t('Contact Editor'),
490                         '$tab_str' => $tab_str,
491                         '$submit' => t('Submit'),
492                         '$lbl_vis1' => t('Profile Visibility'),
493                         '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
494                         '$lbl_info1' => t('Contact Information / Notes'),
495                         '$infedit' => t('Edit contact notes'),
496                         '$common_text' => $common_text,
497                         '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
498                         '$all_friends' => $all_friends,
499                         '$relation_text' => $relation_text,
500                         '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
501                         '$blockunblock' => t('Block/Unblock contact'),
502                         '$ignorecont' => t('Ignore contact'),
503                         '$lblcrepair' => t("Repair URL settings"),
504                         '$lblrecent' => t('View conversations'),
505                         '$lblsuggest' => $lblsuggest,
506                         '$delete' => t('Delete contact'),
507                         '$nettype' => $nettype,
508                         '$poll_interval' => $poll_interval,
509                         '$poll_enabled' => $poll_enabled,
510                         '$lastupdtext' => t('Last update:'),
511                         '$lost_contact' => $lost_contact,
512                         '$updpub' => t('Update public posts'),
513                         '$last_update' => $last_update,
514                         '$udnow' => t('Update now'),
515                         '$profile_select' => $profile_select,
516                         '$contact_id' => $contact['id'],
517                         '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
518                         '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
519                         '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
520                         '$info' => $contact['info'],
521                         '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
522                         '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
523                         '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
524                         '$hidden' => array('hidden', t('Hide this contact from others'), ($contact['hidden'] == 1), t('Replies/likes to your public posts <strong>may</strong> still be visible')),
525                         '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
526                         '$fetch_further_information' => $fetch_further_information,
527                         '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
528                         '$ffi_keyword_blacklist' => array('ffi_keyword_blacklist', t('Blacklisted keywords'), $contact['ffi_keyword_blacklist'], t('Comma separated list of keywords that should not be converted to hashtags, when "Fetch information and keywords" is selected')),
529                         '$photo' => $contact['photo'],
530                         '$name' => $contact['name'],
531                         '$dir_icon' => $dir_icon,
532                         '$alt_text' => $alt_text,
533                         '$sparkle' => $sparkle,
534                         '$url' => $url,
535
536                 ));
537
538                 $arr = array('contact' => $contact,'output' => $o);
539
540                 call_hooks('contact_edit', $arr);
541
542                 return $arr['output'];
543
544         }
545
546         $blocked = false;
547         $hidden = false;
548         $ignored = false;
549         $all = false;
550
551         if(($a->argc == 2) && ($a->argv[1] === 'all')) {
552                 $sql_extra = '';
553                 $all = true;
554         }
555         elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
556                 $sql_extra = " AND `blocked` = 1 ";
557                 $blocked = true;
558         }
559         elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
560                 $sql_extra = " AND `hidden` = 1 ";
561                 $hidden = true;
562         }
563         elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
564                 $sql_extra = " AND `readonly` = 1 ";
565                 $ignored = true;
566         }
567         elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
568                 $sql_extra = " AND `archive` = 1 ";
569                 $archived = true;
570         }
571         else
572                 $sql_extra = " AND `blocked` = 0 ";
573
574         $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
575         $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
576
577         $tabs = array(
578                 array(
579                         'label' => t('Suggestions'),
580                         'url'   => $a->get_baseurl(true) . '/suggest', 
581                         'sel'   => '',
582                         'title' => t('Suggest potential friends'),
583                 ),
584                 array(
585                         'label' => t('All Contacts'),
586                         'url'   => $a->get_baseurl(true) . '/contacts/all', 
587                         'sel'   => ($all) ? 'active' : '',
588                         'title' => t('Show all contacts'),
589                 ),
590                 array(
591                         'label' => t('Unblocked'),
592                         'url'   => $a->get_baseurl(true) . '/contacts',
593                         'sel'   => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
594                         'title' => t('Only show unblocked contacts'),
595                 ),
596
597                 array(
598                         'label' => t('Blocked'),
599                         'url'   => $a->get_baseurl(true) . '/contacts/blocked',
600                         'sel'   => ($blocked) ? 'active' : '',
601                         'title' => t('Only show blocked contacts'),
602                 ),
603
604                 array(
605                         'label' => t('Ignored'),
606                         'url'   => $a->get_baseurl(true) . '/contacts/ignored',
607                         'sel'   => ($ignored) ? 'active' : '',
608                         'title' => t('Only show ignored contacts'),
609                 ),
610
611                 array(
612                         'label' => t('Archived'),
613                         'url'   => $a->get_baseurl(true) . '/contacts/archived',
614                         'sel'   => ($archived) ? 'active' : '',
615                         'title' => t('Only show archived contacts'),
616                 ),
617
618                 array(
619                         'label' => t('Hidden'),
620                         'url'   => $a->get_baseurl(true) . '/contacts/hidden',
621                         'sel'   => ($hidden) ? 'active' : '',
622                         'title' => t('Only show hidden contacts'),
623                 ),
624
625         );
626
627         $tab_tpl = get_markup_template('common_tabs.tpl');
628         $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
629
630
631
632         $searching = false;
633         if($search) {
634                 $search_hdr = $search;
635                 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
636                 $searching = true;
637         }
638         $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt'  OR nick REGEXP '$search_txt') " : "");
639
640         if($nets)
641                 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
642
643         $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
644
645
646         $r = q("SELECT COUNT(*) AS `total` FROM `contact`
647                 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
648                 intval($_SESSION['uid']));
649         if(count($r)) {
650                 $a->set_pager_total($r[0]['total']);
651                 $total = $r[0]['total'];
652         }
653
654
655         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
656                 intval($_SESSION['uid']),
657                 intval($a->pager['start']),
658                 intval($a->pager['itemspage'])
659         );
660
661         $contacts = array();
662
663         if(count($r)) {
664
665                 foreach($r as $rr) {
666
667                         switch($rr['rel']) {
668                                 case CONTACT_IS_FRIEND:
669                                         $dir_icon = 'images/lrarrow.gif';
670                                         $alt_text = t('Mutual Friendship');
671                                         break;
672                                 case  CONTACT_IS_FOLLOWER;
673                                         $dir_icon = 'images/larrow.gif';
674                                         $alt_text = t('is a fan of yours');
675                                         break;
676                                 case CONTACT_IS_SHARING;
677                                         $dir_icon = 'images/rarrow.gif';
678                                         $alt_text = t('you are a fan of');
679                                         break;
680                                 default:
681                                         break;
682                         }
683                         if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
684                                 $url = "redir/{$rr['id']}";
685                                 $sparkle = ' class="sparkle" ';
686                         }
687                         else {
688                                 $url = $rr['url'];
689                                 $sparkle = '';
690                         }
691
692
693                         $contacts[] = array(
694                                 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
695                                 'edit_hover' => t('Edit contact'),
696                                 'photo_menu' => contact_photo_menu($rr),
697                                 'id' => $rr['id'],
698                                 'alt_text' => $alt_text,
699                                 'dir_icon' => $dir_icon,
700                                 'thumb' => proxy_url($rr['thumb']),
701                                 'name' => $rr['name'],
702                                 'username' => $rr['name'],
703                                 'sparkle' => $sparkle,
704                                 'itemurl' => $rr['url'],
705                                 'url' => $url,
706                                 'network' => network_to_name($rr['network']),
707                         );
708                 }
709
710
711
712         }
713
714         $tpl = get_markup_template("contacts-template.tpl");
715         $o .= replace_macros($tpl, array(
716                 '$baseurl' => $a->get_baseurl(),
717                 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
718                 '$tabs' => $t,
719                 '$total' => $total,
720                 '$search' => $search_hdr,
721                 '$desc' => t('Search your contacts'),
722                 '$finding' => (($searching) ? t('Finding: ') . "'" . $search . "'" : ""),
723                 '$submit' => t('Find'),
724                 '$cmd' => $a->cmd,
725                 '$contacts' => $contacts,
726                 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
727                 '$batch_actions' => array(
728                         'contacts_batch_update' => t('Update'),
729                         'contacts_batch_block' => t('Block')."/".t("Unblock"),
730                         "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
731                         "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
732                         "contacts_batch_drop" => t('Delete'),
733                 ),
734                 '$paginate' => paginate($a),
735
736         )); 
737         
738         return $o;
739 }