]> git.mxchange.org Git - friendica.git/blob - mod/contacts.php
515d9d5dcb49e1f85dbec38e3e3d75cd2fe34209
[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                 $relation_text = sprintf($relation_text,$contact['name']);
409
410                 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
411                         $url = "redir/{$contact['id']}";
412                         $sparkle = ' class="sparkle" ';
413                 }
414                 else {
415                         $url = $contact['url'];
416                         $sparkle = '';
417                 }
418
419                 $insecure = t('Private communications are not available for this contact.');
420
421                 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
422                                 ? t('Never')
423                                 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
424
425                 if($contact['last-update'] !== '0000-00-00 00:00:00')
426                         $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
427
428                 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
429
430                 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
431
432                 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
433
434                 $common = count_common_friends(local_user(),$contact['id']);
435                 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
436
437                 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
438
439                 $x = count_all_friends(local_user(), $contact['id']);
440                 $all_friends = (($x) ? t('View all contacts') : '');
441
442                 // tabs
443                 $tabs = array(
444                         array(
445                                 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
446                                 'url'   => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
447                                 'sel'   => '',
448                                 'title' => t('Toggle Blocked status'),
449                         ),
450                         array(
451                                 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
452                                 'url'   => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
453                                 'sel'   => '',
454                                 'title' => t('Toggle Ignored status'),
455                         ),
456
457                         array(
458                                 'label' => (($contact['archive']) ? t('Unarchive') : t('Archive') ),
459                                 'url'   => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive',
460                                 'sel'   => '',
461                                 'title' => t('Toggle Archive status'),
462                         ),
463                         array(
464                                 'label' => t('Repair'),
465                                 'url'   => $a->get_baseurl(true) . '/crepair/' . $contact_id,
466                                 'sel'   => '',
467                                 'title' => t('Advanced Contact Settings'),
468                         )
469                 );
470                 $tab_tpl = get_markup_template('common_tabs.tpl');
471                 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
472
473                 $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!') : '');
474
475                 if ($contact['network'] == NETWORK_FEED)
476                         $fetch_further_information = array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
477                                                                         array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords')));
478
479                 if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)))
480                         $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
481
482                 $o .= replace_macros($tpl, array(
483                         '$header' => t('Contact Editor'),
484                         '$tab_str' => $tab_str,
485                         '$submit' => t('Submit'),
486                         '$lbl_vis1' => t('Profile Visibility'),
487                         '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
488                         '$lbl_info1' => t('Contact Information / Notes'),
489                         '$infedit' => t('Edit contact notes'),
490                         '$common_text' => $common_text,
491                         '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
492                         '$all_friends' => $all_friends,
493                         '$relation_text' => $relation_text,
494                         '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
495                         '$blockunblock' => t('Block/Unblock contact'),
496                         '$ignorecont' => t('Ignore contact'),
497                         '$lblcrepair' => t("Repair URL settings"),
498                         '$lblrecent' => t('View conversations'),
499                         '$lblsuggest' => $lblsuggest,
500                         '$delete' => t('Delete contact'),
501                         '$nettype' => $nettype,
502                         '$poll_interval' => $poll_interval,
503                         '$poll_enabled' => $poll_enabled,
504                         '$lastupdtext' => t('Last update:'),
505                         '$lost_contact' => $lost_contact,
506                         '$updpub' => t('Update public posts'),
507                         '$last_update' => $last_update,
508                         '$udnow' => t('Update now'),
509                         '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
510                         '$contact_id' => $contact['id'],
511                         '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
512                         '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
513                         '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
514                         '$info' => $contact['info'],
515                         '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
516                         '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
517                         '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
518                         '$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')),
519                         '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
520                         '$fetch_further_information' => $fetch_further_information,
521                         '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
522                         '$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')),
523                         '$photo' => $contact['photo'],
524                         '$name' => $contact['name'],
525                         '$dir_icon' => $dir_icon,
526                         '$alt_text' => $alt_text,
527                         '$sparkle' => $sparkle,
528                         '$url' => $url,
529
530                 ));
531
532                 $arr = array('contact' => $contact,'output' => $o);
533
534                 call_hooks('contact_edit', $arr);
535
536                 return $arr['output'];
537
538         }
539
540         $blocked = false;
541         $hidden = false;
542         $ignored = false;
543         $all = false;
544
545         if(($a->argc == 2) && ($a->argv[1] === 'all')) {
546                 $sql_extra = '';
547                 $all = true;
548         }
549         elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
550                 $sql_extra = " AND `blocked` = 1 ";
551                 $blocked = true;
552         }
553         elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
554                 $sql_extra = " AND `hidden` = 1 ";
555                 $hidden = true;
556         }
557         elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
558                 $sql_extra = " AND `readonly` = 1 ";
559                 $ignored = true;
560         }
561         elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
562                 $sql_extra = " AND `archive` = 1 ";
563                 $archived = true;
564         }
565         else
566                 $sql_extra = " AND `blocked` = 0 ";
567
568         $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
569         $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
570
571         $tabs = array(
572                 array(
573                         'label' => t('Suggestions'),
574                         'url'   => $a->get_baseurl(true) . '/suggest', 
575                         'sel'   => '',
576                         'title' => t('Suggest potential friends'),
577                 ),
578                 array(
579                         'label' => t('All Contacts'),
580                         'url'   => $a->get_baseurl(true) . '/contacts/all', 
581                         'sel'   => ($all) ? 'active' : '',
582                         'title' => t('Show all contacts'),
583                 ),
584                 array(
585                         'label' => t('Unblocked'),
586                         'url'   => $a->get_baseurl(true) . '/contacts',
587                         'sel'   => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
588                         'title' => t('Only show unblocked contacts'),
589                 ),
590
591                 array(
592                         'label' => t('Blocked'),
593                         'url'   => $a->get_baseurl(true) . '/contacts/blocked',
594                         'sel'   => ($blocked) ? 'active' : '',
595                         'title' => t('Only show blocked contacts'),
596                 ),
597
598                 array(
599                         'label' => t('Ignored'),
600                         'url'   => $a->get_baseurl(true) . '/contacts/ignored',
601                         'sel'   => ($ignored) ? 'active' : '',
602                         'title' => t('Only show ignored contacts'),
603                 ),
604
605                 array(
606                         'label' => t('Archived'),
607                         'url'   => $a->get_baseurl(true) . '/contacts/archived',
608                         'sel'   => ($archived) ? 'active' : '',
609                         'title' => t('Only show archived contacts'),
610                 ),
611
612                 array(
613                         'label' => t('Hidden'),
614                         'url'   => $a->get_baseurl(true) . '/contacts/hidden',
615                         'sel'   => ($hidden) ? 'active' : '',
616                         'title' => t('Only show hidden contacts'),
617                 ),
618
619         );
620
621         $tab_tpl = get_markup_template('common_tabs.tpl');
622         $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
623
624
625
626         $searching = false;
627         if($search) {
628                 $search_hdr = $search;
629                 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
630                 $searching = true;
631         }
632         $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt'  OR nick REGEXP '$search_txt') " : "");
633
634         if($nets)
635                 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
636
637         $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
638
639
640         $r = q("SELECT COUNT(*) AS `total` FROM `contact`
641                 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
642                 intval($_SESSION['uid']));
643         if(count($r)) {
644                 $a->set_pager_total($r[0]['total']);
645                 $total = $r[0]['total'];
646         }
647
648
649         $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 ",
650                 intval($_SESSION['uid']),
651                 intval($a->pager['start']),
652                 intval($a->pager['itemspage'])
653         );
654
655         $contacts = array();
656
657         if(count($r)) {
658
659                 foreach($r as $rr) {
660
661                         switch($rr['rel']) {
662                                 case CONTACT_IS_FRIEND:
663                                         $dir_icon = 'images/lrarrow.gif';
664                                         $alt_text = t('Mutual Friendship');
665                                         break;
666                                 case  CONTACT_IS_FOLLOWER;
667                                         $dir_icon = 'images/larrow.gif';
668                                         $alt_text = t('is a fan of yours');
669                                         break;
670                                 case CONTACT_IS_SHARING;
671                                         $dir_icon = 'images/rarrow.gif';
672                                         $alt_text = t('you are a fan of');
673                                         break;
674                                 default:
675                                         break;
676                         }
677                         if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
678                                 $url = "redir/{$rr['id']}";
679                                 $sparkle = ' class="sparkle" ';
680                         }
681                         else {
682                                 $url = $rr['url'];
683                                 $sparkle = '';
684                         }
685
686
687                         $contacts[] = array(
688                                 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
689                                 'edit_hover' => t('Edit contact'),
690                                 'photo_menu' => contact_photo_menu($rr),
691                                 'id' => $rr['id'],
692                                 'alt_text' => $alt_text,
693                                 'dir_icon' => $dir_icon,
694                                 'thumb' => proxy_url($rr['thumb']),
695                                 'name' => $rr['name'],
696                                 'username' => $rr['name'],
697                                 'sparkle' => $sparkle,
698                                 'itemurl' => $rr['url'],
699                                 'url' => $url,
700                                 'network' => network_to_name($rr['network']),
701                         );
702                 }
703
704
705
706         }
707
708         $tpl = get_markup_template("contacts-template.tpl");
709         $o .= replace_macros($tpl, array(
710                 '$baseurl' => $a->get_baseurl(),
711                 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
712                 '$tabs' => $t,
713                 '$total' => $total,
714                 '$search' => $search_hdr,
715                 '$desc' => t('Search your contacts'),
716                 '$finding' => (($searching) ? t('Finding: ') . "'" . $search . "'" : ""),
717                 '$submit' => t('Find'),
718                 '$cmd' => $a->cmd,
719                 '$contacts' => $contacts,
720                 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
721                 '$batch_actions' => array(
722                         'contacts_batch_update' => t('Update'),
723                         'contacts_batch_block' => t('Block')."/".t("Unblock"),
724                         "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
725                         "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
726                         "contacts_batch_drop" => t('Delete'),
727                 ),
728                 '$paginate' => paginate($a),
729
730         )); 
731         
732         return $o;
733 }