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