diff --git a/mod/admin.php b/mod/admin.php index 1cbe24e71..9b8a054c4 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -33,6 +33,23 @@ use Friendica\Util\Network; use Friendica\Util\Strings; use Friendica\Util\Temporal; +/** + * Sets the current theme for theme settings pages. + * + * This needs to be done before the post() or content() methods are called. + * + * @param App $a + */ +function admin_init(App $a) +{ + if ($a->argc > 2 && $a->argv[1] == 'themes') { + $theme = $a->argv[2]; + if (is_file("view/theme/$theme/config.php")) { + $a->setCurrentTheme($theme); + } + } +} + /** * @brief Process send data from the admin panels subpages * @@ -89,15 +106,8 @@ function admin_post(App $a) $theme = $a->argv[2]; if (is_file("view/theme/$theme/config.php")) { - $a->setCurrentTheme($theme); - - require_once "view/theme/$theme/theme.php"; require_once "view/theme/$theme/config.php"; - $init = $theme . '_init'; - if (function_exists($init)) { - $init($a); - } if (function_exists('theme_admin_post')) { theme_admin_post($a); } @@ -2306,16 +2316,8 @@ function admin_page_themes(App $a) $admin_form = ''; if (is_file("view/theme/$theme/config.php")) { - $a->setCurrentTheme($theme); - - require_once "view/theme/$theme/theme.php"; require_once "view/theme/$theme/config.php"; - $init = $theme . "_init"; - if (function_exists($init)) { - $init($a); - } - if (function_exists('theme_admin')) { $admin_form = theme_admin($a); } diff --git a/src/App.php b/src/App.php index 26c93b250..c41cfdc6c 100644 --- a/src/App.php +++ b/src/App.php @@ -1720,13 +1720,7 @@ class App $content = ''; - // Load current theme info after module has been executed as theme could have been set in module - $theme_info_file = 'view/theme/' . $this->getCurrentTheme() . '/theme.php'; - if (file_exists($theme_info_file)) { - require_once $theme_info_file; - } - - // Call module functions + // Initialize module that can set the current theme in the init() method, either directly or via App->profile_uid if ($this->module_loaded) { $this->page['page_title'] = $this->module; $placeholder = ''; @@ -1740,12 +1734,20 @@ class App if (!$this->error) { call_user_func([$this->module_class, 'rawContent']); } + } - if (function_exists(str_replace('-', '_', $this->getCurrentTheme()) . '_init')) { - $func = str_replace('-', '_', $this->getCurrentTheme()) . '_init'; - $func($this); - } + // Load current theme info after module has been initialized as theme could have been set in module + $theme_info_file = 'view/theme/' . $this->getCurrentTheme() . '/theme.php'; + if (file_exists($theme_info_file)) { + require_once $theme_info_file; + } + if (function_exists(str_replace('-', '_', $this->getCurrentTheme()) . '_init')) { + $func = str_replace('-', '_', $this->getCurrentTheme()) . '_init'; + $func($this); + } + + if ($this->module_loaded) { if (! $this->error && $_SERVER['REQUEST_METHOD'] === 'POST') { Core\Addon::callHooks($this->module . '_mod_post', $_POST); call_user_func([$this->module_class, 'post']); diff --git a/view/theme/frio/theme.php b/view/theme/frio/theme.php index 9019a2620..9bae9053a 100644 --- a/view/theme/frio/theme.php +++ b/view/theme/frio/theme.php @@ -22,26 +22,17 @@ use Friendica\Model; use Friendica\Module; use Friendica\Util\Strings; -$frio = 'view/theme/frio'; - -global $frio; - function frio_init(App $a) { + global $frio; + $frio = 'view/theme/frio'; + // disable the events module link in the profile tab $a->theme_events_in_profile = false; $a->videowidth = 622; Renderer::setActiveTemplateEngine('smarty3'); - $baseurl = System::baseUrl(); - - $style = PConfig::get(local_user(), 'frio', 'style'); - - $frio = 'view/theme/frio'; - - global $frio; - // if the device is a mobile device set js is_mobile // variable so the js scripts can use this information if ($a->is_mobile || $a->is_tablet) { @@ -51,10 +42,6 @@ function frio_init(App $a) EOT; } - - if ($style == '') { - $style = Config::get('frio', 'style'); - } } function frio_install()