Add skinning ability via override_templates themepack option

This commit is contained in:
Celestora 2021-09-16 20:24:03 +03:00
parent dd6b1e3e8a
commit 0acad2066f
2 changed files with 16 additions and 2 deletions

View file

@ -212,6 +212,13 @@ abstract class OpenVKPresenter extends SimplePresenter
{ {
parent::onBeforeRender(); 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"))) { if(!is_null(Session::i()->get("_error"))) {
$this->template->flashMessage = json_decode(Session::i()->get("_error")); $this->template->flashMessage = json_decode(Session::i()->get("_error"));
Session::i()->set("_error", NULL); Session::i()->set("_error", NULL);

View file

@ -6,15 +6,17 @@ class Themepack
private $id; private $id;
private $ver; private $ver;
private $inh; private $inh;
private $tpl;
private $meta; private $meta;
private $home; private $home;
private $enabled; 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->id = $id;
$this->ver = $ver; $this->ver = $ver;
$this->inh = $inh; $this->inh = $inh;
$this->tpl = $tpl;
$this->meta = $meta; $this->meta = $meta;
$this->home = OPENVK_ROOT . "/themepacks/$id"; $this->home = OPENVK_ROOT . "/themepacks/$id";
$this->enabled = $enabled; $this->enabled = $enabled;
@ -65,6 +67,11 @@ class Themepack
return $this->inh; return $this->inh;
} }
function overridesTemplates(): bool
{
return $this->tpl;
}
function fetchStyleSheet(): ?string function fetchStyleSheet(): ?string
{ {
$file = "$this->home/stylesheet.css"; $file = "$this->home/stylesheet.css";
@ -90,6 +97,6 @@ class Themepack
if($manifest->openvk_version > Themepacks::THEMPACK_ENGINE_VERSION) if($manifest->openvk_version > Themepacks::THEMPACK_ENGINE_VERSION)
throw new Exceptions\IncompatibleThemeException("Theme is built for newer OVK (themeEngine" . $manifest->openvk_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);
} }
} }