mirror of
https://github.com/friendica/friendica
synced 2024-11-18 07:03:40 +00:00
Remove DI dependency in Contact\Contacts module
This commit is contained in:
parent
cef408c842
commit
a633532475
1 changed files with 39 additions and 21 deletions
|
@ -21,54 +21,72 @@
|
|||
|
||||
namespace Friendica\Module\Contact;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Content\Widget;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\DI;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Model;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Util\Profiler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Contacts extends BaseModule
|
||||
{
|
||||
/** @var IHandleUserSessions */
|
||||
private $userSession;
|
||||
/** @var App\Page */
|
||||
private $page;
|
||||
|
||||
public function __construct(App\Page $page, IHandleUserSessions $userSession, 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->userSession = $userSession;
|
||||
$this->page = $page;
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
if (!$this->userSession->getLocalUserId()) {
|
||||
throw new HTTPException\ForbiddenException();
|
||||
}
|
||||
|
||||
$cid = $this->parameters['id'];
|
||||
$type = $this->parameters['type'] ?? 'all';
|
||||
$accounttype = $_GET['accounttype'] ?? '';
|
||||
$accounttype = $request['accounttype'] ?? '';
|
||||
$accounttypeid = User::getAccountTypeByString($accounttype);
|
||||
|
||||
if (!$cid) {
|
||||
throw new HTTPException\BadRequestException(DI::l10n()->t('Invalid contact.'));
|
||||
throw new HTTPException\BadRequestException($this->t('Invalid contact.'));
|
||||
}
|
||||
|
||||
$contact = Model\Contact::getById($cid, []);
|
||||
if (empty($contact)) {
|
||||
throw new HTTPException\NotFoundException(DI::l10n()->t('Contact not found.'));
|
||||
throw new HTTPException\NotFoundException($this->t('Contact not found.'));
|
||||
}
|
||||
|
||||
$localContactId = Model\Contact::getPublicIdByUserId(DI::userSession()->getLocalUserId());
|
||||
$localContactId = Model\Contact::getPublicIdByUserId($this->userSession->getLocalUserId());
|
||||
|
||||
DI::page()['aside'] = Widget\VCard::getHTML($contact);
|
||||
$this->page['aside'] = Widget\VCard::getHTML($contact);
|
||||
|
||||
$condition = [
|
||||
'blocked' => false,
|
||||
'self' => false,
|
||||
'hidden' => false,
|
||||
'failed' => false,
|
||||
'self' => false,
|
||||
'hidden' => false,
|
||||
'failed' => false,
|
||||
];
|
||||
|
||||
if (isset($accounttypeid)) {
|
||||
$condition['contact-type'] = $accounttypeid;
|
||||
}
|
||||
|
||||
$noresult_label = DI::l10n()->t('No known contacts.');
|
||||
$noresult_label = $this->t('No known contacts.');
|
||||
|
||||
switch ($type) {
|
||||
case 'followers':
|
||||
|
@ -82,43 +100,43 @@ class Contacts extends BaseModule
|
|||
break;
|
||||
case 'common':
|
||||
$total = Model\Contact\Relation::countCommon($localContactId, $cid, $condition);
|
||||
$noresult_label = DI::l10n()->t('No common contacts.');
|
||||
$noresult_label = $this->t('No common contacts.');
|
||||
break;
|
||||
default:
|
||||
$total = Model\Contact\Relation::countAll($cid, $condition);
|
||||
}
|
||||
|
||||
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30);
|
||||
$pager = new Pager($this->l10n, $this->args->getQueryString(), 30);
|
||||
$desc = '';
|
||||
|
||||
switch ($type) {
|
||||
case 'followers':
|
||||
$friends = Model\Contact\Relation::listFollowers($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
|
||||
$title = DI::l10n()->tt('Follower (%s)', 'Followers (%s)', $total);
|
||||
$title = $this->tt('Follower (%s)', 'Followers (%s)', $total);
|
||||
break;
|
||||
case 'following':
|
||||
$friends = Model\Contact\Relation::listFollows($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
|
||||
$title = DI::l10n()->tt('Following (%s)', 'Following (%s)', $total);
|
||||
$title = $this->tt('Following (%s)', 'Following (%s)', $total);
|
||||
break;
|
||||
case 'mutuals':
|
||||
$friends = Model\Contact\Relation::listMutuals($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
|
||||
$title = DI::l10n()->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total);
|
||||
$desc = DI::l10n()->t(
|
||||
$title = $this->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total);
|
||||
$desc = $this->t(
|
||||
'These contacts both follow and are followed by <strong>%s</strong>.',
|
||||
htmlentities($contact['name'], ENT_COMPAT, 'UTF-8')
|
||||
);
|
||||
break;
|
||||
case 'common':
|
||||
$friends = Model\Contact\Relation::listCommon($localContactId, $cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
|
||||
$title = DI::l10n()->tt('Common contact (%s)', 'Common contacts (%s)', $total);
|
||||
$desc = DI::l10n()->t(
|
||||
$title = $this->tt('Common contact (%s)', 'Common contacts (%s)', $total);
|
||||
$desc = $this->t(
|
||||
'Both <strong>%s</strong> and yourself have publicly interacted with these contacts (follow, comment or likes on public posts).',
|
||||
htmlentities($contact['name'], ENT_COMPAT, 'UTF-8')
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$friends = Model\Contact\Relation::listAll($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
|
||||
$title = DI::l10n()->tt('Contact (%s)', 'Contacts (%s)', $total);
|
||||
$title = $this->tt('Contact (%s)', 'Contacts (%s)', $total);
|
||||
}
|
||||
|
||||
$o = Module\Contact::getTabsHTML($contact, Module\Contact::TAB_CONTACTS);
|
||||
|
@ -139,7 +157,7 @@ class Contacts extends BaseModule
|
|||
'$paginate' => $pager->renderFull($total),
|
||||
]);
|
||||
|
||||
DI::page()['aside'] .= Widget::accountTypes($_SERVER['REQUEST_URI'], $accounttype);
|
||||
$this->page['aside'] .= Widget::accountTypes($_SERVER['REQUEST_URI'], $accounttype);
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue