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),
122 function contacts_batch_actions(App $a)
124 if (empty($_POST['contact_batch']) || !is_array($_POST['contact_batch'])) {
128 $contacts_id = $_POST['contact_batch'];
130 $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
131 implode(",", $contacts_id),
136 foreach ($orig_records as $orig_record) {
137 $contact_id = $orig_record['id'];
138 if (x($_POST, 'contacts_batch_update')) {
139 _contact_update($contact_id);
142 if (x($_POST, 'contacts_batch_block')) {
143 _contact_block($contact_id);
146 if (x($_POST, 'contacts_batch_ignore')) {
147 _contact_ignore($contact_id);
150 if (x($_POST, 'contacts_batch_archive')) {
151 $r = _contact_archive($contact_id, $orig_record);
156 if (x($_POST, 'contacts_batch_drop')) {
157 _contact_drop($orig_record);
161 if ($count_actions > 0) {
162 info(L10n::tt("%d contact edited.", "%d contacts edited.", $count_actions));
168 function contacts_post(App $a)
174 if ($a->argv[1] === "batch") {
175 contacts_batch_actions($a);
179 $contact_id = intval($a->argv[1]);
184 if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user()])) {
185 notice(L10n::t('Could not access contact record.') . EOL);
187 return; // NOTREACHED
190 Addon::callHooks('contact_edit_post', $_POST);
192 $profile_id = intval(defaults($_POST, 'profile-assign', 0));
194 if (!DBA::exists('profile', ['id' => $profile_id, 'uid' => local_user()])) {
195 notice(L10n::t('Could not locate selected profile.') . EOL);
200 $hidden = intval($_POST['hidden']);
202 $notify = intval($_POST['notify']);
204 $fetch_further_information = intval(defaults($_POST, 'fetch_further_information', 0));
206 $ffi_keyword_blacklist = escape_tags(trim(defaults($_POST, 'ffi_keyword_blacklist', '')));
208 $priority = intval(defaults($_POST, 'poll', 0));
209 if ($priority > 5 || $priority < 0) {
213 $info = escape_tags(trim($_POST['info']));
215 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
216 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
217 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
223 intval($fetch_further_information),
224 DBA::escape($ffi_keyword_blacklist),
228 if (DBA::isResult($r)) {
229 info(L10n::t('Contact updated.') . EOL);
231 notice(L10n::t('Failed to update contact record.') . EOL);
234 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
235 if (DBA::isResult($contact)) {
236 $a->data['contact'] = $contact;
242 /* contact actions */
244 function _contact_update($contact_id)
246 $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
247 if (!DBA::isResult($contact)) {
251 $uid = $contact["uid"];
253 if ($contact["network"] == Protocol::OSTATUS) {
254 $result = Contact::createFromProbe($uid, $contact["url"], false, $contact["network"]);
256 if ($result['success']) {
257 q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d", intval($contact_id));
260 // pull feed and consume it, which should subscribe to the hub.
261 Worker::add(PRIORITY_HIGH, "OnePoll", $contact_id, "force");
265 function _contact_update_profile($contact_id)
267 $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
268 if (!DBA::isResult($contact)) {
272 $uid = $contact["uid"];
274 $data = Probe::uri($contact["url"], "", 0, false);
276 // "Feed" or "Unknown" is mostly a sign of communication problems
277 if ((in_array($data["network"], [Protocol::FEED, Protocol::PHANTOM])) && ($data["network"] != $contact["network"])) {
281 $updatefields = ["name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
282 "poco", "network", "alias"];
285 if ($data["network"] == Protocol::OSTATUS) {
286 $result = Contact::createFromProbe($uid, $data["url"], false);
288 if ($result['success']) {
289 $update["subhub"] = true;
293 foreach ($updatefields AS $field) {
294 if (isset($data[$field]) && ($data[$field] != "")) {
295 $update[$field] = $data[$field];
299 $update["nurl"] = normalise_link($data["url"]);
303 if (isset($data["priority"]) && ($data["priority"] != 0)) {
304 $query = "`priority` = " . intval($data["priority"]);
307 foreach ($update AS $key => $value) {
312 $query .= "`" . $key . "` = '" . DBA::escape($value) . "'";
319 $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
324 // Update the entry in the contact table
325 Contact::updateAvatar($data['photo'], local_user(), $contact_id, true);
327 // Update the entry in the gcontact table
328 GContact::updateFromProbe($data["url"]);
331 function _contact_block($contact_id)
333 $blocked = !Contact::isBlockedByUser($contact_id, local_user());
334 Contact::setBlockedForUser($contact_id, local_user(), $blocked);
337 function _contact_ignore($contact_id)
339 $ignored = !Contact::isIgnoredByUser($contact_id, local_user());
340 Contact::setIgnoredForUser($contact_id, local_user(), $ignored);
343 function _contact_archive($contact_id, $orig_record)
345 $archived = (($orig_record['archive']) ? 0 : 1);
346 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
351 return DBA::isResult($r);
354 function _contact_drop($orig_record)
358 $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
359 WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
360 intval($a->user['uid'])
362 if (!DBA::isResult($r)) {
366 Contact::terminateFriendship($r[0], $orig_record, true);
367 Contact::remove($orig_record['id']);
370 function contacts_content(App $a, $update = 0)
374 Nav::setSelected('contacts');
377 notice(L10n::t('Permission denied.') . EOL);
382 $contact_id = intval($a->argv[1]);
389 $orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'self' => false]);
390 if (!DBA::isResult($orig_record)) {
391 notice(L10n::t('Could not access contact record.') . EOL);
393 return; // NOTREACHED
396 if ($cmd === 'update' && ($orig_record['uid'] != 0)) {
397 _contact_update($contact_id);
398 goaway('contacts/' . $contact_id);
402 if ($cmd === 'updateprofile' && ($orig_record['uid'] != 0)) {
403 _contact_update_profile($contact_id);
404 goaway('crepair/' . $contact_id);
408 if ($cmd === 'block') {
409 _contact_block($contact_id);
411 $blocked = Contact::isBlockedByUser($contact_id, local_user());
412 info(($blocked ? L10n::t('Contact has been blocked') : L10n::t('Contact has been unblocked')) . EOL);
414 goaway('contacts/' . $contact_id);
415 return; // NOTREACHED
418 if ($cmd === 'ignore') {
419 _contact_ignore($contact_id);
421 $ignored = Contact::isIgnoredByUser($contact_id, local_user());
422 info(($ignored ? L10n::t('Contact has been ignored') : L10n::t('Contact has been unignored')) . EOL);
424 goaway('contacts/' . $contact_id);
425 return; // NOTREACHED
428 if ($cmd === 'archive' && ($orig_record['uid'] != 0)) {
429 $r = _contact_archive($contact_id, $orig_record);
431 $archived = (($orig_record['archive']) ? 0 : 1);
432 info((($archived) ? L10n::t('Contact has been archived') : L10n::t('Contact has been unarchived')) . EOL);
435 goaway('contacts/' . $contact_id);
436 return; // NOTREACHED
439 if ($cmd === 'drop' && ($orig_record['uid'] != 0)) {
440 // Check if we should do HTML-based delete confirmation
441 if (x($_REQUEST, 'confirm')) {
442 // <form> can't take arguments in its "action" parameter
443 // so add any arguments as hidden inputs
444 $query = explode_querystring($a->query_string);
446 foreach ($query['args'] as $arg) {
447 if (strpos($arg, 'confirm=') === false) {
448 $arg_parts = explode('=', $arg);
449 $inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]];
453 $a->page['aside'] = '';
455 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), [
456 '$header' => L10n::t('Drop contact'),
457 '$contact' => _contact_detail_for_template($orig_record),
459 '$message' => L10n::t('Do you really want to delete this contact?'),
460 '$extra_inputs' => $inputs,
461 '$confirm' => L10n::t('Yes'),
462 '$confirm_url' => $query['base'],
463 '$confirm_name' => 'confirmed',
464 '$cancel' => L10n::t('Cancel'),
467 // Now check how the user responded to the confirmation query
468 if (x($_REQUEST, 'canceled')) {
472 _contact_drop($orig_record);
473 info(L10n::t('Contact has been removed.') . EOL);
476 return; // NOTREACHED
478 if ($cmd === 'posts') {
479 return contact_posts($a, $contact_id);
481 if ($cmd === 'conversations') {
482 return contact_conversations($a, $contact_id, $update);
486 $_SESSION['return_url'] = $a->query_string;
488 if ((x($a->data, 'contact')) && (is_array($a->data['contact']))) {
489 $contact_id = $a->data['contact']['id'];
490 $contact = $a->data['contact'];
492 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), [
493 '$baseurl' => System::baseUrl(true),
496 $contact['blocked'] = Contact::isBlockedByUser($contact['id'], local_user());
497 $contact['readonly'] = Contact::isIgnoredByUser($contact['id'], local_user());
501 switch ($contact['rel']) {
502 case Contact::FRIEND:
503 $dir_icon = 'images/lrarrow.gif';
504 $relation_text = L10n::t('You are mutual friends with %s');
507 case Contact::FOLLOWER;
508 $dir_icon = 'images/larrow.gif';
509 $relation_text = L10n::t('You are sharing with %s');
512 case Contact::SHARING;
513 $dir_icon = 'images/rarrow.gif';
514 $relation_text = L10n::t('%s is sharing with you');
521 if ($contact['uid'] == 0) {
525 if (!in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
529 $relation_text = sprintf($relation_text, htmlentities($contact['name']));
531 $url = Contact::magicLink($contact['url']);
532 if (strpos($url, 'redir/') === 0) {
533 $sparkle = ' class="sparkle" ';
538 $insecure = L10n::t('Private communications are not available for this contact.');
540 $last_update = (($contact['last-update'] <= NULL_DATE) ? L10n::t('Never') : DateTimeFormat::local($contact['last-update'], 'D, j M Y, g:i A'));
542 if ($contact['last-update'] > NULL_DATE) {
543 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? L10n::t("\x28Update was successful\x29") : L10n::t("\x28Update was not successful\x29"));
545 $lblsuggest = (($contact['network'] === Protocol::DFRN) ? L10n::t('Suggest friends') : '');
547 $poll_enabled = in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
549 $nettype = L10n::t('Network type: %s', ContactSelector::networkToName($contact['network'], $contact["url"]));
552 $tab_str = contacts_tab($a, $contact, 3);
554 $lost_contact = (($contact['archive'] && $contact['term-date'] > NULL_DATE && $contact['term-date'] < DateTimeFormat::utcNow()) ? L10n::t('Communications lost with this contact!') : '');
556 $fetch_further_information = null;
557 if ($contact['network'] == Protocol::FEED) {
558 $fetch_further_information = [
559 'fetch_further_information',
560 L10n::t('Fetch further information for feeds'),
561 $contact['fetch_further_information'],
562 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."),
563 ['0' => L10n::t('Disabled'),
564 '1' => L10n::t('Fetch information'),
565 '3' => L10n::t('Fetch keywords'),
566 '2' => L10n::t('Fetch information and keywords')
571 $poll_interval = null;
572 if (in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
573 $poll_interval = ContactSelector::pollInterval($contact['priority'], (!$poll_enabled));
576 $profile_select = null;
577 if ($contact['network'] == Protocol::DFRN) {
578 $profile_select = ContactSelector::profileAssign($contact['profile-id'], (($contact['network'] !== Protocol::DFRN) ? true : false));
581 /// @todo Only show the following link with DFRN when the remote version supports it
584 if (in_array($contact['rel'], [Contact::FRIEND, Contact::SHARING])) {
585 if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
586 $follow = System::baseUrl(true) . "/unfollow?url=" . urlencode($contact["url"]);
587 $follow_text = L10n::t("Disconnect/Unfollow");
590 $follow = System::baseUrl(true) . "/follow?url=" . urlencode($contact["url"]);
591 $follow_text = L10n::t("Connect/Follow");
594 // Load contactact related actions like hide, suggest, delete and others
595 $contact_actions = contact_actions($contact);
597 if ($contact['uid'] != 0) {
598 $lbl_vis1 = L10n::t('Profile Visibility');
599 $lbl_info1 = L10n::t('Contact Information / Notes');
600 $contact_settings_label = L10n::t('Contact Settings');
604 $contact_settings_label = null;
607 $tpl = get_markup_template("contact_edit.tpl");
608 $o .= replace_macros($tpl, [
609 '$header' => L10n::t("Contact"),
610 '$tab_str' => $tab_str,
611 '$submit' => L10n::t('Submit'),
612 '$lbl_vis1' => $lbl_vis1,
613 '$lbl_vis2' => L10n::t('Please choose the profile you would like to display to %s when viewing your profile securely.', $contact['name']),
614 '$lbl_info1' => $lbl_info1,
615 '$lbl_info2' => L10n::t('Their personal note'),
616 '$reason' => trim(notags($contact['reason'])),
617 '$infedit' => L10n::t('Edit contact notes'),
618 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
619 '$relation_text' => $relation_text,
620 '$visit' => L10n::t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']),
621 '$blockunblock' => L10n::t('Block/Unblock contact'),
622 '$ignorecont' => L10n::t('Ignore contact'),
623 '$lblcrepair' => L10n::t("Repair URL settings"),
624 '$lblrecent' => L10n::t('View conversations'),
625 '$lblsuggest' => $lblsuggest,
626 '$nettype' => $nettype,
627 '$poll_interval' => $poll_interval,
628 '$poll_enabled' => $poll_enabled,
629 '$lastupdtext' => L10n::t('Last update:'),
630 '$lost_contact' => $lost_contact,
631 '$updpub' => L10n::t('Update public posts'),
632 '$last_update' => $last_update,
633 '$udnow' => L10n::t('Update now'),
634 '$follow' => $follow,
635 '$follow_text' => $follow_text,
636 '$profile_select' => $profile_select,
637 '$contact_id' => $contact['id'],
638 '$block_text' => ($contact['blocked'] ? L10n::t('Unblock') : L10n::t('Block')),
639 '$ignore_text' => ($contact['readonly'] ? L10n::t('Unignore') : L10n::t('Ignore')),
640 '$insecure' => (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::MAIL, Protocol::DIASPORA]) ? '' : $insecure),
641 '$info' => $contact['info'],
642 '$cinfo' => ['info', '', $contact['info'], ''],
643 '$blocked' => ($contact['blocked'] ? L10n::t('Currently blocked') : ''),
644 '$ignored' => ($contact['readonly'] ? L10n::t('Currently ignored') : ''),
645 '$archived' => ($contact['archive'] ? L10n::t('Currently archived') : ''),
646 '$pending' => ($contact['pending'] ? L10n::t('Awaiting connection acknowledge') : ''),
647 '$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')],
648 '$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')],
649 '$fetch_further_information' => $fetch_further_information,
650 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
651 '$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')],
652 '$photo' => $contact['photo'],
653 '$name' => htmlentities($contact['name']),
654 '$dir_icon' => $dir_icon,
655 '$sparkle' => $sparkle,
657 '$profileurllabel' => L10n::t('Profile URL'),
658 '$profileurl' => $contact['url'],
659 '$account_type' => Contact::getAccountType($contact),
660 '$location' => BBCode::convert($contact["location"]),
661 '$location_label' => L10n::t("Location:"),
662 '$xmpp' => BBCode::convert($contact["xmpp"]),
663 '$xmpp_label' => L10n::t("XMPP:"),
664 '$about' => BBCode::convert($contact["about"], false),
665 '$about_label' => L10n::t("About:"),
666 '$keywords' => $contact["keywords"],
667 '$keywords_label' => L10n::t("Tags:"),
668 '$contact_action_button' => L10n::t("Actions"),
669 '$contact_actions' => $contact_actions,
670 '$contact_status' => L10n::t("Status"),
671 '$contact_settings_label' => $contact_settings_label,
672 '$contact_profile_label' => L10n::t("Profile"),
675 $arr = ['contact' => $contact, 'output' => $o];
677 Addon::callHooks('contact_edit', $arr);
679 return $arr['output'];
688 if (($a->argc == 2) && ($a->argv[1] === 'all')) {
691 } elseif (($a->argc == 2) && ($a->argv[1] === 'blocked')) {
692 $sql_extra = " AND `blocked` = 1 ";
694 } elseif (($a->argc == 2) && ($a->argv[1] === 'hidden')) {
695 $sql_extra = " AND `hidden` = 1 ";
697 } elseif (($a->argc == 2) && ($a->argv[1] === 'ignored')) {
698 $sql_extra = " AND `readonly` = 1 ";
700 } elseif (($a->argc == 2) && ($a->argv[1] === 'archived')) {
701 $sql_extra = " AND `archive` = 1 ";
704 $sql_extra = " AND `blocked` = 0 ";
707 $sql_extra .= sprintf(" AND `network` != '%s' ", Protocol::PHANTOM);
709 $search = x($_GET, 'search') ? notags(trim($_GET['search'])) : '';
710 $nets = x($_GET, 'nets' ) ? notags(trim($_GET['nets'])) : '';
714 'label' => L10n::t('Suggestions'),
717 'title' => L10n::t('Suggest potential friends'),
718 'id' => 'suggestions-tab',
722 'label' => L10n::t('All Contacts'),
723 'url' => 'contacts/all',
724 'sel' => ($all) ? 'active' : '',
725 'title' => L10n::t('Show all contacts'),
726 'id' => 'showall-tab',
730 'label' => L10n::t('Unblocked'),
732 'sel' => ((!$all) && (!$blocked) && (!$hidden) && (!$search) && (!$nets) && (!$ignored) && (!$archived)) ? 'active' : '',
733 'title' => L10n::t('Only show unblocked contacts'),
734 'id' => 'showunblocked-tab',
738 'label' => L10n::t('Blocked'),
739 'url' => 'contacts/blocked',
740 'sel' => ($blocked) ? 'active' : '',
741 'title' => L10n::t('Only show blocked contacts'),
742 'id' => 'showblocked-tab',
746 'label' => L10n::t('Ignored'),
747 'url' => 'contacts/ignored',
748 'sel' => ($ignored) ? 'active' : '',
749 'title' => L10n::t('Only show ignored contacts'),
750 'id' => 'showignored-tab',
754 'label' => L10n::t('Archived'),
755 'url' => 'contacts/archived',
756 'sel' => ($archived) ? 'active' : '',
757 'title' => L10n::t('Only show archived contacts'),
758 'id' => 'showarchived-tab',
762 'label' => L10n::t('Hidden'),
763 'url' => 'contacts/hidden',
764 'sel' => ($hidden) ? 'active' : '',
765 'title' => L10n::t('Only show hidden contacts'),
766 'id' => 'showhidden-tab',
771 $tab_tpl = get_markup_template('common_tabs.tpl');
772 $t = replace_macros($tab_tpl, ['$tabs' => $tabs]);
779 $search_hdr = $search;
780 $search_txt = DBA::escape(protect_sprintf(preg_quote($search)));
781 $sql_extra .= " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') ";
785 $sql_extra .= sprintf(" AND network = '%s' ", DBA::escape($nets));
788 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= Contact::FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : '');
790 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
791 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
792 intval($_SESSION['uid'])
794 if (DBA::isResult($r)) {
795 $a->set_pager_total($r[0]['total']);
796 $total = $r[0]['total'];
799 $sql_extra3 = Widget::unavailableNetworks();
803 $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 ",
804 intval($_SESSION['uid']),
805 intval($a->pager['start']),
806 intval($a->pager['itemspage'])
808 if (DBA::isResult($r)) {
809 foreach ($r as $rr) {
810 $rr['blocked'] = Contact::isBlockedByUser($rr['id'], local_user());
811 $rr['readonly'] = Contact::isIgnoredByUser($rr['id'], local_user());
812 $contacts[] = _contact_detail_for_template($rr);
816 $tpl = get_markup_template("contacts-template.tpl");
817 $o .= replace_macros($tpl, [
818 '$baseurl' => System::baseUrl(),
819 '$header' => L10n::t('Contacts') . (($nets) ? ' - ' . ContactSelector::networkToName($nets) : ''),
822 '$search' => $search_hdr,
823 '$desc' => L10n::t('Search your contacts'),
824 '$finding' => $searching ? L10n::t('Results for: %s', $search) : "",
825 '$submit' => L10n::t('Find'),
827 '$contacts' => $contacts,
828 '$contact_drop_confirm' => L10n::t('Do you really want to delete this contact?'),
830 '$batch_actions' => [
831 'contacts_batch_update' => L10n::t('Update'),
832 'contacts_batch_block' => L10n::t('Block') . "/" . L10n::t("Unblock"),
833 "contacts_batch_ignore" => L10n::t('Ignore') . "/" . L10n::t("Unignore"),
834 "contacts_batch_archive" => L10n::t('Archive') . "/" . L10n::t("Unarchive"),
835 "contacts_batch_drop" => L10n::t('Delete'),
837 '$h_batch_actions' => L10n::t('Batch Actions'),
838 '$paginate' => paginate($a),
845 * @brief List of pages for the Contact TabBar
847 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
850 * @param array $contact The contact array
851 * @param int $active_tab 1 if tab should be marked as active
855 function contacts_tab($a, $contact, $active_tab)
860 'label' => L10n::t('Status'),
861 'url' => "contacts/" . $contact['id'] . "/conversations",
862 'sel' => (($active_tab == 1) ? 'active' : ''),
863 'title' => L10n::t('Conversations started by this contact'),
864 'id' => 'status-tab',
868 'label' => L10n::t('Posts and Comments'),
869 'url' => "contacts/" . $contact['id'] . "/posts",
870 'sel' => (($active_tab == 2) ? 'active' : ''),
871 'title' => L10n::t('Status Messages and Posts'),
876 'label' => L10n::t('Profile'),
877 'url' => "contacts/" . $contact['id'],
878 'sel' => (($active_tab == 3) ? 'active' : ''),
879 'title' => L10n::t('Profile Details'),
880 'id' => 'profile-tab',
885 // Show this tab only if there is visible friend list
886 $x = GContact::countAllFriends(local_user(), $contact['id']);
888 $tabs[] = ['label' => L10n::t('Contacts'),
889 'url' => "allfriends/" . $contact['id'],
890 'sel' => (($active_tab == 4) ? 'active' : ''),
891 'title' => L10n::t('View all contacts'),
892 'id' => 'allfriends-tab',
896 // Show this tab only if there is visible common friend list
897 $common = GContact::countCommonFriends(local_user(), $contact['id']);
899 $tabs[] = ['label' => L10n::t('Common Friends'),
900 'url' => "common/loc/" . local_user() . "/" . $contact['id'],
901 'sel' => (($active_tab == 5) ? 'active' : ''),
902 'title' => L10n::t('View all common friends'),
903 'id' => 'common-loc-tab',
908 if (!empty($contact['uid'])) {
909 $tabs[] = ['label' => L10n::t('Advanced'),
910 'url' => 'crepair/' . $contact['id'],
911 'sel' => (($active_tab == 6) ? 'active' : ''),
912 'title' => L10n::t('Advanced Contact Settings'),
913 'id' => 'advanced-tab',
918 $tab_tpl = get_markup_template('common_tabs.tpl');
919 $tab_str = replace_macros($tab_tpl, ['$tabs' => $tabs]);
924 function contact_conversations(App $a, $contact_id, $update)
929 // We need the editor here to be able to reshare an item.
933 'allow_location' => $a->user['allow_location'],
934 'default_location' => $a->user['default-location'],
935 'nickname' => $a->user['nickname'],
936 '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'),
937 'acl' => ACL::getFullSelectorHTML($a->user, true),
939 'visitor' => 'block',
940 'profile_uid' => local_user(),
942 $o = status_editor($a, $x, 0, true);
946 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id]);
949 $o .= contacts_tab($a, $contact, 1);
952 if (DBA::isResult($contact)) {
953 $a->page['aside'] = "";
955 $profiledata = Contact::getDetailsByURL($contact["url"]);
958 if (in_array($profiledata["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
959 $profiledata["remoteconnect"] = System::baseUrl()."/follow?url=".urlencode($profiledata["url"]);
963 Profile::load($a, "", 0, $profiledata, true);
964 $o .= Contact::getPostsFromUrl($contact["url"], true, $update);
970 function contact_posts(App $a, $contact_id)
972 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id]);
974 $o = contacts_tab($a, $contact, 2);
976 if (DBA::isResult($contact)) {
977 $a->page['aside'] = "";
979 $profiledata = Contact::getDetailsByURL($contact["url"]);
982 if (in_array($profiledata["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
983 $profiledata["remoteconnect"] = System::baseUrl()."/follow?url=".urlencode($profiledata["url"]);
987 Profile::load($a, "", 0, $profiledata, true);
988 $o .= Contact::getPostsFromUrl($contact["url"]);
994 function _contact_detail_for_template(array $rr)
999 switch ($rr['rel']) {
1000 case Contact::FRIEND:
1001 $dir_icon = 'images/lrarrow.gif';
1002 $alt_text = L10n::t('Mutual Friendship');
1005 case Contact::FOLLOWER;
1006 $dir_icon = 'images/larrow.gif';
1007 $alt_text = L10n::t('is a fan of yours');
1010 case Contact::SHARING;
1011 $dir_icon = 'images/rarrow.gif';
1012 $alt_text = L10n::t('you are a fan of');
1019 $url = Contact::magicLink($rr['url']);
1021 if (strpos($url, 'redir/') === 0) {
1022 $sparkle = ' class="sparkle" ';
1028 $dir_icon = 'images/larrow.gif';
1029 $alt_text = L10n::t('This is you');
1035 'img_hover' => L10n::t('Visit %s\'s profile [%s]', $rr['name'], $rr['url']),
1036 'edit_hover' => L10n::t('Edit contact'),
1037 'photo_menu' => Contact::photoMenu($rr),
1039 'alt_text' => $alt_text,
1040 'dir_icon' => $dir_icon,
1041 'thumb' => ProxyUtils::proxifyUrl($rr['thumb'], false, ProxyUtils::SIZE_THUMB),
1042 'name' => htmlentities($rr['name']),
1043 'username' => htmlentities($rr['name']),
1044 'account_type' => Contact::getAccountType($rr),
1045 'sparkle' => $sparkle,
1046 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
1048 'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
1049 'nick' => htmlentities($rr['nick']),
1054 * @brief Gives a array with actions which can performed to a given contact
1056 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
1058 * @param array $contact Data about the Contact
1059 * @return array with contact related actions
1061 function contact_actions($contact)
1063 $poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
1064 $contact_actions = [];
1066 // Provide friend suggestion only for Friendica contacts
1067 if ($contact['network'] === Protocol::DFRN) {
1068 $contact_actions['suggest'] = [
1069 'label' => L10n::t('Suggest friends'),
1070 'url' => 'fsuggest/' . $contact['id'],
1077 if ($poll_enabled) {
1078 $contact_actions['update'] = [
1079 'label' => L10n::t('Update now'),
1080 'url' => 'contacts/' . $contact['id'] . '/update',
1087 $contact_actions['block'] = [
1088 'label' => (intval($contact['blocked']) ? L10n::t('Unblock') : L10n::t('Block')),
1089 'url' => 'contacts/' . $contact['id'] . '/block',
1090 'title' => L10n::t('Toggle Blocked status'),
1091 'sel' => (intval($contact['blocked']) ? 'active' : ''),
1092 'id' => 'toggle-block',
1095 $contact_actions['ignore'] = [
1096 'label' => (intval($contact['readonly']) ? L10n::t('Unignore') : L10n::t('Ignore')),
1097 'url' => 'contacts/' . $contact['id'] . '/ignore',
1098 'title' => L10n::t('Toggle Ignored status'),
1099 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1100 'id' => 'toggle-ignore',
1103 if ($contact['uid'] != 0) {
1104 $contact_actions['archive'] = [
1105 'label' => (intval($contact['archive']) ? L10n::t('Unarchive') : L10n::t('Archive')),
1106 'url' => 'contacts/' . $contact['id'] . '/archive',
1107 'title' => L10n::t('Toggle Archive status'),
1108 'sel' => (intval($contact['archive']) ? 'active' : ''),
1109 'id' => 'toggle-archive',
1112 $contact_actions['delete'] = [
1113 'label' => L10n::t('Delete'),
1114 'url' => 'contacts/' . $contact['id'] . '/drop',
1115 'title' => L10n::t('Delete contact'),
1121 return $contact_actions;