Update event_osm (#154)

* Changed my name

* Added PHP 7 dependency

* Improved translations

* Added Spanish translations

* Avoid regex pattern for file name

* Whitespaces fixed

* Optimized code for compressing GPX files

* JavaScript code changed for Geo-JSON version 3 and better readability

* Added *.map files

* Only add done gpx tracks to the total sum

* Update event_osm to 0.4.0

* Only add done gpx tracks to the total sum
* Added missing *.map files
* JavaScript code changed for Geo-JSON version 3 and better readability
* Optimized code for compressing GPX files
* Whitespaces fixed
* Avoid regex pattern for file name
* Added Spanish translations
* Improved translations
* Added PHP 7 dependency
* Changed my name

---------

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

View file

@ -1,3 +1,16 @@
0.4.0:
---
* Only add done gpx tracks to the total sum
* Added missing *.map files
* JavaScript code changed for Geo-JSON version 3 and better readability
* Optimized code for compressing GPX files
* Whitespaces fixed
* Avoid regex pattern for file name
* Added Spanish translations
* Improved translations
* Added PHP 7 dependency
* Changed my name
0.3.13: 0.3.13:
--- ---
* OpenLayers updated to v7.2.2 * OpenLayers updated to v7.2.2

View file

@ -1,5 +1,4 @@
<?php <?php
@define('PLUGIN_EVENT_OSM_NAME', 'OpenStreetMap Integration'); @define('PLUGIN_EVENT_OSM_NAME', 'OpenStreetMap Integration');
@define('PLUGIN_EVENT_OSM_DESCRIPTION', 'Bietet eine interaktive Karte für *.gpx Uploads und Blogs mit Geo-Daten'); @define('PLUGIN_EVENT_OSM_DESCRIPTION', 'Bietet eine interaktive Karte für *.gpx Uploads und Blogs mit Geo-Daten');
@define('PLUGIN_EVENT_OSM_NOT_SHOWN', 'Wird nicht auf der Webseite angezeigt'); @define('PLUGIN_EVENT_OSM_NOT_SHOWN', 'Wird nicht auf der Webseite angezeigt');
@ -18,6 +17,6 @@
@define('PLUGIN_EVENT_OSM_LONG', 'Längengrad (Lon.)'); @define('PLUGIN_EVENT_OSM_LONG', 'Längengrad (Lon.)');
@define('PLUGIN_EVENT_OSM_LONG_DESCRIPTION', 'Längengrad für die Mitte der Karte'); @define('PLUGIN_EVENT_OSM_LONG_DESCRIPTION', 'Längengrad für die Mitte der Karte');
@define('PLUGIN_EVENT_OSM_ZOOM', 'Zoom'); @define('PLUGIN_EVENT_OSM_ZOOM', 'Zoom');
@define('PLUGIN_EVENT_OSM_ZOOM_DESCRIPTION', 'Zoom Level der Karte'); @define('PLUGIN_EVENT_OSM_ZOOM_DESCRIPTION', 'Zoom-Level der Karte');
@define('PLUGIN_EVENT_OSM_HEIGHT', 'Kartenhöhe'); @define('PLUGIN_EVENT_OSM_HEIGHT', 'Kartenhöhe');
@define('PLUGIN_EVENT_OSM_HEIGHT_DESCRIPTION', 'Die Höhe der Karte'); @define('PLUGIN_EVENT_OSM_HEIGHT_DESCRIPTION', 'Kartehöhe mit CSS-Einheit (px, em, usw.)');

View file

@ -0,0 +1,22 @@
<?php
@define('PLUGIN_EVENT_OSM_NAME', 'Integración de OpenStreetMap');
@define('PLUGIN_EVENT_OSM_DESCRIPTION', 'Ofrece un mapa interactivo para archivos *.gpx y entradas de blog con coordenadas geográficas');
@define('PLUGIN_EVENT_OSM_NOT_SHOWN', 'No se muestra en el sitio web');
@define('PLUGIN_EVENT_STATIC_OSM_NAME', 'Archivos estáticos de OpenStreetMap');
@define('PLUGIN_EVENT_STATIC_OSM_DESCRIPTION', 'Inserta scripts y hojas de estilo para OpenStreetMap');
@define('PLUGIN_EVENT_STATIC_OSM_COMPRESS_GPX', 'Comprimir archivos GPX');
@define('PLUGIN_EVENT_STATIC_OSM_COMPRESS_GPX_DESCRIPTION', 'Elimina todos los datos innecesarios de los archivos GPX durante la carga');
@define('PLUGIN_EVENT_OSM_CATEGORY', 'Categoría');
@define('PLUGIN_EVENT_OSM_CATEGORY_DESCRIPTION', 'El mapa se muestra para esta categoría');
@define('PLUGIN_EVENT_OSM_CATEGORY_WITHOUT', 'Sin');
@define('PLUGIN_EVENT_OSM_CATEGORY_ANY', 'Cualquier');
@define('PLUGIN_EVENT_OSM_PATH', 'CarpetaPfad');
@define('PLUGIN_EVENT_OSM_PATH_DESCRIPTION', 'Carpeta para los archivos GPX, separados por saltos de línea');
@define('PLUGIN_EVENT_OSM_LAT', 'Latitud (Lat.)');
@define('PLUGIN_EVENT_OSM_LAT_DESCRIPTION', 'Latitud del centro del mapa');
@define('PLUGIN_EVENT_OSM_LONG', 'Longitud (Lon.)');
@define('PLUGIN_EVENT_OSM_LONG_DESCRIPTION', 'Longitud del centro del mapa');
@define('PLUGIN_EVENT_OSM_ZOOM', 'Zoom');
@define('PLUGIN_EVENT_OSM_ZOOM_DESCRIPTION', 'Nivel de zoom del mapa');
@define('PLUGIN_EVENT_OSM_HEIGHT', 'Altura del mapa');
@define('PLUGIN_EVENT_OSM_HEIGHT_DESCRIPTION', 'Altura del mapa con unidad CSS (px, em, etc.)');

View file

@ -17,6 +17,6 @@
@define('PLUGIN_EVENT_OSM_LONG', 'Längengrad (Lon.)'); @define('PLUGIN_EVENT_OSM_LONG', 'Längengrad (Lon.)');
@define('PLUGIN_EVENT_OSM_LONG_DESCRIPTION', 'Längengrad für die Mitte der Karte'); @define('PLUGIN_EVENT_OSM_LONG_DESCRIPTION', 'Längengrad für die Mitte der Karte');
@define('PLUGIN_EVENT_OSM_ZOOM', 'Zoom'); @define('PLUGIN_EVENT_OSM_ZOOM', 'Zoom');
@define('PLUGIN_EVENT_OSM_ZOOM_DESCRIPTION', 'Zoom Level der Karte'); @define('PLUGIN_EVENT_OSM_ZOOM_DESCRIPTION', 'Zoom-Level der Karte');
@define('PLUGIN_EVENT_OSM_HEIGHT', 'Kartenhöhe'); @define('PLUGIN_EVENT_OSM_HEIGHT', 'Kartenhöhe');
@define('PLUGIN_EVENT_OSM_HEIGHT_DESCRIPTION', 'Die Höhe der Karte'); @define('PLUGIN_EVENT_OSM_HEIGHT_DESCRIPTION', 'Kartehöhe mit CSS-Einheit (px, em, usw.)');

View file

@ -1,6 +1,6 @@
<?php <?php
@define('PLUGIN_EVENT_OSM_NAME', 'OpenStreetMap integration'); @define('PLUGIN_EVENT_OSM_NAME', 'OpenStreetMap integration');
@define('PLUGIN_EVENT_OSM_DESCRIPTION', 'Provides an interactive map with *.gpx uploads and tagged geo data'); @define('PLUGIN_EVENT_OSM_DESCRIPTION', 'Provides an interactive map for *.gpx uploads and geo-tagged entries');
@define('PLUGIN_EVENT_OSM_NOT_SHOWN', 'Not shows on webpage'); @define('PLUGIN_EVENT_OSM_NOT_SHOWN', 'Not shows on webpage');
@define('PLUGIN_EVENT_STATIC_OSM_NAME', 'OpenStreetMap static files'); @define('PLUGIN_EVENT_STATIC_OSM_NAME', 'OpenStreetMap static files');
@define('PLUGIN_EVENT_STATIC_OSM_DESCRIPTION', 'Includes scripts and stylesheets for OpenStreetMap support'); @define('PLUGIN_EVENT_STATIC_OSM_DESCRIPTION', 'Includes scripts and stylesheets for OpenStreetMap support');
@ -19,4 +19,4 @@
@define('PLUGIN_EVENT_OSM_ZOOM', 'Zoom'); @define('PLUGIN_EVENT_OSM_ZOOM', 'Zoom');
@define('PLUGIN_EVENT_OSM_ZOOM_DESCRIPTION', 'Zoom level of the map'); @define('PLUGIN_EVENT_OSM_ZOOM_DESCRIPTION', 'Zoom level of the map');
@define('PLUGIN_EVENT_OSM_HEIGHT', 'Map height'); @define('PLUGIN_EVENT_OSM_HEIGHT', 'Map height');
@define('PLUGIN_EVENT_OSM_HEIGHT_DESCRIPTION', 'The height of the map'); @define('PLUGIN_EVENT_OSM_HEIGHT_DESCRIPTION', 'Map height with CSS unit (px, em, etc.)');

View file

@ -0,0 +1,23 @@
<?php
@define('PLUGIN_EVENT_OSM_NAME', 'Integración de OpenStreetMap');
@define('PLUGIN_EVENT_OSM_DESCRIPTION', 'Ofrece un mapa interactivo para archivos *.gpx y entradas de blog con coordenadas geográficas');
@define('PLUGIN_EVENT_OSM_NOT_SHOWN', 'No se muestra en el sitio web');
@define('PLUGIN_EVENT_STATIC_OSM_NAME', 'Archivos estáticos de OpenStreetMap');
@define('PLUGIN_EVENT_STATIC_OSM_DESCRIPTION', 'Inserta scripts y hojas de estilo para OpenStreetMap');
@define('PLUGIN_EVENT_STATIC_OSM_COMPRESS_GPX', 'Comprimir archivos GPX');
@define('PLUGIN_EVENT_STATIC_OSM_COMPRESS_GPX_DESCRIPTION', 'Elimina todos los datos innecesarios de los archivos GPX durante la carga');
@define('PLUGIN_EVENT_OSM_CATEGORY', 'Categoría');
@define('PLUGIN_EVENT_OSM_CATEGORY_DESCRIPTION', 'El mapa se muestra para esta categoría');
@define('PLUGIN_EVENT_OSM_CATEGORY_WITHOUT', 'Sin');
@define('PLUGIN_EVENT_OSM_CATEGORY_ANY', 'Cualquier');
@define('PLUGIN_EVENT_OSM_PATH', 'CarpetaPfad');
@define('PLUGIN_EVENT_OSM_PATH_DESCRIPTION', 'Carpeta para los archivos GPX, separados por saltos de línea');
@define('PLUGIN_EVENT_OSM_LAT', 'Latitud (Lat.)');
@define('PLUGIN_EVENT_OSM_LAT_DESCRIPTION', 'Latitud del centro del mapa');
@define('PLUGIN_EVENT_OSM_LONG', 'Longitud (Lon.)');
@define('PLUGIN_EVENT_OSM_LONG_DESCRIPTION', 'Longitud del centro del mapa');
@define('PLUGIN_EVENT_OSM_ZOOM', 'Zoom');
@define('PLUGIN_EVENT_OSM_ZOOM_DESCRIPTION', 'Nivel de zoom del mapa');
@define('PLUGIN_EVENT_OSM_HEIGHT', 'Altura del mapa');
@define('PLUGIN_EVENT_OSM_HEIGHT_DESCRIPTION', 'Altura del mapa con unidad CSS (px, em, etc.)');

View file

@ -1,3 +1,3 @@
<?php <?php
@define('PLUGIN_EVENT_OSM_VERSION', '0.3.13'); @define('PLUGIN_EVENT_OSM_VERSION', '0.4.0');
@define('PLUGIN_EVENT_OSM_AUTHOR', 'Martin Sewelies'); @define('PLUGIN_EVENT_OSM_AUTHOR', 'Kathi Sewelies');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,26 +1,27 @@
const dateToColor = date => { const dateToColor = date => {
const minDate = new Date(date.getFullYear(), date.getMonth() - 1, 0); const minDate = new Date(date.getFullYear(), date.getMonth() - 1, 0);
const maxDate = new Date(date.getFullYear(), date.getMonth(), 0); const maxDate = new Date(date.getFullYear(), date.getMonth(), 0);
return "hsl(" + ((date.getTime() - minDate.getTime()) / (maxDate.getTime() - minDate.getTime())).toFixed(3) + "turn, 100%, 50%)" return "hsl(" + ((date.getTime() - minDate.getTime()) / (maxDate.getTime() - minDate.getTime())).toFixed(3) + "turn, 100%, 50%)";
}; };
window.addEventListener("load", () => { window.addEventListener("load", () => {
document.querySelectorAll("div.map").forEach(divMap => { document.querySelectorAll("div.map").forEach(divMap => {
const popup = document.createElement("div"); const popup = document.createElement("div");
popup.setAttribute("class", "ol-popup"); popup.setAttribute("class", "ol-popup");
const overlay = new ol.Overlay({
element: popup
});
popup.onclick = () => { popup.onclick = () => {
overlay.setPosition(undefined); overlay.setPosition(undefined);
}; };
const overlay = new ol.Overlay({ const dataset = divMap.dataset;
element: popup const articles = geo.articles
}); .filter(article => ["all", "none"].includes(dataset.category) || article.categories.includes(parseInt(dataset.category)));
const tracks = geo.tracks
const data = divMap.dataset; .filter(track => dataset.path.split("\n").some(y => track.url.startsWith(y)));
const entries = geo.entries.filter(x => ["all", "none"].includes(data.category) || x.categories.includes(parseInt(data.category))); const features = articles.map((article, id) => {
const uploads = geo.uploads.filter(x => data.path.split("\n").some(y => x.url.startsWith(y))); const feature = new ol.Feature(new ol.geom.Point(ol.proj.fromLonLat(article.location.reverse())));
const features = entries.map((entry, id) => {
const feature = new ol.Feature(new ol.geom.Point(ol.proj.fromLonLat(entry.pos.reverse())));
feature.setId(id); feature.setId(id);
return feature; return feature;
}); });
@ -32,8 +33,8 @@ window.addEventListener("load", () => {
source: new ol.source.Vector({features: features}), source: new ol.source.Vector({features: features}),
style: feature => { style: feature => {
const id = feature.getId(); const id = feature.getId();
const entry = entries[id]; const article = articles[id];
const date = new Date(entry.date * 1000); const date = new Date(article.date * 1000);
return new ol.style.Style({ return new ol.style.Style({
image: new ol.style.Circle({ image: new ol.style.Circle({
@ -45,19 +46,20 @@ window.addEventListener("load", () => {
zIndex: Infinity zIndex: Infinity
}) })
]; ];
for (const upload of uploads) { const unixTime = Date.now() / 1000;
for (const track of tracks) {
const source = new ol.source.Vector({ const source = new ol.source.Vector({
url: upload.url, url: track.url,
format: new ol.format.GPX() format: new ol.format.GPX()
}); });
source.on("featuresloadend", event => { source.on("featuresloadend", event => {
upload.length = event.features track.distance = event.features
.filter(feature => feature.getGeometry().getType() === "MultiLineString") .filter(feature => feature.getGeometry().getType() === "MultiLineString")
.map(feature => ol.sphere.getLength(feature.getGeometry())) .map(feature => ol.sphere.getLength(feature.getGeometry()))
.reduce((a, b) => a + b, 0); .reduce((a, b) => a + b, 0);
}); });
const color = dateToColor(new Date(upload.date * 1000)); const color = dateToColor(new Date(track.date * 1000));
const lineDash = upload.date * 1000 > Date.now() ? [3, 6] : undefined; const lineDash = track.date > unixTime ? [3, 6] : undefined;
const layer = new ol.layer.VectorImage({ const layer = new ol.layer.VectorImage({
source: source, source: source,
style: feature => feature.getGeometry().getType() === "MultiLineString" style: feature => feature.getGeometry().getType() === "MultiLineString"
@ -93,8 +95,8 @@ window.addEventListener("load", () => {
overlays: [overlay], overlays: [overlay],
target: divMap, target: divMap,
view: new ol.View({ view: new ol.View({
center: ol.proj.fromLonLat([data.longitude, data.latitude]), center: ol.proj.fromLonLat([dataset.longitude, dataset.latitude]),
zoom: data.zoom zoom: dataset.zoom
}) })
}); });
@ -110,9 +112,21 @@ window.addEventListener("load", () => {
a.setAttribute("title", a.setAttribute("title",
(object.author !== undefined ? object.author + ", " : "") (object.author !== undefined ? object.author + ", " : "")
+ +
new Date(object.date * 1000).toLocaleString(undefined, {year: "numeric", month: "long", day: "2-digit", hour: "2-digit", minute: "2-digit"}) new Date(object.date * 1000).toLocaleString(undefined, {
year: "numeric",
month: "long",
day: "2-digit",
hour: "2-digit",
minute: "2-digit"
})
+ +
(object.length !== undefined ? ", " + (object.length / 1000).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}) + "km" : "") (object.distance !== undefined
? ", " + (object.distance / 1000).toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2
}) + "km"
: ""
)
); );
return a; return a;
})() })()
@ -121,32 +135,39 @@ window.addEventListener("load", () => {
return li; return li;
}; };
const foundEntries = []; const foundArticles = [];
const foundUploads = []; const foundTracks = [];
map.forEachFeatureAtPixel(event.pixel, (feature, layer) => { map.forEachFeatureAtPixel(event.pixel, (feature, layer) => {
const id = feature.getId(); const id = feature.getId();
if (id !== undefined) { if (id !== undefined) {
foundEntries.push(id); foundArticles.push(id);
} else { } else {
const url = layer.getSource().getUrl(); const url = layer.getSource().getUrl();
const id = uploads.findIndex(upload => upload.url === url); const id = tracks.findIndex(track => track.url === url);
foundUploads.push(id); foundTracks.push(id);
} }
}, {hitTolerance: 10}); }, {hitTolerance: 10});
foundEntries.sort((x, y) => x - y); foundArticles.sort();
foundUploads.sort((x, y) => x - y); foundTracks.sort();
if (foundEntries.length || foundUploads.length) { if (foundArticles.length || foundTracks.length) {
const initUl = title => { const initUl = title => {
const ul = document.createElement("ul"); const ul = document.createElement("ul");
ul.setAttribute("data-title", title); ul.setAttribute("data-title", title);
return ul; return ul;
}; };
const ulEntries = foundEntries.map(x => makeItem(entries[x])).reduce((x, y) => {x.appendChild(y); return x;}, initUl("Blogs")); const ulArticles = foundArticles
const ulUploads = foundUploads.map(x => makeItem(uploads[x])).reduce((x, y) => {x.appendChild(y); return x;}, initUl("Downloads")); .map(x => makeItem(articles[x]))
popup.innerHTML = (foundEntries.length ? ulEntries.outerHTML : "") + (foundUploads.length ? ulUploads.outerHTML : ""); .reduce((x, y) => {x.appendChild(y); return x;}, initUl("Articles"));
overlay.setPosition(foundEntries.length ? ol.proj.fromLonLat( const ulTracks = foundTracks
[0, 1].map(latLon => foundEntries.map(x => entries[x].pos[latLon]).reduce((x, y) => x + y, 0) / foundEntries.length) .map(x => makeItem(tracks[x]))
.reduce((x, y) => {x.appendChild(y); return x;}, initUl("Tracks"));
popup.innerHTML = (foundArticles.length ? ulArticles.outerHTML : "") + (foundTracks.length ? ulTracks.outerHTML : "");
overlay.setPosition(foundArticles.length ? ol.proj.fromLonLat(
[0, 1].map(latLon => foundArticles
.map(x => articles[x].location[latLon])
.reduce((x, y) => x + y, 0) / foundArticles.length
)
) : event.coordinate); ) : event.coordinate);
} else { } else {
overlay.setPosition(undefined); overlay.setPosition(undefined);
@ -158,9 +179,12 @@ window.addEventListener("load", () => {
divMap.style.cursor = hit ? "pointer" : ""; divMap.style.cursor = hit ? "pointer" : "";
}); });
map.on("rendercomplete", event => { map.on("rendercomplete", event => {
const distance = uploads.map(u => u.length).reduce((a, b) => a + b, 0); const distance = tracks
document.querySelectorAll("span.distance-counter[data-category=\"" + data.category + "\"]").forEach(span => { .filter(track => track.date < unixTime)
span.innerHTML = (distance / 1000).toLocaleString(undefined, {minimumFractionDigits: 0, maximumFractionDigits: 0}); .map(track => track.distance)
.reduce((a, b) => a + b, 0);
document.querySelectorAll("span.distance-counter[data-category=\"" + dataset.category + "\"]").forEach(span => {
span.innerHTML = (distance / 1000).toFixed(0);
}); });
}); });
}); });

View file

@ -18,10 +18,10 @@ class serendipity_event_osm extends serendipity_event
$propbag->add('event_hooks', array('entries_header' => true)); $propbag->add('event_hooks', array('entries_header' => true));
$propbag->add('author', PLUGIN_EVENT_OSM_AUTHOR); $propbag->add('author', PLUGIN_EVENT_OSM_AUTHOR);
$propbag->add('version', PLUGIN_EVENT_OSM_VERSION); $propbag->add('version', PLUGIN_EVENT_OSM_VERSION);
$propbag->add('requirements', array( $propbag->add('requirements', [
'php' => '7.0.0', 'php' => '7.0.0',
'serendipity' => '2.3' 'serendipity' => '2.3'
)); ]);
$propbag->add('stackable', true); $propbag->add('stackable', true);
$propbag->add('groups', array('FRONTEND_ENTRY_RELATED')); $propbag->add('groups', array('FRONTEND_ENTRY_RELATED'));
$this->dependencies = array( $this->dependencies = array(

View file

@ -22,6 +22,7 @@ class serendipity_event_static_osm extends serendipity_event
$propbag->add('author', PLUGIN_EVENT_OSM_AUTHOR); $propbag->add('author', PLUGIN_EVENT_OSM_AUTHOR);
$propbag->add('version', PLUGIN_EVENT_OSM_VERSION); $propbag->add('version', PLUGIN_EVENT_OSM_VERSION);
$propbag->add('requirements', [ $propbag->add('requirements', [
'php' => '7.0.0',
'serendipity' => '2.3' 'serendipity' => '2.3'
]); ]);
$propbag->add('stackable', false); $propbag->add('stackable', false);
@ -39,38 +40,34 @@ class serendipity_event_static_osm extends serendipity_event
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 ' <link rel="stylesheet" href="'.$this->getFile('ressources/ol.css', 'serendipityHTTPPath').'" type="text/css" />'.PHP_EOL; echo ' <link rel="stylesheet" href="' . $this->getFile('ressources/ol.css', 'serendipityHTTPPath') . '" type="text/css" />' . PHP_EOL;
echo ' <link rel="stylesheet" href="'.$this->getFile('ressources/osm.css', 'serendipityHTTPPath').'" type="text/css" />'.PHP_EOL; echo ' <link rel="stylesheet" href="' . $this->getFile('ressources/osm.css', 'serendipityHTTPPath') . '" type="text/css" />' . PHP_EOL;
echo ' <script src="'.$this->getFile('ressources/ol.js', 'serendipityHTTPPath').'"></script>'.PHP_EOL; echo ' <script src="' . $this->getFile('ressources/ol.js', 'serendipityHTTPPath') . '"></script>' . PHP_EOL;
echo ' <script src="'.$this->getFile('ressources/osm.js', 'serendipityHTTPPath').'"></script>'.PHP_EOL; echo ' <script src="' . $this->getFile('ressources/osm.js', 'serendipityHTTPPath') . '"></script>' . PHP_EOL;
} else if ($event === 'backend_image_add') { } else if ($event === 'backend_image_add') {
if (preg_match('/\\.gpx$/i', mb_strtolower($eventData)) && $this->get_config('compress_gpx', true) === true) { $fileName = $eventData;
$fileName = $eventData; if (str_ends_with(strtolower($fileName), '.gpx') && $this->get_config('compress_gpx', true) === true) {
$tmpFile = tmpfile(); $gpx = new SimpleXMLElement($fileName, dataIsURL: true);
fwrite($tmpFile, '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><gpx version="1.1" creator="surrim.org" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">'); $tmpGpx = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><gpx version="1.1" creator="surrim.org" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"></gpx>');
$gpx = simplexml_load_file($fileName);
foreach (($gpx->trk ?? []) as $trk) { foreach (($gpx->trk ?? []) as $trk) {
fwrite($tmpFile, '<trk>'); $tmpTrk = $tmpGpx->addChild('trk');
foreach (($trk->trkseg ?? []) as $seg) { foreach (($trk->trkseg ?? []) as $trkseg) {
fwrite($tmpFile, '<trkseg>'); $tmpTrkseg = $tmpTrk->addChild('trkseg');
foreach (($seg->trkpt ?? []) as $pt) { foreach (($trkseg->trkpt ?? []) as $trkpt) {
fwrite($tmpFile, '<trkpt lat="'.$pt['lat'].'" lon="'.$pt['lon'].'"><ele>'.$pt->ele.'</ele></trkpt>'); $tmpTrkpt = $tmpTrkseg->addChild('trkpt');
$tmpTrkpt->addAttribute('lat', $trkpt['lat']);
$tmpTrkpt->addAttribute('lon', $trkpt['lon']);
if ($trkpt->ele != '') {
$tmpTrkpt->addChild('ele', $trkpt->ele);
}
} }
fwrite($tmpFile, '</trkseg>');
} }
fwrite($tmpFile, '</trk>');
} }
fwrite($tmpFile, '</gpx>'); $tmpGpx->asXML($fileName);
$fileSize = ftell($tmpFile); clearstatcache(true, $fileName);
unset($gpx);
rewind($tmpFile);
$file = fopen($fileName, 'w');
stream_copy_to_stream($tmpFile, $file, $fileSize);
fclose($file);
fclose($tmpFile);
$fileId = $addData['image_id']; $fileId = $addData['image_id'];
$fileSize = filesize($fileName);
serendipity_updateImageInDatabase(['size' => $fileSize], $fileId); serendipity_updateImageInDatabase(['size' => $fileSize], $fileId);
} }
} }