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;
28 use Friendica\Core\Session;
31 use Friendica\Model\User;
33 use Friendica\Network\HTTPException;
35 class Contacts extends BaseModule
37 protected function content(array $request = []): string
39 if (!Session::getLocalUser()) {
40 throw new HTTPException\ForbiddenException();
43 $cid = $this->parameters['id'];
44 $type = $this->parameters['type'] ?? 'all';
45 $accounttype = $_GET['accounttype'] ?? '';
46 $accounttypeid = User::getAccountTypeByString($accounttype);
49 throw new HTTPException\BadRequestException(DI::l10n()->t('Invalid contact.'));
52 $contact = Model\Contact::getById($cid, []);
53 if (empty($contact)) {
54 throw new HTTPException\NotFoundException(DI::l10n()->t('Contact not found.'));
57 $localContactId = Model\Contact::getPublicIdByUserId(Session::getLocalUser());
59 DI::page()['aside'] = Widget\VCard::getHTML($contact);
68 if (isset($accounttypeid)) {
69 $condition['contact-type'] = $accounttypeid;
72 $noresult_label = DI::l10n()->t('No known contacts.');
76 $total = Model\Contact\Relation::countFollowers($cid, $condition);
79 $total = Model\Contact\Relation::countFollows($cid, $condition);
82 $total = Model\Contact\Relation::countMutuals($cid, $condition);
85 $total = Model\Contact\Relation::countCommon($localContactId, $cid, $condition);
86 $noresult_label = DI::l10n()->t('No common contacts.');
89 $total = Model\Contact\Relation::countAll($cid, $condition);
92 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30);
97 $friends = Model\Contact\Relation::listFollowers($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
98 $title = DI::l10n()->tt('Follower (%s)', 'Followers (%s)', $total);
101 $friends = Model\Contact\Relation::listFollows($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
102 $title = DI::l10n()->tt('Following (%s)', 'Following (%s)', $total);
105 $friends = Model\Contact\Relation::listMutuals($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
106 $title = DI::l10n()->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total);
107 $desc = DI::l10n()->t(
108 'These contacts both follow and are followed by <strong>%s</strong>.',
109 htmlentities($contact['name'], ENT_COMPAT, 'UTF-8')
113 $friends = Model\Contact\Relation::listCommon($localContactId, $cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
114 $title = DI::l10n()->tt('Common contact (%s)', 'Common contacts (%s)', $total);
115 $desc = DI::l10n()->t(
116 'Both <strong>%s</strong> and yourself have publicly interacted with these contacts (follow, comment or likes on public posts).',
117 htmlentities($contact['name'], ENT_COMPAT, 'UTF-8')
121 $friends = Model\Contact\Relation::listAll($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
122 $title = DI::l10n()->tt('Contact (%s)', 'Contacts (%s)', $total);
125 $o = Module\Contact::getTabsHTML($contact, Module\Contact::TAB_CONTACTS);
127 $tabs = self::getContactFilterTabs('contact/' . $cid, $type, true);
129 $contacts = array_map([Module\Contact::class, 'getContactTemplateVars'], $friends);
131 $tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
132 $o .= Renderer::replaceMacros($tpl, [
137 '$noresult_label' => $noresult_label,
139 '$contacts' => $contacts,
140 '$paginate' => $pager->renderFull($total),
143 DI::page()['aside'] .= Widget::accountTypes($_SERVER['REQUEST_URI'], $accounttype);