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;
18 use Friendica\Network\Probe;
19 use Friendica\Util\DateTimeFormat;
20 use Friendica\Util\Proxy as ProxyUtils;
21 use Friendica\Core\ACL;
22 use Friendica\Module\Login;
25 * Manages and show Contacts and their content
27 * @brief manages contacts
29 class Contact extends BaseModule
31 public static function init()
39 $nets = defaults($_GET, 'nets', '');
44 if (!x($a->page, 'aside')) {
45 $a->page['aside'] = '';
50 if ((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations']))) {
51 $contact_id = intval($a->argv[1]);
52 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
54 if (!DBA::isResult($contact)) {
55 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => 0]);
58 // Don't display contacts that are about to be deleted
59 if ($contact['network'] == Protocol::PHANTOM) {
64 if (DBA::isResult($contact)) {
65 if ($contact['self']) {
66 if (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])) {
67 goaway('profile/' . $contact['nick']);
69 goaway('profile/' . $contact['nick'] . '?tab=profile');
73 $a->data['contact'] = $contact;
75 if (($a->data['contact']['network'] != "") && ($a->data['contact']['network'] != Protocol::DFRN)) {
76 $networkname = format_network_name($a->data['contact']['network'], $a->data['contact']['url']);
81 /// @TODO Add nice spaces
82 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"), [
83 '$name' => htmlentities($a->data['contact']['name']),
84 '$photo' => $a->data['contact']['photo'],
85 '$url' => Model\Contact::MagicLink($a->data['contact']['url']),
86 '$addr' => defaults($contact, 'addr', ''),
87 '$network_name' => $networkname,
88 '$network' => L10n::t('Network:'),
89 '$account_type' => Model\Contact::getAccountType($a->data['contact'])
92 $findpeople_widget = '';
94 $networks_widget = '';
97 $networks_widget = Widget::networks('contact', $nets);
98 if (isset($_GET['add'])) {
99 $follow_widget = Widget::follow($_GET['add']);
101 $follow_widget = Widget::follow();
104 $findpeople_widget = Widget::findPeople();
107 if ($contact['uid'] != 0) {
108 $groups_widget = Model\Group::sidebarWidget('contact', 'group', 'full', 'everyone', $contact_id);
110 $groups_widget = null;
113 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"), [
114 '$vcard_widget' => $vcard_widget,
115 '$findpeople_widget' => $findpeople_widget,
116 '$follow_widget' => $follow_widget,
117 '$groups_widget' => $groups_widget,
118 '$networks_widget' => $networks_widget
121 $base = $a->getBaseURL();
122 $tpl = get_markup_template("contacts-head.tpl");
123 $a->page['htmlhead'] .= replace_macros($tpl, [
124 '$baseurl' => System::baseUrl(true),
129 private static function batchActions(App $a)
131 if (empty($_POST['contact_batch']) || !is_array($_POST['contact_batch'])) {
135 $contacts_id = $_POST['contact_batch'];
137 $stmt = DBA::select('contact', ['id'], ['id' => $contacts_id, 'uid' => local_user(), 'self' => false]);
138 $orig_records = DBA::toArray($stmt);
141 foreach ($orig_records as $orig_record) {
142 $contact_id = $orig_record['id'];
143 if (!empty($_POST['contacts_batch_update'])) {
144 self::updateContactFromPoll($contact_id);
147 if (!empty($_POST['contacts_batch_block'])) {
148 self::blockContact($contact_id);
151 if (!empty($_POST['contacts_batch_ignore'])) {
152 self::ignoreContact($contact_id);
155 if (!empty($_POST['contacts_batch_archive'])
156 && self::archiveContact($contact_id, $orig_record)
160 if (!empty($_POST['contacts_batch_drop'])) {
161 self::dropContact($orig_record);
165 if ($count_actions > 0) {
166 info(L10n::tt("%d contact edited.", "%d contacts edited.", $count_actions));
172 public static function post()
180 if ($a->argv[1] === "batch") {
181 self::batchActions($a);
185 $contact_id = intval($a->argv[1]);
190 if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user()])) {
191 notice(L10n::t('Could not access contact record.') . EOL);
193 return; // NOTREACHED
196 Addon::callHooks('contact_edit_post', $_POST);
198 $profile_id = intval(defaults($_POST, 'profile-assign', 0));
200 if (!DBA::exists('profile', ['id' => $profile_id, 'uid' => local_user()])) {
201 notice(L10n::t('Could not locate selected profile.') . EOL);
206 $hidden = !empty($_POST['hidden']);
208 $notify = !empty($_POST['notify']);
210 $fetch_further_information = intval(defaults($_POST, 'fetch_further_information', 0));
212 $ffi_keyword_blacklist = escape_tags(trim(defaults($_POST, 'ffi_keyword_blacklist', '')));
214 $priority = intval(defaults($_POST, 'poll', 0));
215 if ($priority > 5 || $priority < 0) {
219 $info = escape_tags(trim($_POST['info']));
221 $r = DBA::update('contact',
222 ['profile-id' => $profile_id,
223 'priority' => $priority,
226 'notify_new_posts' => $notify,
227 'fetch_further_information' => $fetch_further_information,
228 'ffi_keyword_blacklist' => $ffi_keyword_blacklist],
229 ['id' => $contact_id, 'uid' => local_user()]);
231 if (DBA::isResult($r)) {
232 info(L10n::t('Contact updated.') . EOL);
234 notice(L10n::t('Failed to update contact record.') . EOL);
237 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
238 if (DBA::isResult($contact)) {
239 $a->data['contact'] = $contact;
245 /* contact actions */
247 private static function updateContactFromPoll($contact_id)
249 $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
250 if (!DBA::isResult($contact)) {
254 $uid = $contact["uid"];
256 if ($contact["network"] == Protocol::OSTATUS) {
257 $result = Model\Contact::createFromProbe($uid, $contact["url"], false, $contact["network"]);
259 if ($result['success']) {
260 DBA::update('contact', ['subhub' => 1], ['id' => $contact_id]);
263 // pull feed and consume it, which should subscribe to the hub.
264 Worker::add(PRIORITY_HIGH, "OnePoll", $contact_id, "force");
268 private static function updateContactFromProbe($contact_id)
270 $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
271 if (!DBA::isResult($contact)) {
275 $uid = $contact["uid"];
277 $data = Probe::uri($contact["url"], "", 0, false);
279 // "Feed" or "Unknown" is mostly a sign of communication problems
280 if ((in_array($data["network"], [Protocol::FEED, Protocol::PHANTOM])) && ($data["network"] != $contact["network"])) {
284 $updatefields = ["name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
285 "poco", "network", "alias"];
288 if ($data["network"] == Protocol::OSTATUS) {
289 $result = Model\Contact::createFromProbe($uid, $data["url"], false);
291 if ($result['success']) {
292 $update["subhub"] = true;
296 foreach ($updatefields AS $field) {
297 if (isset($data[$field]) && ($data[$field] != "")) {
298 $update[$field] = $data[$field];
302 $update["nurl"] = normalise_link($data["url"]);
306 if (isset($data["priority"]) && ($data["priority"] != 0)) {
307 $query = "'priority' => '" . intval($data["priority"]) . "'";
310 foreach ($update AS $key => $value) {
315 $query .= "'" . $key . "' => '" . DBA::escape($value) . "'";
322 $r = DBA::update('contact', $query, ['id' => $contact_id, 'uid' => local_user()]);
324 // Update the entry in the contact table
325 Model\Contact::updateAvatar($data['photo'], local_user(), $contact_id, true);
327 // Update the entry in the gcontact table
328 Model\GContact::updateFromProbe($data["url"]);
331 private static function blockContact($contact_id)
333 $blocked = !Model\Contact::isBlockedByUser($contact_id, local_user());
334 Model\Contact::setBlockedForUser($contact_id, local_user(), $blocked);
337 private static function ignoreContact($contact_id)
339 $ignored = !Model\Contact::isIgnoredByUser($contact_id, local_user());
340 Model\Contact::setIgnoredForUser($contact_id, local_user(), $ignored);
343 private static function archiveContact($contact_id, $orig_record)
345 $archived = (($orig_record['archive']) ? 0 : 1);
346 $r = DBA::update('contact', ['archive' => $archived], ['id' => $contact_id, 'uid' => local_user()]);
348 return DBA::isResult($r);
351 private static function dropContact($orig_record)
355 $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
356 WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
357 intval($a->user['uid'])
359 if (!DBA::isResult($r)) {
363 Model\Contact::terminateFriendship($r[0], $orig_record, true);
364 Model\Contact::remove($orig_record['id']);
367 public static function content($update = 0)
372 Nav::setSelected('contact');
375 notice(L10n::t('Permission denied.') . EOL);
376 return Login::form();
380 $contact_id = intval($a->argv[1]);
387 $orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'self' => false]);
388 if (!DBA::isResult($orig_record)) {
389 notice(L10n::t('Could not access contact record.') . EOL);
391 return; // NOTREACHED
394 if ($cmd === 'update' && ($orig_record['uid'] != 0)) {
395 self::updateContactFromPoll($contact_id);
396 goaway('contact/' . $contact_id);
400 if ($cmd === 'updateprofile' && ($orig_record['uid'] != 0)) {
401 self::updateContactFromProbe($contact_id);
402 goaway('crepair/' . $contact_id);
406 if ($cmd === 'block') {
407 self::blockContact($contact_id);
409 $blocked = Model\Contact::isBlockedByUser($contact_id, local_user());
410 info(($blocked ? L10n::t('Contact has been blocked') : L10n::t('Contact has been unblocked')) . EOL);
412 goaway('contact/' . $contact_id);
413 return; // NOTREACHED
416 if ($cmd === 'ignore') {
417 self::ignoreContact($contact_id);
419 $ignored = Model\Contact::isIgnoredByUser($contact_id, local_user());
420 info(($ignored ? L10n::t('Contact has been ignored') : L10n::t('Contact has been unignored')) . EOL);
422 goaway('contact/' . $contact_id);
423 return; // NOTREACHED
426 if ($cmd === 'archive' && ($orig_record['uid'] != 0)) {
427 $r = self::archiveContact($contact_id, $orig_record);
429 $archived = (($orig_record['archive']) ? 0 : 1);
430 info((($archived) ? L10n::t('Contact has been archived') : L10n::t('Contact has been unarchived')) . EOL);
433 goaway('contact/' . $contact_id);
434 return; // NOTREACHED
437 if ($cmd === 'drop' && ($orig_record['uid'] != 0)) {
438 // Check if we should do HTML-based delete confirmation
439 if (!empty($_REQUEST['confirm'])) {
440 // <form> can't take arguments in its 'action' parameter
441 // so add any arguments as hidden inputs
442 $query = explode_querystring($a->query_string);
444 foreach ($query['args'] as $arg) {
445 if (strpos($arg, 'confirm=') === false) {
446 $arg_parts = explode('=', $arg);
447 $inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]];
451 $a->page['aside'] = '';
453 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), [
454 '$header' => L10n::t('Drop contact'),
455 '$contact' => self::getContactTemplateVars($orig_record),
457 '$message' => L10n::t('Do you really want to delete this contact?'),
458 '$extra_inputs' => $inputs,
459 '$confirm' => L10n::t('Yes'),
460 '$confirm_url' => $query['base'],
461 '$confirm_name' => 'confirmed',
462 '$cancel' => L10n::t('Cancel'),
465 // Now check how the user responded to the confirmation query
466 if (!empty($_REQUEST['canceled'])) {
470 self::dropContact($orig_record);
471 info(L10n::t('Contact has been removed.') . EOL);
474 return; // NOTREACHED
476 if ($cmd === 'posts') {
477 return self::getPostsHTML($a, $contact_id);
479 if ($cmd === 'conversations') {
480 return self::getConversationsHMTL($a, $contact_id, $update);
484 $_SESSION['return_url'] = $a->query_string;
486 if (!empty($a->data['contact']) && is_array($a->data['contact'])) {
487 $contact_id = $a->data['contact']['id'];
488 $contact = $a->data['contact'];
490 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), [
491 '$baseurl' => $a->getBaseURL(true),
494 $contact['blocked'] = Model\Contact::isBlockedByUser($contact['id'], local_user());
495 $contact['readonly'] = Model\Contact::isIgnoredByUser($contact['id'], local_user());
499 switch ($contact['rel']) {
500 case Model\Contact::FRIEND:
501 $dir_icon = 'images/lrarrow.gif';
502 $relation_text = L10n::t('You are mutual friends with %s');
505 case Model\Contact::FOLLOWER;
506 $dir_icon = 'images/larrow.gif';
507 $relation_text = L10n::t('You are sharing with %s');
510 case Model\Contact::SHARING;
511 $dir_icon = 'images/rarrow.gif';
512 $relation_text = L10n::t('%s is sharing with you');
519 if ($contact['uid'] == 0) {
523 if (!in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
527 $relation_text = sprintf($relation_text, htmlentities($contact['name']));
529 $url = Model\Contact::magicLink($contact['url']);
530 if (strpos($url, 'redir/') === 0) {
531 $sparkle = ' class="sparkle" ';
536 $insecure = L10n::t('Private communications are not available for this contact.');
538 $last_update = (($contact['last-update'] <= NULL_DATE) ? L10n::t('Never') : DateTimeFormat::local($contact['last-update'], 'D, j M Y, g:i A'));
540 if ($contact['last-update'] > NULL_DATE) {
541 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? L10n::t("\x28Update was successful\x29") : L10n::t("\x28Update was not successful\x29"));
543 $lblsuggest = (($contact['network'] === Protocol::DFRN) ? L10n::t('Suggest friends') : '');
545 $poll_enabled = in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
547 $nettype = L10n::t('Network type: %s', ContactSelector::networkToName($contact['network'], $contact["url"]));
550 $tab_str = self::getTabsHTML($a, $contact, 3);
552 $lost_contact = (($contact['archive'] && $contact['term-date'] > NULL_DATE && $contact['term-date'] < DateTimeFormat::utcNow()) ? L10n::t('Communications lost with this contact!') : '');
554 $fetch_further_information = null;
555 if ($contact['network'] == Protocol::FEED) {
556 $fetch_further_information = [
557 'fetch_further_information',
558 L10n::t('Fetch further information for feeds'),
559 $contact['fetch_further_information'],
560 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."),
561 ['0' => L10n::t('Disabled'),
562 '1' => L10n::t('Fetch information'),
563 '3' => L10n::t('Fetch keywords'),
564 '2' => L10n::t('Fetch information and keywords')
569 $poll_interval = null;
570 if (in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
571 $poll_interval = ContactSelector::pollInterval($contact['priority'], (!$poll_enabled));
574 $profile_select = null;
575 if ($contact['network'] == Protocol::DFRN) {
576 $profile_select = ContactSelector::profileAssign($contact['profile-id'], (($contact['network'] !== Protocol::DFRN) ? true : false));
579 /// @todo Only show the following link with DFRN when the remote version supports it
582 if (in_array($contact['rel'], [Model\Contact::FRIEND, Model\Contact::SHARING])) {
583 if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
584 $follow = $a->getBaseURL(true) . "/unfollow?url=" . urlencode($contact["url"]);
585 $follow_text = L10n::t("Disconnect/Unfollow");
588 $follow = $a->getBaseURL(true) . "/follow?url=" . urlencode($contact["url"]);
589 $follow_text = L10n::t("Connect/Follow");
592 // Load contactact related actions like hide, suggest, delete and others
593 $contact_actions = self::getContactActions($contact);
595 if ($contact['uid'] != 0) {
596 $lbl_vis1 = L10n::t('Profile Visibility');
597 $lbl_info1 = L10n::t('Contact Information / Notes');
598 $contact_settings_label = L10n::t('Contact Settings');
602 $contact_settings_label = null;
605 $tpl = get_markup_template("contact_edit.tpl");
606 $o .= replace_macros($tpl, [
607 '$header' => L10n::t("Contact"),
608 '$tab_str' => $tab_str,
609 '$submit' => L10n::t('Submit'),
610 '$lbl_vis1' => $lbl_vis1,
611 '$lbl_vis2' => L10n::t('Please choose the profile you would like to display to %s when viewing your profile securely.', $contact['name']),
612 '$lbl_info1' => $lbl_info1,
613 '$lbl_info2' => L10n::t('Their personal note'),
614 '$reason' => trim(notags($contact['reason'])),
615 '$infedit' => L10n::t('Edit contact notes'),
616 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
617 '$relation_text' => $relation_text,
618 '$visit' => L10n::t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']),
619 '$blockunblock' => L10n::t('Block/Unblock contact'),
620 '$ignorecont' => L10n::t('Ignore contact'),
621 '$lblcrepair' => L10n::t("Repair URL settings"),
622 '$lblrecent' => L10n::t('View conversations'),
623 '$lblsuggest' => $lblsuggest,
624 '$nettype' => $nettype,
625 '$poll_interval' => $poll_interval,
626 '$poll_enabled' => $poll_enabled,
627 '$lastupdtext' => L10n::t('Last update:'),
628 '$lost_contact' => $lost_contact,
629 '$updpub' => L10n::t('Update public posts'),
630 '$last_update' => $last_update,
631 '$udnow' => L10n::t('Update now'),
632 '$follow' => $follow,
633 '$follow_text' => $follow_text,
634 '$profile_select' => $profile_select,
635 '$contact_id' => $contact['id'],
636 '$block_text' => ($contact['blocked'] ? L10n::t('Unblock') : L10n::t('Block')),
637 '$ignore_text' => ($contact['readonly'] ? L10n::t('Unignore') : L10n::t('Ignore')),
638 '$insecure' => (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::MAIL, Protocol::DIASPORA]) ? '' : $insecure),
639 '$info' => $contact['info'],
640 '$cinfo' => ['info', '', $contact['info'], ''],
641 '$blocked' => ($contact['blocked'] ? L10n::t('Currently blocked') : ''),
642 '$ignored' => ($contact['readonly'] ? L10n::t('Currently ignored') : ''),
643 '$archived' => ($contact['archive'] ? L10n::t('Currently archived') : ''),
644 '$pending' => ($contact['pending'] ? L10n::t('Awaiting connection acknowledge') : ''),
645 '$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')],
646 '$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')],
647 '$fetch_further_information' => $fetch_further_information,
648 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
649 '$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')],
650 '$photo' => $contact['photo'],
651 '$name' => htmlentities($contact['name']),
652 '$dir_icon' => $dir_icon,
653 '$sparkle' => $sparkle,
655 '$profileurllabel' => L10n::t('Profile URL'),
656 '$profileurl' => $contact['url'],
657 '$account_type' => Model\Contact::getAccountType($contact),
658 '$location' => BBCode::convert($contact["location"]),
659 '$location_label' => L10n::t("Location:"),
660 '$xmpp' => BBCode::convert($contact["xmpp"]),
661 '$xmpp_label' => L10n::t("XMPP:"),
662 '$about' => BBCode::convert($contact["about"], false),
663 '$about_label' => L10n::t("About:"),
664 '$keywords' => $contact["keywords"],
665 '$keywords_label' => L10n::t("Tags:"),
666 '$contact_action_button' => L10n::t("Actions"),
667 '$contact_actions' => $contact_actions,
668 '$contact_status' => L10n::t("Status"),
669 '$contact_settings_label' => $contact_settings_label,
670 '$contact_profile_label' => L10n::t("Profile"),
673 $arr = ['contact' => $contact, 'output' => $o];
675 Addon::callHooks('contact_edit', $arr);
677 return $arr['output'];
686 if (($a->argc == 2) && ($a->argv[1] === 'all')) {
689 } elseif (($a->argc == 2) && ($a->argv[1] === 'blocked')) {
690 $sql_extra = " AND `blocked` = 1 ";
692 } elseif (($a->argc == 2) && ($a->argv[1] === 'hidden')) {
693 $sql_extra = " AND `hidden` = 1 ";
695 } elseif (($a->argc == 2) && ($a->argv[1] === 'ignored')) {
696 $sql_extra = " AND `readonly` = 1 ";
698 } elseif (($a->argc == 2) && ($a->argv[1] === 'archived')) {
699 $sql_extra = " AND `archive` = 1 ";
702 $sql_extra = " AND `blocked` = 0 ";
705 $sql_extra .= sprintf(" AND `network` != '%s' ", Protocol::PHANTOM);
707 $search = notags(trim(defaults($_GET, 'search', '')));
708 $nets = notags(trim(defaults($_GET, 'nets' , '')));
712 'label' => L10n::t('Suggestions'),
715 'title' => L10n::t('Suggest potential friends'),
716 'id' => 'suggestions-tab',
720 'label' => L10n::t('All Contacts'),
721 'url' => 'contact/all',
722 'sel' => ($all) ? 'active' : '',
723 'title' => L10n::t('Show all contacts'),
724 'id' => 'showall-tab',
728 'label' => L10n::t('Unblocked'),
730 'sel' => ((!$all) && (!$blocked) && (!$hidden) && (!$search) && (!$nets) && (!$ignored) && (!$archived)) ? 'active' : '',
731 'title' => L10n::t('Only show unblocked contacts'),
732 'id' => 'showunblocked-tab',
736 'label' => L10n::t('Blocked'),
737 'url' => 'contact/blocked',
738 'sel' => ($blocked) ? 'active' : '',
739 'title' => L10n::t('Only show blocked contacts'),
740 'id' => 'showblocked-tab',
744 'label' => L10n::t('Ignored'),
745 'url' => 'contact/ignored',
746 'sel' => ($ignored) ? 'active' : '',
747 'title' => L10n::t('Only show ignored contacts'),
748 'id' => 'showignored-tab',
752 'label' => L10n::t('Archived'),
753 'url' => 'contact/archived',
754 'sel' => ($archived) ? 'active' : '',
755 'title' => L10n::t('Only show archived contacts'),
756 'id' => 'showarchived-tab',
760 'label' => L10n::t('Hidden'),
761 'url' => 'contact/hidden',
762 'sel' => ($hidden) ? 'active' : '',
763 'title' => L10n::t('Only show hidden contacts'),
764 'id' => 'showhidden-tab',
769 $tab_tpl = get_markup_template('common_tabs.tpl');
770 $t = replace_macros($tab_tpl, ['$tabs' => $tabs]);
777 $search_hdr = $search;
778 $search_txt = DBA::escape(protect_sprintf(preg_quote($search)));
779 $sql_extra .= " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') ";
783 $sql_extra .= sprintf(" AND network = '%s' ", DBA::escape($nets));
786 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= Model\Contact::FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : '');
788 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
789 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
790 intval($_SESSION['uid'])
792 if (DBA::isResult($r)) {
793 $a->setPagerTotal($r[0]['total']);
794 $total = $r[0]['total'];
797 $sql_extra3 = Widget::unavailableNetworks();
801 $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 ",
802 intval($_SESSION['uid']),
803 intval($a->pager['start']),
804 intval($a->pager['itemspage'])
806 if (DBA::isResult($r)) {
807 foreach ($r as $rr) {
808 $rr['blocked'] = Model\Contact::isBlockedByUser($rr['id'], local_user());
809 $rr['readonly'] = Model\Contact::isIgnoredByUser($rr['id'], local_user());
810 $contacts[] = self::getContactTemplateVars($rr);
814 $tpl = get_markup_template("contacts-template.tpl");
815 $o .= replace_macros($tpl, [
816 '$baseurl' => System::baseUrl(),
817 '$header' => L10n::t('Contacts') . (($nets) ? ' - ' . ContactSelector::networkToName($nets) : ''),
820 '$search' => $search_hdr,
821 '$desc' => L10n::t('Search your contacts'),
822 '$finding' => $searching ? L10n::t('Results for: %s', $search) : "",
823 '$submit' => L10n::t('Find'),
825 '$contacts' => $contacts,
826 '$contact_drop_confirm' => L10n::t('Do you really want to delete this contact?'),
828 '$batch_actions' => [
829 'contacts_batch_update' => L10n::t('Update'),
830 'contacts_batch_block' => L10n::t('Block') . "/" . L10n::t("Unblock"),
831 "contacts_batch_ignore" => L10n::t('Ignore') . "/" . L10n::t("Unignore"),
832 "contacts_batch_archive" => L10n::t('Archive') . "/" . L10n::t("Unarchive"),
833 "contacts_batch_drop" => L10n::t('Delete'),
835 '$h_batch_actions' => L10n::t('Batch Actions'),
836 '$paginate' => paginate($a),
843 * @brief List of pages for the Contact TabBar
845 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
848 * @param array $contact The contact array
849 * @param int $active_tab 1 if tab should be marked as active
851 * @return string | HTML string of the contact page tabs buttons.
854 public static function getTabsHTML($a, $contact, $active_tab)
859 'label' => L10n::t('Status'),
860 'url' => "contact/" . $contact['id'] . "/conversations",
861 'sel' => (($active_tab == 1) ? 'active' : ''),
862 'title' => L10n::t('Conversations started by this contact'),
863 'id' => 'status-tab',
867 'label' => L10n::t('Posts and Comments'),
868 'url' => "contact/" . $contact['id'] . "/posts",
869 'sel' => (($active_tab == 2) ? 'active' : ''),
870 'title' => L10n::t('Status Messages and Posts'),
875 'label' => L10n::t('Profile'),
876 'url' => "contact/" . $contact['id'],
877 'sel' => (($active_tab == 3) ? 'active' : ''),
878 'title' => L10n::t('Profile Details'),
879 'id' => 'profile-tab',
884 // Show this tab only if there is visible friend list
885 $x = Model\GContact::countAllFriends(local_user(), $contact['id']);
887 $tabs[] = ['label' => L10n::t('Contacts'),
888 'url' => "allfriends/" . $contact['id'],
889 'sel' => (($active_tab == 4) ? 'active' : ''),
890 'title' => L10n::t('View all contacts'),
891 'id' => 'allfriends-tab',
895 // Show this tab only if there is visible common friend list
896 $common = Model\GContact::countCommonFriends(local_user(), $contact['id']);
898 $tabs[] = ['label' => L10n::t('Common Friends'),
899 'url' => "common/loc/" . local_user() . "/" . $contact['id'],
900 'sel' => (($active_tab == 5) ? 'active' : ''),
901 'title' => L10n::t('View all common friends'),
902 'id' => 'common-loc-tab',
907 if (!empty($contact['uid'])) {
908 $tabs[] = ['label' => L10n::t('Advanced'),
909 'url' => 'crepair/' . $contact['id'],
910 'sel' => (($active_tab == 6) ? 'active' : ''),
911 'title' => L10n::t('Advanced Contact Settings'),
912 'id' => 'advanced-tab',
917 $tab_tpl = get_markup_template('common_tabs.tpl');
918 $tab_str = replace_macros($tab_tpl, ['$tabs' => $tabs]);
923 private static function getConversationsHMTL($a, $contact_id, $update)
928 // We need the editor here to be able to reshare an item.
932 'allow_location' => $a->user['allow_location'],
933 'default_location' => $a->user['default-location'],
934 'nickname' => $a->user['nickname'],
935 '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'),
936 'acl' => ACL::getFullSelectorHTML($a->user, true),
938 'visitor' => 'block',
939 'profile_uid' => local_user(),
941 $o = status_editor($a, $x, 0, true);
945 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id]);
948 $o .= self::getTabsHTML($a, $contact, 1);
951 if (DBA::isResult($contact)) {
952 $a->page['aside'] = "";
954 $profiledata = Model\Contact::getDetailsByURL($contact["url"]);
957 if (in_array($profiledata["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
958 $profiledata["remoteconnect"] = System::baseUrl()."/follow?url=".urlencode($profiledata["url"]);
962 Model\Profile::load($a, "", 0, $profiledata, true);
963 $o .= Model\Contact::getPostsFromUrl($contact["url"], true, $update);
969 private static function getPostsHTML($a, $contact_id)
971 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id]);
973 $o = self::getTabsHTML($a, $contact, 2);
975 if (DBA::isResult($contact)) {
976 $a->page['aside'] = "";
978 $profiledata = Model\Contact::getDetailsByURL($contact["url"]);
981 if (in_array($profiledata["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
982 $profiledata["remoteconnect"] = System::baseUrl()."/follow?url=".urlencode($profiledata["url"]);
986 Model\Profile::load($a, "", 0, $profiledata, true);
987 $o .= Model\Contact::getPostsFromUrl($contact["url"]);
993 public static function getContactTemplateVars(array $rr)
998 switch ($rr['rel']) {
999 case Model\Contact::FRIEND:
1000 $dir_icon = 'images/lrarrow.gif';
1001 $alt_text = L10n::t('Mutual Friendship');
1004 case Model\Contact::FOLLOWER;
1005 $dir_icon = 'images/larrow.gif';
1006 $alt_text = L10n::t('is a fan of yours');
1009 case Model\Contact::SHARING;
1010 $dir_icon = 'images/rarrow.gif';
1011 $alt_text = L10n::t('you are a fan of');
1018 $url = Model\Contact::magicLink($rr['url']);
1020 if (strpos($url, 'redir/') === 0) {
1021 $sparkle = ' class="sparkle" ';
1027 $dir_icon = 'images/larrow.gif';
1028 $alt_text = L10n::t('This is you');
1034 'img_hover' => L10n::t('Visit %s\'s profile [%s]', $rr['name'], $rr['url']),
1035 'edit_hover' => L10n::t('Edit contact'),
1036 'photo_menu' => Model\Contact::photoMenu($rr),
1038 'alt_text' => $alt_text,
1039 'dir_icon' => $dir_icon,
1040 'thumb' => ProxyUtils::proxifyUrl($rr['thumb'], false, ProxyUtils::SIZE_THUMB),
1041 'name' => htmlentities($rr['name']),
1042 'username' => htmlentities($rr['name']),
1043 'account_type' => Model\Contact::getAccountType($rr),
1044 'sparkle' => $sparkle,
1045 'itemurl' => defaults($rr, 'addr', $rr['url']),
1047 'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
1048 'nick' => htmlentities($rr['nick']),
1053 * @brief Gives a array with actions which can performed to a given contact
1055 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
1057 * @param array $contact Data about the Contact
1058 * @return array with contact related actions
1060 private static function getContactActions($contact)
1062 $poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
1063 $contact_actions = [];
1065 // Provide friend suggestion only for Friendica contacts
1066 if ($contact['network'] === Protocol::DFRN) {
1067 $contact_actions['suggest'] = [
1068 'label' => L10n::t('Suggest friends'),
1069 'url' => 'fsuggest/' . $contact['id'],
1076 if ($poll_enabled) {
1077 $contact_actions['update'] = [
1078 'label' => L10n::t('Update now'),
1079 'url' => 'contact/' . $contact['id'] . '/update',
1086 $contact_actions['block'] = [
1087 'label' => (intval($contact['blocked']) ? L10n::t('Unblock') : L10n::t('Block')),
1088 'url' => 'contact/' . $contact['id'] . '/block',
1089 'title' => L10n::t('Toggle Blocked status'),
1090 'sel' => (intval($contact['blocked']) ? 'active' : ''),
1091 'id' => 'toggle-block',
1094 $contact_actions['ignore'] = [
1095 'label' => (intval($contact['readonly']) ? L10n::t('Unignore') : L10n::t('Ignore')),
1096 'url' => 'contact/' . $contact['id'] . '/ignore',
1097 'title' => L10n::t('Toggle Ignored status'),
1098 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1099 'id' => 'toggle-ignore',
1102 if ($contact['uid'] != 0) {
1103 $contact_actions['archive'] = [
1104 'label' => (intval($contact['archive']) ? L10n::t('Unarchive') : L10n::t('Archive')),
1105 'url' => 'contact/' . $contact['id'] . '/archive',
1106 'title' => L10n::t('Toggle Archive status'),
1107 'sel' => (intval($contact['archive']) ? 'active' : ''),
1108 'id' => 'toggle-archive',
1111 $contact_actions['delete'] = [
1112 'label' => L10n::t('Delete'),
1113 'url' => 'contact/' . $contact['id'] . '/drop',
1114 'title' => L10n::t('Delete contact'),
1120 return $contact_actions;