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\Profile;
24 use Friendica\Content\Nav;
25 use Friendica\Content\Pager;
26 use Friendica\Core\Protocol;
27 use Friendica\Core\Renderer;
30 use Friendica\Model\Contact;
31 use Friendica\Model\Profile;
32 use Friendica\Module\BaseProfile;
33 use Friendica\Network\HTTPException;
35 class Common extends BaseProfile
37 protected function content(array $request = []): string
39 if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) {
40 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
45 Nav::setSelected('home');
47 $nickname = $this->parameters['nickname'];
49 $profile = Profile::load($a, $nickname);
50 if (empty($profile)) {
51 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
54 if (!empty($profile['hide-friends'])) {
55 throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
58 $displayCommonTab = DI::userSession()->isAuthenticated() && $profile['uid'] != DI::userSession()->getLocalUserId();
60 if (!$displayCommonTab) {
61 $a->redirect('profile/' . $nickname . '/contacts');
64 $o = self::getTabsHTML('contacts', false, $profile['nickname'], $profile['hide-friends']);
66 $tabs = self::getContactFilterTabs('profile/' . $nickname, 'common', $displayCommonTab);
68 $sourceId = Contact::getIdForURL(Profile::getMyURL());
69 $targetId = Contact::getPublicIdByUserId($profile['uid']);
74 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED],
77 $total = Contact\Relation::countCommon($sourceId, $targetId, $condition);
79 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30);
81 $commonFollows = Contact\Relation::listCommon($sourceId, $targetId, $condition, $pager->getItemsPerPage(), $pager->getStart());
83 $contacts = array_map([Module\Contact::class, 'getContactTemplateVars'], $commonFollows);
85 $title = DI::l10n()->tt('Common contact (%s)', 'Common contacts (%s)', $total);
86 $desc = DI::l10n()->t(
87 'Both <strong>%s</strong> and yourself have publicly interacted with these contacts (follow, comment or likes on public posts).',
88 htmlentities($profile['name'], ENT_COMPAT, 'UTF-8')
91 $tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
92 $o .= Renderer::replaceMacros($tpl, [
97 '$noresult_label' => DI::l10n()->t('No common contacts.'),
99 '$contacts' => $contacts,
100 '$paginate' => $pager->renderFull($total),