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\Module\Login;
22 use Friendica\Network\Probe;
23 use Friendica\Util\DateTimeFormat;
24 use Friendica\Util\Proxy as ProxyUtils;
25 use Friendica\Util\Strings;
28 * Manages and show Contacts and their content
30 * @brief manages contacts
32 class Contact extends BaseModule
34 public static function init()
42 $nets = defaults($_GET, 'nets', '');
44 if (empty($a->page['aside'])) {
45 $a->page['aside'] = '';
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 if (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])) {
69 $a->internalRedirect('profile/' . $contact['nick']);
71 $a->internalRedirect('profile/' . $contact['nick'] . '?tab=profile');
75 $a->data['contact'] = $contact;
77 if (($contact['network'] != '') && ($contact['network'] != Protocol::DFRN)) {
78 $network_link = Strings::formatNetworkName($contact['network'], $contact['url']);
83 $vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('vcard-widget.tpl'), [
84 '$name' => $contact['name'],
85 '$photo' => $contact['photo'],
86 '$url' => Model\Contact::MagicLink($contact['url']),
87 '$addr' => defaults($contact, 'addr', ''),
88 '$network_link' => $network_link,
89 '$network' => L10n::t('Network:'),
90 '$account_type' => Model\Contact::getAccountType($contact)
93 $findpeople_widget = '';
95 $networks_widget = '';
98 $networks_widget = Widget::networks('contact', $nets);
99 if (isset($_GET['add'])) {
100 $follow_widget = Widget::follow($_GET['add']);
102 $follow_widget = Widget::follow();
105 $findpeople_widget = Widget::findPeople();
108 if ($contact['uid'] != 0) {
109 $groups_widget = Model\Group::sidebarWidget('contact', 'group', 'full', 'everyone', $contact_id);
111 $groups_widget = null;
114 $a->page['aside'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('contacts-widget-sidebar.tpl'), [
115 '$vcard_widget' => $vcard_widget,
116 '$findpeople_widget' => $findpeople_widget,
117 '$follow_widget' => $follow_widget,
118 '$groups_widget' => $groups_widget,
119 '$networks_widget' => $networks_widget
122 $base = $a->getBaseURL();
123 $tpl = Renderer::getMarkupTemplate('contacts-head.tpl');
124 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl, [
125 '$baseurl' => System::baseUrl(true),
130 private static function batchActions(App $a)
132 if (empty($_POST['contact_batch']) || !is_array($_POST['contact_batch'])) {
136 $contacts_id = $_POST['contact_batch'];
138 $stmt = DBA::select('contact', ['id', 'archive'], ['id' => $contacts_id, 'uid' => local_user(), 'self' => false, 'deleted' => false]);
139 $orig_records = DBA::toArray($stmt);
142 foreach ($orig_records as $orig_record) {
143 $contact_id = $orig_record['id'];
144 if (!empty($_POST['contacts_batch_update'])) {
145 self::updateContactFromPoll($contact_id);
148 if (!empty($_POST['contacts_batch_block'])) {
149 self::blockContact($contact_id);
152 if (!empty($_POST['contacts_batch_ignore'])) {
153 self::ignoreContact($contact_id);
156 if (!empty($_POST['contacts_batch_archive'])
157 && self::archiveContact($contact_id, $orig_record)
161 if (!empty($_POST['contacts_batch_drop'])) {
162 self::dropContact($orig_record);
166 if ($count_actions > 0) {
167 info(L10n::tt('%d contact edited.', '%d contacts edited.', $count_actions));
170 $a->internalRedirect('contact');
173 public static function post()
181 if ($a->argv[1] === 'batch') {
182 self::batchActions($a);
186 $contact_id = intval($a->argv[1]);
191 if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false])) {
192 notice(L10n::t('Could not access contact record.') . EOL);
193 $a->internalRedirect('contact');
194 return; // NOTREACHED
197 Hook::callAll('contact_edit_post', $_POST);
199 $profile_id = intval(defaults($_POST, 'profile-assign', 0));
201 if (!DBA::exists('profile', ['id' => $profile_id, 'uid' => local_user(), 'deleted' => false])) {
202 notice(L10n::t('Could not locate selected profile.') . EOL);
207 $hidden = !empty($_POST['hidden']);
209 $notify = !empty($_POST['notify']);
211 $fetch_further_information = intval(defaults($_POST, 'fetch_further_information', 0));
213 $ffi_keyword_blacklist = Strings::escapeHtml(trim(defaults($_POST, 'ffi_keyword_blacklist', '')));
215 $priority = intval(defaults($_POST, 'poll', 0));
216 if ($priority > 5 || $priority < 0) {
220 $info = Strings::escapeHtml(trim(defaults($_POST, 'info', '')));
222 $r = DBA::update('contact', [
223 'profile-id' => $profile_id,
224 'priority' => $priority,
227 'notify_new_posts' => $notify,
228 'fetch_further_information' => $fetch_further_information,
229 'ffi_keyword_blacklist' => $ffi_keyword_blacklist],
230 ['id' => $contact_id, 'uid' => local_user()]
233 if (DBA::isResult($r)) {
234 info(L10n::t('Contact updated.') . EOL);
236 notice(L10n::t('Failed to update contact record.') . EOL);
239 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
240 if (DBA::isResult($contact)) {
241 $a->data['contact'] = $contact;
247 /* contact actions */
249 private static function updateContactFromPoll($contact_id)
251 $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
252 if (!DBA::isResult($contact)) {
256 $uid = $contact['uid'];
258 if ($contact['network'] == Protocol::OSTATUS) {
259 $result = Model\Contact::createFromProbe($uid, $contact['url'], false, $contact['network']);
261 if ($result['success']) {
262 DBA::update('contact', ['subhub' => 1], ['id' => $contact_id]);
265 // pull feed and consume it, which should subscribe to the hub.
266 Worker::add(PRIORITY_HIGH, 'OnePoll', $contact_id, 'force');
270 private static function updateContactFromProbe($contact_id)
272 $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
273 if (!DBA::isResult($contact)) {
277 $uid = $contact['uid'];
279 $data = Probe::uri($contact['url'], '', 0, false);
281 // 'Feed' or 'Unknown' is mostly a sign of communication problems
282 if ((in_array($data['network'], [Protocol::FEED, Protocol::PHANTOM])) && ($data['network'] != $contact['network'])) {
286 $updatefields = ['name', 'nick', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'network', 'alias'];
289 if ($data['network'] == Protocol::OSTATUS) {
290 $result = Model\Contact::createFromProbe($uid, $data['url'], false);
292 if ($result['success']) {
293 $fields['subhub'] = true;
297 foreach ($updatefields AS $field) {
298 if (!empty($data[$field])) {
299 $fields[$field] = $data[$field];
303 $fields['nurl'] = Strings::normaliseLink($data['url']);
305 if (!empty($data['priority'])) {
306 $fields['priority'] = intval($data['priority']);
309 if (empty($fields)) {
313 $r = DBA::update('contact', $fields, ['id' => $contact_id, 'uid' => local_user()]);
315 // Update the entry in the contact table
316 Model\Contact::updateAvatar($data['photo'], local_user(), $contact_id, true);
318 // Update the entry in the gcontact table
319 Model\GContact::updateFromProbe($data['url']);
322 private static function blockContact($contact_id)
324 $blocked = !Model\Contact::isBlockedByUser($contact_id, local_user());
325 Model\Contact::setBlockedForUser($contact_id, local_user(), $blocked);
328 private static function ignoreContact($contact_id)
330 $ignored = !Model\Contact::isIgnoredByUser($contact_id, local_user());
331 Model\Contact::setIgnoredForUser($contact_id, local_user(), $ignored);
334 private static function archiveContact($contact_id, $orig_record)
336 $archived = (defaults($orig_record, 'archive', '') ? 0 : 1);
337 $r = DBA::update('contact', ['archive' => $archived], ['id' => $contact_id, 'uid' => local_user()]);
339 return DBA::isResult($r);
342 private static function dropContact($orig_record)
344 $owner = Model\User::getOwnerDataById(local_user());
345 if (!DBA::isResult($owner)) {
349 Model\Contact::terminateFriendship($owner, $orig_record, true);
350 Model\Contact::remove($orig_record['id']);
353 public static function content($update = 0)
358 Nav::setSelected('contact');
361 notice(L10n::t('Permission denied.') . EOL);
362 return Login::form();
366 $contact_id = intval($a->argv[1]);
373 $orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'self' => false, 'deleted' => false]);
374 if (!DBA::isResult($orig_record)) {
375 notice(L10n::t('Could not access contact record.') . EOL);
376 $a->internalRedirect('contact');
377 return; // NOTREACHED
380 if ($cmd === 'update' && ($orig_record['uid'] != 0)) {
381 self::updateContactFromPoll($contact_id);
382 $a->internalRedirect('contact/' . $contact_id);
386 if ($cmd === 'updateprofile' && ($orig_record['uid'] != 0)) {
387 self::updateContactFromProbe($contact_id);
388 $a->internalRedirect('crepair/' . $contact_id);
392 if ($cmd === 'block') {
393 self::blockContact($contact_id);
395 $blocked = Model\Contact::isBlockedByUser($contact_id, local_user());
396 info(($blocked ? L10n::t('Contact has been blocked') : L10n::t('Contact has been unblocked')) . EOL);
398 $a->internalRedirect('contact/' . $contact_id);
399 return; // NOTREACHED
402 if ($cmd === 'ignore') {
403 self::ignoreContact($contact_id);
405 $ignored = Model\Contact::isIgnoredByUser($contact_id, local_user());
406 info(($ignored ? L10n::t('Contact has been ignored') : L10n::t('Contact has been unignored')) . EOL);
408 $a->internalRedirect('contact/' . $contact_id);
409 return; // NOTREACHED
412 if ($cmd === 'archive' && ($orig_record['uid'] != 0)) {
413 $r = self::archiveContact($contact_id, $orig_record);
415 $archived = (($orig_record['archive']) ? 0 : 1);
416 info((($archived) ? L10n::t('Contact has been archived') : L10n::t('Contact has been unarchived')) . EOL);
419 $a->internalRedirect('contact/' . $contact_id);
420 return; // NOTREACHED
423 if ($cmd === 'drop' && ($orig_record['uid'] != 0)) {
424 // Check if we should do HTML-based delete confirmation
425 if (!empty($_REQUEST['confirm'])) {
426 // <form> can't take arguments in its 'action' parameter
427 // so add any arguments as hidden inputs
428 $query = explode_querystring($a->query_string);
430 foreach ($query['args'] as $arg) {
431 if (strpos($arg, 'confirm=') === false) {
432 $arg_parts = explode('=', $arg);
433 $inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]];
437 $a->page['aside'] = '';
439 return Renderer::replaceMacros(Renderer::getMarkupTemplate('contact_drop_confirm.tpl'), [
440 '$header' => L10n::t('Drop contact'),
441 '$contact' => self::getContactTemplateVars($orig_record),
443 '$message' => L10n::t('Do you really want to delete this contact?'),
444 '$extra_inputs' => $inputs,
445 '$confirm' => L10n::t('Yes'),
446 '$confirm_url' => $query['base'],
447 '$confirm_name' => 'confirmed',
448 '$cancel' => L10n::t('Cancel'),
451 // Now check how the user responded to the confirmation query
452 if (!empty($_REQUEST['canceled'])) {
453 $a->internalRedirect('contact');
456 self::dropContact($orig_record);
457 info(L10n::t('Contact has been removed.') . EOL);
459 $a->internalRedirect('contact');
460 return; // NOTREACHED
462 if ($cmd === 'posts') {
463 return self::getPostsHTML($a, $contact_id);
465 if ($cmd === 'conversations') {
466 return self::getConversationsHMTL($a, $contact_id, $update);
470 $_SESSION['return_path'] = $a->query_string;
472 if (!empty($a->data['contact']) && is_array($a->data['contact'])) {
473 $contact_id = $a->data['contact']['id'];
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' => $contact['ffi_keyword_blacklist'],
636 '$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')],
637 '$photo' => $contact['photo'],
638 '$name' => $contact['name'],
639 '$dir_icon' => $dir_icon,
640 '$sparkle' => $sparkle,
642 '$profileurllabel'=> L10n::t('Profile URL'),
643 '$profileurl' => $contact['url'],
644 '$account_type' => Model\Contact::getAccountType($contact),
645 '$location' => BBCode::convert($contact['location']),
646 '$location_label' => L10n::t('Location:'),
647 '$xmpp' => BBCode::convert($contact['xmpp']),
648 '$xmpp_label' => L10n::t('XMPP:'),
649 '$about' => BBCode::convert($contact['about'], false),
650 '$about_label' => L10n::t('About:'),
651 '$keywords' => $contact['keywords'],
652 '$keywords_label' => L10n::t('Tags:'),
653 '$contact_action_button' => L10n::t('Actions'),
654 '$contact_actions'=> $contact_actions,
655 '$contact_status' => L10n::t('Status'),
656 '$contact_settings_label' => $contact_settings_label,
657 '$contact_profile_label' => L10n::t('Profile'),
660 $arr = ['contact' => $contact, 'output' => $o];
662 Hook::callAll('contact_edit', $arr);
664 return $arr['output'];
673 if (($a->argc == 2) && ($a->argv[1] === 'all')) {
676 } elseif (($a->argc == 2) && ($a->argv[1] === 'blocked')) {
677 $sql_extra = " AND `blocked` = 1 ";
679 } elseif (($a->argc == 2) && ($a->argv[1] === 'hidden')) {
680 $sql_extra = " AND `hidden` = 1 ";
682 } elseif (($a->argc == 2) && ($a->argv[1] === 'ignored')) {
683 $sql_extra = " AND `readonly` = 1 ";
685 } elseif (($a->argc == 2) && ($a->argv[1] === 'archived')) {
686 $sql_extra = " AND `archive` = 1 ";
689 $sql_extra = " AND `blocked` = 0 ";
692 $sql_extra .= sprintf(" AND `network` != '%s' ", Protocol::PHANTOM);
694 $search = Strings::escapeTags(trim(defaults($_GET, 'search', '')));
695 $nets = Strings::escapeTags(trim(defaults($_GET, 'nets' , '')));
699 'label' => L10n::t('Suggestions'),
702 'title' => L10n::t('Suggest potential friends'),
703 'id' => 'suggestions-tab',
707 'label' => L10n::t('All Contacts'),
708 'url' => 'contact/all',
709 'sel' => ($all) ? 'active' : '',
710 'title' => L10n::t('Show all contacts'),
711 'id' => 'showall-tab',
715 'label' => L10n::t('Unblocked'),
717 'sel' => ((!$all) && (!$blocked) && (!$hidden) && (!$search) && (!$nets) && (!$ignored) && (!$archived)) ? 'active' : '',
718 'title' => L10n::t('Only show unblocked contacts'),
719 'id' => 'showunblocked-tab',
723 'label' => L10n::t('Blocked'),
724 'url' => 'contact/blocked',
725 'sel' => ($blocked) ? 'active' : '',
726 'title' => L10n::t('Only show blocked contacts'),
727 'id' => 'showblocked-tab',
731 'label' => L10n::t('Ignored'),
732 'url' => 'contact/ignored',
733 'sel' => ($ignored) ? 'active' : '',
734 'title' => L10n::t('Only show ignored contacts'),
735 'id' => 'showignored-tab',
739 'label' => L10n::t('Archived'),
740 'url' => 'contact/archived',
741 'sel' => ($archived) ? 'active' : '',
742 'title' => L10n::t('Only show archived contacts'),
743 'id' => 'showarchived-tab',
747 'label' => L10n::t('Hidden'),
748 'url' => 'contact/hidden',
749 'sel' => ($hidden) ? 'active' : '',
750 'title' => L10n::t('Only show hidden contacts'),
751 'id' => 'showhidden-tab',
755 'label' => L10n::t('Groups'),
757 'sel' => ($hidden) ? 'active' : '',
758 'title' => L10n::t('Organize your contact groups'),
759 'id' => 'contactgroups-tab',
764 $tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
765 $t = Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);
772 $search_hdr = $search;
773 $search_txt = DBA::escape(Strings::protectSprintf(preg_quote($search)));
774 $sql_extra .= " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') ";
778 $sql_extra .= sprintf(" AND network = '%s' ", DBA::escape($nets));
781 $sql_extra .= " AND NOT `deleted` ";
783 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= Model\Contact::FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : '');
785 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
786 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
787 intval($_SESSION['uid'])
789 if (DBA::isResult($r)) {
790 $total = $r[0]['total'];
792 $pager = new Pager($a->query_string);
794 $sql_extra3 = Widget::unavailableNetworks();
798 $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 ",
799 intval($_SESSION['uid']),
801 $pager->getItemsPerPage()
803 if (DBA::isResult($r)) {
804 foreach ($r as $rr) {
805 $rr['blocked'] = Model\Contact::isBlockedByUser($rr['id'], local_user());
806 $rr['readonly'] = Model\Contact::isIgnoredByUser($rr['id'], local_user());
807 $contacts[] = self::getContactTemplateVars($rr);
811 $tpl = Renderer::getMarkupTemplate('contacts-template.tpl');
812 $o .= Renderer::replaceMacros($tpl, [
813 '$baseurl' => System::baseUrl(),
814 '$header' => L10n::t('Contacts') . (($nets) ? ' - ' . ContactSelector::networkToName($nets) : ''),
817 '$search' => $search_hdr,
818 '$desc' => L10n::t('Search your contacts'),
819 '$finding' => $searching ? L10n::t('Results for: %s', $search) : '',
820 '$submit' => L10n::t('Find'),
822 '$contacts' => $contacts,
823 '$contact_drop_confirm' => L10n::t('Do you really want to delete this contact?'),
825 '$batch_actions' => [
826 'contacts_batch_update' => L10n::t('Update'),
827 'contacts_batch_block' => L10n::t('Block') . '/' . L10n::t('Unblock'),
828 'contacts_batch_ignore' => L10n::t('Ignore') . '/' . L10n::t('Unignore'),
829 'contacts_batch_archive' => L10n::t('Archive') . '/' . L10n::t('Unarchive'),
830 'contacts_batch_drop' => L10n::t('Delete'),
832 '$h_batch_actions' => L10n::t('Batch Actions'),
833 '$paginate' => $pager->renderFull($total),
840 * @brief List of pages for the Contact TabBar
842 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
845 * @param array $contact The contact array
846 * @param int $active_tab 1 if tab should be marked as active
848 * @return string | HTML string of the contact page tabs buttons.
851 public static function getTabsHTML($a, $contact, $active_tab)
856 'label' => L10n::t('Status'),
857 'url' => "contact/" . $contact['id'] . "/conversations",
858 'sel' => (($active_tab == 1) ? 'active' : ''),
859 'title' => L10n::t('Conversations started by this contact'),
860 'id' => 'status-tab',
864 'label' => L10n::t('Posts and Comments'),
865 'url' => "contact/" . $contact['id'] . "/posts",
866 'sel' => (($active_tab == 2) ? 'active' : ''),
867 'title' => L10n::t('Status Messages and Posts'),
872 'label' => L10n::t('Profile'),
873 'url' => "contact/" . $contact['id'],
874 'sel' => (($active_tab == 3) ? 'active' : ''),
875 'title' => L10n::t('Profile Details'),
876 'id' => 'profile-tab',
881 // Show this tab only if there is visible friend list
882 $x = Model\GContact::countAllFriends(local_user(), $contact['id']);
884 $tabs[] = ['label' => L10n::t('Contacts'),
885 'url' => "allfriends/" . $contact['id'],
886 'sel' => (($active_tab == 4) ? 'active' : ''),
887 'title' => L10n::t('View all contacts'),
888 'id' => 'allfriends-tab',
892 // Show this tab only if there is visible common friend list
893 $common = Model\GContact::countCommonFriends(local_user(), $contact['id']);
895 $tabs[] = ['label' => L10n::t('Common Friends'),
896 'url' => "common/loc/" . local_user() . "/" . $contact['id'],
897 'sel' => (($active_tab == 5) ? 'active' : ''),
898 'title' => L10n::t('View all common friends'),
899 'id' => 'common-loc-tab',
904 if (!empty($contact['uid'])) {
905 $tabs[] = ['label' => L10n::t('Advanced'),
906 'url' => 'crepair/' . $contact['id'],
907 'sel' => (($active_tab == 6) ? 'active' : ''),
908 'title' => L10n::t('Advanced Contact Settings'),
909 'id' => 'advanced-tab',
914 $tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
915 $tab_str = Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);
920 private static function getConversationsHMTL($a, $contact_id, $update)
925 // We need the editor here to be able to reshare an item.
929 'allow_location' => $a->user['allow_location'],
930 'default_location' => $a->user['default-location'],
931 'nickname' => $a->user['nickname'],
932 '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'),
933 'acl' => ACL::getFullSelectorHTML($a->user, true),
935 'visitor' => 'block',
936 'profile_uid' => local_user(),
938 $o = status_editor($a, $x, 0, true);
942 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id, 'deleted' => false]);
945 $o .= self::getTabsHTML($a, $contact, 1);
948 if (DBA::isResult($contact)) {
949 $a->page['aside'] = '';
951 $profiledata = Model\Contact::getDetailsByURL($contact['url']);
953 if (local_user() && in_array($profiledata['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
954 $profiledata['remoteconnect'] = System::baseUrl() . '/follow?url=' . urlencode($profiledata['url']);
957 Model\Profile::load($a, '', 0, $profiledata, true);
958 $o .= Model\Contact::getPostsFromUrl($contact['url'], true, $update);
964 private static function getPostsHTML($a, $contact_id)
966 $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id, 'deleted' => false]);
968 $o = self::getTabsHTML($a, $contact, 2);
970 if (DBA::isResult($contact)) {
971 $a->page['aside'] = '';
973 $profiledata = Model\Contact::getDetailsByURL($contact['url']);
975 if (local_user() && in_array($profiledata['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
976 $profiledata['remoteconnect'] = System::baseUrl() . '/follow?url=' . urlencode($profiledata['url']);
979 Model\Profile::load($a, '', 0, $profiledata, true);
980 $o .= Model\Contact::getPostsFromUrl($contact['url']);
986 public static function getContactTemplateVars(array $rr)
991 switch ($rr['rel']) {
992 case Model\Contact::FRIEND:
993 $dir_icon = 'images/lrarrow.gif';
994 $alt_text = L10n::t('Mutual Friendship');
997 case Model\Contact::FOLLOWER;
998 $dir_icon = 'images/larrow.gif';
999 $alt_text = L10n::t('is a fan of yours');
1002 case Model\Contact::SHARING;
1003 $dir_icon = 'images/rarrow.gif';
1004 $alt_text = L10n::t('you are a fan of');
1011 $url = Model\Contact::magicLink($rr['url']);
1013 if (strpos($url, 'redir/') === 0) {
1014 $sparkle = ' class="sparkle" ';
1020 $dir_icon = 'images/larrow.gif';
1021 $alt_text = L10n::t('This is you');
1027 'img_hover' => L10n::t('Visit %s\'s profile [%s]', $rr['name'], $rr['url']),
1028 'edit_hover'=> L10n::t('Edit contact'),
1029 'photo_menu'=> Model\Contact::photoMenu($rr),
1031 'alt_text' => $alt_text,
1032 'dir_icon' => $dir_icon,
1033 'thumb' => ProxyUtils::proxifyUrl($rr['thumb'], false, ProxyUtils::SIZE_THUMB),
1034 'name' => $rr['name'],
1035 'username' => $rr['name'],
1036 'account_type' => Model\Contact::getAccountType($rr),
1037 'sparkle' => $sparkle,
1038 'itemurl' => defaults($rr, 'addr', $rr['url']),
1040 'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
1041 'nick' => $rr['nick'],
1046 * @brief Gives a array with actions which can performed to a given contact
1048 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
1050 * @param array $contact Data about the Contact
1051 * @return array with contact related actions
1053 private static function getContactActions($contact)
1055 $poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
1056 $contact_actions = [];
1058 // Provide friend suggestion only for Friendica contacts
1059 if ($contact['network'] === Protocol::DFRN) {
1060 $contact_actions['suggest'] = [
1061 'label' => L10n::t('Suggest friends'),
1062 'url' => 'fsuggest/' . $contact['id'],
1069 if ($poll_enabled) {
1070 $contact_actions['update'] = [
1071 'label' => L10n::t('Update now'),
1072 'url' => 'contact/' . $contact['id'] . '/update',
1079 $contact_actions['block'] = [
1080 'label' => (intval($contact['blocked']) ? L10n::t('Unblock') : L10n::t('Block')),
1081 'url' => 'contact/' . $contact['id'] . '/block',
1082 'title' => L10n::t('Toggle Blocked status'),
1083 'sel' => (intval($contact['blocked']) ? 'active' : ''),
1084 'id' => 'toggle-block',
1087 $contact_actions['ignore'] = [
1088 'label' => (intval($contact['readonly']) ? L10n::t('Unignore') : L10n::t('Ignore')),
1089 'url' => 'contact/' . $contact['id'] . '/ignore',
1090 'title' => L10n::t('Toggle Ignored status'),
1091 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1092 'id' => 'toggle-ignore',
1095 if ($contact['uid'] != 0) {
1096 $contact_actions['archive'] = [
1097 'label' => (intval($contact['archive']) ? L10n::t('Unarchive') : L10n::t('Archive')),
1098 'url' => 'contact/' . $contact['id'] . '/archive',
1099 'title' => L10n::t('Toggle Archive status'),
1100 'sel' => (intval($contact['archive']) ? 'active' : ''),
1101 'id' => 'toggle-archive',
1104 $contact_actions['delete'] = [
1105 'label' => L10n::t('Delete'),
1106 'url' => 'contact/' . $contact['id'] . '/drop',
1107 'title' => L10n::t('Delete contact'),
1113 return $contact_actions;