From 959a6d6ac3ec412da631aceaeb511523e523ddaf Mon Sep 17 00:00:00 2001 From: mrilyew <99399973+mrilyew@users.noreply.github.com> Date: Fri, 13 Dec 2024 20:02:49 +0300 Subject: [PATCH] feat(geo): add ability to change point name and... ...fix federal cities name and territorial integrity --- VKAPI/Handlers/Wall.php | 2 +- Web/Models/Entities/Post.php | 16 ++++++++++++++++ Web/Presenters/WallPresenter.php | 2 +- Web/static/css/main.css | 4 ++++ Web/static/js/al_wall.js | 21 ++++++++++++++++++++- Web/static/js/utils.js | 7 ++++++- locales/en.strings | 3 +++ locales/ru.strings | 3 +++ 8 files changed, 54 insertions(+), 4 deletions(-) diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index e01446e6..ab369a6b 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -639,7 +639,7 @@ final class Wall extends VKAPIRequestHandler $res['name'] = 'Geopoint'; } - $post->setGeo(json_encode($res)); + $post->setGeo($res); $post->setGeo_Lat($latitude); $post->setGeo_Lon($longitude); } diff --git a/Web/Models/Entities/Post.php b/Web/Models/Entities/Post.php index f3f8e1f7..dceaeac9 100644 --- a/Web/Models/Entities/Post.php +++ b/Web/Models/Entities/Post.php @@ -463,6 +463,21 @@ class Post extends Postable return (object) json_decode($this->getRecord()->geo, true, JSON_UNESCAPED_UNICODE); } + function setGeo($encoded_object): void + { + $final_geo = $encoded_object['name']; + $neutral_names = ["Россия", "Russia", "Росія", "Россія", "Украина", "Ukraine", "Україна", "Украіна"]; + foreach($neutral_names as $name) { + if(str_contains($final_geo, $name.", ")) { + $final_geo = str_replace($name.", ", "", $final_geo); + } + } + + $encoded_object['name'] = ovk_proc_strtr($final_geo, 255); + $encoded = json_encode($encoded_object); + $this->stateChanges("geo", $encoded); + } + function getLat(): ?float { return (float) $this->getRecord()->geo_lat ?? NULL; @@ -478,6 +493,7 @@ class Post extends Postable return (object) [ 'type' => 'point', 'coordinates' => $this->getLat() . ',' . $this->getLon(), + 'name' => $this->getGeo()->name, ]; } diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index 3790e5a3..12067ad0 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -346,7 +346,7 @@ final class WallPresenter extends OpenVKPresenter $post->setSuggested(1); if ($geo) { - $post->setGeo(json_encode($geo)); + $post->setGeo($geo); $post->setGeo_Lat($latitude); $post->setGeo_Lon($longitude); } diff --git a/Web/static/css/main.css b/Web/static/css/main.css index b83c2d45..e740e49d 100644 --- a/Web/static/css/main.css +++ b/Web/static/css/main.css @@ -856,6 +856,10 @@ h4 { padding: 0 4px; } +#geo-name { + cursor: pointer; +} + .post-signature span { color: grey; } diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js index f089294c..a20b0d9d 100644 --- a/Web/static/js/al_wall.js +++ b/Web/static/js/al_wall.js @@ -2634,7 +2634,7 @@ u(document).on('click', "#__geoAttacher", async (e) => { const marker = { lat: currentMarker._latlng.lat, lng: currentMarker._latlng.lng, - name: escapeHtml(geo_name) + name: geo_name } buttons.find(`input[name='geo']`).nodes[0].value = JSON.stringify(marker) buttons.find(`.post-has-geo`).html(` @@ -2712,6 +2712,25 @@ u(document).on('click', '.post-has-geo #small_remove_button', (e) => { form.find(`input[name='geo']`).nodes[0].value = '' }) +u(document).on('click', '#geo-name', (e) => { + const current_value = escapeHtml(e.target.innerHTML) + const msg = new CMessageBox({ + title: tr('change_geo_name'), + unique_name: 'geo_change_name_menu', + body: ` +