Skip to content

Commit

Permalink
Wall, VKAPI: More geolocation suppor
Browse files Browse the repository at this point in the history
  • Loading branch information
veselcraft committed Aug 3, 2023
1 parent b9932ee commit 2428e3c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
13 changes: 13 additions & 0 deletions VKAPI/Handlers/Wall.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 3
];
}

$geo = [];

if($post->getGeolocation()) {
$geoarray = $post->getGeolocationByArray();

$geo = [
"coordinates" => $geoarray[0] . " " . $geoarray[1],
"showmap" => 1,
"type" => "point"
];
}

$items[] = (object)[
"id" => $post->getVirtualId(),
"from_id" => $from_id,
Expand All @@ -128,6 +140,7 @@ function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 3
"is_explicit" => $post->isExplicit(),
"attachments" => $attachments,
"post_source" => $post_source,
"geo" => $geo,
"comments" => (object)[
"count" => $post->getCommentsCount(),
"can_post" => 1
Expand Down
12 changes: 12 additions & 0 deletions Web/Models/Entities/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ function getGeolocation(): ?string {
return $this->getRecord()->geolocation;
}

function getGeolocationAsArray(): ?array {
$location = $this->getRecord()->geolocation;
if(is_null($location)) return null;

preg_match('/^((\-?|\+?)?\d+(\.\d+)?),\s*((\-?|\+?)?\d+(\.\d+)?)$/', $location, $location_array);

$latitude = floatval($location_array[1]);
$longitude = floatval($location_array[4]);

return array($latitude, $longitude);
}

function getMapEmbed(): ?string {
$location = $this->getRecord()->geolocation;
if(is_null($location)) return null;
Expand Down
2 changes: 1 addition & 1 deletion Web/static/js/al_wall.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ async function openMapDialog(id)
{
let iframe = await API.Wall.getMapIframe(id)

let frame = MessageBox("Геолокация", iframe, [tr("close")], [Function.noop]);
let frame = MessageBox(tr("geolocation"), iframe, [tr("close")], [Function.noop]);

document.querySelector(".ovk-diag-body").style.padding = "10px"
}
2 changes: 2 additions & 0 deletions locales/en.strings
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@

"reply" = "Reply";

"geolocation" = "Geolocation";

/* Friends */

"friends" = "Friends";
Expand Down
1 change: 1 addition & 0 deletions locales/ru.strings
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
"version_incompatibility" = "Не удалось отобразить это вложение. Возможно, база данных несовместима с текущей версией OpenVK.";
"graffiti" = "Граффити";
"reply" = "Ответить";
"geolocation" = "Геолокация";

/* Friends */

Expand Down

0 comments on commit 2428e3c

Please sign in to comment.