3 namespace Friendica\Module;
6 use Friendica\BaseModule;
7 use Friendica\Content\ContactSelector;
8 use Friendica\Content\Nav;
9 use Friendica\Content\Pager;
10 use Friendica\Content\Text\BBCode;
11 use Friendica\Content\Widget;
12 use Friendica\Core\ACL;
13 use Friendica\Core\Hook;
14 use Friendica\Core\L10n;
15 use Friendica\Core\Protocol;
16 use Friendica\Core\Renderer;
17 use Friendica\Core\System;
18 use Friendica\Core\Worker;
19 use Friendica\Database\DBA;
21 use Friendica\Network\Probe;
22 use Friendica\Util\DateTimeFormat;
23 use Friendica\Util\Proxy as ProxyUtils;
24 use Friendica\Util\Strings;
27 * Manages and show Contacts and their content
29 * @brief manages contacts
31 class Contact extends BaseModule
33 public static function init()
41 $nets = defaults($_GET, 'nets', '');
43 if (empty($a->page['aside'])) {
44 $a->page['aside'] = '';
49 // @TODO: Replace with parameter from router
50 if ($a->argc == 2 && intval($a->argv[1])
51 || $a->argc == 3 && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])
53 $contact_id = intval($a->argv[1]);
54 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
56 if (!DBA::isResult($contact)) {
57 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => 0, 'deleted' => false]);
60 // Don't display contacts that are about to be deleted
61 if ($contact['network'] == Protocol::PHANTOM) {
66 if (DBA::isResult($contact)) {
67 if ($contact['self']) {
68 // @TODO: Replace with parameter from router
69 if (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])) {
70 $a->internalRedirect('profile/' . $contact['nick']);
72 $a->internalRedirect('profile/' . $contact['nick'] . '?tab=profile');
76 $a->data['contact'] = $contact;
78 if (($contact['network'] != '') && ($contact['network'] != Protocol::DFRN)) {
79 $network_link = Strings::formatNetworkName($contact['network'], $contact['url']);
84 $vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('vcard-widget.tpl'), [
85 '$name' => $contact['name'],
86 '$photo' => $contact['photo'],
87 '$url' => Model\Contact::MagicLink($contact['url']),
88 '$addr' => defaults($contact, 'addr', ''),
89 '$network_link' => $network_link,
90 '$network' => L10n::t('Network:'),
91 '$account_type' => Model\Contact::getAccountType($contact)
94 $findpeople_widget = '';
96 $networks_widget = '';
99 $networks_widget = Widget::networks('contact', $nets);
100 if (isset($_GET['add'])) {
101 $follow_widget = Widget::follow($_GET['add']);
103 $follow_widget = Widget::follow();
106 $findpeople_widget = Widget::findPeople();
109 if ($contact['uid'] != 0) {
110 $groups_widget = Model\Group::sidebarWidget('contact', 'group', 'full', 'everyone', $contact_id);
112 $groups_widget = null;
115 $a->page['aside'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('contacts-widget-sidebar.tpl'), [
116 '$vcard_widget' => $vcard_widget,
117 '$findpeople_widget' => $findpeople_widget,
118 '$follow_widget' => $follow_widget,
119 '$groups_widget' => $groups_widget,
120 '$networks_widget' => $networks_widget
123 $base = $a->getBaseURL();
124 $tpl = Renderer::getMarkupTemplate('contacts-head.tpl');
125 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl, [
126 '$baseurl' => System::baseUrl(true),
131 private static function batchActions(App $a)
133 if (empty($_POST['contact_batch']) || !is_array($_POST['contact_batch'])) {
137 $contacts_id = $_POST['contact_batch'];
139 $stmt = DBA::select('contact', ['id', 'archive'], ['id' => $contacts_id, 'uid' => local_user(), 'self' => false, 'deleted' => false]);
140 $orig_records = DBA::toArray($stmt);
143 foreach ($orig_records as $orig_record) {
144 $contact_id = $orig_record['id'];
145 if (!empty($_POST['contacts_batch_update'])) {
146 self::updateContactFromPoll($contact_id);
149 if (!empty($_POST['contacts_batch_block'])) {
150 self::blockContact($contact_id);
153 if (!empty($_POST['contacts_batch_ignore'])) {
154 self::ignoreContact($contact_id);
157 if (!empty($_POST['contacts_batch_archive'])
158 && self::archiveContact($contact_id, $orig_record)
162 if (!empty($_POST['contacts_batch_drop'])) {
163 self::dropContact($orig_record);
167 if ($count_actions > 0) {
168 info(L10n::tt('%d contact edited.', '%d contacts edited.', $count_actions));
171 $a->internalRedirect('contact');
174 public static function post()
182 if ($a->argv[1] === 'batch') {
183 self::batchActions($a);
187 $contact_id = intval($a->argv[1]);
192 if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false])) {
193 notice(L10n::t('Could not access contact record.') . EOL);
194 $a->internalRedirect('contact');
195 return; // NOTREACHED
198 Hook::callAll('contact_edit_post', $_POST);
200 $profile_id = intval(defaults($_POST, 'profile-assign', 0));
202 if (!DBA::exists('profile', ['id' => $profile_id, 'uid' => local_user()])) {
203 notice(L10n::t('Could not locate selected profile.') . EOL);
208 $hidden = !empty($_POST['hidden']);
210 $notify = !empty($_POST['notify']);
212 $fetch_further_information = intval(defaults($_POST, 'fetch_further_information', 0));
214 $ffi_keyword_blacklist = Strings::escapeHtml(trim(defaults($_POST, 'ffi_keyword_blacklist', '')));
216 $priority = intval(defaults($_POST, 'poll', 0));
217 if ($priority > 5 || $priority < 0) {
221 $info = Strings::escapeHtml(trim(defaults($_POST, 'info', '')));
223 $r = DBA::update('contact', [
224 'profile-id' => $profile_id,
225 'priority' => $priority,
228 'notify_new_posts' => $notify,
229 'fetch_further_information' => $fetch_further_information,
230 'ffi_keyword_blacklist' => $ffi_keyword_blacklist],
231 ['id' => $contact_id, 'uid' => local_user()]
234 if (DBA::isResult($r)) {
235 info(L10n::t('Contact updated.') . EOL);
237 notice(L10n::t('Failed to update contact record.') . EOL);
240 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
241 if (DBA::isResult($contact)) {
242 $a->data['contact'] = $contact;
248 /* contact actions */
250 private static function updateContactFromPoll($contact_id)
252 $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
253 if (!DBA::isResult($contact)) {
257 $uid = $contact['uid'];
259 if ($contact['network'] == Protocol::OSTATUS) {
260 $result = Model\Contact::createFromProbe($uid, $contact['url'], false, $contact['network']);
262 if ($result['success']) {
263 DBA::update('contact', ['subhub' => 1], ['id' => $contact_id]);
266 // pull feed and consume it, which should subscribe to the hub.
267 Worker::add(PRIORITY_HIGH, 'OnePoll', $contact_id, 'force');
271 private static function updateContactFromProbe($contact_id)
273 $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
274 if (!DBA::isResult($contact)) {
278 $uid = $contact['uid'];
280 $data = Probe::uri($contact['url'], '', 0, false);
282 // 'Feed' or 'Unknown' is mostly a sign of communication problems
283 if ((in_array($data['network'], [Protocol::FEED, Protocol::PHANTOM])) && ($data['network'] != $contact['network'])) {
287 $updatefields = ['name', 'nick', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'network', 'alias'];
290 if ($data['network'] == Protocol::OSTATUS) {
291 $result = Model\Contact::createFromProbe($uid, $data['url'], false);
293 if ($result['success']) {
294 $fields['subhub'] = true;
298 foreach ($updatefields AS $field) {
299 if (!empty($data[$field])) {
300 $fields[$field] = $data[$field];
304 $fields['nurl'] = Strings::normaliseLink($data['url']);
306 if (!empty($data['priority'])) {
307 $fields['priority'] = intval($data['priority']);
310 if (empty($fields)) {
314 DBA::update('contact', $fields, ['id' => $contact_id, 'uid' => local_user()]);
316 // Update the entry in the contact table
317 Model\Contact::updateAvatar($data['photo'], local_user(), $contact_id, true);
319 // Update the entry in the gcontact table
320 Model\GContact::updateFromProbe($data['url']);
323 private static function blockContact($contact_id)
325 $blocked = !Model\Contact::isBlockedByUser($contact_id, local_user());
326 Model\Contact::setBlockedForUser($contact_id, local_user(), $blocked);
329 private static function ignoreContact($contact_id)
331 $ignored = !Model\Contact::isIgnoredByUser($contact_id, local_user());
332 Model\Contact::setIgnoredForUser($contact_id, local_user(), $ignored);
335 private static function archiveContact($contact_id, $orig_record)
337 $archived = (defaults($orig_record, 'archive', '') ? 0 : 1);
338 $r = DBA::update('contact', ['archive' => $archived], ['id' => $contact_id, 'uid' => local_user()]);
340 return DBA::isResult($r);
343 private static function dropContact($orig_record)
345 $owner = Model\User::getOwnerDataById(local_user());
346 if (!DBA::isResult($owner)) {
350 Model\Contact::terminateFriendship($owner, $orig_record, true);
351 Model\Contact::remove($orig_record['id']);
354 public static function content($update = 0)
359 Nav::setSelected('contact');
362 notice(L10n::t('Permission denied.') . EOL);
363 return Login::form();
367 $contact_id = intval($a->argv[1]);
374 $orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'self' => false, 'deleted' => false]);
375 if (!DBA::isResult($orig_record)) {
376 notice(L10n::t('Could not access contact record.') . EOL);
377 $a->internalRedirect('contact');
378 return; // NOTREACHED
381 if ($cmd === 'update' && ($orig_record['uid'] != 0)) {
382 self::updateContactFromPoll($contact_id);
383 $a->internalRedirect('contact/' . $contact_id);
387 if ($cmd === 'updateprofile' && ($orig_record['uid'] != 0)) {
388 self::updateContactFromProbe($contact_id);
389 $a->internalRedirect('crepair/' . $contact_id);
393 if ($cmd === 'block') {
394 self::blockContact($contact_id);
396 $blocked = Model\Contact::isBlockedByUser($contact_id, local_user());
397 info(($blocked ? L10n::t('Contact has been blocked') : L10n::t('Contact has been unblocked')) . EOL);
399 $a->internalRedirect('contact/' . $contact_id);
400 return; // NOTREACHED
403 if ($cmd === 'ignore') {
404 self::ignoreContact($contact_id);
406 $ignored = Model\Contact::isIgnoredByUser($contact_id, local_user());
407 info(($ignored ? L10n::t('Contact has been ignored') : L10n::t('Contact has been unignored')) . EOL);
409 $a->internalRedirect('contact/' . $contact_id);
410 return; // NOTREACHED
413 if ($cmd === 'archive' && ($orig_record['uid'] != 0)) {
414 $r = self::archiveContact($contact_id, $orig_record);
416 $archived = (($orig_record['archive']) ? 0 : 1);
417 info((($archived) ? L10n::t('Contact has been archived') : L10n::t('Contact has been unarchived')) . EOL);
420 $a->internalRedirect('contact/' . $contact_id);
421 return; // NOTREACHED
424 if ($cmd === 'drop' && ($orig_record['uid'] != 0)) {
425 // Check if we should do HTML-based delete confirmation
426 if (!empty($_REQUEST['confirm'])) {
427 // <form> can't take arguments in its 'action' parameter
428 // so add any arguments as hidden inputs
429 $query = explode_querystring($a->query_string);
431 foreach ($query['args'] as $arg) {
432 if (strpos($arg, 'confirm=') === false) {
433 $arg_parts = explode('=', $arg);
434 $inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]];
438 $a->page['aside'] = '';
440 return Renderer::replaceMacros(Renderer::getMarkupTemplate('contact_drop_confirm.tpl'), [
441 '$header' => L10n::t('Drop contact'),
442 '$contact' => self::getContactTemplateVars($orig_record),
444 '$message' => L10n::t('Do you really want to delete this contact?'),
445 '$extra_inputs' => $inputs,
446 '$confirm' => L10n::t('Yes'),
447 '$confirm_url' => $query['base'],
448 '$confirm_name' => 'confirmed',
449 '$cancel' => L10n::t('Cancel'),
452 // Now check how the user responded to the confirmation query
453 if (!empty($_REQUEST['canceled'])) {
454 $a->internalRedirect('contact');
457 self::dropContact($orig_record);
458 info(L10n::t('Contact has been removed.') . EOL);
460 $a->internalRedirect('contact');
461 return; // NOTREACHED
463 if ($cmd === 'posts') {
464 return self::getPostsHTML($a, $contact_id);
466 if ($cmd === 'conversations') {
467 return self::getConversationsHMTL($a, $contact_id, $update);
471 $_SESSION['return_path'] = $a->query_string;
473 if (!empty($a->data['contact']) && is_array($a->data['contact'])) {
474 $contact = $a->data['contact'];
476 $a->page['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('contact_head.tpl'), [
477 '$baseurl' => $a->getBaseURL(true),
480 $contact['blocked'] = Model\Contact::isBlockedByUser($contact['id'], local_user());
481 $contact['readonly'] = Model\Contact::isIgnoredByUser($contact['id'], local_user());
485 switch ($contact['rel']) {
486 case Model\Contact::FRIEND:
487 $dir_icon = 'images/lrarrow.gif';
488 $relation_text = L10n::t('You are mutual friends with %s');
491 case Model\Contact::FOLLOWER;
492 $dir_icon = 'images/larrow.gif';
493 $relation_text = L10n::t('You are sharing with %s');
496 case Model\Contact::SHARING;
497 $dir_icon = 'images/rarrow.gif';
498 $relation_text = L10n::t('%s is sharing with you');
505 if ($contact['uid'] == 0) {
509 if (!in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
513 $relation_text = sprintf($relation_text, $contact['name']);
515 $url = Model\Contact::magicLink($contact['url']);
516 if (strpos($url, 'redir/') === 0) {
517 $sparkle = ' class="sparkle" ';
522 $insecure = L10n::t('Private communications are not available for this contact.');
524 $last_update = (($contact['last-update'] <= DBA::NULL_DATETIME) ? L10n::t('Never') : DateTimeFormat::local($contact['last-update'], 'D, j M Y, g:i A'));
526 if ($contact['last-update'] > DBA::NULL_DATETIME) {
527 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? L10n::t('(Update was successful)') : L10n::t('(Update was not successful)'));
529 $lblsuggest = (($contact['network'] === Protocol::DFRN) ? L10n::t('Suggest friends') : '');
531 $poll_enabled = in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
533 $nettype = L10n::t('Network type: %s', ContactSelector::networkToName($contact['network'], $contact['url']));
536 $tab_str = self::getTabsHTML($a, $contact, 3);
538 $lost_contact = (($contact['archive'] && $contact['term-date'] > DBA::NULL_DATETIME && $contact['term-date'] < DateTimeFormat::utcNow()) ? L10n::t('Communications lost with this contact!') : '');
540 $fetch_further_information = null;
541 if ($contact['network'] == Protocol::FEED) {
542 $fetch_further_information = [
543 'fetch_further_information',
544 L10n::t('Fetch further information for feeds'),
545 $contact['fetch_further_information'],
546 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.'),
548 '0' => L10n::t('Disabled'),
549 '1' => L10n::t('Fetch information'),
550 '3' => L10n::t('Fetch keywords'),
551 '2' => L10n::t('Fetch information and keywords')
556 $poll_interval = null;
557 if (in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
558 $poll_interval = ContactSelector::pollInterval($contact['priority'], !$poll_enabled);
561 $profile_select = null;
562 if ($contact['network'] == Protocol::DFRN) {
563 $profile_select = ContactSelector::profileAssign($contact['profile-id'], $contact['network'] !== Protocol::DFRN);
566 /// @todo Only show the following link with DFRN when the remote version supports it
569 if ($contact['uid'] && in_array($contact['rel'], [Model\Contact::FRIEND, Model\Contact::SHARING])) {
570 if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
571 $follow = $a->getBaseURL(true) . '/unfollow?url=' . urlencode($contact['url']);
572 $follow_text = L10n::t('Disconnect/Unfollow');
574 } elseif(!$contact['pending']) {
575 $follow = $a->getBaseURL(true) . '/follow?url=' . urlencode($contact['url']);
576 $follow_text = L10n::t('Connect/Follow');
579 // Load contactact related actions like hide, suggest, delete and others
580 $contact_actions = self::getContactActions($contact);
582 if ($contact['uid'] != 0) {
583 $lbl_vis1 = L10n::t('Profile Visibility');
584 $lbl_info1 = L10n::t('Contact Information / Notes');
585 $contact_settings_label = L10n::t('Contact Settings');
589 $contact_settings_label = null;
592 $tpl = Renderer::getMarkupTemplate('contact_edit.tpl');
593 $o .= Renderer::replaceMacros($tpl, [
594 '$header' => L10n::t('Contact'),
595 '$tab_str' => $tab_str,
596 '$submit' => L10n::t('Submit'),
597 '$lbl_vis1' => $lbl_vis1,
598 '$lbl_vis2' => L10n::t('Please choose the profile you would like to display to %s when viewing your profile securely.', $contact['name']),
599 '$lbl_info1' => $lbl_info1,
600 '$lbl_info2' => L10n::t('Their personal note'),
601 '$reason' => trim(Strings::escapeTags($contact['reason'])),
602 '$infedit' => L10n::t('Edit contact notes'),
603 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
604 '$relation_text' => $relation_text,
605 '$visit' => L10n::t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']),
606 '$blockunblock' => L10n::t('Block/Unblock contact'),
607 '$ignorecont' => L10n::t('Ignore contact'),
608 '$lblcrepair' => L10n::t('Repair URL settings'),
609 '$lblrecent' => L10n::t('View conversations'),
610 '$lblsuggest' => $lblsuggest,
611 '$nettype' => $nettype,
612 '$poll_interval' => $poll_interval,
613 '$poll_enabled' => $poll_enabled,
614 '$lastupdtext' => L10n::t('Last update:'),
615 '$lost_contact' => $lost_contact,
616 '$updpub' => L10n::t('Update public posts'),
617 '$last_update' => $last_update,
618 '$udnow' => L10n::t('Update now'),
619 '$follow' => $follow,
620 '$follow_text' => $follow_text,
621 '$profile_select' => $profile_select,
622 '$contact_id' => $contact['id'],
623 '$block_text' => ($contact['blocked'] ? L10n::t('Unblock') : L10n::t('Block')),
624 '$ignore_text' => ($contact['readonly'] ? L10n::t('Unignore') : L10n::t('Ignore')),
625 '$insecure' => (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::MAIL, Protocol::DIASPORA]) ? '' : $insecure),
626 '$info' => $contact['info'],
627 '$cinfo' => ['info', '', $contact['info'], ''],
628 '$blocked' => ($contact['blocked'] ? L10n::t('Currently blocked') : ''),
629 '$ignored' => ($contact['readonly'] ? L10n::t('Currently ignored') : ''),
630 '$archived' => ($contact['archive'] ? L10n::t('Currently archived') : ''),
631 '$pending' => ($contact['pending'] ? L10n::t('Awaiting connection acknowledge') : ''),
632 '$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')],
633 '$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')],
634 '$fetch_further_information' => $fetch_further_information,
635 '$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')],
636 '$photo' => $contact['photo'],
637 '$name' => $contact['name'],
638 '$dir_icon' => $dir_icon,
639 '$sparkle' => $sparkle,
641 '$profileurllabel'=> L10n::t('Profile URL'),
642 '$profileurl' => $contact['url'],
643 '$account_type' => Model\Contact::getAccountType($contact),
644 '$location' => BBCode::convert($contact['location']),
645 '$location_label' => L10n::t('Location:'),
646 '$xmpp' => BBCode::convert($contact['xmpp']),
647 '$xmpp_label' => L10n::t('XMPP:'),
648 '$about' => BBCode::convert($contact['about'], false),
649 '$about_label' => L10n::t('About:'),
650 '$keywords' => $contact['keywords'],
651 '$keywords_label' => L10n::t('Tags:'),
652 '$contact_action_button' => L10n::t('Actions'),
653 '$contact_actions'=> $contact_actions,
654 '$contact_status' => L10n::t('Status'),
655 '$contact_settings_label' => $contact_settings_label,
656 '$contact_profile_label' => L10n::t('Profile'),
659 $arr = ['contact' => $contact, 'output' => $o];
661 Hook::callAll('contact_edit', $arr);
663 return $arr['output'];
672 if (($a->argc == 2) && ($a->argv[1] === 'all')) {
675 } elseif (($a->argc == 2) && ($a->argv[1] === 'blocked')) {
676 $sql_extra = " AND `blocked` = 1 ";
678 } elseif (($a->argc == 2) && ($a->argv[1] === 'hidden')) {
679 $sql_extra = " AND `hidden` = 1 ";
681 } elseif (($a->argc == 2) && ($a->argv[1] === 'ignored')) {
682 $sql_extra = " AND `readonly` = 1 ";
684 } elseif (($a->argc == 2) && ($a->argv[1] === 'archived')) {
685 $sql_extra = " AND `archive` = 1 ";
688 $sql_extra = " AND `blocked` = 0 ";
691 $sql_extra .= sprintf(" AND `network` != '%s' ", Protocol::PHANTOM);
693 $search = Strings::escapeTags(trim(defaults($_GET, 'search', '')));
694 $nets = Strings::escapeTags(trim(defaults($_GET, 'nets' , '')));
698 'label' => L10n::t('Suggestions'),
701 'title' => L10n::t('Suggest potential friends'),
702 'id' => 'suggestions-tab',
706 'label' => L10n::t('All Contacts'),
707 'url' => 'contact/all',
708 'sel' => ($all) ? 'active' : '',
709 'title' => L10n::t('Show all contacts'),
710 'id' => 'showall-tab',
714 'label' => L10n::t('Unblocked'),
716 'sel' => ((!$all) && (!$blocked) && (!$hidden) && (!$search) && (!$nets) && (!$ignored) && (!$archived)) ? 'active' : '',
717 'title' => L10n::t('Only show unblocked contacts'),
718 'id' => 'showunblocked-tab',
722 'label' => L10n::t('Blocked'),
723 'url' => 'contact/blocked',
724 'sel' => ($blocked) ? 'active' : '',
725 'title' => L10n::t('Only show blocked contacts'),
726 'id' => 'showblocked-tab',
730 'label' => L10n::t('Ignored'),
731 'url' => 'contact/ignored',
732 'sel' => ($ignored) ? 'active' : '',
733 'title' => L10n::t('Only show ignored contacts'),
734 'id' => 'showignored-tab',
738 'label' => L10n::t('Archived'),
739 'url' => 'contact/archived',
740 'sel' => ($archived) ? 'active' : '',
741 'title' => L10n::t('Only show archived contacts'),
742 'id' => 'showarchived-tab',
746 'label' => L10n::t('Hidden'),
747 'url' => 'contact/hidden',
748 'sel' => ($hidden) ? 'active' : '',
749 'title' => L10n::t('Only show hidden contacts'),
750 'id' => 'showhidden-tab',
754 'label' => L10n::t('Groups'),
756 'sel' => ($hidden) ? 'active' : '',
757 'title' => L10n::t('Organize your contact groups'),
758 'id' => 'contactgroups-tab',
763 $tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
764 $t = Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);
771 $search_hdr = $search;
772 $search_txt = DBA::escape(Strings::protectSprintf(preg_quote($search)));
773 $sql_extra .= " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') ";
777 $sql_extra .= sprintf(" AND network = '%s' ", DBA::escape($nets));
780 $sql_extra .= " AND NOT `deleted` ";
782 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= Model\Contact::FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : '');
784 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
785 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
786 intval($_SESSION['uid'])
788 if (DBA::isResult($r)) {
789 $total = $r[0]['total'];
791 $pager = new Pager($a->query_string);
793 $sql_extra3 = Widget::unavailableNetworks();
797 $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 ",
798 intval($_SESSION['uid']),
800 $pager->getItemsPerPage()
802 if (DBA::isResult($r)) {
803 foreach ($r as $rr) {
804 $rr['blocked'] = Model\Contact::isBlockedByUser($rr['id'], local_user());
805 $rr['readonly'] = Model\Contact::isIgnoredByUser($rr['id'], local_user());
806 $contacts[] = self::getContactTemplateVars($rr);
810 $tpl = Renderer::getMarkupTemplate('contacts-template.tpl');
811 $o .= Renderer::replaceMacros($tpl, [
812 '$baseurl' => System::baseUrl(),
813 '$header' => L10n::t('Contacts') . (($nets) ? ' - ' . ContactSelector::networkToName($nets) : ''),
816 '$search' => $search_hdr,
817 '$desc' => L10n::t('Search your contacts'),
818 '$finding' => $searching ? L10n::t('Results for: %s', $search) : '',
819 '$submit' => L10n::t('Find'),
821 '$contacts' => $contacts,
822 '$contact_drop_confirm' => L10n::t('Do you really want to delete this contact?'),
824 '$batch_actions' => [
825 'contacts_batch_update' => L10n::t('Update'),
826 'contacts_batch_block' => L10n::t('Block') . '/' . L10n::t('Unblock'),
827 'contacts_batch_ignore' => L10n::t('Ignore') . '/' . L10n::t('Unignore'),
828 'contacts_batch_archive' => L10n::t('Archive') . '/' . L10n::t('Unarchive'),
829 'contacts_batch_drop' => L10n::t('Delete'),
831 '$h_batch_actions' => L10n::t('Batch Actions'),
832 '$paginate' => $pager->renderFull($total),
839 * @brief List of pages for the Contact TabBar
841 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
844 * @param array $contact The contact array
845 * @param int $active_tab 1 if tab should be marked as active
847 * @return string HTML string of the contact page tabs buttons.
848 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
850 public static function getTabsHTML($a, $contact, $active_tab)
855 'label' => L10n::t('Status'),
856 'url' => "contact/" . $contact['id'] . "/conversations",
857 'sel' => (($active_tab == 1) ? 'active' : ''),
858 'title' => L10n::t('Conversations started by this contact'),
859 'id' => 'status-tab',
863 'label' => L10n::t('Posts and Comments'),
864 'url' => "contact/" . $contact['id'] . "/posts",
865 'sel' => (($active_tab == 2) ? 'active' : ''),
866 'title' => L10n::t('Status Messages and Posts'),
871 'label' => L10n::t('Profile'),
872 'url' => "contact/" . $contact['id'],
873 'sel' => (($active_tab == 3) ? 'active' : ''),
874 'title' => L10n::t('Profile Details'),
875 'id' => 'profile-tab',
880 // Show this tab only if there is visible friend list
881 $x = Model\GContact::countAllFriends(local_user(), $contact['id']);
883 $tabs[] = ['label' => L10n::t('Contacts'),
884 'url' => "allfriends/" . $contact['id'],
885 'sel' => (($active_tab == 4) ? 'active' : ''),
886 'title' => L10n::t('View all contacts'),
887 'id' => 'allfriends-tab',
891 // Show this tab only if there is visible common friend list
892 $common = Model\GContact::countCommonFriends(local_user(), $contact['id']);
894 $tabs[] = ['label' => L10n::t('Common Friends'),
895 'url' => "common/loc/" . local_user() . "/" . $contact['id'],
896 'sel' => (($active_tab == 5) ? 'active' : ''),
897 'title' => L10n::t('View all common friends'),
898 'id' => 'common-loc-tab',
903 if (!empty($contact['uid'])) {
904 $tabs[] = ['label' => L10n::t('Advanced'),
905 'url' => 'crepair/' . $contact['id'],
906 'sel' => (($active_tab == 6) ? 'active' : ''),
907 'title' => L10n::t('Advanced Contact Settings'),
908 'id' => 'advanced-tab',
913 $tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
914 $tab_str = Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);
919 private static function getConversationsHMTL($a, $contact_id, $update)
924 // We need the editor here to be able to reshare an item.
928 'allow_location' => $a->user['allow_location'],
929 'default_location' => $a->user['default-location'],
930 'nickname' => $a->user['nickname'],
931 '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'),
932 'acl' => ACL::getFullSelectorHTML($a->user, true),
934 'visitor' => 'block',
935 'profile_uid' => local_user(),
937 $o = status_editor($a, $x, 0, true);
941 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id, 'deleted' => false]);
944 $o .= self::getTabsHTML($a, $contact, 1);
947 if (DBA::isResult($contact)) {
948 $a->page['aside'] = '';
950 $profiledata = Model\Contact::getDetailsByURL($contact['url']);
952 if (local_user() && in_array($profiledata['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
953 $profiledata['remoteconnect'] = System::baseUrl() . '/follow?url=' . urlencode($profiledata['url']);
956 Model\Profile::load($a, '', 0, $profiledata, true);
957 $o .= Model\Contact::getPostsFromUrl($contact['url'], true, $update);
963 private static function getPostsHTML($a, $contact_id)
965 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id, 'deleted' => false]);
967 $o = self::getTabsHTML($a, $contact, 2);
969 if (DBA::isResult($contact)) {
970 $a->page['aside'] = '';
972 $profiledata = Model\Contact::getDetailsByURL($contact['url']);
974 if (local_user() && in_array($profiledata['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
975 $profiledata['remoteconnect'] = System::baseUrl() . '/follow?url=' . urlencode($profiledata['url']);
978 Model\Profile::load($a, '', 0, $profiledata, true);
979 $o .= Model\Contact::getPostsFromUrl($contact['url']);
985 public static function getContactTemplateVars(array $rr)
990 switch ($rr['rel']) {
991 case Model\Contact::FRIEND:
992 $dir_icon = 'images/lrarrow.gif';
993 $alt_text = L10n::t('Mutual Friendship');
996 case Model\Contact::FOLLOWER;
997 $dir_icon = 'images/larrow.gif';
998 $alt_text = L10n::t('is a fan of yours');
1001 case Model\Contact::SHARING;
1002 $dir_icon = 'images/rarrow.gif';
1003 $alt_text = L10n::t('you are a fan of');
1010 $url = Model\Contact::magicLink($rr['url']);
1012 if (strpos($url, 'redir/') === 0) {
1013 $sparkle = ' class="sparkle" ';
1019 $dir_icon = 'images/larrow.gif';
1020 $alt_text = L10n::t('This is you');
1026 'img_hover' => L10n::t('Visit %s\'s profile [%s]', $rr['name'], $rr['url']),
1027 'edit_hover'=> L10n::t('Edit contact'),
1028 'photo_menu'=> Model\Contact::photoMenu($rr),
1030 'alt_text' => $alt_text,
1031 'dir_icon' => $dir_icon,
1032 'thumb' => ProxyUtils::proxifyUrl($rr['thumb'], false, ProxyUtils::SIZE_THUMB),
1033 'name' => $rr['name'],
1034 'username' => $rr['name'],
1035 'account_type' => Model\Contact::getAccountType($rr),
1036 'sparkle' => $sparkle,
1037 'itemurl' => defaults($rr, 'addr', $rr['url']),
1039 'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
1040 'nick' => $rr['nick'],
1045 * @brief Gives a array with actions which can performed to a given contact
1047 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
1049 * @param array $contact Data about the Contact
1050 * @return array with contact related actions
1052 private static function getContactActions($contact)
1054 $poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
1055 $contact_actions = [];
1057 // Provide friend suggestion only for Friendica contacts
1058 if ($contact['network'] === Protocol::DFRN) {
1059 $contact_actions['suggest'] = [
1060 'label' => L10n::t('Suggest friends'),
1061 'url' => 'fsuggest/' . $contact['id'],
1068 if ($poll_enabled) {
1069 $contact_actions['update'] = [
1070 'label' => L10n::t('Update now'),
1071 'url' => 'contact/' . $contact['id'] . '/update',
1078 $contact_actions['block'] = [
1079 'label' => (intval($contact['blocked']) ? L10n::t('Unblock') : L10n::t('Block')),
1080 'url' => 'contact/' . $contact['id'] . '/block',
1081 'title' => L10n::t('Toggle Blocked status'),
1082 'sel' => (intval($contact['blocked']) ? 'active' : ''),
1083 'id' => 'toggle-block',
1086 $contact_actions['ignore'] = [
1087 'label' => (intval($contact['readonly']) ? L10n::t('Unignore') : L10n::t('Ignore')),
1088 'url' => 'contact/' . $contact['id'] . '/ignore',
1089 'title' => L10n::t('Toggle Ignored status'),
1090 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1091 'id' => 'toggle-ignore',
1094 if ($contact['uid'] != 0) {
1095 $contact_actions['archive'] = [
1096 'label' => (intval($contact['archive']) ? L10n::t('Unarchive') : L10n::t('Archive')),
1097 'url' => 'contact/' . $contact['id'] . '/archive',
1098 'title' => L10n::t('Toggle Archive status'),
1099 'sel' => (intval($contact['archive']) ? 'active' : ''),
1100 'id' => 'toggle-archive',
1103 $contact_actions['delete'] = [
1104 'label' => L10n::t('Delete'),
1105 'url' => 'contact/' . $contact['id'] . '/drop',
1106 'title' => L10n::t('Delete contact'),
1112 return $contact_actions;