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:
parent
736d2bfeaa
commit
b35019c7ce
|
@ -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:
|
||||
---
|
||||
* OpenLayers updated to v7.2.2
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
@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_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_DESCRIPTION', 'Längengrad für die Mitte der Karte');
|
||||
@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_DESCRIPTION', 'Die Höhe der Karte');
|
||||
@define('PLUGIN_EVENT_OSM_HEIGHT_DESCRIPTION', 'Kartehöhe mit CSS-Einheit (px, em, usw.)');
|
||||
|
|
22
serendipity_event_osm/UTF-8/lang_es.inc.php
Normal file
22
serendipity_event_osm/UTF-8/lang_es.inc.php
Normal 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.)');
|
|
@ -17,6 +17,6 @@
|
|||
@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_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_DESCRIPTION', 'Die Höhe der Karte');
|
||||
@define('PLUGIN_EVENT_OSM_HEIGHT_DESCRIPTION', 'Kartehöhe mit CSS-Einheit (px, em, usw.)');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
@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_STATIC_OSM_NAME', 'OpenStreetMap static files');
|
||||
@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_DESCRIPTION', 'Zoom level of the map');
|
||||
@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.)');
|
||||
|
|
23
serendipity_event_osm/lang_es.inc.php
Normal file
23
serendipity_event_osm/lang_es.inc.php
Normal 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.)');
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
<?php
|
||||
@define('PLUGIN_EVENT_OSM_VERSION', '0.3.13');
|
||||
@define('PLUGIN_EVENT_OSM_AUTHOR', 'Martin Sewelies');
|
||||
@define('PLUGIN_EVENT_OSM_VERSION', '0.4.0');
|
||||
@define('PLUGIN_EVENT_OSM_AUTHOR', 'Kathi Sewelies');
|
||||
|
|
1
serendipity_event_osm/ressources/ol.css.map
Normal file
1
serendipity_event_osm/ressources/ol.css.map
Normal file
File diff suppressed because one or more lines are too long
1
serendipity_event_osm/ressources/ol.js.map
Normal file
1
serendipity_event_osm/ressources/ol.js.map
Normal file
File diff suppressed because one or more lines are too long
|
@ -1,26 +1,27 @@
|
|||
const dateToColor = date => {
|
||||
const minDate = new Date(date.getFullYear(), date.getMonth() - 1, 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", () => {
|
||||
document.querySelectorAll("div.map").forEach(divMap => {
|
||||
const popup = document.createElement("div");
|
||||
popup.setAttribute("class", "ol-popup");
|
||||
const overlay = new ol.Overlay({
|
||||
element: popup
|
||||
});
|
||||
popup.onclick = () => {
|
||||
overlay.setPosition(undefined);
|
||||
};
|
||||
|
||||
const overlay = new ol.Overlay({
|
||||
element: popup
|
||||
});
|
||||
|
||||
const data = divMap.dataset;
|
||||
const entries = geo.entries.filter(x => ["all", "none"].includes(data.category) || x.categories.includes(parseInt(data.category)));
|
||||
const uploads = geo.uploads.filter(x => data.path.split("\n").some(y => x.url.startsWith(y)));
|
||||
const features = entries.map((entry, id) => {
|
||||
const feature = new ol.Feature(new ol.geom.Point(ol.proj.fromLonLat(entry.pos.reverse())));
|
||||
const dataset = divMap.dataset;
|
||||
const articles = geo.articles
|
||||
.filter(article => ["all", "none"].includes(dataset.category) || article.categories.includes(parseInt(dataset.category)));
|
||||
const tracks = geo.tracks
|
||||
.filter(track => dataset.path.split("\n").some(y => track.url.startsWith(y)));
|
||||
const features = articles.map((article, id) => {
|
||||
const feature = new ol.Feature(new ol.geom.Point(ol.proj.fromLonLat(article.location.reverse())));
|
||||
feature.setId(id);
|
||||
return feature;
|
||||
});
|
||||
|
@ -32,8 +33,8 @@ window.addEventListener("load", () => {
|
|||
source: new ol.source.Vector({features: features}),
|
||||
style: feature => {
|
||||
const id = feature.getId();
|
||||
const entry = entries[id];
|
||||
const date = new Date(entry.date * 1000);
|
||||
const article = articles[id];
|
||||
const date = new Date(article.date * 1000);
|
||||
|
||||
return new ol.style.Style({
|
||||
image: new ol.style.Circle({
|
||||
|
@ -45,19 +46,20 @@ window.addEventListener("load", () => {
|
|||
zIndex: Infinity
|
||||
})
|
||||
];
|
||||
for (const upload of uploads) {
|
||||
const unixTime = Date.now() / 1000;
|
||||
for (const track of tracks) {
|
||||
const source = new ol.source.Vector({
|
||||
url: upload.url,
|
||||
url: track.url,
|
||||
format: new ol.format.GPX()
|
||||
});
|
||||
source.on("featuresloadend", event => {
|
||||
upload.length = event.features
|
||||
track.distance = event.features
|
||||
.filter(feature => feature.getGeometry().getType() === "MultiLineString")
|
||||
.map(feature => ol.sphere.getLength(feature.getGeometry()))
|
||||
.reduce((a, b) => a + b, 0);
|
||||
});
|
||||
const color = dateToColor(new Date(upload.date * 1000));
|
||||
const lineDash = upload.date * 1000 > Date.now() ? [3, 6] : undefined;
|
||||
const color = dateToColor(new Date(track.date * 1000));
|
||||
const lineDash = track.date > unixTime ? [3, 6] : undefined;
|
||||
const layer = new ol.layer.VectorImage({
|
||||
source: source,
|
||||
style: feature => feature.getGeometry().getType() === "MultiLineString"
|
||||
|
@ -93,8 +95,8 @@ window.addEventListener("load", () => {
|
|||
overlays: [overlay],
|
||||
target: divMap,
|
||||
view: new ol.View({
|
||||
center: ol.proj.fromLonLat([data.longitude, data.latitude]),
|
||||
zoom: data.zoom
|
||||
center: ol.proj.fromLonLat([dataset.longitude, dataset.latitude]),
|
||||
zoom: dataset.zoom
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -110,9 +112,21 @@ window.addEventListener("load", () => {
|
|||
a.setAttribute("title",
|
||||
(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;
|
||||
})()
|
||||
|
@ -121,32 +135,39 @@ window.addEventListener("load", () => {
|
|||
return li;
|
||||
};
|
||||
|
||||
const foundEntries = [];
|
||||
const foundUploads = [];
|
||||
const foundArticles = [];
|
||||
const foundTracks = [];
|
||||
map.forEachFeatureAtPixel(event.pixel, (feature, layer) => {
|
||||
const id = feature.getId();
|
||||
if (id !== undefined) {
|
||||
foundEntries.push(id);
|
||||
foundArticles.push(id);
|
||||
} else {
|
||||
const url = layer.getSource().getUrl();
|
||||
const id = uploads.findIndex(upload => upload.url === url);
|
||||
foundUploads.push(id);
|
||||
const id = tracks.findIndex(track => track.url === url);
|
||||
foundTracks.push(id);
|
||||
}
|
||||
}, {hitTolerance: 10});
|
||||
foundEntries.sort((x, y) => x - y);
|
||||
foundUploads.sort((x, y) => x - y);
|
||||
foundArticles.sort();
|
||||
foundTracks.sort();
|
||||
|
||||
if (foundEntries.length || foundUploads.length) {
|
||||
if (foundArticles.length || foundTracks.length) {
|
||||
const initUl = title => {
|
||||
const ul = document.createElement("ul");
|
||||
ul.setAttribute("data-title", title);
|
||||
return ul;
|
||||
};
|
||||
const ulEntries = foundEntries.map(x => makeItem(entries[x])).reduce((x, y) => {x.appendChild(y); return x;}, initUl("Blogs"));
|
||||
const ulUploads = foundUploads.map(x => makeItem(uploads[x])).reduce((x, y) => {x.appendChild(y); return x;}, initUl("Downloads"));
|
||||
popup.innerHTML = (foundEntries.length ? ulEntries.outerHTML : "") + (foundUploads.length ? ulUploads.outerHTML : "");
|
||||
overlay.setPosition(foundEntries.length ? ol.proj.fromLonLat(
|
||||
[0, 1].map(latLon => foundEntries.map(x => entries[x].pos[latLon]).reduce((x, y) => x + y, 0) / foundEntries.length)
|
||||
const ulArticles = foundArticles
|
||||
.map(x => makeItem(articles[x]))
|
||||
.reduce((x, y) => {x.appendChild(y); return x;}, initUl("Articles"));
|
||||
const ulTracks = foundTracks
|
||||
.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);
|
||||
} else {
|
||||
overlay.setPosition(undefined);
|
||||
|
@ -158,9 +179,12 @@ window.addEventListener("load", () => {
|
|||
divMap.style.cursor = hit ? "pointer" : "";
|
||||
});
|
||||
map.on("rendercomplete", event => {
|
||||
const distance = uploads.map(u => u.length).reduce((a, b) => a + b, 0);
|
||||
document.querySelectorAll("span.distance-counter[data-category=\"" + data.category + "\"]").forEach(span => {
|
||||
span.innerHTML = (distance / 1000).toLocaleString(undefined, {minimumFractionDigits: 0, maximumFractionDigits: 0});
|
||||
const distance = tracks
|
||||
.filter(track => track.date < unixTime)
|
||||
.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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -18,10 +18,10 @@ class serendipity_event_osm extends serendipity_event
|
|||
$propbag->add('event_hooks', array('entries_header' => true));
|
||||
$propbag->add('author', PLUGIN_EVENT_OSM_AUTHOR);
|
||||
$propbag->add('version', PLUGIN_EVENT_OSM_VERSION);
|
||||
$propbag->add('requirements', array(
|
||||
$propbag->add('requirements', [
|
||||
'php' => '7.0.0',
|
||||
'serendipity' => '2.3'
|
||||
));
|
||||
]);
|
||||
$propbag->add('stackable', true);
|
||||
$propbag->add('groups', array('FRONTEND_ENTRY_RELATED'));
|
||||
$this->dependencies = array(
|
||||
|
|
|
@ -22,6 +22,7 @@ class serendipity_event_static_osm extends serendipity_event
|
|||
$propbag->add('author', PLUGIN_EVENT_OSM_AUTHOR);
|
||||
$propbag->add('version', PLUGIN_EVENT_OSM_VERSION);
|
||||
$propbag->add('requirements', [
|
||||
'php' => '7.0.0',
|
||||
'serendipity' => '2.3'
|
||||
]);
|
||||
$propbag->add('stackable', false);
|
||||
|
@ -39,38 +40,34 @@ class serendipity_event_static_osm extends serendipity_event
|
|||
function event_hook($event, &$bag, &$eventData, $addData = null)
|
||||
{
|
||||
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/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/osm.js', 'serendipityHTTPPath').'"></script>'.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 ' <script src="' . $this->getFile('ressources/ol.js', 'serendipityHTTPPath') . '"></script>' . PHP_EOL;
|
||||
echo ' <script src="' . $this->getFile('ressources/osm.js', 'serendipityHTTPPath') . '"></script>' . PHP_EOL;
|
||||
} else if ($event === 'backend_image_add') {
|
||||
if (preg_match('/\\.gpx$/i', mb_strtolower($eventData)) && $this->get_config('compress_gpx', true) === true) {
|
||||
$fileName = $eventData;
|
||||
$tmpFile = tmpfile();
|
||||
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">');
|
||||
$gpx = simplexml_load_file($fileName);
|
||||
$fileName = $eventData;
|
||||
if (str_ends_with(strtolower($fileName), '.gpx') && $this->get_config('compress_gpx', true) === true) {
|
||||
$gpx = new SimpleXMLElement($fileName, dataIsURL: true);
|
||||
$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>');
|
||||
foreach (($gpx->trk ?? []) as $trk) {
|
||||
fwrite($tmpFile, '<trk>');
|
||||
foreach (($trk->trkseg ?? []) as $seg) {
|
||||
fwrite($tmpFile, '<trkseg>');
|
||||
foreach (($seg->trkpt ?? []) as $pt) {
|
||||
fwrite($tmpFile, '<trkpt lat="'.$pt['lat'].'" lon="'.$pt['lon'].'"><ele>'.$pt->ele.'</ele></trkpt>');
|
||||
$tmpTrk = $tmpGpx->addChild('trk');
|
||||
foreach (($trk->trkseg ?? []) as $trkseg) {
|
||||
$tmpTrkseg = $tmpTrk->addChild('trkseg');
|
||||
foreach (($trkseg->trkpt ?? []) as $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>');
|
||||
$fileSize = ftell($tmpFile);
|
||||
unset($gpx);
|
||||
|
||||
rewind($tmpFile);
|
||||
$file = fopen($fileName, 'w');
|
||||
stream_copy_to_stream($tmpFile, $file, $fileSize);
|
||||
fclose($file);
|
||||
fclose($tmpFile);
|
||||
$tmpGpx->asXML($fileName);
|
||||
clearstatcache(true, $fileName);
|
||||
|
||||
$fileId = $addData['image_id'];
|
||||
$fileSize = filesize($fileName);
|
||||
serendipity_updateImageInDatabase(['size' => $fileSize], $fileId);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue