3 * @file mod/contacts.php
7 use Friendica\Content\ContactSelector;
8 use Friendica\Content\Nav;
9 use Friendica\Content\Text\BBCode;
10 use Friendica\Content\Widget;
11 use Friendica\Core\Addon;
12 use Friendica\Core\L10n;
13 use Friendica\Core\System;
14 use Friendica\Core\Worker;
15 use Friendica\Database\DBM;
16 use Friendica\Model\Contact;
17 use Friendica\Model\GContact;
18 use Friendica\Model\Group;
19 use Friendica\Model\Profile;
20 use Friendica\Network\Probe;
21 use Friendica\Util\DateTimeFormat;
23 require_once 'mod/proxy.php';
25 function contacts_init(App $a)
31 $nets = defaults($_GET, 'nets', '');
36 if (!x($a->page, 'aside')) {
37 $a->page['aside'] = '';
42 if ((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
43 $contact_id = intval($a->argv[1]);
44 $contact = dba::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
47 if (DBM::is_result($contact)) {
48 $a->data['contact'] = $contact;
50 if (($a->data['contact']['network'] != "") && ($a->data['contact']['network'] != NETWORK_DFRN)) {
51 $networkname = format_network_name($a->data['contact']['network'], $a->data['contact']['url']);
56 /// @TODO Add nice spaces
57 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"), [
58 '$name' => htmlentities($a->data['contact']['name']),
59 '$photo' => $a->data['contact']['photo'],
60 '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? "redir/" . $a->data['contact']['id'] : $a->data['contact']['url'],
61 '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""),
62 '$network_name' => $networkname,
63 '$network' => L10n::t('Network:'),
64 '$account_type' => Contact::getAccountType($a->data['contact'])
67 $findpeople_widget = '';
69 $networks_widget = '';
72 $networks_widget = Widget::networks('contacts', $nets);
73 if (isset($_GET['add'])) {
74 $follow_widget = Widget::follow($_GET['add']);
76 $follow_widget = Widget::follow();
79 $findpeople_widget = Widget::findPeople();
82 $groups_widget = Group::sidebarWidget('contacts', 'group', 'full', 0, $contact_id);
84 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"), [
85 '$vcard_widget' => $vcard_widget,
86 '$findpeople_widget' => $findpeople_widget,
87 '$follow_widget' => $follow_widget,
88 '$groups_widget' => $groups_widget,
89 '$networks_widget' => $networks_widget
92 $base = System::baseUrl();
93 $tpl = get_markup_template("contacts-head.tpl");
94 $a->page['htmlhead'] .= replace_macros($tpl, [
95 '$baseurl' => System::baseUrl(true),
99 $tpl = get_markup_template("contacts-end.tpl");
100 $a->page['end'] .= replace_macros($tpl, [
101 '$baseurl' => System::baseUrl(true),
106 function contacts_batch_actions(App $a)
108 $contacts_id = $_POST['contact_batch'];
109 if (!is_array($contacts_id)) {
113 $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
114 implode(",", $contacts_id),
119 foreach ($orig_records as $orig_record) {
120 $contact_id = $orig_record['id'];
121 if (x($_POST, 'contacts_batch_update')) {
122 _contact_update($contact_id);
125 if (x($_POST, 'contacts_batch_block')) {
126 $r = _contact_block($contact_id, $orig_record);
131 if (x($_POST, 'contacts_batch_ignore')) {
132 $r = _contact_ignore($contact_id, $orig_record);
137 if (x($_POST, 'contacts_batch_archive')) {
138 $r = _contact_archive($contact_id, $orig_record);
143 if (x($_POST, 'contacts_batch_drop')) {
144 _contact_drop($orig_record);
148 if ($count_actions > 0) {
149 info(L10n::tt("%d contact edited.", "%d contacts edited.", $count_actions));
152 if (x($_SESSION, 'return_url')) {
153 goaway('' . $_SESSION['return_url']);
159 function contacts_post(App $a)
165 if ($a->argv[1] === "batch") {
166 contacts_batch_actions($a);
170 $contact_id = intval($a->argv[1]);
175 if (!dba::exists('contact', ['id' => $contact_id, 'uid' => local_user()])) {
176 notice(L10n::t('Could not access contact record.') . EOL);
178 return; // NOTREACHED
181 Addon::callHooks('contact_edit_post', $_POST);
183 $profile_id = intval($_POST['profile-assign']);
185 if (!dba::exists('profile', ['id' => $profile_id, 'uid' => local_user()])) {
186 notice(L10n::t('Could not locate selected profile.') . EOL);
191 $hidden = intval($_POST['hidden']);
193 $notify = intval($_POST['notify']);
195 $fetch_further_information = intval($_POST['fetch_further_information']);
197 $ffi_keyword_blacklist = escape_tags(trim($_POST['ffi_keyword_blacklist']));
199 $priority = intval($_POST['poll']);
200 if ($priority > 5 || $priority < 0) {
204 $info = escape_tags(trim($_POST['info']));
206 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
207 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
208 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
214 intval($fetch_further_information),
215 dbesc($ffi_keyword_blacklist),
219 if (DBM::is_result($r)) {
220 info(L10n::t('Contact updated.') . EOL);
222 notice(L10n::t('Failed to update contact record.') . EOL);
225 $contact = dba::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
226 if (DBM::is_result($contact)) {
227 $a->data['contact'] = $contact;
233 /* contact actions */
235 function _contact_update($contact_id)
237 $contact = dba::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
238 if (!DBM::is_result($contact)) {
242 $uid = $contact["uid"];
244 if ($contact["network"] == NETWORK_OSTATUS) {
245 $result = Contact::createFromProbe($uid, $contact["url"], false, $contact["network"]);
247 if ($result['success']) {
248 q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d", intval($contact_id));
251 // pull feed and consume it, which should subscribe to the hub.
252 Worker::add(PRIORITY_HIGH, "OnePoll", $contact_id, "force");
256 function _contact_update_profile($contact_id)
258 $contact = dba::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
259 if (!DBM::is_result($contact)) {
263 $uid = $contact["uid"];
265 $data = Probe::uri($contact["url"], "", 0, false);
267 // "Feed" or "Unknown" is mostly a sign of communication problems
268 if ((in_array($data["network"], [NETWORK_FEED, NETWORK_PHANTOM])) && ($data["network"] != $contact["network"])) {
272 $updatefields = ["name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
273 "poco", "network", "alias"];
276 if ($data["network"] == NETWORK_OSTATUS) {
277 $result = Contact::createFromProbe($uid, $data["url"], false);
279 if ($result['success']) {
280 $update["subhub"] = true;
284 foreach ($updatefields AS $field) {
285 if (isset($data[$field]) && ($data[$field] != "")) {
286 $update[$field] = $data[$field];
290 $update["nurl"] = normalise_link($data["url"]);
294 if (isset($data["priority"]) && ($data["priority"] != 0)) {
295 $query = "`priority` = " . intval($data["priority"]);
298 foreach ($update AS $key => $value) {
303 $query .= "`" . $key . "` = '" . dbesc($value) . "'";
310 $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
315 // Update the entry in the contact table
316 Contact::updateAvatar($data['photo'], local_user(), $contact_id, true);
318 // Update the entry in the gcontact table
319 GContact::updateFromProbe($data["url"]);
322 function _contact_block($contact_id, $orig_record)
324 $blocked = (($orig_record['blocked']) ? 0 : 1);
325 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
330 return DBM::is_result($r);
333 function _contact_ignore($contact_id, $orig_record)
335 $readonly = (($orig_record['readonly']) ? 0 : 1);
336 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
341 return DBM::is_result($r);
344 function _contact_archive($contact_id, $orig_record)
346 $archived = (($orig_record['archive']) ? 0 : 1);
347 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
352 return DBM::is_result($r);
355 function _contact_drop($orig_record)
359 $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
360 WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
361 intval($a->user['uid'])
363 if (!DBM::is_result($r)) {
367 Contact::terminateFriendship($r[0], $orig_record);
368 Contact::remove($orig_record['id']);
371 function contacts_content(App $a)
375 Nav::setSelected('contacts');
378 notice(L10n::t('Permission denied.') . EOL);
383 $contact_id = intval($a->argv[1]);
390 $orig_record = dba::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'self' => false]);
391 if (!DBM::is_result($orig_record)) {
392 notice(L10n::t('Could not access contact record.') . EOL);
394 return; // NOTREACHED
397 if ($cmd === 'update') {
398 _contact_update($contact_id);
399 goaway('contacts/' . $contact_id);
403 if ($cmd === 'updateprofile') {
404 _contact_update_profile($contact_id);
405 goaway('crepair/' . $contact_id);
409 if ($cmd === 'block') {
410 $r = _contact_block($contact_id, $orig_record);
412 $blocked = (($orig_record['blocked']) ? 0 : 1);
413 info((($blocked) ? L10n::t('Contact has been blocked') : L10n::t('Contact has been unblocked')) . EOL);
416 goaway('contacts/' . $contact_id);
417 return; // NOTREACHED
420 if ($cmd === 'ignore') {
421 $r = _contact_ignore($contact_id, $orig_record);
423 $readonly = (($orig_record['readonly']) ? 0 : 1);
424 info((($readonly) ? L10n::t('Contact has been ignored') : L10n::t('Contact has been unignored')) . EOL);
427 goaway('contacts/' . $contact_id);
428 return; // NOTREACHED
431 if ($cmd === 'archive') {
432 $r = _contact_archive($contact_id, $orig_record);
434 $archived = (($orig_record['archive']) ? 0 : 1);
435 info((($archived) ? L10n::t('Contact has been archived') : L10n::t('Contact has been unarchived')) . EOL);
438 goaway('contacts/' . $contact_id);
439 return; // NOTREACHED
442 if ($cmd === 'drop') {
443 // Check if we should do HTML-based delete confirmation
444 if (x($_REQUEST, 'confirm')) {
445 // <form> can't take arguments in its "action" parameter
446 // so add any arguments as hidden inputs
447 $query = explode_querystring($a->query_string);
449 foreach ($query['args'] as $arg) {
450 if (strpos($arg, 'confirm=') === false) {
451 $arg_parts = explode('=', $arg);
452 $inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]];
456 $a->page['aside'] = '';
458 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), [
459 '$header' => L10n::t('Drop contact'),
460 '$contact' => _contact_detail_for_template($orig_record),
462 '$message' => L10n::t('Do you really want to delete this contact?'),
463 '$extra_inputs' => $inputs,
464 '$confirm' => L10n::t('Yes'),
465 '$confirm_url' => $query['base'],
466 '$confirm_name' => 'confirmed',
467 '$cancel' => L10n::t('Cancel'),
470 // Now check how the user responded to the confirmation query
471 if (x($_REQUEST, 'canceled')) {
472 if (x($_SESSION, 'return_url')) {
473 goaway('' . $_SESSION['return_url']);
479 _contact_drop($orig_record);
480 info(L10n::t('Contact has been removed.') . EOL);
481 if (x($_SESSION, 'return_url')) {
482 goaway('' . $_SESSION['return_url']);
486 return; // NOTREACHED
488 if ($cmd === 'posts') {
489 return contact_posts($a, $contact_id);
493 $_SESSION['return_url'] = $a->query_string;
495 if ((x($a->data, 'contact')) && (is_array($a->data['contact']))) {
496 $contact_id = $a->data['contact']['id'];
497 $contact = $a->data['contact'];
499 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), [
500 '$baseurl' => System::baseUrl(true),
502 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), [
503 '$baseurl' => System::baseUrl(true),
508 switch ($contact['rel']) {
509 case CONTACT_IS_FRIEND:
510 $dir_icon = 'images/lrarrow.gif';
511 $relation_text = L10n::t('You are mutual friends with %s');
513 case CONTACT_IS_FOLLOWER;
514 $dir_icon = 'images/larrow.gif';
515 $relation_text = L10n::t('You are sharing with %s');
517 case CONTACT_IS_SHARING;
518 $dir_icon = 'images/rarrow.gif';
519 $relation_text = L10n::t('%s is sharing with you');
525 if (!in_array($contact['network'], [NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA])) {
529 $relation_text = sprintf($relation_text, htmlentities($contact['name']));
531 if (($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
532 $url = "redir/{$contact['id']}";
533 $sparkle = ' class="sparkle" ';
535 $url = $contact['url'];
539 $insecure = L10n::t('Private communications are not available for this contact.');
541 $last_update = (($contact['last-update'] <= NULL_DATE) ? L10n::t('Never') : DateTimeFormat::local($contact['last-update'], 'D, j M Y, g:i A'));
543 if ($contact['last-update'] > NULL_DATE) {
544 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? L10n::t("\x28Update was successful\x29") : L10n::t("\x28Update was not successful\x29"));
546 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? L10n::t('Suggest friends') : '');
548 $poll_enabled = in_array($contact['network'], [NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL]);
550 $nettype = L10n::t('Network type: %s', ContactSelector::networkToName($contact['network'], $contact["url"]));
553 $tab_str = contacts_tab($a, $contact_id, 2);
555 $lost_contact = (($contact['archive'] && $contact['term-date'] > NULL_DATE && $contact['term-date'] < DateTimeFormat::utcNow()) ? L10n::t('Communications lost with this contact!') : '');
557 $fetch_further_information = null;
558 if ($contact['network'] == NETWORK_FEED) {
559 $fetch_further_information = [
560 'fetch_further_information',
561 L10n::t('Fetch further information for feeds'),
562 $contact['fetch_further_information'],
563 L10n::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."),
564 ['0' => L10n::t('Disabled'),
565 '1' => L10n::t('Fetch information'),
566 '3' => L10n::t('Fetch keywords'),
567 '2' => L10n::t('Fetch information and keywords')
572 $poll_interval = null;
573 if (in_array($contact['network'], [NETWORK_FEED, NETWORK_MAIL])) {
574 $poll_interval = ContactSelector::pollInterval($contact['priority'], (!$poll_enabled));
577 $profile_select = null;
578 if ($contact['network'] == NETWORK_DFRN) {
579 $profile_select = ContactSelector::profileAssign($contact['profile-id'], (($contact['network'] !== NETWORK_DFRN) ? true : false));
584 if (in_array($contact['network'], [NETWORK_DIASPORA, NETWORK_OSTATUS])) {
585 if ($contact['rel'] == CONTACT_IS_FOLLOWER) {
586 $follow = System::baseUrl(true) . "/follow?url=" . urlencode($contact["url"]);
587 $follow_text = L10n::t("Connect/Follow");
588 } elseif ($contact['rel'] == CONTACT_IS_FRIEND) {
589 $follow = System::baseUrl(true) . "/unfollow?url=" . urlencode($contact["url"]);
590 $follow_text = L10n::t("Disconnect/Unfollow");
594 // Load contactact related actions like hide, suggest, delete and others
595 $contact_actions = contact_actions($contact);
597 $tpl = get_markup_template("contact_edit.tpl");
598 $o .= replace_macros($tpl, [
599 '$header' => L10n::t("Contact"),
600 '$tab_str' => $tab_str,
601 '$submit' => L10n::t('Submit'),
602 '$lbl_vis1' => L10n::t('Profile Visibility'),
603 '$lbl_vis2' => L10n::t('Please choose the profile you would like to display to %s when viewing your profile securely.', $contact['name']),
604 '$lbl_info1' => L10n::t('Contact Information / Notes'),
605 '$lbl_info2' => L10n::t('Their personal note'),
606 '$reason' => trim(notags($contact['reason'])),
607 '$infedit' => L10n::t('Edit contact notes'),
608 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
609 '$relation_text' => $relation_text,
610 '$visit' => L10n::t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']),
611 '$blockunblock' => L10n::t('Block/Unblock contact'),
612 '$ignorecont' => L10n::t('Ignore contact'),
613 '$lblcrepair' => L10n::t("Repair URL settings"),
614 '$lblrecent' => L10n::t('View conversations'),
615 '$lblsuggest' => $lblsuggest,
616 '$nettype' => $nettype,
617 '$poll_interval' => $poll_interval,
618 '$poll_enabled' => $poll_enabled,
619 '$lastupdtext' => L10n::t('Last update:'),
620 '$lost_contact' => $lost_contact,
621 '$updpub' => L10n::t('Update public posts'),
622 '$last_update' => $last_update,
623 '$udnow' => L10n::t('Update now'),
624 '$follow' => $follow,
625 '$follow_text' => $follow_text,
626 '$profile_select' => $profile_select,
627 '$contact_id' => $contact['id'],
628 '$block_text' => (($contact['blocked']) ? L10n::t('Unblock') : L10n::t('Block') ),
629 '$ignore_text' => (($contact['readonly']) ? L10n::t('Unignore') : L10n::t('Ignore') ),
630 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
631 '$info' => $contact['info'],
632 '$cinfo' => ['info', '', $contact['info'], ''],
633 '$blocked' => (($contact['blocked']) ? L10n::t('Currently blocked') : ''),
634 '$ignored' => (($contact['readonly']) ? L10n::t('Currently ignored') : ''),
635 '$archived' => (($contact['archive']) ? L10n::t('Currently archived') : ''),
636 '$pending' => (($contact['pending']) ? L10n::t('Awaiting connection acknowledge') : ''),
637 '$hidden' => ['hidden', L10n::t('Hide this contact from others'), ($contact['hidden'] == 1), L10n::t('Replies/likes to your public posts <strong>may</strong> still be visible')],
638 '$notify' => ['notify', L10n::t('Notification for new posts'), ($contact['notify_new_posts'] == 1), L10n::t('Send a notification of every new post of this contact')],
639 '$fetch_further_information' => $fetch_further_information,
640 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
641 '$ffi_keyword_blacklist' => ['ffi_keyword_blacklist', L10n::t('Blacklisted keywords'), $contact['ffi_keyword_blacklist'], L10n::t('Comma separated list of keywords that should not be converted to hashtags, when "Fetch information and keywords" is selected')],
642 '$photo' => $contact['photo'],
643 '$name' => htmlentities($contact['name']),
644 '$dir_icon' => $dir_icon,
645 '$sparkle' => $sparkle,
647 '$profileurllabel' => L10n::t('Profile URL'),
648 '$profileurl' => $contact['url'],
649 '$account_type' => Contact::getAccountType($contact),
650 '$location' => BBCode::convert($contact["location"]),
651 '$location_label' => L10n::t("Location:"),
652 '$xmpp' => BBCode::convert($contact["xmpp"]),
653 '$xmpp_label' => L10n::t("XMPP:"),
654 '$about' => BBCode::convert($contact["about"], false),
655 '$about_label' => L10n::t("About:"),
656 '$keywords' => $contact["keywords"],
657 '$keywords_label' => L10n::t("Tags:"),
658 '$contact_action_button' => L10n::t("Actions"),
659 '$contact_actions' => $contact_actions,
660 '$contact_status' => L10n::t("Status"),
661 '$contact_settings_label' => L10n::t('Contact Settings'),
662 '$contact_profile_label' => L10n::t("Profile"),
665 $arr = ['contact' => $contact, 'output' => $o];
667 Addon::callHooks('contact_edit', $arr);
669 return $arr['output'];
678 if (($a->argc == 2) && ($a->argv[1] === 'all')) {
681 } elseif (($a->argc == 2) && ($a->argv[1] === 'blocked')) {
682 $sql_extra = " AND `blocked` = 1 ";
684 } elseif (($a->argc == 2) && ($a->argv[1] === 'hidden')) {
685 $sql_extra = " AND `hidden` = 1 ";
687 } elseif (($a->argc == 2) && ($a->argv[1] === 'ignored')) {
688 $sql_extra = " AND `readonly` = 1 ";
690 } elseif (($a->argc == 2) && ($a->argv[1] === 'archived')) {
691 $sql_extra = " AND `archive` = 1 ";
694 $sql_extra = " AND `blocked` = 0 ";
697 $search = x($_GET, 'search') ? notags(trim($_GET['search'])) : '';
698 $nets = x($_GET, 'nets' ) ? notags(trim($_GET['nets'])) : '';
702 'label' => L10n::t('Suggestions'),
705 'title' => L10n::t('Suggest potential friends'),
706 'id' => 'suggestions-tab',
710 'label' => L10n::t('All Contacts'),
711 'url' => 'contacts/all',
712 'sel' => ($all) ? 'active' : '',
713 'title' => L10n::t('Show all contacts'),
714 'id' => 'showall-tab',
718 'label' => L10n::t('Unblocked'),
720 'sel' => ((!$all) && (!$blocked) && (!$hidden) && (!$search) && (!$nets) && (!$ignored) && (!$archived)) ? 'active' : '',
721 'title' => L10n::t('Only show unblocked contacts'),
722 'id' => 'showunblocked-tab',
726 'label' => L10n::t('Blocked'),
727 'url' => 'contacts/blocked',
728 'sel' => ($blocked) ? 'active' : '',
729 'title' => L10n::t('Only show blocked contacts'),
730 'id' => 'showblocked-tab',
734 'label' => L10n::t('Ignored'),
735 'url' => 'contacts/ignored',
736 'sel' => ($ignored) ? 'active' : '',
737 'title' => L10n::t('Only show ignored contacts'),
738 'id' => 'showignored-tab',
742 'label' => L10n::t('Archived'),
743 'url' => 'contacts/archived',
744 'sel' => ($archived) ? 'active' : '',
745 'title' => L10n::t('Only show archived contacts'),
746 'id' => 'showarchived-tab',
750 'label' => L10n::t('Hidden'),
751 'url' => 'contacts/hidden',
752 'sel' => ($hidden) ? 'active' : '',
753 'title' => L10n::t('Only show hidden contacts'),
754 'id' => 'showhidden-tab',
759 $tab_tpl = get_markup_template('common_tabs.tpl');
760 $t = replace_macros($tab_tpl, ['$tabs' => $tabs]);
767 $search_hdr = $search;
768 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
769 $sql_extra .= " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') ";
773 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
776 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : '');
778 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
779 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
780 intval($_SESSION['uid'])
782 if (DBM::is_result($r)) {
783 $a->set_pager_total($r[0]['total']);
784 $total = $r[0]['total'];
787 $sql_extra3 = Widget::unavailableNetworks();
791 $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 ",
792 intval($_SESSION['uid']),
793 intval($a->pager['start']),
794 intval($a->pager['itemspage'])
796 if (DBM::is_result($r)) {
797 foreach ($r as $rr) {
798 $contacts[] = _contact_detail_for_template($rr);
802 $tpl = get_markup_template("contacts-template.tpl");
803 $o .= replace_macros($tpl, [
804 '$baseurl' => System::baseUrl(),
805 '$header' => L10n::t('Contacts') . (($nets) ? ' - ' . ContactSelector::networkToName($nets) : ''),
808 '$search' => $search_hdr,
809 '$desc' => L10n::t('Search your contacts'),
810 '$finding' => $searching ? L10n::t('Results for: %s', $search) : "",
811 '$submit' => L10n::t('Find'),
813 '$contacts' => $contacts,
814 '$contact_drop_confirm' => L10n::t('Do you really want to delete this contact?'),
816 '$batch_actions' => [
817 'contacts_batch_update' => L10n::t('Update'),
818 'contacts_batch_block' => L10n::t('Block') . "/" . L10n::t("Unblock"),
819 "contacts_batch_ignore" => L10n::t('Ignore') . "/" . L10n::t("Unignore"),
820 "contacts_batch_archive" => L10n::t('Archive') . "/" . L10n::t("Unarchive"),
821 "contacts_batch_drop" => L10n::t('Delete'),
823 '$h_batch_actions' => L10n::t('Batch Actions'),
824 '$paginate' => paginate($a),
831 * @brief List of pages for the Contact TabBar
833 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
836 * @param int $contact_id The ID of the contact
837 * @param int $active_tab 1 if tab should be marked as active
841 function contacts_tab($a, $contact_id, $active_tab)
846 'label' => L10n::t('Status'),
847 'url' => "contacts/" . $contact_id . "/posts",
848 'sel' => (($active_tab == 1) ? 'active' : ''),
849 'title' => L10n::t('Status Messages and Posts'),
850 'id' => 'status-tab',
854 'label' => L10n::t('Profile'),
855 'url' => "contacts/" . $contact_id,
856 'sel' => (($active_tab == 2) ? 'active' : ''),
857 'title' => L10n::t('Profile Details'),
858 'id' => 'profile-tab',
863 // Show this tab only if there is visible friend list
864 $x = GContact::countAllFriends(local_user(), $contact_id);
866 $tabs[] = ['label' => L10n::t('Contacts'),
867 'url' => "allfriends/" . $contact_id,
868 'sel' => (($active_tab == 3) ? 'active' : ''),
869 'title' => L10n::t('View all contacts'),
870 'id' => 'allfriends-tab',
874 // Show this tab only if there is visible common friend list
875 $common = GContact::countCommonFriends(local_user(), $contact_id);
877 $tabs[] = ['label' => L10n::t('Common Friends'),
878 'url' => "common/loc/" . local_user() . "/" . $contact_id,
879 'sel' => (($active_tab == 4) ? 'active' : ''),
880 'title' => L10n::t('View all common friends'),
881 'id' => 'common-loc-tab',
886 $tabs[] = ['label' => L10n::t('Advanced'),
887 'url' => 'crepair/' . $contact_id,
888 'sel' => (($active_tab == 5) ? 'active' : ''),
889 'title' => L10n::t('Advanced Contact Settings'),
890 'id' => 'advanced-tab',
894 $tab_tpl = get_markup_template('common_tabs.tpl');
895 $tab_str = replace_macros($tab_tpl, ['$tabs' => $tabs]);
900 function contact_posts($a, $contact_id)
902 $o = contacts_tab($a, $contact_id, 1);
904 $contact = dba::selectFirst('contact', ['url'], ['id' => $contact_id]);
905 if (DBM::is_result($contact)) {
906 $a->page['aside'] = "";
907 Profile::load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
908 $o .= Contact::getPostsFromUrl($contact["url"]);
914 function _contact_detail_for_template($rr)
918 switch ($rr['rel']) {
919 case CONTACT_IS_FRIEND:
920 $dir_icon = 'images/lrarrow.gif';
921 $alt_text = L10n::t('Mutual Friendship');
923 case CONTACT_IS_FOLLOWER;
924 $dir_icon = 'images/larrow.gif';
925 $alt_text = L10n::t('is a fan of yours');
927 case CONTACT_IS_SHARING;
928 $dir_icon = 'images/rarrow.gif';
929 $alt_text = L10n::t('you are a fan of');
934 if (($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
935 $url = "redir/{$rr['id']}";
936 $sparkle = ' class="sparkle" ';
943 'img_hover' => L10n::t('Visit %s\'s profile [%s]', $rr['name'], $rr['url']),
944 'edit_hover' => L10n::t('Edit contact'),
945 'photo_menu' => Contact::photoMenu($rr),
947 'alt_text' => $alt_text,
948 'dir_icon' => $dir_icon,
949 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
950 'name' => htmlentities($rr['name']),
951 'username' => htmlentities($rr['name']),
952 'account_type' => Contact::getAccountType($rr),
953 'sparkle' => $sparkle,
954 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
956 'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
961 * @brief Gives a array with actions which can performed to a given contact
963 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
965 * @param array $contact Data about the Contact
966 * @return array with contact related actions
968 function contact_actions($contact)
970 $poll_enabled = in_array($contact['network'], [NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL]);
971 $contact_actions = [];
973 // Provide friend suggestion only for Friendica contacts
974 if ($contact['network'] === NETWORK_DFRN) {
975 $contact_actions['suggest'] = [
976 'label' => L10n::t('Suggest friends'),
977 'url' => 'fsuggest/' . $contact['id'],
985 $contact_actions['update'] = [
986 'label' => L10n::t('Update now'),
987 'url' => 'contacts/' . $contact['id'] . '/update',
994 $contact_actions['block'] = [
995 'label' => (intval($contact['blocked']) ? L10n::t('Unblock') : L10n::t('Block') ),
996 'url' => 'contacts/' . $contact['id'] . '/block',
997 'title' => L10n::t('Toggle Blocked status'),
998 'sel' => (intval($contact['blocked']) ? 'active' : ''),
999 'id' => 'toggle-block',
1002 $contact_actions['ignore'] = [
1003 'label' => (intval($contact['readonly']) ? L10n::t('Unignore') : L10n::t('Ignore') ),
1004 'url' => 'contacts/' . $contact['id'] . '/ignore',
1005 'title' => L10n::t('Toggle Ignored status'),
1006 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1007 'id' => 'toggle-ignore',
1010 $contact_actions['archive'] = [
1011 'label' => (intval($contact['archive']) ? L10n::t('Unarchive') : L10n::t('Archive') ),
1012 'url' => 'contacts/' . $contact['id'] . '/archive',
1013 'title' => L10n::t('Toggle Archive status'),
1014 'sel' => (intval($contact['archive']) ? 'active' : ''),
1015 'id' => 'toggle-archive',
1018 $contact_actions['delete'] = [
1019 'label' => L10n::t('Delete'),
1020 'url' => 'contacts/' . $contact['id'] . '/drop',
1021 'title' => L10n::t('Delete contact'),
1026 return $contact_actions;