Some more deprecated function calls are replaced

This commit is contained in:
Michael 2024-05-14 08:37:10 +00:00
parent bd6616e84f
commit e12f92e516
30 changed files with 101 additions and 163 deletions

View file

@ -45,7 +45,7 @@ use Friendica\Model\Post;
use Friendica\Network\HTTPException;
use Friendica\Util\DateTimeFormat;
function item_post(App $a)
function item_post()
{
$uid = DI::userSession()->getLocalUserId();

View file

@ -134,42 +134,6 @@ class App
*/
private $session;
/**
* @deprecated 2022.03
* @see IHandleUserSessions::isAuthenticated()
*/
public function isLoggedIn(): bool
{
return $this->session->isAuthenticated();
}
/**
* @deprecated 2022.03
* @see IHandleUserSessions::isSiteAdmin()
*/
public function isSiteAdmin(): bool
{
return $this->session->isSiteAdmin();
}
/**
* @deprecated 2022.03
* @see IHandleUserSessions::getLocalUserId()
*/
public function getLoggedInUserId(): int
{
return $this->session->getLocalUserId();
}
/**
* @deprecated 2022.03
* @see IHandleUserSessions::getLocalUserNickname()
*/
public function getLoggedInUserNickname(): string
{
return $this->session->getLocalUserNickname();
}
/**
* Set the profile owner ID
*
@ -716,7 +680,7 @@ class App
// Wrapping HTML responses in the theme template
if ($response->getHeaderLine(ICanCreateResponses::X_HEADER) === ICanCreateResponses::TYPE_HTML) {
$response = $page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig, $nav, $this->session->getLocalUserId());
$response = $page->run($this, $this->session, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig, $nav, $this->session->getLocalUserId());
}
$this->logger->debug('Request processed sucessfully', ['response' => $response->getStatusCode(), 'address' => $server['REMOTE_ADDR'] ?? '', 'request' => $requeststring, 'referer' => $server['HTTP_REFERER'] ?? '', 'user-agent' => $server['HTTP_USER_AGENT'] ?? '', 'duration' => number_format(microtime(true) - $request_start, 3)]);

View file

@ -32,6 +32,7 @@ use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
use Friendica\Core\Session\Model\UserSession;
use Friendica\Core\System;
use Friendica\Core\Theme;
use Friendica\Module\Response;
@ -325,13 +326,13 @@ class Page implements ArrayAccess
*
* @throws HTTPException\InternalServerErrorException
*/
private function initFooter(App $app, Mode $mode, L10n $l10n)
private function initFooter(UserSession $session, Mode $mode, L10n $l10n)
{
// If you're just visiting, let javascript take you home
if (!empty($_SESSION['visitor_home'])) {
$homebase = $_SESSION['visitor_home'];
} elseif (!empty($app->getLoggedInUserNickname())) {
$homebase = 'profile/' . $app->getLoggedInUserNickname();
} elseif (!empty($session->getLocalUserNickname())) {
$homebase = 'profile/' . $session->getLocalUserNickname();
}
if (isset($homebase)) {
@ -420,7 +421,7 @@ class Page implements ArrayAccess
* @throws HTTPException\InternalServerErrorException
* @throws HTTPException\ServiceUnavailableException
*/
public function run(App $app, BaseURL $baseURL, Arguments $args, Mode $mode, ResponseInterface $response, L10n $l10n, Profiler $profiler, IManageConfigValues $config, IManagePersonalConfigValues $pconfig, Nav $nav, int $localUID)
public function run(App $app, UserSession $session, BaseURL $baseURL, Arguments $args, Mode $mode, ResponseInterface $response, L10n $l10n, Profiler $profiler, IManageConfigValues $config, IManagePersonalConfigValues $pconfig, Nav $nav, int $localUID)
{
$moduleName = $args->getModuleName();
@ -459,7 +460,7 @@ class Page implements ArrayAccess
/* Build the page ending -- this is stuff that goes right before
* the closing </body> tag
*/
$this->initFooter($app, $mode, $l10n);
$this->initFooter($session, $mode, $l10n);
$profiler->set(microtime(true) - $timestamp, 'aftermath');

View file

@ -356,7 +356,7 @@ abstract class BaseModule implements ICanHandleRequests
*/
public static function getFormSecurityToken(string $typename = ''): string
{
$user = User::getById(DI::app()->getLoggedInUserId(), ['guid', 'prvkey']);
$user = User::getById(DI::userSession()->getLocalUserId(), ['guid', 'prvkey']);
$timestamp = time();
$sec_hash = hash('whirlpool', ($user['guid'] ?? '') . ($user['prvkey'] ?? '') . session_id() . $timestamp . $typename);
@ -390,7 +390,7 @@ abstract class BaseModule implements ICanHandleRequests
$max_livetime = 10800; // 3 hours
$user = User::getById(DI::app()->getLoggedInUserId(), ['guid', 'prvkey']);
$user = User::getById(DI::userSession()->getLocalUserId(), ['guid', 'prvkey']);
$x = explode('.', $hash);
if (time() > (intval($x[0]) + $max_livetime)) {

View file

@ -308,7 +308,7 @@ class Conversation
public function statusEditor(array $x = [], int $notes_cid = 0, bool $popup = false): string
{
$user = User::getById($this->app->getLoggedInUserId(), ['uid', 'nickname', 'allow_location', 'default-location']);
$user = User::getById($this->session->getLocalUserId(), ['uid', 'nickname', 'allow_location', 'default-location']);
if (empty($user['uid'])) {
return '';
}

View file

@ -67,7 +67,7 @@ class Widget
if (DI::config()->get('system', 'invitation_only')) {
$x = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'invites_remaining'));
if ($x || DI::app()->isSiteAdmin()) {
if ($x || DI::userSession()->isSiteAdmin()) {
DI::page()['aside'] .= '<div class="side-link widget" id="side-invite-remain">'
. DI::l10n()->tt('%d invitation available', '%d invitations available', $x)
. '</div>';

View file

@ -87,7 +87,7 @@ class Renderer
$output = $t->replaceMacros($template, $vars);
} catch (Exception $e) {
DI::logger()->critical($e->getMessage(), ['template' => $template, 'vars' => $vars]);
$message = DI::app()->isSiteAdmin() ?
$message = DI::userSession()->isSiteAdmin() ?
$e->getMessage() :
DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.');
throw new ServiceUnavailableException($message);
@ -116,7 +116,7 @@ class Renderer
$template = $t->getTemplateFile($file, $subDir);
} catch (Exception $e) {
DI::logger()->critical($e->getMessage(), ['file' => $file, 'subDir' => $subDir]);
$message = DI::app()->isSiteAdmin() ?
$message = DI::userSession()->isSiteAdmin() ?
$e->getMessage() :
DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.');
throw new ServiceUnavailableException($message);
@ -145,7 +145,7 @@ class Renderer
} else {
$admin_message = DI::l10n()->t('template engine cannot be registered without a name.');
DI::logger()->critical($admin_message, ['class' => $class]);
$message = DI::app()->isSiteAdmin() ?
$message = DI::userSession()->isSiteAdmin() ?
$admin_message :
DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.');
throw new ServiceUnavailableException($message);
@ -179,7 +179,7 @@ class Renderer
$admin_message = DI::l10n()->t('template engine is not registered!');
DI::logger()->critical($admin_message, ['template_engine' => $template_engine]);
$message = DI::app()->isSiteAdmin() ?
$message = DI::userSession()->isSiteAdmin() ?
$admin_message :
DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.');
throw new ServiceUnavailableException($message);

View file

@ -113,15 +113,6 @@ class Contact
* @}
*/
/** @deprecated Use Entity\LocalRelationship::MIRROR_DEACTIVATED instead */
const MIRROR_DEACTIVATED = LocalRelationship::MIRROR_DEACTIVATED;
/** @deprecated Now does the same as MIRROR_OWN_POST */
const MIRROR_FORWARDED = 1;
/** @deprecated Use Entity\LocalRelationship::MIRROR_OWN_POST instead */
const MIRROR_OWN_POST = LocalRelationship::MIRROR_OWN_POST;
/** @deprecated Use Entity\LocalRelationship::MIRROR_NATIVE_RESHARE instead */
const MIRROR_NATIVE_RESHARE = LocalRelationship::MIRROR_NATIVE_RESHARE;
/**
* @param array $fields Array of selected fields, empty for all
* @param array $condition Array of fields for condition

View file

@ -297,7 +297,7 @@ class Profile
if (DI::userSession()->getLocalUserId() && ($profile['uid'] ?? 0) != DI::userSession()->getLocalUserId()) {
$profile_contact = Contact::getByURL($profile['nurl'], null, [], DI::userSession()->getLocalUserId());
}
if (!empty($profile['cid']) && self::getMyURL()) {
if (!empty($profile['cid']) && DI::userSession()->getMyUrl()) {
$profile_contact = Contact::selectFirst([], ['id' => $profile['cid']]);
}
@ -322,19 +322,19 @@ class Profile
// Who is the logged-in user to this profile?
$visitor_contact = [];
if (!empty($profile['uid']) && self::getMyURL()) {
$visitor_contact = Contact::selectFirst(['rel'], ['uid' => $profile['uid'], 'nurl' => Strings::normaliseLink(self::getMyURL())]);
if (!empty($profile['uid']) && DI::userSession()->getMyUrl()) {
$visitor_contact = Contact::selectFirst(['rel'], ['uid' => $profile['uid'], 'nurl' => Strings::normaliseLink(DI::userSession()->getMyUrl())]);
}
$local_user_is_self = self::getMyURL() && ($profile['url'] == self::getMyURL());
$visitor_is_authenticated = (bool)self::getMyURL();
$local_user_is_self = DI::userSession()->getMyUrl() && ($profile['url'] == DI::userSession()->getMyUrl());
$visitor_is_authenticated = (bool)DI::userSession()->getMyUrl();
$visitor_is_following =
in_array($visitor_contact['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND])
|| in_array($profile_contact['rel'] ?? 0, [Contact::SHARING, Contact::FRIEND]);
$visitor_is_followed =
in_array($visitor_contact['rel'] ?? 0, [Contact::SHARING, Contact::FRIEND])
|| in_array($profile_contact['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND]);
$visitor_base_path = self::getMyURL() ? preg_replace('=/profile/(.*)=ism', '', self::getMyURL()) : '';
$visitor_base_path = DI::userSession()->getMyUrl() ? preg_replace('=/profile/(.*)=ism', '', DI::userSession()->getMyUrl()) : '';
if (!$local_user_is_self) {
if (!$visitor_is_authenticated) {
@ -696,17 +696,6 @@ class Profile
]);
}
/**
* Retrieves the my_url session variable
*
* @return string
* @deprecated since version 2022.12, please use UserSession->getMyUrl instead
*/
public static function getMyURL(): string
{
return DI::userSession()->getMyUrl();
}
/**
* Process the 'zrl' parameter and initiate the remote authentication.
*
@ -730,7 +719,7 @@ class Profile
*/
public static function zrlInit(App $a)
{
$my_url = self::getMyURL();
$my_url = DI::userSession()->getMyUrl();
$my_url = Network::isUrlValid($my_url);
if (empty($my_url) || DI::userSession()->getLocalUserId()) {
@ -916,7 +905,7 @@ class Profile
}
$achar = strpos($url, '?') ? '&' : '?';
$mine = self::getMyURL();
$mine = DI::userSession()->getMyUrl();
if ($mine && !Strings::compareLink($mine, $url)) {
return $url . $achar . 'zrl=' . urlencode($mine);

View file

@ -59,7 +59,7 @@ abstract class BaseAdmin extends BaseModule
}
}
if (!DI::app()->isSiteAdmin()) {
if (!DI::userSession()->isSiteAdmin()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('You don\'t have access to administration pages.'));
}

View file

@ -24,6 +24,7 @@ namespace Friendica\Module\Contact;
use Friendica\App;
use Friendica\BaseModule;
use Friendica\Contact\LocalRelationship;
use Friendica\Contact\LocalRelationship\Entity\LocalRelationship as LocalRelationshipEntity;
use Friendica\Content\ContactSelector;
use Friendica\Content\Nav;
use Friendica\Content\Text\BBCode;
@ -323,24 +324,24 @@ class Profile extends BaseModule
if ($contact['network'] == Protocol::FEED) {
$remote_self_options = [
Contact::MIRROR_DEACTIVATED => $this->t('No mirroring'),
Contact::MIRROR_OWN_POST => $this->t('Mirror as my own posting')
LocalRelationshipEntity::MIRROR_DEACTIVATED => $this->t('No mirroring'),
LocalRelationshipEntity::MIRROR_OWN_POST => $this->t('Mirror as my own posting')
];
} elseif ($contact['network'] == Protocol::ACTIVITYPUB) {
$remote_self_options = [
Contact::MIRROR_DEACTIVATED => $this->t('No mirroring'),
Contact::MIRROR_NATIVE_RESHARE => $this->t('Native reshare')
LocalRelationshipEntity::MIRROR_DEACTIVATED => $this->t('No mirroring'),
LocalRelationshipEntity::MIRROR_NATIVE_RESHARE => $this->t('Native reshare')
];
} elseif ($contact['network'] == Protocol::DFRN) {
$remote_self_options = [
Contact::MIRROR_DEACTIVATED => $this->t('No mirroring'),
Contact::MIRROR_OWN_POST => $this->t('Mirror as my own posting'),
Contact::MIRROR_NATIVE_RESHARE => $this->t('Native reshare')
LocalRelationshipEntity::MIRROR_DEACTIVATED => $this->t('No mirroring'),
LocalRelationshipEntity::MIRROR_OWN_POST => $this->t('Mirror as my own posting'),
LocalRelationshipEntity::MIRROR_NATIVE_RESHARE => $this->t('Native reshare')
];
} else {
$remote_self_options = [
Contact::MIRROR_DEACTIVATED => $this->t('No mirroring'),
Contact::MIRROR_OWN_POST => $this->t('Mirror as my own posting')
LocalRelationshipEntity::MIRROR_DEACTIVATED => $this->t('No mirroring'),
LocalRelationshipEntity::MIRROR_OWN_POST => $this->t('Mirror as my own posting')
];
}

View file

@ -68,7 +68,7 @@ class Invite extends BaseModule
if ($config->get('system', 'invitation_only')) {
$invitation_only = true;
$invites_remaining = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'invites_remaining');
if ((!$invites_remaining) && (!$app->isSiteAdmin())) {
if ((!$invites_remaining) && (!DI::userSession()->isSiteAdmin())) {
throw new HTTPException\ForbiddenException();
}
}
@ -83,11 +83,11 @@ class Invite extends BaseModule
continue;
}
if ($invitation_only && ($invites_remaining || $app->isSiteAdmin())) {
if ($invitation_only && ($invites_remaining || DI::userSession()->isSiteAdmin())) {
$code = Model\Register::createForInvitation();
$nmessage = str_replace('$invite_code', $code, $message);
if (!$app->isSiteAdmin()) {
if (!DI::userSession()->isSiteAdmin()) {
$invites_remaining--;
if ($invites_remaining >= 0) {
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'invites_remaining', $invites_remaining);
@ -139,7 +139,7 @@ class Invite extends BaseModule
if ($config->get('system', 'invitation_only')) {
$inviteOnly = true;
$x = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'invites_remaining');
if ((!$x) && (!$app->isSiteAdmin())) {
if ((!$x) && (!DI::userSession()->isSiteAdmin())) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('You have no more invitations available'));
}
}
@ -172,7 +172,7 @@ class Invite extends BaseModule
DI::l10n()->t('You are cordially invited to join me and other close friends on Friendica - and help us to create a better social web.') . "\r\n" . "\r\n"
. $linkTxt
. "\r\n" . "\r\n" . (($inviteOnly) ? DI::l10n()->t('You will need to supply this invitation code: $invite_code') . "\r\n" . "\r\n" : '') . DI::l10n()->t('Once you have registered, please connect with me via my profile page at:')
. "\r\n" . "\r\n" . DI::baseUrl() . '/profile/' . $app->getLoggedInUserNickname()
. "\r\n" . "\r\n" . DI::baseUrl() . '/profile/' . DI::userSession()->getLocalUserNickname()
. "\r\n" . "\r\n" . DI::l10n()->t('For more information about the Friendica project and why we feel it is important, please visit http://friendi.ca') . "\r\n" . "\r\n",
],
'$submit' => DI::l10n()->t('Submit')

View file

@ -31,9 +31,9 @@ use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
use Friendica\Core\Session\Model\UserSession;
use Friendica\Core\Theme;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\User;
@ -64,7 +64,14 @@ class Compose extends BaseModule
/** @var IManageConfigValues */
private $config;
public function __construct(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 = [])
/** @var UserSession */
private $session;
/** @var App */
private $app;
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 = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
@ -73,6 +80,8 @@ class Compose extends BaseModule
$this->page = $page;
$this->pConfig = $pConfig;
$this->config = $config;
$this->session = $session;
$this->app = $app;
}
protected function post(array $request = [])
@ -80,7 +89,7 @@ class Compose extends BaseModule
if (!empty($_REQUEST['body'])) {
$_REQUEST['return'] = 'network';
require_once 'mod/item.php';
item_post(DI::app());
item_post();
} else {
$this->systemMessages->addNotice($this->l10n->t('Please enter a post body.'));
}
@ -88,13 +97,11 @@ class Compose extends BaseModule
protected function content(array $request = []): string
{
if (!DI::userSession()->getLocalUserId()) {
if (!$this->session->getLocalUserId()) {
return Login::form('compose');
}
$a = DI::app();
if ($a->getCurrentTheme() !== 'frio') {
if ($this->app->getCurrentTheme() !== 'frio') {
throw new NotImplementedException($this->l10n->t('This feature is only available with the frio theme.'));
}
@ -110,7 +117,7 @@ class Compose extends BaseModule
}
}
$user = User::getById(DI::userSession()->getLocalUserId(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'default-location']);
$user = User::getById($this->session->getLocalUserId(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'default-location']);
$contact_allow_list = $this->ACLFormatter->expand($user['allow_cid']);
$circle_allow_list = $this->ACLFormatter->expand($user['allow_gid']);
@ -122,7 +129,7 @@ class Compose extends BaseModule
$compose_title = $this->l10n->t('Compose new personal note');
$type = 'note';
$doesFederate = false;
$contact_allow_list = [$a->getContactId()];
$contact_allow_list = [$this->app->getContactId()];
$circle_allow_list = [];
$contact_deny_list = [];
$circle_deny_list = [];
@ -165,9 +172,9 @@ class Compose extends BaseModule
$this->page->registerFooterScript(Theme::getPathForFile('js/linkPreview.js'));
$this->page->registerFooterScript(Theme::getPathForFile('js/compose.js'));
$contact = Contact::getById($a->getContactId());
$contact = Contact::getById($this->app->getContactId());
if ($this->pConfig->get(DI::userSession()->getLocalUserId(), 'system', 'set_creation_date')) {
if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'set_creation_date')) {
$created_at = Temporal::getDateTimeField(
new \DateTime(DBA::NULL_DATETIME),
new \DateTime('now'),
@ -205,8 +212,8 @@ class Compose extends BaseModule
'location_disabled' => $this->l10n->t('Location services are disabled. Please check the website\'s permissions on your device'),
'wait' => $this->l10n->t('Please wait'),
'placeholdertitle' => $this->l10n->t('Set title'),
'placeholdercategory' => Feature::isEnabled(DI::userSession()->getLocalUserId(), Feature::CATEGORIES) ? $this->l10n->t('Categories (comma-separated list)') : '',
'always_open_compose' => $this->pConfig->get(DI::userSession()->getLocalUserId(), 'frio', 'always_open_compose',
'placeholdercategory' => Feature::isEnabled($this->session->getLocalUserId(), Feature::CATEGORIES) ? $this->l10n->t('Categories (comma-separated list)') : '',
'always_open_compose' => $this->pConfig->get($this->session->getLocalUserId(), 'frio', 'always_open_compose',
$this->config->get('frio', 'always_open_compose', false)) ? '' :
$this->l10n->t('You can make this page always open when you use the New Post button in the <a href="/settings/display">Theme Customization settings</a>.'),
],
@ -237,7 +244,7 @@ class Compose extends BaseModule
'$jotplugins' => $jotplugins,
'$rand_num' => Crypto::randomDigits(12),
'$acl_selector' => ACL::getFullSelectorHTML($this->page, $a->getLoggedInUserId(), $doesFederate, [
'$acl_selector' => ACL::getFullSelectorHTML($this->page, $this->session->getLocalUserId(), $doesFederate, [
'allow_cid' => $contact_allow_list,
'allow_gid' => $circle_allow_list,
'deny_cid' => $contact_deny_list,

View file

@ -188,7 +188,7 @@ class Display extends BaseModule
$author = Contact::getById($item['author-id']);
}
if (Network::isLocalLink($author['url'])) {
if ($this->baseUrl->isLocalUrl($author['url'])) {
Profile::load($this->app, $author['nick'], false);
} else {
$this->page['aside'] = Widget\VCard::getHTML($author);

View file

@ -66,7 +66,7 @@ class Contact extends BaseModeration
$this->baseUrl->redirect('moderation/blocklist/contact');
}
if (Network::isLocalLink($contact['nurl'])) {
if ($this->baseUrl->isLocalUrl($contact['nurl'])) {
$this->systemMessages->addNotice($this->t('You can\'t block a local contact, please block the user instead'));
$this->baseUrl->redirect('moderation/blocklist/contact');
}

View file

@ -293,7 +293,7 @@ class Create extends BaseModule
'$ignore' => ['contact_action', $this->t('Ignore contact'), self::CONTACT_ACTION_IGNORE, $this->t("Their posts won't appear in your Network page anymore, but their replies can appear in forum threads. They still can follow you.")],
'$block' => ['contact_action', $this->t('Block contact'), self::CONTACT_ACTION_BLOCK, $this->t("Their posts won't appear in your Network page anymore, but their replies can appear in forum threads, with their content collapsed by default. They cannot follow you but still can have access to your public posts by other means.")],
'$display_forward' => !Network::isLocalLink($contact['url']),
'$display_forward' => !$this->baseUrl->isLocalUrl($contact['url']),
'$forward' => ['report_forward', $this->t('Forward report'), self::CONTACT_ACTION_BLOCK, $this->t('Would you ike to forward this report to the remote server?')],
'$summary' => $this->getAside($request),

View file

@ -157,7 +157,7 @@ class Conversations extends BaseProfile
'allow_location' => ($is_owner || $commvisitor) && $profile['allow_location'],
'default_location' => $is_owner ? $profile['default-location'] : '',
'nickname' => $profile['nickname'],
'acl' => $is_owner ? ACL::getFullSelectorHTML($this->page, $this->app->getLoggedInUserId(), true) : '',
'acl' => $is_owner ? ACL::getFullSelectorHTML($this->page, $this->session->getLocalUserId(), true) : '',
'visitor' => $is_owner || $commvisitor ? 'block' : 'none',
'profile_uid' => $profile['uid'],
];

View file

@ -64,7 +64,7 @@ class Logout extends BaseModule
{
$visitor_home = null;
if ($this->session->getRemoteUserId()) {
$visitor_home = Profile::getMyURL();
$visitor_home = $this->session->getMyUrl();
$this->cache->delete('zrlInit:' . $visitor_home);
}

View file

@ -73,7 +73,7 @@ class Recovery extends BaseModule
$this->session->set('2fa', true);
DI::sysmsg()->addInfo($this->t('Remaining recovery codes: %d', RecoveryCode::countValidForUser($this->session->getLocalUserId())));
$this->auth->setForUser($this->app, User::getById($this->app->getLoggedInUserId()), true, true);
$this->auth->setForUser($this->app, User::getById($this->session->getLocalUserId()), true, true);
$this->baseUrl->redirect($this->session->pop('return_path', ''));
} else {

View file

@ -102,13 +102,13 @@ class Trust extends BaseModule
}
try {
$this->auth->setForUser($this->app, User::getById($this->app->getLoggedInUserId()), true, true);
$this->auth->setForUser($this->app, User::getById($this->session->getLocalUserId()), true, true);
$this->baseUrl->redirect($this->session->pop('return_path', ''));
} catch (FoundException | TemporaryRedirectException | MovedPermanentlyException $e) {
// exception wanted!
throw $e;
} catch (\Exception $e) {
$this->logger->warning('Unexpected error during authentication.', ['user' => $this->app->getLoggedInUserId(), 'exception' => $exception]);
$this->logger->warning('Unexpected error during authentication.', ['user' => $this->session->getLocalUserId(), 'exception' => $exception]);
}
}
}
@ -123,15 +123,15 @@ class Trust extends BaseModule
try {
$trustedBrowser = $this->trustedBrowserRepository->selectOneByHash($this->cookie->get('2fa_cookie_hash'));
if (!$trustedBrowser->trusted) {
$this->auth->setForUser($this->app, User::getById($this->app->getLoggedInUserId()), true, true);
$this->auth->setForUser($this->app, User::getById($this->session->getLocalUserId()), true, true);
$this->baseUrl->redirect($this->session->pop('return_path', ''));
}
} catch (TrustedBrowserNotFoundException $exception) {
$this->logger->notice('Trusted Browser of the cookie not found.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->app->getLoggedInUserId(), 'exception' => $exception]);
$this->logger->notice('Trusted Browser of the cookie not found.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->session->getLocalUserId(), 'exception' => $exception]);
} catch (TrustedBrowserPersistenceException $exception) {
$this->logger->warning('Unexpected persistence exception.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->app->getLoggedInUserId(), 'exception' => $exception]);
$this->logger->warning('Unexpected persistence exception.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->session->getLocalUserId(), 'exception' => $exception]);
} catch (\Exception $exception) {
$this->logger->warning('Unexpected exception.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->app->getLoggedInUserId(), 'exception' => $exception]);
$this->logger->warning('Unexpected exception.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->session->getLocalUserId(), 'exception' => $exception]);
}
}

View file

@ -46,7 +46,7 @@ class Account extends BaseSettings
{
protected function post(array $request = [])
{
if (!DI::app()->isLoggedIn()) {
if (!DI::userSession()->isAuthenticated()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
@ -56,7 +56,7 @@ class Account extends BaseSettings
$a = DI::app();
$user = User::getById($a->getLoggedInUserId());
$user = User::getById($this->session->getLocalUserId());
if (!empty($request['password-submit'])) {
$newpass = $request['password'];
@ -394,7 +394,7 @@ class Account extends BaseSettings
$a = DI::app();
$user = User::getById($a->getLoggedInUserId());
$user = User::getById($this->session->getLocalUserId());
$username = $user['username'];
$email = $user['email'];
@ -591,7 +591,7 @@ class Account extends BaseSettings
'$circle_select' => Circle::getSelectorHTML(DI::userSession()->getLocalUserId(), $user['def_gid'], 'circle-selection', DI::l10n()->t('Default privacy circle for new contacts')),
'$circle_select_group' => Circle::getSelectorHTML(DI::userSession()->getLocalUserId(), DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'default-group-gid', $user['def_gid']), 'circle-selection-group', DI::l10n()->t('Default privacy circle for new group contacts')),
'$permissions' => DI::l10n()->t('Default Post Permissions'),
'$aclselect' => ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId()),
'$aclselect' => ACL::getFullSelectorHTML(DI::page(), $this->session->getLocalUserId()),
'$expire' => [
'label' => DI::l10n()->t('Expiration settings'),

View file

@ -27,6 +27,7 @@ use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session\Model\UserSession;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\Database;
@ -48,9 +49,6 @@ class Import extends \Friendica\BaseModule
{
const IMPORT_DEBUG = false;
/** @var App */
private $app;
/** @var IManageConfigValues */
private $config;
@ -66,21 +64,24 @@ class Import extends \Friendica\BaseModule
/** @var PermissionSet */
private $permissionSet;
public function __construct(PermissionSet $permissionSet, IManagePersonalConfigValues $pconfig, Database $database, SystemMessages $systemMessages, IManageConfigValues $config, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
/** @var UserSession */
private $session;
public function __construct(UserSession $session, PermissionSet $permissionSet, IManagePersonalConfigValues $pconfig, Database $database, SystemMessages $systemMessages, 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->app = $app;
$this->config = $config;
$this->pconfig = $pconfig;
$this->systemMessages = $systemMessages;
$this->database = $database;
$this->permissionSet = $permissionSet;
$this->session = $session;
}
protected function post(array $request = [])
{
if (\Friendica\Module\Register::getPolicy() !== \Friendica\Module\Register::OPEN && !$this->app->isSiteAdmin()) {
if (\Friendica\Module\Register::getPolicy() !== \Friendica\Module\Register::OPEN && !$this->session->isSiteAdmin()) {
throw new HttpException\ForbiddenException($this->t('Permission denied.'));
}
@ -99,7 +100,7 @@ class Import extends \Friendica\BaseModule
protected function content(array $request = []): string
{
if ((\Friendica\Module\Register::getPolicy() !== \Friendica\Module\Register::OPEN) && !$this->app->isSiteAdmin()) {
if ((\Friendica\Module\Register::getPolicy() !== \Friendica\Module\Register::OPEN) && !$this->session->isSiteAdmin()) {
$this->systemMessages->addNotice($this->t('User imports on closed servers can only be done by an administrator.'));
}

View file

@ -83,7 +83,7 @@ class HttpClient implements ICanSendHttpRequests
return CurlResult::createErrorCurl($this->logger, $url);
}
if (Network::isLocalLink($url)) {
if ($this->baseUrl->isLocalUrl($url)) {
$this->logger->info('Local link', ['url' => $url]);
}
@ -249,7 +249,7 @@ class HttpClient implements ICanSendHttpRequests
{
$this->profiler->startRecording('network');
if (Network::isLocalLink($url)) {
if ($this->baseUrl->isLocalUrl($url)) {
$this->logger->debug('Local link', ['url' => $url]);
}

View file

@ -25,30 +25,30 @@ use Friendica\App;
use Friendica\App\BaseURL;
use Friendica\Content\Text\HTML;
use Friendica\Core\L10n;
use Friendica\Core\Session\Model\UserSession;
use Friendica\Model\Item;
use Friendica\Model\User;
use Friendica\Object\Email;
use Friendica\Protocol\Email as EmailProtocol;
/**
* Class for creating CC emails based on a received item
*/
class ItemCCEMail extends Email
{
public function __construct(App $a, L10n $l10n, BaseURL $baseUrl, array $item, string $toAddress, string $authorThumb)
public function __construct(UserSession $session, L10n $l10n, BaseURL $baseUrl, array $item, string $toAddress, string $authorThumb)
{
$user = User::getById($a->getLoggedInUserId());
$user = User::getById($session->getLocalUserId());
$disclaimer = '<hr />' . $l10n->t('This message was sent to you by %s, a member of the Friendica social network.', $user['username'])
. '<br />';
$disclaimer .= $l10n->t('You may visit them online at %s', $baseUrl . '/profile/' . $a->getLoggedInUserNickname()) . '<br />';
$disclaimer .= $l10n->t('You may visit them online at %s', $baseUrl . '/profile/' . $session->getLocalUserNickname()) . '<br />';
$disclaimer .= $l10n->t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . '<br />';
if (!$item['title'] == '') {
$subject = $item['title'];
} else {
$subject = '[Friendica]' . ' ' . $l10n->t('%s posted an update.', $user['username']);
}
$link = '<a href="' . $baseUrl . '/profile/' . $a->getLoggedInUserNickname() . '"><img src="' . $authorThumb . '" alt="' . $user['username'] . '" /></a><br /><br />';
$link = '<a href="' . $baseUrl . '/profile/' . $session->getLocalUserNickname() . '"><img src="' . $authorThumb . '" alt="' . $user['username'] . '" /></a><br /><br />';
$html = Item::prepareBody($item);
$message = '<html><body>' . $link . $html . $disclaimer . '</body></html>';;

View file

@ -1071,13 +1071,11 @@ class Post
*/
private function getDefaultText(): string
{
$a = DI::app();
if (!DI::userSession()->getLocalUserId()) {
return '';
}
$owner = User::getOwnerDataById($a->getLoggedInUserId());
$owner = User::getOwnerDataById(DI::userSession()->getLocalUserId());
$item = $this->getData();
if (!empty($item['content-warning']) && Feature::isEnabled(DI::userSession()->getLocalUserId(), Feature::ADD_ABSTRACT)) {
@ -1124,8 +1122,6 @@ class Post
*/
private function getCommentBox(string $indent)
{
$a = DI::app();
$comment_box = '';
$conv = $this->getThread();
@ -1144,7 +1140,7 @@ class Post
$uid = $conv->getProfileOwner();
$parent_uid = $this->getDataValue('uid');
$owner = User::getOwnerDataById($a->getLoggedInUserId());
$owner = User::getOwnerDataById(DI::userSession()->getLocalUserId());
$default_text = $this->getDefaultText();

View file

@ -55,7 +55,7 @@ final class FriendicaSmartyEngine extends TemplateEngine
if (!is_writable($work_dir)) {
$admin_message = DI::l10n()->t('The folder %s must be writable by webserver.', $work_dir);
DI::logger()->critical($admin_message);
$message = DI::app()->isSiteAdmin() ?
$message = DI::userSession()->isSiteAdmin() ?
$admin_message :
DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.');
throw new ServiceUnavailableException($message);

View file

@ -648,19 +648,6 @@ class Network
}
}
/**
* Check if the given URL is a local link
*
* @param string $url
*
* @return bool
* @deprecated since 2023.09, please use BaseUrl->isLocalUrl or BaseUrl->isLocalUri instead.
*/
public static function isLocalLink(string $url): bool
{
return DI::baseUrl()->isLocalUrl($url);
}
/**
* Check if the given URL is a valid HTTP/HTTPS URL
*

View file

@ -40,6 +40,7 @@
* If you need to run a script before the database update, name the function "pre_update_4712()"
*/
use Friendica\Contact\LocalRelationship\Entity\LocalRelationship;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
@ -1133,7 +1134,7 @@ function update_1481()
function update_1491()
{
DBA::update('contact', ['remote_self' => Contact::MIRROR_OWN_POST], ['remote_self' => Contact::MIRROR_FORWARDED]);
DBA::update('contact', ['remote_self' => LocalRelationship::MIRROR_OWN_POST], ['remote_self' => 1]);
return Update::SUCCESS;
}

View file

@ -57,9 +57,9 @@ function theme_post(App $a)
}
}
function theme_admin_post(App $a)
function theme_admin_post()
{
if (!$a->isSiteAdmin()) {
if (!DI::userSession()->isSiteAdmin()) {
return;
}

View file

@ -199,7 +199,7 @@ function frio_remote_nav(array &$nav_info)
{
if (DI::mode()->has(App\Mode::MAINTENANCEDISABLED)) {
// get the homelink from $_SESSION
$homelink = Profile::getMyURL();
$homelink = DI::userSession()->getMyUrl();
if (!$homelink) {
$homelink = DI::session()->get('visitor_home', '');
}
@ -212,7 +212,7 @@ function frio_remote_nav(array &$nav_info)
} elseif (!DI::userSession()->getLocalUserId() && DI::userSession()->getRemoteUserId()) {
$remoteUser = Contact::getById(DI::userSession()->getRemoteUserId(), $fields);
$nav_info['nav']['remote'] = DI::l10n()->t('Guest');
} elseif (Profile::getMyURL()) {
} elseif (DI::userSession()->getMyUrl()) {
$remoteUser = Contact::getByURL($homelink, null, $fields);
$nav_info['nav']['remote'] = DI::l10n()->t('Visitor');
} else {