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"]);
584 // Load contactact related actions like hide, suggest, delete and others
585 $contact_actions = contact_actions($contact);
588 $o .= replace_macros($tpl, array(
589 //'$header' => t('Contact Editor'),
590 '$tab_str' => $tab_str,
591 '$submit' => t('Submit'),
592 '$lbl_vis1' => t('Profile Visibility'),
593 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
594 '$lbl_info1' => t('Contact Information / Notes'),
595 '$infedit' => t('Edit contact notes'),
596 //'$common_text' => $common_text,
597 '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
598 '$all_friends' => $all_friends,
599 '$relation_text' => $relation_text,
600 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
601 '$blockunblock' => t('Block/Unblock contact'),
602 '$ignorecont' => t('Ignore contact'),
603 '$lblcrepair' => t("Repair URL settings"),
604 '$lblrecent' => t('View conversations'),
605 '$lblsuggest' => $lblsuggest,
606 //'$delete' => t('Delete contact'),
607 '$nettype' => $nettype,
608 '$poll_interval' => $poll_interval,
609 '$poll_enabled' => $poll_enabled,
610 '$lastupdtext' => t('Last update:'),
611 '$lost_contact' => $lost_contact,
612 '$updpub' => t('Update public posts'),
613 '$last_update' => $last_update,
614 '$udnow' => t('Update now'),
615 '$follow' => $follow,
616 '$follow_text' => t("Connect/Follow"),
617 '$profile_select' => $profile_select,
618 '$contact_id' => $contact['id'],
619 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
620 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
621 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
622 '$info' => $contact['info'],
623 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
624 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
625 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
626 '$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')),
627 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
628 '$fetch_further_information' => $fetch_further_information,
629 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
630 '$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')),
631 '$photo' => $contact['photo'],
632 '$name' => htmlentities($contact['name']),
633 '$dir_icon' => $dir_icon,
634 '$alt_text' => $alt_text,
635 '$sparkle' => $sparkle,
637 '$profileurllabel' => t('Profile URL'),
638 '$profileurl' => $contact['url'],
639 '$location' => bbcode($contact["location"]),
640 '$location_label' => t("Location:"),
641 '$about' => bbcode($contact["about"], false, false),
642 '$about_label' => t("About:"),
643 '$keywords' => $contact["keywords"],
644 '$keywords_label' => t("Tags:"),
645 '$contact_action_button' => t("Actions"),
646 '$contact_actions' => $contact_actions,
647 '$contact_status' => t("Status"),
648 '$contact_settings_label' => t('Contact Settings'),
652 $arr = array('contact' => $contact,'output' => $o);
654 call_hooks('contact_edit', $arr);
656 return $arr['output'];
665 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
669 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
670 $sql_extra = " AND `blocked` = 1 ";
673 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
674 $sql_extra = " AND `hidden` = 1 ";
677 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
678 $sql_extra = " AND `readonly` = 1 ";
681 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
682 $sql_extra = " AND `archive` = 1 ";
686 $sql_extra = " AND `blocked` = 0 ";
688 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
689 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
693 'label' => t('Suggestions'),
694 'url' => $a->get_baseurl(true) . '/suggest',
696 'title' => t('Suggest potential friends'),
697 'id' => 'suggestions-tab',
701 'label' => t('All Contacts'),
702 'url' => $a->get_baseurl(true) . '/contacts/all',
703 'sel' => ($all) ? 'active' : '',
704 'title' => t('Show all contacts'),
705 'id' => 'showall-tab',
709 'label' => t('Unblocked'),
710 'url' => $a->get_baseurl(true) . '/contacts',
711 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
712 'title' => t('Only show unblocked contacts'),
713 'id' => 'showunblocked-tab',
718 'label' => t('Blocked'),
719 'url' => $a->get_baseurl(true) . '/contacts/blocked',
720 'sel' => ($blocked) ? 'active' : '',
721 'title' => t('Only show blocked contacts'),
722 'id' => 'showblocked-tab',
727 'label' => t('Ignored'),
728 'url' => $a->get_baseurl(true) . '/contacts/ignored',
729 'sel' => ($ignored) ? 'active' : '',
730 'title' => t('Only show ignored contacts'),
731 'id' => 'showignored-tab',
736 'label' => t('Archived'),
737 'url' => $a->get_baseurl(true) . '/contacts/archived',
738 'sel' => ($archived) ? 'active' : '',
739 'title' => t('Only show archived contacts'),
740 'id' => 'showarchived-tab',
745 'label' => t('Hidden'),
746 'url' => $a->get_baseurl(true) . '/contacts/hidden',
747 'sel' => ($hidden) ? 'active' : '',
748 'title' => t('Only show hidden contacts'),
749 'id' => 'showhidden-tab',
755 $tab_tpl = get_markup_template('common_tabs.tpl');
756 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
762 $search_hdr = $search;
763 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
766 $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
769 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
771 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
774 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
775 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
776 intval($_SESSION['uid']));
778 $a->set_pager_total($r[0]['total']);
779 $total = $r[0]['total'];
782 $sql_extra3 = unavailable_networks();
784 $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 ",
785 intval($_SESSION['uid']),
786 intval($a->pager['start']),
787 intval($a->pager['itemspage'])
794 $contacts[] = _contact_detail_for_template($rr);
798 $tpl = get_markup_template("contacts-template.tpl");
799 $o .= replace_macros($tpl, array(
800 '$baseurl' => z_root(),
801 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
804 '$search' => $search_hdr,
805 '$desc' => t('Search your contacts'),
806 '$finding' => (($searching) ? t('Finding: ') . "'" . $search . "'" : ""),
807 '$submit' => t('Find'),
809 '$contacts' => $contacts,
810 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
812 '$batch_actions' => array(
813 'contacts_batch_update' => t('Update'),
814 'contacts_batch_block' => t('Block')."/".t("Unblock"),
815 "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
816 "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
817 "contacts_batch_drop" => t('Delete'),
819 '$paginate' => paginate($a),
828 * @brief List of pages for the Contact TabBar
830 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
833 * @param int $contact_id The ID of the contact
834 * @param int $active_tab 1 if tab should be marked as active
836 * @return array with with contact TabBar data
838 function contacts_tab($a, $contact_id, $active_tab) {
842 'label'=>t('Status'),
843 'url' => "contacts/".$contact_id."/posts",
844 'sel' => (($active_tab == 1)?'active':''),
845 'title' => t('Status Messages and Posts'),
846 'id' => 'status-tab',
850 'label'=>t('Profile'),
851 'url' => "contacts/".$contact_id,
852 'sel' => (($active_tab == 2)?'active':''),
853 'title' => t('Profile Details'),
854 'id' => 'status-tab',
859 // Show this tab only if there is visible friend list
860 $x = count_all_friends(local_user(), $contact_id);
862 $tabs[] = array('label'=>t('Contacts'),
863 'url' => "allfriends/".$contact_id,
864 'sel' => (($active_tab == 3)?'active':''),
865 'title' => t('View all contacts'),
866 'id' => 'allfriends-tab',
869 // Show this tab only if there is visible common friend list
870 $common = count_common_friends(local_user(),$contact_id);
872 $tabs[] = array('label'=>t('Common Friends'),
873 'url' => "common/loc/".local_user()."/".$contact_id,
874 'sel' => (($active_tab == 4)?'active':''),
875 'title' => t('View all common friends'),
876 'id' => 'common-loc-tab',
879 $tab_tpl = get_markup_template('common_tabs.tpl');
880 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
885 if(! function_exists('contact_posts')) {
886 function contact_posts($a, $contact_id) {
888 $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
891 $a->page['aside'] = "";
892 profile_load($a, "", 0, get_contact_details_by_url($contact["url"]));
896 $tab_str = contacts_tab($a, $contact_id, 1);
900 $r = q("SELECT `id` FROM `item` WHERE `contact-id` = %d LIMIT 1", intval($contact_id));
902 $o .= posts_from_contact($a, $contact_id);
903 elseif ($contact["url"]) {
904 $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
905 dbesc(normalise_link($contact["url"])));
907 if ($r[0]["id"] <> 0)
908 $o .= posts_from_gcontact($a, $r[0]["id"]);
915 if(! function_exists('_contact_detail_for_template')) {
916 function _contact_detail_for_template($rr){
921 case CONTACT_IS_FRIEND:
922 $dir_icon = 'images/lrarrow.gif';
923 $alt_text = t('Mutual Friendship');
925 case CONTACT_IS_FOLLOWER;
926 $dir_icon = 'images/larrow.gif';
927 $alt_text = t('is a fan of yours');
929 case CONTACT_IS_SHARING;
930 $dir_icon = 'images/rarrow.gif';
931 $alt_text = t('you are a fan of');
936 if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
937 $url = "redir/{$rr['id']}";
938 $sparkle = ' class="sparkle" ';
945 //test if contact is a forum page
946 if (isset($rr['forum']) OR isset($rr['prv']))
947 $community = ($rr['forum'] OR $rr['prv']);
951 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
952 'edit_hover' => t('Edit contact'),
953 'photo_menu' => contact_photo_menu($rr),
955 'alt_text' => $alt_text,
956 'dir_icon' => $dir_icon,
957 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
958 'name' => htmlentities($rr['name']),
959 'username' => htmlentities($rr['name']),
960 'account_type' => ($community ? t('Forum') : ''),
961 'sparkle' => $sparkle,
962 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
964 'network' => network_to_name($rr['network'], $rr['url']),
970 * @brief Gives a array with actions which can performed to a given contact
972 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
974 * @param array $contact Data about the Contact
975 * @return array with contact related actions
977 function contact_actions($contact) {
979 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
980 $contact_action = array();
982 // Provide friend suggestion only for Friendica contacts
983 if($contact['network'] === NETWORK_DFRN) {
984 $contact_actions['suggest'] = array(
985 'label' => t('Suggest friends'),
986 'url' => app::get_baseurl(true) . '/fsuggest/' . $contact['id'],
994 $contact_actions['update'] = array(
995 'label' => t('Update now'),
996 'url' => app::get_baseurl(true) . '/contacts/' . $contact['id'] . '/update',
1003 $contact_actions['repair'] = array(
1004 'label' => t('Repair'),
1005 'url' => app::get_baseurl(true) . '/crepair/' . $contact['id'],
1006 'title' => t('Advanced Contact Settings'),
1011 $contact_actions['block'] = array(
1012 'label' => (intval($contact['blocked']) ? t('Unblock') : t('Block') ),
1013 'url' => app::get_baseurl(true) . '/contacts/' . $contact['id'] . '/block',
1014 'title' => t('Toggle Blocked status'),
1015 'sel' => (intval($contact['blocked']) ? 'active' : ''),
1016 'id' => 'toggle-block',
1019 $contact_actions['ignore'] = array(
1020 'label' => (intval($contact['readonly']) ? t('Unignore') : t('Ignore') ),
1021 'url' => app::get_baseurl(true) . '/contacts/' . $contact['id'] . '/ignore',
1022 'title' => t('Toggle Ignored status'),
1023 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1024 'id' => 'toggle-ignore',
1027 $contact_actions['archive'] = array(
1028 'label' => (intval($contact['archive']) ? t('Unarchive') : t('Archive') ),
1029 'url' => app::get_baseurl(true) . '/contacts/' . $contact['id'] . '/archive',
1030 'title' => t('Toggle Archive status'),
1031 'sel' => (intval($contact['archive']) ? 'active' : ''),
1032 'id' => 'toggle-archive',
1035 $contact_actions['delete'] = array(
1036 'label' => t('Delete'),
1037 'url' => app::get_baseurl(true) . '/contacts/' . $contact['id'] . '/drop',
1038 'title' => t('Delete contact'),
1043 return $contact_actions;