diff --git a/mod/display.php b/mod/display.php index daa78b03e1..dce2a10ce7 100644 --- a/mod/display.php +++ b/mod/display.php @@ -40,7 +40,7 @@ use Friendica\Protocol\DFRN; function display_init(App $a) { if (ActivityPub::isRequest()) { - (new Objects(DI::l10n(), ['guid' => DI::args()->getArgv()[1] ?? null]))->rawContent(); + (new Objects(['guid' => DI::args()->getArgv()[1] ?? null]))->rawContent(); } if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) { diff --git a/src/App/ModuleController.php b/src/App/ModuleController.php index ae27236398..6e3a106b5b 100644 --- a/src/App/ModuleController.php +++ b/src/App/ModuleController.php @@ -81,7 +81,7 @@ class ModuleController private $moduleName; /** - * @var ?ICanHandleRequests The module object + * @var ICanHandleRequests The module object */ private $module; @@ -104,9 +104,9 @@ class ModuleController } /** - * @return ?ICanHandleRequests The base module object + * @return ICanHandleRequests The base module object */ - public function getModule(): ?ICanHandleRequests + public function getModule(): ICanHandleRequests { return $this->module; } @@ -120,10 +120,12 @@ class ModuleController return $this->isBackend; } - public function __construct(string $moduleName = self::DEFAULT, ?ICanHandleRequests $module = null, bool $isBackend = false, bool $printNotAllowedAddon = false) + public function __construct(string $moduleName = self::DEFAULT, ICanHandleRequests $module = null, bool $isBackend = false, bool $printNotAllowedAddon = false) { + $defaultClass = static::DEFAULT_CLASS; + $this->moduleName = $moduleName; - $this->module = $module; + $this->module = $module ?? new $defaultClass(); $this->isBackend = $isBackend; $this->printNotAllowedAddon = $printNotAllowedAddon; } @@ -295,6 +297,8 @@ class ModuleController Core\Hook::callAll($this->moduleName . '_mod_init', $placeholder); + $this->module->init(); + $profiler->set(microtime(true) - $timestamp, 'init'); if ($server['REQUEST_METHOD'] === Router::DELETE) { diff --git a/src/BaseModule.php b/src/BaseModule.php index be4788045c..aaca6c5311 100644 --- a/src/BaseModule.php +++ b/src/BaseModule.php @@ -22,7 +22,6 @@ namespace Friendica; use Friendica\Capabilities\ICanHandleRequests; -use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Model\User; @@ -40,33 +39,16 @@ abstract class BaseModule implements ICanHandleRequests /** @var array */ protected $parameters = []; - /** @var L10n */ - protected $l10n; - - public function __construct(L10n $l10n, array $parameters = []) + public function __construct(array $parameters = []) { $this->parameters = $parameters; - $this->l10n = $l10n; } /** - * Wraps the L10n::t() function for Modules - * - * @see L10n::t() + * {@inheritDoc} */ - protected function t(string $s, ...$args): string + public function init() { - return $this->l10n->t($s, $args); - } - - /** - * Wraps the L10n::tt() function for Modules - * - * @see L10n::tt() - */ - protected function tt(string $singular, string $plurarl, int $count): string - { - return $this->l10n->tt($singular, $plurarl, $count); } /** diff --git a/src/Capabilities/ICanHandleRequests.php b/src/Capabilities/ICanHandleRequests.php index 23feec2b73..1d02be4397 100644 --- a/src/Capabilities/ICanHandleRequests.php +++ b/src/Capabilities/ICanHandleRequests.php @@ -7,6 +7,14 @@ namespace Friendica\Capabilities; */ interface ICanHandleRequests { + /** + * Initialization method common to both content() and post() + * + * Extend this method if you need to do any shared processing before either + * content() or post() + */ + public function init(); + /** * Module GET method to display raw content from technical endpoints * diff --git a/src/LegacyModule.php b/src/LegacyModule.php index 77b35ba92c..53f7676604 100644 --- a/src/LegacyModule.php +++ b/src/LegacyModule.php @@ -21,8 +21,6 @@ namespace Friendica; -use Friendica\Core\L10n; - /** * This mock module enable class encapsulation of legacy global function modules. * After having provided the module file name, all the methods will behave like a normal Module class. @@ -39,13 +37,11 @@ class LegacyModule extends BaseModule */ private $moduleName = ''; - public function __construct(L10n $l10n, string $file_path = '', array $parameters = []) + public function __construct(string $file_path = '', array $parameters = []) { - parent::__construct($l10n, $parameters); + parent::__construct($parameters); $this->setModuleFile($file_path); - - $this->runModuleFunction('init'); } /** @@ -65,6 +61,11 @@ class LegacyModule extends BaseModule require_once $file_path; } + public function init() + { + $this->runModuleFunction('init'); + } + public function content(): string { return $this->runModuleFunction('content'); diff --git a/src/Module/Admin/Themes/Embed.php b/src/Module/Admin/Themes/Embed.php index 0d2a2dc047..bf4e5b5560 100644 --- a/src/Module/Admin/Themes/Embed.php +++ b/src/Module/Admin/Themes/Embed.php @@ -21,32 +21,18 @@ namespace Friendica\Module\Admin\Themes; -use Friendica\App; -use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Module\BaseAdmin; use Friendica\Util\Strings; class Embed extends BaseAdmin { - /** @var App */ - protected $app; - /** @var App\BaseURL */ - protected $baseUrl; - /** @var App\Mode */ - protected $mode; - - public function __construct(App $app, App\BaseURL $baseUrl, App\Mode $mode, L10n $l10n, array $parameters = []) + public function init() { - parent::__construct($l10n, $parameters); - - $this->app = $app; - $this->baseUrl = $baseUrl; - $this->mode = $mode; - $theme = Strings::sanitizeFilePathItem($this->parameters['theme']); if (is_file("view/theme/$theme/config.php")) { - $this->app->setCurrentTheme($theme); + DI::app()->setCurrentTheme($theme); } } @@ -59,15 +45,15 @@ class Embed extends BaseAdmin require_once "view/theme/$theme/config.php"; if (function_exists('theme_admin_post')) { self::checkFormSecurityTokenRedirectOnError('/admin/themes/' . $theme . '/embed?mode=minimal', 'admin_theme_settings'); - theme_admin_post($this->app); + theme_admin_post(DI::app()); } } - if ($this->mode->isAjax()) { + if (DI::mode()->isAjax()) { return; } - $this->baseUrl->redirect('admin/themes/' . $theme . '/embed?mode=minimal'); + DI::baseUrl()->redirect('admin/themes/' . $theme . '/embed?mode=minimal'); } public function content(): string @@ -76,7 +62,7 @@ class Embed extends BaseAdmin $theme = Strings::sanitizeFilePathItem($this->parameters['theme']); if (!is_dir("view/theme/$theme")) { - notice($this->t('Unknown theme.')); + notice(DI::l10n()->t('Unknown theme.')); return ''; } @@ -85,7 +71,7 @@ class Embed extends BaseAdmin require_once "view/theme/$theme/config.php"; if (function_exists('theme_admin')) { - $admin_form = theme_admin($this->app); + $admin_form = theme_admin(DI::app()); } } diff --git a/src/Module/Admin/Tos.php b/src/Module/Admin/Tos.php index 0e019cc329..17c8372b00 100644 --- a/src/Module/Admin/Tos.php +++ b/src/Module/Admin/Tos.php @@ -21,30 +21,12 @@ namespace Friendica\Module\Admin; -use Friendica\App\BaseURL; -use Friendica\Core\Config\Capability\IManageConfigValues; -use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Module\BaseAdmin; class Tos extends BaseAdmin { - /** @var \Friendica\Module\Tos */ - protected $tos; - /** @var IManageConfigValues */ - protected $config; - /** @var BaseURL */ - protected $baseUrl; - - public function __construct(\Friendica\Module\Tos $tos, IManageConfigValues $config, BaseURL $baseUrl, L10n $l10n, array $parameters = []) - { - parent::__construct($l10n, $parameters); - - $this->tos = $tos; - $this->config = $config; - $this->baseUrl = $baseUrl; - } - public function post() { self::checkAdminAccess(); @@ -59,28 +41,29 @@ class Tos extends BaseAdmin $displayprivstatement = !empty($_POST['displayprivstatement']); $tostext = (!empty($_POST['tostext']) ? strip_tags(trim($_POST['tostext'])) : ''); - $this->config->set('system', 'tosdisplay', $displaytos); - $this->config->set('system', 'tosprivstatement', $displayprivstatement); - $this->config->set('system', 'tostext', $tostext); + DI::config()->set('system', 'tosdisplay', $displaytos); + DI::config()->set('system', 'tosprivstatement', $displayprivstatement); + DI::config()->set('system', 'tostext', $tostext); - $this->baseUrl->redirect('admin/tos'); + DI::baseUrl()->redirect('admin/tos'); } public function content(): string { parent::content(); + $tos = new \Friendica\Module\Tos($this->parameters); $t = Renderer::getMarkupTemplate('admin/tos.tpl'); return Renderer::replaceMacros($t, [ - '$title' => $this->t('Administration'), - '$page' => $this->t('Terms of Service'), - '$displaytos' => ['displaytos', $this->t('Display Terms of Service'), $this->config->get('system', 'tosdisplay'), $this->t('Enable the Terms of Service page. If this is enabled a link to the terms will be added to the registration form and the general information page.')], - '$displayprivstatement' => ['displayprivstatement', $this->t('Display Privacy Statement'), $this->config->get('system', 'tosprivstatement'), $this->t('Show some informations regarding the needed information to operate the node according e.g. to EU-GDPR.', 'https://en.wikipedia.org/wiki/General_Data_Protection_Regulation')], - '$preview' => $this->t('Privacy Statement Preview'), - '$privtext' => $this->tos->privacy_complete, - '$tostext' => ['tostext', $this->t('The Terms of Service'), $this->config->get('system', 'tostext'), $this->t('Enter the Terms of Service for your node here. You can use BBCode. Headers of sections should be [h2] and below.')], + '$title' => DI::l10n()->t('Administration'), + '$page' => DI::l10n()->t('Terms of Service'), + '$displaytos' => ['displaytos', DI::l10n()->t('Display Terms of Service'), DI::config()->get('system', 'tosdisplay'), DI::l10n()->t('Enable the Terms of Service page. If this is enabled a link to the terms will be added to the registration form and the general information page.')], + '$displayprivstatement' => ['displayprivstatement', DI::l10n()->t('Display Privacy Statement'), DI::config()->get('system', 'tosprivstatement'), DI::l10n()->t('Show some informations regarding the needed information to operate the node according e.g. to EU-GDPR.', 'https://en.wikipedia.org/wiki/General_Data_Protection_Regulation')], + '$preview' => DI::l10n()->t('Privacy Statement Preview'), + '$privtext' => $tos->privacy_complete, + '$tostext' => ['tostext', DI::l10n()->t('The Terms of Service'), DI::config()->get('system', 'tostext'), DI::l10n()->t('Enter the Terms of Service for your node here. You can use BBCode. Headers of sections should be [h2] and below.')], '$form_security_token' => self::getFormSecurityToken('admin_tos'), - '$submit' => $this->t('Save Settings'), + '$submit' => DI::l10n()->t('Save Settings'), ]); } } diff --git a/src/Module/Api/Twitter/ContactEndpoint.php b/src/Module/Api/Twitter/ContactEndpoint.php index 183ea1c4e4..39e6d2d457 100644 --- a/src/Module/Api/Twitter/ContactEndpoint.php +++ b/src/Module/Api/Twitter/ContactEndpoint.php @@ -21,7 +21,6 @@ namespace Friendica\Module\Api\Twitter; -use Friendica\Core\L10n; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Profile; @@ -36,9 +35,9 @@ abstract class ContactEndpoint extends BaseApi const DEFAULT_COUNT = 20; const MAX_COUNT = 200; - public function __construct(L10n $l10n, array $parameters = []) + public function init() { - parent::__construct($l10n, $parameters); + parent::init(); self::checkAllowedScope(self::SCOPE_READ); } diff --git a/src/Module/Apps.php b/src/Module/Apps.php index f414f7f8cb..1d6144f16d 100644 --- a/src/Module/Apps.php +++ b/src/Module/Apps.php @@ -21,25 +21,21 @@ namespace Friendica\Module; -use Friendica\App\BaseURL; use Friendica\BaseModule; use Friendica\Content\Nav; -use Friendica\Core\Config\Capability\IManageConfigValues; -use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; /** * Shows the App menu */ class Apps extends BaseModule { - public function __construct(L10n $l10n, IManageConfigValues $config, BaseURL $baseUrl, array $parameters = []) + public function init() { - parent::__construct($l10n, $parameters); - - $privateaddons = $config->get('config', 'private_addons'); + $privateaddons = DI::config()->get('config', 'private_addons'); if ($privateaddons === "1" && !local_user()) { - $baseUrl->redirect(); + DI::baseUrl()->redirect(); } } @@ -48,12 +44,12 @@ class Apps extends BaseModule $apps = Nav::getAppMenu(); if (count($apps) == 0) { - notice($this->t('No installed applications.')); + notice(DI::l10n()->t('No installed applications.')); } $tpl = Renderer::getMarkupTemplate('apps.tpl'); return Renderer::replaceMacros($tpl, [ - '$title' => $this->t('Applications'), + '$title' => DI::l10n()->t('Applications'), '$apps' => $apps, ]); } diff --git a/src/Module/BaseNotifications.php b/src/Module/BaseNotifications.php index 0e39eb651d..685337699b 100644 --- a/src/Module/BaseNotifications.php +++ b/src/Module/BaseNotifications.php @@ -22,12 +22,11 @@ namespace Friendica\Module; use Exception; -use Friendica\App\Arguments; use Friendica\BaseModule; use Friendica\Content\Pager; -use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\System; +use Friendica\DI; use Friendica\Navigation\Notifications\ValueObject\FormattedNotification; use Friendica\Network\HTTPException\ForbiddenException; @@ -71,12 +70,9 @@ abstract class BaseNotifications extends BaseModule const DEFAULT_PAGE_LIMIT = 80; /** @var boolean True, if ALL entries should get shown */ - protected $showAll; + protected static $showAll; /** @var int The determined start item of the current page */ - protected $firstItemNum; - - /** @var Arguments */ - protected $args; + protected static $firstItemNum; /** * Collects all notifications from the backend @@ -84,37 +80,33 @@ abstract class BaseNotifications extends BaseModule * @return array The determined notification array * ['header', 'notifications'] */ - abstract public function getNotifications(); + abstract public static function getNotifications(); - public function __construct(Arguments $args, L10n $l10n, array $parameters = []) + public function init() { - parent::__construct($l10n, $parameters); - if (!local_user()) { - throw new ForbiddenException($this->t('Permission denied.')); + throw new ForbiddenException(DI::l10n()->t('Permission denied.')); } $page = ($_REQUEST['page'] ?? 0) ?: 1; - $this->firstItemNum = ($page * self::ITEMS_PER_PAGE) - self::ITEMS_PER_PAGE; - $this->showAll = ($_REQUEST['show'] ?? '') === 'all'; - - $this->args = $args; + self::$firstItemNum = ($page * self::ITEMS_PER_PAGE) - self::ITEMS_PER_PAGE; + self::$showAll = ($_REQUEST['show'] ?? '') === 'all'; } public function rawContent() { // If the last argument of the query is NOT json, return - if ($this->args->get($this->args->getArgc() - 1) !== 'json') { + if (DI::args()->get(DI::args()->getArgc() - 1) !== 'json') { return; } // Set the pager - $pager = new Pager($this->l10n, $this->args->getQueryString(), self::ITEMS_PER_PAGE); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), self::ITEMS_PER_PAGE); // Add additional informations (needed for json output) $notifications = [ - 'notifications' => $this->getNotifications(), + 'notifications' => static::getNotifications(), 'items_page' => $pager->getItemsPerPage(), 'page' => $pager->getPage(), ]; @@ -134,17 +126,17 @@ abstract class BaseNotifications extends BaseModule * * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - protected function printContent(string $header, array $notifications, string $noContent, array $showLink) + protected static function printContent(string $header, array $notifications, string $noContent, array $showLink) { // Get the nav tabs for the notification pages - $tabs = $this->getTabs(); + $tabs = self::getTabs(); // Set the pager - $pager = new Pager($this->l10n, $this->args->getQueryString(), self::ITEMS_PER_PAGE); + $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), self::ITEMS_PER_PAGE); $notif_tpl = Renderer::getMarkupTemplate('notifications/notifications.tpl'); return Renderer::replaceMacros($notif_tpl, [ - '$header' => $header ?? $this->t('Notifications'), + '$header' => $header ?? DI::l10n()->t('Notifications'), '$tabs' => $tabs, '$notifications' => $notifications, '$noContent' => $noContent, @@ -159,15 +151,15 @@ abstract class BaseNotifications extends BaseModule * @return array with with notifications TabBar data * @throws Exception */ - private function getTabs() + private static function getTabs() { - $selected = $this->args->get(1, ''); + $selected = DI::args()->get(1, ''); $tabs = []; foreach (self::URL_TYPES as $type => $url) { $tabs[] = [ - 'label' => $this->t(self::PRINT_TYPES[$type]), + 'label' => DI::l10n()->t(self::PRINT_TYPES[$type]), 'url' => 'notifications/' . $url, 'sel' => (($selected == $url) ? 'active' : ''), 'id' => $type . '-tab', diff --git a/src/Module/Contact/Advanced.php b/src/Module/Contact/Advanced.php index 8d0a4e0f3f..fb3aa62f4f 100644 --- a/src/Module/Contact/Advanced.php +++ b/src/Module/Contact/Advanced.php @@ -21,43 +21,27 @@ namespace Friendica\Module\Contact; -use Friendica\App\Page; use Friendica\BaseModule; use Friendica\Content\Widget; -use Friendica\Core\L10n; use Friendica\Core\Protocol; use Friendica\Core\Renderer; use Friendica\Core\Session; -use Friendica\Database\Database; +use Friendica\DI; use Friendica\Model; use Friendica\Module\Contact; use Friendica\Network\HTTPException\BadRequestException; use Friendica\Network\HTTPException\ForbiddenException; use Friendica\Util\Strings; -use Psr\Log\LoggerInterface; /** * GUI for advanced contact details manipulation */ class Advanced extends BaseModule { - /** @var Database */ - protected $dba; - /** @var LoggerInterface */ - protected $logger; - /** @var Page */ - protected $page; - - public function __construct(Database $dba, LoggerInterface $logger, Page $page, L10n $l10n, array $parameters = []) + public function init() { - parent::__construct($l10n, $parameters); - - $this->dba = $dba; - $this->logger = $logger; - $this->page = $page; - if (!Session::isAuthenticated()) { - throw new ForbiddenException($this->t('Permission denied.')); + throw new ForbiddenException(DI::l10n()->t('Permission denied.')); } } @@ -67,7 +51,7 @@ class Advanced extends BaseModule $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]); if (empty($contact)) { - throw new BadRequestException($this->t('Contact not found.')); + throw new BadRequestException(DI::l10n()->t('Contact not found.')); } $name = ($_POST['name'] ?? '') ?: $contact['name']; @@ -82,7 +66,7 @@ class Advanced extends BaseModule $photo = $_POST['photo'] ?? ''; $nurl = Strings::normaliseLink($url); - $r = $this->dba->update( + $r = DI::dba()->update( 'contact', [ 'name' => $name, @@ -100,14 +84,16 @@ class Advanced extends BaseModule ); if ($photo) { - $this->logger->notice('Updating photo.', ['photo' => $photo]); + DI::logger()->notice('Updating photo.', ['photo' => $photo]); Model\Contact::updateAvatar($contact['id'], $photo, true); } if (!$r) { - notice($this->t('Contact update failed.')); + notice(DI::l10n()->t('Contact update failed.')); } + + return; } public function content(): string @@ -116,13 +102,13 @@ class Advanced extends BaseModule $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]); if (empty($contact)) { - throw new BadRequestException($this->t('Contact not found.')); + throw new BadRequestException(DI::l10n()->t('Contact not found.')); } - $this->page['aside'] = Widget\VCard::getHTML($contact); + DI::page()['aside'] = Widget\VCard::getHTML($contact); - $warning = $this->t('WARNING: This is highly advanced and if you enter incorrect information your communications with this contact may stop working.'); - $info = $this->t('Please use your browser \'Back\' button now if you are uncertain what to do on this page.'); + $warning = DI::l10n()->t('WARNING: This is highly advanced and if you enter incorrect information your communications with this contact may stop working.'); + $info = DI::l10n()->t('Please use your browser \'Back\' button now if you are uncertain what to do on this page.'); $returnaddr = "contact/$cid"; @@ -142,20 +128,20 @@ class Advanced extends BaseModule '$warning' => $warning, '$info' => $info, '$returnaddr' => $returnaddr, - '$return' => $this->t('Return to contact editor'), + '$return' => DI::l10n()->t('Return to contact editor'), '$contact_id' => $contact['id'], - '$lbl_submit' => $this->t('Submit'), + '$lbl_submit' => DI::l10n()->t('Submit'), - '$name' => ['name', $this->t('Name'), $contact['name'], '', '', $readonly], - '$nick' => ['nick', $this->t('Account Nickname'), $contact['nick'], '', '', $readonly], - '$attag' => ['attag', $this->t('@Tagname - overrides Name/Nickname'), $contact['attag']], - '$url' => ['url', $this->t('Account URL'), $contact['url'], '', '', $readonly], - '$alias' => ['alias', $this->t('Account URL Alias'), $contact['alias'], '', '', $readonly], - '$request' => ['request', $this->t('Friend Request URL'), $contact['request'], '', '', $readonly], - 'confirm' => ['confirm', $this->t('Friend Confirm URL'), $contact['confirm'], '', '', $readonly], - 'notify' => ['notify', $this->t('Notification Endpoint URL'), $contact['notify'], '', '', $readonly], - 'poll' => ['poll', $this->t('Poll/Feed URL'), $contact['poll'], '', '', $readonly], - 'photo' => ['photo', $this->t('New photo from this URL'), '', '', '', $readonly], + '$name' => ['name', DI::l10n()->t('Name'), $contact['name'], '', '', $readonly], + '$nick' => ['nick', DI::l10n()->t('Account Nickname'), $contact['nick'], '', '', $readonly], + '$attag' => ['attag', DI::l10n()->t('@Tagname - overrides Name/Nickname'), $contact['attag']], + '$url' => ['url', DI::l10n()->t('Account URL'), $contact['url'], '', '', $readonly], + '$alias' => ['alias', DI::l10n()->t('Account URL Alias'), $contact['alias'], '', '', $readonly], + '$request' => ['request', DI::l10n()->t('Friend Request URL'), $contact['request'], '', '', $readonly], + 'confirm' => ['confirm', DI::l10n()->t('Friend Confirm URL'), $contact['confirm'], '', '', $readonly], + 'notify' => ['notify', DI::l10n()->t('Notification Endpoint URL'), $contact['notify'], '', '', $readonly], + 'poll' => ['poll', DI::l10n()->t('Poll/Feed URL'), $contact['poll'], '', '', $readonly], + 'photo' => ['photo', DI::l10n()->t('New photo from this URL'), '', '', '', $readonly], ]); } } diff --git a/src/Module/Contact/Revoke.php b/src/Module/Contact/Revoke.php index 88177cc3b4..07fe7779b5 100644 --- a/src/Module/Contact/Revoke.php +++ b/src/Module/Contact/Revoke.php @@ -21,14 +21,12 @@ namespace Friendica\Module\Contact; -use Friendica\App\Arguments; -use Friendica\App\BaseURL; use Friendica\BaseModule; use Friendica\Content\Nav; -use Friendica\Core\L10n; use Friendica\Core\Protocol; use Friendica\Core\Renderer; -use Friendica\Database\Database; +use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model; use Friendica\Module\Contact; use Friendica\Module\Security\Login; @@ -37,44 +35,31 @@ use Friendica\Network\HTTPException; class Revoke extends BaseModule { /** @var array */ - protected $contact; - - /** @var Database */ - protected $dba; - /** @var BaseURL */ - protected $baseUrl; - /** @var Arguments */ - protected $args; - - public function __construct(Database $dba, BaseURL $baseUrl, Arguments $args, L10n $l10n, array $parameters = []) + private static $contact; + + public function init() { - parent::__construct($l10n, $parameters); - - $this->dba = $dba; - $this->baseUrl = $baseUrl; - $this->args = $args; - if (!local_user()) { return; } $data = Model\Contact::getPublicAndUserContactID($this->parameters['id'], local_user()); - if (!$this->dba->isResult($data)) { - throw new HTTPException\NotFoundException($this->t('Unknown contact.')); + if (!DBA::isResult($data)) { + throw new HTTPException\NotFoundException(DI::l10n()->t('Unknown contact.')); } if (empty($data['user'])) { throw new HTTPException\ForbiddenException(); } - $this->contact = Model\Contact::getById($data['user']); + self::$contact = Model\Contact::getById($data['user']); - if ($this->contact['deleted']) { - throw new HTTPException\NotFoundException($this->t('Contact is deleted.')); + if (self::$contact['deleted']) { + throw new HTTPException\NotFoundException(DI::l10n()->t('Contact is deleted.')); } - if (!empty($this->contact['network']) && $this->contact['network'] == Protocol::PHANTOM) { - throw new HTTPException\NotFoundException($this->t('Contact is being deleted.')); + if (!empty(self::$contact['network']) && self::$contact['network'] == Protocol::PHANTOM) { + throw new HTTPException\NotFoundException(DI::l10n()->t('Contact is being deleted.')); } } @@ -86,16 +71,16 @@ class Revoke extends BaseModule self::checkFormSecurityTokenRedirectOnError('contact/' . $this->parameters['id'], 'contact_revoke'); - $result = Model\Contact::revokeFollow($this->contact); + $result = Model\Contact::revokeFollow(self::$contact); if ($result === true) { - notice($this->t('Follow was successfully revoked.')); + notice(DI::l10n()->t('Follow was successfully revoked.')); } elseif ($result === null) { - notice($this->t('Follow was successfully revoked, however the remote contact won\'t be aware of this revokation.')); + notice(DI::l10n()->t('Follow was successfully revoked, however the remote contact won\'t be aware of this revokation.')); } else { - notice($this->t('Unable to revoke follow, please try again later or contact the administrator.')); + notice(DI::l10n()->t('Unable to revoke follow, please try again later or contact the administrator.')); } - $this->baseUrl->redirect('contact/' . $this->parameters['id']); + DI::baseUrl()->redirect('contact/' . $this->parameters['id']); } public function content(): string @@ -108,14 +93,14 @@ class Revoke extends BaseModule return Renderer::replaceMacros(Renderer::getMarkupTemplate('contact_drop_confirm.tpl'), [ '$l10n' => [ - 'header' => $this->t('Revoke Follow'), - 'message' => $this->t('Do you really want to revoke this contact\'s follow? This cannot be undone and they will have to manually follow you back again.'), - 'confirm' => $this->t('Yes'), - 'cancel' => $this->t('Cancel'), + 'header' => DI::l10n()->t('Revoke Follow'), + 'message' => DI::l10n()->t('Do you really want to revoke this contact\'s follow? This cannot be undone and they will have to manually follow you back again.'), + 'confirm' => DI::l10n()->t('Yes'), + 'cancel' => DI::l10n()->t('Cancel'), ], - '$contact' => Contact::getContactTemplateVars($this->contact), + '$contact' => Contact::getContactTemplateVars(self::$contact), '$method' => 'post', - '$confirm_url' => $this->args->getCommand(), + '$confirm_url' => DI::args()->getCommand(), '$confirm_name' => 'form_security_token', '$confirm_value' => BaseModule::getFormSecurityToken('contact_revoke'), ]); diff --git a/src/Module/Debug/Feed.php b/src/Module/Debug/Feed.php index 9368dd0268..2d2a7dc549 100644 --- a/src/Module/Debug/Feed.php +++ b/src/Module/Debug/Feed.php @@ -21,12 +21,10 @@ namespace Friendica\Module\Debug; -use Friendica\App\BaseURL; use Friendica\BaseModule; -use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Model; -use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests; use Friendica\Protocol; /** @@ -34,18 +32,11 @@ use Friendica\Protocol; */ class Feed extends BaseModule { - /** @var ICanSendHttpRequests */ - protected $httpClient; - - public function __construct(BaseURL $baseUrl, ICanSendHttpRequests $httpClient, L10n $l10n, array $parameters = []) + public function init() { - parent::__construct($l10n, $parameters); - - $this->httpClient = $httpClient; - if (!local_user()) { - notice($this->t('You must be logged in to use this module')); - $baseUrl->redirect(); + notice(DI::l10n()->t('You must be logged in to use this module')); + DI::baseUrl()->redirect(); } } @@ -57,7 +48,7 @@ class Feed extends BaseModule $contact = Model\Contact::getByURLForUser($url, local_user(), null); - $xml = $this->httpClient->fetch($contact['poll']); + $xml = DI::httpClient()->fetch($contact['poll']); $import_result = Protocol\Feed::import($xml); @@ -69,7 +60,7 @@ class Feed extends BaseModule $tpl = Renderer::getMarkupTemplate('feedtest.tpl'); return Renderer::replaceMacros($tpl, [ - '$url' => ['url', $this->t('Source URL'), $_REQUEST['url'] ?? '', ''], + '$url' => ['url', DI::l10n()->t('Source URL'), $_REQUEST['url'] ?? '', ''], '$result' => $result ]); } diff --git a/src/Module/Diaspora/Receive.php b/src/Module/Diaspora/Receive.php index ed4f8a5d25..14ad5c3912 100644 --- a/src/Module/Diaspora/Receive.php +++ b/src/Module/Diaspora/Receive.php @@ -22,8 +22,7 @@ namespace Friendica\Module\Diaspora; use Friendica\BaseModule; -use Friendica\Core\Config\Capability\IManageConfigValues; -use Friendica\Core\L10n; +use Friendica\DI; use Friendica\Model\User; use Friendica\Network\HTTPException; use Friendica\Protocol\Diaspora; @@ -37,30 +36,25 @@ use Psr\Log\LoggerInterface; class Receive extends BaseModule { /** @var LoggerInterface */ - protected $logger; - /** @var IManageConfigValues */ - protected $config; + private static $logger; - public function __construct(LoggerInterface $logger, IManageConfigValues $config, L10n $l10n, array $parameters = []) + public function init() { - parent::__construct($l10n, $parameters); - - $this->logger = $logger; - $this->config = $config; + self::$logger = DI::logger(); } public function post() { - $enabled = $this->config->get('system', 'diaspora_enabled', false); + $enabled = DI::config()->get('system', 'diaspora_enabled', false); if (!$enabled) { - $this->logger->info('Diaspora disabled.'); - throw new HTTPException\ForbiddenException($this->t('Access denied.')); + self::$logger->info('Diaspora disabled.'); + throw new HTTPException\ForbiddenException(DI::l10n()->t('Access denied.')); } if ($this->parameters['type'] === 'public') { - $this->receivePublic(); + self::receivePublic(); } else if ($this->parameters['type'] === 'users') { - $this->receiveUser(); + self::receiveUser($this->parameters['guid']); } } @@ -70,13 +64,13 @@ class Receive extends BaseModule * @throws HTTPException\InternalServerErrorException * @throws \ImagickException */ - private function receivePublic() + private static function receivePublic() { - $this->logger->info('Diaspora: Receiving post.'); + self::$logger->info('Diaspora: Receiving post.'); - $msg = $this->decodePost(); + $msg = self::decodePost(); - $this->logger->info('Diaspora: Dispatching.'); + self::$logger->info('Diaspora: Dispatching.'); Diaspora::dispatchPublic($msg); } @@ -84,18 +78,20 @@ class Receive extends BaseModule /** * Receive a Diaspora posting for a user * + * @param string $guid The GUID of the importer + * * @throws HTTPException\InternalServerErrorException * @throws \ImagickException */ - private function receiveUser() + private static function receiveUser(string $guid) { - $this->logger->info('Diaspora: Receiving post.'); + self::$logger->info('Diaspora: Receiving post.'); - $importer = User::getByGuid($this->parameters['guid']); + $importer = User::getByGuid($guid); - $msg = $this->decodePost(false, $importer['prvkey'] ?? ''); + $msg = self::decodePost(false, $importer['prvkey'] ?? ''); - $this->logger->info('Diaspora: Dispatching.'); + self::$logger->info('Diaspora: Dispatching.'); if (Diaspora::dispatch($importer, $msg)) { throw new HTTPException\OKException(); @@ -116,7 +112,7 @@ class Receive extends BaseModule * @throws HTTPException\InternalServerErrorException * @throws \ImagickException */ - private function decodePost(bool $public = true, string $privKey = '') + private static function decodePost(bool $public = true, string $privKey = '') { if (empty($_POST['xml'])) { @@ -126,24 +122,24 @@ class Receive extends BaseModule throw new HTTPException\InternalServerErrorException('Missing postdata.'); } - $this->logger->info('Diaspora: Message is in the new format.'); + self::$logger->info('Diaspora: Message is in the new format.'); $msg = Diaspora::decodeRaw($postdata, $privKey); } else { $xml = urldecode($_POST['xml']); - $this->logger->info('Diaspora: Decode message in the old format.'); + self::$logger->info('Diaspora: Decode message in the old format.'); $msg = Diaspora::decode($xml, $privKey); if ($public && !$msg) { - $this->logger->info('Diaspora: Decode message in the new format.'); + self::$logger->info('Diaspora: Decode message in the new format.'); $msg = Diaspora::decodeRaw($xml, $privKey); } } - $this->logger->info('Diaspora: Post decoded.'); - $this->logger->debug('Diaspora: Decoded message.', ['msg' => $msg]); + self::$logger->info('Diaspora: Post decoded.'); + self::$logger->debug('Diaspora: Decoded message.', ['msg' => $msg]); if (!is_array($msg)) { throw new HTTPException\InternalServerErrorException('Message is not an array.'); diff --git a/src/Module/Filer/SaveTag.php b/src/Module/Filer/SaveTag.php index fd572a7bea..b1742c8a6a 100644 --- a/src/Module/Filer/SaveTag.php +++ b/src/Module/Filer/SaveTag.php @@ -21,43 +21,36 @@ namespace Friendica\Module\Filer; -use Friendica\App\BaseURL; use Friendica\BaseModule; -use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model; use Friendica\Network\HTTPException; use Friendica\Util\XML; -use Psr\Log\LoggerInterface; /** * Shows a dialog for adding tags to a file */ class SaveTag extends BaseModule { - /** @var LoggerInterface */ - protected $logger; - - public function __construct(LoggerInterface $logger, BaseURL $baseUrl, L10n $l10n, array $parameters = []) + public function init() { - parent::__construct($l10n, $parameters); - - $this->logger = $logger; - if (!local_user()) { - notice($this->t('You must be logged in to use this module')); - $baseUrl->redirect(); + notice(DI::l10n()->t('You must be logged in to use this module')); + DI::baseUrl()->redirect(); } } public function rawContent() { + $logger = DI::logger(); + $term = XML::unescape(trim($_GET['term'] ?? '')); $item_id = $this->parameters['id'] ?? 0; - $this->logger->info('filer', ['tag' => $term, 'item' => $item_id]); + $logger->info('filer', ['tag' => $term, 'item' => $item_id]); if ($item_id && strlen($term)) { $item = Model\Post::selectFirst(['uri-id'], ['id' => $item_id]); @@ -72,8 +65,8 @@ class SaveTag extends BaseModule $tpl = Renderer::getMarkupTemplate("filer_dialog.tpl"); echo Renderer::replaceMacros($tpl, [ - '$field' => ['term', $this->t("Save to Folder:"), '', '', $filetags, $this->t('- select -')], - '$submit' => $this->t('Save'), + '$field' => ['term', DI::l10n()->t("Save to Folder:"), '', '', $filetags, DI::l10n()->t('- select -')], + '$submit' => DI::l10n()->t('Save'), ]); exit; diff --git a/src/Module/FriendSuggest.php b/src/Module/FriendSuggest.php index 940e6ff9ce..b0456377f1 100644 --- a/src/Module/FriendSuggest.php +++ b/src/Module/FriendSuggest.php @@ -21,16 +21,15 @@ namespace Friendica\Module; -use Friendica\App\BaseURL; use Friendica\BaseModule; -use Friendica\Core\L10n; use Friendica\Core\Protocol; use Friendica\Core\Renderer; use Friendica\Core\Worker; -use Friendica\Database\Database; +use Friendica\DI; use Friendica\Model\Contact as ContactModel; use Friendica\Network\HTTPException\ForbiddenException; use Friendica\Network\HTTPException\NotFoundException; +use Friendica\Util\DateTimeFormat; use Friendica\Util\Strings; use Friendica\Worker\Delivery; @@ -39,27 +38,11 @@ use Friendica\Worker\Delivery; */ class FriendSuggest extends BaseModule { - /** @var BaseURL */ - protected $baseUrl; - /** @var Database */ - protected $dba; - /** @var \Friendica\Contact\FriendSuggest\Repository\FriendSuggest */ - protected $friendSuggestRepo; - /** @var \Friendica\Contact\FriendSuggest\Factory\FriendSuggest */ - protected $friendSuggestFac; - - public function __construct(BaseURL $baseUrl, Database $dba, \Friendica\Contact\FriendSuggest\Repository\FriendSuggest $friendSuggestRepo, \Friendica\Contact\FriendSuggest\Factory\FriendSuggest $friendSuggestFac, L10n $l10n, array $parameters = []) + public function init() { - parent::__construct($l10n, $parameters); - if (!local_user()) { - throw new ForbiddenException($this->t('Permission denied.')); + throw new ForbiddenException(DI::l10n()->t('Permission denied.')); } - - $this->baseUrl = $baseUrl; - $this->dba = $dba; - $this->friendSuggestRepo = $friendSuggestRepo; - $this->friendSuggestFac = $friendSuggestFac; } public function post() @@ -67,8 +50,8 @@ class FriendSuggest extends BaseModule $cid = intval($this->parameters['contact']); // We do query the "uid" as well to ensure that it is our contact - if (!$this->dba->exists('contact', ['id' => $cid, 'uid' => local_user()])) { - throw new NotFoundException($this->t('Contact not found.')); + if (!DI::dba()->exists('contact', ['id' => $cid, 'uid' => local_user()])) { + throw new NotFoundException(DI::l10n()->t('Contact not found.')); } $suggest_contact_id = intval($_POST['suggest']); @@ -77,15 +60,15 @@ class FriendSuggest extends BaseModule } // We do query the "uid" as well to ensure that it is our contact - $contact = $this->dba->selectFirst('contact', ['name', 'url', 'request', 'avatar'], ['id' => $suggest_contact_id, 'uid' => local_user()]); + $contact = DI::dba()->selectFirst('contact', ['name', 'url', 'request', 'avatar'], ['id' => $suggest_contact_id, 'uid' => local_user()]); if (empty($contact)) { - notice($this->t('Suggested contact not found.')); + notice(DI::l10n()->t('Suggested contact not found.')); return; } $note = Strings::escapeHtml(trim($_POST['note'] ?? '')); - $suggest = $this->friendSuggestRepo->save($this->friendSuggestFac->createNew( + $suggest = DI::fsuggest()->save(DI::fsuggestFactory()->createNew( local_user(), $cid, $contact['name'], @@ -97,17 +80,17 @@ class FriendSuggest extends BaseModule Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::SUGGESTION, $suggest->id); - info($this->t('Friend suggestion sent.')); + info(DI::l10n()->t('Friend suggestion sent.')); } public function content(): string { $cid = intval($this->parameters['contact']); - $contact = $this->dba->selectFirst('contact', [], ['id' => $cid, 'uid' => local_user()]); + $contact = DI::dba()->selectFirst('contact', [], ['id' => $cid, 'uid' => local_user()]); if (empty($contact)) { - notice($this->t('Contact not found.')); - $this->baseUrl->redirect(); + notice(DI::l10n()->t('Contact not found.')); + DI::baseUrl()->redirect(); } $suggestableContacts = ContactModel::selectToArray(['id', 'name'], [ @@ -134,15 +117,15 @@ class FriendSuggest extends BaseModule $tpl = Renderer::getMarkupTemplate('fsuggest.tpl'); return Renderer::replaceMacros($tpl, [ '$contact_id' => $cid, - '$fsuggest_title' => $this->t('Suggest Friends'), + '$fsuggest_title' => DI::l10n()->t('Suggest Friends'), '$fsuggest_select' => [ 'suggest', - $this->t('Suggest a friend for %s', $contact['name']), + DI::l10n()->t('Suggest a friend for %s', $contact['name']), '', '', $formattedContacts, ], - '$submit' => $this->t('Submit'), + '$submit' => DI::l10n()->t('Submit'), ]); } } diff --git a/src/Module/Install.php b/src/Module/Install.php index c766dd5515..8f872c683e 100644 --- a/src/Module/Install.php +++ b/src/Module/Install.php @@ -25,7 +25,6 @@ use Friendica\App; use Friendica\BaseModule; use Friendica\Core; use Friendica\Core\Config\ValueObject\Cache; -use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\Theme; use Friendica\DI; @@ -59,119 +58,110 @@ class Install extends BaseModule /** * @var int The current step of the wizard */ - private $currentWizardStep; + private static $currentWizardStep; /** * @var Core\Installer The installer */ - private $installer; - - /** @var App */ - protected $app; - /** @var App\Mode */ - protected $mode; - /** @var App\BaseURL */ - protected $baseUrl; + private static $installer; - public function __construct(App $app, App\Mode $mode, App\BaseURL $baseUrl, App\Arguments $args, Core\Installer $installer, L10n $l10n, array $parameters = []) + public function init() { - parent::__construct($l10n, $parameters); + $a = DI::app(); - $this->app = $app; - $this->mode = $mode; - $this->baseUrl = $baseUrl; - $this->installer = $installer; - - if (!$this->mode->isInstall()) { + if (!DI::mode()->isInstall()) { throw new HTTPException\ForbiddenException(); } // route: install/testrwrite // $baseurl/install/testrwrite to test if rewrite in .htaccess is working - if ($args->get(1, '') == 'testrewrite') { + if (DI::args()->get(1, '') == 'testrewrite') { // Status Code 204 means that it worked without content throw new HTTPException\NoContentException(); } + self::$installer = new Core\Installer(); + // get basic installation information and save them to the config cache - $configCache = $this->app->getConfigCache(); - $basePath = new BasePath($this->app->getBasePath()); - $this->installer->setUpCache($configCache, $basePath->getPath()); + $configCache = $a->getConfigCache(); + $basePath = new BasePath($a->getBasePath()); + self::$installer->setUpCache($configCache, $basePath->getPath()); // We overwrite current theme css, because during install we may not have a working mod_rewrite // so we may not have a css at all. Here we set a static css file for the install procedure pages - Renderer::$theme['stylesheet'] = $this->baseUrl->get() . '/view/install/style.css'; + Renderer::$theme['stylesheet'] = DI::baseUrl()->get() . '/view/install/style.css'; - $this->currentWizardStep = ($_POST['pass'] ?? '') ?: self::SYSTEM_CHECK; + self::$currentWizardStep = ($_POST['pass'] ?? '') ?: self::SYSTEM_CHECK; } public function post() { - $configCache = $this->app->getConfigCache(); + $a = DI::app(); + $configCache = $a->getConfigCache(); - switch ($this->currentWizardStep) { + switch (self::$currentWizardStep) { case self::SYSTEM_CHECK: case self::BASE_CONFIG: - $this->checkSetting($configCache, $_POST, 'config', 'php_path'); + self::checkSetting($configCache, $_POST, 'config', 'php_path'); break; case self::DATABASE_CONFIG: - $this->checkSetting($configCache, $_POST, 'config', 'php_path'); + self::checkSetting($configCache, $_POST, 'config', 'php_path'); - $this->checkSetting($configCache, $_POST, 'config', 'hostname'); - $this->checkSetting($configCache, $_POST, 'system', 'ssl_policy'); - $this->checkSetting($configCache, $_POST, 'system', 'basepath'); - $this->checkSetting($configCache, $_POST, 'system', 'urlpath'); + self::checkSetting($configCache, $_POST, 'config', 'hostname'); + self::checkSetting($configCache, $_POST, 'system', 'ssl_policy'); + self::checkSetting($configCache, $_POST, 'system', 'basepath'); + self::checkSetting($configCache, $_POST, 'system', 'urlpath'); break; case self::SITE_SETTINGS: - $this->checkSetting($configCache, $_POST, 'config', 'php_path'); + self::checkSetting($configCache, $_POST, 'config', 'php_path'); - $this->checkSetting($configCache, $_POST, 'config', 'hostname'); - $this->checkSetting($configCache, $_POST, 'system', 'ssl_policy'); - $this->checkSetting($configCache, $_POST, 'system', 'basepath'); - $this->checkSetting($configCache, $_POST, 'system', 'urlpath'); + self::checkSetting($configCache, $_POST, 'config', 'hostname'); + self::checkSetting($configCache, $_POST, 'system', 'ssl_policy'); + self::checkSetting($configCache, $_POST, 'system', 'basepath'); + self::checkSetting($configCache, $_POST, 'system', 'urlpath'); - $this->checkSetting($configCache, $_POST, 'database', 'hostname', Core\Installer::DEFAULT_HOST); - $this->checkSetting($configCache, $_POST, 'database', 'username', ''); - $this->checkSetting($configCache, $_POST, 'database', 'password', ''); - $this->checkSetting($configCache, $_POST, 'database', 'database', ''); + self::checkSetting($configCache, $_POST, 'database', 'hostname', Core\Installer::DEFAULT_HOST); + self::checkSetting($configCache, $_POST, 'database', 'username', ''); + self::checkSetting($configCache, $_POST, 'database', 'password', ''); + self::checkSetting($configCache, $_POST, 'database', 'database', ''); // If we cannot connect to the database, return to the previous step - if (!$this->installer->checkDB(DI::dba())) { - $this->currentWizardStep = self::DATABASE_CONFIG; + if (!self::$installer->checkDB(DI::dba())) { + self::$currentWizardStep = self::DATABASE_CONFIG; } break; case self::FINISHED: - $this->checkSetting($configCache, $_POST, 'config', 'php_path'); + self::checkSetting($configCache, $_POST, 'config', 'php_path'); - $this->checkSetting($configCache, $_POST, 'config', 'hostname'); - $this->checkSetting($configCache, $_POST, 'system', 'ssl_policy'); - $this->checkSetting($configCache, $_POST, 'system', 'basepath'); - $this->checkSetting($configCache, $_POST, 'system', 'urlpath'); + self::checkSetting($configCache, $_POST, 'config', 'hostname'); + self::checkSetting($configCache, $_POST, 'system', 'ssl_policy'); + self::checkSetting($configCache, $_POST, 'system', 'basepath'); + self::checkSetting($configCache, $_POST, 'system', 'urlpath'); - $this->checkSetting($configCache, $_POST, 'database', 'hostname', Core\Installer::DEFAULT_HOST); - $this->checkSetting($configCache, $_POST, 'database', 'username', ''); - $this->checkSetting($configCache, $_POST, 'database', 'password', ''); - $this->checkSetting($configCache, $_POST, 'database', 'database', ''); + self::checkSetting($configCache, $_POST, 'database', 'hostname', Core\Installer::DEFAULT_HOST); + self::checkSetting($configCache, $_POST, 'database', 'username', ''); + self::checkSetting($configCache, $_POST, 'database', 'password', ''); + self::checkSetting($configCache, $_POST, 'database', 'database', ''); - $this->checkSetting($configCache, $_POST, 'system', 'default_timezone', Core\Installer::DEFAULT_TZ); - $this->checkSetting($configCache, $_POST, 'system', 'language', Core\Installer::DEFAULT_LANG); - $this->checkSetting($configCache, $_POST, 'config', 'admin_email', ''); + self::checkSetting($configCache, $_POST, 'system', 'default_timezone', Core\Installer::DEFAULT_TZ); + self::checkSetting($configCache, $_POST, 'system', 'language', Core\Installer::DEFAULT_LANG); + self::checkSetting($configCache, $_POST, 'config', 'admin_email', ''); // If we cannot connect to the database, return to the Database config wizard - if (!$this->installer->checkDB(DI::dba())) { - $this->currentWizardStep = self::DATABASE_CONFIG; + if (!self::$installer->checkDB(DI::dba())) { + self::$currentWizardStep = self::DATABASE_CONFIG; return; } - if (!$this->installer->createConfig($configCache)) { + if (!self::$installer->createConfig($configCache)) { return; } - $this->installer->installDatabase($configCache->get('system', 'basepath')); + self::$installer->installDatabase($configCache->get('system', 'basepath')); // install allowed themes to register theme hooks // this is same as "Reload active theme" in /admin/themes @@ -189,68 +179,69 @@ class Install extends BaseModule public function content(): string { - $configCache = $this->app->getConfigCache(); + $a = DI::app(); + $configCache = $a->getConfigCache(); $output = ''; - $install_title = $this->t('Friendica Communications Server - Setup'); + $install_title = DI::l10n()->t('Friendica Communications Server - Setup'); - switch ($this->currentWizardStep) { + switch (self::$currentWizardStep) { case self::SYSTEM_CHECK: $php_path = $configCache->get('config', 'php_path'); - $status = $this->installer->checkEnvironment($this->baseUrl->get(), $php_path); + $status = self::$installer->checkEnvironment(DI::baseUrl()->get(), $php_path); $tpl = Renderer::getMarkupTemplate('install_checks.tpl'); $output .= Renderer::replaceMacros($tpl, [ '$title' => $install_title, - '$pass' => $this->t('System check'), - '$required' => $this->t('Required'), - '$requirement_not_satisfied' => $this->t('Requirement not satisfied'), - '$optional_requirement_not_satisfied' => $this->t('Optional requirement not satisfied'), - '$ok' => $this->t('OK'), - '$checks' => $this->installer->getChecks(), + '$pass' => DI::l10n()->t('System check'), + '$required' => DI::l10n()->t('Required'), + '$requirement_not_satisfied' => DI::l10n()->t('Requirement not satisfied'), + '$optional_requirement_not_satisfied' => DI::l10n()->t('Optional requirement not satisfied'), + '$ok' => DI::l10n()->t('OK'), + '$checks' => self::$installer->getChecks(), '$passed' => $status, - '$see_install' => $this->t('Please see the file "doc/INSTALL.md".'), - '$next' => $this->t('Next'), - '$reload' => $this->t('Check again'), + '$see_install' => DI::l10n()->t('Please see the file "doc/INSTALL.md".'), + '$next' => DI::l10n()->t('Next'), + '$reload' => DI::l10n()->t('Check again'), '$php_path' => $php_path, ]); break; case self::BASE_CONFIG: $ssl_choices = [ - App\BaseURL::SSL_POLICY_NONE => $this->t("No SSL policy, links will track page SSL state"), - App\BaseURL::SSL_POLICY_FULL => $this->t("Force all links to use SSL"), - App\BaseURL::SSL_POLICY_SELFSIGN => $this->t("Self-signed certificate, use SSL for local links only \x28discouraged\x29") + App\BaseURL::SSL_POLICY_NONE => DI::l10n()->t("No SSL policy, links will track page SSL state"), + App\BaseURL::SSL_POLICY_FULL => DI::l10n()->t("Force all links to use SSL"), + App\BaseURL::SSL_POLICY_SELFSIGN => DI::l10n()->t("Self-signed certificate, use SSL for local links only \x28discouraged\x29") ]; $tpl = Renderer::getMarkupTemplate('install_base.tpl'); $output .= Renderer::replaceMacros($tpl, [ '$title' => $install_title, - '$pass' => $this->t('Base settings'), + '$pass' => DI::l10n()->t('Base settings'), '$ssl_policy' => ['system-ssl_policy', - $this->t("SSL link policy"), + DI::l10n()->t("SSL link policy"), $configCache->get('system', 'ssl_policy'), - $this->t("Determines whether generated links should be forced to use SSL"), + DI::l10n()->t("Determines whether generated links should be forced to use SSL"), $ssl_choices], '$hostname' => ['config-hostname', - $this->t('Host name'), + DI::l10n()->t('Host name'), $configCache->get('config', 'hostname'), - $this->t('Overwrite this field in case the determinated hostname isn\'t right, otherweise leave it as is.'), - $this->t('Required')], + DI::l10n()->t('Overwrite this field in case the determinated hostname isn\'t right, otherweise leave it as is.'), + DI::l10n()->t('Required')], '$basepath' => ['system-basepath', - $this->t("Base path to installation"), + DI::l10n()->t("Base path to installation"), $configCache->get('system', 'basepath'), - $this->t("If the system cannot detect the correct path to your installation, enter the correct path here. This setting should only be set if you are using a restricted system and symbolic links to your webroot."), - $this->t('Required')], + DI::l10n()->t("If the system cannot detect the correct path to your installation, enter the correct path here. This setting should only be set if you are using a restricted system and symbolic links to your webroot."), + DI::l10n()->t('Required')], '$urlpath' => ['system-urlpath', - $this->t('Sub path of the URL'), + DI::l10n()->t('Sub path of the URL'), $configCache->get('system', 'urlpath'), - $this->t('Overwrite this field in case the sub path determination isn\'t right, otherwise leave it as is. Leaving this field blank means the installation is at the base URL without sub path.'), + DI::l10n()->t('Overwrite this field in case the sub path determination isn\'t right, otherwise leave it as is. Leaving this field blank means the installation is at the base URL without sub path.'), ''], '$php_path' => $configCache->get('config', 'php_path'), - '$submit' => $this->t('Submit'), + '$submit' => DI::l10n()->t('Submit'), ]); break; @@ -258,54 +249,54 @@ class Install extends BaseModule $tpl = Renderer::getMarkupTemplate('install_db.tpl'); $output .= Renderer::replaceMacros($tpl, [ '$title' => $install_title, - '$pass' => $this->t('Database connection'), - '$info_01' => $this->t('In order to install Friendica we need to know how to connect to your database.'), - '$info_02' => $this->t('Please contact your hosting provider or site administrator if you have questions about these settings.'), - '$info_03' => $this->t('The database you specify below should already exist. If it does not, please create it before continuing.'), - '$required' => $this->t('Required'), - '$requirement_not_satisfied' => $this->t('Requirement not satisfied'), - '$checks' => $this->installer->getChecks(), + '$pass' => DI::l10n()->t('Database connection'), + '$info_01' => DI::l10n()->t('In order to install Friendica we need to know how to connect to your database.'), + '$info_02' => DI::l10n()->t('Please contact your hosting provider or site administrator if you have questions about these settings.'), + '$info_03' => DI::l10n()->t('The database you specify below should already exist. If it does not, please create it before continuing.'), + '$required' => DI::l10n()->t('Required'), + '$requirement_not_satisfied' => DI::l10n()->t('Requirement not satisfied'), + '$checks' => self::$installer->getChecks(), '$hostname' => $configCache->get('config', 'hostname'), '$ssl_policy' => $configCache->get('system', 'ssl_policy'), '$basepath' => $configCache->get('system', 'basepath'), '$urlpath' => $configCache->get('system', 'urlpath'), '$dbhost' => ['database-hostname', - $this->t('Database Server Name'), + DI::l10n()->t('Database Server Name'), $configCache->get('database', 'hostname'), '', - $this->t('Required')], + DI::l10n()->t('Required')], '$dbuser' => ['database-username', - $this->t('Database Login Name'), + DI::l10n()->t('Database Login Name'), $configCache->get('database', 'username'), '', - $this->t('Required'), + DI::l10n()->t('Required'), 'autofocus'], '$dbpass' => ['database-password', - $this->t('Database Login Password'), + DI::l10n()->t('Database Login Password'), $configCache->get('database', 'password'), - $this->t("For security reasons the password must not be empty"), - $this->t('Required')], + DI::l10n()->t("For security reasons the password must not be empty"), + DI::l10n()->t('Required')], '$dbdata' => ['database-database', - $this->t('Database Name'), + DI::l10n()->t('Database Name'), $configCache->get('database', 'database'), '', - $this->t('Required')], - '$lbl_10' => $this->t('Please select a default timezone for your website'), + DI::l10n()->t('Required')], + '$lbl_10' => DI::l10n()->t('Please select a default timezone for your website'), '$php_path' => $configCache->get('config', 'php_path'), - '$submit' => $this->t('Submit') + '$submit' => DI::l10n()->t('Submit') ]); break; case self::SITE_SETTINGS: /* Installed langs */ - $lang_choices = $this->l10n->getAvailableLanguages(); + $lang_choices = DI::l10n()->getAvailableLanguages(); $tpl = Renderer::getMarkupTemplate('install_settings.tpl'); $output .= Renderer::replaceMacros($tpl, [ '$title' => $install_title, - '$required' => $this->t('Required'), - '$checks' => $this->installer->getChecks(), - '$pass' => $this->t('Site settings'), + '$required' => DI::l10n()->t('Required'), + '$checks' => self::$installer->getChecks(), + '$pass' => DI::l10n()->t('Site settings'), '$hostname' => $configCache->get('config', 'hostname'), '$ssl_policy' => $configCache->get('system', 'ssl_policy'), '$basepath' => $configCache->get('system', 'basepath'), @@ -315,41 +306,41 @@ class Install extends BaseModule '$dbpass' => $configCache->get('database', 'password'), '$dbdata' => $configCache->get('database', 'database'), '$adminmail' => ['config-admin_email', - $this->t('Site administrator email address'), + DI::l10n()->t('Site administrator email address'), $configCache->get('config', 'admin_email'), - $this->t('Your account email address must match this in order to use the web admin panel.'), - $this->t('Required'), 'autofocus', 'email'], + DI::l10n()->t('Your account email address must match this in order to use the web admin panel.'), + DI::l10n()->t('Required'), 'autofocus', 'email'], '$timezone' => Temporal::getTimezoneField('system-default_timezone', - $this->t('Please select a default timezone for your website'), + DI::l10n()->t('Please select a default timezone for your website'), $configCache->get('system', 'default_timezone'), ''), '$language' => ['system-language', - $this->t('System Language:'), + DI::l10n()->t('System Language:'), $configCache->get('system', 'language'), - $this->t('Set the default language for your Friendica installation interface and to send emails.'), + DI::l10n()->t('Set the default language for your Friendica installation interface and to send emails.'), $lang_choices], '$php_path' => $configCache->get('config', 'php_path'), - '$submit' => $this->t('Submit') + '$submit' => DI::l10n()->t('Submit') ]); break; case self::FINISHED: $db_return_text = ""; - if (count($this->installer->getChecks()) == 0) { + if (count(self::$installer->getChecks()) == 0) { $txt = '
'; - $txt .= $this->t('Your Friendica site database has been installed.') . EOL; + $txt .= DI::l10n()->t('Your Friendica site database has been installed.') . EOL; $db_return_text .= $txt; } $tpl = Renderer::getMarkupTemplate('install_finished.tpl'); $output .= Renderer::replaceMacros($tpl, [ '$title' => $install_title, - '$required' => $this->t('Required'), - '$requirement_not_satisfied' => $this->t('Requirement not satisfied'), - '$checks' => $this->installer->getChecks(), - '$pass' => $this->t('Installation finished'), - '$text' => $db_return_text . $this->whatNext(), + '$required' => DI::l10n()->t('Required'), + '$requirement_not_satisfied' => DI::l10n()->t('Requirement not satisfied'), + '$checks' => self::$installer->getChecks(), + '$pass' => DI::l10n()->t('Installation finished'), + '$text' => $db_return_text . self::whatNext(), ]); break; @@ -364,15 +355,15 @@ class Install extends BaseModule * @return string The text for the next steps * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - private function whatNext() + private static function whatNext() { - $baseurl = $this->baseUrl->get(); + $baseurl = DI::baseUrl()->get(); return - $this->t('
" . $this->t('IMPORTANT: You will need to [manually] setup a scheduled task for the worker.') - . $this->t('Please see the file "doc/INSTALL.md".') + DI::l10n()->t('
" . DI::l10n()->t('IMPORTANT: You will need to [manually] setup a scheduled task for the worker.') + . DI::l10n()->t('Please see the file "doc/INSTALL.md".') . "
" - . $this->t('Go to your new Friendica node registration page and register as new user. Remember to use the same email you have entered as administrator email. This will allow you to enter the site admin panel.', $baseurl) + . DI::l10n()->t('Go to your new Friendica node registration page and register as new user. Remember to use the same email you have entered as administrator email. This will allow you to enter the site admin panel.', $baseurl) . "
"; } @@ -385,7 +376,7 @@ class Install extends BaseModule * @param string $key The key of the setting * @param null|string $default The default value */ - private function checkSetting(Cache $configCache, array $post, $cat, $key, $default = null) + private static function checkSetting(Cache $configCache, array $post, $cat, $key, $default = null) { $configCache->set($cat, $key, trim(($post[sprintf('%s-%s', $cat, $key)] ?? '') ?: diff --git a/src/Module/Magic.php b/src/Module/Magic.php index c47a7a4d50..af9e5084a1 100644 --- a/src/Module/Magic.php +++ b/src/Module/Magic.php @@ -21,18 +21,16 @@ namespace Friendica\Module; -use Friendica\App; use Friendica\BaseModule; -use Friendica\Core\L10n; +use Friendica\Core\Logger; use Friendica\Core\System; -use Friendica\Database\Database; +use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\User; -use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests; use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Util\HTTPSignature; use Friendica\Util\Strings; -use Psr\Log\LoggerInterface; /** * Magic Auth (remote authentication) module. @@ -41,35 +39,17 @@ use Psr\Log\LoggerInterface; */ class Magic extends BaseModule { - /** @var App */ - protected $app; - /** @var LoggerInterface */ - protected $logger; - /** @var Database */ - protected $dba; - /** @var ICanSendHttpRequests */ - protected $httpClient; - protected $baseUrl; - - public function __construct(App $app, App\BaseURL $baseUrl, LoggerInterface $logger, Database $dba, ICanSendHttpRequests $httpClient, L10n $l10n, array $parameters = []) + public function init() { - parent::__construct($l10n, $parameters); + $a = DI::app(); + $ret = ['success' => false, 'url' => '', 'message' => '']; + Logger::info('magic mdule: invoked'); - $this->app = $app; - $this->logger = $logger; - $this->dba = $dba; - $this->httpClient = $httpClient; - $this->baseUrl = $baseUrl; - } - - public function rawContent() - { - $this->logger->info('magic module: invoked'); - - $this->logger->debug('args', ['request' => $_REQUEST]); + Logger::debug('args', ['request' => $_REQUEST]); $addr = $_REQUEST['addr'] ?? ''; $dest = $_REQUEST['dest'] ?? ''; + $test = (!empty($_REQUEST['test']) ? intval($_REQUEST['test']) : 0); $owa = (!empty($_REQUEST['owa']) ? intval($_REQUEST['owa']) : 0); $cid = 0; @@ -80,15 +60,21 @@ class Magic extends BaseModule } if (!$cid) { - $this->logger->info('No contact record found', $_REQUEST); + Logger::info('No contact record found', $_REQUEST); // @TODO Finding a more elegant possibility to redirect to either internal or external URL - $this->app->redirect($dest); + $a->redirect($dest); } - $contact = $this->dba->selectFirst('contact', ['id', 'nurl', 'url'], ['id' => $cid]); + $contact = DBA::selectFirst('contact', ['id', 'nurl', 'url'], ['id' => $cid]); // Redirect if the contact is already authenticated on this site. - if ($this->app->getContactId() && strpos($contact['nurl'], Strings::normaliseLink($this->baseUrl->get())) !== false) { - $this->logger->info('Contact is already authenticated'); + if ($a->getContactId() && strpos($contact['nurl'], Strings::normaliseLink(DI::baseUrl()->get())) !== false) { + if ($test) { + $ret['success'] = true; + $ret['message'] .= 'Local site - you are already authenticated.' . EOL; + return $ret; + } + + Logger::info('Contact is already authenticated'); System::externalRedirect($dest); } @@ -112,11 +98,11 @@ class Magic extends BaseModule $header = HTTPSignature::createSig( $header, $user['prvkey'], - 'acct:' . $user['nickname'] . '@' . $this->baseUrl->getHostname() . ($this->baseUrl->getUrlPath() ? '/' . $this->baseUrl->getUrlPath() : '') + 'acct:' . $user['nickname'] . '@' . DI::baseUrl()->getHostname() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : '') ); // Try to get an authentication token from the other instance. - $curlResult = $this->httpClient->get($basepath . '/owa', [HttpClientOptions::HEADERS => $header]); + $curlResult = DI::httpClient()->get($basepath . '/owa', [HttpClientOptions::HEADERS => $header]); if ($curlResult->isSuccess()) { $j = json_decode($curlResult->getBody(), true); @@ -132,14 +118,19 @@ class Magic extends BaseModule } $args = (strpbrk($dest, '?&') ? '&' : '?') . 'owt=' . $token; - $this->logger->info('Redirecting', ['path' => $dest . $args]); + Logger::info('Redirecting', ['path' => $dest . $args]); System::externalRedirect($dest . $args); } } System::externalRedirect($dest); } + if ($test) { + $ret['message'] = 'Not authenticated or invalid arguments' . EOL; + return $ret; + } + // @TODO Finding a more elegant possibility to redirect to either internal or external URL - $this->app->redirect($dest); + $a->redirect($dest); } } diff --git a/src/Module/Notifications/Introductions.php b/src/Module/Notifications/Introductions.php index b9bbd0be93..7379510d81 100644 --- a/src/Module/Notifications/Introductions.php +++ b/src/Module/Notifications/Introductions.php @@ -21,17 +21,14 @@ namespace Friendica\Module\Notifications; -use Friendica\App\Arguments; -use Friendica\App\Mode; use Friendica\Content\ContactSelector; use Friendica\Content\Nav; use Friendica\Content\Text\BBCode; -use Friendica\Core\L10n; use Friendica\Core\Protocol; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Model\User; use Friendica\Module\BaseNotifications; -use Friendica\Navigation\Notifications\Factory\Introduction as IntroductionFactory; use Friendica\Navigation\Notifications\ValueObject\Introduction; /** @@ -39,34 +36,21 @@ use Friendica\Navigation\Notifications\ValueObject\Introduction; */ class Introductions extends BaseNotifications { - /** @var IntroductionFactory */ - protected $notificationIntro; - /** @var Mode */ - protected $mode; - - public function __construct(Mode $mode, IntroductionFactory $notificationIntro, Arguments $args, L10n $l10n, array $parameters = []) - { - parent::__construct($args, $l10n, $parameters); - - $this->notificationIntro = $notificationIntro; - $this->mode = $mode; - } - /** * @inheritDoc */ - public function getNotifications() + public static function getNotifications() { - $id = (int)$this->args->get(2, 0); - $all = $this->args->get(2) == 'all'; + $id = (int)DI::args()->get(2, 0); + $all = DI::args()->get(2) == 'all'; $notifications = [ 'ident' => 'introductions', - 'notifications' => $this->notificationIntro->getList($all, $this->firstItemNum, self::ITEMS_PER_PAGE, $id), + 'notifications' => DI::notificationIntro()->getList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id), ]; return [ - 'header' => $this->t('Notifications'), + 'header' => DI::l10n()->t('Notifications'), 'notifications' => $notifications, ]; } @@ -75,12 +59,12 @@ class Introductions extends BaseNotifications { Nav::setSelected('introductions'); - $all = $this->args->get(2) == 'all'; + $all = DI::args()->get(2) == 'all'; $notificationContent = []; $notificationNoContent = ''; - $notificationResult = $this->getNotifications(); + $notificationResult = self::getNotifications(); $notifications = $notificationResult['notifications'] ?? []; $notificationHeader = $notificationResult['header'] ?? ''; @@ -90,7 +74,7 @@ class Introductions extends BaseNotifications // The link to switch between ignored and normal connection requests $notificationShowLink = [ 'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros'), - 'text' => (!$all ? $this->t('Show Ignored Requests') : $this->t('Hide Ignored Requests')), + 'text' => (!$all ? DI::l10n()->t('Show Ignored Requests') : DI::l10n()->t('Hide Ignored Requests')), ]; $owner = User::getOwnerDataById(local_user()); @@ -106,10 +90,10 @@ class Introductions extends BaseNotifications case 'friend_suggestion': $notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [ '$type' => $Introduction->getLabel(), - '$str_notification_type' => $this->t('Notification type:'), + '$str_notification_type' => DI::l10n()->t('Notification type:'), '$str_type' => $Introduction->getType(), '$intro_id' => $Introduction->getIntroId(), - '$lbl_madeby' => $this->t('Suggested by:'), + '$lbl_madeby' => DI::l10n()->t('Suggested by:'), '$madeby' => $Introduction->getMadeBy(), '$madeby_url' => $Introduction->getMadeByUrl(), '$madeby_zrl' => $Introduction->getMadeByZrl(), @@ -120,22 +104,22 @@ class Introductions extends BaseNotifications '$dfrn_url' => $owner['url'], '$url' => $Introduction->getUrl(), '$zrl' => $Introduction->getZrl(), - '$lbl_url' => $this->t('Profile URL'), + '$lbl_url' => DI::l10n()->t('Profile URL'), '$addr' => $Introduction->getAddr(), '$action' => 'follow', - '$approve' => $this->t('Approve'), + '$approve' => DI::l10n()->t('Approve'), '$note' => $Introduction->getNote(), - '$ignore' => $this->t('Ignore'), - '$discard' => $this->t('Discard'), - '$is_mobile' => $this->mode->isMobile(), + '$ignore' => DI::l10n()->t('Ignore'), + '$discard' => DI::l10n()->t('Discard'), + '$is_mobile' => DI::mode()->isMobile(), ]); break; // Normal connection requests default: if ($Introduction->getNetwork() === Protocol::DFRN) { - $lbl_knowyou = $this->t('Claims to be known to you: '); - $knowyou = ($Introduction->getKnowYou() ? $this->t('Yes') : $this->t('No')); + $lbl_knowyou = DI::l10n()->t('Claims to be known to you: '); + $knowyou = ($Introduction->getKnowYou() ? DI::l10n()->t('Yes') : DI::l10n()->t('No')); } else { $lbl_knowyou = ''; $knowyou = ''; @@ -143,12 +127,12 @@ class Introductions extends BaseNotifications $convertedName = BBCode::convert($Introduction->getName()); - $helptext = $this->t('Shall your connection be bidirectional or not?'); - $helptext2 = $this->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $convertedName, $convertedName); - $helptext3 = $this->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $convertedName); + $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?'); + $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $convertedName, $convertedName); + $helptext3 = DI::l10n()->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $convertedName); - $friend = ['duplex', $this->t('Friend'), '1', $helptext2, true]; - $follower = ['duplex', $this->t('Subscriber'), '0', $helptext3, false]; + $friend = ['duplex', DI::l10n()->t('Friend'), '1', $helptext2, true]; + $follower = ['duplex', DI::l10n()->t('Subscriber'), '0', $helptext3, false]; $action = 'follow_confirm'; @@ -161,7 +145,7 @@ class Introductions extends BaseNotifications $header .= ' (' . ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()) . ')'; if ($Introduction->getNetwork() != Protocol::DIASPORA) { - $discard = $this->t('Discard'); + $discard = DI::l10n()->t('Discard'); } else { $discard = ''; } @@ -169,7 +153,7 @@ class Introductions extends BaseNotifications $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [ '$type' => $Introduction->getLabel(), '$header' => $header, - '$str_notification_type' => $this->t('Notification type:'), + '$str_notification_type' => DI::l10n()->t('Notification type:'), '$str_type' => $Introduction->getType(), '$dfrn_id' => $Introduction->getDfrnId(), '$uid' => $Introduction->getUid(), @@ -178,39 +162,39 @@ class Introductions extends BaseNotifications '$photo' => $Introduction->getPhoto(), '$fullname' => $Introduction->getName(), '$location' => $Introduction->getLocation(), - '$lbl_location' => $this->t('Location:'), + '$lbl_location' => DI::l10n()->t('Location:'), '$about' => $Introduction->getAbout(), - '$lbl_about' => $this->t('About:'), + '$lbl_about' => DI::l10n()->t('About:'), '$keywords' => $Introduction->getKeywords(), - '$lbl_keywords' => $this->t('Tags:'), - '$hidden' => ['hidden', $this->t('Hide this contact from others'), $Introduction->isHidden(), ''], + '$lbl_keywords' => DI::l10n()->t('Tags:'), + '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $Introduction->isHidden(), ''], '$lbl_connection_type' => $helptext, '$friend' => $friend, '$follower' => $follower, '$url' => $Introduction->getUrl(), '$zrl' => $Introduction->getZrl(), - '$lbl_url' => $this->t('Profile URL'), + '$lbl_url' => DI::l10n()->t('Profile URL'), '$addr' => $Introduction->getAddr(), '$lbl_knowyou' => $lbl_knowyou, - '$lbl_network' => $this->t('Network:'), + '$lbl_network' => DI::l10n()->t('Network:'), '$network' => ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()), '$knowyou' => $knowyou, - '$approve' => $this->t('Approve'), + '$approve' => DI::l10n()->t('Approve'), '$note' => $Introduction->getNote(), - '$ignore' => $this->t('Ignore'), + '$ignore' => DI::l10n()->t('Ignore'), '$discard' => $discard, '$action' => $action, - '$is_mobile' => $this->mode->isMobile(), + '$is_mobile' => DI::mode()->isMobile(), ]); break; } } if (count($notifications['notifications']) == 0) { - notice($this->t('No introductions.')); - $notificationNoContent = $this->t('No more %s notifications.', $notifications['ident']); + notice(DI::l10n()->t('No introductions.')); + $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']); } - return $this->printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink); + return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink); } } diff --git a/src/Module/Notifications/Notifications.php b/src/Module/Notifications/Notifications.php index 269acb79db..eef4af9bc4 100644 --- a/src/Module/Notifications/Notifications.php +++ b/src/Module/Notifications/Notifications.php @@ -21,13 +21,13 @@ namespace Friendica\Module\Notifications; -use Friendica\App\Arguments; -use Friendica\App\BaseURL; use Friendica\Content\Nav; -use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Module\BaseNotifications; +use Friendica\Navigation\Notifications\Collection\FormattedNotifications; use Friendica\Navigation\Notifications\ValueObject\FormattedNotification; +use Friendica\Network\HTTPException\InternalServerErrorException; /** * Prints all notification types except introduction: @@ -38,56 +38,42 @@ use Friendica\Navigation\Notifications\ValueObject\FormattedNotification; */ class Notifications extends BaseNotifications { - /** @var \Friendica\Navigation\Notifications\Factory\FormattedNotification */ - protected $formattedNotificationFactory; - - /** @var BaseURL */ - protected $baseUrl; - - public function __construct(BaseURL $baseUrl, \Friendica\Navigation\Notifications\Factory\FormattedNotification $formattedNotificationFactory, Arguments $args, L10n $l10n, array $parameters = []) - { - parent::__construct($args, $l10n, $parameters); - - $this->formattedNotificationFactory = $formattedNotificationFactory; - $this->baseUrl = $baseUrl; - } - /** * {@inheritDoc} */ - public function getNotifications() + public static function getNotifications() { $notificationHeader = ''; $notifications = []; - $factory = $this->formattedNotificationFactory; + $factory = DI::formattedNotificationFactory(); - if (($this->args->get(1) == 'network')) { - $notificationHeader = $this->t('Network Notifications'); + if ((DI::args()->get(1) == 'network')) { + $notificationHeader = DI::l10n()->t('Network Notifications'); $notifications = [ 'ident' => FormattedNotification::NETWORK, - 'notifications' => $factory->getNetworkList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE), + 'notifications' => $factory->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE), ]; - } elseif (($this->args->get(1) == 'system')) { - $notificationHeader = $this->t('System Notifications'); + } elseif ((DI::args()->get(1) == 'system')) { + $notificationHeader = DI::l10n()->t('System Notifications'); $notifications = [ 'ident' => FormattedNotification::SYSTEM, - 'notifications' => $factory->getSystemList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE), + 'notifications' => $factory->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE), ]; - } elseif (($this->args->get(1) == 'personal')) { - $notificationHeader = $this->t('Personal Notifications'); + } elseif ((DI::args()->get(1) == 'personal')) { + $notificationHeader = DI::l10n()->t('Personal Notifications'); $notifications = [ 'ident' => FormattedNotification::PERSONAL, - 'notifications' => $factory->getPersonalList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE), + 'notifications' => $factory->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE), ]; - } elseif (($this->args->get(1) == 'home')) { - $notificationHeader = $this->t('Home Notifications'); + } elseif ((DI::args()->get(1) == 'home')) { + $notificationHeader = DI::l10n()->t('Home Notifications'); $notifications = [ 'ident' => FormattedNotification::HOME, - 'notifications' => $factory->getHomeList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE), + 'notifications' => $factory->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE), ]; } else { - $this->baseUrl->redirect('notifications'); + DI::baseUrl()->redirect('notifications'); } return [ @@ -103,7 +89,7 @@ class Notifications extends BaseNotifications $notificationContent = []; $notificationNoContent = ''; - $notificationResult = $this->getNotifications(); + $notificationResult = self::getNotifications(); $notifications = $notificationResult['notifications'] ?? []; $notificationHeader = $notificationResult['header'] ?? ''; @@ -132,14 +118,14 @@ class Notifications extends BaseNotifications ]); } } else { - $notificationNoContent = $this->t('No more %s notifications.', $notificationResult['ident']); + $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notificationResult['ident']); } $notificationShowLink = [ - 'href' => ($this->showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'), - 'text' => ($this->showAll ? $this->t('Show unread') : $this->t('Show all')), + 'href' => (self::$showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'), + 'text' => (self::$showAll ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')), ]; - return $this->printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink); + return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink); } } diff --git a/src/Module/Owa.php b/src/Module/Owa.php index 6062f2c998..85530df6f9 100644 --- a/src/Module/Owa.php +++ b/src/Module/Owa.php @@ -44,8 +44,9 @@ use Friendica\Util\Strings; */ class Owa extends BaseModule { - public function rawContent() + public function init() { + $ret = [ 'success' => false ]; foreach (['REDIRECT_REMOTE_USER', 'HTTP_AUTHORIZATION'] as $head) { diff --git a/src/Module/Profile/Index.php b/src/Module/Profile/Index.php index 653eb2a199..75d467f547 100644 --- a/src/Module/Profile/Index.php +++ b/src/Module/Profile/Index.php @@ -22,7 +22,6 @@ namespace Friendica\Module\Profile; use Friendica\BaseModule; -use Friendica\Core\L10n; /** * Profile index router @@ -37,11 +36,11 @@ class Index extends BaseModule { public function rawContent() { - (new Profile($this->l10n, $this->parameters))->rawContent(); + (new Profile($this->parameters))->rawContent(); } public function content(): string { - return (new Status($this->l10n, $this->parameters))->content(); + return (new Status($this->parameters))->content(); } } diff --git a/src/Module/Register.php b/src/Module/Register.php index 609e86a919..fca59a2c85 100644 --- a/src/Module/Register.php +++ b/src/Module/Register.php @@ -33,6 +33,7 @@ use Friendica\DI; use Friendica\Model; use Friendica\Model\User; use Friendica\Util\Proxy; +use Friendica\Util\Strings; /** * @author Hypolite PetovanYou can enter one of your one-time recovery codes in case you lost access to your mobile device.
'), - '$recovery_message' => $this->t('Don’t have your phone? Enter a two-factor recovery code', '2fa/recovery'), - '$recovery_code' => ['recovery_code', $this->t('Please enter a recovery code'), '', '', '', 'placeholder="000000-000000"'], - '$recovery_label' => $this->t('Submit recovery code and complete login'), + '$title' => DI::l10n()->t('Two-factor recovery'), + '$message' => DI::l10n()->t('You can enter one of your one-time recovery codes in case you lost access to your mobile device.
'), + '$recovery_message' => DI::l10n()->t('Don’t have your phone? Enter a two-factor recovery code', '2fa/recovery'), + '$recovery_code' => ['recovery_code', DI::l10n()->t('Please enter a recovery code'), '', '', '', 'placeholder="000000-000000"'], + '$recovery_label' => DI::l10n()->t('Submit recovery code and complete login'), ]); } } diff --git a/src/Module/Settings/TwoFactor/AppSpecific.php b/src/Module/Settings/TwoFactor/AppSpecific.php index 21db4f8abf..74a9ba6578 100644 --- a/src/Module/Settings/TwoFactor/AppSpecific.php +++ b/src/Module/Settings/TwoFactor/AppSpecific.php @@ -21,10 +21,8 @@ namespace Friendica\Module\Settings\TwoFactor; -use Friendica\App\BaseURL; -use Friendica\Core\L10n; -use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Security\TwoFactor\Model\AppSpecificPassword; use Friendica\Module\BaseSettings; use Friendica\Module\Security\Login; @@ -36,33 +34,23 @@ use Friendica\Module\Security\Login; */ class AppSpecific extends BaseSettings { - private $appSpecificPassword = null; + private static $appSpecificPassword = null; - /** @var IManagePersonalConfigValues */ - protected $pConfig; - /** @var BaseURL */ - protected $baseUrl; - - public function __construct(IManagePersonalConfigValues $pConfig, BaseURL $baseUrl, L10n $l10n, array $parameters = []) + public function init() { - parent::__construct($l10n, $parameters); - - $this->pConfig = $pConfig; - $this->baseUrl = $baseUrl; - if (!local_user()) { return; } - $verified = $this->pConfig->get(local_user(), '2fa', 'verified'); + $verified = DI::pConfig()->get(local_user(), '2fa', 'verified'); if (!$verified) { - $this->baseUrl->redirect('settings/2fa'); + DI::baseUrl()->redirect('settings/2fa'); } if (!self::checkFormSecurityToken('settings_2fa_password', 't')) { - notice($this->t('Please enter your password to access this page.')); - $this->baseUrl->redirect('settings/2fa'); + notice(DI::l10n()->t('Please enter your password to access this page.')); + DI::baseUrl()->redirect('settings/2fa'); } } @@ -79,21 +67,21 @@ class AppSpecific extends BaseSettings case 'generate': $description = $_POST['description'] ?? ''; if (empty($description)) { - notice($this->t('App-specific password generation failed: The description is empty.')); - $this->baseUrl->redirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); + notice(DI::l10n()->t('App-specific password generation failed: The description is empty.')); + DI::baseUrl()->redirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); } elseif (AppSpecificPassword::checkDuplicateForUser(local_user(), $description)) { - notice($this->t('App-specific password generation failed: This description already exists.')); - $this->baseUrl->redirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); + notice(DI::l10n()->t('App-specific password generation failed: This description already exists.')); + DI::baseUrl()->redirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); } else { - $this->appSpecificPassword = AppSpecificPassword::generateForUser(local_user(), $_POST['description'] ?? ''); - info($this->t('New app-specific password generated.')); + self::$appSpecificPassword = AppSpecificPassword::generateForUser(local_user(), $_POST['description'] ?? ''); + info(DI::l10n()->t('New app-specific password generated.')); } break; case 'revoke_all' : AppSpecificPassword::deleteAllForUser(local_user()); - info($this->t('App-specific passwords successfully revoked.')); - $this->baseUrl->redirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); + info(DI::l10n()->t('App-specific passwords successfully revoked.')); + DI::baseUrl()->redirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); break; } } @@ -102,10 +90,10 @@ class AppSpecific extends BaseSettings self::checkFormSecurityTokenRedirectOnError('settings/2fa/app_specific', 'settings_2fa_app_specific'); if (AppSpecificPassword::deleteForUser(local_user(), $_POST['revoke_id'])) { - info($this->t('App-specific password successfully revoked.')); + info(DI::l10n()->t('App-specific password successfully revoked.')); } - $this->baseUrl->redirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::baseUrl()->redirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); } } @@ -123,22 +111,22 @@ class AppSpecific extends BaseSettings '$form_security_token' => self::getFormSecurityToken('settings_2fa_app_specific'), '$password_security_token' => self::getFormSecurityToken('settings_2fa_password'), - '$title' => $this->t('Two-factor app-specific passwords'), - '$help_label' => $this->t('Help'), - '$message' => $this->t('App-specific passwords are randomly generated passwords used instead your regular password to authenticate your account on third-party applications that don\'t support two-factor authentication.
'), - '$generated_message' => $this->t('Make sure to copy your new app-specific password now. You won’t be able to see it again!'), - '$generated_app_specific_password' => $this->appSpecificPassword, + '$title' => DI::l10n()->t('Two-factor app-specific passwords'), + '$help_label' => DI::l10n()->t('Help'), + '$message' => DI::l10n()->t('App-specific passwords are randomly generated passwords used instead your regular password to authenticate your account on third-party applications that don\'t support two-factor authentication.
'), + '$generated_message' => DI::l10n()->t('Make sure to copy your new app-specific password now. You won’t be able to see it again!'), + '$generated_app_specific_password' => self::$appSpecificPassword, - '$description_label' => $this->t('Description'), - '$last_used_label' => $this->t('Last Used'), - '$revoke_label' => $this->t('Revoke'), - '$revoke_all_label' => $this->t('Revoke All'), + '$description_label' => DI::l10n()->t('Description'), + '$last_used_label' => DI::l10n()->t('Last Used'), + '$revoke_label' => DI::l10n()->t('Revoke'), + '$revoke_all_label' => DI::l10n()->t('Revoke All'), '$app_specific_passwords' => $appSpecificPasswords, - '$generate_message' => $this->t('When you generate a new app-specific password, you must use it right away, it will be shown to you once after you generate it.'), - '$generate_title' => $this->t('Generate new app-specific password'), - '$description_placeholder_label' => $this->t('Friendiqa on my Fairphone 2...'), - '$generate_label' => $this->t('Generate'), + '$generate_message' => DI::l10n()->t('When you generate a new app-specific password, you must use it right away, it will be shown to you once after you generate it.'), + '$generate_title' => DI::l10n()->t('Generate new app-specific password'), + '$description_placeholder_label' => DI::l10n()->t('Friendiqa on my Fairphone 2...'), + '$generate_label' => DI::l10n()->t('Generate'), ]); } } diff --git a/src/Module/Settings/TwoFactor/Recovery.php b/src/Module/Settings/TwoFactor/Recovery.php index 961c2cd904..d46f6a8f52 100644 --- a/src/Module/Settings/TwoFactor/Recovery.php +++ b/src/Module/Settings/TwoFactor/Recovery.php @@ -21,10 +21,8 @@ namespace Friendica\Module\Settings\TwoFactor; -use Friendica\App\BaseURL; -use Friendica\Core\L10n; -use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Security\TwoFactor\Model\RecoveryCode; use Friendica\Module\BaseSettings; use Friendica\Module\Security\Login; @@ -36,31 +34,21 @@ use Friendica\Module\Security\Login; */ class Recovery extends BaseSettings { - /** @var IManagePersonalConfigValues */ - protected $pConfig; - /** @var BaseURL */ - protected $baseUrl; - - public function __construct(IManagePersonalConfigValues $pConfig, BaseURL $baseUrl, L10n $l10n, array $parameters = []) + public function init() { - parent::__construct($l10n, $parameters); - - $this->pConfig = $pConfig; - $this->baseUrl = $baseUrl; - if (!local_user()) { return; } - $secret = $this->pConfig->get(local_user(), '2fa', 'secret'); + $secret = DI::pConfig()->get(local_user(), '2fa', 'secret'); if (!$secret) { - $this->baseUrl->redirect('settings/2fa'); + DI::baseUrl()->redirect('settings/2fa'); } if (!self::checkFormSecurityToken('settings_2fa_password', 't')) { - notice($this->t('Please enter your password to access this page.')); - $this->baseUrl->redirect('settings/2fa'); + notice(DI::l10n()->t('Please enter your password to access this page.')); + DI::baseUrl()->redirect('settings/2fa'); } } @@ -75,8 +63,8 @@ class Recovery extends BaseSettings if ($_POST['action'] == 'regenerate') { RecoveryCode::regenerateForUser(local_user()); - info($this->t('New recovery codes successfully generated.')); - $this->baseUrl->redirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password')); + info(DI::l10n()->t('New recovery codes successfully generated.')); + DI::baseUrl()->redirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password')); } } } @@ -95,20 +83,20 @@ class Recovery extends BaseSettings $recoveryCodes = RecoveryCode::getListForUser(local_user()); - $verified = $this->pConfig->get(local_user(), '2fa', 'verified'); + $verified = DI::pConfig()->get(local_user(), '2fa', 'verified'); return Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/twofactor/recovery.tpl'), [ '$form_security_token' => self::getFormSecurityToken('settings_2fa_recovery'), '$password_security_token' => self::getFormSecurityToken('settings_2fa_password'), - '$title' => $this->t('Two-factor recovery codes'), - '$help_label' => $this->t('Help'), - '$message' => $this->t('Recovery codes can be used to access your account in the event you lose access to your device and cannot receive two-factor authentication codes.
Put these in a safe spot! If you lose your device and don’t have the recovery codes you will lose access to your account.
'), + '$title' => DI::l10n()->t('Two-factor recovery codes'), + '$help_label' => DI::l10n()->t('Help'), + '$message' => DI::l10n()->t('Recovery codes can be used to access your account in the event you lose access to your device and cannot receive two-factor authentication codes.
Put these in a safe spot! If you lose your device and don’t have the recovery codes you will lose access to your account.
'), '$recovery_codes' => $recoveryCodes, - '$regenerate_message' => $this->t('When you generate new recovery codes, you must copy the new codes. Your old codes won’t work anymore.'), - '$regenerate_label' => $this->t('Generate new recovery codes'), + '$regenerate_message' => DI::l10n()->t('When you generate new recovery codes, you must copy the new codes. Your old codes won’t work anymore.'), + '$regenerate_label' => DI::l10n()->t('Generate new recovery codes'), '$verified' => $verified, - '$verify_label' => $this->t('Next: Verification'), + '$verify_label' => DI::l10n()->t('Next: Verification'), ]); } } diff --git a/src/Module/Settings/TwoFactor/Trusted.php b/src/Module/Settings/TwoFactor/Trusted.php index e38d64ac04..d1e0c177a9 100644 --- a/src/Module/Settings/TwoFactor/Trusted.php +++ b/src/Module/Settings/TwoFactor/Trusted.php @@ -2,10 +2,8 @@ namespace Friendica\Module\Settings\TwoFactor; -use Friendica\App\BaseURL; -use Friendica\Core\L10n; -use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Module\BaseSettings; use Friendica\Security\TwoFactor; use Friendica\Util\Temporal; @@ -16,34 +14,21 @@ use UAParser\Parser; */ class Trusted extends BaseSettings { - /** @var IManagePersonalConfigValues */ - protected $pConfig; - /** @var BaseURL */ - protected $baseUrl; - /** @var TwoFactor\Repository\TrustedBrowser */ - protected $trustedBrowserRepo; - - public function __construct(IManagePersonalConfigValues $pConfig, BaseURL $baseUrl, TwoFactor\Repository\TrustedBrowser $trustedBrowserRepo, L10n $l10n, array $parameters = []) + public function init() { - parent::__construct($l10n, $parameters); - - $this->pConfig = $pConfig; - $this->baseUrl = $baseUrl; - $this->trustedBrowserRepo = $trustedBrowserRepo; - if (!local_user()) { return; } - $verified = $this->pConfig->get(local_user(), '2fa', 'verified'); + $verified = DI::pConfig()->get(local_user(), '2fa', 'verified'); if (!$verified) { - $this->baseUrl->redirect('settings/2fa'); + DI::baseUrl()->redirect('settings/2fa'); } if (!self::checkFormSecurityToken('settings_2fa_password', 't')) { - notice($this->t('Please enter your password to access this page.')); - $this->baseUrl->redirect('settings/2fa'); + notice(DI::l10n()->t('Please enter your password to access this page.')); + DI::baseUrl()->redirect('settings/2fa'); } } @@ -53,14 +38,16 @@ class Trusted extends BaseSettings return; } + $trustedBrowserRepository = new TwoFactor\Repository\TrustedBrowser(DI::dba(), DI::logger()); + if (!empty($_POST['action'])) { self::checkFormSecurityTokenRedirectOnError('settings/2fa/trusted', 'settings_2fa_trusted'); switch ($_POST['action']) { case 'remove_all' : - $this->trustedBrowserRepo->removeAllForUser(local_user()); - info($this->t('Trusted browsers successfully removed.')); - $this->baseUrl->redirect('settings/2fa/trusted?t=' . self::getFormSecurityToken('settings_2fa_password')); + $trustedBrowserRepository->removeAllForUser(local_user()); + info(DI::l10n()->t('Trusted browsers successfully removed.')); + DI::baseUrl()->redirect('settings/2fa/trusted?t=' . self::getFormSecurityToken('settings_2fa_password')); break; } } @@ -68,11 +55,11 @@ class Trusted extends BaseSettings if (!empty($_POST['remove_id'])) { self::checkFormSecurityTokenRedirectOnError('settings/2fa/trusted', 'settings_2fa_trusted'); - if ($this->trustedBrowserRepo->removeForUser(local_user(), $_POST['remove_id'])) { - info($this->t('Trusted browser successfully removed.')); + if ($trustedBrowserRepository->removeForUser(local_user(), $_POST['remove_id'])) { + info(DI::l10n()->t('Trusted browser successfully removed.')); } - $this->baseUrl->redirect('settings/2fa/trusted?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::baseUrl()->redirect('settings/2fa/trusted?t=' . self::getFormSecurityToken('settings_2fa_password')); } } @@ -81,7 +68,8 @@ class Trusted extends BaseSettings { parent::content(); - $trustedBrowsers = $this->trustedBrowserRepo->selectAllByUid(local_user()); + $trustedBrowserRepository = new TwoFactor\Repository\TrustedBrowser(DI::dba(), DI::logger()); + $trustedBrowsers = $trustedBrowserRepository->selectAllByUid(local_user()); $parser = Parser::create(); @@ -106,15 +94,15 @@ class Trusted extends BaseSettings '$form_security_token' => self::getFormSecurityToken('settings_2fa_trusted'), '$password_security_token' => self::getFormSecurityToken('settings_2fa_password'), - '$title' => $this->t('Two-factor Trusted Browsers'), - '$message' => $this->t('Trusted browsers are individual browsers you chose to skip two-factor authentication to access Friendica. Please use this feature sparingly, as it can negate the benefit of two-factor authentication.'), - '$device_label' => $this->t('Device'), - '$os_label' => $this->t('OS'), - '$browser_label' => $this->t('Browser'), - '$created_label' => $this->t('Trusted'), - '$last_used_label' => $this->t('Last Use'), - '$remove_label' => $this->t('Remove'), - '$remove_all_label' => $this->t('Remove All'), + '$title' => DI::l10n()->t('Two-factor Trusted Browsers'), + '$message' => DI::l10n()->t('Trusted browsers are individual browsers you chose to skip two-factor authentication to access Friendica. Please use this feature sparingly, as it can negate the benefit of two-factor authentication.'), + '$device_label' => DI::l10n()->t('Device'), + '$os_label' => DI::l10n()->t('OS'), + '$browser_label' => DI::l10n()->t('Browser'), + '$created_label' => DI::l10n()->t('Trusted'), + '$last_used_label' => DI::l10n()->t('Last Use'), + '$remove_label' => DI::l10n()->t('Remove'), + '$remove_all_label' => DI::l10n()->t('Remove All'), '$trusted_browsers' => $trustedBrowserDisplay, ]); diff --git a/src/Module/Settings/TwoFactor/Verify.php b/src/Module/Settings/TwoFactor/Verify.php index 93fdde9207..18aa6ca9f0 100644 --- a/src/Module/Settings/TwoFactor/Verify.php +++ b/src/Module/Settings/TwoFactor/Verify.php @@ -25,11 +25,9 @@ use BaconQrCode\Renderer\Image\SvgImageBackEnd; use BaconQrCode\Renderer\ImageRenderer; use BaconQrCode\Renderer\RendererStyle\RendererStyle; use BaconQrCode\Writer; -use Friendica\App\BaseURL; -use Friendica\Core\L10n; -use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\Renderer; use Friendica\Core\Session; +use Friendica\DI; use Friendica\Module\BaseSettings; use Friendica\Module\Security\Login; use PragmaRX\Google2FA\Google2FA; @@ -41,32 +39,22 @@ use PragmaRX\Google2FA\Google2FA; */ class Verify extends BaseSettings { - /** @var IManagePersonalConfigValues */ - protected $pConfig; - /** @var BaseURL */ - protected $baseUrl; - - public function __construct(IManagePersonalConfigValues $pConfig, BaseURL $baseUrl, L10n $l10n, array $parameters = []) + public function init() { - parent::__construct($l10n, $parameters); - - $this->pConfig = $pConfig; - $this->baseUrl = $baseUrl; - if (!local_user()) { return; } - $secret = $this->pConfig->get(local_user(), '2fa', 'secret'); - $verified = $this->pConfig->get(local_user(), '2fa', 'verified'); + $secret = DI::pConfig()->get(local_user(), '2fa', 'secret'); + $verified = DI::pConfig()->get(local_user(), '2fa', 'verified'); if ($secret && $verified) { - $this->baseUrl->redirect('settings/2fa'); + DI::baseUrl()->redirect('settings/2fa'); } if (!self::checkFormSecurityToken('settings_2fa_password', 't')) { - notice($this->t('Please enter your password to access this page.')); - $this->baseUrl->redirect('settings/2fa'); + notice(DI::l10n()->t('Please enter your password to access this page.')); + DI::baseUrl()->redirect('settings/2fa'); } } @@ -81,17 +69,17 @@ class Verify extends BaseSettings $google2fa = new Google2FA(); - $valid = $google2fa->verifyKey($this->pConfig->get(local_user(), '2fa', 'secret'), $_POST['verify_code'] ?? ''); + $valid = $google2fa->verifyKey(DI::pConfig()->get(local_user(), '2fa', 'secret'), $_POST['verify_code'] ?? ''); if ($valid) { - $this->pConfig->set(local_user(), '2fa', 'verified', true); + DI::pConfig()->set(local_user(), '2fa', 'verified', true); Session::set('2fa', true); - info($this->t('Two-factor authentication successfully activated.')); + info(DI::l10n()->t('Two-factor authentication successfully activated.')); - $this->baseUrl->redirect('settings/2fa'); + DI::baseUrl()->redirect('settings/2fa'); } else { - notice($this->t('Invalid code, please retry.')); + notice(DI::l10n()->t('Invalid code, please retry.')); } } } @@ -106,7 +94,7 @@ class Verify extends BaseSettings $company = 'Friendica'; $holder = Session::get('my_address'); - $secret = $this->pConfig->get(local_user(), '2fa', 'secret'); + $secret = DI::pConfig()->get(local_user(), '2fa', 'secret'); $otpauthUrl = (new Google2FA())->getQRCodeUrl($company, $holder, $secret); @@ -120,7 +108,7 @@ class Verify extends BaseSettings $shortOtpauthUrl = explode('?', $otpauthUrl)[0]; - $manual_message = $this->t('Or you can submit the authentication settings manually:
+ $manual_message = DI::l10n()->t('Or you can submit the authentication settings manually:
Please scan this QR Code with your authenticator app and submit the provided code.
'), + '$title' => DI::l10n()->t('Two-factor code verification'), + '$help_label' => DI::l10n()->t('Help'), + '$message' => DI::l10n()->t('Please scan this QR Code with your authenticator app and submit the provided code.
'), '$qrcode_image' => $qrcode_image, - '$qrcode_url_message' => $this->t('Or you can open the following URL in your mobile device:
', $otpauthUrl, $shortOtpauthUrl), + '$qrcode_url_message' => DI::l10n()->t('Or you can open the following URL in your mobile device:
', $otpauthUrl, $shortOtpauthUrl), '$manual_message' => $manual_message, '$company' => $company, '$holder' => $holder, '$secret' => $secret, - '$verify_code' => ['verify_code', $this->t('Please enter a code from your authentication app'), '', '', $this->t('Required'), 'autofocus autocomplete="off" placeholder="000000"'], - '$verify_label' => $this->t('Verify code and enable two-factor authentication'), + '$verify_code' => ['verify_code', DI::l10n()->t('Please enter a code from your authentication app'), '', '', DI::l10n()->t('Required'), 'autofocus autocomplete="off" placeholder="000000"'], + '$verify_label' => DI::l10n()->t('Verify code and enable two-factor authentication'), ]); } } diff --git a/src/Module/Statistics.php b/src/Module/Statistics.php index f4a1334d2e..a78031c369 100644 --- a/src/Module/Statistics.php +++ b/src/Module/Statistics.php @@ -23,35 +23,26 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\Addon; -use Friendica\Core\Config\Capability\IManageConfigValues; -use Friendica\Core\L10n; +use Friendica\DI; use Friendica\Network\HTTPException\NotFoundException; -use Psr\Log\LoggerInterface; class Statistics extends BaseModule { - /** @var IManageConfigValues */ - protected $config; - /** @var LoggerInterface */ - protected $logger; - - public function __construct(IManageConfigValues $config, LoggerInterface $logger, L10n $l10n, array $parameters = []) + public function init() { - parent::__construct($l10n, $parameters); - - $this->logger = $logger; - $this->config = $config; - - if (!$this->config->get("system", "nodeinfo")) { + if (!DI::config()->get("system", "nodeinfo")) { throw new NotFoundException(); } } public function rawContent() { + $config = DI::config(); + $logger = DI::logger(); + $registration_open = - intval($this->config->get('config', 'register_policy')) !== Register::CLOSED - && !$this->config->get('config', 'invitation_only'); + intval($config->get('config', 'register_policy')) !== Register::CLOSED + && !$config->get('config', 'invitation_only'); /// @todo mark the "service" addons and load them dynamically here $services = [ @@ -68,20 +59,20 @@ class Statistics extends BaseModule ]; $statistics = array_merge([ - 'name' => $this->config->get('config', 'sitename'), + 'name' => $config->get('config', 'sitename'), 'network' => FRIENDICA_PLATFORM, 'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION, 'registrations_open' => $registration_open, - 'total_users' => $this->config->get('nodeinfo', 'total_users'), - 'active_users_halfyear' => $this->config->get('nodeinfo', 'active_users_halfyear'), - 'active_users_monthly' => $this->config->get('nodeinfo', 'active_users_monthly'), - 'local_posts' => $this->config->get('nodeinfo', 'local_posts'), + 'total_users' => $config->get('nodeinfo', 'total_users'), + 'active_users_halfyear' => $config->get('nodeinfo', 'active_users_halfyear'), + 'active_users_monthly' => $config->get('nodeinfo', 'active_users_monthly'), + 'local_posts' => $config->get('nodeinfo', 'local_posts'), 'services' => $services, ], $services); header("Content-Type: application/json"); echo json_encode($statistics, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); - $this->logger->debug("statistics.", ['statistics' => $statistics]); + $logger->debug("statistics.", ['statistics' => $statistics]); exit(); } } diff --git a/src/Module/Tos.php b/src/Module/Tos.php index 1b71627535..8357ead18a 100644 --- a/src/Module/Tos.php +++ b/src/Module/Tos.php @@ -21,12 +21,10 @@ namespace Friendica\Module; -use Friendica\App\BaseURL; use Friendica\BaseModule; -use Friendica\Core\Config\Capability\IManageConfigValues; -use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Content\Text\BBCode; +use Friendica\DI; class Tos extends BaseModule { @@ -36,11 +34,6 @@ class Tos extends BaseModule public $privacy_delete; public $privacy_complete; - /** @var IManageConfigValues */ - protected $config; - /** @var BaseURL */ - protected $baseUrl; - /** * constructor for the module, initializing the text variables * @@ -48,20 +41,30 @@ class Tos extends BaseModule * be properties of the class, however cannot be set directly as the property * cannot depend on a function result when declaring the variable. **/ - public function __construct(IManageConfigValues $config, BaseURL $baseUrl, L10n $l10n, array $parameters = []) + public function __construct(array $parameters = []) { - parent::__construct($l10n, $parameters); + parent::__construct($parameters); - $this->config = $config; - $this->baseUrl = $baseUrl; - - $this->privacy_operate = $this->t('At the time of registration, and for providing communications between the user account and their contacts, the user has to provide a display name (pen name), an username (nickname) and a working email address. The names will be accessible on the profile page of the account by any visitor of the page, even if other profile details are not displayed. The email address will only be used to send the user notifications about interactions, but wont be visibly displayed. The listing of an account in the node\'s user directory or the global user directory is optional and can be controlled in the user settings, it is not necessary for communication.'); - $this->privacy_distribute = $this->t('This data is required for communication and is passed on to the nodes of the communication partners and is stored there. Users can enter additional private data that may be transmitted to the communication partners accounts.'); - $this->privacy_delete = $this->t('At any point in time a logged in user can export their account data from the account settings. If the user wants to delete their account they can do so at %1$s/removeme. The deletion of the account will be permanent. Deletion of the data will also be requested from the nodes of the communication partners.', $this->baseUrl); + $this->privacy_operate = DI::l10n()->t('At the time of registration, and for providing communications between the user account and their contacts, the user has to provide a display name (pen name), an username (nickname) and a working email address. The names will be accessible on the profile page of the account by any visitor of the page, even if other profile details are not displayed. The email address will only be used to send the user notifications about interactions, but wont be visibly displayed. The listing of an account in the node\'s user directory or the global user directory is optional and can be controlled in the user settings, it is not necessary for communication.'); + $this->privacy_distribute = DI::l10n()->t('This data is required for communication and is passed on to the nodes of the communication partners and is stored there. Users can enter additional private data that may be transmitted to the communication partners accounts.'); + $this->privacy_delete = DI::l10n()->t('At any point in time a logged in user can export their account data from the account settings. If the user wants to delete their account they can do so at %1$s/removeme. The deletion of the account will be permanent. Deletion of the data will also be requested from the nodes of the communication partners.', DI::baseUrl()); // In some cases we don't need every single one of the above separate, but all in one block. // So here is an array to look over - $this->privacy_complete = [$this->t('Privacy Statement'), $this->privacy_operate, - $this->privacy_distribute, $this->privacy_delete]; + $this->privacy_complete = [DI::l10n()->t('Privacy Statement'), $this->privacy_operate, $this->privacy_distribute, $this->privacy_delete]; + } + + /** + * initialize the TOS module. + * + * If this is a single user instance, we expect the user to know their + * dealings with their own node so a TOS is not necessary. + * + **/ + public function init() + { + if (strlen(DI::config()->get('system','singleuser'))) { + DI::baseUrl()->redirect('profile/' . DI::config()->get('system','singleuser')); + } } /** @@ -76,22 +79,17 @@ class Tos extends BaseModule * @return string * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function content(): string - { - if (strlen($this->config->get('system', 'singleuser'))) { - $this->baseUrl->redirect('profile/' . $this->config->get('system', 'singleuser')); - } - + public function content(): string { $tpl = Renderer::getMarkupTemplate('tos.tpl'); - if ($this->config->get('system', 'tosdisplay')) { + if (DI::config()->get('system', 'tosdisplay')) { return Renderer::replaceMacros($tpl, [ - '$title' => $this->t('Terms of Service'), - '$tostext' => BBCode::convert($this->config->get('system', 'tostext')), - '$displayprivstatement' => $this->config->get('system', 'tosprivstatement'), - '$privstatementtitle' => $this->t('Privacy Statement'), - '$privacy_operate' => $this->t('At the time of registration, and for providing communications between the user account and their contacts, the user has to provide a display name (pen name), an username (nickname) and a working email address. The names will be accessible on the profile page of the account by any visitor of the page, even if other profile details are not displayed. The email address will only be used to send the user notifications about interactions, but wont be visibly displayed. The listing of an account in the node\'s user directory or the global user directory is optional and can be controlled in the user settings, it is not necessary for communication.'), - '$privacy_distribute' => $this->t('This data is required for communication and is passed on to the nodes of the communication partners and is stored there. Users can enter additional private data that may be transmitted to the communication partners accounts.'), - '$privacy_delete' => $this->t('At any point in time a logged in user can export their account data from the account settings. If the user wants to delete their account they can do so at %1$s/removeme. The deletion of the account will be permanent. Deletion of the data will also be requested from the nodes of the communication partners.', $this->baseUrl) + '$title' => DI::l10n()->t('Terms of Service'), + '$tostext' => BBCode::convert(DI::config()->get('system', 'tostext')), + '$displayprivstatement' => DI::config()->get('system', 'tosprivstatement'), + '$privstatementtitle' => DI::l10n()->t('Privacy Statement'), + '$privacy_operate' => DI::l10n()->t('At the time of registration, and for providing communications between the user account and their contacts, the user has to provide a display name (pen name), an username (nickname) and a working email address. The names will be accessible on the profile page of the account by any visitor of the page, even if other profile details are not displayed. The email address will only be used to send the user notifications about interactions, but wont be visibly displayed. The listing of an account in the node\'s user directory or the global user directory is optional and can be controlled in the user settings, it is not necessary for communication.'), + '$privacy_distribute' => DI::l10n()->t('This data is required for communication and is passed on to the nodes of the communication partners and is stored there. Users can enter additional private data that may be transmitted to the communication partners accounts.'), + '$privacy_delete' => DI::l10n()->t('At any point in time a logged in user can export their account data from the account settings. If the user wants to delete their account they can do so at %1$s/removeme. The deletion of the account will be permanent. Deletion of the data will also be requested from the nodes of the communication partners.', DI::baseUrl()) ]); } else { return ''; diff --git a/tests/src/App/ModuleControllerTest.php b/tests/src/App/ModuleControllerTest.php index 4e3983adde..13ef16a6d4 100644 --- a/tests/src/App/ModuleControllerTest.php +++ b/tests/src/App/ModuleControllerTest.php @@ -54,7 +54,7 @@ class ModuleControllerTest extends DatabaseTest self::assertModule([ 'isBackend' => false, 'name' => App\ModuleController::DEFAULT, - 'class' => null, + 'class' => new $defaultClass(), ], $module); } @@ -146,28 +146,28 @@ class ModuleControllerTest extends DatabaseTest 'name' => App\ModuleController::DEFAULT, 'command' => App\ModuleController::DEFAULT, 'privAdd' => false, - 'args' => [Mockery::mock(L10n::class)], + 'args' => [], ], 'legacy' => [ 'assert' => LegacyModule::class, 'name' => 'display', 'command' => 'display/test/it', 'privAdd' => false, - 'args' => [Mockery::mock(L10n::class), __DIR__ . '/../../datasets/legacy/legacy.php'], + 'args' => [__DIR__ . '/../../datasets/legacy/legacy.php'], ], 'new' => [ 'assert' => HostMeta::class, 'not_required', 'command' => '.well-known/host-meta', 'privAdd' => false, - 'args' => [Mockery::mock(L10n::class)], + 'args' => [], ], '404' => [ 'assert' => PageNotFound::class, 'name' => 'invalid', 'command' => 'invalid', 'privAdd' => false, - 'args' => [Mockery::mock(L10n::class)], + 'args' => [], ] ]; } diff --git a/tests/src/Module/Api/Friendica/NotificationTest.php b/tests/src/Module/Api/Friendica/NotificationTest.php index 125e7d63d0..7f1fd701fa 100644 --- a/tests/src/Module/Api/Friendica/NotificationTest.php +++ b/tests/src/Module/Api/Friendica/NotificationTest.php @@ -67,7 +67,7 @@ class NotificationTest extends ApiTest XML; - $notification = new Notification(DI::l10n(), ['extension' => 'xml']); + $notification = new Notification(['extension' => 'xml']); $notification->rawContent(); self::assertXmlStringEqualsXmlString($assertXml, ApiResponseDouble::getOutput()); @@ -75,7 +75,7 @@ XML; public function testWithJsonResult() { - $notification = new Notification(DI::l10n(),['parameter' => 'json']); + $notification = new Notification(['parameter' => 'json']); $notification->rawContent(); $result = json_encode(ApiResponseDouble::getOutput()); diff --git a/tests/src/Module/Api/Friendica/Photo/DeleteTest.php b/tests/src/Module/Api/Friendica/Photo/DeleteTest.php index 0958110115..5581c9cc2e 100644 --- a/tests/src/Module/Api/Friendica/Photo/DeleteTest.php +++ b/tests/src/Module/Api/Friendica/Photo/DeleteTest.php @@ -21,7 +21,6 @@ namespace Friendica\Test\src\Module\Api\Friendica\Photo; -use Friendica\DI; use Friendica\Module\Api\Friendica\Photo\Delete; use Friendica\Network\HTTPException\BadRequestException; use Friendica\Test\src\Module\Api\ApiTest; @@ -31,7 +30,7 @@ class DeleteTest extends ApiTest public function testEmpty() { $this->expectException(BadRequestException::class); - (new Delete(DI::l10n()))->rawContent(); + (new Delete())->rawContent(); } public function testWithoutAuthenticatedUser() @@ -42,7 +41,7 @@ class DeleteTest extends ApiTest public function testWrong() { $this->expectException(BadRequestException::class); - (new Delete(DI::l10n(), ['photo_id' => 1]))->rawContent(); + (new Delete(['photo_id' => 1]))->rawContent(); } public function testWithCorrectPhotoId() diff --git a/tests/src/Module/Api/Friendica/Photoalbum/DeleteTest.php b/tests/src/Module/Api/Friendica/Photoalbum/DeleteTest.php index aabd7e581c..6ee3c5e7b5 100644 --- a/tests/src/Module/Api/Friendica/Photoalbum/DeleteTest.php +++ b/tests/src/Module/Api/Friendica/Photoalbum/DeleteTest.php @@ -21,7 +21,6 @@ namespace Friendica\Test\src\Module\Api\Friendica\Photoalbum; -use Friendica\DI; use Friendica\Module\Api\Friendica\Photoalbum\Delete; use Friendica\Network\HTTPException\BadRequestException; use Friendica\Test\src\Module\Api\ApiTest; @@ -31,13 +30,13 @@ class DeleteTest extends ApiTest public function testEmpty() { $this->expectException(BadRequestException::class); - (new Delete(DI::l10n()))->rawContent(); + (new Delete())->rawContent(); } public function testWrong() { $this->expectException(BadRequestException::class); - (new Delete(DI::l10n(), ['album' => 'album_name']))->rawContent(); + (new Delete(['album' => 'album_name']))->rawContent(); } public function testValid() diff --git a/tests/src/Module/Api/Friendica/Photoalbum/UpdateTest.php b/tests/src/Module/Api/Friendica/Photoalbum/UpdateTest.php index 51414302fa..c7d65cb16b 100644 --- a/tests/src/Module/Api/Friendica/Photoalbum/UpdateTest.php +++ b/tests/src/Module/Api/Friendica/Photoalbum/UpdateTest.php @@ -21,7 +21,6 @@ namespace Friendica\Test\src\Module\Api\Friendica\Photoalbum; -use Friendica\DI; use Friendica\Module\Api\Friendica\Photoalbum\Update; use Friendica\Network\HTTPException\BadRequestException; use Friendica\Test\src\Module\Api\ApiTest; @@ -31,19 +30,19 @@ class UpdateTest extends ApiTest public function testEmpty() { $this->expectException(BadRequestException::class); - (new Update(DI::l10n()))->rawContent(); + (new Update())->rawContent(); } public function testTooFewArgs() { $this->expectException(BadRequestException::class); - (new Update(DI::l10n(), ['album' => 'album_name']))->rawContent(); + (new Update(['album' => 'album_name']))->rawContent(); } public function testWrongUpdate() { $this->expectException(BadRequestException::class); - (new Update(DI::l10n(), ['album' => 'album_name', 'album_new' => 'album_name']))->rawContent(); + (new Update(['album' => 'album_name', 'album_new' => 'album_name']))->rawContent(); } public function testWithoutAuthenticatedUser() diff --git a/tests/src/Module/Api/GnuSocial/GnuSocial/VersionTest.php b/tests/src/Module/Api/GnuSocial/GnuSocial/VersionTest.php index 448f6ce145..a819a7a1e6 100644 --- a/tests/src/Module/Api/GnuSocial/GnuSocial/VersionTest.php +++ b/tests/src/Module/Api/GnuSocial/GnuSocial/VersionTest.php @@ -2,7 +2,6 @@ namespace Friendica\Test\src\Module\Api\GnuSocial\GnuSocial; -use Friendica\DI; use Friendica\Module\Api\GNUSocial\GNUSocial\Version; use Friendica\Test\src\Module\Api\ApiTest; use Friendica\Test\Util\ApiResponseDouble; @@ -11,7 +10,7 @@ class VersionTest extends ApiTest { public function test() { - $version = new Version(DI::l10n(), ['extension' => 'json']); + $version = new Version(['extension' => 'json']); $version->rawContent(); $result = json_decode(ApiResponseDouble::getOutput()); diff --git a/tests/src/Module/Api/GnuSocial/Help/TestTest.php b/tests/src/Module/Api/GnuSocial/Help/TestTest.php index 40d8e9750e..c624ca0326 100644 --- a/tests/src/Module/Api/GnuSocial/Help/TestTest.php +++ b/tests/src/Module/Api/GnuSocial/Help/TestTest.php @@ -2,7 +2,6 @@ namespace Friendica\Test\src\Module\Api\GnuSocial\Help; -use Friendica\DI; use Friendica\Module\Api\GNUSocial\Help\Test; use Friendica\Test\src\Module\Api\ApiTest; use Friendica\Test\Util\ApiResponseDouble; @@ -11,7 +10,7 @@ class TestTest extends ApiTest { public function testJson() { - $test = new Test(DI::l10n(), ['extension' => 'json']); + $test = new Test(['extension' => 'json']); $test->rawContent(); self::assertEquals('"ok"', ApiResponseDouble::getOutput()); @@ -19,7 +18,7 @@ class TestTest extends ApiTest public function testXml() { - $test = new Test(DI::l10n(), ['extension' => 'xml']); + $test = new Test(['extension' => 'xml']); $test->rawContent(); self::assertxml(ApiResponseDouble::getOutput(), 'ok'); diff --git a/tests/src/Module/Api/Twitter/Account/RateLimitStatusTest.php b/tests/src/Module/Api/Twitter/Account/RateLimitStatusTest.php index 93d76933ba..3a84324af5 100644 --- a/tests/src/Module/Api/Twitter/Account/RateLimitStatusTest.php +++ b/tests/src/Module/Api/Twitter/Account/RateLimitStatusTest.php @@ -2,7 +2,6 @@ namespace Friendica\Test\src\Module\Api\Twitter\Account; -use Friendica\DI; use Friendica\Module\Api\Twitter\Account\RateLimitStatus; use Friendica\Test\src\Module\Api\ApiTest; use Friendica\Test\Util\ApiResponseDouble; @@ -11,7 +10,7 @@ class RateLimitStatusTest extends ApiTest { public function testWithJson() { - $rateLimitStatus = new RateLimitStatus(DI::l10n(), ['extension' => 'json']); + $rateLimitStatus = new RateLimitStatus(['extension' => 'json']); $rateLimitStatus->rawContent(); $result = json_decode(ApiResponseDouble::getOutput()); @@ -23,7 +22,7 @@ class RateLimitStatusTest extends ApiTest public function testWithXml() { - $rateLimitStatus = new RateLimitStatus(DI::l10n(),['extension' => 'xml']); + $rateLimitStatus = new RateLimitStatus(['extension' => 'xml']); $rateLimitStatus->rawContent(); self::assertXml(ApiResponseDouble::getOutput(), 'hash'); diff --git a/tests/src/Module/Api/Twitter/SavedSearchesTest.php b/tests/src/Module/Api/Twitter/SavedSearchesTest.php index 8e066d4bad..fc0f80467b 100644 --- a/tests/src/Module/Api/Twitter/SavedSearchesTest.php +++ b/tests/src/Module/Api/Twitter/SavedSearchesTest.php @@ -2,7 +2,6 @@ namespace Friendica\Test\src\Module\Api\Twitter; -use Friendica\DI; use Friendica\Module\Api\Twitter\SavedSearches; use Friendica\Test\src\Module\Api\ApiTest; use Friendica\Test\Util\ApiResponseDouble; @@ -11,7 +10,7 @@ class SavedSearchesTest extends ApiTest { public function test() { - $savedSearch = new SavedSearches(DI::l10n(), ['extension' => 'json']); + $savedSearch = new SavedSearches(['extension' => 'json']); $savedSearch->rawContent(); $result = json_decode(ApiResponseDouble::getOutput()); diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index cf869e30c2..204fc07531 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2021.12-dev\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-11-18 21:26+0100\n" +"POT-Creation-Date: 2021-11-15 19:02-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAMEYou can enter one of your one-time recovery codes in case you lost access " "to your mobile device.
" msgstr "" -#: src/Module/Security/TwoFactor/Recovery.php:98 +#: src/Module/Security/TwoFactor/Recovery.php:86 #: src/Module/Security/TwoFactor/Verify.php:99 #, php-format msgid "" "Don’t have your phone? Enter a two-factor recovery code" msgstr "" -#: src/Module/Security/TwoFactor/Recovery.php:99 +#: src/Module/Security/TwoFactor/Recovery.php:87 msgid "Please enter a recovery code" msgstr "" -#: src/Module/Security/TwoFactor/Recovery.php:100 +#: src/Module/Security/TwoFactor/Recovery.php:88 msgid "Submit recovery code and complete login" msgstr "" @@ -8978,7 +8978,7 @@ msgid "" msgstr "" #: src/Module/Security/TwoFactor/Verify.php:100 -#: src/Module/Settings/TwoFactor/Verify.php:153 +#: src/Module/Settings/TwoFactor/Verify.php:141 msgid "Please enter a code from your authentication app" msgstr "" @@ -9401,82 +9401,82 @@ msgstr "" msgid "select a photo from your photo albums" msgstr "" -#: src/Module/Settings/TwoFactor/AppSpecific.php:64 -#: src/Module/Settings/TwoFactor/Recovery.php:62 -#: src/Module/Settings/TwoFactor/Trusted.php:45 -#: src/Module/Settings/TwoFactor/Verify.php:68 +#: src/Module/Settings/TwoFactor/AppSpecific.php:52 +#: src/Module/Settings/TwoFactor/Recovery.php:50 +#: src/Module/Settings/TwoFactor/Trusted.php:30 +#: src/Module/Settings/TwoFactor/Verify.php:56 msgid "Please enter your password to access this page." msgstr "" -#: src/Module/Settings/TwoFactor/AppSpecific.php:82 +#: src/Module/Settings/TwoFactor/AppSpecific.php:70 msgid "App-specific password generation failed: The description is empty." msgstr "" -#: src/Module/Settings/TwoFactor/AppSpecific.php:85 +#: src/Module/Settings/TwoFactor/AppSpecific.php:73 msgid "" "App-specific password generation failed: This description already exists." msgstr "" -#: src/Module/Settings/TwoFactor/AppSpecific.php:89 +#: src/Module/Settings/TwoFactor/AppSpecific.php:77 msgid "New app-specific password generated." msgstr "" -#: src/Module/Settings/TwoFactor/AppSpecific.php:95 +#: src/Module/Settings/TwoFactor/AppSpecific.php:83 msgid "App-specific passwords successfully revoked." msgstr "" -#: src/Module/Settings/TwoFactor/AppSpecific.php:105 +#: src/Module/Settings/TwoFactor/AppSpecific.php:93 msgid "App-specific password successfully revoked." msgstr "" -#: src/Module/Settings/TwoFactor/AppSpecific.php:126 +#: src/Module/Settings/TwoFactor/AppSpecific.php:114 msgid "Two-factor app-specific passwords" msgstr "" -#: src/Module/Settings/TwoFactor/AppSpecific.php:128 +#: src/Module/Settings/TwoFactor/AppSpecific.php:116 msgid "" "App-specific passwords are randomly generated passwords used instead your " "regular password to authenticate your account on third-party applications " "that don't support two-factor authentication.
" msgstr "" -#: src/Module/Settings/TwoFactor/AppSpecific.php:129 +#: src/Module/Settings/TwoFactor/AppSpecific.php:117 msgid "" "Make sure to copy your new app-specific password now. You won’t be able to " "see it again!" msgstr "" -#: src/Module/Settings/TwoFactor/AppSpecific.php:132 +#: src/Module/Settings/TwoFactor/AppSpecific.php:120 msgid "Description" msgstr "" -#: src/Module/Settings/TwoFactor/AppSpecific.php:133 +#: src/Module/Settings/TwoFactor/AppSpecific.php:121 msgid "Last Used" msgstr "" -#: src/Module/Settings/TwoFactor/AppSpecific.php:134 +#: src/Module/Settings/TwoFactor/AppSpecific.php:122 msgid "Revoke" msgstr "" -#: src/Module/Settings/TwoFactor/AppSpecific.php:135 +#: src/Module/Settings/TwoFactor/AppSpecific.php:123 msgid "Revoke All" msgstr "" -#: src/Module/Settings/TwoFactor/AppSpecific.php:138 +#: src/Module/Settings/TwoFactor/AppSpecific.php:126 msgid "" "When you generate a new app-specific password, you must use it right away, " "it will be shown to you once after you generate it." msgstr "" -#: src/Module/Settings/TwoFactor/AppSpecific.php:139 +#: src/Module/Settings/TwoFactor/AppSpecific.php:127 msgid "Generate new app-specific password" msgstr "" -#: src/Module/Settings/TwoFactor/AppSpecific.php:140 +#: src/Module/Settings/TwoFactor/AppSpecific.php:128 msgid "Friendiqa on my Fairphone 2..." msgstr "" -#: src/Module/Settings/TwoFactor/AppSpecific.php:141 +#: src/Module/Settings/TwoFactor/AppSpecific.php:129 msgid "Generate" msgstr "" @@ -9576,15 +9576,15 @@ msgstr "" msgid "Finish app configuration" msgstr "" -#: src/Module/Settings/TwoFactor/Recovery.php:78 +#: src/Module/Settings/TwoFactor/Recovery.php:66 msgid "New recovery codes successfully generated." msgstr "" -#: src/Module/Settings/TwoFactor/Recovery.php:104 +#: src/Module/Settings/TwoFactor/Recovery.php:92 msgid "Two-factor recovery codes" msgstr "" -#: src/Module/Settings/TwoFactor/Recovery.php:106 +#: src/Module/Settings/TwoFactor/Recovery.php:94 msgid "" "Recovery codes can be used to access your account in the event you lose " "access to your device and cannot receive two-factor authentication codes." @@ -9592,64 +9592,64 @@ msgid "" "don’t have the recovery codes you will lose access to your account.
" msgstr "" -#: src/Module/Settings/TwoFactor/Recovery.php:108 +#: src/Module/Settings/TwoFactor/Recovery.php:96 msgid "" "When you generate new recovery codes, you must copy the new codes. Your old " "codes won’t work anymore." msgstr "" -#: src/Module/Settings/TwoFactor/Recovery.php:109 +#: src/Module/Settings/TwoFactor/Recovery.php:97 msgid "Generate new recovery codes" msgstr "" -#: src/Module/Settings/TwoFactor/Recovery.php:111 +#: src/Module/Settings/TwoFactor/Recovery.php:99 msgid "Next: Verification" msgstr "" -#: src/Module/Settings/TwoFactor/Trusted.php:62 +#: src/Module/Settings/TwoFactor/Trusted.php:49 msgid "Trusted browsers successfully removed." msgstr "" -#: src/Module/Settings/TwoFactor/Trusted.php:72 +#: src/Module/Settings/TwoFactor/Trusted.php:59 msgid "Trusted browser successfully removed." msgstr "" -#: src/Module/Settings/TwoFactor/Trusted.php:109 +#: src/Module/Settings/TwoFactor/Trusted.php:97 msgid "Two-factor Trusted Browsers" msgstr "" -#: src/Module/Settings/TwoFactor/Trusted.php:110 +#: src/Module/Settings/TwoFactor/Trusted.php:98 msgid "" "Trusted browsers are individual browsers you chose to skip two-factor " "authentication to access Friendica. Please use this feature sparingly, as it " "can negate the benefit of two-factor authentication." msgstr "" -#: src/Module/Settings/TwoFactor/Trusted.php:111 +#: src/Module/Settings/TwoFactor/Trusted.php:99 msgid "Device" msgstr "" -#: src/Module/Settings/TwoFactor/Trusted.php:112 +#: src/Module/Settings/TwoFactor/Trusted.php:100 msgid "OS" msgstr "" -#: src/Module/Settings/TwoFactor/Trusted.php:114 +#: src/Module/Settings/TwoFactor/Trusted.php:102 msgid "Trusted" msgstr "" -#: src/Module/Settings/TwoFactor/Trusted.php:115 +#: src/Module/Settings/TwoFactor/Trusted.php:103 msgid "Last Use" msgstr "" -#: src/Module/Settings/TwoFactor/Trusted.php:117 +#: src/Module/Settings/TwoFactor/Trusted.php:105 msgid "Remove All" msgstr "" -#: src/Module/Settings/TwoFactor/Verify.php:90 +#: src/Module/Settings/TwoFactor/Verify.php:78 msgid "Two-factor authentication successfully activated." msgstr "" -#: src/Module/Settings/TwoFactor/Verify.php:123 +#: src/Module/Settings/TwoFactor/Verify.php:111 #, php-format msgid "" "Or you can submit the authentication settings manually:
\n" @@ -9669,53 +9669,53 @@ msgid "" "Please scan this QR Code with your authenticator app and submit the " "provided code.
" msgstr "" -#: src/Module/Settings/TwoFactor/Verify.php:147 +#: src/Module/Settings/TwoFactor/Verify.php:135 #, php-format msgid "" "Or you can open the following URL in your mobile device:
" msgstr "" -#: src/Module/Settings/TwoFactor/Verify.php:154 +#: src/Module/Settings/TwoFactor/Verify.php:142 msgid "Verify code and enable two-factor authentication" msgstr "" -#: src/Module/Settings/UserExport.php:67 +#: src/Module/Settings/UserExport.php:68 msgid "Export account" msgstr "" -#: src/Module/Settings/UserExport.php:67 +#: src/Module/Settings/UserExport.php:68 msgid "" "Export your account info and contacts. Use this to make a backup of your " "account and/or to move it to another server." msgstr "" -#: src/Module/Settings/UserExport.php:68 +#: src/Module/Settings/UserExport.php:69 msgid "Export all" msgstr "" -#: src/Module/Settings/UserExport.php:68 +#: src/Module/Settings/UserExport.php:69 msgid "" "Export your account info, contacts and all your items as json. Could be a " "very big file, and could take a lot of time. Use this to make a full backup " "of your account (photos are not exported)" msgstr "" -#: src/Module/Settings/UserExport.php:69 +#: src/Module/Settings/UserExport.php:70 msgid "Export Contacts to CSV" msgstr "" -#: src/Module/Settings/UserExport.php:69 +#: src/Module/Settings/UserExport.php:70 msgid "" "Export the list of the accounts you are following as CSV file. Compatible to " "e.g. Mastodon." @@ -9730,7 +9730,7 @@ msgstr "" msgid "Exception thrown in %s:%d" msgstr "" -#: src/Module/Tos.php:58 src/Module/Tos.php:92 +#: src/Module/Tos.php:46 src/Module/Tos.php:88 msgid "" "At the time of registration, and for providing communications between the " "user account and their contacts, the user has to provide a display name (pen " @@ -9743,14 +9743,14 @@ msgid "" "settings, it is not necessary for communication." msgstr "" -#: src/Module/Tos.php:59 src/Module/Tos.php:93 +#: src/Module/Tos.php:47 src/Module/Tos.php:89 msgid "" "This data is required for communication and is passed on to the nodes of the " "communication partners and is stored there. Users can enter additional " "private data that may be transmitted to the communication partners accounts." msgstr "" -#: src/Module/Tos.php:60 src/Module/Tos.php:94 +#: src/Module/Tos.php:48 src/Module/Tos.php:90 #, php-format msgid "" "At any point in time a logged in user can export their account data from the " @@ -9760,7 +9760,7 @@ msgid "" "data will also be requested from the nodes of the communication partners." msgstr "" -#: src/Module/Tos.php:63 src/Module/Tos.php:91 +#: src/Module/Tos.php:51 src/Module/Tos.php:87 msgid "Privacy Statement" msgstr ""