mirror of
https://github.com/openvk/openvk
synced 2024-12-22 16:42:32 +03:00
Themes: Autodetect Mobile and Desktop platforms
Check out openvk-example.yml to set up default mobile theme (if u have one) I also changed the function's name and added a 'once' boolean arg which means the theme will be set for only one page Also closes #402 and #403
This commit is contained in:
parent
ca64bf210d
commit
8e07a59172
3 changed files with 13 additions and 3 deletions
|
@ -8,6 +8,7 @@ use Latte\Engine as TemplatingEngine;
|
|||
use openvk\Web\Models\Entities\IP;
|
||||
use openvk\Web\Themes\Themepacks;
|
||||
use openvk\Web\Models\Repositories\{IPs, Users, APITokens, Tickets};
|
||||
use WhichBrowser;
|
||||
|
||||
abstract class OpenVKPresenter extends SimplePresenter
|
||||
{
|
||||
|
@ -34,9 +35,10 @@ abstract class OpenVKPresenter extends SimplePresenter
|
|||
]));
|
||||
}
|
||||
|
||||
protected function setTempTheme(string $theme): void
|
||||
protected function setSessionTheme(string $theme, bool $once = false): void
|
||||
{
|
||||
Session::i()->set("_tempTheme", $theme);
|
||||
if(once) Session::i()->set("_tempTheme", $theme);
|
||||
else Session::i()->set("_sessionTheme", $theme);
|
||||
}
|
||||
|
||||
protected function flashFail(string $type, string $title, ?string $message = NULL, ?int $code = NULL, bool $json = false): void
|
||||
|
@ -234,10 +236,17 @@ abstract class OpenVKPresenter extends SimplePresenter
|
|||
{
|
||||
parent::onBeforeRender();
|
||||
|
||||
$whichbrowser = new WhichBrowser\Parser(getallheaders());
|
||||
$mobiletheme = OPENVK_ROOT_CONF["openvk"]["preferences"]["defaultMobileTheme"];
|
||||
if($mobiletheme && $whichbrowser->isType('mobile') && Session::i()->get("_tempTheme") == null)
|
||||
$this->setSessionTheme($mobiletheme);
|
||||
|
||||
$theme = NULL;
|
||||
if(Session::i()->get("_tempTheme")) {
|
||||
$theme = Themepacks::i()[Session::i()->get("_tempTheme", "ovk")];
|
||||
Session::i()->set("_tempTheme", NULL);
|
||||
} else if(Session::i()->get("_sessionTheme")) {
|
||||
$theme = Themepacks::i()[Session::i()->get("_sessionTheme", "ovk")];
|
||||
} else if($this->requestParam("themePreview")) {
|
||||
$theme = Themepacks::i()[$this->requestParam("themePreview")];
|
||||
} else if($this->user->identity !== null && $this->user->identity->getTheme()) {
|
||||
|
|
|
@ -354,7 +354,7 @@ final class UserPresenter extends OpenVKPresenter
|
|||
if (isset(Themepacks::i()[$this->postParam("style")]) || $this->postParam("style") === Themepacks::DEFAULT_THEME_ID)
|
||||
{
|
||||
$user->setStyle($this->postParam("style"));
|
||||
$this->setTempTheme($this->postParam("style"));
|
||||
$this->setSessionTheme($this->postParam("style"));
|
||||
}
|
||||
|
||||
if ($this->postParam("style_avatar") <= 2 && $this->postParam("style_avatar") >= 0)
|
||||
|
|
|
@ -59,6 +59,7 @@ openvk:
|
|||
bellsAndWhistles:
|
||||
fartscroll: false
|
||||
testLabel: false
|
||||
defaultMobileTheme: ""
|
||||
|
||||
telemetry:
|
||||
plausible:
|
||||
|
|
Loading…
Reference in a new issue