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\Protocol;
14 use Friendica\Core\System;
15 use Friendica\Core\Worker;
16 use Friendica\Database\DBA;
17 use Friendica\Model\Contact;
18 use Friendica\Model\GContact;
19 use Friendica\Model\Group;
20 use Friendica\Model\Profile;
21 use Friendica\Network\Probe;
22 use Friendica\Util\DateTimeFormat;
23 use Friendica\Util\Proxy as ProxyUtils;
24 use Friendica\Core\ACL;
26 function contacts_init(App $a)
32 $nets = defaults($_GET, 'nets', '');
37 if (!x($a->page, 'aside')) {
38 $a->page['aside'] = '';
43 if ((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations']))) {
44 $contact_id = intval($a->argv[1]);
45 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
47 if (!DBA::isResult($contact)) {
48 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => 0]);
51 // Don't display contacts that are about to be deleted
52 if ($contact['network'] == Protocol::PHANTOM) {
57 if (DBA::isResult($contact)) {
58 if ($contact['self']) {
59 if (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])) {
60 goaway('profile/' . $contact['nick']);
62 goaway('profile/' . $contact['nick'] . '?tab=profile');
66 $a->data['contact'] = $contact;
68 if (($a->data['contact']['network'] != "") && ($a->data['contact']['network'] != Protocol::DFRN)) {
69 $networkname = format_network_name($a->data['contact']['network'], $a->data['contact']['url']);
74 /// @TODO Add nice spaces
75 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"), [
76 '$name' => htmlentities($a->data['contact']['name']),
77 '$photo' => $a->data['contact']['photo'],
78 '$url' => Contact::MagicLink($a->data['contact']['url']),
79 '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""),
80 '$network_name' => $networkname,
81 '$network' => L10n::t('Network:'),
82 '$account_type' => Contact::getAccountType($a->data['contact'])
85 $findpeople_widget = '';
87 $networks_widget = '';
90 $networks_widget = Widget::networks('contacts', $nets);
91 if (isset($_GET['add'])) {
92 $follow_widget = Widget::follow($_GET['add']);
94 $follow_widget = Widget::follow();
97 $findpeople_widget = Widget::findPeople();
100 if ($contact['uid'] != 0) {
101 $groups_widget = Group::sidebarWidget('contacts', 'group', 'full', 'everyone', $contact_id);
103 $groups_widget = null;
106 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"), [
107 '$vcard_widget' => $vcard_widget,
108 '$findpeople_widget' => $findpeople_widget,
109 '$follow_widget' => $follow_widget,
110 '$groups_widget' => $groups_widget,
111 '$networks_widget' => $networks_widget
114 $base = System::baseUrl();
115 $tpl = get_markup_template("contacts-head.tpl");
116 $a->page['htmlhead'] .= replace_macros($tpl, [
117 '$baseurl' => System::baseUrl(true),
121 $tpl = get_markup_template("contacts-end.tpl");
122 $a->page['end'] .= replace_macros($tpl, [
123 '$baseurl' => System::baseUrl(true),
128 function contacts_batch_actions(App $a)
130 if (empty($_POST['contact_batch']) || !is_array($_POST['contact_batch'])) {
134 $contacts_id = $_POST['contact_batch'];
136 $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
137 implode(",", $contacts_id),
142 foreach ($orig_records as $orig_record) {
143 $contact_id = $orig_record['id'];
144 if (x($_POST, 'contacts_batch_update')) {
145 _contact_update($contact_id);
148 if (x($_POST, 'contacts_batch_block')) {
149 _contact_block($contact_id);
152 if (x($_POST, 'contacts_batch_ignore')) {
153 _contact_ignore($contact_id);
156 if (x($_POST, 'contacts_batch_archive')) {
157 $r = _contact_archive($contact_id, $orig_record);
162 if (x($_POST, 'contacts_batch_drop')) {
163 _contact_drop($orig_record);
167 if ($count_actions > 0) {
168 info(L10n::tt("%d contact edited.", "%d contacts edited.", $count_actions));
171 if (x($_SESSION, 'return_url')) {
172 goaway('' . $_SESSION['return_url']);
178 function contacts_post(App $a)
184 if ($a->argv[1] === "batch") {
185 contacts_batch_actions($a);
189 $contact_id = intval($a->argv[1]);
194 if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user()])) {
195 notice(L10n::t('Could not access contact record.') . EOL);
197 return; // NOTREACHED
200 Addon::callHooks('contact_edit_post', $_POST);
202 $profile_id = intval(defaults($_POST, 'profile-assign', 0));
204 if (!DBA::exists('profile', ['id' => $profile_id, 'uid' => local_user()])) {
205 notice(L10n::t('Could not locate selected profile.') . EOL);
210 $hidden = intval($_POST['hidden']);
212 $notify = intval($_POST['notify']);
214 $fetch_further_information = intval(defaults($_POST, 'fetch_further_information', 0));
216 $ffi_keyword_blacklist = escape_tags(trim(defaults($_POST, 'ffi_keyword_blacklist', '')));
218 $priority = intval(defaults($_POST, 'poll', 0));
219 if ($priority > 5 || $priority < 0) {
223 $info = escape_tags(trim($_POST['info']));
225 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
226 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
227 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
233 intval($fetch_further_information),
234 DBA::escape($ffi_keyword_blacklist),
238 if (DBA::isResult($r)) {
239 info(L10n::t('Contact updated.') . EOL);
241 notice(L10n::t('Failed to update contact record.') . EOL);
244 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
245 if (DBA::isResult($contact)) {
246 $a->data['contact'] = $contact;
252 /* contact actions */
254 function _contact_update($contact_id)
256 $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
257 if (!DBA::isResult($contact)) {
261 $uid = $contact["uid"];
263 if ($contact["network"] == Protocol::OSTATUS) {
264 $result = Contact::createFromProbe($uid, $contact["url"], false, $contact["network"]);
266 if ($result['success']) {
267 q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d", intval($contact_id));
270 // pull feed and consume it, which should subscribe to the hub.
271 Worker::add(PRIORITY_HIGH, "OnePoll", $contact_id, "force");
275 function _contact_update_profile($contact_id)
277 $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
278 if (!DBA::isResult($contact)) {
282 $uid = $contact["uid"];
284 $data = Probe::uri($contact["url"], "", 0, false);
286 // "Feed" or "Unknown" is mostly a sign of communication problems
287 if ((in_array($data["network"], [Protocol::FEED, Protocol::PHANTOM])) && ($data["network"] != $contact["network"])) {
291 $updatefields = ["name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
292 "poco", "network", "alias"];
295 if ($data["network"] == Protocol::OSTATUS) {
296 $result = Contact::createFromProbe($uid, $data["url"], false);
298 if ($result['success']) {
299 $update["subhub"] = true;
303 foreach ($updatefields AS $field) {
304 if (isset($data[$field]) && ($data[$field] != "")) {
305 $update[$field] = $data[$field];
309 $update["nurl"] = normalise_link($data["url"]);
313 if (isset($data["priority"]) && ($data["priority"] != 0)) {
314 $query = "`priority` = " . intval($data["priority"]);
317 foreach ($update AS $key => $value) {
322 $query .= "`" . $key . "` = '" . DBA::escape($value) . "'";
329 $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
334 // Update the entry in the contact table
335 Contact::updateAvatar($data['photo'], local_user(), $contact_id, true);
337 // Update the entry in the gcontact table
338 GContact::updateFromProbe($data["url"]);
341 function _contact_block($contact_id)
343 $blocked = !Contact::isBlockedByUser($contact_id, local_user());
344 Contact::setBlockedForUser($contact_id, local_user(), $blocked);
347 function _contact_ignore($contact_id)
349 $ignored = !Contact::isIgnoredByUser($contact_id, local_user());
350 Contact::setIgnoredForUser($contact_id, local_user(), $ignored);
353 function _contact_archive($contact_id, $orig_record)
355 $archived = (($orig_record['archive']) ? 0 : 1);
356 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
361 return DBA::isResult($r);
364 function _contact_drop($orig_record)
368 $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
369 WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
370 intval($a->user['uid'])
372 if (!DBA::isResult($r)) {
376 Contact::terminateFriendship($r[0], $orig_record, true);
377 Contact::remove($orig_record['id']);
380 function contacts_content(App $a, $update = 0)
384 Nav::setSelected('contacts');
387 notice(L10n::t('Permission denied.') . EOL);
392 $contact_id = intval($a->argv[1]);
399 $orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'self' => false]);
400 if (!DBA::isResult($orig_record)) {
401 notice(L10n::t('Could not access contact record.') . EOL);
403 return; // NOTREACHED
406 if ($cmd === 'update' && ($orig_record['uid'] != 0)) {
407 _contact_update($contact_id);
408 goaway('contacts/' . $contact_id);
412 if ($cmd === 'updateprofile' && ($orig_record['uid'] != 0)) {
413 _contact_update_profile($contact_id);
414 goaway('crepair/' . $contact_id);
418 if ($cmd === 'block') {
419 _contact_block($contact_id);
421 $blocked = Contact::isBlockedByUser($contact_id, local_user());
422 info(($blocked ? L10n::t('Contact has been blocked') : L10n::t('Contact has been unblocked')) . EOL);
424 goaway('contacts/' . $contact_id);
425 return; // NOTREACHED
428 if ($cmd === 'ignore') {
429 _contact_ignore($contact_id);
431 $ignored = Contact::isIgnoredByUser($contact_id, local_user());
432 info(($ignored ? L10n::t('Contact has been ignored') : L10n::t('Contact has been unignored')) . EOL);
434 goaway('contacts/' . $contact_id);
435 return; // NOTREACHED
438 if ($cmd === 'archive' && ($orig_record['uid'] != 0)) {
439 $r = _contact_archive($contact_id, $orig_record);
441 $archived = (($orig_record['archive']) ? 0 : 1);
442 info((($archived) ? L10n::t('Contact has been archived') : L10n::t('Contact has been unarchived')) . EOL);
445 goaway('contacts/' . $contact_id);
446 return; // NOTREACHED
449 if ($cmd === 'drop' && ($orig_record['uid'] != 0)) {
450 // Check if we should do HTML-based delete confirmation
451 if (x($_REQUEST, 'confirm')) {
452 // <form> can't take arguments in its "action" parameter
453 // so add any arguments as hidden inputs
454 $query = explode_querystring($a->query_string);
456 foreach ($query['args'] as $arg) {
457 if (strpos($arg, 'confirm=') === false) {
458 $arg_parts = explode('=', $arg);
459 $inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]];
463 $a->page['aside'] = '';
465 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), [
466 '$header' => L10n::t('Drop contact'),
467 '$contact' => _contact_detail_for_template($orig_record),
469 '$message' => L10n::t('Do you really want to delete this contact?'),
470 '$extra_inputs' => $inputs,
471 '$confirm' => L10n::t('Yes'),
472 '$confirm_url' => $query['base'],
473 '$confirm_name' => 'confirmed',
474 '$cancel' => L10n::t('Cancel'),
477 // Now check how the user responded to the confirmation query
478 if (x($_REQUEST, 'canceled')) {
479 if (x($_SESSION, 'return_url')) {
480 goaway('' . $_SESSION['return_url']);
486 _contact_drop($orig_record);
487 info(L10n::t('Contact has been removed.') . EOL);
488 if (x($_SESSION, 'return_url')) {
489 goaway('' . $_SESSION['return_url']);
493 return; // NOTREACHED
495 if ($cmd === 'posts') {
496 return contact_posts($a, $contact_id);
498 if ($cmd === 'conversations') {
499 return contact_conversations($a, $contact_id, $update);
503 $_SESSION['return_url'] = $a->query_string;
505 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'), [
510 '$baseurl' => System::baseUrl(true),
512 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), [
513 '$baseurl' => System::baseUrl(true),
516 $contact['blocked'] = Contact::isBlockedByUser($contact['id'], local_user());
517 $contact['readonly'] = Contact::isIgnoredByUser($contact['id'], local_user());
521 switch ($contact['rel']) {
522 case Contact::FRIEND:
523 $dir_icon = 'images/lrarrow.gif';
524 $relation_text = L10n::t('You are mutual friends with %s');
527 case Contact::FOLLOWER;
528 $dir_icon = 'images/larrow.gif';
529 $relation_text = L10n::t('You are sharing with %s');
532 case Contact::SHARING;
533 $dir_icon = 'images/rarrow.gif';
534 $relation_text = L10n::t('%s is sharing with you');
541 if ($contact['uid'] == 0) {
545 if (!in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
549 $relation_text = sprintf($relation_text, htmlentities($contact['name']));
551 $url = Contact::magicLink($contact['url']);
552 if (strpos($url, 'redir/') === 0) {
553 $sparkle = ' class="sparkle" ';
558 $insecure = L10n::t('Private communications are not available for this contact.');
560 $last_update = (($contact['last-update'] <= NULL_DATE) ? L10n::t('Never') : DateTimeFormat::local($contact['last-update'], 'D, j M Y, g:i A'));
562 if ($contact['last-update'] > NULL_DATE) {
563 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? L10n::t("\x28Update was successful\x29") : L10n::t("\x28Update was not successful\x29"));
565 $lblsuggest = (($contact['network'] === Protocol::DFRN) ? L10n::t('Suggest friends') : '');
567 $poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
569 $nettype = L10n::t('Network type: %s', ContactSelector::networkToName($contact['network'], $contact["url"]));
572 $tab_str = contacts_tab($a, $contact, 3);
574 $lost_contact = (($contact['archive'] && $contact['term-date'] > NULL_DATE && $contact['term-date'] < DateTimeFormat::utcNow()) ? L10n::t('Communications lost with this contact!') : '');
576 $fetch_further_information = null;
577 if ($contact['network'] == Protocol::FEED) {
578 $fetch_further_information = [
579 'fetch_further_information',
580 L10n::t('Fetch further information for feeds'),
581 $contact['fetch_further_information'],
582 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."),
583 ['0' => L10n::t('Disabled'),
584 '1' => L10n::t('Fetch information'),
585 '3' => L10n::t('Fetch keywords'),
586 '2' => L10n::t('Fetch information and keywords')
591 $poll_interval = null;
592 if (in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
593 $poll_interval = ContactSelector::pollInterval($contact['priority'], (!$poll_enabled));
596 $profile_select = null;
597 if ($contact['network'] == Protocol::DFRN) {
598 $profile_select = ContactSelector::profileAssign($contact['profile-id'], (($contact['network'] !== Protocol::DFRN) ? true : false));
601 /// @todo Only show the following link with DFRN when the remote version supports it
604 if (in_array($contact['rel'], [Contact::FRIEND, Contact::SHARING])) {
605 if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
606 $follow = System::baseUrl(true) . "/unfollow?url=" . urlencode($contact["url"]);
607 $follow_text = L10n::t("Disconnect/Unfollow");
610 $follow = System::baseUrl(true) . "/follow?url=" . urlencode($contact["url"]);
611 $follow_text = L10n::t("Connect/Follow");
614 // Load contactact related actions like hide, suggest, delete and others
615 $contact_actions = contact_actions($contact);
617 if ($contact['uid'] != 0) {
618 $lbl_vis1 = L10n::t('Profile Visibility');
619 $lbl_info1 = L10n::t('Contact Information / Notes');
620 $contact_settings_label = L10n::t('Contact Settings');
624 $contact_settings_label = null;
627 $tpl = get_markup_template("contact_edit.tpl");
628 $o .= replace_macros($tpl, [
629 '$header' => L10n::t("Contact"),
630 '$tab_str' => $tab_str,
631 '$submit' => L10n::t('Submit'),
632 '$lbl_vis1' => $lbl_vis1,
633 '$lbl_vis2' => L10n::t('Please choose the profile you would like to display to %s when viewing your profile securely.', $contact['name']),
634 '$lbl_info1' => $lbl_info1,
635 '$lbl_info2' => L10n::t('Their personal note'),
636 '$reason' => trim(notags($contact['reason'])),
637 '$infedit' => L10n::t('Edit contact notes'),
638 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
639 '$relation_text' => $relation_text,
640 '$visit' => L10n::t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']),
641 '$blockunblock' => L10n::t('Block/Unblock contact'),
642 '$ignorecont' => L10n::t('Ignore contact'),
643 '$lblcrepair' => L10n::t("Repair URL settings"),
644 '$lblrecent' => L10n::t('View conversations'),
645 '$lblsuggest' => $lblsuggest,
646 '$nettype' => $nettype,
647 '$poll_interval' => $poll_interval,
648 '$poll_enabled' => $poll_enabled,
649 '$lastupdtext' => L10n::t('Last update:'),
650 '$lost_contact' => $lost_contact,
651 '$updpub' => L10n::t('Update public posts'),
652 '$last_update' => $last_update,
653 '$udnow' => L10n::t('Update now'),
654 '$follow' => $follow,
655 '$follow_text' => $follow_text,
656 '$profile_select' => $profile_select,
657 '$contact_id' => $contact['id'],
658 '$block_text' => (($contact['blocked']) ? L10n::t('Unblock') : L10n::t('Block') ),
659 '$ignore_text' => (($contact['readonly']) ? L10n::t('Unignore') : L10n::t('Ignore') ),
660 '$insecure' => (($contact['network'] !== Protocol::DFRN && $contact['network'] !== Protocol::MAIL && $contact['network'] !== Protocol::DIASPORA) ? $insecure : ''),
661 '$info' => $contact['info'],
662 '$cinfo' => ['info', '', $contact['info'], ''],
663 '$blocked' => (($contact['blocked']) ? L10n::t('Currently blocked') : ''),
664 '$ignored' => (($contact['readonly']) ? L10n::t('Currently ignored') : ''),
665 '$archived' => (($contact['archive']) ? L10n::t('Currently archived') : ''),
666 '$pending' => (($contact['pending']) ? L10n::t('Awaiting connection acknowledge') : ''),
667 '$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')],
668 '$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')],
669 '$fetch_further_information' => $fetch_further_information,
670 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
671 '$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')],
672 '$photo' => $contact['photo'],
673 '$name' => htmlentities($contact['name']),
674 '$dir_icon' => $dir_icon,
675 '$sparkle' => $sparkle,
677 '$profileurllabel' => L10n::t('Profile URL'),
678 '$profileurl' => $contact['url'],
679 '$account_type' => Contact::getAccountType($contact),
680 '$location' => BBCode::convert($contact["location"]),
681 '$location_label' => L10n::t("Location:"),
682 '$xmpp' => BBCode::convert($contact["xmpp"]),
683 '$xmpp_label' => L10n::t("XMPP:"),
684 '$about' => BBCode::convert($contact["about"], false),
685 '$about_label' => L10n::t("About:"),
686 '$keywords' => $contact["keywords"],
687 '$keywords_label' => L10n::t("Tags:"),
688 '$contact_action_button' => L10n::t("Actions"),
689 '$contact_actions' => $contact_actions,
690 '$contact_status' => L10n::t("Status"),
691 '$contact_settings_label' => $contact_settings_label,
692 '$contact_profile_label' => L10n::t("Profile"),
695 $arr = ['contact' => $contact, 'output' => $o];
697 Addon::callHooks('contact_edit', $arr);
699 return $arr['output'];
708 if (($a->argc == 2) && ($a->argv[1] === 'all')) {
711 } elseif (($a->argc == 2) && ($a->argv[1] === 'blocked')) {
712 $sql_extra = " AND `blocked` = 1 ";
714 } elseif (($a->argc == 2) && ($a->argv[1] === 'hidden')) {
715 $sql_extra = " AND `hidden` = 1 ";
717 } elseif (($a->argc == 2) && ($a->argv[1] === 'ignored')) {
718 $sql_extra = " AND `readonly` = 1 ";
720 } elseif (($a->argc == 2) && ($a->argv[1] === 'archived')) {
721 $sql_extra = " AND `archive` = 1 ";
724 $sql_extra = " AND `blocked` = 0 ";
727 $sql_extra .= sprintf(" AND `network` != '%s' ", Protocol::PHANTOM);
729 $search = x($_GET, 'search') ? notags(trim($_GET['search'])) : '';
730 $nets = x($_GET, 'nets' ) ? notags(trim($_GET['nets'])) : '';
734 'label' => L10n::t('Suggestions'),
737 'title' => L10n::t('Suggest potential friends'),
738 'id' => 'suggestions-tab',
742 'label' => L10n::t('All Contacts'),
743 'url' => 'contacts/all',
744 'sel' => ($all) ? 'active' : '',
745 'title' => L10n::t('Show all contacts'),
746 'id' => 'showall-tab',
750 'label' => L10n::t('Unblocked'),
752 'sel' => ((!$all) && (!$blocked) && (!$hidden) && (!$search) && (!$nets) && (!$ignored) && (!$archived)) ? 'active' : '',
753 'title' => L10n::t('Only show unblocked contacts'),
754 'id' => 'showunblocked-tab',
758 'label' => L10n::t('Blocked'),
759 'url' => 'contacts/blocked',
760 'sel' => ($blocked) ? 'active' : '',
761 'title' => L10n::t('Only show blocked contacts'),
762 'id' => 'showblocked-tab',
766 'label' => L10n::t('Ignored'),
767 'url' => 'contacts/ignored',
768 'sel' => ($ignored) ? 'active' : '',
769 'title' => L10n::t('Only show ignored contacts'),
770 'id' => 'showignored-tab',
774 'label' => L10n::t('Archived'),
775 'url' => 'contacts/archived',
776 'sel' => ($archived) ? 'active' : '',
777 'title' => L10n::t('Only show archived contacts'),
778 'id' => 'showarchived-tab',
782 'label' => L10n::t('Hidden'),
783 'url' => 'contacts/hidden',
784 'sel' => ($hidden) ? 'active' : '',
785 'title' => L10n::t('Only show hidden contacts'),
786 'id' => 'showhidden-tab',
791 $tab_tpl = get_markup_template('common_tabs.tpl');
792 $t = replace_macros($tab_tpl, ['$tabs' => $tabs]);
799 $search_hdr = $search;
800 $search_txt = DBA::escape(protect_sprintf(preg_quote($search)));
801 $sql_extra .= " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') ";
805 $sql_extra .= sprintf(" AND network = '%s' ", DBA::escape($nets));
808 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= Contact::FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : '');
810 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
811 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
812 intval($_SESSION['uid'])
814 if (DBA::isResult($r)) {
815 $a->set_pager_total($r[0]['total']);
816 $total = $r[0]['total'];
819 $sql_extra3 = Widget::unavailableNetworks();
823 $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 ",
824 intval($_SESSION['uid']),
825 intval($a->pager['start']),
826 intval($a->pager['itemspage'])
828 if (DBA::isResult($r)) {
829 foreach ($r as $rr) {
830 $rr['blocked'] = Contact::isBlockedByUser($rr['id'], local_user());
831 $rr['readonly'] = Contact::isIgnoredByUser($rr['id'], local_user());
832 $contacts[] = _contact_detail_for_template($rr);
836 $tpl = get_markup_template("contacts-template.tpl");
837 $o .= replace_macros($tpl, [
838 '$baseurl' => System::baseUrl(),
839 '$header' => L10n::t('Contacts') . (($nets) ? ' - ' . ContactSelector::networkToName($nets) : ''),
842 '$search' => $search_hdr,
843 '$desc' => L10n::t('Search your contacts'),
844 '$finding' => $searching ? L10n::t('Results for: %s', $search) : "",
845 '$submit' => L10n::t('Find'),
847 '$contacts' => $contacts,
848 '$contact_drop_confirm' => L10n::t('Do you really want to delete this contact?'),
850 '$batch_actions' => [
851 'contacts_batch_update' => L10n::t('Update'),
852 'contacts_batch_block' => L10n::t('Block') . "/" . L10n::t("Unblock"),
853 "contacts_batch_ignore" => L10n::t('Ignore') . "/" . L10n::t("Unignore"),
854 "contacts_batch_archive" => L10n::t('Archive') . "/" . L10n::t("Unarchive"),
855 "contacts_batch_drop" => L10n::t('Delete'),
857 '$h_batch_actions' => L10n::t('Batch Actions'),
858 '$paginate' => paginate($a),
865 * @brief List of pages for the Contact TabBar
867 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
870 * @param array $contact The contact array
871 * @param int $active_tab 1 if tab should be marked as active
875 function contacts_tab($a, $contact, $active_tab)
880 'label' => L10n::t('Status'),
881 'url' => "contacts/" . $contact['id'] . "/conversations",
882 'sel' => (($active_tab == 1) ? 'active' : ''),
883 'title' => L10n::t('Conversations started by this contact'),
884 'id' => 'status-tab',
888 'label' => L10n::t('Posts and Comments'),
889 'url' => "contacts/" . $contact['id'] . "/posts",
890 'sel' => (($active_tab == 2) ? 'active' : ''),
891 'title' => L10n::t('Status Messages and Posts'),
896 'label' => L10n::t('Profile'),
897 'url' => "contacts/" . $contact['id'],
898 'sel' => (($active_tab == 3) ? 'active' : ''),
899 'title' => L10n::t('Profile Details'),
900 'id' => 'profile-tab',
905 // Show this tab only if there is visible friend list
906 $x = GContact::countAllFriends(local_user(), $contact['id']);
908 $tabs[] = ['label' => L10n::t('Contacts'),
909 'url' => "allfriends/" . $contact['id'],
910 'sel' => (($active_tab == 4) ? 'active' : ''),
911 'title' => L10n::t('View all contacts'),
912 'id' => 'allfriends-tab',
916 // Show this tab only if there is visible common friend list
917 $common = GContact::countCommonFriends(local_user(), $contact['id']);
919 $tabs[] = ['label' => L10n::t('Common Friends'),
920 'url' => "common/loc/" . local_user() . "/" . $contact['id'],
921 'sel' => (($active_tab == 5) ? 'active' : ''),
922 'title' => L10n::t('View all common friends'),
923 'id' => 'common-loc-tab',
928 if (!empty($contact['uid'])) {
929 $tabs[] = ['label' => L10n::t('Advanced'),
930 'url' => 'crepair/' . $contact['id'],
931 'sel' => (($active_tab == 6) ? 'active' : ''),
932 'title' => L10n::t('Advanced Contact Settings'),
933 'id' => 'advanced-tab',
938 $tab_tpl = get_markup_template('common_tabs.tpl');
939 $tab_str = replace_macros($tab_tpl, ['$tabs' => $tabs]);
944 function contact_conversations(App $a, $contact_id, $update)
949 // We need the editor here to be able to reshare an item.
953 'allow_location' => $a->user['allow_location'],
954 'default_location' => $a->user['default-location'],
955 'nickname' => $a->user['nickname'],
956 'lockstate' => (is_array($a->user) && (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) || strlen($a->user['deny_cid']) || strlen($a->user['deny_gid'])) ? 'lock' : 'unlock'),
957 'acl' => ACL::getFullSelectorHTML($a->user, true),
959 'visitor' => 'block',
960 'profile_uid' => local_user(),
962 $o = status_editor($a, $x, 0, true);
966 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id]);
969 $o .= contacts_tab($a, $contact, 1);
972 if (DBA::isResult($contact)) {
973 $a->page['aside'] = "";
975 $profiledata = Contact::getDetailsByURL($contact["url"]);
978 if (in_array($profiledata["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
979 $profiledata["remoteconnect"] = System::baseUrl()."/follow?url=".urlencode($profiledata["url"]);
983 Profile::load($a, "", 0, $profiledata, true);
984 $o .= Contact::getPostsFromUrl($contact["url"], true, $update);
990 function contact_posts(App $a, $contact_id)
992 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id]);
994 $o = contacts_tab($a, $contact, 2);
996 if (DBA::isResult($contact)) {
997 $a->page['aside'] = "";
999 $profiledata = Contact::getDetailsByURL($contact["url"]);
1002 if (in_array($profiledata["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
1003 $profiledata["remoteconnect"] = System::baseUrl()."/follow?url=".urlencode($profiledata["url"]);
1007 Profile::load($a, "", 0, $profiledata, true);
1008 $o .= Contact::getPostsFromUrl($contact["url"]);
1014 function _contact_detail_for_template(array $rr)
1019 switch ($rr['rel']) {
1020 case Contact::FRIEND:
1021 $dir_icon = 'images/lrarrow.gif';
1022 $alt_text = L10n::t('Mutual Friendship');
1025 case Contact::FOLLOWER;
1026 $dir_icon = 'images/larrow.gif';
1027 $alt_text = L10n::t('is a fan of yours');
1030 case Contact::SHARING;
1031 $dir_icon = 'images/rarrow.gif';
1032 $alt_text = L10n::t('you are a fan of');
1039 $url = Contact::magicLink($rr['url']);
1041 if (strpos($url, 'redir/') === 0) {
1042 $sparkle = ' class="sparkle" ';
1048 $dir_icon = 'images/larrow.gif';
1049 $alt_text = L10n::t('This is you');
1055 'img_hover' => L10n::t('Visit %s\'s profile [%s]', $rr['name'], $rr['url']),
1056 'edit_hover' => L10n::t('Edit contact'),
1057 'photo_menu' => Contact::photoMenu($rr),
1059 'alt_text' => $alt_text,
1060 'dir_icon' => $dir_icon,
1061 'thumb' => ProxyUtils::proxifyUrl($rr['thumb'], false, ProxyUtils::SIZE_THUMB),
1062 'name' => htmlentities($rr['name']),
1063 'username' => htmlentities($rr['name']),
1064 'account_type' => Contact::getAccountType($rr),
1065 'sparkle' => $sparkle,
1066 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
1068 'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
1069 'nick' => htmlentities($rr['nick']),
1074 * @brief Gives a array with actions which can performed to a given contact
1076 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
1078 * @param array $contact Data about the Contact
1079 * @return array with contact related actions
1081 function contact_actions($contact)
1083 $poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
1084 $contact_actions = [];
1086 // Provide friend suggestion only for Friendica contacts
1087 if ($contact['network'] === Protocol::DFRN) {
1088 $contact_actions['suggest'] = [
1089 'label' => L10n::t('Suggest friends'),
1090 'url' => 'fsuggest/' . $contact['id'],
1097 if ($poll_enabled) {
1098 $contact_actions['update'] = [
1099 'label' => L10n::t('Update now'),
1100 'url' => 'contacts/' . $contact['id'] . '/update',
1107 $contact_actions['block'] = [
1108 'label' => (intval($contact['blocked']) ? L10n::t('Unblock') : L10n::t('Block') ),
1109 'url' => 'contacts/' . $contact['id'] . '/block',
1110 'title' => L10n::t('Toggle Blocked status'),
1111 'sel' => (intval($contact['blocked']) ? 'active' : ''),
1112 'id' => 'toggle-block',
1115 $contact_actions['ignore'] = [
1116 'label' => (intval($contact['readonly']) ? L10n::t('Unignore') : L10n::t('Ignore') ),
1117 'url' => 'contacts/' . $contact['id'] . '/ignore',
1118 'title' => L10n::t('Toggle Ignored status'),
1119 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1120 'id' => 'toggle-ignore',
1123 if ($contact['uid'] != 0) {
1124 $contact_actions['archive'] = [
1125 'label' => (intval($contact['archive']) ? L10n::t('Unarchive') : L10n::t('Archive') ),
1126 'url' => 'contacts/' . $contact['id'] . '/archive',
1127 'title' => L10n::t('Toggle Archive status'),
1128 'sel' => (intval($contact['archive']) ? 'active' : ''),
1129 'id' => 'toggle-archive',
1132 $contact_actions['delete'] = [
1133 'label' => L10n::t('Delete'),
1134 'url' => 'contacts/' . $contact['id'] . '/drop',
1135 'title' => L10n::t('Delete contact'),
1141 return $contact_actions;