diff --git a/Web/Models/Entities/APIToken.php b/Web/Models/Entities/APIToken.php index f5744ec3..4dea1726 100644 --- a/Web/Models/Entities/APIToken.php +++ b/Web/Models/Entities/APIToken.php @@ -48,11 +48,11 @@ class APIToken extends RowModel $this->delete(); } - function save(): void + function save(?bool $log = false): void { if(is_null($this->getRecord())) $this->stateChanges("secret", bin2hex(openssl_random_pseudo_bytes(36))); - parent::save(); + parent::save($log); } } diff --git a/Web/Models/Entities/IP.php b/Web/Models/Entities/IP.php index ecea92ca..141a28c9 100644 --- a/Web/Models/Entities/IP.php +++ b/Web/Models/Entities/IP.php @@ -105,11 +105,11 @@ class IP extends RowModel $this->stateChanges("ip", $ip); } - function save(): void + function save(?bool $log = false): void { if(is_null($this->getRecord())) $this->stateChanges("first_seen", time()); - parent::save(); + parent::save($log); } } diff --git a/Web/Models/Entities/Media.php b/Web/Models/Entities/Media.php index 9377f3e8..648d3564 100644 --- a/Web/Models/Entities/Media.php +++ b/Web/Models/Entities/Media.php @@ -121,14 +121,14 @@ abstract class Media extends Postable $this->stateChanges("hash", $hash); } - function save(): void + function save(?bool $log = false): void { if(!is_null($this->processingPlaceholder) && is_null($this->getRecord())) { $this->stateChanges("processed", 0); $this->stateChanges("last_checked", time()); } - parent::save(); + parent::save($log); } function delete(bool $softly = true): void diff --git a/Web/Models/Entities/PasswordReset.php b/Web/Models/Entities/PasswordReset.php index cf0e73ea..372c63f8 100644 --- a/Web/Models/Entities/PasswordReset.php +++ b/Web/Models/Entities/PasswordReset.php @@ -54,11 +54,11 @@ class PasswordReset extends RowModel } } - function save(): void + function save(?bool $log = false): void { $this->stateChanges("key", base64_encode(openssl_random_pseudo_bytes(46))); $this->stateChanges("timestamp", time()); - parent::save(); + parent::save($log); } } diff --git a/Web/Models/Entities/Poll.php b/Web/Models/Entities/Poll.php index 6f2885b1..7e32505f 100644 --- a/Web/Models/Entities/Poll.php +++ b/Web/Models/Entities/Poll.php @@ -279,12 +279,12 @@ class Poll extends Attachable return $poll; } - function save(): void + function save(?bool $log = false): void { if(empty($this->choicesToPersist)) throw new InvalidStateException; - parent::save(); + parent::save($log); foreach($this->choicesToPersist as $option) { DatabaseConnection::i()->getContext()->table("poll_options")->insert([ "poll" => $this->getId(), diff --git a/Web/Models/Entities/Postable.php b/Web/Models/Entities/Postable.php index b743793f..dae04b4b 100644 --- a/Web/Models/Entities/Postable.php +++ b/Web/Models/Entities/Postable.php @@ -151,7 +151,7 @@ abstract class Postable extends Attachable throw new ISE("Setting virtual id manually is forbidden"); } - function save(): void + function save(?bool $log = false): void { $vref = $this->upperNodeReferenceColumnName; @@ -170,7 +170,7 @@ abstract class Postable extends Attachable $this->stateChanges("edited", time()); } - parent::save(); + parent::save($log); } use Traits\TAttachmentHost; diff --git a/Web/Presenters/OpenVKPresenter.php b/Web/Presenters/OpenVKPresenter.php index 29440ffa..84a9ff54 100755 --- a/Web/Presenters/OpenVKPresenter.php +++ b/Web/Presenters/OpenVKPresenter.php @@ -197,19 +197,23 @@ 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($this->template)) { + $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"); + } $userValidated = 0; $cacheTime = OPENVK_ROOT_CONF["openvk"]["preferences"]["nginxCacheTime"] ?? 0; - + if(!is_null($user)) { $this->user = (object) []; $this->user->raw = $user; $this->user->identity = (new Users)->getByChandlerUser($user); $this->user->id = $this->user->identity->getId(); - $this->template->thisUser = $this->user->identity; - $this->template->userTainted = $user->isTainted(); + if(!is_null($this->template)) { + $this->template->thisUser = $this->user->identity; + $this->template->userTainted = $user->isTainted(); + } if($this->user->identity->isDeleted() && !$this->deactivationTolerant) { if($this->user->identity->isDeactivated()) { @@ -227,7 +231,7 @@ abstract class OpenVKPresenter extends SimplePresenter } exit; } - + if($this->user->identity->isBanned() && !$this->banTolerant) { header("HTTP/1.1 403 Forbidden"); $this->getTemplatingEngine()->render(__DIR__ . "/templates/@banned.xml", [ @@ -237,7 +241,7 @@ abstract class OpenVKPresenter extends SimplePresenter ]); exit; } - + # ето для емейл уже надо (и по хорошему надо бы избавится от повторяющегося кода мда) if(!$this->user->identity->isActivated() && !$this->activationTolerant) { header("HTTP/1.1 403 Forbidden"); @@ -248,7 +252,7 @@ abstract class OpenVKPresenter extends SimplePresenter ]); exit; } - + $userValidated = 1; $cacheTime = 0; # Force no cache if($this->user->identity->onlineStatus() == 0 && !($this->user->identity->isDeleted() || $this->user->identity->isBanned())) { @@ -256,9 +260,10 @@ abstract class OpenVKPresenter extends SimplePresenter $this->user->identity->setClient_name(NULL); $this->user->identity->save(); } - - $this->template->ticketAnsweredCount = (new Tickets)->getTicketsCountByUserId($this->user->id, 1); - if($user->can("write")->model("openvk\Web\Models\Entities\TicketReply")->whichBelongsTo(0)) + + if(!is_null($this->template)) + $this->template->ticketAnsweredCount = (new Tickets)->getTicketsCountByUserId($this->user->id, 1); + if(!is_null($this->template) && $user->can("write")->model("openvk\Web\Models\Entities\TicketReply")->whichBelongsTo(0)) $this->template->helpdeskTicketNotAnsweredCount = (new Tickets)->getTicketCount(0); } @@ -275,8 +280,8 @@ abstract class OpenVKPresenter extends SimplePresenter $this->redirect("/maintenances/"); } } - - $this->template->__isAjax= $this->requestParam("al"); + if(!is_null($this->template)) + $this->template->__isAjax= $this->requestParam("al"); parent::onStartup(); } diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index 03f0362a..2a3b0bc0 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -182,7 +182,7 @@ final class WallPresenter extends OpenVKPresenter $this->template->paginatorConf = (object) [ "count" => $count, "page" => (int) ($_GET["p"] ?? 1), - "amount" => sizeof($posts), + "amount" => sizeof((array) $posts), "perPage" => $pPage, ]; foreach($posts as $post) diff --git a/Web/Presenters/templates/@ajax.xml b/Web/Presenters/templates/@ajax.xml index aee1fd24..856d52c8 100644 --- a/Web/Presenters/templates/@ajax.xml +++ b/Web/Presenters/templates/@ajax.xml @@ -23,7 +23,7 @@ style="position: absolute; top: 40%; left: 50%; background: #4C4C4C; padding: 20px 30px; border-radius: 3px; opacity: 0.8;"/> - +