mirror of
https://github.com/openvk/openvk
synced 2024-11-11 01:19:53 +03:00
parent
dc20ccb0be
commit
7baa4cf20a
6 changed files with 41 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\Web\Presenters;
|
||||
use MessagePack\MessagePack;
|
||||
use Chandler\Session\Session;
|
||||
|
||||
final class InternalAPIPresenter extends OpenVKPresenter
|
||||
{
|
||||
|
@ -68,4 +69,28 @@ final class InternalAPIPresenter extends OpenVKPresenter
|
|||
$this->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
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) [];
|
||||
|
|
|
@ -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"}
|
||||
|
|
|
@ -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"
|
||||
|
|
7
Web/static/js/timezone.js
Executable file
7
Web/static/js/timezone.js
Executable file
|
@ -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());
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue