Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some more deprecated function calls are replaced #14157

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mod/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
use Friendica\Network\HTTPException;
use Friendica\Util\DateTimeFormat;

function item_post(App $a)
function item_post()
{
$uid = DI::userSession()->getLocalUserId();

Expand Down
38 changes: 1 addition & 37 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be used by the calendar, see #14025 (comment)

{
return $this->session->getLocalUserNickname();
}

/**
* Set the profile owner ID
*
Expand Down Expand Up @@ -716,7 +680,7 @@ public function runFrontend(App\Router $router, IManagePersonalConfigValues $pco

// 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)]);
Expand Down
11 changes: 6 additions & 5 deletions src/App/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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;
Expand Down Expand Up @@ -325,13 +326,13 @@ private function curPageURL(): string
*
* @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)) {
Expand Down Expand Up @@ -420,7 +421,7 @@ public function registerFooterScript($path)
* @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();

Expand Down Expand Up @@ -459,7 +460,7 @@ public function run(App $app, BaseURL $baseURL, Arguments $args, Mode $mode, Res
/* 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');

Expand Down
4 changes: 2 additions & 2 deletions src/BaseModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public function getRequestValue(array $input, string $parameter, $default = null
*/
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);

Expand Down Expand Up @@ -390,7 +390,7 @@ public static function checkFormSecurityToken(string $typename = '', string $for

$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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Content/Conversation.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public function formatActivity(array $links, string $verb, int $id, string $acti

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 '';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Content/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static function findPeople(): string

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>';
Expand Down
8 changes: 4 additions & 4 deletions src/Core/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function replaceMacros(string $template, array $vars = []): string
$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);
Expand Down Expand Up @@ -116,7 +116,7 @@ public static function getMarkupTemplate(string $file, string $subDir = ''): str
$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);
Expand Down Expand Up @@ -145,7 +145,7 @@ public static function registerTemplateEngine(string $class)
} 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);
Expand Down Expand Up @@ -179,7 +179,7 @@ public static function getTemplateEngine(): TemplateEngine

$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);
Expand Down
9 changes: 0 additions & 9 deletions src/Model/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 8 additions & 19 deletions src/Model/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public static function getVCardHtml(array $profile, bool $block, bool $show_cont
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']]);
}

Expand All @@ -322,19 +322,19 @@ public static function getVCardHtml(array $profile, bool $block, bool $show_cont

// 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) {
Expand Down Expand Up @@ -696,17 +696,6 @@ public static function getEventsReminderHTML(int $uid, int $pcid): string
]);
}

/**
* 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.
*
Expand All @@ -730,7 +719,7 @@ public static function getMyURL(): string
*/
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()) {
Expand Down Expand Up @@ -916,7 +905,7 @@ public static function zrl(string $url, bool $force = false): string
}

$achar = strpos($url, '?') ? '&' : '?';
$mine = self::getMyURL();
$mine = DI::userSession()->getMyUrl();

if ($mine && !Strings::compareLink($mine, $url)) {
return $url . $achar . 'zrl=' . urlencode($mine);
Expand Down
2 changes: 1 addition & 1 deletion src/Module/BaseAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function checkAdminAccess(bool $interactive = false)
}
}

if (!DI::app()->isSiteAdmin()) {
if (!DI::userSession()->isSiteAdmin()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('You don\'t have access to administration pages.'));
}

Expand Down
19 changes: 10 additions & 9 deletions src/Module/Contact/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -323,24 +324,24 @@ protected function content(array $request = []): string

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')
];
}

Expand Down
10 changes: 5 additions & 5 deletions src/Module/Invite.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function post(array $request = [])
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();
}
}
Expand All @@ -83,11 +83,11 @@ protected function post(array $request = [])
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);
Expand Down Expand Up @@ -139,7 +139,7 @@ protected function content(array $request = []): string
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'));
}
}
Expand Down Expand Up @@ -172,7 +172,7 @@ protected function content(array $request = []): string
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')
Expand Down
Loading