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