From 4a5dfefacc715f002cbc06d95c515a5386679031 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 6 Oct 2019 11:18:51 -0400 Subject: [PATCH] Move theme determination after full module run --- src/App.php | 9 ++++++--- src/App/Module.php | 16 ++-------------- src/App/Page.php | 12 ++++++++++++ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/App.php b/src/App.php index c7305c8c1d..1f623c0cfe 100644 --- a/src/App.php +++ b/src/App.php @@ -587,7 +587,11 @@ class App * * This probably should change to limit the size of this monster method. * - * @param App\Module $module The determined module + * @param App\Module $module The determined module + * @param App\Router $router + * @param PConfiguration $pconfig + * @throws HTTPException\InternalServerErrorException + * @throws \ImagickException */ public function runFrontend(App\Module $module, App\Router $router, PConfiguration $pconfig) { @@ -733,8 +737,7 @@ class App $module = $module->determineClass($this->args, $router, $this->config); // Let the module run it's internal process (init, get, post, ...) - $module->run($this->l10n, $this, $this->logger, $this->getCurrentTheme(), $_SERVER, $_POST); - + $module->run($this->l10n, $this, $this->logger, $_SERVER, $_POST); } catch (HTTPException $e) { ModuleHTTPException::rawContent($e); } diff --git a/src/App/Module.php b/src/App/Module.php index 5ef4093600..9a24c55544 100644 --- a/src/App/Module.php +++ b/src/App/Module.php @@ -138,7 +138,7 @@ class Module * * @return Module The determined module of this call * - * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws \Exception */ public function determineClass(Arguments $args, Router $router, Core\Config\Configuration $config) { @@ -186,13 +186,12 @@ class Module * @param Core\L10n\L10n $l10n The L10n instance * @param App $app The whole Friendica app (for method arguments) * @param LoggerInterface $logger The Friendica logger - * @param string $currentTheme The chosen theme * @param array $server The $_SERVER variable * @param array $post The $_POST variables * * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function run(Core\L10n\L10n $l10n, App $app, LoggerInterface $logger, string $currentTheme, array $server, array $post) + public function run(Core\L10n\L10n $l10n, App $app, LoggerInterface $logger, array $server, array $post) { if ($this->printNotAllowedAddon) { info($l10n->t("You must be logged in to use addons. ")); @@ -232,17 +231,6 @@ class Module // This endpoint doesn't need any theme initialization or other comparable stuff. call_user_func([$this->module_class, 'rawContent']); - // Load current theme info after module has been initialized as theme could have been set in module - $theme_info_file = 'view/theme/' . $currentTheme . '/theme.php'; - if (file_exists($theme_info_file)) { - require_once $theme_info_file; - } - - if (function_exists(str_replace('-', '_', $currentTheme) . '_init')) { - $func = str_replace('-', '_', $currentTheme) . '_init'; - $func($app); - } - if ($server['REQUEST_METHOD'] === 'POST') { Core\Hook::callAll($this->module . '_mod_post', $post); call_user_func([$this->module_class, 'post']); diff --git a/src/App/Page.php b/src/App/Page.php index 0bccbd7396..ea94f9cfef 100644 --- a/src/App/Page.php +++ b/src/App/Page.php @@ -364,6 +364,18 @@ class Page implements ArrayAccess */ $this->initContent($module, $mode); + // Load current theme info after module has been initialized as theme could have been set in module + $currentTheme = $app->getCurrentTheme(); + $theme_info_file = 'view/theme/' . $currentTheme . '/theme.php'; + if (file_exists($theme_info_file)) { + require_once $theme_info_file; + } + + if (function_exists(str_replace('-', '_', $currentTheme) . '_init')) { + $func = str_replace('-', '_', $currentTheme) . '_init'; + $func($app); + } + /* Create the page head after setting the language * and getting any auth credentials. *