3 require_once('include/Contact.php');
4 require_once('include/socgraph.php');
5 require_once('include/contact_selectors.php');
6 require_once('include/Scrape.php');
7 require_once('mod/proxy.php');
8 require_once('include/Photo.php');
10 if(! function_exists('contacts_init')) {
11 function contacts_init(&$a) {
17 if((($a->argc == 2) && intval($a->argv[1])) OR (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
18 $contact_id = intval($a->argv[1]);
19 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
28 require_once('include/group.php');
29 require_once('include/contact_widgets.php');
31 if ($_GET['nets'] == "all")
34 if(! x($a->page,'aside'))
35 $a->page['aside'] = '';
38 $a->data['contact'] = $r[0];
40 if (($a->data['contact']['network'] != "") AND ($a->data['contact']['network'] != NETWORK_DFRN)) {
41 $networkname = format_network_name($a->data['contact']['network'],$a->data['contact']['url']);
45 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
46 '$name' => htmlentities($a->data['contact']['name']),
47 '$photo' => $a->data['contact']['photo'],
48 '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? z_root()."/redir/".$a->data['contact']['id'] : $a->data['contact']['url'],
49 '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""),
50 '$network_name' => $networkname,
51 '$network' => t('Network:'),
52 'account_type' => (($a->data['contact']['forum'] || $a->data['contact']['prv']) ? t('Forum') : '')
54 $finpeople_widget = '';
56 $networks_widget = '';
60 $networks_widget .= networks_widget('contacts',$_GET['nets']);
61 if (isset($_GET['add']))
62 $follow_widget = follow_widget($_GET['add']);
64 $follow_widget = follow_widget();
66 $findpeople_widget .= findpeople_widget();
69 $groups_widget .= group_side('contacts','group','full',0,$contact_id);
71 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
72 '$vcard_widget' => $vcard_widget,
73 '$findpeople_widget' => $findpeople_widget,
74 '$follow_widget' => $follow_widget,
75 '$groups_widget' => $groups_widget,
76 '$networks_widget' => $networks_widget
80 $tpl = get_markup_template("contacts-head.tpl");
81 $a->page['htmlhead'] .= replace_macros($tpl,array(
82 '$baseurl' => $a->get_baseurl(true),
86 $tpl = get_markup_template("contacts-end.tpl");
87 $a->page['end'] .= replace_macros($tpl,array(
88 '$baseurl' => $a->get_baseurl(true),
95 if(! function_exists('contacts_batch_actions')) {
96 function contacts_batch_actions(&$a){
97 $contacts_id = $_POST['contact_batch'];
98 if (!is_array($contacts_id)) return;
100 $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
101 implode(",", $contacts_id),
106 foreach($orig_records as $orig_record) {
107 $contact_id = $orig_record['id'];
108 if (x($_POST, 'contacts_batch_update')) {
109 _contact_update($contact_id);
112 if (x($_POST, 'contacts_batch_block')) {
113 $r = _contact_block($contact_id, $orig_record);
114 if ($r) $count_actions++;
116 if (x($_POST, 'contacts_batch_ignore')) {
117 $r = _contact_ignore($contact_id, $orig_record);
118 if ($r) $count_actions++;
120 if (x($_POST, 'contacts_batch_archive')) {
121 $r = _contact_archive($contact_id, $orig_record);
122 if ($r) $count_actions++;
124 if (x($_POST, 'contacts_batch_drop')) {
125 _contact_drop($contact_id, $orig_record);
129 if ($count_actions>0) {
130 info ( sprintf( tt("%d contact edited.", "%d contacts edited.", $count_actions), $count_actions) );
133 if(x($_SESSION,'return_url'))
134 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
136 goaway($a->get_baseurl(true) . '/contacts');
140 if(! function_exists('contacts_post')) {
141 function contacts_post(&$a) {
146 if ($a->argv[1]==="batch") {
147 contacts_batch_actions($a);
151 $contact_id = intval($a->argv[1]);
155 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
160 if(! count($orig_record)) {
161 notice( t('Could not access contact record.') . EOL);
162 goaway($a->get_baseurl(true) . '/contacts');
163 return; // NOTREACHED
166 call_hooks('contact_edit_post', $_POST);
168 $profile_id = intval($_POST['profile-assign']);
170 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
175 notice( t('Could not locate selected profile.') . EOL);
180 $hidden = intval($_POST['hidden']);
182 $notify = intval($_POST['notify']);
184 $fetch_further_information = intval($_POST['fetch_further_information']);
186 $ffi_keyword_blacklist = fix_mce_lf(escape_tags(trim($_POST['ffi_keyword_blacklist'])));
188 $priority = intval($_POST['poll']);
189 if($priority > 5 || $priority < 0)
192 $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
194 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
195 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
196 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
202 intval($fetch_further_information),
203 dbesc($ffi_keyword_blacklist),
208 info( t('Contact updated.') . EOL);
210 notice( t('Failed to update contact record.') . EOL);
212 $r = q("select * from contact where id = %d and uid = %d limit 1",
217 $a->data['contact'] = $r[0];
224 if(! function_exists('_contact_update')) {
225 function _contact_update($contact_id) {
226 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
232 if ($uid != local_user())
235 if ($r[0]["network"] == NETWORK_OSTATUS) {
236 $result = new_contact($uid, $r[0]["url"], false);
238 if ($result['success'])
239 $r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
240 intval($contact_id));
242 // pull feed and consume it, which should subscribe to the hub.
243 proc_run('php',"include/onepoll.php","$contact_id", "force");
247 if(! function_exists('_contact_update_profile')) {
248 function _contact_update_profile($contact_id) {
249 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
255 if ($uid != local_user())
258 $data = probe_url($r[0]["url"]);
260 // "Feed" or "Unknown" is mostly a sign of communication problems
261 if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) AND ($data["network"] != $r[0]["network"]))
264 $updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
265 "poco", "network", "alias");
268 if ($data["network"] == NETWORK_OSTATUS) {
269 $result = new_contact($uid, $data["url"], false);
271 if ($result['success'])
272 $update["subhub"] = true;
275 foreach($updatefields AS $field)
276 if (isset($data[$field]) AND ($data[$field] != ""))
277 $update[$field] = $data[$field];
279 $update["nurl"] = normalise_link($data["url"]);
283 if (isset($data["priority"]) AND ($data["priority"] != 0))
284 $query = "`priority` = ".intval($data["priority"]);
286 foreach($update AS $key => $value) {
290 $query .= "`".$key."` = '".dbesc($value)."'";
296 $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
301 // Update the entry in the contact table
302 update_contact_avatar($data['photo'], local_user(), $contact_id);
304 // Update the entry in the gcontact table
305 update_gcontact_from_probe($data["url"]);
309 if(! function_exists('_contact_block')) {
310 function _contact_block($contact_id, $orig_record) {
311 $blocked = (($orig_record['blocked']) ? 0 : 1);
312 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
321 if(! function_exists('_contact_ignore')) {
322 function _contact_ignore($contact_id, $orig_record) {
323 $readonly = (($orig_record['readonly']) ? 0 : 1);
324 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
333 if(! function_exists('_contact_archive')) {
334 function _contact_archive($contact_id, $orig_record) {
335 $archived = (($orig_record['archive']) ? 0 : 1);
336 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
342 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
348 if(! function_exists('_contact_drop')) {
349 function _contact_drop($contact_id, $orig_record) {
352 terminate_friendship($a->user,$a->contact,$orig_record);
353 contact_remove($orig_record['id']);
357 if(! function_exists('contacts_content')) {
358 function contacts_content(&$a) {
362 nav_set_selected('contacts');
366 notice( t('Permission denied.') . EOL);
372 $contact_id = intval($a->argv[1]);
378 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
383 if(! count($orig_record)) {
384 notice( t('Could not access contact record.') . EOL);
385 goaway($a->get_baseurl(true) . '/contacts');
386 return; // NOTREACHED
389 if($cmd === 'update') {
390 _contact_update($contact_id);
391 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
395 if($cmd === 'updateprofile') {
396 _contact_update_profile($contact_id);
397 goaway($a->get_baseurl(true) . '/crepair/' . $contact_id);
401 if($cmd === 'block') {
402 $r = _contact_block($contact_id, $orig_record[0]);
404 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
405 info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL);
408 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
409 return; // NOTREACHED
412 if($cmd === 'ignore') {
413 $r = _contact_ignore($contact_id, $orig_record[0]);
415 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
416 info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL);
419 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
420 return; // NOTREACHED
424 if($cmd === 'archive') {
425 $r = _contact_archive($contact_id, $orig_record[0]);
427 $archived = (($orig_record[0]['archive']) ? 0 : 1);
428 info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL);
431 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
432 return; // NOTREACHED
435 if($cmd === 'drop') {
437 // Check if we should do HTML-based delete confirmation
438 if($_REQUEST['confirm']) {
439 // <form> can't take arguments in its "action" parameter
440 // so add any arguments as hidden inputs
441 $query = explode_querystring($a->query_string);
443 foreach($query['args'] as $arg) {
444 if(strpos($arg, 'confirm=') === false) {
445 $arg_parts = explode('=', $arg);
446 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
450 $a->page['aside'] = '';
452 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), array(
453 '$contact' => _contact_detail_for_template($orig_record[0]),
455 '$message' => t('Do you really want to delete this contact?'),
456 '$extra_inputs' => $inputs,
457 '$confirm' => t('Yes'),
458 '$confirm_url' => $query['base'],
459 '$confirm_name' => 'confirmed',
460 '$cancel' => t('Cancel'),
463 // Now check how the user responded to the confirmation query
464 if($_REQUEST['canceled']) {
465 if(x($_SESSION,'return_url'))
466 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
468 goaway($a->get_baseurl(true) . '/contacts');
471 _contact_drop($contact_id, $orig_record[0]);
472 info( t('Contact has been removed.') . EOL );
473 if(x($_SESSION,'return_url'))
474 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
476 goaway($a->get_baseurl(true) . '/contacts');
477 return; // NOTREACHED
479 if($cmd === 'posts') {
480 return contact_posts($a, $contact_id);
486 $_SESSION['return_url'] = $a->query_string;
488 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
490 $contact_id = $a->data['contact']['id'];
491 $contact = $a->data['contact'];
493 $editselect = 'none';
494 if( feature_enabled(local_user(),'richtext') )
495 $editselect = 'exact';
497 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
498 '$baseurl' => $a->get_baseurl(true),
499 '$editselect' => $editselect,
501 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
502 '$baseurl' => $a->get_baseurl(true),
503 '$editselect' => $editselect,
506 require_once('include/contact_selectors.php');
508 $tpl = get_markup_template("contact_edit.tpl");
510 switch($contact['rel']) {
511 case CONTACT_IS_FRIEND:
512 $dir_icon = 'images/lrarrow.gif';
513 $relation_text = t('You are mutual friends with %s');
515 case CONTACT_IS_FOLLOWER;
516 $dir_icon = 'images/larrow.gif';
517 $relation_text = t('You are sharing with %s');
520 case CONTACT_IS_SHARING;
521 $dir_icon = 'images/rarrow.gif';
522 $relation_text = t('%s is sharing with you');
528 if(!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
531 $relation_text = sprintf($relation_text,htmlentities($contact['name']));
533 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
534 $url = "redir/{$contact['id']}";
535 $sparkle = ' class="sparkle" ';
538 $url = $contact['url'];
542 $insecure = t('Private communications are not available for this contact.');
544 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
546 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
548 if($contact['last-update'] !== '0000-00-00 00:00:00')
549 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
551 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
553 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
555 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"]));
557 //$common = count_common_friends(local_user(),$contact['id']);
558 //$common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
560 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
562 //$x = count_all_friends(local_user(), $contact['id']);
563 //$all_friends = (($x) ? t('View all contacts') : '');
566 $tab_str = contacts_tab($a, $contact_id, 2);
568 $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!') : '');
570 if ($contact['network'] == NETWORK_FEED)
571 $fetch_further_information = array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
572 array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords')));
574 if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)))
575 $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
577 if ($contact['network'] == NETWORK_DFRN)
578 $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
580 if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS)) AND
581 ($contact['rel'] == CONTACT_IS_FOLLOWER))
582 $follow = $a->get_baseurl(true)."/follow?url=".urlencode($contact["url"]);
585 $o .= replace_macros($tpl, array(
586 //'$header' => t('Contact Editor'),
587 '$tab_str' => $tab_str,
588 '$submit' => t('Submit'),
589 '$lbl_vis1' => t('Profile Visibility'),
590 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
591 '$lbl_info1' => t('Contact Information / Notes'),
592 '$infedit' => t('Edit contact notes'),
593 '$common_text' => $common_text,
594 '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
595 '$all_friends' => $all_friends,
596 '$relation_text' => $relation_text,
597 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
598 '$blockunblock' => t('Block/Unblock contact'),
599 '$ignorecont' => t('Ignore contact'),
600 '$lblcrepair' => t("Repair URL settings"),
601 '$lblrecent' => t('View conversations'),
602 '$lblsuggest' => $lblsuggest,
603 '$delete' => t('Delete contact'),
604 '$nettype' => $nettype,
605 '$poll_interval' => $poll_interval,
606 '$poll_enabled' => $poll_enabled,
607 '$lastupdtext' => t('Last update:'),
608 '$lost_contact' => $lost_contact,
609 '$updpub' => t('Update public posts'),
610 '$last_update' => $last_update,
611 '$udnow' => t('Update now'),
612 '$follow' => $follow,
613 '$follow_text' => t("Connect/Follow"),
614 '$profile_select' => $profile_select,
615 '$contact_id' => $contact['id'],
616 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
617 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
618 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
619 '$info' => $contact['info'],
620 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
621 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
622 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
623 '$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')),
624 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
625 '$fetch_further_information' => $fetch_further_information,
626 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
627 '$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')),
628 '$photo' => $contact['photo'],
629 '$name' => htmlentities($contact['name']),
630 '$dir_icon' => $dir_icon,
631 '$alt_text' => $alt_text,
632 '$sparkle' => $sparkle,
634 '$profileurllabel' => t('Profile URL'),
635 '$profileurl' => $contact['url'],
636 '$location' => bbcode($contact["location"]),
637 '$location_label' => t("Location:"),
638 '$about' => bbcode($contact["about"], false, false),
639 '$about_label' => t("About:"),
640 '$keywords' => $contact["keywords"],
641 '$keywords_label' => t("Tags:")
645 $arr = array('contact' => $contact,'output' => $o);
647 call_hooks('contact_edit', $arr);
649 return $arr['output'];
658 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
662 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
663 $sql_extra = " AND `blocked` = 1 ";
666 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
667 $sql_extra = " AND `hidden` = 1 ";
670 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
671 $sql_extra = " AND `readonly` = 1 ";
674 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
675 $sql_extra = " AND `archive` = 1 ";
679 $sql_extra = " AND `blocked` = 0 ";
681 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
682 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
686 'label' => t('Suggestions'),
687 'url' => $a->get_baseurl(true) . '/suggest',
689 'title' => t('Suggest potential friends'),
690 'id' => 'suggestions-tab',
694 'label' => t('All Contacts'),
695 'url' => $a->get_baseurl(true) . '/contacts/all',
696 'sel' => ($all) ? 'active' : '',
697 'title' => t('Show all contacts'),
698 'id' => 'showall-tab',
702 'label' => t('Unblocked'),
703 'url' => $a->get_baseurl(true) . '/contacts',
704 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
705 'title' => t('Only show unblocked contacts'),
706 'id' => 'showunblocked-tab',
711 'label' => t('Blocked'),
712 'url' => $a->get_baseurl(true) . '/contacts/blocked',
713 'sel' => ($blocked) ? 'active' : '',
714 'title' => t('Only show blocked contacts'),
715 'id' => 'showblocked-tab',
720 'label' => t('Ignored'),
721 'url' => $a->get_baseurl(true) . '/contacts/ignored',
722 'sel' => ($ignored) ? 'active' : '',
723 'title' => t('Only show ignored contacts'),
724 'id' => 'showignored-tab',
729 'label' => t('Archived'),
730 'url' => $a->get_baseurl(true) . '/contacts/archived',
731 'sel' => ($archived) ? 'active' : '',
732 'title' => t('Only show archived contacts'),
733 'id' => 'showarchived-tab',
738 'label' => t('Hidden'),
739 'url' => $a->get_baseurl(true) . '/contacts/hidden',
740 'sel' => ($hidden) ? 'active' : '',
741 'title' => t('Only show hidden contacts'),
742 'id' => 'showhidden-tab',
748 $tab_tpl = get_markup_template('common_tabs.tpl');
749 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
755 $search_hdr = $search;
756 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
759 $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
762 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
764 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
767 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
768 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
769 intval($_SESSION['uid']));
771 $a->set_pager_total($r[0]['total']);
772 $total = $r[0]['total'];
775 $sql_extra3 = unavailable_networks();
777 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 $sql_extra3 ORDER BY `name` ASC LIMIT %d , %d ",
778 intval($_SESSION['uid']),
779 intval($a->pager['start']),
780 intval($a->pager['itemspage'])
787 $contacts[] = _contact_detail_for_template($rr);
791 $tpl = get_markup_template("contacts-template.tpl");
792 $o .= replace_macros($tpl, array(
793 '$baseurl' => z_root(),
794 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
797 '$search' => $search_hdr,
798 '$desc' => t('Search your contacts'),
799 '$finding' => (($searching) ? t('Finding: ') . "'" . $search . "'" : ""),
800 '$submit' => t('Find'),
802 '$contacts' => $contacts,
803 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
805 '$batch_actions' => array(
806 'contacts_batch_update' => t('Update'),
807 'contacts_batch_block' => t('Block')."/".t("Unblock"),
808 "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
809 "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
810 "contacts_batch_drop" => t('Delete'),
812 '$paginate' => paginate($a),
820 if(! function_exists('contacts_tab')) {
821 function contacts_tab($a, $contact_id, $active_tab) {
825 'label'=>t('Status'),
826 'url' => "contacts/".$contact_id."/posts",
827 'sel' => (($active_tab == 1)?'active':''),
828 'title' => t('Status Messages and Posts'),
829 'id' => 'status-tab',
833 'label'=>t('Profile'),
834 'url' => "contacts/".$contact_id,
835 'sel' => (($active_tab == 2)?'active':''),
836 'title' => t('Profile Details'),
837 'id' => 'status-tab',
842 $x = count_all_friends(local_user(), $contact_id);
844 $tabs[] = array('label'=>t('Contacts'),
845 'url' => "allfriends/".$contact_id,
846 'sel' => (($active_tab == 3)?'active':''),
847 'title' => t('View all contacts'),
848 'id' => 'allfriends-tab',
851 $common = count_common_friends(local_user(),$contact_id);
853 $tabs[] = array('label'=>t('Common Friends'),
854 'url' => "common/loc/".local_user()."/".$contact_id,
855 'sel' => (($active_tab == 4)?'active':''),
856 'title' => t('View all common friends'),
857 'id' => 'common-loc-tab',
860 $tabs[] = array('label' => t('Repair'),
861 'url' => $a->get_baseurl(true) . '/crepair/' . $contact_id,
862 'sel' => (($active_tab == 5)?'active':''),
863 'title' => t('Advanced Contact Settings'),
864 'id' => 'repair-tab',
868 $tabs[] = array('label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
869 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
871 'title' => t('Toggle Blocked status'),
872 'id' => 'toggle-block-tab',
875 $tabs[] = array('label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
876 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
878 'title' => t('Toggle Ignored status'),
879 'id' => 'toggle-ignore-tab',
882 $tabs[] = array('label' => (($contact['archive']) ? t('Unarchive') : t('Archive') ),
883 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive',
885 'title' => t('Toggle Archive status'),
886 'id' => 'toggle-archive-tab',
889 $tab_tpl = get_markup_template('common_tabs.tpl');
890 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
896 if(! function_exists('contact_posts')) {
897 function contact_posts($a, $contact_id) {
899 $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
902 $a->page['aside'] = "";
903 profile_load($a, "", 0, get_contact_details_by_url($contact["url"]));
907 $tab_str = contacts_tab($a, $contact_id, 1);
911 $r = q("SELECT `id` FROM `item` WHERE `contact-id` = %d LIMIT 1", intval($contact_id));
913 $o .= posts_from_contact($a, $contact_id);
914 elseif ($contact["url"]) {
915 $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
916 dbesc(normalise_link($contact["url"])));
918 if ($r[0]["id"] <> 0)
919 $o .= posts_from_gcontact($a, $r[0]["id"]);
926 if(! function_exists('_contact_detail_for_template')) {
927 function _contact_detail_for_template($rr){
932 case CONTACT_IS_FRIEND:
933 $dir_icon = 'images/lrarrow.gif';
934 $alt_text = t('Mutual Friendship');
936 case CONTACT_IS_FOLLOWER;
937 $dir_icon = 'images/larrow.gif';
938 $alt_text = t('is a fan of yours');
940 case CONTACT_IS_SHARING;
941 $dir_icon = 'images/rarrow.gif';
942 $alt_text = t('you are a fan of');
947 if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
948 $url = "redir/{$rr['id']}";
949 $sparkle = ' class="sparkle" ';
956 //test if contact is a forum page
957 if (isset($rr['forum']) OR isset($rr['prv']))
958 $community = ($rr['forum'] OR $rr['prv']);
962 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
963 'edit_hover' => t('Edit contact'),
964 'photo_menu' => contact_photo_menu($rr),
966 'alt_text' => $alt_text,
967 'dir_icon' => $dir_icon,
968 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
969 'name' => htmlentities($rr['name']),
970 'username' => htmlentities($rr['name']),
971 'account_type' => ($community ? t('Forum') : ''),
972 'sparkle' => $sparkle,
973 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
975 'network' => network_to_name($rr['network'], $rr['url']),