mirror of
https://github.com/friendica/friendica
synced 2024-11-18 09:03:42 +00:00
Remove DI dependency in Module\Profile\Contacts
This commit is contained in:
parent
f9dcb7c6d4
commit
cef408c842
1 changed files with 56 additions and 27 deletions
|
@ -21,45 +21,68 @@
|
||||||
|
|
||||||
namespace Friendica\Module\Profile;
|
namespace Friendica\Module\Profile;
|
||||||
|
|
||||||
|
use Friendica\App;
|
||||||
use Friendica\Content\Nav;
|
use Friendica\Content\Nav;
|
||||||
use Friendica\Content\Pager;
|
use Friendica\Content\Pager;
|
||||||
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||||
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||||
use Friendica\DI;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Model;
|
use Friendica\Model;
|
||||||
use Friendica\Module;
|
use Friendica\Module;
|
||||||
|
use Friendica\Module\Response;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
|
use Friendica\Util\Profiler;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Contacts extends Module\BaseProfile
|
class Contacts extends Module\BaseProfile
|
||||||
{
|
{
|
||||||
|
/** @var IManageConfigValues */
|
||||||
|
private $config;
|
||||||
|
/** @var IHandleUserSessions */
|
||||||
|
private $userSession;
|
||||||
|
/** @var App */
|
||||||
|
private $app;
|
||||||
|
/** @var Database */
|
||||||
|
private $database;
|
||||||
|
|
||||||
|
public function __construct(Database $database, App $app, IHandleUserSessions $userSession, IManageConfigValues $config, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||||
|
{
|
||||||
|
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||||
|
|
||||||
|
$this->config = $config;
|
||||||
|
$this->userSession = $userSession;
|
||||||
|
$this->app = $app;
|
||||||
|
$this->database = $database;
|
||||||
|
}
|
||||||
|
|
||||||
protected function content(array $request = []): string
|
protected function content(array $request = []): string
|
||||||
{
|
{
|
||||||
if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) {
|
if ($this->config->get('system', 'block_public') && !$this->userSession->isAuthenticated()) {
|
||||||
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
|
throw new HTTPException\NotFoundException($this->t('User not found.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$a = DI::app();
|
|
||||||
|
|
||||||
$nickname = $this->parameters['nickname'];
|
$nickname = $this->parameters['nickname'];
|
||||||
$type = $this->parameters['type'] ?? 'all';
|
$type = $this->parameters['type'] ?? 'all';
|
||||||
|
|
||||||
$profile = Model\Profile::load($a, $nickname);
|
$profile = Model\Profile::load($this->app, $nickname);
|
||||||
if (empty($profile)) {
|
if (empty($profile)) {
|
||||||
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
|
throw new HTTPException\NotFoundException($this->t('User not found.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$is_owner = $profile['uid'] == DI::userSession()->getLocalUserId();
|
$is_owner = $profile['uid'] == $this->userSession->getLocalUserId();
|
||||||
|
|
||||||
if ($profile['hide-friends'] && !$is_owner) {
|
if ($profile['hide-friends'] && !$is_owner) {
|
||||||
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
Nav::setSelected('home');
|
Nav::setSelected('home');
|
||||||
|
|
||||||
$o = self::getTabsHTML('contacts', $is_owner, $profile['nickname'], $profile['hide-friends']);
|
$o = self::getTabsHTML('contacts', $is_owner, $profile['nickname'], $profile['hide-friends']);
|
||||||
|
|
||||||
$tabs = self::getContactFilterTabs('profile/' . $nickname, $type, DI::userSession()->isAuthenticated() && $profile['uid'] != DI::userSession()->getLocalUserId());
|
$tabs = self::getContactFilterTabs('profile/' . $nickname, $type, $this->userSession->isAuthenticated() && $profile['uid'] != $this->userSession->getLocalUserId());
|
||||||
|
|
||||||
$condition = [
|
$condition = [
|
||||||
'uid' => $profile['uid'],
|
'uid' => $profile['uid'],
|
||||||
|
@ -73,14 +96,20 @@ class Contacts extends Module\BaseProfile
|
||||||
];
|
];
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'followers': $condition['rel'] = [Model\Contact::FOLLOWER, Model\Contact::FRIEND]; break;
|
case 'followers':
|
||||||
case 'following': $condition['rel'] = [Model\Contact::SHARING, Model\Contact::FRIEND]; break;
|
$condition['rel'] = [Model\Contact::FOLLOWER, Model\Contact::FRIEND];
|
||||||
case 'mutuals': $condition['rel'] = Model\Contact::FRIEND; break;
|
break;
|
||||||
|
case 'following':
|
||||||
|
$condition['rel'] = [Model\Contact::SHARING, Model\Contact::FRIEND];
|
||||||
|
break;
|
||||||
|
case 'mutuals':
|
||||||
|
$condition['rel'] = Model\Contact::FRIEND;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$total = DBA::count('contact', $condition);
|
$total = $this->database->count('contact', $condition);
|
||||||
|
|
||||||
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30);
|
$pager = new Pager($this->l10n, $this->args->getQueryString(), 30);
|
||||||
|
|
||||||
$params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
|
$params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
|
||||||
|
|
||||||
|
@ -92,31 +121,31 @@ class Contacts extends Module\BaseProfile
|
||||||
$desc = '';
|
$desc = '';
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'followers':
|
case 'followers':
|
||||||
$title = DI::l10n()->tt('Follower (%s)', 'Followers (%s)', $total);
|
$title = $this->tt('Follower (%s)', 'Followers (%s)', $total);
|
||||||
break;
|
break;
|
||||||
case 'following':
|
case 'following':
|
||||||
$title = DI::l10n()->tt('Following (%s)', 'Following (%s)', $total);
|
$title = $this->tt('Following (%s)', 'Following (%s)', $total);
|
||||||
break;
|
break;
|
||||||
case 'mutuals':
|
case 'mutuals':
|
||||||
$title = DI::l10n()->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total);
|
$title = $this->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total);
|
||||||
$desc = DI::l10n()->t(
|
$desc = $this->t(
|
||||||
'These contacts both follow and are followed by <strong>%s</strong>.',
|
'These contacts both follow and are followed by <strong>%s</strong>.',
|
||||||
htmlentities($profile['name'], ENT_COMPAT, 'UTF-8')
|
htmlentities($profile['name'], ENT_COMPAT, 'UTF-8')
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case 'all':
|
case 'all':
|
||||||
default:
|
default:
|
||||||
$title = DI::l10n()->tt('Contact (%s)', 'Contacts (%s)', $total);
|
$title = $this->tt('Contact (%s)', 'Contacts (%s)', $total);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
|
$tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
|
||||||
$o .= Renderer::replaceMacros($tpl, [
|
$o .= Renderer::replaceMacros($tpl, [
|
||||||
'$title' => $title,
|
'$title' => $title,
|
||||||
'$desc' => $desc,
|
'$desc' => $desc,
|
||||||
'$tabs' => $tabs,
|
'$tabs' => $tabs,
|
||||||
|
|
||||||
'$noresult_label' => DI::l10n()->t('No contacts.'),
|
'$noresult_label' => $this->t('No contacts.'),
|
||||||
|
|
||||||
'$contacts' => $contacts,
|
'$contacts' => $contacts,
|
||||||
'$paginate' => $pager->renderFull($total),
|
'$paginate' => $pager->renderFull($total),
|
||||||
|
|
Loading…
Reference in a new issue