3 namespace Friendica\Module;
6 use Friendica\BaseModule;
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;
25 use Friendica\Module\Login;
28 * Manages and show Contacts and their content
30 * @brief manages contacts
32 class Contacts extends BaseModule
34 public static function init()
42 $nets = defaults($_GET, 'nets', '');
47 if (!x($a->page, 'aside')) {
48 $a->page['aside'] = '';
53 if ((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations']))) {
54 $contact_id = intval($a->argv[1]);
55 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
57 if (!DBA::isResult($contact)) {
58 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => 0]);
61 // Don't display contacts that are about to be deleted
62 if ($contact['network'] == Protocol::PHANTOM) {
67 if (DBA::isResult($contact)) {
68 if ($contact['self']) {
69 if (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])) {
70 goaway('profile/' . $contact['nick']);
72 goaway('profile/' . $contact['nick'] . '?tab=profile');
76 $a->data['contact'] = $contact;
78 if (($a->data['contact']['network'] != "") && ($a->data['contact']['network'] != Protocol::DFRN)) {
79 $networkname = format_network_name($a->data['contact']['network'], $a->data['contact']['url']);
84 /// @TODO Add nice spaces
85 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"), [
86 '$name' => htmlentities($a->data['contact']['name']),
87 '$photo' => $a->data['contact']['photo'],
88 '$url' => Contact::MagicLink($a->data['contact']['url']),
89 '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""),
90 '$network_name' => $networkname,
91 '$network' => L10n::t('Network:'),
92 '$account_type' => Contact::getAccountType($a->data['contact'])
95 $findpeople_widget = '';
97 $networks_widget = '';
100 $networks_widget = Widget::networks('contacts', $nets);
101 if (isset($_GET['add'])) {
102 $follow_widget = Widget::follow($_GET['add']);
104 $follow_widget = Widget::follow();
107 $findpeople_widget = Widget::findPeople();
110 if ($contact['uid'] != 0) {
111 $groups_widget = Group::sidebarWidget('contacts', 'group', 'full', 'everyone', $contact_id);
113 $groups_widget = null;
116 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"), [
117 '$vcard_widget' => $vcard_widget,
118 '$findpeople_widget' => $findpeople_widget,
119 '$follow_widget' => $follow_widget,
120 '$groups_widget' => $groups_widget,
121 '$networks_widget' => $networks_widget
124 $base = System::baseUrl();
125 $tpl = get_markup_template("contacts-head.tpl");
126 $a->page['htmlhead'] .= replace_macros($tpl, [
127 '$baseurl' => System::baseUrl(true),
132 private static function contacts_batch_actions(App $a)
134 if (empty($_POST['contact_batch']) || !is_array($_POST['contact_batch'])) {
138 $contacts_id = $_POST['contact_batch'];
140 $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
141 implode(",", $contacts_id),
146 foreach ($orig_records as $orig_record) {
147 $contact_id = $orig_record['id'];
148 if (x($_POST, 'contacts_batch_update')) {
149 self::_contact_update($contact_id);
152 if (x($_POST, 'contacts_batch_block')) {
153 self::_contact_block($contact_id);
156 if (x($_POST, 'contacts_batch_ignore')) {
157 self::_contact_ignore($contact_id);
160 if (x($_POST, 'contacts_batch_archive')) {
161 $r = self::_contact_archive($contact_id, $orig_record);
166 if (x($_POST, 'contacts_batch_drop')) {
167 self::_contact_drop($orig_record);
171 if ($count_actions > 0) {
172 info(L10n::tt("%d contact edited.", "%d contacts edited.", $count_actions));
178 public static function post()
186 if ($a->argv[1] === "batch") {
187 self::contacts_batch_actions($a);
191 $contact_id = intval($a->argv[1]);
196 if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user()])) {
197 notice(L10n::t('Could not access contact record.') . EOL);
199 return; // NOTREACHED
202 Addon::callHooks('contact_edit_post', $_POST);
204 $profile_id = intval(defaults($_POST, 'profile-assign', 0));
206 if (!DBA::exists('profile', ['id' => $profile_id, 'uid' => local_user()])) {
207 notice(L10n::t('Could not locate selected profile.') . EOL);
212 $hidden = intval($_POST['hidden']);
214 $notify = intval($_POST['notify']);
216 $fetch_further_information = intval(defaults($_POST, 'fetch_further_information', 0));
218 $ffi_keyword_blacklist = escape_tags(trim(defaults($_POST, 'ffi_keyword_blacklist', '')));
220 $priority = intval(defaults($_POST, 'poll', 0));
221 if ($priority > 5 || $priority < 0) {
225 $info = escape_tags(trim($_POST['info']));
227 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
228 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
229 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
235 intval($fetch_further_information),
236 DBA::escape($ffi_keyword_blacklist),
240 if (DBA::isResult($r)) {
241 info(L10n::t('Contact updated.') . EOL);
243 notice(L10n::t('Failed to update contact record.') . EOL);
246 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
247 if (DBA::isResult($contact)) {
248 $a->data['contact'] = $contact;
254 /* contact actions */
256 private static function _contact_update($contact_id)
258 $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
259 if (!DBA::isResult($contact)) {
263 $uid = $contact["uid"];
265 if ($contact["network"] == Protocol::OSTATUS) {
266 $result = Contact::createFromProbe($uid, $contact["url"], false, $contact["network"]);
268 if ($result['success']) {
269 q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d", intval($contact_id));
272 // pull feed and consume it, which should subscribe to the hub.
273 Worker::add(PRIORITY_HIGH, "OnePoll", $contact_id, "force");
277 private static function _contact_update_profile($contact_id)
279 $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
280 if (!DBA::isResult($contact)) {
284 $uid = $contact["uid"];
286 $data = Probe::uri($contact["url"], "", 0, false);
288 // "Feed" or "Unknown" is mostly a sign of communication problems
289 if ((in_array($data["network"], [Protocol::FEED, Protocol::PHANTOM])) && ($data["network"] != $contact["network"])) {
293 $updatefields = ["name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
294 "poco", "network", "alias"];
297 if ($data["network"] == Protocol::OSTATUS) {
298 $result = Contact::createFromProbe($uid, $data["url"], false);
300 if ($result['success']) {
301 $update["subhub"] = true;
305 foreach ($updatefields AS $field) {
306 if (isset($data[$field]) && ($data[$field] != "")) {
307 $update[$field] = $data[$field];
311 $update["nurl"] = normalise_link($data["url"]);
315 if (isset($data["priority"]) && ($data["priority"] != 0)) {
316 $query = "`priority` = " . intval($data["priority"]);
319 foreach ($update AS $key => $value) {
324 $query .= "`" . $key . "` = '" . DBA::escape($value) . "'";
331 $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
336 // Update the entry in the contact table
337 Contact::updateAvatar($data['photo'], local_user(), $contact_id, true);
339 // Update the entry in the gcontact table
340 GContact::updateFromProbe($data["url"]);
343 private static function _contact_block($contact_id)
345 $blocked = !Contact::isBlockedByUser($contact_id, local_user());
346 Contact::setBlockedForUser($contact_id, local_user(), $blocked);
349 private static function _contact_ignore($contact_id)
351 $ignored = !Contact::isIgnoredByUser($contact_id, local_user());
352 Contact::setIgnoredForUser($contact_id, local_user(), $ignored);
355 private static function _contact_archive($contact_id, $orig_record)
357 $archived = (($orig_record['archive']) ? 0 : 1);
358 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
363 return DBA::isResult($r);
366 private static function _contact_drop($orig_record)
370 $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
371 WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
372 intval($a->user['uid'])
374 if (!DBA::isResult($r)) {
378 Contact::terminateFriendship($r[0], $orig_record, true);
379 Contact::remove($orig_record['id']);
382 public static function content($update = 0)
387 Nav::setSelected('contacts');
390 notice(L10n::t('Permission denied.') . EOL);
391 return Login::form();
395 $contact_id = intval($a->argv[1]);
402 $orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'self' => false]);
403 if (!DBA::isResult($orig_record)) {
404 notice(L10n::t('Could not access contact record.') . EOL);
406 return; // NOTREACHED
409 if ($cmd === 'update' && ($orig_record['uid'] != 0)) {
410 self::_contact_update($contact_id);
411 goaway('contacts/' . $contact_id);
415 if ($cmd === 'updateprofile' && ($orig_record['uid'] != 0)) {
416 self::_contact_update_profile($contact_id);
417 goaway('crepair/' . $contact_id);
421 if ($cmd === 'block') {
422 self::_contact_block($contact_id);
424 $blocked = Contact::isBlockedByUser($contact_id, local_user());
425 info(($blocked ? L10n::t('Contact has been blocked') : L10n::t('Contact has been unblocked')) . EOL);
427 goaway('contacts/' . $contact_id);
428 return; // NOTREACHED
431 if ($cmd === 'ignore') {
432 self::_contact_ignore($contact_id);
434 $ignored = Contact::isIgnoredByUser($contact_id, local_user());
435 info(($ignored ? L10n::t('Contact has been ignored') : L10n::t('Contact has been unignored')) . EOL);
437 goaway('contacts/' . $contact_id);
438 return; // NOTREACHED
441 if ($cmd === 'archive' && ($orig_record['uid'] != 0)) {
442 $r = self::_contact_archive($contact_id, $orig_record);
444 $archived = (($orig_record['archive']) ? 0 : 1);
445 info((($archived) ? L10n::t('Contact has been archived') : L10n::t('Contact has been unarchived')) . EOL);
448 goaway('contacts/' . $contact_id);
449 return; // NOTREACHED
452 if ($cmd === 'drop' && ($orig_record['uid'] != 0)) {
453 // Check if we should do HTML-based delete confirmation
454 if (x($_REQUEST, 'confirm')) {
455 // <form> can't take arguments in its "action" parameter
456 // so add any arguments as hidden inputs
457 $query = explode_querystring($a->query_string);
459 foreach ($query['args'] as $arg) {
460 if (strpos($arg, 'confirm=') === false) {
461 $arg_parts = explode('=', $arg);
462 $inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]];
466 $a->page['aside'] = '';
468 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), [
469 '$header' => L10n::t('Drop contact'),
470 '$contact' => self::_contact_detail_for_template($orig_record),
472 '$message' => L10n::t('Do you really want to delete this contact?'),
473 '$extra_inputs' => $inputs,
474 '$confirm' => L10n::t('Yes'),
475 '$confirm_url' => $query['base'],
476 '$confirm_name' => 'confirmed',
477 '$cancel' => L10n::t('Cancel'),
480 // Now check how the user responded to the confirmation query
481 if (x($_REQUEST, 'canceled')) {
485 self::_contact_drop($orig_record);
486 info(L10n::t('Contact has been removed.') . EOL);
489 return; // NOTREACHED
491 if ($cmd === 'posts') {
492 return self::contact_posts($a, $contact_id);
494 if ($cmd === 'conversations') {
495 return self::contact_conversations($a, $contact_id, $update);
499 $_SESSION['return_url'] = $a->query_string;
501 if ((x($a->data, 'contact')) && (is_array($a->data['contact']))) {
502 $contact_id = $a->data['contact']['id'];
503 $contact = $a->data['contact'];
505 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), [
506 '$baseurl' => System::baseUrl(true),
509 $contact['blocked'] = Contact::isBlockedByUser($contact['id'], local_user());
510 $contact['readonly'] = Contact::isIgnoredByUser($contact['id'], local_user());
514 switch ($contact['rel']) {
515 case Contact::FRIEND:
516 $dir_icon = 'images/lrarrow.gif';
517 $relation_text = L10n::t('You are mutual friends with %s');
520 case Contact::FOLLOWER;
521 $dir_icon = 'images/larrow.gif';
522 $relation_text = L10n::t('You are sharing with %s');
525 case Contact::SHARING;
526 $dir_icon = 'images/rarrow.gif';
527 $relation_text = L10n::t('%s is sharing with you');
534 if ($contact['uid'] == 0) {
538 if (!in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
542 $relation_text = sprintf($relation_text, htmlentities($contact['name']));
544 $url = Contact::magicLink($contact['url']);
545 if (strpos($url, 'redir/') === 0) {
546 $sparkle = ' class="sparkle" ';
551 $insecure = L10n::t('Private communications are not available for this contact.');
553 $last_update = (($contact['last-update'] <= NULL_DATE) ? L10n::t('Never') : DateTimeFormat::local($contact['last-update'], 'D, j M Y, g:i A'));
555 if ($contact['last-update'] > NULL_DATE) {
556 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? L10n::t("\x28Update was successful\x29") : L10n::t("\x28Update was not successful\x29"));
558 $lblsuggest = (($contact['network'] === Protocol::DFRN) ? L10n::t('Suggest friends') : '');
560 $poll_enabled = in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
562 $nettype = L10n::t('Network type: %s', ContactSelector::networkToName($contact['network'], $contact["url"]));
565 $tab_str = self::contacts_tab($a, $contact, 3);
567 $lost_contact = (($contact['archive'] && $contact['term-date'] > NULL_DATE && $contact['term-date'] < DateTimeFormat::utcNow()) ? L10n::t('Communications lost with this contact!') : '');
569 $fetch_further_information = null;
570 if ($contact['network'] == Protocol::FEED) {
571 $fetch_further_information = [
572 'fetch_further_information',
573 L10n::t('Fetch further information for feeds'),
574 $contact['fetch_further_information'],
575 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."),
576 ['0' => L10n::t('Disabled'),
577 '1' => L10n::t('Fetch information'),
578 '3' => L10n::t('Fetch keywords'),
579 '2' => L10n::t('Fetch information and keywords')
584 $poll_interval = null;
585 if (in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
586 $poll_interval = ContactSelector::pollInterval($contact['priority'], (!$poll_enabled));
589 $profile_select = null;
590 if ($contact['network'] == Protocol::DFRN) {
591 $profile_select = ContactSelector::profileAssign($contact['profile-id'], (($contact['network'] !== Protocol::DFRN) ? true : false));
594 /// @todo Only show the following link with DFRN when the remote version supports it
597 if (in_array($contact['rel'], [Contact::FRIEND, Contact::SHARING])) {
598 if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
599 $follow = System::baseUrl(true) . "/unfollow?url=" . urlencode($contact["url"]);
600 $follow_text = L10n::t("Disconnect/Unfollow");
603 $follow = System::baseUrl(true) . "/follow?url=" . urlencode($contact["url"]);
604 $follow_text = L10n::t("Connect/Follow");
607 // Load contactact related actions like hide, suggest, delete and others
608 $contact_actions = self::contact_actions($contact);
610 if ($contact['uid'] != 0) {
611 $lbl_vis1 = L10n::t('Profile Visibility');
612 $lbl_info1 = L10n::t('Contact Information / Notes');
613 $contact_settings_label = L10n::t('Contact Settings');
617 $contact_settings_label = null;
620 $tpl = get_markup_template("contact_edit.tpl");
621 $o .= replace_macros($tpl, [
622 '$header' => L10n::t("Contact"),
623 '$tab_str' => $tab_str,
624 '$submit' => L10n::t('Submit'),
625 '$lbl_vis1' => $lbl_vis1,
626 '$lbl_vis2' => L10n::t('Please choose the profile you would like to display to %s when viewing your profile securely.', $contact['name']),
627 '$lbl_info1' => $lbl_info1,
628 '$lbl_info2' => L10n::t('Their personal note'),
629 '$reason' => trim(notags($contact['reason'])),
630 '$infedit' => L10n::t('Edit contact notes'),
631 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
632 '$relation_text' => $relation_text,
633 '$visit' => L10n::t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']),
634 '$blockunblock' => L10n::t('Block/Unblock contact'),
635 '$ignorecont' => L10n::t('Ignore contact'),
636 '$lblcrepair' => L10n::t("Repair URL settings"),
637 '$lblrecent' => L10n::t('View conversations'),
638 '$lblsuggest' => $lblsuggest,
639 '$nettype' => $nettype,
640 '$poll_interval' => $poll_interval,
641 '$poll_enabled' => $poll_enabled,
642 '$lastupdtext' => L10n::t('Last update:'),
643 '$lost_contact' => $lost_contact,
644 '$updpub' => L10n::t('Update public posts'),
645 '$last_update' => $last_update,
646 '$udnow' => L10n::t('Update now'),
647 '$follow' => $follow,
648 '$follow_text' => $follow_text,
649 '$profile_select' => $profile_select,
650 '$contact_id' => $contact['id'],
651 '$block_text' => ($contact['blocked'] ? L10n::t('Unblock') : L10n::t('Block')),
652 '$ignore_text' => ($contact['readonly'] ? L10n::t('Unignore') : L10n::t('Ignore')),
653 '$insecure' => (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::MAIL, Protocol::DIASPORA]) ? '' : $insecure),
654 '$info' => $contact['info'],
655 '$cinfo' => ['info', '', $contact['info'], ''],
656 '$blocked' => ($contact['blocked'] ? L10n::t('Currently blocked') : ''),
657 '$ignored' => ($contact['readonly'] ? L10n::t('Currently ignored') : ''),
658 '$archived' => ($contact['archive'] ? L10n::t('Currently archived') : ''),
659 '$pending' => ($contact['pending'] ? L10n::t('Awaiting connection acknowledge') : ''),
660 '$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')],
661 '$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')],
662 '$fetch_further_information' => $fetch_further_information,
663 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
664 '$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')],
665 '$photo' => $contact['photo'],
666 '$name' => htmlentities($contact['name']),
667 '$dir_icon' => $dir_icon,
668 '$sparkle' => $sparkle,
670 '$profileurllabel' => L10n::t('Profile URL'),
671 '$profileurl' => $contact['url'],
672 '$account_type' => Contact::getAccountType($contact),
673 '$location' => BBCode::convert($contact["location"]),
674 '$location_label' => L10n::t("Location:"),
675 '$xmpp' => BBCode::convert($contact["xmpp"]),
676 '$xmpp_label' => L10n::t("XMPP:"),
677 '$about' => BBCode::convert($contact["about"], false),
678 '$about_label' => L10n::t("About:"),
679 '$keywords' => $contact["keywords"],
680 '$keywords_label' => L10n::t("Tags:"),
681 '$contact_action_button' => L10n::t("Actions"),
682 '$contact_actions' => $contact_actions,
683 '$contact_status' => L10n::t("Status"),
684 '$contact_settings_label' => $contact_settings_label,
685 '$contact_profile_label' => L10n::t("Profile"),
688 $arr = ['contact' => $contact, 'output' => $o];
690 Addon::callHooks('contact_edit', $arr);
692 return $arr['output'];
701 if (($a->argc == 2) && ($a->argv[1] === 'all')) {
704 } elseif (($a->argc == 2) && ($a->argv[1] === 'blocked')) {
705 $sql_extra = " AND `blocked` = 1 ";
707 } elseif (($a->argc == 2) && ($a->argv[1] === 'hidden')) {
708 $sql_extra = " AND `hidden` = 1 ";
710 } elseif (($a->argc == 2) && ($a->argv[1] === 'ignored')) {
711 $sql_extra = " AND `readonly` = 1 ";
713 } elseif (($a->argc == 2) && ($a->argv[1] === 'archived')) {
714 $sql_extra = " AND `archive` = 1 ";
717 $sql_extra = " AND `blocked` = 0 ";
720 $sql_extra .= sprintf(" AND `network` != '%s' ", Protocol::PHANTOM);
722 $search = x($_GET, 'search') ? notags(trim($_GET['search'])) : '';
723 $nets = x($_GET, 'nets' ) ? notags(trim($_GET['nets'])) : '';
727 'label' => L10n::t('Suggestions'),
730 'title' => L10n::t('Suggest potential friends'),
731 'id' => 'suggestions-tab',
735 'label' => L10n::t('All Contacts'),
736 'url' => 'contacts/all',
737 'sel' => ($all) ? 'active' : '',
738 'title' => L10n::t('Show all contacts'),
739 'id' => 'showall-tab',
743 'label' => L10n::t('Unblocked'),
745 'sel' => ((!$all) && (!$blocked) && (!$hidden) && (!$search) && (!$nets) && (!$ignored) && (!$archived)) ? 'active' : '',
746 'title' => L10n::t('Only show unblocked contacts'),
747 'id' => 'showunblocked-tab',
751 'label' => L10n::t('Blocked'),
752 'url' => 'contacts/blocked',
753 'sel' => ($blocked) ? 'active' : '',
754 'title' => L10n::t('Only show blocked contacts'),
755 'id' => 'showblocked-tab',
759 'label' => L10n::t('Ignored'),
760 'url' => 'contacts/ignored',
761 'sel' => ($ignored) ? 'active' : '',
762 'title' => L10n::t('Only show ignored contacts'),
763 'id' => 'showignored-tab',
767 'label' => L10n::t('Archived'),
768 'url' => 'contacts/archived',
769 'sel' => ($archived) ? 'active' : '',
770 'title' => L10n::t('Only show archived contacts'),
771 'id' => 'showarchived-tab',
775 'label' => L10n::t('Hidden'),
776 'url' => 'contacts/hidden',
777 'sel' => ($hidden) ? 'active' : '',
778 'title' => L10n::t('Only show hidden contacts'),
779 'id' => 'showhidden-tab',
784 $tab_tpl = get_markup_template('common_tabs.tpl');
785 $t = replace_macros($tab_tpl, ['$tabs' => $tabs]);
792 $search_hdr = $search;
793 $search_txt = DBA::escape(protect_sprintf(preg_quote($search)));
794 $sql_extra .= " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') ";
798 $sql_extra .= sprintf(" AND network = '%s' ", DBA::escape($nets));
801 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= Contact::FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : '');
803 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
804 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
805 intval($_SESSION['uid'])
807 if (DBA::isResult($r)) {
808 $a->setPagerTotal($r[0]['total']);
809 $total = $r[0]['total'];
812 $sql_extra3 = Widget::unavailableNetworks();
816 $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 ",
817 intval($_SESSION['uid']),
818 intval($a->pager['start']),
819 intval($a->pager['itemspage'])
821 if (DBA::isResult($r)) {
822 foreach ($r as $rr) {
823 $rr['blocked'] = Contact::isBlockedByUser($rr['id'], local_user());
824 $rr['readonly'] = Contact::isIgnoredByUser($rr['id'], local_user());
825 $contacts[] = self::_contact_detail_for_template($rr);
829 $tpl = get_markup_template("contacts-template.tpl");
830 $o .= replace_macros($tpl, [
831 '$baseurl' => System::baseUrl(),
832 '$header' => L10n::t('Contacts') . (($nets) ? ' - ' . ContactSelector::networkToName($nets) : ''),
835 '$search' => $search_hdr,
836 '$desc' => L10n::t('Search your contacts'),
837 '$finding' => $searching ? L10n::t('Results for: %s', $search) : "",
838 '$submit' => L10n::t('Find'),
840 '$contacts' => $contacts,
841 '$contact_drop_confirm' => L10n::t('Do you really want to delete this contact?'),
843 '$batch_actions' => [
844 'contacts_batch_update' => L10n::t('Update'),
845 'contacts_batch_block' => L10n::t('Block') . "/" . L10n::t("Unblock"),
846 "contacts_batch_ignore" => L10n::t('Ignore') . "/" . L10n::t("Unignore"),
847 "contacts_batch_archive" => L10n::t('Archive') . "/" . L10n::t("Unarchive"),
848 "contacts_batch_drop" => L10n::t('Delete'),
850 '$h_batch_actions' => L10n::t('Batch Actions'),
851 '$paginate' => paginate($a),
858 * @brief List of pages for the Contact TabBar
860 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
863 * @param array $contact The contact array
864 * @param int $active_tab 1 if tab should be marked as active
868 public static function contacts_tab($a, $contact, $active_tab)
873 'label' => L10n::t('Status'),
874 'url' => "contacts/" . $contact['id'] . "/conversations",
875 'sel' => (($active_tab == 1) ? 'active' : ''),
876 'title' => L10n::t('Conversations started by this contact'),
877 'id' => 'status-tab',
881 'label' => L10n::t('Posts and Comments'),
882 'url' => "contacts/" . $contact['id'] . "/posts",
883 'sel' => (($active_tab == 2) ? 'active' : ''),
884 'title' => L10n::t('Status Messages and Posts'),
889 'label' => L10n::t('Profile'),
890 'url' => "contacts/" . $contact['id'],
891 'sel' => (($active_tab == 3) ? 'active' : ''),
892 'title' => L10n::t('Profile Details'),
893 'id' => 'profile-tab',
898 // Show this tab only if there is visible friend list
899 $x = GContact::countAllFriends(local_user(), $contact['id']);
901 $tabs[] = ['label' => L10n::t('Contacts'),
902 'url' => "allfriends/" . $contact['id'],
903 'sel' => (($active_tab == 4) ? 'active' : ''),
904 'title' => L10n::t('View all contacts'),
905 'id' => 'allfriends-tab',
909 // Show this tab only if there is visible common friend list
910 $common = GContact::countCommonFriends(local_user(), $contact['id']);
912 $tabs[] = ['label' => L10n::t('Common Friends'),
913 'url' => "common/loc/" . local_user() . "/" . $contact['id'],
914 'sel' => (($active_tab == 5) ? 'active' : ''),
915 'title' => L10n::t('View all common friends'),
916 'id' => 'common-loc-tab',
921 if (!empty($contact['uid'])) {
922 $tabs[] = ['label' => L10n::t('Advanced'),
923 'url' => 'crepair/' . $contact['id'],
924 'sel' => (($active_tab == 6) ? 'active' : ''),
925 'title' => L10n::t('Advanced Contact Settings'),
926 'id' => 'advanced-tab',
931 $tab_tpl = get_markup_template('common_tabs.tpl');
932 $tab_str = replace_macros($tab_tpl, ['$tabs' => $tabs]);
937 private static function contact_conversations($a, $contact_id, $update)
942 // We need the editor here to be able to reshare an item.
946 'allow_location' => $a->user['allow_location'],
947 'default_location' => $a->user['default-location'],
948 'nickname' => $a->user['nickname'],
949 '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'),
950 'acl' => ACL::getFullSelectorHTML($a->user, true),
952 'visitor' => 'block',
953 'profile_uid' => local_user(),
955 $o = status_editor($a, $x, 0, true);
959 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id]);
962 $o .= self::contacts_tab($a, $contact, 1);
965 if (DBA::isResult($contact)) {
966 $a->page['aside'] = "";
968 $profiledata = Contact::getDetailsByURL($contact["url"]);
971 if (in_array($profiledata["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
972 $profiledata["remoteconnect"] = System::baseUrl()."/follow?url=".urlencode($profiledata["url"]);
976 Profile::load($a, "", 0, $profiledata, true);
977 $o .= Contact::getPostsFromUrl($contact["url"], true, $update);
983 private static function contact_posts($a, $contact_id)
985 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id]);
987 $o = self::contacts_tab($a, $contact, 2);
989 if (DBA::isResult($contact)) {
990 $a->page['aside'] = "";
992 $profiledata = Contact::getDetailsByURL($contact["url"]);
995 if (in_array($profiledata["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
996 $profiledata["remoteconnect"] = System::baseUrl()."/follow?url=".urlencode($profiledata["url"]);
1000 Profile::load($a, "", 0, $profiledata, true);
1001 $o .= Contact::getPostsFromUrl($contact["url"]);
1007 public static function _contact_detail_for_template(array $rr)
1012 switch ($rr['rel']) {
1013 case Contact::FRIEND:
1014 $dir_icon = 'images/lrarrow.gif';
1015 $alt_text = L10n::t('Mutual Friendship');
1018 case Contact::FOLLOWER;
1019 $dir_icon = 'images/larrow.gif';
1020 $alt_text = L10n::t('is a fan of yours');
1023 case Contact::SHARING;
1024 $dir_icon = 'images/rarrow.gif';
1025 $alt_text = L10n::t('you are a fan of');
1032 $url = Contact::magicLink($rr['url']);
1034 if (strpos($url, 'redir/') === 0) {
1035 $sparkle = ' class="sparkle" ';
1041 $dir_icon = 'images/larrow.gif';
1042 $alt_text = L10n::t('This is you');
1048 'img_hover' => L10n::t('Visit %s\'s profile [%s]', $rr['name'], $rr['url']),
1049 'edit_hover' => L10n::t('Edit contact'),
1050 'photo_menu' => Contact::photoMenu($rr),
1052 'alt_text' => $alt_text,
1053 'dir_icon' => $dir_icon,
1054 'thumb' => ProxyUtils::proxifyUrl($rr['thumb'], false, ProxyUtils::SIZE_THUMB),
1055 'name' => htmlentities($rr['name']),
1056 'username' => htmlentities($rr['name']),
1057 'account_type' => Contact::getAccountType($rr),
1058 'sparkle' => $sparkle,
1059 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
1061 'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
1062 'nick' => htmlentities($rr['nick']),
1067 * @brief Gives a array with actions which can performed to a given contact
1069 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
1071 * @param array $contact Data about the Contact
1072 * @return array with contact related actions
1074 private static function contact_actions($contact)
1076 $poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
1077 $contact_actions = [];
1079 // Provide friend suggestion only for Friendica contacts
1080 if ($contact['network'] === Protocol::DFRN) {
1081 $contact_actions['suggest'] = [
1082 'label' => L10n::t('Suggest friends'),
1083 'url' => 'fsuggest/' . $contact['id'],
1090 if ($poll_enabled) {
1091 $contact_actions['update'] = [
1092 'label' => L10n::t('Update now'),
1093 'url' => 'contacts/' . $contact['id'] . '/update',
1100 $contact_actions['block'] = [
1101 'label' => (intval($contact['blocked']) ? L10n::t('Unblock') : L10n::t('Block')),
1102 'url' => 'contacts/' . $contact['id'] . '/block',
1103 'title' => L10n::t('Toggle Blocked status'),
1104 'sel' => (intval($contact['blocked']) ? 'active' : ''),
1105 'id' => 'toggle-block',
1108 $contact_actions['ignore'] = [
1109 'label' => (intval($contact['readonly']) ? L10n::t('Unignore') : L10n::t('Ignore')),
1110 'url' => 'contacts/' . $contact['id'] . '/ignore',
1111 'title' => L10n::t('Toggle Ignored status'),
1112 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1113 'id' => 'toggle-ignore',
1116 if ($contact['uid'] != 0) {
1117 $contact_actions['archive'] = [
1118 'label' => (intval($contact['archive']) ? L10n::t('Unarchive') : L10n::t('Archive')),
1119 'url' => 'contacts/' . $contact['id'] . '/archive',
1120 'title' => L10n::t('Toggle Archive status'),
1121 'sel' => (intval($contact['archive']) ? 'active' : ''),
1122 'id' => 'toggle-archive',
1125 $contact_actions['delete'] = [
1126 'label' => L10n::t('Delete'),
1127 'url' => 'contacts/' . $contact['id'] . '/drop',
1128 'title' => L10n::t('Delete contact'),
1134 return $contact_actions;