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: ` +
+ +
+ `, + buttons: [tr('save'), tr('cancel')], + callbacks: [() => { + const new_value = u(`input[name='final_value']`).nodes[0].value + u('#geo-name').html(escapeHtml(new_value)) + }, Function.noop] + }) + u(`input[name='final_value']`).nodes[0].focus() +}) + function openGeo(data, owner_id, virtual_id) { MessageBox(tr("geotag"), "
", [tr("nearest_posts"), tr("close")], [async () => { const posts = await OVKAPI.call('wall.getNearby', {owner_id: owner_id, post_id: virtual_id}) diff --git a/Web/static/js/utils.js b/Web/static/js/utils.js index efaaf05e..551663fa 100644 --- a/Web/static/js/utils.js +++ b/Web/static/js/utils.js @@ -298,13 +298,18 @@ function short_geo_name(address_osm) final_arr.push(address_osm.state_district) } if(address_osm.city) { - final_arr.push(address_osm.city) + if(address_osm.city != address_osm.state) { + final_arr.push(address_osm.city) + } } else if(address_osm.town) { final_arr.push(address_osm.town) } if(address_osm.city_district) { final_arr.push(address_osm.city_district) } + if(address_osm.village) { + final_arr.push(address_osm.village) + } if(address_osm.road) { final_arr.push(address_osm.road) } diff --git a/locales/en.strings b/locales/en.strings index 4f4a5bd8..ac328308 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -291,6 +291,9 @@ "no_nearest_posts" = "No nearby posts"; "shown_last_nearest_posts" = "Showing last $1 posts per month"; +"change_geo_name" = "Change geo name"; +"change_geo_name_new" = "New name"; + /* Friends */ "friends" = "Friends"; diff --git a/locales/ru.strings b/locales/ru.strings index 0b2a331d..3f036473 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -270,6 +270,9 @@ "no_nearest_posts" = "Нет ближайших постов"; "shown_last_nearest_posts" = "Показаны последние $1 постов за месяц"; +"change_geo_name" = "Изменить название точки"; +"change_geo_name_new" = "Новое название"; + /* Friends */ "friends" = "Друзья";