feat(geo): add ability to change point name and...

...fix federal cities name and territorial integrity
This commit is contained in:
mrilyew 2024-12-13 20:02:49 +03:00
parent a714a0aa16
commit 959a6d6ac3
8 changed files with 54 additions and 4 deletions

View file

@ -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);
}

View file

@ -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,
];
}

View file

@ -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);
}

View file

@ -856,6 +856,10 @@ h4 {
padding: 0 4px;
}
#geo-name {
cursor: pointer;
}
.post-signature span {
color: grey;
}

View file

@ -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: `
<div>
<input type="text" maxlength="255" name="final_value" placeholder="${tr('change_geo_name_new')}" value="${current_value}">
</div>
`,
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"), "<div id=\"osm-map\"></div>", [tr("nearest_posts"), tr("close")], [async () => {
const posts = await OVKAPI.call('wall.getNearby', {owner_id: owner_id, post_id: virtual_id})

View file

@ -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)
}

View file

@ -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";

View file

@ -270,6 +270,9 @@
"no_nearest_posts" = "Нет ближайших постов";
"shown_last_nearest_posts" = "Показаны последние $1 постов за месяц";
"change_geo_name" = "Изменить название точки";
"change_geo_name_new" = "Новое название";
/* Friends */
"friends" = "Друзья";