mirror of
https://github.com/openvk/openvk
synced 2024-11-14 19:19:14 +03:00
Wall, VKAPI: Add geolocation support
This commit is contained in:
parent
a2384cc231
commit
b9932eefdf
7 changed files with 128 additions and 2 deletions
18
ServiceAPI/Clients.php
Normal file
18
ServiceAPI/Clients.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\ServiceAPI;
|
||||
use openvk\Web\Models\Entities\User;
|
||||
|
||||
class Clients implements Handler
|
||||
{
|
||||
protected $user;
|
||||
|
||||
function __construct(?User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
function resolve(string $client_name, callable $resolve, callable $reject): void
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -95,4 +95,15 @@ class Wall implements Handler
|
|||
|
||||
$resolve($arr);
|
||||
}
|
||||
|
||||
function getMapIframe(int $id, callable $resolve, callable $reject)
|
||||
{
|
||||
$post = $this->posts->get($id);
|
||||
if ($post->getGeolocation())
|
||||
{
|
||||
$resolve($post->getMapEmbed());
|
||||
} else {
|
||||
$reject("No geotag found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -379,7 +379,7 @@ final class Wall extends VKAPIRequestHandler
|
|||
];
|
||||
}
|
||||
|
||||
function post(string $owner_id, string $message = "", int $from_group = 0, int $signed = 0, string $attachments = ""): object
|
||||
function post(string $owner_id, string $message = "", int $from_group = 0, int $signed = 0, string $attachments = "", float $latitude, float $longitude): object
|
||||
{
|
||||
$this->requireUser();
|
||||
$this->willExecuteWriteAction();
|
||||
|
@ -428,6 +428,8 @@ final class Wall extends VKAPIRequestHandler
|
|||
$post->setContent($message);
|
||||
$post->setFlags($flags);
|
||||
$post->setApi_Source_Name($this->getPlatform());
|
||||
if($latitude && $longitude)
|
||||
$post->setLocation($latitude, $longitude);
|
||||
$post->save();
|
||||
} catch(\LogicException $ex) {
|
||||
$this->fail(100, "One of the parameters specified was missing or invalid");
|
||||
|
|
|
@ -4,6 +4,7 @@ use Chandler\Database\DatabaseConnection as DB;
|
|||
use openvk\Web\Models\Repositories\{Clubs, Users};
|
||||
use openvk\Web\Models\RowModel;
|
||||
use openvk\Web\Models\Entities\Notifications\LikeNotification;
|
||||
use Nette\InvalidStateException as ISE;
|
||||
|
||||
class Post extends Postable
|
||||
{
|
||||
|
@ -175,6 +176,29 @@ class Post extends Postable
|
|||
"img" => NULL
|
||||
];
|
||||
}
|
||||
|
||||
function getGeolocation(): ?string {
|
||||
return $this->getRecord()->geolocation;
|
||||
}
|
||||
|
||||
function getMapEmbed(): ?string {
|
||||
$location = $this->getRecord()->geolocation;
|
||||
if(is_null($location)) return null;
|
||||
|
||||
$location_array = array();
|
||||
|
||||
preg_match('/^((\-?|\+?)?\d+(\.\d+)?),\s*((\-?|\+?)?\d+(\.\d+)?)$/', $location, $location_array);
|
||||
|
||||
$latitude = floatval($location_array[1]);
|
||||
$longitude = floatval($location_array[4]);
|
||||
|
||||
return "<iframe
|
||||
width=\"100%\"
|
||||
height=\"350\"
|
||||
src=\"https://www.openstreetmap.org/export/embed.html?bbox=". ($longitude - 0.002) ."%2C". ($latitude - 0.002) ."%2C". ($longitude + 0.002) ."%2C". ($latitude + 0.002) ."&layer=mapnik&marker=". $latitude ."%2C". $longitude ."\"
|
||||
style=\"border: 1px solid black\">
|
||||
</iframe>";
|
||||
}
|
||||
|
||||
function pin(): void
|
||||
{
|
||||
|
@ -220,6 +244,15 @@ class Post extends Postable
|
|||
$this->stateChanges("content", $content);
|
||||
}
|
||||
|
||||
function setLocation(float $latitude, $longitude): void
|
||||
{
|
||||
if ($latitude > 90 || $latitude < -90 || $longitude > 180 || $longitude < -180) {
|
||||
throw new \LogicException("Invalid latitude or longitude");
|
||||
} else {
|
||||
$this->setGeolocation($latitude.",".$longitude);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleLike(User $user): bool
|
||||
{
|
||||
$liked = parent::toggleLike($user);
|
||||
|
|
|
@ -86,6 +86,12 @@
|
|||
</a>
|
||||
</span>
|
||||
</div>
|
||||
<div n:if="$post->getGeolocation()" class="post-signature">
|
||||
<a href="javascript:openMapDialog({$post->getId()});">
|
||||
<img src="/assets/packages/static/openvk/img/geo.svg">
|
||||
Геолокация
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="post-menu" n:if="$compact == false">
|
||||
<a href="/wall{$post->getPrettyId()}" class="date">{$post->getPublicationTime()}</a>
|
||||
|
|
47
Web/static/img/geo.svg
Executable file
47
Web/static/img/geo.svg
Executable file
|
@ -0,0 +1,47 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="13"
|
||||
height="12"
|
||||
viewBox="0 0 3.4395833 3.175"
|
||||
version="1.1"
|
||||
id="svg5"
|
||||
inkscape:version="1.2.1 (9c6d41e410, 2022-07-14)"
|
||||
sodipodi:docname="geo.svg"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview7"
|
||||
pagecolor="#505050"
|
||||
bordercolor="#eeeeee"
|
||||
borderopacity="1"
|
||||
inkscape:showpageshadow="0"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#505050"
|
||||
inkscape:document-units="mm"
|
||||
showgrid="false"
|
||||
inkscape:zoom="45.254834"
|
||||
inkscape:cx="5.2922523"
|
||||
inkscape:cy="5.2149125"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1009"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1" />
|
||||
<defs
|
||||
id="defs2" />
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<path
|
||||
id="path4213"
|
||||
style="fill:#b1bfcd;fill-opacity:1;stroke-width:0.264583"
|
||||
d="M 1.7197917 0.0025838216 C 1.1850116 0.0049444593 0.72280427 0.4971031 0.71520182 1.0190592 C 0.70756921 1.5430869 1.7223755 3.1739665 1.7223755 3.1739665 C 1.7223755 3.1739665 2.7249195 1.5439189 2.7243815 0.99632161 C 2.7238745 0.48024825 2.2492929 0.00024648357 1.7197917 0.0025838216 z M 1.7197917 0.52606608 A 0.48526123 0.48526123 0 0 1 2.2050334 1.0113078 A 0.48526123 0.48526123 0 0 1 1.7197917 1.4965495 A 0.48526123 0.48526123 0 0 1 1.23455 1.0113078 A 0.48526123 0.48526123 0 0 1 1.7197917 0.52606608 z " />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.8 KiB |
|
@ -262,4 +262,13 @@ async function showArticle(note_id) {
|
|||
u("#articleText").html(`<h1 class="articleView_nameHeading">${note.title}</h1>` + note.html);
|
||||
u("body").removeClass("dimmed");
|
||||
u("body").addClass("article");
|
||||
}
|
||||
}
|
||||
|
||||
async function openMapDialog(id)
|
||||
{
|
||||
let iframe = await API.Wall.getMapIframe(id)
|
||||
|
||||
let frame = MessageBox("Геолокация", iframe, [tr("close")], [Function.noop]);
|
||||
|
||||
document.querySelector(".ovk-diag-body").style.padding = "10px"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue