3 * @copyright Copyright (C) 2010-2023, 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;
25 use Friendica\Content\Nav;
26 use Friendica\Content\Pager;
27 use Friendica\Core\Config\Capability\IManageConfigValues;
28 use Friendica\Core\L10n;
29 use Friendica\Core\Protocol;
30 use Friendica\Core\Renderer;
31 use Friendica\Core\Session\Capability\IHandleUserSessions;
33 use Friendica\Model\Contact;
34 use Friendica\Model\Profile;
35 use Friendica\Module\BaseProfile;
36 use Friendica\Module\Response;
37 use Friendica\Network\HTTPException;
38 use Friendica\Util\Profiler;
39 use Psr\Log\LoggerInterface;
41 class Common extends BaseProfile
43 /** @var IManageConfigValues */
45 /** @var IHandleUserSessions */
50 public function __construct(App $app, IHandleUserSessions $userSession, IManageConfigValues $config, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
52 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
54 $this->config = $config;
55 $this->userSession = $userSession;
59 protected function content(array $request = []): string
61 if ($this->config->get('system', 'block_public') && !$this->userSession->isAuthenticated()) {
62 throw new HTTPException\NotFoundException($this->t('User not found.'));
65 Nav::setSelected('home');
67 $nickname = $this->parameters['nickname'];
69 $profile = Profile::load($this->app, $nickname);
70 if (empty($profile)) {
71 throw new HTTPException\NotFoundException($this->t('User not found.'));
74 if (!empty($profile['hide-friends'])) {
75 throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
78 $displayCommonTab = $this->userSession->isAuthenticated() && $profile['uid'] != $this->userSession->getLocalUserId();
80 if (!$displayCommonTab) {
81 $this->baseUrl->redirect('profile/' . $nickname . '/contacts');
84 $o = self::getTabsHTML('contacts', false, $profile['nickname'], $profile['hide-friends']);
86 $tabs = self::getContactFilterTabs('profile/' . $nickname, 'common', $displayCommonTab);
88 $sourceId = Contact::getIdForURL($this->userSession->getMyUrl());
89 $targetId = Contact::getPublicIdByUserId($profile['uid']);
94 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED],
97 $total = Contact\Relation::countCommon($sourceId, $targetId, $condition);
99 $pager = new Pager($this->l10n, $this->args->getQueryString(), 30);
101 $commonFollows = Contact\Relation::listCommon($sourceId, $targetId, $condition, $pager->getItemsPerPage(), $pager->getStart());
103 // Contact list is obtained from the visited profile user, but the contact display is visitor dependent
104 $contacts = array_map(
105 function ($contact) {
106 $contact = Contact::selectFirst(
108 ['uri-id' => $contact['uri-id'], 'uid' => [0, $this->userSession->getLocalUserId()]],
109 ['order' => ['uid' => 'DESC']]
111 return Module\Contact::getContactTemplateVars($contact);
116 $title = $this->tt('Common contact (%s)', 'Common contacts (%s)', $total);
118 'Both <strong>%s</strong> and yourself have publicly interacted with these contacts (follow, comment or likes on public posts).',
119 htmlentities($profile['name'], ENT_COMPAT, 'UTF-8')
122 $tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
123 $o .= Renderer::replaceMacros($tpl, [
128 '$noresult_label' => $this->t('No common contacts.'),
130 '$contacts' => $contacts,
131 '$paginate' => $pager->renderFull($total),