diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index 95ee1c48..b6a5a824 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -216,12 +216,15 @@ class User extends RowModel function getCoins(): int { + if(!OPENVK_ROOT_CONF["openvk"]["preferences"]["commerce"]) + return 0; + return $this->getRecord()->coins; } function getRating(): int { - return $this->getRecord()->rating; + return OPENVK_ROOT_CONF["openvk"]["preferences"]["commerce"] ? $this->getRecord()->rating : 0; } function getReputation(): int @@ -400,11 +403,9 @@ class User extends RowModel $total = max(100 - $incompleteness + $this->getRating(), 0); if(ovkGetQuirk("profile.rating-bar-behaviour") === 0) if ($total >= 100) - $percent = round(($total / 10**strlen(strval($total))) * 100, 0); - else - $percent = min($total, 100); + $percent = round(($total / 10**strlen(strval($total))) * 100, 0); else - $percent = min($total, 100); + $percent = min($total, 100); return (object) [ "total" => $total, diff --git a/Web/Presenters/AdminPresenter.php b/Web/Presenters/AdminPresenter.php index 98003e6b..c180302a 100644 --- a/Web/Presenters/AdminPresenter.php +++ b/Web/Presenters/AdminPresenter.php @@ -20,6 +20,12 @@ final class AdminPresenter extends OpenVKPresenter parent::__construct(); } + private function warnIfNoCommerce(): void + { + if(!OPENVK_ROOT_CONF["openvk"]["preferences"]["commerce"]) + $this->flash("warn", "Коммерция отключена системным администратором", "Настройки ваучеров и подарков будут сохранены, но не будут оказывать никакого влияния."); + } + private function searchResults(object $repo, &$count) { $query = $this->queryParam("q") ?? ""; @@ -112,12 +118,16 @@ final class AdminPresenter extends OpenVKPresenter function renderVouchers(): void { + $this->warnIfNoCommerce(); + $this->template->count = $this->vouchers->size(); $this->template->vouchers = iterator_to_array($this->vouchers->enumerate((int) ($this->queryParam("p") ?? 1))); } function renderVoucher(int $id): void { + $this->warnIfNoCommerce(); + $voucher = NULL; $this->template->form = (object) []; if($id === 0) { @@ -163,12 +173,16 @@ final class AdminPresenter extends OpenVKPresenter function renderGiftCategories(): void { + $this->warnIfNoCommerce(); + $this->template->act = $this->queryParam("act") ?? "list"; $this->template->categories = iterator_to_array($this->gifts->getCategories((int) ($this->queryParam("p") ?? 1), NULL, $this->template->count)); } function renderGiftCategory(string $slug, int $id): void { + $this->warnIfNoCommerce(); + $cat; $gen = false; if($id !== 0) { @@ -222,6 +236,8 @@ final class AdminPresenter extends OpenVKPresenter function renderGifts(string $catSlug, int $catId): void { + $this->warnIfNoCommerce(); + $cat = $this->gifts->getCat($catId); if(!$cat) $this->notFound(); @@ -234,6 +250,8 @@ final class AdminPresenter extends OpenVKPresenter function renderGift(int $id): void { + $this->warnIfNoCommerce(); + $gift = $this->gifts->get($id); $act = $this->queryParam("act") ?? "edit"; switch($act) { diff --git a/Web/Presenters/GiftsPresenter.php b/Web/Presenters/GiftsPresenter.php index 9b07702e..c4c7e9d8 100644 --- a/Web/Presenters/GiftsPresenter.php +++ b/Web/Presenters/GiftsPresenter.php @@ -129,4 +129,12 @@ final class GiftsPresenter extends OpenVKPresenter header("Content-Type: image/png"); exit($image); } + + function onStartup(): void + { + if(!OPENVK_ROOT_CONF["openvk"]["preferences"]["commerce"]) + $this->flashFail("err", tr("error"), tr("feature_disabled")); + + parent::onStartup(); + } } diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index 12245671..01a2431d 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -225,6 +225,9 @@ final class UserPresenter extends OpenVKPresenter if(!$id) $this->notFound(); + if(in_array($this->queryParam("act"), ["finance", "finance.top-up"]) && !OPENVK_ROOT_CONF["openvk"]["preferences"]["commerce"]) + $this->flashFail("err", tr("error"), tr("feature_disabled")); + $user = $this->users->get($id); if($_SERVER["REQUEST_METHOD"] === "POST") { $this->willExecuteWriteAction(); diff --git a/Web/Presenters/templates/Admin/@layout.xml b/Web/Presenters/templates/Admin/@layout.xml index 8b9ebd42..3186353d 100644 --- a/Web/Presenters/templates/Admin/@layout.xml +++ b/Web/Presenters/templates/Admin/@layout.xml @@ -140,6 +140,10 @@ {/ifset} + {ifset preHeader} + {include preHeader} + {/ifset} +
diff --git a/Web/Presenters/templates/User/Settings.xml b/Web/Presenters/templates/User/Settings.xml index 812d8d5e..410cafc1 100644 --- a/Web/Presenters/templates/User/Settings.xml +++ b/Web/Presenters/templates/User/Settings.xml @@ -20,7 +20,7 @@ -
+
diff --git a/Web/Presenters/templates/User/View.xml b/Web/Presenters/templates/User/View.xml index f7831809..c2576ac6 100644 --- a/Web/Presenters/templates/User/View.xml +++ b/Web/Presenters/templates/User/View.xml @@ -84,7 +84,7 @@ {/if} - {_send_gift} + {_send_gift} {var subStatus = $user->getSubscriptionStatus($thisUser)} {if $subStatus === 0} @@ -152,7 +152,7 @@ {/if}

-
+
{_gifts}
diff --git a/openvk-example.yml b/openvk-example.yml index 2cbe77f6..b644d64d 100644 --- a/openvk-example.yml +++ b/openvk-example.yml @@ -37,6 +37,7 @@ openvk: maxSize: 60000 processingLimit: 3000 emojiProcessingLimit: 1000 + commerce: false menu: links: