diff --git a/Web/Presenters/AppsPresenter.php b/Web/Presenters/AppsPresenter.php index 02fb8922..8dcfb8a4 100644 --- a/Web/Presenters/AppsPresenter.php +++ b/Web/Presenters/AppsPresenter.php @@ -6,7 +6,7 @@ use openvk\Web\Models\Repositories\Applications; final class AppsPresenter extends OpenVKPresenter { private $apps; - + protected $presenterName = "apps"; function __construct(Applications $apps) { $this->apps = $apps; diff --git a/Web/Presenters/CommentPresenter.php b/Web/Presenters/CommentPresenter.php index cbdac84e..0429b32e 100644 --- a/Web/Presenters/CommentPresenter.php +++ b/Web/Presenters/CommentPresenter.php @@ -6,6 +6,7 @@ use openvk\Web\Models\Repositories\{Comments, Clubs}; final class CommentPresenter extends OpenVKPresenter { + protected $presenterName = "comment"; private $models = [ "posts" => "openvk\\Web\\Models\\Repositories\\Posts", "photos" => "openvk\\Web\\Models\\Repositories\\Photos", diff --git a/Web/Presenters/GiftsPresenter.php b/Web/Presenters/GiftsPresenter.php index b99e5ba9..8f59bdcb 100644 --- a/Web/Presenters/GiftsPresenter.php +++ b/Web/Presenters/GiftsPresenter.php @@ -7,6 +7,7 @@ final class GiftsPresenter extends OpenVKPresenter { private $gifts; private $users; + protected $presenterName = "gifts"; function __construct(Gifts $gifts, Users $users) { diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index a83386db..00d74c2e 100644 --- a/Web/Presenters/GroupPresenter.php +++ b/Web/Presenters/GroupPresenter.php @@ -8,7 +8,8 @@ use Chandler\Security\Authenticator; final class GroupPresenter extends OpenVKPresenter { private $clubs; - + protected $presenterName = "group"; + function __construct(Clubs $clubs) { $this->clubs = $clubs; diff --git a/Web/Presenters/MaintenancePresenter.php b/Web/Presenters/MaintenancePresenter.php new file mode 100644 index 00000000..d4a5a6ef --- /dev/null +++ b/Web/Presenters/MaintenancePresenter.php @@ -0,0 +1,35 @@ +flashFail("err", tr("error"), tr("forbidden")); + + $this->template->name = [ + "photos" => tr("my_photos"), + "videos" => tr("my_videos"), + "messenger" => tr("my_messages"), + "user" => tr("users"), + "group" => tr("my_groups"), + "comment" => tr("comments"), + "gifts" => tr("gifts"), + "apps" => tr("apps"), + "notes" => tr("my_notes"), + "notification" => tr("my_feedback"), + "support" => tr("menu_support"), + "topics" => tr("topics") + ][$name] ?? $name; + } + + function renderAll(): void + { + + } +} diff --git a/Web/Presenters/MessengerPresenter.php b/Web/Presenters/MessengerPresenter.php index cea440ba..593d9245 100644 --- a/Web/Presenters/MessengerPresenter.php +++ b/Web/Presenters/MessengerPresenter.php @@ -9,11 +9,13 @@ final class MessengerPresenter extends OpenVKPresenter { private $messages; private $signaler; - + protected $presenterName = "messenger"; + function __construct(Messages $messages) { $this->messages = $messages; $this->signaler = SignalManager::i(); + parent::__construct(); } @@ -30,7 +32,7 @@ final class MessengerPresenter extends OpenVKPresenter function renderIndex(): void { $this->assertUserLoggedIn(); - + if(isset($_GET["sel"])) $this->pass("openvk!Messenger->app", $_GET["sel"]); diff --git a/Web/Presenters/NotesPresenter.php b/Web/Presenters/NotesPresenter.php index 363d814c..50437ad7 100644 --- a/Web/Presenters/NotesPresenter.php +++ b/Web/Presenters/NotesPresenter.php @@ -6,7 +6,8 @@ use openvk\Web\Models\Entities\Note; final class NotesPresenter extends OpenVKPresenter { private $notes; - + protected $presenterName = "notes"; + function __construct(Notes $notes) { $this->notes = $notes; diff --git a/Web/Presenters/NotificationPresenter.php b/Web/Presenters/NotificationPresenter.php index d12f27f0..3bd7a321 100644 --- a/Web/Presenters/NotificationPresenter.php +++ b/Web/Presenters/NotificationPresenter.php @@ -3,6 +3,8 @@ namespace openvk\Web\Presenters; final class NotificationPresenter extends OpenVKPresenter { + protected $presenterName = "notification"; + function renderFeed(): void { $this->assertUserLoggedIn(); diff --git a/Web/Presenters/OpenVKPresenter.php b/Web/Presenters/OpenVKPresenter.php index 2a19fa03..5b7908a8 100755 --- a/Web/Presenters/OpenVKPresenter.php +++ b/Web/Presenters/OpenVKPresenter.php @@ -17,7 +17,8 @@ abstract class OpenVKPresenter extends SimplePresenter protected $deactivationTolerant = false; protected $errorTemplate = "@error"; protected $user = NULL; - + protected $presenterName; + private function calculateQueryString(array $data): string { $rawUrl = "tcp+stratum://fakeurl.net$_SERVER[REQUEST_URI]"; #HTTP_HOST can be tainted @@ -196,12 +197,13 @@ abstract class OpenVKPresenter extends SimplePresenter function onStartup(): void { $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"); - + $userValidated = 0; $cacheTime = OPENVK_ROOT_CONF["openvk"]["preferences"]["nginxCacheTime"] ?? 0; + if(!is_null($user)) { $this->user = (object) []; $this->user->raw = $user; @@ -226,7 +228,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", [ @@ -247,23 +249,33 @@ 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())) { $this->user->identity->setOnline(time()); $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)) $this->template->helpdeskTicketNotAnsweredCount = (new Tickets)->getTicketCount(0); } - + header("X-OpenVK-User-Validated: $userValidated"); header("X-Accel-Expires: $cacheTime"); setlocale(LC_TIME, ...(explode(";", tr("__locale")))); - + + if (!OPENVK_ROOT_CONF["openvk"]["preferences"]["maintenanceMode"]["all"]) { + if (OPENVK_ROOT_CONF["openvk"]["preferences"]["maintenanceMode"][$this->presenterName]) { + $this->pass("openvk!Maintenance->section", $this->presenterName); + } + } else { + if ($this->presenterName != "maintenance") { + $this->redirect("/maintenances/"); + } + } + parent::onStartup(); } diff --git a/Web/Presenters/PhotosPresenter.php b/Web/Presenters/PhotosPresenter.php index eacf76d4..3dd2a774 100644 --- a/Web/Presenters/PhotosPresenter.php +++ b/Web/Presenters/PhotosPresenter.php @@ -9,7 +9,8 @@ final class PhotosPresenter extends OpenVKPresenter private $users; private $photos; private $albums; - + protected $presenterName = "photos"; + function __construct(Photos $photos, Albums $albums, Users $users) { $this->users = $users; diff --git a/Web/Presenters/SupportPresenter.php b/Web/Presenters/SupportPresenter.php index 99a1908d..8f4fd7d3 100644 --- a/Web/Presenters/SupportPresenter.php +++ b/Web/Presenters/SupportPresenter.php @@ -11,6 +11,7 @@ final class SupportPresenter extends OpenVKPresenter { protected $banTolerant = true; protected $deactivationTolerant = true; + protected $presenterName = "support"; private $tickets; private $comments; diff --git a/Web/Presenters/TopicsPresenter.php b/Web/Presenters/TopicsPresenter.php index 6dd1ec6c..528b51ad 100644 --- a/Web/Presenters/TopicsPresenter.php +++ b/Web/Presenters/TopicsPresenter.php @@ -7,7 +7,8 @@ final class TopicsPresenter extends OpenVKPresenter { private $topics; private $clubs; - + protected $presenterName = "topics"; + function __construct(Topics $topics, Clubs $clubs) { $this->topics = $topics; diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index bfda79e8..48ebb660 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -15,12 +15,13 @@ use Nette\Database\UniqueConstraintViolationException; final class UserPresenter extends OpenVKPresenter { private $users; - public $deactivationTolerant = false; + protected $presenterName = "user"; + function __construct(Users $users) { $this->users = $users; - + parent::__construct(); } diff --git a/Web/Presenters/VideosPresenter.php b/Web/Presenters/VideosPresenter.php index e7b24344..6db7771d 100644 --- a/Web/Presenters/VideosPresenter.php +++ b/Web/Presenters/VideosPresenter.php @@ -8,7 +8,8 @@ final class VideosPresenter extends OpenVKPresenter { private $videos; private $users; - + protected $presenterName = "videos"; + function __construct(Videos $videos, Users $users) { $this->videos = $videos; diff --git a/Web/Presenters/templates/Maintenance/All.xml b/Web/Presenters/templates/Maintenance/All.xml new file mode 100644 index 00000000..e8f88e2c --- /dev/null +++ b/Web/Presenters/templates/Maintenance/All.xml @@ -0,0 +1,20 @@ +{extends "../@layout.xml"} + +{block title} + {_global_maintenance} +{/block} + +{block header} + {_global_maintenance} +{/block} + +{block content} +
+
+ + + {_undergoing_global_maintenance} + +
+
+{/block} diff --git a/Web/Presenters/templates/Maintenance/Section.xml b/Web/Presenters/templates/Maintenance/Section.xml new file mode 100644 index 00000000..9bdb0965 --- /dev/null +++ b/Web/Presenters/templates/Maintenance/Section.xml @@ -0,0 +1,20 @@ +{extends "../@layout.xml"} + +{block title} + {_section_maintenance} +{/block} + +{block header} + {_section_maintenance} +{/block} + +{block content} +
+
+ + + {tr("undergoing_section_maintenance", $name)|noescape} + +
+
+{/block} diff --git a/Web/di.yml b/Web/di.yml index f18654b4..f4b04650 100644 --- a/Web/di.yml +++ b/Web/di.yml @@ -44,3 +44,4 @@ services: - openvk\Web\Models\Repositories\Applications - openvk\Web\Models\Repositories\ContentSearchRepository - openvk\Web\Models\Repositories\BannedLinks + - openvk\Web\Presenters\MaintenancePresenter diff --git a/Web/routes.yml b/Web/routes.yml index 0ee44444..d6f63a11 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -331,3 +331,7 @@ routes: handler: "UnknownTextRouteStrategy->delegate" placeholders: shortCode: "[a-z][a-z0-9\\@\\.\\_]{0,30}[a-z0-9]" + - url: "/maintenance/{text}" + handler: "Maintenance->section" + - url: "/maintenances/" + handler: "Maintenance->all" diff --git a/locales/en.strings b/locales/en.strings index 2e3461b7..240dd5d0 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -1147,3 +1147,12 @@ "url_is_banned_default_reason" = "The link you are trying to open may lead you to a site that was created for the purpose of deceiving users with the intention of gaining profit."; "url_is_banned_title" = "Link to a suspicious site"; "url_is_banned_proceed" = "Follow the link"; + +/* Maintenance */ + +"global_maintenance" = "Undergoing maintenance"; +"section_maintenance" = "The section is not available"; +"undergoing_global_maintenance" = "Unfortunately, the instance is now closed for technical work. We are already working on troubleshooting. Please try to come back later."; +"undergoing_section_maintenance" = "Unfortunately, the $1 section is temporarily unavailable. We are already working on troubleshooting. Please try to come back later."; + +"topics" = "Topics"; diff --git a/locales/ru.strings b/locales/ru.strings index 68f6d69f..2f176233 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -1208,3 +1208,12 @@ "url_is_banned_default_reason" = "Ссылка, по которой вы попытались перейти, может вести на сайт, который был создан с целью обмана пользователей и получения за счёт этого прибыли."; "url_is_banned_title" = "Ссылка на подозрительный сайт"; "url_is_banned_proceed" = "Перейти по ссылке"; + +/* Maintenance */ + +"global_maintenance" = "Технические работы"; +"section_maintenance" = "Раздел недоступен"; +"undergoing_global_maintenance" = "К сожалению, сейчас инстанс закрыт на технические работы. Мы уже работаем над устранением неисправностей. Пожалуйста, попробуйте зайти позже."; +"undergoing_section_maintenance" = "К сожалению, раздел $1 временно недоступен. Мы уже работаем над устранением неисправностей. Пожалуйста, попробуйте зайти позже."; + +"topics" = "Темы"; diff --git a/openvk-example.yml b/openvk-example.yml index 64b7b38c..47eacd24 100644 --- a/openvk-example.yml +++ b/openvk-example.yml @@ -58,6 +58,20 @@ openvk: susLinks: warnings: true showReason: true + maintenanceMode: + all: false + photos: false + videos: false + messenger: false + user: false + group: false + comment: false + gifts: false + apps: false + notes: false + notification: false + support: false + topics: false ton: enabled: false address: "🅿"