Merge pull request #14570 from Art4/replace-app-with-apphelper

[Refactoring] Replace App with AppHelper
This commit is contained in:
Hypolite Petovan 2024-11-29 15:50:51 -05:00 committed by GitHub
commit a06e18a4bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 40 additions and 43 deletions

View file

@ -16,7 +16,6 @@
* information. * information.
*/ */
use Friendica\AppHelper;
use Friendica\Content\Conversation; use Friendica\Content\Conversation;
use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode;
use Friendica\Core\Hook; use Friendica\Core\Hook;
@ -330,7 +329,7 @@ function item_post_return($baseurl, $return_path)
System::jsonExit($json); System::jsonExit($json);
} }
function item_content(AppHelper $appHelper) function item_content()
{ {
if (!DI::userSession()->isAuthenticated()) { if (!DI::userSession()->isAuthenticated()) {
throw new HTTPException\UnauthorizedException(); throw new HTTPException\UnauthorizedException();

View file

@ -7,7 +7,6 @@
* *
*/ */
use Friendica\AppHelper;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
@ -15,7 +14,7 @@ use Friendica\Model\User;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings; use Friendica\Util\Strings;
function lostpass_post(AppHelper $a) function lostpass_post()
{ {
$loginame = trim($_POST['login-name']); $loginame = trim($_POST['login-name']);
if (!$loginame) { if (!$loginame) {
@ -78,7 +77,7 @@ function lostpass_post(AppHelper $a)
DI::baseUrl()->redirect(); DI::baseUrl()->redirect();
} }
function lostpass_content(AppHelper $appHelper) function lostpass_content()
{ {
if (DI::args()->getArgc() > 1) { if (DI::args()->getArgc() > 1) {
$pwdreset_token = DI::args()->getArgv()[1]; $pwdreset_token = DI::args()->getArgv()[1];

View file

@ -7,7 +7,6 @@
* *
*/ */
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 +16,7 @@ use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Module\BaseProfile; use Friendica\Module\BaseProfile;
function notes_init(AppHelper $appHelper) function notes_init()
{ {
if (! DI::userSession()->getLocalUserId()) { if (! DI::userSession()->getLocalUserId()) {
return; return;
@ -27,8 +26,10 @@ function notes_init(AppHelper $appHelper)
} }
function notes_content(AppHelper $appHelper, bool $update = false) function notes_content(bool $update = false)
{ {
$contactId = DI::appHelper()->getContactId();
if (!DI::userSession()->getLocalUserId()) { if (!DI::userSession()->getLocalUserId()) {
DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
return; return;
@ -46,11 +47,11 @@ function notes_content(AppHelper $appHelper, bool $update = false)
'acl_data' => '', 'acl_data' => '',
]; ];
$o .= DI::conversation()->statusEditor($x, $appHelper->getContactId()); $o .= DI::conversation()->statusEditor($x, $contactId);
} }
$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'=> $appHelper->getContactId()]; 'contact-id'=> $contactId];
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

@ -28,9 +28,7 @@ use Friendica\Model\Tag;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Module\BaseProfile; use Friendica\Module\BaseProfile;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Network\Probe;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
use Friendica\Protocol\ActivityNamespace;
use Friendica\Security\Security; use Friendica\Security\Security;
use Friendica\Util\Crypto; use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -49,7 +47,7 @@ function photos_init()
Nav::setSelected('home'); Nav::setSelected('home');
if (DI::args()->getArgc() > 1) { if (DI::args()->getArgc() > 1) {
$owner = Profile::load(DI::app(), DI::args()->getArgv()[1], false); $owner = Profile::load(DI::appHelper(), DI::args()->getArgv()[1], false);
if (!isset($owner['account_removed']) || $owner['account_removed']) { if (!isset($owner['account_removed']) || $owner['account_removed']) {
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.')); throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
} }

View file

@ -9,14 +9,13 @@
* *
*/ */
use Friendica\AppHelper;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\Contact; use Friendica\Model\Contact;
function update_contact_content(AppHelper $appHelper) function update_contact_content()
{ {
if (!empty(DI::args()->get(1)) && !empty($_GET['force'])) { if (!empty(DI::args()->get(1)) && !empty($_GET['force'])) {
$contact = DBA::selectFirst('account-user-view', ['pid', 'deleted'], ['id' => DI::args()->get(1)]); $contact = DBA::selectFirst('account-user-view', ['pid', 'deleted'], ['id' => DI::args()->get(1)]);

View file

@ -8,12 +8,11 @@
* AJAX synchronisation of notes page * AJAX synchronisation of notes page
*/ */
use Friendica\AppHelper;
use Friendica\Core\System; use Friendica\Core\System;
require_once 'mod/notes.php'; require_once 'mod/notes.php';
function update_notes_content(AppHelper $appHelper) function update_notes_content()
{ {
$profile_uid = intval($_GET['p']); $profile_uid = intval($_GET['p']);
@ -27,7 +26,7 @@ function update_notes_content(AppHelper $appHelper)
* *
*/ */
$text = notes_content($appHelper, $profile_uid); $text = notes_content($profile_uid);
System::htmlUpdateExit($text); System::htmlUpdateExit($text);
} }

View file

@ -155,7 +155,7 @@ class Addon
@include_once($addon_file_path); @include_once($addon_file_path);
if (function_exists($addon . '_install')) { if (function_exists($addon . '_install')) {
$func = $addon . '_install'; $func = $addon . '_install';
$func(DI::app()); $func();
} }
DI::config()->set('addons', $addon, [ DI::config()->set('addons', $addon, [

View file

@ -78,8 +78,7 @@ class LegacyModule extends BaseModule
$function_name = $this->moduleName . '_' . $function_suffix; $function_name = $this->moduleName . '_' . $function_suffix;
if (\function_exists($function_name)) { if (\function_exists($function_name)) {
$a = DI::app(); return $function_name() ?? '';
return $function_name($a) ?? '';
} }
return ''; return '';

View file

@ -31,7 +31,7 @@ class Details extends BaseAdmin
self::checkFormSecurityTokenRedirectOnError($redirect, 'admin_addons_details'); self::checkFormSecurityTokenRedirectOnError($redirect, 'admin_addons_details');
$func = $addon . '_addon_admin_post'; $func = $addon . '_addon_admin_post';
$func(DI::app()); $func();
} }
} }
@ -42,8 +42,6 @@ class Details extends BaseAdmin
{ {
parent::content(); parent::content();
$a = DI::app();
$addons_admin = Addon::getAdminList(); $addons_admin = Addon::getAdminList();
$addon = Strings::sanitizeFilePathItem($this->parameters['addon']); $addon = Strings::sanitizeFilePathItem($this->parameters['addon']);

View file

@ -20,8 +20,6 @@ class DBSync extends BaseAdmin
{ {
parent::content(); parent::content();
$a = DI::app();
$action = $this->parameters['action'] ?? ''; $action = $this->parameters['action'] ?? '';
$update = $this->parameters['update'] ?? 0; $update = $this->parameters['update'] ?? 0;

View file

@ -27,7 +27,6 @@ class Directory extends BaseModule
{ {
protected function content(array $request = []): string protected function content(array $request = []): string
{ {
$app = DI::app();
$config = DI::config(); $config = DI::config();
if (($config->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) || if (($config->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) ||

View file

@ -30,7 +30,6 @@ class Invite extends BaseModule
self::checkFormSecurityTokenRedirectOnError('/', 'send_invite'); self::checkFormSecurityTokenRedirectOnError('/', 'send_invite');
$app = DI::app();
$config = DI::config(); $config = DI::config();
$max_invites = intval($config->get('system', 'max_invites')); $max_invites = intval($config->get('system', 'max_invites'));
@ -117,7 +116,6 @@ class Invite extends BaseModule
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.')); throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
} }
$app = DI::app();
$config = DI::config(); $config = DI::config();
$inviteOnly = false; $inviteOnly = false;
@ -142,7 +140,7 @@ class Invite extends BaseModule
if (Register::getPolicy() === Register::CLOSED) { if (Register::getPolicy() === Register::CLOSED) {
return DI::l10n()->t('Our apologies. This system is not currently configured to connect with other public sites or invite members.'); return DI::l10n()->t('Our apologies. This system is not currently configured to connect with other public sites or invite members.');
} else { } else {
$linkTxt = DI::l10n()->t('To accept this invitation, please visit and register at %s.', DI::baseUrl() . '/register' $linkTxt = DI::l10n()->t('To accept this invitation, please visit and register at %s.', DI::baseUrl() . '/register'
. "\r\n" . "\r\n" . DI::l10n()->t('Friendica sites all inter-connect to create a huge privacy-enhanced social web that is owned and controlled by its members. They can also connect with many traditional social networks.')); . "\r\n" . "\r\n" . DI::l10n()->t('Friendica sites all inter-connect to create a huge privacy-enhanced social web that is owned and controlled by its members. They can also connect with many traditional social networks.'));
} }
} }

View file

@ -22,8 +22,6 @@ class NoScrape extends BaseModule
{ {
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
$a = DI::app();
if (isset($this->parameters['nick'])) { if (isset($this->parameters['nick'])) {
// Get infos about a specific nick (public) // Get infos about a specific nick (public)
$which = $this->parameters['nick']; $which = $this->parameters['nick'];

View file

@ -7,7 +7,9 @@
namespace Friendica\Module\Profile; namespace Friendica\Module\Profile;
use Friendica\App; use Friendica\App\Arguments;
use Friendica\App\BaseURL;
use Friendica\AppHelper;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Session\Capability\IHandleUserSessions; use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\DI; use Friendica\DI;
@ -21,23 +23,37 @@ use Psr\Log\LoggerInterface;
class Media extends BaseProfile class Media extends BaseProfile
{ {
/**
* @var AppHelper
*/
private $appHelper;
/** /**
* @var IHandleUserSessions * @var IHandleUserSessions
*/ */
private $userSession; private $userSession;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $userSession, $server, array $parameters = []) public function __construct(
{ L10n $l10n,
BaseURL $baseUrl,
Arguments $args,
AppHelper $appHelper,
LoggerInterface $logger,
Profiler $profiler,
Response $response,
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->appHelper = $appHelper;
$this->userSession = $userSession; $this->userSession = $userSession;
} }
protected function content(array $request = []): string protected function content(array $request = []): string
{ {
$a = DI::app(); $profile = ProfileModel::load($this->appHelper, $this->parameters['nickname']);
$profile = ProfileModel::load($a, $this->parameters['nickname']);
if (empty($profile)) { if (empty($profile)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.')); throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
} }

View file

@ -42,8 +42,6 @@ class Schedule extends BaseProfile
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.')); throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
} }
$a = DI::app();
$o = self::getTabsHTML('schedule', true, DI::userSession()->getLocalUserNickname(), false); $o = self::getTabsHTML('schedule', true, DI::userSession()->getLocalUserNickname(), false);
$schedule = []; $schedule = [];

View file

@ -726,7 +726,7 @@ class Post
$title = DI::l10n()->t('Commented by: %s', $actors); $title = DI::l10n()->t('Commented by: %s', $actors);
$icon = ['fa' => 'fa-commenting', 'icon' => 'icon-commenting']; $icon = ['fa' => 'fa-commenting', 'icon' => 'icon-commenting'];
break; break;
default: default:
$title = DI::l10n()->t('Reacted with %s by: %s', $element['emoji'], $actors); $title = DI::l10n()->t('Reacted with %s by: %s', $element['emoji'], $actors);
$icon = []; $icon = [];
@ -1180,7 +1180,6 @@ class Post
*/ */
protected function checkWallToWall() protected function checkWallToWall()
{ {
$a = DI::app();
$conv = $this->getThread(); $conv = $this->getThread();
$this->wall_to_wall = false; $this->wall_to_wall = false;

View file

@ -107,7 +107,6 @@ class BasicAuth
*/ */
private static function getUserIdByAuth(bool $do_login = true):int private static function getUserIdByAuth(bool $do_login = true):int
{ {
$a = DI::app();
self::$current_user_id = 0; self::$current_user_id = 0;
// workaround for HTTP-auth in CGI mode // workaround for HTTP-auth in CGI mode