diff --git a/src/Module/Profile/Common.php b/src/Module/Profile/Common.php new file mode 100644 index 0000000000..0b08d327c9 --- /dev/null +++ b/src/Module/Profile/Common.php @@ -0,0 +1,112 @@ +. + * + */ + +namespace Friendica\Module\Profile; + +use Friendica\Content\Nav; +use Friendica\Content\Pager; +use Friendica\Core\Protocol; +use Friendica\Core\Renderer; +use Friendica\Core\Session; +use Friendica\Module; +use Friendica\DI; +use Friendica\Model\Contact; +use Friendica\Model\Profile; +use Friendica\Module\BaseProfile; +use Friendica\Network\HTTPException; + +class Common extends BaseProfile +{ + public static function content(array $parameters = []) + { + if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) { + throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.')); + } + + $a = DI::app(); + + Nav::setSelected('home'); + + $nickname = $parameters['nickname']; + + Profile::load($a, $nickname); + + if (empty($a->profile)) { + throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.')); + } + + $o = self::getTabsHTML($a, 'contacts', false, $nickname); + + if (!empty($a->profile['hide-friends'])) { + throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.')); + } + + $displayCommonTab = Session::isAuthenticated() && $a->profile['uid'] != local_user(); + + if (!$displayCommonTab) { + $a->redirect('profile/' . $nickname . '/contacts'); + }; + + $sourceId = Contact::getIdForURL(Profile::getMyURL()); + $targetId = Contact::getPublicIdByUserId($a->profile['uid']); + + $condition = [ + 'blocked' => false, + 'deleted' => false, + 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED], + ]; + + $total = Contact\Relation::countCommon($sourceId, $targetId, $condition); + + $pager = new Pager(DI::l10n(), DI::args()->getQueryString()); + + $commonFollows = Contact\Relation::listCommon($sourceId, $targetId, $condition, $pager->getItemsPerPage(), $pager->getStart()); + + $contacts = array_map([Module\Contact::class, 'getContactTemplateVars'], $commonFollows); + + $title = DI::l10n()->tt('Common contact (%s)', 'Common contacts (%s)', $total); + $desc = DI::l10n()->t( + 'Both %s and yourself have publicly interacted with these contacts (follow, comment or likes on public posts).', + htmlentities($a->profile['name'], ENT_COMPAT, 'UTF-8') + ); + + $tpl = Renderer::getMarkupTemplate('profile/contacts.tpl'); + $o .= Renderer::replaceMacros($tpl, [ + '$title' => $title, + '$desc' => $desc, + '$nickname' => $nickname, + '$type' => 'common', + '$displayCommonTab' => $displayCommonTab, + + '$all_label' => DI::l10n()->t('All contacts'), + '$followers_label' => DI::l10n()->t('Followers'), + '$following_label' => DI::l10n()->t('Following'), + '$mutuals_label' => DI::l10n()->t('Mutual friends'), + '$common_label' => DI::l10n()->t('Common'), + '$noresult_label' => DI::l10n()->t('No common contacts.'), + + '$contacts' => $contacts, + '$paginate' => $pager->renderFull($total), + ]); + + return $o; + } +} diff --git a/src/Module/Profile/Contacts.php b/src/Module/Profile/Contacts.php index b1d8fa6c2f..938dbd3d05 100644 --- a/src/Module/Profile/Contacts.php +++ b/src/Module/Profile/Contacts.php @@ -115,11 +115,13 @@ class Contacts extends Module\BaseProfile '$desc' => $desc, '$nickname' => $nickname, '$type' => $type, + '$displayCommonTab' => Session::isAuthenticated() && $a->profile['uid'] != local_user(), '$all_label' => DI::l10n()->t('All contacts'), '$followers_label' => DI::l10n()->t('Followers'), '$following_label' => DI::l10n()->t('Following'), '$mutuals_label' => DI::l10n()->t('Mutual friends'), + '$common_label' => DI::l10n()->t('Common'), '$noresult_label' => DI::l10n()->t('No contacts.'), '$contacts' => $contacts, diff --git a/static/routes.config.php b/static/routes.config.php index ddfabd7780..15eec298e9 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -252,6 +252,7 @@ return [ '/profile' => [ '/{nickname}' => [Module\Profile\Index::class, [R::GET]], '/{nickname}/profile' => [Module\Profile\Profile::class, [R::GET]], + '/{nickname}/contacts/common' => [Module\Profile\Common::class, [R::GET]], '/{nickname}/contacts[/{type}]' => [Module\Profile\Contacts::class, [R::GET]], '/{nickname}/status[/{category}[/{date1}[/{date2}]]]' => [Module\Profile\Status::class, [R::GET]], ], diff --git a/view/templates/profile/contacts.tpl b/view/templates/profile/contacts.tpl index 90ef867c77..4a1379f17b 100644 --- a/view/templates/profile/contacts.tpl +++ b/view/templates/profile/contacts.tpl @@ -10,6 +10,9 @@