3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Contact;
24 use Friendica\BaseModule;
25 use Friendica\Content\Pager;
26 use Friendica\Content\Widget;
27 use Friendica\Core\Renderer;
30 use Friendica\Model\User;
32 use Friendica\Network\HTTPException;
34 class Contacts extends BaseModule
36 protected function content(array $request = []): string
41 throw new HTTPException\ForbiddenException();
44 $cid = $this->parameters['id'];
45 $type = $this->parameters['type'] ?? 'all';
46 $accounttype = $_GET['accounttype'] ?? '';
47 $accounttypeid = User::getAccountTypeByString($accounttype);
50 throw new HTTPException\BadRequestException(DI::l10n()->t('Invalid contact.'));
53 $contact = Model\Contact::getById($cid, []);
54 if (empty($contact)) {
55 throw new HTTPException\NotFoundException(DI::l10n()->t('Contact not found.'));
58 $localContactId = Model\Contact::getPublicIdByUserId(local_user());
60 DI::page()['aside'] = Widget\VCard::getHTML($contact);
69 if (isset($accounttypeid)) {
70 $condition['contact-type'] = $accounttypeid;
73 $noresult_label = DI::l10n()->t('No known contacts.');
77 $total = Model\Contact\Relation::countFollowers($cid, $condition);
80 $total = Model\Contact\Relation::countFollows($cid, $condition);
83 $total = Model\Contact\Relation::countMutuals($cid, $condition);
86 $total = Model\Contact\Relation::countCommon($localContactId, $cid, $condition);
87 $noresult_label = DI::l10n()->t('No common contacts.');
90 $total = Model\Contact\Relation::countAll($cid, $condition);
93 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30);
98 $friends = Model\Contact\Relation::listFollowers($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
99 $title = DI::l10n()->tt('Follower (%s)', 'Followers (%s)', $total);
102 $friends = Model\Contact\Relation::listFollows($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
103 $title = DI::l10n()->tt('Following (%s)', 'Following (%s)', $total);
106 $friends = Model\Contact\Relation::listMutuals($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
107 $title = DI::l10n()->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total);
108 $desc = DI::l10n()->t(
109 'These contacts both follow and are followed by <strong>%s</strong>.',
110 htmlentities($contact['name'], ENT_COMPAT, 'UTF-8')
114 $friends = Model\Contact\Relation::listCommon($localContactId, $cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
115 $title = DI::l10n()->tt('Common contact (%s)', 'Common contacts (%s)', $total);
116 $desc = DI::l10n()->t(
117 'Both <strong>%s</strong> and yourself have publicly interacted with these contacts (follow, comment or likes on public posts).',
118 htmlentities($contact['name'], ENT_COMPAT, 'UTF-8')
122 $friends = Model\Contact\Relation::listAll($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
123 $title = DI::l10n()->tt('Contact (%s)', 'Contacts (%s)', $total);
126 $o = Module\Contact::getTabsHTML($contact, Module\Contact::TAB_CONTACTS);
128 $tabs = self::getContactFilterTabs('contact/' . $cid, $type, true);
130 $contacts = array_map([Module\Contact::class, 'getContactTemplateVars'], $friends);
132 $tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
133 $o .= Renderer::replaceMacros($tpl, [
138 '$noresult_label' => $noresult_label,
140 '$contacts' => $contacts,
141 '$paginate' => $pager->renderFull($total),
144 DI::page()['aside'] .= Widget::accountTypes($_SERVER['REQUEST_URI'], $accounttype);