mirror of
https://github.com/openvk/openvk
synced 2024-11-11 01:19:53 +03:00
Maintenance (#719)
This commit is contained in:
parent
ed7faa4a16
commit
753be2aaff
21 changed files with 155 additions and 18 deletions
|
@ -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;
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -7,6 +7,7 @@ final class GiftsPresenter extends OpenVKPresenter
|
|||
{
|
||||
private $gifts;
|
||||
private $users;
|
||||
protected $presenterName = "gifts";
|
||||
|
||||
function __construct(Gifts $gifts, Users $users)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
35
Web/Presenters/MaintenancePresenter.php
Normal file
35
Web/Presenters/MaintenancePresenter.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace openvk\Web\Presenters;
|
||||
|
||||
final class MaintenancePresenter extends OpenVKPresenter
|
||||
{
|
||||
protected $presenterName = "maintenance";
|
||||
|
||||
function renderSection(string $name): void
|
||||
{
|
||||
if(!OPENVK_ROOT_CONF["openvk"]["preferences"]["maintenanceMode"][$name])
|
||||
$this->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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -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"]);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -3,6 +3,8 @@ namespace openvk\Web\Presenters;
|
|||
|
||||
final class NotificationPresenter extends OpenVKPresenter
|
||||
{
|
||||
protected $presenterName = "notification";
|
||||
|
||||
function renderFeed(): void
|
||||
{
|
||||
$this->assertUserLoggedIn();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -11,6 +11,7 @@ final class SupportPresenter extends OpenVKPresenter
|
|||
{
|
||||
protected $banTolerant = true;
|
||||
protected $deactivationTolerant = true;
|
||||
protected $presenterName = "support";
|
||||
|
||||
private $tickets;
|
||||
private $comments;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
20
Web/Presenters/templates/Maintenance/All.xml
Normal file
20
Web/Presenters/templates/Maintenance/All.xml
Normal file
|
@ -0,0 +1,20 @@
|
|||
{extends "../@layout.xml"}
|
||||
|
||||
{block title}
|
||||
{_global_maintenance}
|
||||
{/block}
|
||||
|
||||
{block header}
|
||||
{_global_maintenance}
|
||||
{/block}
|
||||
|
||||
{block content}
|
||||
<div class="container_gray">
|
||||
<center style="background: white;border: #DEDEDE solid 1px;">
|
||||
<img src="/assets/packages/static/openvk/img/oof.apng" style="width: 20%;" />
|
||||
<span style="color: #707070;margin: 10px 0;display: block;">
|
||||
{_undergoing_global_maintenance}
|
||||
</span>
|
||||
</center>
|
||||
</div>
|
||||
{/block}
|
20
Web/Presenters/templates/Maintenance/Section.xml
Normal file
20
Web/Presenters/templates/Maintenance/Section.xml
Normal file
|
@ -0,0 +1,20 @@
|
|||
{extends "../@layout.xml"}
|
||||
|
||||
{block title}
|
||||
{_section_maintenance}
|
||||
{/block}
|
||||
|
||||
{block header}
|
||||
{_section_maintenance}
|
||||
{/block}
|
||||
|
||||
{block content}
|
||||
<div class="container_gray">
|
||||
<center style="background: white;border: #DEDEDE solid 1px;">
|
||||
<img src="/assets/packages/static/openvk/img/oof.apng" style="width: 20%;" />
|
||||
<span style="color: #707070;margin: 10px 0;display: block;">
|
||||
{tr("undergoing_section_maintenance", $name)|noescape}
|
||||
</span>
|
||||
</center>
|
||||
</div>
|
||||
{/block}
|
|
@ -44,3 +44,4 @@ services:
|
|||
- openvk\Web\Models\Repositories\Applications
|
||||
- openvk\Web\Models\Repositories\ContentSearchRepository
|
||||
- openvk\Web\Models\Repositories\BannedLinks
|
||||
- openvk\Web\Presenters\MaintenancePresenter
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 <b>$1</b> section is temporarily unavailable. We are already working on troubleshooting. Please try to come back later.";
|
||||
|
||||
"topics" = "Topics";
|
||||
|
|
|
@ -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" = "К сожалению, раздел <b>$1</b> временно недоступен. Мы уже работаем над устранением неисправностей. Пожалуйста, попробуйте зайти позже.";
|
||||
|
||||
"topics" = "Темы";
|
||||
|
|
|
@ -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: "🅿"
|
||||
|
|
Loading…
Reference in a new issue