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 if ($a->argc == 2 && intval($a->argv[1])
50 || $a->argc == 3 && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])
52 $contact_id = intval($a->argv[1]);
53 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
55 if (!DBA::isResult($contact)) {
56 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => 0, 'deleted' => false]);
59 // Don't display contacts that are about to be deleted
60 if ($contact['network'] == Protocol::PHANTOM) {
65 if (DBA::isResult($contact)) {
66 if ($contact['self']) {
67 if (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])) {
68 $a->internalRedirect('profile/' . $contact['nick']);
70 $a->internalRedirect('profile/' . $contact['nick'] . '?tab=profile');
74 $a->data['contact'] = $contact;
76 if (($contact['network'] != '') && ($contact['network'] != Protocol::DFRN)) {
77 $network_link = Strings::formatNetworkName($contact['network'], $contact['url']);
82 $vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('vcard-widget.tpl'), [
83 '$name' => $contact['name'],
84 '$photo' => $contact['photo'],
85 '$url' => Model\Contact::MagicLink($contact['url']),
86 '$addr' => defaults($contact, 'addr', ''),
87 '$network_link' => $network_link,
88 '$network' => L10n::t('Network:'),
89 '$account_type' => Model\Contact::getAccountType($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'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('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 = Renderer::getMarkupTemplate('contacts-head.tpl');
123 $a->page['htmlhead'] .= Renderer::replaceMacros($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', 'archive'], ['id' => $contacts_id, 'uid' => local_user(), 'self' => false, 'deleted' => 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));
169 $a->internalRedirect('contact');
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(), 'deleted' => false])) {
191 notice(L10n::t('Could not access contact record.') . EOL);
192 $a->internalRedirect('contact');
193 return; // NOTREACHED
196 Hook::callAll('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 = Strings::escapeHtml(trim(defaults($_POST, 'ffi_keyword_blacklist', '')));
214 $priority = intval(defaults($_POST, 'poll', 0));
215 if ($priority > 5 || $priority < 0) {
219 $info = Strings::escapeHtml(trim(defaults($_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()]
232 if (DBA::isResult($r)) {
233 info(L10n::t('Contact updated.') . EOL);
235 notice(L10n::t('Failed to update contact record.') . EOL);
238 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
239 if (DBA::isResult($contact)) {
240 $a->data['contact'] = $contact;
246 /* contact actions */
248 private static function updateContactFromPoll($contact_id)
250 $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
251 if (!DBA::isResult($contact)) {
255 $uid = $contact['uid'];
257 if ($contact['network'] == Protocol::OSTATUS) {
258 $result = Model\Contact::createFromProbe($uid, $contact['url'], false, $contact['network']);
260 if ($result['success']) {
261 DBA::update('contact', ['subhub' => 1], ['id' => $contact_id]);
264 // pull feed and consume it, which should subscribe to the hub.
265 Worker::add(PRIORITY_HIGH, 'OnePoll', $contact_id, 'force');
269 private static function updateContactFromProbe($contact_id)
271 $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
272 if (!DBA::isResult($contact)) {
276 $uid = $contact['uid'];
278 $data = Probe::uri($contact['url'], '', 0, false);
280 // 'Feed' or 'Unknown' is mostly a sign of communication problems
281 if ((in_array($data['network'], [Protocol::FEED, Protocol::PHANTOM])) && ($data['network'] != $contact['network'])) {
285 $updatefields = ['name', 'nick', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'network', 'alias'];
288 if ($data['network'] == Protocol::OSTATUS) {
289 $result = Model\Contact::createFromProbe($uid, $data['url'], false);
291 if ($result['success']) {
292 $fields['subhub'] = true;
296 foreach ($updatefields AS $field) {
297 if (!empty($data[$field])) {
298 $fields[$field] = $data[$field];
302 $fields['nurl'] = Strings::normaliseLink($data['url']);
304 if (!empty($data['priority'])) {
305 $fields['priority'] = intval($data['priority']);
308 if (empty($fields)) {
312 DBA::update('contact', $fields, ['id' => $contact_id, 'uid' => local_user()]);
314 // Update the entry in the contact table
315 Model\Contact::updateAvatar($data['photo'], local_user(), $contact_id, true);
317 // Update the entry in the gcontact table
318 Model\GContact::updateFromProbe($data['url']);
321 private static function blockContact($contact_id)
323 $blocked = !Model\Contact::isBlockedByUser($contact_id, local_user());
324 Model\Contact::setBlockedForUser($contact_id, local_user(), $blocked);
327 private static function ignoreContact($contact_id)
329 $ignored = !Model\Contact::isIgnoredByUser($contact_id, local_user());
330 Model\Contact::setIgnoredForUser($contact_id, local_user(), $ignored);
333 private static function archiveContact($contact_id, $orig_record)
335 $archived = (defaults($orig_record, 'archive', '') ? 0 : 1);
336 $r = DBA::update('contact', ['archive' => $archived], ['id' => $contact_id, 'uid' => local_user()]);
338 return DBA::isResult($r);
341 private static function dropContact($orig_record)
343 $owner = Model\User::getOwnerDataById(local_user());
344 if (!DBA::isResult($owner)) {
348 Model\Contact::terminateFriendship($owner, $orig_record, true);
349 Model\Contact::remove($orig_record['id']);
352 public static function content($update = 0)
357 Nav::setSelected('contact');
360 notice(L10n::t('Permission denied.') . EOL);
361 return Login::form();
365 $contact_id = intval($a->argv[1]);
372 $orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'self' => false, 'deleted' => false]);
373 if (!DBA::isResult($orig_record)) {
374 notice(L10n::t('Could not access contact record.') . EOL);
375 $a->internalRedirect('contact');
376 return; // NOTREACHED
379 if ($cmd === 'update' && ($orig_record['uid'] != 0)) {
380 self::updateContactFromPoll($contact_id);
381 $a->internalRedirect('contact/' . $contact_id);
385 if ($cmd === 'updateprofile' && ($orig_record['uid'] != 0)) {
386 self::updateContactFromProbe($contact_id);
387 $a->internalRedirect('crepair/' . $contact_id);
391 if ($cmd === 'block') {
392 self::blockContact($contact_id);
394 $blocked = Model\Contact::isBlockedByUser($contact_id, local_user());
395 info(($blocked ? L10n::t('Contact has been blocked') : L10n::t('Contact has been unblocked')) . EOL);
397 $a->internalRedirect('contact/' . $contact_id);
398 return; // NOTREACHED
401 if ($cmd === 'ignore') {
402 self::ignoreContact($contact_id);
404 $ignored = Model\Contact::isIgnoredByUser($contact_id, local_user());
405 info(($ignored ? L10n::t('Contact has been ignored') : L10n::t('Contact has been unignored')) . EOL);
407 $a->internalRedirect('contact/' . $contact_id);
408 return; // NOTREACHED
411 if ($cmd === 'archive' && ($orig_record['uid'] != 0)) {
412 $r = self::archiveContact($contact_id, $orig_record);
414 $archived = (($orig_record['archive']) ? 0 : 1);
415 info((($archived) ? L10n::t('Contact has been archived') : L10n::t('Contact has been unarchived')) . EOL);
418 $a->internalRedirect('contact/' . $contact_id);
419 return; // NOTREACHED
422 if ($cmd === 'drop' && ($orig_record['uid'] != 0)) {
423 // Check if we should do HTML-based delete confirmation
424 if (!empty($_REQUEST['confirm'])) {
425 // <form> can't take arguments in its 'action' parameter
426 // so add any arguments as hidden inputs
427 $query = explode_querystring($a->query_string);
429 foreach ($query['args'] as $arg) {
430 if (strpos($arg, 'confirm=') === false) {
431 $arg_parts = explode('=', $arg);
432 $inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]];
436 $a->page['aside'] = '';
438 return Renderer::replaceMacros(Renderer::getMarkupTemplate('contact_drop_confirm.tpl'), [
439 '$header' => L10n::t('Drop contact'),
440 '$contact' => self::getContactTemplateVars($orig_record),
442 '$message' => L10n::t('Do you really want to delete this contact?'),
443 '$extra_inputs' => $inputs,
444 '$confirm' => L10n::t('Yes'),
445 '$confirm_url' => $query['base'],
446 '$confirm_name' => 'confirmed',
447 '$cancel' => L10n::t('Cancel'),
450 // Now check how the user responded to the confirmation query
451 if (!empty($_REQUEST['canceled'])) {
452 $a->internalRedirect('contact');
455 self::dropContact($orig_record);
456 info(L10n::t('Contact has been removed.') . EOL);
458 $a->internalRedirect('contact');
459 return; // NOTREACHED
461 if ($cmd === 'posts') {
462 return self::getPostsHTML($a, $contact_id);
464 if ($cmd === 'conversations') {
465 return self::getConversationsHMTL($a, $contact_id, $update);
469 $_SESSION['return_path'] = $a->query_string;
471 if (!empty($a->data['contact']) && is_array($a->data['contact'])) {
472 $contact = $a->data['contact'];
474 $a->page['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('contact_head.tpl'), [
475 '$baseurl' => $a->getBaseURL(true),
478 $contact['blocked'] = Model\Contact::isBlockedByUser($contact['id'], local_user());
479 $contact['readonly'] = Model\Contact::isIgnoredByUser($contact['id'], local_user());
483 switch ($contact['rel']) {
484 case Model\Contact::FRIEND:
485 $dir_icon = 'images/lrarrow.gif';
486 $relation_text = L10n::t('You are mutual friends with %s');
489 case Model\Contact::FOLLOWER;
490 $dir_icon = 'images/larrow.gif';
491 $relation_text = L10n::t('You are sharing with %s');
494 case Model\Contact::SHARING;
495 $dir_icon = 'images/rarrow.gif';
496 $relation_text = L10n::t('%s is sharing with you');
503 if ($contact['uid'] == 0) {
507 if (!in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
511 $relation_text = sprintf($relation_text, $contact['name']);
513 $url = Model\Contact::magicLink($contact['url']);
514 if (strpos($url, 'redir/') === 0) {
515 $sparkle = ' class="sparkle" ';
520 $insecure = L10n::t('Private communications are not available for this contact.');
522 $last_update = (($contact['last-update'] <= DBA::NULL_DATETIME) ? L10n::t('Never') : DateTimeFormat::local($contact['last-update'], 'D, j M Y, g:i A'));
524 if ($contact['last-update'] > DBA::NULL_DATETIME) {
525 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? L10n::t('(Update was successful)') : L10n::t('(Update was not successful)'));
527 $lblsuggest = (($contact['network'] === Protocol::DFRN) ? L10n::t('Suggest friends') : '');
529 $poll_enabled = in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
531 $nettype = L10n::t('Network type: %s', ContactSelector::networkToName($contact['network'], $contact['url']));
534 $tab_str = self::getTabsHTML($a, $contact, 3);
536 $lost_contact = (($contact['archive'] && $contact['term-date'] > DBA::NULL_DATETIME && $contact['term-date'] < DateTimeFormat::utcNow()) ? L10n::t('Communications lost with this contact!') : '');
538 $fetch_further_information = null;
539 if ($contact['network'] == Protocol::FEED) {
540 $fetch_further_information = [
541 'fetch_further_information',
542 L10n::t('Fetch further information for feeds'),
543 $contact['fetch_further_information'],
544 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.'),
546 '0' => L10n::t('Disabled'),
547 '1' => L10n::t('Fetch information'),
548 '3' => L10n::t('Fetch keywords'),
549 '2' => L10n::t('Fetch information and keywords')
554 $poll_interval = null;
555 if (in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
556 $poll_interval = ContactSelector::pollInterval($contact['priority'], !$poll_enabled);
559 $profile_select = null;
560 if ($contact['network'] == Protocol::DFRN) {
561 $profile_select = ContactSelector::profileAssign($contact['profile-id'], $contact['network'] !== Protocol::DFRN);
564 /// @todo Only show the following link with DFRN when the remote version supports it
567 if ($contact['uid'] && in_array($contact['rel'], [Model\Contact::FRIEND, Model\Contact::SHARING])) {
568 if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
569 $follow = $a->getBaseURL(true) . '/unfollow?url=' . urlencode($contact['url']);
570 $follow_text = L10n::t('Disconnect/Unfollow');
572 } elseif(!$contact['pending']) {
573 $follow = $a->getBaseURL(true) . '/follow?url=' . urlencode($contact['url']);
574 $follow_text = L10n::t('Connect/Follow');
577 // Load contactact related actions like hide, suggest, delete and others
578 $contact_actions = self::getContactActions($contact);
580 if ($contact['uid'] != 0) {
581 $lbl_vis1 = L10n::t('Profile Visibility');
582 $lbl_info1 = L10n::t('Contact Information / Notes');
583 $contact_settings_label = L10n::t('Contact Settings');
587 $contact_settings_label = null;
590 $tpl = Renderer::getMarkupTemplate('contact_edit.tpl');
591 $o .= Renderer::replaceMacros($tpl, [
592 '$header' => L10n::t('Contact'),
593 '$tab_str' => $tab_str,
594 '$submit' => L10n::t('Submit'),
595 '$lbl_vis1' => $lbl_vis1,
596 '$lbl_vis2' => L10n::t('Please choose the profile you would like to display to %s when viewing your profile securely.', $contact['name']),
597 '$lbl_info1' => $lbl_info1,
598 '$lbl_info2' => L10n::t('Their personal note'),
599 '$reason' => trim(Strings::escapeTags($contact['reason'])),
600 '$infedit' => L10n::t('Edit contact notes'),
601 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
602 '$relation_text' => $relation_text,
603 '$visit' => L10n::t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']),
604 '$blockunblock' => L10n::t('Block/Unblock contact'),
605 '$ignorecont' => L10n::t('Ignore contact'),
606 '$lblcrepair' => L10n::t('Repair URL settings'),
607 '$lblrecent' => L10n::t('View conversations'),
608 '$lblsuggest' => $lblsuggest,
609 '$nettype' => $nettype,
610 '$poll_interval' => $poll_interval,
611 '$poll_enabled' => $poll_enabled,
612 '$lastupdtext' => L10n::t('Last update:'),
613 '$lost_contact' => $lost_contact,
614 '$updpub' => L10n::t('Update public posts'),
615 '$last_update' => $last_update,
616 '$udnow' => L10n::t('Update now'),
617 '$follow' => $follow,
618 '$follow_text' => $follow_text,
619 '$profile_select' => $profile_select,
620 '$contact_id' => $contact['id'],
621 '$block_text' => ($contact['blocked'] ? L10n::t('Unblock') : L10n::t('Block')),
622 '$ignore_text' => ($contact['readonly'] ? L10n::t('Unignore') : L10n::t('Ignore')),
623 '$insecure' => (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::MAIL, Protocol::DIASPORA]) ? '' : $insecure),
624 '$info' => $contact['info'],
625 '$cinfo' => ['info', '', $contact['info'], ''],
626 '$blocked' => ($contact['blocked'] ? L10n::t('Currently blocked') : ''),
627 '$ignored' => ($contact['readonly'] ? L10n::t('Currently ignored') : ''),
628 '$archived' => ($contact['archive'] ? L10n::t('Currently archived') : ''),
629 '$pending' => ($contact['pending'] ? L10n::t('Awaiting connection acknowledge') : ''),
630 '$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')],
631 '$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')],
632 '$fetch_further_information' => $fetch_further_information,
633 '$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')],
634 '$photo' => $contact['photo'],
635 '$name' => $contact['name'],
636 '$dir_icon' => $dir_icon,
637 '$sparkle' => $sparkle,
639 '$profileurllabel'=> L10n::t('Profile URL'),
640 '$profileurl' => $contact['url'],
641 '$account_type' => Model\Contact::getAccountType($contact),
642 '$location' => BBCode::convert($contact['location']),
643 '$location_label' => L10n::t('Location:'),
644 '$xmpp' => BBCode::convert($contact['xmpp']),
645 '$xmpp_label' => L10n::t('XMPP:'),
646 '$about' => BBCode::convert($contact['about'], false),
647 '$about_label' => L10n::t('About:'),
648 '$keywords' => $contact['keywords'],
649 '$keywords_label' => L10n::t('Tags:'),
650 '$contact_action_button' => L10n::t('Actions'),
651 '$contact_actions'=> $contact_actions,
652 '$contact_status' => L10n::t('Status'),
653 '$contact_settings_label' => $contact_settings_label,
654 '$contact_profile_label' => L10n::t('Profile'),
657 $arr = ['contact' => $contact, 'output' => $o];
659 Hook::callAll('contact_edit', $arr);
661 return $arr['output'];
670 if (($a->argc == 2) && ($a->argv[1] === 'all')) {
673 } elseif (($a->argc == 2) && ($a->argv[1] === 'blocked')) {
674 $sql_extra = " AND `blocked` = 1 ";
676 } elseif (($a->argc == 2) && ($a->argv[1] === 'hidden')) {
677 $sql_extra = " AND `hidden` = 1 ";
679 } elseif (($a->argc == 2) && ($a->argv[1] === 'ignored')) {
680 $sql_extra = " AND `readonly` = 1 ";
682 } elseif (($a->argc == 2) && ($a->argv[1] === 'archived')) {
683 $sql_extra = " AND `archive` = 1 ";
686 $sql_extra = " AND `blocked` = 0 ";
689 $sql_extra .= sprintf(" AND `network` != '%s' ", Protocol::PHANTOM);
691 $search = Strings::escapeTags(trim(defaults($_GET, 'search', '')));
692 $nets = Strings::escapeTags(trim(defaults($_GET, 'nets' , '')));
696 'label' => L10n::t('Suggestions'),
699 'title' => L10n::t('Suggest potential friends'),
700 'id' => 'suggestions-tab',
704 'label' => L10n::t('All Contacts'),
705 'url' => 'contact/all',
706 'sel' => ($all) ? 'active' : '',
707 'title' => L10n::t('Show all contacts'),
708 'id' => 'showall-tab',
712 'label' => L10n::t('Unblocked'),
714 'sel' => ((!$all) && (!$blocked) && (!$hidden) && (!$search) && (!$nets) && (!$ignored) && (!$archived)) ? 'active' : '',
715 'title' => L10n::t('Only show unblocked contacts'),
716 'id' => 'showunblocked-tab',
720 'label' => L10n::t('Blocked'),
721 'url' => 'contact/blocked',
722 'sel' => ($blocked) ? 'active' : '',
723 'title' => L10n::t('Only show blocked contacts'),
724 'id' => 'showblocked-tab',
728 'label' => L10n::t('Ignored'),
729 'url' => 'contact/ignored',
730 'sel' => ($ignored) ? 'active' : '',
731 'title' => L10n::t('Only show ignored contacts'),
732 'id' => 'showignored-tab',
736 'label' => L10n::t('Archived'),
737 'url' => 'contact/archived',
738 'sel' => ($archived) ? 'active' : '',
739 'title' => L10n::t('Only show archived contacts'),
740 'id' => 'showarchived-tab',
744 'label' => L10n::t('Hidden'),
745 'url' => 'contact/hidden',
746 'sel' => ($hidden) ? 'active' : '',
747 'title' => L10n::t('Only show hidden contacts'),
748 'id' => 'showhidden-tab',
752 'label' => L10n::t('Groups'),
754 'sel' => ($hidden) ? 'active' : '',
755 'title' => L10n::t('Organize your contact groups'),
756 'id' => 'contactgroups-tab',
761 $tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
762 $t = Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);
769 $search_hdr = $search;
770 $search_txt = DBA::escape(Strings::protectSprintf(preg_quote($search)));
771 $sql_extra .= " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') ";
775 $sql_extra .= sprintf(" AND network = '%s' ", DBA::escape($nets));
778 $sql_extra .= " AND NOT `deleted` ";
780 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= Model\Contact::FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : '');
782 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
783 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
784 intval($_SESSION['uid'])
786 if (DBA::isResult($r)) {
787 $total = $r[0]['total'];
789 $pager = new Pager($a->query_string);
791 $sql_extra3 = Widget::unavailableNetworks();
795 $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 ",
796 intval($_SESSION['uid']),
798 $pager->getItemsPerPage()
800 if (DBA::isResult($r)) {
801 foreach ($r as $rr) {
802 $rr['blocked'] = Model\Contact::isBlockedByUser($rr['id'], local_user());
803 $rr['readonly'] = Model\Contact::isIgnoredByUser($rr['id'], local_user());
804 $contacts[] = self::getContactTemplateVars($rr);
808 $tpl = Renderer::getMarkupTemplate('contacts-template.tpl');
809 $o .= Renderer::replaceMacros($tpl, [
810 '$baseurl' => System::baseUrl(),
811 '$header' => L10n::t('Contacts') . (($nets) ? ' - ' . ContactSelector::networkToName($nets) : ''),
814 '$search' => $search_hdr,
815 '$desc' => L10n::t('Search your contacts'),
816 '$finding' => $searching ? L10n::t('Results for: %s', $search) : '',
817 '$submit' => L10n::t('Find'),
819 '$contacts' => $contacts,
820 '$contact_drop_confirm' => L10n::t('Do you really want to delete this contact?'),
822 '$batch_actions' => [
823 'contacts_batch_update' => L10n::t('Update'),
824 'contacts_batch_block' => L10n::t('Block') . '/' . L10n::t('Unblock'),
825 'contacts_batch_ignore' => L10n::t('Ignore') . '/' . L10n::t('Unignore'),
826 'contacts_batch_archive' => L10n::t('Archive') . '/' . L10n::t('Unarchive'),
827 'contacts_batch_drop' => L10n::t('Delete'),
829 '$h_batch_actions' => L10n::t('Batch Actions'),
830 '$paginate' => $pager->renderFull($total),
837 * @brief List of pages for the Contact TabBar
839 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
842 * @param array $contact The contact array
843 * @param int $active_tab 1 if tab should be marked as active
845 * @return string HTML string of the contact page tabs buttons.
846 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
848 public static function getTabsHTML($a, $contact, $active_tab)
853 'label' => L10n::t('Status'),
854 'url' => "contact/" . $contact['id'] . "/conversations",
855 'sel' => (($active_tab == 1) ? 'active' : ''),
856 'title' => L10n::t('Conversations started by this contact'),
857 'id' => 'status-tab',
861 'label' => L10n::t('Posts and Comments'),
862 'url' => "contact/" . $contact['id'] . "/posts",
863 'sel' => (($active_tab == 2) ? 'active' : ''),
864 'title' => L10n::t('Status Messages and Posts'),
869 'label' => L10n::t('Profile'),
870 'url' => "contact/" . $contact['id'],
871 'sel' => (($active_tab == 3) ? 'active' : ''),
872 'title' => L10n::t('Profile Details'),
873 'id' => 'profile-tab',
878 // Show this tab only if there is visible friend list
879 $x = Model\GContact::countAllFriends(local_user(), $contact['id']);
881 $tabs[] = ['label' => L10n::t('Contacts'),
882 'url' => "allfriends/" . $contact['id'],
883 'sel' => (($active_tab == 4) ? 'active' : ''),
884 'title' => L10n::t('View all contacts'),
885 'id' => 'allfriends-tab',
889 // Show this tab only if there is visible common friend list
890 $common = Model\GContact::countCommonFriends(local_user(), $contact['id']);
892 $tabs[] = ['label' => L10n::t('Common Friends'),
893 'url' => "common/loc/" . local_user() . "/" . $contact['id'],
894 'sel' => (($active_tab == 5) ? 'active' : ''),
895 'title' => L10n::t('View all common friends'),
896 'id' => 'common-loc-tab',
901 if (!empty($contact['uid'])) {
902 $tabs[] = ['label' => L10n::t('Advanced'),
903 'url' => 'crepair/' . $contact['id'],
904 'sel' => (($active_tab == 6) ? 'active' : ''),
905 'title' => L10n::t('Advanced Contact Settings'),
906 'id' => 'advanced-tab',
911 $tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
912 $tab_str = Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);
917 private static function getConversationsHMTL($a, $contact_id, $update)
922 // We need the editor here to be able to reshare an item.
926 'allow_location' => $a->user['allow_location'],
927 'default_location' => $a->user['default-location'],
928 'nickname' => $a->user['nickname'],
929 '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'),
930 'acl' => ACL::getFullSelectorHTML($a->user, true),
932 'visitor' => 'block',
933 'profile_uid' => local_user(),
935 $o = status_editor($a, $x, 0, true);
939 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id, 'deleted' => false]);
942 $o .= self::getTabsHTML($a, $contact, 1);
945 if (DBA::isResult($contact)) {
946 $a->page['aside'] = '';
948 $profiledata = Model\Contact::getDetailsByURL($contact['url']);
950 if (local_user() && in_array($profiledata['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
951 $profiledata['remoteconnect'] = System::baseUrl() . '/follow?url=' . urlencode($profiledata['url']);
954 Model\Profile::load($a, '', 0, $profiledata, true);
955 $o .= Model\Contact::getPostsFromUrl($contact['url'], true, $update);
961 private static function getPostsHTML($a, $contact_id)
963 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id, 'deleted' => false]);
965 $o = self::getTabsHTML($a, $contact, 2);
967 if (DBA::isResult($contact)) {
968 $a->page['aside'] = '';
970 $profiledata = Model\Contact::getDetailsByURL($contact['url']);
972 if (local_user() && in_array($profiledata['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
973 $profiledata['remoteconnect'] = System::baseUrl() . '/follow?url=' . urlencode($profiledata['url']);
976 Model\Profile::load($a, '', 0, $profiledata, true);
977 $o .= Model\Contact::getPostsFromUrl($contact['url']);
983 public static function getContactTemplateVars(array $rr)
988 switch ($rr['rel']) {
989 case Model\Contact::FRIEND:
990 $dir_icon = 'images/lrarrow.gif';
991 $alt_text = L10n::t('Mutual Friendship');
994 case Model\Contact::FOLLOWER;
995 $dir_icon = 'images/larrow.gif';
996 $alt_text = L10n::t('is a fan of yours');
999 case Model\Contact::SHARING;
1000 $dir_icon = 'images/rarrow.gif';
1001 $alt_text = L10n::t('you are a fan of');
1008 $url = Model\Contact::magicLink($rr['url']);
1010 if (strpos($url, 'redir/') === 0) {
1011 $sparkle = ' class="sparkle" ';
1017 $dir_icon = 'images/larrow.gif';
1018 $alt_text = L10n::t('This is you');
1024 'img_hover' => L10n::t('Visit %s\'s profile [%s]', $rr['name'], $rr['url']),
1025 'edit_hover'=> L10n::t('Edit contact'),
1026 'photo_menu'=> Model\Contact::photoMenu($rr),
1028 'alt_text' => $alt_text,
1029 'dir_icon' => $dir_icon,
1030 'thumb' => ProxyUtils::proxifyUrl($rr['thumb'], false, ProxyUtils::SIZE_THUMB),
1031 'name' => $rr['name'],
1032 'username' => $rr['name'],
1033 'account_type' => Model\Contact::getAccountType($rr),
1034 'sparkle' => $sparkle,
1035 'itemurl' => defaults($rr, 'addr', $rr['url']),
1037 'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
1038 'nick' => $rr['nick'],
1043 * @brief Gives a array with actions which can performed to a given contact
1045 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
1047 * @param array $contact Data about the Contact
1048 * @return array with contact related actions
1050 private static function getContactActions($contact)
1052 $poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
1053 $contact_actions = [];
1055 // Provide friend suggestion only for Friendica contacts
1056 if ($contact['network'] === Protocol::DFRN) {
1057 $contact_actions['suggest'] = [
1058 'label' => L10n::t('Suggest friends'),
1059 'url' => 'fsuggest/' . $contact['id'],
1066 if ($poll_enabled) {
1067 $contact_actions['update'] = [
1068 'label' => L10n::t('Update now'),
1069 'url' => 'contact/' . $contact['id'] . '/update',
1076 $contact_actions['block'] = [
1077 'label' => (intval($contact['blocked']) ? L10n::t('Unblock') : L10n::t('Block')),
1078 'url' => 'contact/' . $contact['id'] . '/block',
1079 'title' => L10n::t('Toggle Blocked status'),
1080 'sel' => (intval($contact['blocked']) ? 'active' : ''),
1081 'id' => 'toggle-block',
1084 $contact_actions['ignore'] = [
1085 'label' => (intval($contact['readonly']) ? L10n::t('Unignore') : L10n::t('Ignore')),
1086 'url' => 'contact/' . $contact['id'] . '/ignore',
1087 'title' => L10n::t('Toggle Ignored status'),
1088 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1089 'id' => 'toggle-ignore',
1092 if ($contact['uid'] != 0) {
1093 $contact_actions['archive'] = [
1094 'label' => (intval($contact['archive']) ? L10n::t('Unarchive') : L10n::t('Archive')),
1095 'url' => 'contact/' . $contact['id'] . '/archive',
1096 'title' => L10n::t('Toggle Archive status'),
1097 'sel' => (intval($contact['archive']) ? 'active' : ''),
1098 'id' => 'toggle-archive',
1101 $contact_actions['delete'] = [
1102 'label' => L10n::t('Delete'),
1103 'url' => 'contact/' . $contact['id'] . '/drop',
1104 'title' => L10n::t('Delete contact'),
1110 return $contact_actions;