From e73857cdc31cc77e1ed417992bfb37cd73b7c9d2 Mon Sep 17 00:00:00 2001 From: Celestora Date: Sun, 12 Dec 2021 15:11:44 +0200 Subject: [PATCH] Make "themePreview" work correctly with themes that override templates --- Web/Presenters/OpenVKPresenter.php | 32 ++++++++++++------------------ 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/Web/Presenters/OpenVKPresenter.php b/Web/Presenters/OpenVKPresenter.php index 6caf21d5..eed07884 100755 --- a/Web/Presenters/OpenVKPresenter.php +++ b/Web/Presenters/OpenVKPresenter.php @@ -34,10 +34,10 @@ abstract class OpenVKPresenter extends SimplePresenter ])); } - protected function setTempTheme(string $theme): void - { - Session::i()->set("_tempTheme", $theme); - } + protected function setTempTheme(string $theme): void + { + Session::i()->set("_tempTheme", $theme); + } protected function flashFail(string $type, string $title, ?string $message = NULL, ?int $code = NULL): void { @@ -221,25 +221,19 @@ abstract class OpenVKPresenter extends SimplePresenter { parent::onBeforeRender(); - if(!is_null($this->user)) { - $theme = $this->user->identity->getTheme(); - if(!is_null($theme) && $theme->overridesTemplates()) { - $this->template->_templatePath = $theme->getBaseDir() . "/tpl"; - } - } + if(Session::i()->get("_tempTheme")) + $theme = Themepacks::i()[Session::i()->get("_tempTheme", "ovk")]; + else if($this->requestParam("themePreview")) + $theme = Themepacks::i()[$this->requestParam("themePreview")]; + else if($this->user->identity !== null && $this->user->identity->getTheme()) + $theme = $this->user->identity->getTheme(); + + if(!is_null($theme) && $theme->overridesTemplates()) + $this->template->_templatePath = $theme->getBaseDir() . "/tpl"; if(!is_null(Session::i()->get("_error"))) { $this->template->flashMessage = json_decode(Session::i()->get("_error")); Session::i()->set("_error", NULL); } - - if(Session::i()->get("_tempTheme")) - $this->template->theme = Themepacks::i()[Session::i()->get("_tempTheme", "ovk")]; - else if($this->requestParam("themePreview")) - $this->template->theme = Themepacks::i()[$this->requestParam("themePreview")]; - else if($this->user->identity !== null && $this->user->identity->getTheme()) - $this->template->theme = $this->user->identity->getTheme(); - - // Знаю, каша ебаная, целестора рефактор всё равно сделает :))) } }