Replace all calls for App::getContactId() with AppHelper

This commit is contained in:
Art4 2024-11-08 23:04:52 +00:00
parent cad3311afb
commit d9087b4f7c
4 changed files with 46 additions and 39 deletions

View file

@ -7,7 +7,7 @@
* *
*/ */
use Friendica\App; use Friendica\AppHelper;
use Friendica\Content\Conversation; use Friendica\Content\Conversation;
use Friendica\Content\Nav; use Friendica\Content\Nav;
use Friendica\Content\Pager; use Friendica\Content\Pager;
@ -17,7 +17,7 @@ use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Module\BaseProfile; use Friendica\Module\BaseProfile;
function notes_init(App $a) function notes_init(AppHelper $appHelper)
{ {
if (! DI::userSession()->getLocalUserId()) { if (! DI::userSession()->getLocalUserId()) {
return; return;
@ -27,7 +27,7 @@ function notes_init(App $a)
} }
function notes_content(App $a, bool $update = false) function notes_content(AppHelper $appHelper, bool $update = false)
{ {
if (!DI::userSession()->getLocalUserId()) { if (!DI::userSession()->getLocalUserId()) {
DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
@ -46,11 +46,11 @@ function notes_content(App $a, bool $update = false)
'acl_data' => '', 'acl_data' => '',
]; ];
$o .= DI::conversation()->statusEditor($x, $a->getContactId()); $o .= DI::conversation()->statusEditor($x, $appHelper->getContactId());
} }
$condition = ['uid' => DI::userSession()->getLocalUserId(), 'post-type' => Item::PT_PERSONAL_NOTE, 'gravity' => Item::GRAVITY_PARENT, $condition = ['uid' => DI::userSession()->getLocalUserId(), 'post-type' => Item::PT_PERSONAL_NOTE, 'gravity' => Item::GRAVITY_PARENT,
'contact-id'=> $a->getContactId()]; 'contact-id'=> $appHelper->getContactId()];
if (DI::mode()->isMobile()) { if (DI::mode()->isMobile()) {
$itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network', $itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network',

View file

@ -7,8 +7,10 @@
namespace Friendica\Module\Contact; namespace Friendica\Module\Contact;
use Friendica\App\Arguments;
use Friendica\App\BaseURL;
use Friendica\AppHelper;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\App;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\Session\Capability\IHandleUserSessions; use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Core\Worker; use Friendica\Core\Worker;
@ -27,16 +29,16 @@ class Redir extends \Friendica\BaseModule
private $session; private $session;
/** @var Database */ /** @var Database */
private $database; private $database;
/** @var App */ /** @var AppHelper */
private $app; private $appHelper;
public function __construct(App $app, Database $database, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = []) public function __construct(AppHelper $appHelper, Database $database, IHandleUserSessions $session, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
{ {
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->session = $session; $this->session = $session;
$this->database = $database; $this->database = $database;
$this->app = $app; $this->appHelper = $appHelper;
} }
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
@ -100,14 +102,14 @@ class Redir extends \Friendica\BaseModule
// We don't use magic auth when there is no visitor, we are on the same system, or we visit our own stuff // We don't use magic auth when there is no visitor, we are on the same system, or we visit our own stuff
if (empty($visitor) || Strings::compareLink($basepath, $this->baseUrl) || Strings::compareLink($contact_url, $visitor)) { if (empty($visitor) || Strings::compareLink($basepath, $this->baseUrl) || Strings::compareLink($contact_url, $visitor)) {
$this->logger->info('Redirecting without magic', ['target' => $target_url, 'visitor' => $visitor, 'contact' => $contact_url]); $this->logger->info('Redirecting without magic', ['target' => $target_url, 'visitor' => $visitor, 'contact' => $contact_url]);
$this->app->redirect($target_url); $this->appHelper->redirect($target_url);
} }
$separator = strpos($target_url, '?') ? '&' : '?'; $separator = strpos($target_url, '?') ? '&' : '?';
$target_url .= $separator . 'zrl=' . urlencode($visitor) . '&addr=' . urlencode($contact_url); $target_url .= $separator . 'zrl=' . urlencode($visitor) . '&addr=' . urlencode($contact_url);
$this->logger->info('Redirecting with magic', ['target' => $target_url, 'visitor' => $visitor, 'contact' => $contact_url]); $this->logger->info('Redirecting with magic', ['target' => $target_url, 'visitor' => $visitor, 'contact' => $contact_url]);
$this->app->redirect($target_url); $this->appHelper->redirect($target_url);
} }
/** /**
@ -135,9 +137,9 @@ class Redir extends \Friendica\BaseModule
$this->checkUrl($contact_url, $url); $this->checkUrl($contact_url, $url);
$target_url = $url ?: $contact_url; $target_url = $url ?: $contact_url;
if (!empty($this->app->getContactId()) && $this->app->getContactId() == $cid) { if (!empty($this->appHelper->getContactId()) && $this->appHelper->getContactId() == $cid) {
// Local user is already authenticated. // Local user is already authenticated.
$this->app->redirect($target_url); $this->appHelper->redirect($target_url);
} }
if ($contact['uid'] == 0 && $this->session->getLocalUserId()) { if ($contact['uid'] == 0 && $this->session->getLocalUserId()) {
@ -148,10 +150,10 @@ class Redir extends \Friendica\BaseModule
$cid = $contact['id']; $cid = $contact['id'];
} }
if (!empty($this->app->getContactId()) && $this->app->getContactId() == $cid) { if (!empty($this->appHelper->getContactId()) && $this->appHelper->getContactId() == $cid) {
// Local user is already authenticated. // Local user is already authenticated.
$this->logger->info('Contact already authenticated. Redirecting to target url', ['url' => $contact['url'], 'name' => $contact['name'], 'target_url' => $target_url]); $this->logger->info('Contact already authenticated. Redirecting to target url', ['url' => $contact['url'], 'name' => $contact['name'], 'target_url' => $target_url]);
$this->app->redirect($target_url); $this->appHelper->redirect($target_url);
} }
} }
@ -166,7 +168,7 @@ class Redir extends \Friendica\BaseModule
if (($host == $remotehost) && ($this->session->getRemoteContactID($this->session->get('visitor_visiting')) == $this->session->get('visitor_id'))) { if (($host == $remotehost) && ($this->session->getRemoteContactID($this->session->get('visitor_visiting')) == $this->session->get('visitor_id'))) {
// Remote user is already authenticated. // Remote user is already authenticated.
$this->logger->info('Contact already authenticated. Redirecting to target url', ['url' => $contact['url'], 'name' => $contact['name'], 'target_url' => $target_url]); $this->logger->info('Contact already authenticated. Redirecting to target url', ['url' => $contact['url'], 'name' => $contact['name'], 'target_url' => $target_url]);
$this->app->redirect($target_url); $this->appHelper->redirect($target_url);
} }
} }
@ -181,7 +183,7 @@ class Redir extends \Friendica\BaseModule
} }
$this->logger->info('redirecting to ' . $target_url); $this->logger->info('redirecting to ' . $target_url);
$this->app->redirect($target_url); $this->appHelper->redirect($target_url);
} }

View file

@ -8,7 +8,10 @@
namespace Friendica\Module\Item; namespace Friendica\Module\Item;
use DateTime; use DateTime;
use Friendica\App; use Friendica\App\Arguments;
use Friendica\App\BaseURL;
use Friendica\App\Page;
use Friendica\AppHelper;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Content\Feature; use Friendica\Content\Feature;
use Friendica\Core\ACL; use Friendica\Core\ACL;
@ -41,7 +44,7 @@ class Compose extends BaseModule
/** @var ACLFormatter */ /** @var ACLFormatter */
private $ACLFormatter; private $ACLFormatter;
/** @var App\Page */ /** @var Page */
private $page; private $page;
/** @var IManagePersonalConfigValues */ /** @var IManagePersonalConfigValues */
@ -53,11 +56,11 @@ class Compose extends BaseModule
/** @var UserSession */ /** @var UserSession */
private $session; private $session;
/** @var App */ /** @var AppHelper */
private $app; private $appHelper;
public function __construct(App $app, UserSession $session, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, App\Page $page, ACLFormatter $ACLFormatter, SystemMessages $systemMessages, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = []) public function __construct(AppHelper $appHelper, UserSession $session, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, Page $page, ACLFormatter $ACLFormatter, SystemMessages $systemMessages, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
{ {
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
@ -67,7 +70,7 @@ class Compose extends BaseModule
$this->pConfig = $pConfig; $this->pConfig = $pConfig;
$this->config = $config; $this->config = $config;
$this->session = $session; $this->session = $session;
$this->app = $app; $this->appHelper = $appHelper;
} }
protected function post(array $request = []) protected function post(array $request = [])
@ -87,7 +90,7 @@ class Compose extends BaseModule
return Login::form('compose'); return Login::form('compose');
} }
if ($this->app->getCurrentTheme() !== 'frio') { if ($this->appHelper->getCurrentTheme() !== 'frio') {
throw new NotImplementedException($this->l10n->t('This feature is only available with the frio theme.')); throw new NotImplementedException($this->l10n->t('This feature is only available with the frio theme.'));
} }
@ -115,7 +118,7 @@ class Compose extends BaseModule
$compose_title = $this->l10n->t('Compose new personal note'); $compose_title = $this->l10n->t('Compose new personal note');
$type = 'note'; $type = 'note';
$doesFederate = false; $doesFederate = false;
$contact_allow_list = [$this->app->getContactId()]; $contact_allow_list = [$this->appHelper->getContactId()];
$circle_allow_list = []; $circle_allow_list = [];
$contact_deny_list = []; $contact_deny_list = [];
$circle_deny_list = []; $circle_deny_list = [];
@ -158,12 +161,12 @@ class Compose extends BaseModule
$this->page->registerFooterScript(Theme::getPathForFile('js/linkPreview.js')); $this->page->registerFooterScript(Theme::getPathForFile('js/linkPreview.js'));
$this->page->registerFooterScript(Theme::getPathForFile('js/compose.js')); $this->page->registerFooterScript(Theme::getPathForFile('js/compose.js'));
$contact = Contact::getById($this->app->getContactId()); $contact = Contact::getById($this->appHelper->getContactId());
if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'set_creation_date')) { if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'set_creation_date')) {
$created_at = Temporal::getDateTimeField( $created_at = Temporal::getDateTimeField(
new \DateTime(DBA::NULL_DATETIME), new DateTime(DBA::NULL_DATETIME),
new \DateTime('now'), new DateTime('now'),
null, null,
$this->l10n->t('Created at'), $this->l10n->t('Created at'),
'created_at' 'created_at'

View file

@ -8,7 +8,9 @@
namespace Friendica\Module; namespace Friendica\Module;
use Exception; use Exception;
use Friendica\App; use Friendica\App\Arguments;
use Friendica\App\BaseURL;
use Friendica\AppHelper;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
@ -35,8 +37,8 @@ use Psr\Log\LoggerInterface;
*/ */
class Magic extends BaseModule class Magic extends BaseModule
{ {
/** @var App */ /** @var AppHelper */
protected $app; protected $appHelper;
/** @var Database */ /** @var Database */
protected $dba; protected $dba;
/** @var ICanSendHttpRequests */ /** @var ICanSendHttpRequests */
@ -44,11 +46,11 @@ class Magic extends BaseModule
/** @var IHandleUserSessions */ /** @var IHandleUserSessions */
protected $userSession; protected $userSession;
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Database $dba, ICanSendHttpRequests $httpClient, IHandleUserSessions $userSession, $server, array $parameters = []) public function __construct(AppHelper $appHelper, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Database $dba, ICanSendHttpRequests $httpClient, IHandleUserSessions $userSession, $server, array $parameters = [])
{ {
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->app = $app; $this->appHelper = $appHelper;
$this->dba = $dba; $this->dba = $dba;
$this->httpClient = $httpClient; $this->httpClient = $httpClient;
$this->userSession = $userSession; $this->userSession = $userSession;
@ -85,11 +87,11 @@ class Magic extends BaseModule
if (empty($contact)) { if (empty($contact)) {
if (!$owa) { if (!$owa) {
$this->logger->info('No contact record found, no oWA, redirecting to destination.', ['request' => $request, 'server' => $_SERVER, 'dest' => $dest]); $this->logger->info('No contact record found, no oWA, redirecting to destination.', ['request' => $request, 'server' => $_SERVER, 'dest' => $dest]);
$this->app->redirect($dest); $this->appHelper->redirect($dest);
} }
} else { } else {
// Redirect if the contact is already authenticated on this site. // Redirect if the contact is already authenticated on this site.
if ($this->app->getContactId() && strpos($contact['nurl'], Strings::normaliseLink($this->baseUrl)) !== false) { if ($this->appHelper->getContactId() && strpos($contact['nurl'], Strings::normaliseLink($this->baseUrl)) !== false) {
$this->logger->info('Contact is already authenticated, redirecting to destination.', ['dest' => $dest]); $this->logger->info('Contact is already authenticated, redirecting to destination.', ['dest' => $dest]);
System::externalRedirect($dest); System::externalRedirect($dest);
} }
@ -99,7 +101,7 @@ class Magic extends BaseModule
if (!$this->userSession->getLocalUserId() || !$owa) { if (!$this->userSession->getLocalUserId() || !$owa) {
$this->logger->notice('Not logged in or not OWA, redirecting to destination.', ['uid' => $this->userSession->getLocalUserId(), 'owa' => $owa, 'dest' => $dest]); $this->logger->notice('Not logged in or not OWA, redirecting to destination.', ['uid' => $this->userSession->getLocalUserId(), 'owa' => $owa, 'dest' => $dest]);
$this->app->redirect($dest); $this->appHelper->redirect($dest);
} }
$dest = Network::removeUrlParameter($dest, 'zid'); $dest = Network::removeUrlParameter($dest, 'zid');
@ -169,7 +171,7 @@ class Magic extends BaseModule
$j = json_decode($curlResult->getBodyString(), true); $j = json_decode($curlResult->getBodyString(), true);
if (empty($j) || !$j['success']) { if (empty($j) || !$j['success']) {
$this->logger->notice('Invalid JSON, redirecting to destination.', ['json' => $j, 'dest' => $dest]); $this->logger->notice('Invalid JSON, redirecting to destination.', ['json' => $j, 'dest' => $dest]);
$this->app->redirect($dest); $this->appHelper->redirect($dest);
} }
if ($j['encrypted_token']) { if ($j['encrypted_token']) {