SQL and geopoint name fixes

This commit is contained in:
n1rwana 2023-08-04 21:53:53 +03:00
parent b565daf827
commit 83e6d13f1a
No known key found for this signature in database
GPG key ID: 9071E6F0FF27A358
4 changed files with 13 additions and 10 deletions

View file

@ -436,16 +436,19 @@ final class Wall extends VKAPIRequestHandler
$geo = NULL;
if ($latitude && $longitude) {
$latitude = number_format($latitude, 8, ".", '');
$longitude = number_format($longitude, 8, ".", '');
if ((!$latitude || !$longitude) || ($latitude > 90 || $latitude < -90 || $longitude > 180 || $longitude < -180)) {
$this->fail(100, "Invalid latitude or longitude");
}
$geo = array(
"name" => null,
"lat" => $latitude,
"lng" => $longitude,
);
if ($latitude > 90 || $latitude < -90 || $longitude > 180 || $longitude < -180) {
$this->fail(100, "Invalid latitude or longitude");
}
if (strlen(trim($geo_name))) {
$geo["name"] = $geo_name;
} else {

View file

@ -301,8 +301,8 @@ final class WallPresenter extends OpenVKPresenter
$this->flashFail("err", tr("error"), tr("error_geolocation"));
}
$latitude = (float) $geo["lat"];
$longitude = (float) $geo["lng"];
$latitude = number_format((float) $geo["lat"], 8, ".", '');
$longitude = number_format((float) $geo["lng"], 8, ".", '');
if ($latitude > 90 || $latitude < -90 || $longitude > 180 || $longitude < -180) {
$this->flashFail("err", tr("error"), "Invalid latitude or longitude");
}

View file

@ -269,7 +269,7 @@ async function initGeo(tid) {
let marker = {
lat: currentMarker._latlng.lat,
lng: currentMarker._latlng.lng,
name: $(`#geo-name-input-${tid}`).val() ?? currentMarker._popup._content
name: $(`#geo-name-input-${tid}`).val() ? $(`#geo-name-input-${tid}`).val() : $(`#geo-name-${tid}`).text()
};
$(`#post-buttons${tid} #geo`).val(JSON.stringify(marker));
$(`#post-buttons${tid} .post-has-geo`).text(`${tr("geotag")}: ${marker.name}`);
@ -305,7 +305,7 @@ async function initGeo(tid) {
let name = response?.name ?? response?.display_name ?? tr("geotag");
let content = `<span onclick="let name = prompt('Введите название геоточки'); $('#geo-name-input-${tid}').val(name); $(this).text(name);" id="geo-name-${tid}">${name}</span>`;
content += `<input type="hidden" id="geo-name-input-${tid}" />`;
content += `<input type="hidden" id="geo-name-input-${tid}" value="" />`;
currentMarker.bindPopup(content).openPopup();
markerLayers.addLayer(currentMarker);

View file

@ -1,4 +1,4 @@
ALTER TABLE `posts`
ADD `geo` LONGTEXT NULL DEFAULT NULL AFTER `deleted`,
ADD `geo_lat` DECIMAL(10, 8) NULL DEFAULT NULL AFTER `geo`,
ADD `geo_lon` DECIMAL(10, 8) NULL DEFAULT NULL AFTER `geo_lat`;
ADD `geo_lat` DECIMAL(12, 8) NULL DEFAULT NULL AFTER `geo`,
ADD `geo_lon` DECIMAL(12, 8) NULL DEFAULT NULL AFTER `geo_lat`;