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

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