From 93466f6de44ffea1c0e14ce186c4c219c2a116ff Mon Sep 17 00:00:00 2001 From: n1rwana Date: Fri, 11 Aug 2023 00:23:43 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D0=B2=D0=B8=D0=B3=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20AJAX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Web/Presenters/CommentPresenter.php | 9 +- Web/Presenters/NotesPresenter.php | 8 +- Web/Presenters/OpenVKPresenter.php | 2 +- Web/Presenters/SearchPresenter.php | 52 +- Web/Presenters/SupportPresenter.php | 14 +- Web/Presenters/WallPresenter.php | 9 +- Web/Presenters/templates/@ajax.xml | 387 +++++++++++ Web/Presenters/templates/@layout.xml | 749 +++++++++++----------- Web/Presenters/templates/Group/View.xml | 2 +- Web/Presenters/templates/Notes/Edit.xml | 6 +- Web/Presenters/templates/Notes/List.xml | 2 +- Web/Presenters/templates/Notes/View.xml | 2 +- Web/Presenters/templates/Search/Index.xml | 88 +-- Web/Presenters/templates/User/Groups.xml | 4 +- Web/static/js/st_manager.js | 191 ++++++ 15 files changed, 1066 insertions(+), 459 deletions(-) create mode 100644 Web/Presenters/templates/@ajax.xml create mode 100644 Web/static/js/st_manager.js diff --git a/Web/Presenters/CommentPresenter.php b/Web/Presenters/CommentPresenter.php index cb0efd0d..ab070961 100644 --- a/Web/Presenters/CommentPresenter.php +++ b/Web/Presenters/CommentPresenter.php @@ -27,8 +27,13 @@ final class CommentPresenter extends OpenVKPresenter $this->flashFail("err", tr("error"), tr("forbidden")); if(!is_null($this->user)) $comment->toggleLike($this->user->identity); - - $this->redirect($_SERVER["HTTP_REFERER"]); + + $currentUrl = $_SERVER["HTTP_REFERER"] ?? "/"; + $parsedUrl = parse_url($currentUrl); + $queryParams = []; + parse_str($parsedUrl['query'] ?? '', $queryParams); + $queryParams['al'] = '1'; + $this->redirect("{$parsedUrl['scheme']}://{$parsedUrl['host']}{$parsedUrl['path']}?" . http_build_query($queryParams)); } function renderMakeComment(string $repo, int $eId): void diff --git a/Web/Presenters/NotesPresenter.php b/Web/Presenters/NotesPresenter.php index 50437ad7..c684eaf6 100644 --- a/Web/Presenters/NotesPresenter.php +++ b/Web/Presenters/NotesPresenter.php @@ -93,7 +93,7 @@ final class NotesPresenter extends OpenVKPresenter $note->setEdited(time()); $note->save(); - $this->redirect("/note" . $this->user->id . "_" . $note->getVirtualId()); + $this->redirect("/note" . $this->user->id . "_" . $note->getVirtualId() . "?al=1"); } } @@ -120,8 +120,8 @@ final class NotesPresenter extends OpenVKPresenter $note->setCached_Content(NULL); $note->setEdited(time()); $note->save(); - - $this->redirect("/note" . $this->user->id . "_" . $note->getVirtualId()); + + $this->redirect("/note" . $this->user->id . "_" . $note->getVirtualId() . "?al=1"); } } @@ -140,6 +140,6 @@ final class NotesPresenter extends OpenVKPresenter $name = $note->getName(); $note->delete(); $this->flash("succ", "Заметка удалена", "Заметка \"$name\" была успешно удалена."); - $this->redirect("/notes" . $this->user->id); + $this->redirect("/notes" . $this->user->id . "?al=1"); } } diff --git a/Web/Presenters/OpenVKPresenter.php b/Web/Presenters/OpenVKPresenter.php index 710713e5..29440ffa 100755 --- a/Web/Presenters/OpenVKPresenter.php +++ b/Web/Presenters/OpenVKPresenter.php @@ -61,7 +61,6 @@ abstract class OpenVKPresenter extends SimplePresenter } else { $this->flash($type, $title, $message, $code); $referer = $_SERVER["HTTP_REFERER"] ?? "/"; - $this->redirect($referer); } } @@ -277,6 +276,7 @@ abstract class OpenVKPresenter extends SimplePresenter } } + $this->template->__isAjax= $this->requestParam("al"); parent::onStartup(); } diff --git a/Web/Presenters/SearchPresenter.php b/Web/Presenters/SearchPresenter.php index fadf9954..828a1ec5 100644 --- a/Web/Presenters/SearchPresenter.php +++ b/Web/Presenters/SearchPresenter.php @@ -29,11 +29,11 @@ final class SearchPresenter extends OpenVKPresenter function renderIndex(): void { - $query = $this->queryParam("query") ?? ""; - $type = $this->queryParam("type") ?? "users"; - $sorter = $this->queryParam("sort") ?? "id"; - $invert = $this->queryParam("invert") == 1 ? "ASC" : "DESC"; - $page = (int) ($this->queryParam("p") ?? 1); + $query = $this->requestParam("query") ?? ""; + $type = $this->requestParam("type") ?? "users"; + $sorter = $this->requestParam("sort") ?? "id"; + $invert = $this->requestParam("invert") == 1 ? "ASC" : "DESC"; + $page = (int) ($this->requestParam("p") ?? 1); $this->willExecuteWriteAction(); if($query != "") @@ -66,27 +66,27 @@ final class SearchPresenter extends OpenVKPresenter } $parameters = [ - "type" => $this->queryParam("type"), - "city" => $this->queryParam("city") != "" ? $this->queryParam("city") : NULL, - "maritalstatus" => $this->queryParam("maritalstatus") != 0 ? $this->queryParam("maritalstatus") : NULL, - "with_photo" => $this->queryParam("with_photo"), - "status" => $this->queryParam("status") != "" ? $this->queryParam("status") : NULL, - "politViews" => $this->queryParam("politViews") != 0 ? $this->queryParam("politViews") : NULL, - "email" => $this->queryParam("email"), - "telegram" => $this->queryParam("telegram"), - "site" => $this->queryParam("site") != "" ? "https://".$this->queryParam("site") : NULL, - "address" => $this->queryParam("address"), - "is_online" => $this->queryParam("is_online") == 1 ? 1 : NULL, - "interests" => $this->queryParam("interests") != "" ? $this->queryParam("interests") : NULL, - "fav_mus" => $this->queryParam("fav_mus") != "" ? $this->queryParam("fav_mus") : NULL, - "fav_films" => $this->queryParam("fav_films") != "" ? $this->queryParam("fav_films") : NULL, - "fav_shows" => $this->queryParam("fav_shows") != "" ? $this->queryParam("fav_shows") : NULL, - "fav_books" => $this->queryParam("fav_books") != "" ? $this->queryParam("fav_books") : NULL, - "fav_quote" => $this->queryParam("fav_quote") != "" ? $this->queryParam("fav_quote") : NULL, - "hometown" => $this->queryParam("hometown") != "" ? $this->queryParam("hometown") : NULL, - "before" => $this->queryParam("datebefore") != "" ? strtotime($this->queryParam("datebefore")) : NULL, - "after" => $this->queryParam("dateafter") != "" ? strtotime($this->queryParam("dateafter")) : NULL, - "gender" => $this->queryParam("gender") != "" && $this->queryParam("gender") != 2 ? $this->queryParam("gender") : NULL + "type" => $this->requestParam("type"), + "city" => $this->requestParam("city") != "" ? $this->requestParam("city") : NULL, + "maritalstatus" => $this->requestParam("maritalstatus") != 0 ? $this->requestParam("maritalstatus") : NULL, + "with_photo" => $this->requestParam("with_photo"), + "status" => $this->requestParam("status") != "" ? $this->requestParam("status") : NULL, + "politViews" => $this->requestParam("politViews") != 0 ? $this->requestParam("politViews") : NULL, + "email" => $this->requestParam("email"), + "telegram" => $this->requestParam("telegram"), + "site" => $this->requestParam("site") != "" ? "https://".$this->requestParam("site") : NULL, + "address" => $this->requestParam("address"), + "is_online" => $this->requestParam("is_online") == 1 ? 1 : NULL, + "interests" => $this->requestParam("interests") != "" ? $this->requestParam("interests") : NULL, + "fav_mus" => $this->requestParam("fav_mus") != "" ? $this->requestParam("fav_mus") : NULL, + "fav_films" => $this->requestParam("fav_films") != "" ? $this->requestParam("fav_films") : NULL, + "fav_shows" => $this->requestParam("fav_shows") != "" ? $this->requestParam("fav_shows") : NULL, + "fav_books" => $this->requestParam("fav_books") != "" ? $this->requestParam("fav_books") : NULL, + "fav_quote" => $this->requestParam("fav_quote") != "" ? $this->requestParam("fav_quote") : NULL, + "hometown" => $this->requestParam("hometown") != "" ? $this->requestParam("hometown") : NULL, + "before" => $this->requestParam("datebefore") != "" ? strtotime($this->requestParam("datebefore")) : NULL, + "after" => $this->requestParam("dateafter") != "" ? strtotime($this->requestParam("dateafter")) : NULL, + "gender" => $this->requestParam("gender") != "" && $this->requestParam("gender") != 2 ? $this->requestParam("gender") : NULL ]; $repo = $repos[$type] or $this->throwError(400, "Bad Request", "Invalid search entity $type."); diff --git a/Web/Presenters/SupportPresenter.php b/Web/Presenters/SupportPresenter.php index c4d729ea..ae84e09c 100644 --- a/Web/Presenters/SupportPresenter.php +++ b/Web/Presenters/SupportPresenter.php @@ -191,7 +191,7 @@ final class SupportPresenter extends OpenVKPresenter $comment->setCreated(time()); $comment->save(); - $this->redirect("/support/view/" . $id); + $this->redirect("/support/view/" . $id . "?al=1"); } else { $this->flashFail("err", tr("error"), tr("you_have_not_entered_text")); } @@ -282,13 +282,21 @@ final class SupportPresenter extends OpenVKPresenter if($ticket->isDeleted()) $this->notFound(); - if(!($ticket->getUserId() === $this->user->id && $comment->getUType() === 0)) + $mode = "view"; + + if(!($ticket->getUserId() === $this->user->id && $comment->getUType() === 0)) { $this->assertPermission("openvk\Web\Models\Entities\TicketReply", "write", 0); + $mode = "reply"; + } $this->willExecuteWriteAction(); + + // $url = "/support/" . !($ticket->getUserId() === $this->user->id && $comment->getUType() === 0) ? "reply" : "view" . "/" . $comment->getTicket()->getId() . "?al=1"; + $url = "/support/$mode/" . $comment->getTicket()->getId() . "?al=1"; $comment->delete(); - $this->flashFail("succ", tr("ticket_changed"), tr("ticket_changed_comment")); + $this->flash("succ", tr("ticket_changed"), tr("ticket_changed_comment")); + $this->redirect($url); } function renderRateAnswer(int $id, int $mark): void diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index 3e115ec7..03f0362a 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -381,8 +381,13 @@ final class WallPresenter extends OpenVKPresenter if(!is_null($this->user)) { $post->toggleLike($this->user->identity); } - - $this->redirect("$_SERVER[HTTP_REFERER]#postGarter=" . $post->getId()); + + $currentUrl = $_SERVER["HTTP_REFERER"] ?? "/"; + $queryParams = []; + parse_str(parse_url($currentUrl, PHP_URL_QUERY) ?? "", $queryParams); + $queryParams['al'] = '1'; + $updatedUrl = strtok($currentUrl, '?') . '?' . http_build_query($queryParams); + $this->redirect($updatedUrl); } function renderShare(int $wall, int $post_id): void diff --git a/Web/Presenters/templates/@ajax.xml b/Web/Presenters/templates/@ajax.xml new file mode 100644 index 00000000..06211aff --- /dev/null +++ b/Web/Presenters/templates/@ajax.xml @@ -0,0 +1,387 @@ +{var $instance_name = OPENVK_ROOT_CONF['openvk']['appearance']['name']} + {if !isset($parentModule) || substr($parentModule, 0, 21) === 'libchandler:absolute.'} + + + + + {include title} + + {if $isTimezoned == NULL} + {script "js/timezone.js"} + {/if} + + {ifset headIncludes} + {include headIncludes} + {/ifset} + + +
+ +
+ + +
+

+ Вы вошли как {$thisUser->getCanonicalName()}. Пожалуйста, уважайте + право на тайну переписки других людей и не злоупотребляйте подменой пользователя. + Нажмите здесь, чтобы выйти. +

+
+ +
FOR TESTING PURPOSES ONLY
+ +
+
+ +
+ {_close} +
+
+
+ +
+ + +
+
+ + +
+ +
+
+
+
+ + {if isset($backdrops) && !is_null($backdrops)} +
+
+
+ {/if} + +
+ ⬆ {_to_top} +
+ +
+
+
+ {if $instance_name != OPENVK_DEFAULT_INSTANCE_NAME}{$instance_name}{/if} +
+ {ifset $thisUser} + {if $thisUser->isDeactivated()} + + {else} + + + + + + + {var $atSearch = str_contains($_SERVER['REQUEST_URI'], "/search")} +
+ + {if !$atSearch} +
+ + +
+ + {else} +
+ + + +
+ + {/if} +
+ {/if} + {else} + + + + {/ifset} +
+
+ + + +
+
+
+
+ {include header} +
+
+
+ + {ifset wrap} +
+ {$flashMessage->title}
+ {$flashMessage->msg|noescape} +
+ + {include wrap} + {else} +
+
+
+
+
+ {$flashMessage->title}
+ {$flashMessage->msg|noescape} +
+ + {include content} +
+
+
+
+ {/ifset} +
+
+ + + + {if OPENVK_ROOT_CONF['openvk']['preferences']['bellsAndWhistles']['fartscroll']} + + + {/if} + + + + + + + + + + + + + {/if} + + {if isset($parentModule) && substr($parentModule, 0, 21) !== 'libchandler:absolute.'} + + + {include content} + {/if} diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index 1718c499..946b269c 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -1,421 +1,436 @@ -{var $instance_name = OPENVK_ROOT_CONF['openvk']['appearance']['name']} -{if !isset($parentModule) || substr($parentModule, 0, 21) === 'libchandler:absolute.'} - - - - - {ifset title}{include title} - {/ifset}{$instance_name} - - - - - +{if $__isAjax} + {include "@ajax.xml" with blocks} +{else} + {var $instance_name = OPENVK_ROOT_CONF['openvk']['appearance']['name']} + {if !isset($parentModule) || substr($parentModule, 0, 21) === 'libchandler:absolute.'} + + + + + {ifset title}{include title} - {/ifset}{$instance_name} + + + + + - - {script "js/node_modules/jquery/dist/jquery.min.js"} - {script "js/node_modules/umbrellajs/umbrella.min.js"} - {script "js/l10n.js"} - {script "js/openvk.cls.js"} + + {script "js/node_modules/jquery/dist/jquery.min.js"} + {script "js/node_modules/umbrellajs/umbrella.min.js"} + {script "js/l10n.js"} + {script "js/openvk.cls.js"} + {script "js/st_manager.js"} - {css "js/node_modules/tippy.js/dist/backdrop.css"} - {css "js/node_modules/tippy.js/dist/border.css"} - {css "js/node_modules/tippy.js/dist/svg-arrow.css"} - {css "js/node_modules/tippy.js/themes/light.css"} - {script "js/node_modules/@popperjs/core/dist/umd/popper.min.js"} - {script "js/node_modules/tippy.js/dist/tippy-bundle.umd.min.js"} - {script "js/node_modules/handlebars/dist/handlebars.min.js"} + {css "js/node_modules/tippy.js/dist/backdrop.css"} + {css "js/node_modules/tippy.js/dist/border.css"} + {css "js/node_modules/tippy.js/dist/svg-arrow.css"} + {css "js/node_modules/tippy.js/themes/light.css"} + {script "js/node_modules/@popperjs/core/dist/umd/popper.min.js"} + {script "js/node_modules/tippy.js/dist/tippy-bundle.umd.min.js"} + {script "js/node_modules/handlebars/dist/handlebars.min.js"} - {if $isTimezoned == NULL} - {script "js/timezone.js"} - {/if} + {if $isTimezoned == NULL} + {script "js/timezone.js"} + {/if} - {include "_includeCSS.xml"} + {include "_includeCSS.xml"} - {ifset headIncludes} - {include headIncludes} - {/ifset} - - -
-

- Вы вошли как {$thisUser->getCanonicalName()}. Пожалуйста, уважайте - право на тайну переписки других людей и не злоупотребляйте подменой пользователя. - Нажмите здесь, чтобы выйти. -

-
+ {ifset headIncludes} + {include headIncludes} + {/ifset} + + +
+ +
+

+ Вы вошли как {$thisUser->getCanonicalName()}. Пожалуйста, уважайте + право на тайну переписки других людей и не злоупотребляйте подменой пользователя. + Нажмите здесь, чтобы выйти. +

+
-
FOR TESTING PURPOSES ONLY
+
FOR TESTING PURPOSES ONLY
-
-
+
+
-
- {_close} -
-
-
- -
- - +
+ {_close} +
+
+
+ +
+ + +
+
+ +
- +
-
+ {if isset($backdrops) && !is_null($backdrops)} +
+
+ {/if} + +
+ ⬆ {_to_top}
-
- {if isset($backdrops) && !is_null($backdrops)} -
-
-
- {/if} +
+
+
+ {if $instance_name != OPENVK_DEFAULT_INSTANCE_NAME}{$instance_name}{/if} +
+ {ifset $thisUser} + {if $thisUser->isDeactivated()} + + {else} + + + + + + + {var $atSearch = str_contains($_SERVER['REQUEST_URI'], "/search")} +
-
- ⬆ {_to_top} -
- -
-
-
- {if $instance_name != OPENVK_DEFAULT_INSTANCE_NAME}{$instance_name}{/if} -
- {ifset $thisUser} - {if $thisUser->isDeactivated()} + {if !$atSearch} +
+ + +
+ + {else} +
+ + + +
+ + {/if} +
+ {/if} + {else} - {else} - -
-