diff --git a/mod/admin.php b/mod/admin.php index b906ad7d05..c0ad281d3b 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -89,12 +89,10 @@ function admin_post(App $a) $theme = $a->argv[2]; if (is_file("view/theme/$theme/config.php")) { - $orig_theme = Renderer::$theme; - $orig_page = $a->page; - $orig_session_theme = $_SESSION['theme']; + $a->setCurrentTheme($theme); + require_once "view/theme/$theme/theme.php"; require_once "view/theme/$theme/config.php"; - $_SESSION['theme'] = $theme; $init = $theme . '_init'; if (function_exists($init)) { @@ -103,17 +101,13 @@ function admin_post(App $a) if (function_exists('theme_admin_post')) { theme_admin_post($a); } - - $_SESSION['theme'] = $orig_session_theme; - Renderer::$theme = $orig_theme; - $a->page = $orig_page; } info(L10n::t('Theme settings updated.')); if ($a->isAjax()) { return; } - $return_path = 'admin/themes/' . $theme; + $return_path = 'admin/themes/' . $theme . (!empty($_GET['mode']) ? '?mode=' . $_GET['mode'] : ''); break; case 'tos': admin_page_tos_post($a); @@ -2312,12 +2306,10 @@ function admin_page_themes(App $a) $admin_form = ''; if (is_file("view/theme/$theme/config.php")) { - $orig_theme = Renderer::$theme; - $orig_page = $a->page; - $orig_session_theme = $_SESSION['theme']; + $a->setCurrentTheme($theme); + require_once "view/theme/$theme/theme.php"; require_once "view/theme/$theme/config.php"; - $_SESSION['theme'] = $theme; $init = $theme . "_init"; if (function_exists($init)) { @@ -2327,10 +2319,6 @@ function admin_page_themes(App $a) if (function_exists('theme_admin')) { $admin_form = theme_admin($a); } - - $_SESSION['theme'] = $orig_session_theme; - Renderer::$theme = $orig_theme; - $a->page = $orig_page; } $screenshot = [Theme::getScreenshot($theme), L10n::t('Screenshot')]; @@ -2345,7 +2333,7 @@ function admin_page_themes(App $a) '$toggle' => L10n::t('Toggle'), '$settings' => L10n::t('Settings'), '$baseurl' => System::baseUrl(true), - '$addon' => $theme, + '$addon' => $theme . (!empty($_GET['mode']) ? '?mode=' . $_GET['mode'] : ''), '$status' => $status, '$action' => $action, '$info' => Theme::getInfo($theme), diff --git a/src/App.php b/src/App.php index 57d61d04bb..1045c413dc 100644 --- a/src/App.php +++ b/src/App.php @@ -1360,14 +1360,18 @@ class App return ''; } - //// @TODO Compute the current theme only once (this behavior has - /// already been implemented, but it didn't work well - - /// https://github.com/friendica/friendica/issues/5092) - $this->computeCurrentTheme(); + if (!$this->currentTheme) { + $this->computeCurrentTheme(); + } return $this->currentTheme; } + public function setCurrentTheme($theme) + { + $this->currentTheme = $theme; + } + /** * Computes the current theme name based on the node settings, the user settings and the device type * @@ -1706,16 +1710,7 @@ class App } } - // Load current theme info - $theme_info_file = 'view/theme/' . $this->getCurrentTheme() . '/theme.php'; - if (file_exists($theme_info_file)) { - require_once $theme_info_file; - } - - // initialise content region - if ($this->getMode()->isNormal()) { - Core\Addon::callHooks('page_content_top', $this->page['content']); - } + $content = ''; // Call module functions if ($this->module_loaded) { @@ -1748,20 +1743,28 @@ class App } if (! $this->error) { - $arr = ['content' => $this->page['content']]; + $arr = ['content' => $content]; Core\Addon::callHooks($this->module . '_mod_content', $arr); - $this->page['content'] = $arr['content']; + $content = $arr['content']; $arr = ['content' => call_user_func([$this->module_class, 'content'])]; Core\Addon::callHooks($this->module . '_mod_aftercontent', $arr); - $this->page['content'] .= $arr['content']; - } - - if (function_exists(str_replace('-', '_', $this->getCurrentTheme()) . '_content_loaded')) { - $func = str_replace('-', '_', $this->getCurrentTheme()) . '_content_loaded'; - $func($this); + $content .= $arr['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; + } + + // initialise content region + if ($this->getMode()->isNormal()) { + Core\Addon::callHooks('page_content_top', $this->page['content']); + } + + $this->page['content'] .= $content; + /* Create the page head after setting the language * and getting any auth credentials. * diff --git a/view/templates/admin/addon_details.tpl b/view/templates/admin/addon_details.tpl index f4e8e5c23c..7479b1385e 100644 --- a/view/templates/admin/addon_details.tpl +++ b/view/templates/admin/addon_details.tpl @@ -23,7 +23,7 @@ {{if $admin_form}}