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
38 if (!DI::userSession()->getLocalUserId()) {
39 throw new HTTPException\ForbiddenException();
42 $cid = $this->parameters['id'];
43 $type = $this->parameters['type'] ?? 'all';
44 $accounttype = $_GET['accounttype'] ?? '';
45 $accounttypeid = User::getAccountTypeByString($accounttype);
48 throw new HTTPException\BadRequestException(DI::l10n()->t('Invalid contact.'));
51 $contact = Model\Contact::getById($cid, []);
52 if (empty($contact)) {
53 throw new HTTPException\NotFoundException(DI::l10n()->t('Contact not found.'));
56 $localContactId = Model\Contact::getPublicIdByUserId(DI::userSession()->getLocalUserId());
58 DI::page()['aside'] = Widget\VCard::getHTML($contact);
67 if (isset($accounttypeid)) {
68 $condition['contact-type'] = $accounttypeid;
71 $noresult_label = DI::l10n()->t('No known contacts.');
75 $total = Model\Contact\Relation::countFollowers($cid, $condition);
78 $total = Model\Contact\Relation::countFollows($cid, $condition);
81 $total = Model\Contact\Relation::countMutuals($cid, $condition);
84 $total = Model\Contact\Relation::countCommon($localContactId, $cid, $condition);
85 $noresult_label = DI::l10n()->t('No common contacts.');
88 $total = Model\Contact\Relation::countAll($cid, $condition);
91 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30);
96 $friends = Model\Contact\Relation::listFollowers($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
97 $title = DI::l10n()->tt('Follower (%s)', 'Followers (%s)', $total);
100 $friends = Model\Contact\Relation::listFollows($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
101 $title = DI::l10n()->tt('Following (%s)', 'Following (%s)', $total);
104 $friends = Model\Contact\Relation::listMutuals($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
105 $title = DI::l10n()->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total);
106 $desc = DI::l10n()->t(
107 'These contacts both follow and are followed by <strong>%s</strong>.',
108 htmlentities($contact['name'], ENT_COMPAT, 'UTF-8')
112 $friends = Model\Contact\Relation::listCommon($localContactId, $cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
113 $title = DI::l10n()->tt('Common contact (%s)', 'Common contacts (%s)', $total);
114 $desc = DI::l10n()->t(
115 'Both <strong>%s</strong> and yourself have publicly interacted with these contacts (follow, comment or likes on public posts).',
116 htmlentities($contact['name'], ENT_COMPAT, 'UTF-8')
120 $friends = Model\Contact\Relation::listAll($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
121 $title = DI::l10n()->tt('Contact (%s)', 'Contacts (%s)', $total);
124 $o = Module\Contact::getTabsHTML($contact, Module\Contact::TAB_CONTACTS);
126 $tabs = self::getContactFilterTabs('contact/' . $cid, $type, true);
128 $contacts = array_map([Module\Contact::class, 'getContactTemplateVars'], $friends);
130 $tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
131 $o .= Renderer::replaceMacros($tpl, [
136 '$noresult_label' => $noresult_label,
138 '$contacts' => $contacts,
139 '$paginate' => $pager->renderFull($total),
142 DI::page()['aside'] .= Widget::accountTypes($_SERVER['REQUEST_URI'], $accounttype);