3 * @file mod/contacts.php
6 use Friendica\Core\System;
7 use Friendica\Core\Worker;
8 use Friendica\Database\DBM;
9 use Friendica\Model\Contact;
10 use Friendica\Model\GContact;
11 use Friendica\Model\Group;
12 use Friendica\Network\Probe;
14 require_once 'include/contact_selectors.php';
15 require_once 'mod/proxy.php';
16 require_once 'include/follow.php';
18 function contacts_init(App $a) {
25 if((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
26 $contact_id = intval($a->argv[1]);
27 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
31 if (! DBM::is_result($r)) {
36 require_once 'include/contact_widgets.php';
38 if ($_GET['nets'] == "all") {
42 if (! x($a->page,'aside')) {
43 $a->page['aside'] = '';
47 $a->data['contact'] = $r[0];
49 if (($a->data['contact']['network'] != "") && ($a->data['contact']['network'] != NETWORK_DFRN)) {
50 $networkname = format_network_name($a->data['contact']['network'],$a->data['contact']['url']);
55 /// @TODO Add nice spaces
56 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
57 '$name' => htmlentities($a->data['contact']['name']),
58 '$photo' => $a->data['contact']['photo'],
59 '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? "redir/".$a->data['contact']['id'] : $a->data['contact']['url'],
60 '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""),
61 '$network_name' => $networkname,
62 '$network' => t('Network:'),
63 '$account_type' => Contact::getAccountType($a->data['contact'])
66 $finpeople_widget = '';
68 $networks_widget = '';
71 $networks_widget .= networks_widget('contacts',$_GET['nets']);
72 if (isset($_GET['add'])) {
73 $follow_widget = follow_widget($_GET['add']);
75 $follow_widget = follow_widget();
78 $findpeople_widget .= findpeople_widget();
81 $groups_widget .= Group::sidebarWidget('contacts','group','full',0,$contact_id);
83 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
84 '$vcard_widget' => $vcard_widget,
85 '$findpeople_widget' => $findpeople_widget,
86 '$follow_widget' => $follow_widget,
87 '$groups_widget' => $groups_widget,
88 '$networks_widget' => $networks_widget
91 $base = System::baseUrl();
92 $tpl = get_markup_template("contacts-head.tpl");
93 $a->page['htmlhead'] .= replace_macros($tpl,array(
94 '$baseurl' => System::baseUrl(true),
98 $tpl = get_markup_template("contacts-end.tpl");
99 $a->page['end'] .= replace_macros($tpl,array(
100 '$baseurl' => System::baseUrl(true),
107 function contacts_batch_actions(App $a) {
108 $contacts_id = $_POST['contact_batch'];
109 if (!is_array($contacts_id)) return;
111 $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
112 implode(",", $contacts_id),
117 foreach($orig_records as $orig_record) {
118 $contact_id = $orig_record['id'];
119 if (x($_POST, 'contacts_batch_update')) {
120 _contact_update($contact_id);
123 if (x($_POST, 'contacts_batch_block')) {
124 $r = _contact_block($contact_id, $orig_record);
125 if ($r) $count_actions++;
127 if (x($_POST, 'contacts_batch_ignore')) {
128 $r = _contact_ignore($contact_id, $orig_record);
129 if ($r) $count_actions++;
131 if (x($_POST, 'contacts_batch_archive')) {
132 $r = _contact_archive($contact_id, $orig_record);
133 if ($r) $count_actions++;
135 if (x($_POST, 'contacts_batch_drop')) {
136 _contact_drop($orig_record);
140 if ($count_actions>0) {
141 info ( sprintf( tt("%d contact edited.", "%d contacts edited.", $count_actions), $count_actions) );
144 if (x($_SESSION,'return_url')) {
145 goaway('' . $_SESSION['return_url']);
154 function contacts_post(App $a) {
156 if (! local_user()) {
160 if ($a->argv[1]==="batch") {
161 contacts_batch_actions($a);
165 $contact_id = intval($a->argv[1]);
170 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
175 if (! count($orig_record)) {
176 notice( t('Could not access contact record.') . EOL);
178 return; // NOTREACHED
181 call_hooks('contact_edit_post', $_POST);
183 $profile_id = intval($_POST['profile-assign']);
185 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
189 if (! DBM::is_result($r)) {
190 notice( t('Could not locate selected profile.') . EOL);
195 $hidden = intval($_POST['hidden']);
197 $notify = intval($_POST['notify']);
199 $fetch_further_information = intval($_POST['fetch_further_information']);
201 $ffi_keyword_blacklist = escape_tags(trim($_POST['ffi_keyword_blacklist']));
203 $priority = intval($_POST['poll']);
204 if($priority > 5 || $priority < 0)
207 $info = escape_tags(trim($_POST['info']));
209 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
210 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
211 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
217 intval($fetch_further_information),
218 dbesc($ffi_keyword_blacklist),
223 info( t('Contact updated.') . EOL);
225 notice( t('Failed to update contact record.') . EOL);
227 $r = q("select * from contact where id = %d and uid = %d limit 1",
231 if($r && DBM::is_result($r))
232 $a->data['contact'] = $r[0];
239 function _contact_update($contact_id) {
240 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
246 if ($uid != local_user())
249 if ($r[0]["network"] == NETWORK_OSTATUS) {
250 $result = new_contact($uid, $r[0]["url"], false, $r[0]["network"]);
252 if ($result['success'])
253 $r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
254 intval($contact_id));
256 // pull feed and consume it, which should subscribe to the hub.
257 Worker::add(PRIORITY_HIGH, "OnePoll", $contact_id, "force");
260 function _contact_update_profile($contact_id) {
261 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
267 if ($uid != local_user())
270 $data = Probe::uri($r[0]["url"], "", 0, false);
272 // "Feed" or "Unknown" is mostly a sign of communication problems
273 if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) && ($data["network"] != $r[0]["network"]))
276 $updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
277 "poco", "network", "alias");
280 if ($data["network"] == NETWORK_OSTATUS) {
281 $result = new_contact($uid, $data["url"], false);
283 if ($result['success'])
284 $update["subhub"] = true;
287 foreach($updatefields AS $field)
288 if (isset($data[$field]) && ($data[$field] != ""))
289 $update[$field] = $data[$field];
291 $update["nurl"] = normalise_link($data["url"]);
295 if (isset($data["priority"]) && ($data["priority"] != 0))
296 $query = "`priority` = ".intval($data["priority"]);
298 foreach($update AS $key => $value) {
302 $query .= "`".$key."` = '".dbesc($value)."'";
308 $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
313 // Update the entry in the contact table
314 Contact::updateAvatar($data['photo'], local_user(), $contact_id, true);
316 // Update the entry in the gcontact table
317 GContact::updateFromProbe($data["url"]);
320 function _contact_block($contact_id, $orig_record) {
321 $blocked = (($orig_record['blocked']) ? 0 : 1);
322 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
330 function _contact_ignore($contact_id, $orig_record) {
331 $readonly = (($orig_record['readonly']) ? 0 : 1);
332 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
339 function _contact_archive($contact_id, $orig_record) {
340 $archived = (($orig_record['archive']) ? 0 : 1);
341 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
347 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
352 function _contact_drop($orig_record)
356 $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
357 WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
358 intval($a->user['uid'])
360 if (!DBM::is_result($r)) {
364 Contact::terminateFriendship($r[0], $orig_record);
365 Contact::remove($orig_record['id']);
369 function contacts_content(App $a) {
373 nav_set_selected('contacts');
376 if (! local_user()) {
377 notice( t('Permission denied.') . EOL);
383 $contact_id = intval($a->argv[1]);
389 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
394 if(! count($orig_record)) {
395 notice( t('Could not access contact record.') . EOL);
397 return; // NOTREACHED
400 if($cmd === 'update') {
401 _contact_update($contact_id);
402 goaway('contacts/' . $contact_id);
406 if($cmd === 'updateprofile') {
407 _contact_update_profile($contact_id);
408 goaway('crepair/' . $contact_id);
412 if($cmd === 'block') {
413 $r = _contact_block($contact_id, $orig_record[0]);
415 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
416 info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL);
419 goaway('contacts/' . $contact_id);
420 return; // NOTREACHED
423 if($cmd === 'ignore') {
424 $r = _contact_ignore($contact_id, $orig_record[0]);
426 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
427 info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL);
430 goaway('contacts/' . $contact_id);
431 return; // NOTREACHED
435 if($cmd === 'archive') {
436 $r = _contact_archive($contact_id, $orig_record[0]);
438 $archived = (($orig_record[0]['archive']) ? 0 : 1);
439 info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL);
442 goaway('contacts/' . $contact_id);
443 return; // NOTREACHED
446 if($cmd === 'drop') {
448 // Check if we should do HTML-based delete confirmation
449 if($_REQUEST['confirm']) {
450 // <form> can't take arguments in its "action" parameter
451 // so add any arguments as hidden inputs
452 $query = explode_querystring($a->query_string);
454 foreach($query['args'] as $arg) {
455 if(strpos($arg, 'confirm=') === false) {
456 $arg_parts = explode('=', $arg);
457 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
461 $a->page['aside'] = '';
463 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), array(
464 '$header' => t('Drop contact'),
465 '$contact' => _contact_detail_for_template($orig_record[0]),
467 '$message' => t('Do you really want to delete this contact?'),
468 '$extra_inputs' => $inputs,
469 '$confirm' => t('Yes'),
470 '$confirm_url' => $query['base'],
471 '$confirm_name' => 'confirmed',
472 '$cancel' => t('Cancel'),
475 // Now check how the user responded to the confirmation query
476 if ($_REQUEST['canceled']) {
477 if (x($_SESSION,'return_url')) {
478 goaway('' . $_SESSION['return_url']);
485 _contact_drop($orig_record[0]);
486 info( t('Contact has been removed.') . EOL );
487 if (x($_SESSION,'return_url')) {
488 goaway('' . $_SESSION['return_url']);
493 return; // NOTREACHED
495 if ($cmd === 'posts') {
496 return contact_posts($a, $contact_id);
502 $_SESSION['return_url'] = $a->query_string;
504 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
506 $contact_id = $a->data['contact']['id'];
507 $contact = $a->data['contact'];
509 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
510 '$baseurl' => System::baseUrl(true),
512 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
513 '$baseurl' => System::baseUrl(true),
516 require_once 'include/contact_selectors.php';
518 $tpl = get_markup_template("contact_edit.tpl");
520 switch($contact['rel']) {
521 case CONTACT_IS_FRIEND:
522 $dir_icon = 'images/lrarrow.gif';
523 $relation_text = t('You are mutual friends with %s');
525 case CONTACT_IS_FOLLOWER;
526 $dir_icon = 'images/larrow.gif';
527 $relation_text = t('You are sharing with %s');
530 case CONTACT_IS_SHARING;
531 $dir_icon = 'images/rarrow.gif';
532 $relation_text = t('%s is sharing with you');
538 if(!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
541 $relation_text = sprintf($relation_text,htmlentities($contact['name']));
543 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
544 $url = "redir/{$contact['id']}";
545 $sparkle = ' class="sparkle" ';
548 $url = $contact['url'];
552 $insecure = t('Private communications are not available for this contact.');
554 $last_update = (($contact['last-update'] <= NULL_DATE)
556 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
558 if ($contact['last-update'] > NULL_DATE) {
559 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
561 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
563 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL));
565 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"]));
567 //$common = GlobalContact::countCommonFriends(local_user(),$contact['id']);
568 //$common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
570 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
572 //$x = GlobalContact::countAllFriends(local_user(), $contact['id']);
573 //$all_friends = (($x) ? t('View all contacts') : '');
576 $tab_str = contacts_tab($a, $contact_id, 2);
578 $lost_contact = (($contact['archive'] && $contact['term-date'] > NULL_DATE && $contact['term-date'] < datetime_convert('','','now')) ? t('Communications lost with this contact!') : '');
580 if ($contact['network'] == NETWORK_FEED) {
581 $fetch_further_information = array('fetch_further_information',
582 t('Fetch further information for feeds'),
583 $contact['fetch_further_information'],
584 t("Fetch information like preview pictures, title and teaser from the feed item. You can activate this if the feed doesn't contain much text. Keywords are taken from the meta header in the feed item and are posted as hash tags."),
585 array('0' => t('Disabled'),
586 '1' => t('Fetch information'),
587 '3' => t('Fetch keywords'),
588 '2' => t('Fetch information and keywords')));
590 if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL)))
591 $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
593 if ($contact['network'] == NETWORK_DFRN)
594 $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
596 if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS))) {
597 if ($contact['rel'] == CONTACT_IS_FOLLOWER) {
598 $follow = System::baseUrl(true)."/follow?url=".urlencode($contact["url"]);
599 $follow_text = t("Connect/Follow");
600 } elseif ($contact['rel'] == CONTACT_IS_FRIEND) {
601 $follow = System::baseUrl(true)."/unfollow?url=".urlencode($contact["url"]);
602 $follow_text = t("Disconnect/Unfollow");
606 // Load contactact related actions like hide, suggest, delete and others
607 $contact_actions = contact_actions($contact);
610 $o .= replace_macros($tpl, array(
611 //'$header' => t('Contact Editor'),
612 '$header' => t("Contact"),
613 '$tab_str' => $tab_str,
614 '$submit' => t('Submit'),
615 '$lbl_vis1' => t('Profile Visibility'),
616 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
617 '$lbl_info1' => t('Contact Information / Notes'),
618 '$lbl_info2' => t('Their personal note'),
619 '$reason' => trim(notags($contact['reason'])),
620 '$infedit' => t('Edit contact notes'),
621 '$common_text' => $common_text,
622 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
623 '$all_friends' => $all_friends,
624 '$relation_text' => $relation_text,
625 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
626 '$blockunblock' => t('Block/Unblock contact'),
627 '$ignorecont' => t('Ignore contact'),
628 '$lblcrepair' => t("Repair URL settings"),
629 '$lblrecent' => t('View conversations'),
630 '$lblsuggest' => $lblsuggest,
631 //'$delete' => t('Delete contact'),
632 '$nettype' => $nettype,
633 '$poll_interval' => $poll_interval,
634 '$poll_enabled' => $poll_enabled,
635 '$lastupdtext' => t('Last update:'),
636 '$lost_contact' => $lost_contact,
637 '$updpub' => t('Update public posts'),
638 '$last_update' => $last_update,
639 '$udnow' => t('Update now'),
640 '$follow' => $follow,
641 '$follow_text' => $follow_text,
642 '$profile_select' => $profile_select,
643 '$contact_id' => $contact['id'],
644 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
645 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
646 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
647 '$info' => $contact['info'],
648 '$cinfo' => array('info', '', $contact['info'], ''),
649 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
650 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
651 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
652 '$pending' => (($contact['pending']) ? t('Awaiting connection acknowledge') : ''),
653 '$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')),
654 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
655 '$fetch_further_information' => $fetch_further_information,
656 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
657 '$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')),
658 '$photo' => $contact['photo'],
659 '$name' => htmlentities($contact['name']),
660 '$dir_icon' => $dir_icon,
661 '$alt_text' => $alt_text,
662 '$sparkle' => $sparkle,
664 '$profileurllabel' => t('Profile URL'),
665 '$profileurl' => $contact['url'],
666 '$account_type' => Contact::getAccountType($contact),
667 '$location' => bbcode($contact["location"]),
668 '$location_label' => t("Location:"),
669 '$xmpp' => bbcode($contact["xmpp"]),
670 '$xmpp_label' => t("XMPP:"),
671 '$about' => bbcode($contact["about"], false, false),
672 '$about_label' => t("About:"),
673 '$keywords' => $contact["keywords"],
674 '$keywords_label' => t("Tags:"),
675 '$contact_action_button' => t("Actions"),
676 '$contact_actions' => $contact_actions,
677 '$contact_status' => t("Status"),
678 '$contact_settings_label' => t('Contact Settings'),
679 '$contact_profile_label' => t("Profile"),
683 $arr = array('contact' => $contact,'output' => $o);
685 call_hooks('contact_edit', $arr);
687 return $arr['output'];
696 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
700 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
701 $sql_extra = " AND `blocked` = 1 ";
704 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
705 $sql_extra = " AND `hidden` = 1 ";
708 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
709 $sql_extra = " AND `readonly` = 1 ";
712 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
713 $sql_extra = " AND `archive` = 1 ";
717 $sql_extra = " AND `blocked` = 0 ";
719 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
720 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
724 'label' => t('Suggestions'),
727 'title' => t('Suggest potential friends'),
728 'id' => 'suggestions-tab',
732 'label' => t('All Contacts'),
733 'url' => 'contacts/all',
734 'sel' => ($all) ? 'active' : '',
735 'title' => t('Show all contacts'),
736 'id' => 'showall-tab',
740 'label' => t('Unblocked'),
742 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
743 'title' => t('Only show unblocked contacts'),
744 'id' => 'showunblocked-tab',
749 'label' => t('Blocked'),
750 'url' => 'contacts/blocked',
751 'sel' => ($blocked) ? 'active' : '',
752 'title' => t('Only show blocked contacts'),
753 'id' => 'showblocked-tab',
758 'label' => t('Ignored'),
759 'url' => 'contacts/ignored',
760 'sel' => ($ignored) ? 'active' : '',
761 'title' => t('Only show ignored contacts'),
762 'id' => 'showignored-tab',
767 'label' => t('Archived'),
768 'url' => 'contacts/archived',
769 'sel' => ($archived) ? 'active' : '',
770 'title' => t('Only show archived contacts'),
771 'id' => 'showarchived-tab',
776 'label' => t('Hidden'),
777 'url' => 'contacts/hidden',
778 'sel' => ($hidden) ? 'active' : '',
779 'title' => t('Only show hidden contacts'),
780 'id' => 'showhidden-tab',
786 $tab_tpl = get_markup_template('common_tabs.tpl');
787 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
793 $search_hdr = $search;
794 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
797 $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
800 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
802 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
805 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
806 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
807 intval($_SESSION['uid']));
808 if (DBM::is_result($r)) {
809 $a->set_pager_total($r[0]['total']);
810 $total = $r[0]['total'];
813 $sql_extra3 = unavailable_networks();
815 $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 ",
816 intval($_SESSION['uid']),
817 intval($a->pager['start']),
818 intval($a->pager['itemspage'])
823 if (DBM::is_result($r)) {
824 foreach ($r as $rr) {
825 $contacts[] = _contact_detail_for_template($rr);
829 $tpl = get_markup_template("contacts-template.tpl");
830 $o .= replace_macros($tpl, array(
831 '$baseurl' => System::baseUrl(),
832 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
835 '$search' => $search_hdr,
836 '$desc' => t('Search your contacts'),
837 '$finding' => (($searching) ? sprintf(t('Results for: %s'),$search) : ""),
838 '$submit' => t('Find'),
840 '$contacts' => $contacts,
841 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
843 '$batch_actions' => array(
844 'contacts_batch_update' => t('Update'),
845 'contacts_batch_block' => t('Block')."/".t("Unblock"),
846 "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
847 "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
848 "contacts_batch_drop" => t('Delete'),
850 '$h_batch_actions' => t('Batch Actions'),
851 '$paginate' => paginate($a),
859 * @brief List of pages for the Contact TabBar
861 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
864 * @param int $contact_id The ID of the contact
865 * @param int $active_tab 1 if tab should be marked as active
867 * @return array with with contact TabBar data
869 function contacts_tab($a, $contact_id, $active_tab) {
873 'label'=>t('Status'),
874 'url' => "contacts/".$contact_id."/posts",
875 'sel' => (($active_tab == 1)?'active':''),
876 'title' => t('Status Messages and Posts'),
877 'id' => 'status-tab',
881 'label'=>t('Profile'),
882 'url' => "contacts/".$contact_id,
883 'sel' => (($active_tab == 2)?'active':''),
884 'title' => t('Profile Details'),
885 'id' => 'profile-tab',
890 // Show this tab only if there is visible friend list
891 $x = GContact::countAllFriends(local_user(), $contact_id);
893 $tabs[] = array('label'=>t('Contacts'),
894 'url' => "allfriends/".$contact_id,
895 'sel' => (($active_tab == 3)?'active':''),
896 'title' => t('View all contacts'),
897 'id' => 'allfriends-tab',
900 // Show this tab only if there is visible common friend list
901 $common = GContact::countCommonFriends(local_user(), $contact_id);
903 $tabs[] = array('label'=>t('Common Friends'),
904 'url' => "common/loc/".local_user()."/".$contact_id,
905 'sel' => (($active_tab == 4)?'active':''),
906 'title' => t('View all common friends'),
907 'id' => 'common-loc-tab',
910 $tabs[] = array('label' => t('Advanced'),
911 'url' => 'crepair/' . $contact_id,
912 'sel' => (($active_tab == 5)?'active':''),
913 'title' => t('Advanced Contact Settings'),
914 'id' => 'advanced-tab',
917 $tab_tpl = get_markup_template('common_tabs.tpl');
918 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
923 function contact_posts($a, $contact_id) {
925 $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
928 $a->page['aside'] = "";
929 profile_load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
933 $tab_str = contacts_tab($a, $contact_id, 1);
937 $o .= Contact::getPostsFromUrl($contact["url"]);
942 function _contact_detail_for_template($rr){
945 case CONTACT_IS_FRIEND:
946 $dir_icon = 'images/lrarrow.gif';
947 $alt_text = t('Mutual Friendship');
949 case CONTACT_IS_FOLLOWER;
950 $dir_icon = 'images/larrow.gif';
951 $alt_text = t('is a fan of yours');
953 case CONTACT_IS_SHARING;
954 $dir_icon = 'images/rarrow.gif';
955 $alt_text = t('you are a fan of');
960 if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
961 $url = "redir/{$rr['id']}";
962 $sparkle = ' class="sparkle" ';
970 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
971 'edit_hover' => t('Edit contact'),
972 'photo_menu' => Contact::photoMenu($rr),
974 'alt_text' => $alt_text,
975 'dir_icon' => $dir_icon,
976 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
977 'name' => htmlentities($rr['name']),
978 'username' => htmlentities($rr['name']),
979 'account_type' => Contact::getAccountType($rr),
980 'sparkle' => $sparkle,
981 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
983 'network' => network_to_name($rr['network'], $rr['url']),
989 * @brief Gives a array with actions which can performed to a given contact
991 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
993 * @param array $contact Data about the Contact
994 * @return array with contact related actions
996 function contact_actions($contact) {
998 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL));
999 $contact_action = array();
1001 // Provide friend suggestion only for Friendica contacts
1002 if($contact['network'] === NETWORK_DFRN) {
1003 $contact_actions['suggest'] = array(
1004 'label' => t('Suggest friends'),
1005 'url' => 'fsuggest/' . $contact['id'],
1013 $contact_actions['update'] = array(
1014 'label' => t('Update now'),
1015 'url' => 'contacts/' . $contact['id'] . '/update',
1022 $contact_actions['block'] = array(
1023 'label' => (intval($contact['blocked']) ? t('Unblock') : t('Block') ),
1024 'url' => 'contacts/' . $contact['id'] . '/block',
1025 'title' => t('Toggle Blocked status'),
1026 'sel' => (intval($contact['blocked']) ? 'active' : ''),
1027 'id' => 'toggle-block',
1030 $contact_actions['ignore'] = array(
1031 'label' => (intval($contact['readonly']) ? t('Unignore') : t('Ignore') ),
1032 'url' => 'contacts/' . $contact['id'] . '/ignore',
1033 'title' => t('Toggle Ignored status'),
1034 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1035 'id' => 'toggle-ignore',
1038 $contact_actions['archive'] = array(
1039 'label' => (intval($contact['archive']) ? t('Unarchive') : t('Archive') ),
1040 'url' => 'contacts/' . $contact['id'] . '/archive',
1041 'title' => t('Toggle Archive status'),
1042 'sel' => (intval($contact['archive']) ? 'active' : ''),
1043 'id' => 'toggle-archive',
1046 $contact_actions['delete'] = array(
1047 'label' => t('Delete'),
1048 'url' => 'contacts/' . $contact['id'] . '/drop',
1049 'title' => t('Delete contact'),
1054 return $contact_actions;