diff --git a/Web/Presenters/InternalAPIPresenter.php b/Web/Presenters/InternalAPIPresenter.php index a8933639..51f03cd3 100644 --- a/Web/Presenters/InternalAPIPresenter.php +++ b/Web/Presenters/InternalAPIPresenter.php @@ -1,6 +1,7 @@ fail(-32603, "Uncaught " . get_class($ex)); } } + + function renderTimezone() { + if($_SERVER["REQUEST_METHOD"] !== "POST") + exit("ты дебил это метод апи"); + + $sessionOffset = Session::i()->get("_timezoneOffset"); + if(is_numeric($this->postParam("timezone"))) { + $postTZ = intval($this->postParam("timezone")); + if ($postTZ != $sessionOffset || $sessionOffset == null) { + Session::i()->set("_timezoneOffset", $postTZ ? $postTZ : 3 * MINUTE ); + $this->returnJson([ + "success" => 1 // If it's new value + ]); + } else { + $this->returnJson([ + "success" => 2 // If it's the same value (if for some reason server will call this func) + ]); + } + } else { + $this->returnJson([ + "success" => 0 + ]); + } + } } diff --git a/Web/Presenters/OpenVKPresenter.php b/Web/Presenters/OpenVKPresenter.php index 1f2ad294..c232cd91 100755 --- a/Web/Presenters/OpenVKPresenter.php +++ b/Web/Presenters/OpenVKPresenter.php @@ -201,6 +201,7 @@ abstract class OpenVKPresenter extends SimplePresenter $user = Authenticator::i()->getUser(); $this->template->isXmas = intval(date('d')) >= 1 && date('m') == 12 || intval(date('d')) <= 15 && date('m') == 1 ? true : false; + $this->template->isTimezoned = Session::i()->get("_timezoneOffset"); if(!is_null($user)) { $this->user = (object) []; diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index 10ebec28..d410bc84 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -17,6 +17,10 @@ {script "js/l10n.js"} {script "js/openvk.cls.js"} + {if $isTimezoned == null} + {script "js/timezone.js"} + {/if} + {ifset $thisUser} {if $thisUser->getNsfwTolerance() < 2} {css "css/nsfw-posts.css"} diff --git a/Web/routes.yml b/Web/routes.yml index ec53b002..e22f938e 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -9,6 +9,8 @@ routes: handler: "About->rules" - url: "/rpc" handler: "InternalAPI->route" + - url: "/iapi/timezone" + handler: "InternalAPI->timezone" - url: "/support" handler: "Support->index" - url: "/support/tickets" diff --git a/Web/static/js/timezone.js b/Web/static/js/timezone.js new file mode 100755 index 00000000..a85472fd --- /dev/null +++ b/Web/static/js/timezone.js @@ -0,0 +1,7 @@ +// This file is included only when there is no info about timezone in users's chandler session + +xhr = new XMLHttpRequest(); +xhr.open("POST", "/iapi/timezone", true); +xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); +xhr.onload = () => {window.location.reload()}; +xhr.send('timezone=' + new Date().getTimezoneOffset()); diff --git a/bootstrap.php b/bootstrap.php index c4ac5395..5c1fb0d7 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -167,7 +167,8 @@ function ovk_proc_strtrim(string $string, int $length = 0): string function ovk_strftime_safe(string $format, ?int $timestamp = NULL): string { - $str = strftime($format, $timestamp ?? time()); + $sessionOffset = intval(Session::i()->get("_timezoneOffset")); + $str = strftime($format, $timestamp + ($sessionOffset * MINUTE) * -1 ?? time() + ($sessionOffset * MINUTE) * -1); if(PHP_SHLIB_SUFFIX === "dll") { $enc = tr("__WinEncoding"); if($enc === "@__WinEncoding")