<?php
/**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\Content\Pager;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
-use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model;
class Contacts extends Module\BaseProfile
{
- public static function content(array $parameters = [])
+ protected function content(array $request = []): string
{
- if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
+ if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) {
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
}
$a = DI::app();
- $nickname = $parameters['nickname'];
- $type = $parameters['type'] ?? 'all';
+ $nickname = $this->parameters['nickname'];
+ $type = $this->parameters['type'] ?? 'all';
- Model\Profile::load($a, $nickname);
-
- if (empty($a->profile)) {
+ $profile = Model\Profile::load($a, $nickname);
+ if (empty($profile)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
}
- if (!empty($a->profile['hide-friends'])) {
+ $is_owner = $profile['uid'] == DI::userSession()->getLocalUserId();
+
+ if ($profile['hide-friends'] && !$is_owner) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
Nav::setSelected('home');
- $is_owner = $a->profile['uid'] == local_user();
+ $o = self::getTabsHTML('contacts', $is_owner, $profile['nickname'], $profile['hide-friends']);
- $o = self::getTabsHTML($a, 'contacts', $is_owner, $nickname);
+ $tabs = self::getContactFilterTabs('profile/' . $nickname, $type, DI::userSession()->isAuthenticated() && $profile['uid'] != DI::userSession()->getLocalUserId());
$condition = [
- 'uid' => $a->profile['uid'],
+ 'uid' => $profile['uid'],
'blocked' => false,
'pending' => false,
'hidden' => false,
'archive' => false,
+ 'failed' => false,
'self' => false,
'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED]
];
$total = DBA::count('contact', $condition);
- $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
+ $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30);
$params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
$title = DI::l10n()->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total);
$desc = DI::l10n()->t(
'These contacts both follow and are followed by <strong>%s</strong>.',
- htmlentities($a->profile['name'], ENT_COMPAT, 'UTF-8')
+ htmlentities($profile['name'], ENT_COMPAT, 'UTF-8')
);
break;
case 'all':
$o .= Renderer::replaceMacros($tpl, [
'$title' => $title,
'$desc' => $desc,
- '$nickname' => $nickname,
- '$type' => $type,
+ '$tabs' => $tabs,
- '$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'),
'$noresult_label' => DI::l10n()->t('No contacts.'),
'$contacts' => $contacts,