3 namespace Friendica\Module\Contact;
5 use Friendica\BaseModule;
6 use Friendica\Content\Pager;
7 use Friendica\Content\Widget;
8 use Friendica\Core\Renderer;
11 use Friendica\Model\User;
13 use Friendica\Network\HTTPException;
15 class Contacts extends BaseModule
17 public static function content()
22 throw new HTTPException\ForbiddenException();
25 $cid = static::$parameters['id'];
26 $type = static::$parameters['type'] ?? 'all';
27 $accounttype = $_GET['accounttype'] ?? '';
28 $accounttypeid = User::getAccountTypeByString($accounttype);
31 throw new HTTPException\BadRequestException(DI::l10n()->t('Invalid contact.'));
34 $contact = Model\Contact::getById($cid, []);
35 if (empty($contact)) {
36 throw new HTTPException\NotFoundException(DI::l10n()->t('Contact not found.'));
39 $localContactId = Model\Contact::getPublicIdByUserId(local_user());
41 DI::page()['aside'] = Widget\VCard::getHTML($contact);
50 if (isset($accounttypeid)) {
51 $condition['contact-type'] = $accounttypeid;
54 $noresult_label = DI::l10n()->t('No known contacts.');
58 $total = Model\Contact\Relation::countFollowers($cid, $condition);
61 $total = Model\Contact\Relation::countFollows($cid, $condition);
64 $total = Model\Contact\Relation::countMutuals($cid, $condition);
67 $total = Model\Contact\Relation::countCommon($localContactId, $cid, $condition);
68 $noresult_label = DI::l10n()->t('No common contacts.');
71 $total = Model\Contact\Relation::countAll($cid, $condition);
74 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30);
79 $friends = Model\Contact\Relation::listFollowers($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
80 $title = DI::l10n()->tt('Follower (%s)', 'Followers (%s)', $total);
83 $friends = Model\Contact\Relation::listFollows($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
84 $title = DI::l10n()->tt('Following (%s)', 'Following (%s)', $total);
87 $friends = Model\Contact\Relation::listMutuals($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
88 $title = DI::l10n()->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total);
89 $desc = DI::l10n()->t(
90 'These contacts both follow and are followed by <strong>%s</strong>.',
91 htmlentities($contact['name'], ENT_COMPAT, 'UTF-8')
95 $friends = Model\Contact\Relation::listCommon($localContactId, $cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
96 $title = DI::l10n()->tt('Common contact (%s)', 'Common contacts (%s)', $total);
97 $desc = DI::l10n()->t(
98 'Both <strong>%s</strong> and yourself have publicly interacted with these contacts (follow, comment or likes on public posts).',
99 htmlentities($contact['name'], ENT_COMPAT, 'UTF-8')
103 $friends = Model\Contact\Relation::listAll($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
104 $title = DI::l10n()->tt('Contact (%s)', 'Contacts (%s)', $total);
107 $o = Module\Contact::getTabsHTML($contact, Module\Contact::TAB_CONTACTS);
109 $tabs = self::getContactFilterTabs('contact/' . $cid, $type, true);
111 $contacts = array_map([Module\Contact::class, 'getContactTemplateVars'], $friends);
113 $tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
114 $o .= Renderer::replaceMacros($tpl, [
119 '$noresult_label' => $noresult_label,
121 '$contacts' => $contacts,
122 '$paginate' => $pager->renderFull($total),
125 DI::page()['aside'] .= Widget::accounttypes($_SERVER['REQUEST_URI'], $accounttype);