From 0acad2066fad447b452a5a79c106c66d50caed9a Mon Sep 17 00:00:00 2001 From: Celestora Date: Thu, 16 Sep 2021 20:24:03 +0300 Subject: [PATCH] Add skinning ability via override_templates themepack option --- Web/Presenters/OpenVKPresenter.php | 7 +++++++ Web/Themes/Themepack.php | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Web/Presenters/OpenVKPresenter.php b/Web/Presenters/OpenVKPresenter.php index e74114ed..c733479b 100644 --- a/Web/Presenters/OpenVKPresenter.php +++ b/Web/Presenters/OpenVKPresenter.php @@ -212,6 +212,13 @@ 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(!is_null(Session::i()->get("_error"))) { $this->template->flashMessage = json_decode(Session::i()->get("_error")); Session::i()->set("_error", NULL); diff --git a/Web/Themes/Themepack.php b/Web/Themes/Themepack.php index f82aa66b..b7718c2b 100644 --- a/Web/Themes/Themepack.php +++ b/Web/Themes/Themepack.php @@ -6,15 +6,17 @@ class Themepack private $id; private $ver; private $inh; + private $tpl; private $meta; private $home; private $enabled; - function __construct(string $id, string $ver, bool $inh, bool $enabled, object $meta) + function __construct(string $id, string $ver, bool $inh, bool $tpl, bool $enabled, object $meta) { $this->id = $id; $this->ver = $ver; $this->inh = $inh; + $this->tpl = $tpl; $this->meta = $meta; $this->home = OPENVK_ROOT . "/themepacks/$id"; $this->enabled = $enabled; @@ -65,6 +67,11 @@ class Themepack return $this->inh; } + function overridesTemplates(): bool + { + return $this->tpl; + } + function fetchStyleSheet(): ?string { $file = "$this->home/stylesheet.css"; @@ -90,6 +97,6 @@ class Themepack if($manifest->openvk_version > Themepacks::THEMPACK_ENGINE_VERSION) throw new Exceptions\IncompatibleThemeException("Theme is built for newer OVK (themeEngine" . $manifest->openvk_version . ")"); - return new static($manifest->id, $manifest->version, (bool) ($manifest->inherit_master ?? true), (bool) ($manifest->enabled ?? true), (object) $manifest->metadata); + return new static($manifest->id, $manifest->version, (bool) ($manifest->inherit_master ?? true), (bool) ($manifest->override_templates ?? false), (bool) ($manifest->enabled ?? true), (object) $manifest->metadata); } }