From af7b852d04eb2a255eafb38a9dae5d554be1a1bb Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 19 Jan 2019 21:52:43 -0500 Subject: [PATCH 1/5] Insert theme init after module init but before post/content --- src/App.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/App.php b/src/App.php index 26c93b250..bc8b444db 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 = ''; @@ -1734,18 +1728,26 @@ class App Core\Addon::callHooks($this->module . '_mod_init', $placeholder); call_user_func([$this->module_class, 'init']); + } + // 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) { // "rawContent" is especially meant for technical endpoints. // This endpoint doesn't need any theme initialization or other comparable stuff. 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); - } - if (! $this->error && $_SERVER['REQUEST_METHOD'] === 'POST') { Core\Addon::callHooks($this->module . '_mod_post', $_POST); call_user_func([$this->module_class, 'post']); From 6aa0899d6788b2360250d63fc2ad4d7a6e0c339f Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 19 Jan 2019 21:53:17 -0500 Subject: [PATCH 2/5] Move theme selection to init() in mod/admin --- mod/admin.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index 1cbe24e71..24b8b29a1 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -33,6 +33,21 @@ 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() 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 +104,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 +2314,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); } From 765784aad3e21d0cf24aa92273fe35b27d29cc26 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 19 Jan 2019 21:54:10 -0500 Subject: [PATCH 3/5] [frio] Remove unused code in frio_init() --- view/theme/frio/theme.php | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) 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() From 89cb1b276d675e992e201c68cb2a69c0c8bd651e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 19 Jan 2019 22:03:49 -0500 Subject: [PATCH 4/5] Move rawContent before theme initialization --- src/App.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/App.php b/src/App.php index bc8b444db..c41cfdc6c 100644 --- a/src/App.php +++ b/src/App.php @@ -1728,6 +1728,12 @@ class App Core\Addon::callHooks($this->module . '_mod_init', $placeholder); call_user_func([$this->module_class, 'init']); + + // "rawContent" is especially meant for technical endpoints. + // This endpoint doesn't need any theme initialization or other comparable stuff. + if (!$this->error) { + call_user_func([$this->module_class, 'rawContent']); + } } // Load current theme info after module has been initialized as theme could have been set in module @@ -1742,12 +1748,6 @@ class App } if ($this->module_loaded) { - // "rawContent" is especially meant for technical endpoints. - // This endpoint doesn't need any theme initialization or other comparable stuff. - if (!$this->error) { - call_user_func([$this->module_class, 'rawContent']); - } - if (! $this->error && $_SERVER['REQUEST_METHOD'] === 'POST') { Core\Addon::callHooks($this->module . '_mod_post', $_POST); call_user_func([$this->module_class, 'post']); From f4502af2398a2a86b801838cf06f56cac2f4d9d7 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 19 Jan 2019 22:04:01 -0500 Subject: [PATCH 5/5] Fix docblock in mod/admin.php --- mod/admin.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mod/admin.php b/mod/admin.php index 24b8b29a1..9b8a054c4 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -34,7 +34,9 @@ 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() are called + * Sets the current theme for theme settings pages. + * + * This needs to be done before the post() or content() methods are called. * * @param App $a */