Update geo json (#153)

* Changed my name

* More generic JSON data

* Improved translations

* Added Spanish translations

* Update event_geo_json to 0.3.0

* Added Spanish translations
* Improved translations
* More generic JSON data
* Changed my name

---------

Co-authored-by: surrim <root@surrim.org>
This commit is contained in:
surrim 2023-01-31 16:23:24 +00:00 committed by GitHub
parent c29c6aafa7
commit 736d2bfeaa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 50 additions and 36 deletions

View file

@ -1,9 +1,14 @@
0.3.0:
---
* Added Spanish translations
* Improved translations
* More generic JSON data
* Changed my name
0.2.2: 0.2.2:
--- ---
* Added missing include
* Added missing include
0.2.1: 0.2.1:
--- ---
* Convert date, size and catergory ids to int, 3% smaller output
* Convert date, size and catergory ids to int, 3% smaller output

View file

@ -1,4 +1,4 @@
<?php <?php
@define('PLUGIN_EVENT_GEO_JSON_NAME', 'Geo-JSON'); @define('PLUGIN_EVENT_GEO_JSON_NAME', 'Geo-JSON');
@define('PLUGIN_EVENT_GEO_JSON_DESCRIPTION', 'Erstellt ein JSON-Object mit allen Geo-Daten, welches mit JavaScript verarbeiete werden kann.'); @define('PLUGIN_EVENT_GEO_JSON_DESCRIPTION', 'Erstellt ein JSON-Object, welches alle Geo-Daten enthält und mit JavaScript verarbeitet werden kann');
?> ?>

View file

@ -0,0 +1,4 @@
<?php
@define('PLUGIN_EVENT_GEO_JSON_NAME', 'Geo-JSON');
@define('PLUGIN_EVENT_GEO_JSON_DESCRIPTION', 'Crea un objeto JSON que contiene todos los datos geográficos y puede procesarse con JavaScript');
?>

View file

@ -1,4 +1,4 @@
<?php <?php
@define('PLUGIN_EVENT_GEO_JSON_NAME', 'Geo-JSON'); @define('PLUGIN_EVENT_GEO_JSON_NAME', 'Geo-JSON');
@define('PLUGIN_EVENT_GEO_JSON_DESCRIPTION', 'Erstellt ein JSON-Object mit allen Geo-Daten, welches mit JavaScript verarbeiete werden kann.'); @define('PLUGIN_EVENT_GEO_JSON_DESCRIPTION', 'Erstellt ein JSON-Object, welches alle Geo-Daten enthält und mit JavaScript verarbeitet werden kann');
?> ?>

View file

@ -1,4 +1,4 @@
<?php <?php
@define('PLUGIN_EVENT_GEO_JSON_NAME', 'Geo-JSON'); @define('PLUGIN_EVENT_GEO_JSON_NAME', 'Geo-JSON');
@define('PLUGIN_EVENT_GEO_JSON_DESCRIPTION', 'Provides a JSON object with all geo data which can be processed by JavaScript.'); @define('PLUGIN_EVENT_GEO_JSON_DESCRIPTION', 'Provides a JSON object which contains all geographic data and can be processed with JavaScript');
?> ?>

View file

@ -0,0 +1,4 @@
<?php
@define('PLUGIN_EVENT_GEO_JSON_NAME', 'Geo-JSON');
@define('PLUGIN_EVENT_GEO_JSON_DESCRIPTION', 'Crea un objeto JSON que contiene todos los datos geográficos y puede procesarse con JavaScript');
?>

View file

@ -1,4 +1,4 @@
<?php <?php
@define('PLUGIN_EVENT_GEO_JSON_VERSION', '0.2.2'); @define('PLUGIN_EVENT_GEO_JSON_VERSION', '0.3.0');
@define('PLUGIN_EVENT_GEO_JSON_AUTHOR', 'Martin Sewelies'); @define('PLUGIN_EVENT_GEO_JSON_AUTHOR', 'Kathi Sewelies');
?> ?>

View file

@ -16,7 +16,7 @@
$propbag->add('event_hooks', array('frontend_header' => true)); $propbag->add('event_hooks', array('frontend_header' => true));
$propbag->add('author', PLUGIN_EVENT_GEO_JSON_AUTHOR); $propbag->add('author', PLUGIN_EVENT_GEO_JSON_AUTHOR);
$propbag->add('version', PLUGIN_EVENT_GEO_JSON_VERSION); $propbag->add('version', PLUGIN_EVENT_GEO_JSON_VERSION);
$propbag->add('requirements', array('serendipity' => '2.3')); $propbag->add('requirements', ['serendipity' => '2.3']);
$propbag->add('stackable', false); $propbag->add('stackable', false);
$propbag->add('groups', array('FRONTEND_FEATURES')); $propbag->add('groups', array('FRONTEND_FEATURES'));
} }
@ -31,9 +31,11 @@
return is_array($rows) ? $rows : []; return is_array($rows) ? $rows : [];
} }
function get_entries() { function get_articles() {
global $serendipity; global $serendipity;
$entries = []; $timestamp = serendipity_db_time();
$showFutureEntries = serendipity_db_bool($serendipity['showFutureEntries']);
$articles = [];
foreach ($this->simple_query( foreach ($this->simple_query(
"SELECT e.id, e.title, p.permalink, e.timestamp, LENGTH(e.body) AS size, a.realname, eplat.value AS lat, eplng.value AS lng "SELECT e.id, e.title, p.permalink, e.timestamp, LENGTH(e.body) AS size, a.realname, eplat.value AS lat, eplng.value AS lng
FROM {$serendipity['dbPrefix']}entries e FROM {$serendipity['dbPrefix']}entries e
@ -44,16 +46,16 @@
WHERE e.isdraft = 'false' WHERE e.isdraft = 'false'
ORDER BY e.timestamp", ORDER BY e.timestamp",
false, 'assoc' false, 'assoc'
) as $row) { ) as $article) {
$entries[$row['id']] = [ $articles[$article['id']] = [
'title' => $row['title'], 'title' => $article['title'],
'url' => serendipity_db_bool($serendipity['showFutureEntries']) || $row['timestamp'] <= serendipity_db_time() 'url' => $article['timestamp'] <= $timestamp || $showFutureEntries
? $serendipity['serendipityHTTPPath'].$row['permalink'] ? $serendipity['serendipityHTTPPath'] . $article['permalink']
: null, : null,
'date' => intval($row['timestamp']), 'date' => intval($article['timestamp']),
'size' => intval($row['size']), 'size' => intval($article['size']),
'author' => $row['realname'], 'author' => $article['realname'],
'pos' => [floatval($row['lat']), floatval($row['lng'])], 'location' => [floatval($article['lat']), floatval($article['lng'])],
'categories' => [] 'categories' => []
]; ];
} }
@ -64,21 +66,21 @@
JOIN {$serendipity['dbPrefix']}entryproperties eplat ON (eplat.entryid = ec.entryid AND eplat.property = 'geo_lat') JOIN {$serendipity['dbPrefix']}entryproperties eplat ON (eplat.entryid = ec.entryid AND eplat.property = 'geo_lat')
JOIN {$serendipity['dbPrefix']}entryproperties eplng ON (eplng.entryid = ec.entryid AND eplng.property = 'geo_long') JOIN {$serendipity['dbPrefix']}entryproperties eplng ON (eplng.entryid = ec.entryid AND eplng.property = 'geo_long')
WHERE e.isdraft = 'false'" WHERE e.isdraft = 'false'"
) as $row) { ) as $articleCategory) {
$entries[$row['entryid']]['categories'][] = intval($row['categoryid']); $articles[$articleCategory['entryid']]['categories'][] = intval($articleCategory['categoryid']);
} }
return array_values($entries); return array_values($articles);
} }
function get_uploads() { function get_tracks() {
global $serendipity; global $serendipity;
return array_map(function($row) { return array_map(function($track) {
global $serendipity; global $serendipity;
return [ return [
'title' => $row['realname'], 'title' => $track['realname'],
'url' => $serendipity['serendipityHTTPPath'].$serendipity['uploadPath'].$row['path'].$row['realname'], 'url' => $serendipity['serendipityHTTPPath'] . $serendipity['uploadPath'] . $track['path'] . $track['realname'],
'date' => intval($row['date']), 'date' => intval($track['date']),
'size' => intval($row['size']) 'size' => intval($track['size'])
]; ];
}, $this->simple_query( }, $this->simple_query(
"SELECT i.realname, i.path, IFNULL(m.value, i.date) AS date, i.size "SELECT i.realname, i.path, IFNULL(m.value, i.date) AS date, i.size
@ -87,23 +89,22 @@
m.mediaid = i.id AND m.property='DATE' AND m.property_group = 'base_property' AND property_subgroup = '' m.mediaid = i.id AND m.property='DATE' AND m.property_group = 'base_property' AND property_subgroup = ''
) )
WHERE i.extension = 'gpx' WHERE i.extension = 'gpx'
ORDER BY i.path, i.realname", ORDER BY i.path",
false, 'assoc' false, 'assoc'
)); ));
} }
function get_geo_json() function get_geo_json() {
{
return json_encode([ return json_encode([
'entries' => $this->get_entries(), 'articles' => $this->get_articles(),
'uploads' => $this->get_uploads() 'tracks' => $this->get_tracks()
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
} }
function event_hook($event, &$bag, &$eventData, $addData = null) function event_hook($event, &$bag, &$eventData, $addData = null)
{ {
if ($event == 'frontend_header') { if ($event == 'frontend_header') {
echo ' <script>const geo = '.$this->get_geo_json().';</script>'.PHP_EOL; echo ' <script>const geo = ' . $this->get_geo_json() . ';</script>' . PHP_EOL;
} }
} }