diff --git a/appinfo/routes.php b/appinfo/routes.php index 4d81662..4988c91 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -20,5 +20,7 @@ return [ 'routes' => [ ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], + ['name' => 'page#getgpx', 'url' => '/getgpx', 'verb' => 'POST'], + ['name' => 'page#savegpx', 'url' => '/savegpx', 'verb' => 'POST'], ] ]; diff --git a/controller/pagecontroller.php b/controller/pagecontroller.php index 53f74c1..cbb3eb2 100644 --- a/controller/pagecontroller.php +++ b/controller/pagecontroller.php @@ -180,4 +180,97 @@ class PageController extends Controller { return $response; } + /** + * + * @NoAdminRequired + * @NoCSRFRequired + */ + public function getgpx($path) { + $userFolder = \OC::$server->getUserFolder(); + $cleanpath = str_replace(array('../', '..\\'), '', $path); + $gpxContent = ''; + if ($userFolder->nodeExists($cleanpath)){ + $file = $userFolder->get($cleanpath); + if ($file->getType() === \OCP\Files\FileInfo::TYPE_FILE and + (endswith($file->getName(), '.GPX') or endswith($file->getName(), '.gpx')) + ){ + // all ok + } + else{ + $file = null; + } + } + + if ($file !== null){ + $gpxContent = $file->getContent(); + } + + $response = new DataResponse( + [ + 'gpx'=>$gpxContent + ] + ); + $csp = new ContentSecurityPolicy(); + $csp->addAllowedImageDomain('*') + ->addAllowedMediaDomain('*') + ->addAllowedConnectDomain('*'); + $response->setContentSecurityPolicy($csp); + return $response; + } + + /** + * + * @NoAdminRequired + * @NoCSRFRequired + */ + public function savegpx($path, $content) { + $userFolder = \OC::$server->getUserFolder(); + $cleanpath = str_replace(array('../', '..\\'), '', $path); + $status = false; + if (endswith($cleanpath, '.GPX') or endswith($cleanpath, '.gpx')){ + if ($userFolder->nodeExists($cleanpath)){ + $file = $userFolder->get($cleanpath); + if ($file->getType() === \OCP\Files\FileInfo::TYPE_FILE and + $file->isUpdateable()){ + $file->putContent($content); + $status = true; + } + else{ + $status = 'fiw'; + } + } + else{ + $dirpath = dirname($cleanpath); + $newFileName = basename($cleanpath); + if ($userFolder->nodeExists($dirpath)){ + $dir = $userFolder->get($dirpath); + if ($dir->getType() === \OCP\Files\FileInfo::TYPE_FOLDER and + $dir->isCreatable()){ + $dir->newFile($newFileName); + $dir->get($newFileName)->putContent($content); + $status = true; + } + else{ + $status = 'fw'; + } + } + else{ + $status = 'fu'; + } + } + } + + $response = new DataResponse( + [ + 'status'=>$status + ] + ); + $csp = new ContentSecurityPolicy(); + $csp->addAllowedImageDomain('*') + ->addAllowedMediaDomain('*') + ->addAllowedConnectDomain('*'); + $response->setContentSecurityPolicy($csp); + return $response; + } + } diff --git a/css/gpxedit.css b/css/gpxedit.css index 6cd9950..549459b 100644 --- a/css/gpxedit.css +++ b/css/gpxedit.css @@ -224,7 +224,7 @@ h3 { margin-left:20px; list-style-type:circle; } -#loading, #loadingmarkers, #deleting { +#saved { /*width: 330px;*/ padding-left: 5px; /*height: 35px;*/ @@ -244,15 +244,11 @@ h3 { display:none; /*z-index: 1000;*/ } -#loading .fa, #loadingmarkers .fa, #deleting .fa { +#saved .fa { font-size: 22px; } -#loadingmarkers { - background-color: green; -} - -#loading p, #loadingmarkers p, #deleting p{ +#saved p{ padding: 6px 6px 6px 6px; } .clear { diff --git a/js/gpxedit.js b/js/gpxedit.js index 8dfbcbf..1e26e46 100644 --- a/js/gpxedit.js +++ b/js/gpxedit.js @@ -396,6 +396,19 @@ function parseGpx(xml){ }); } +// remove layers from map and delete all layers data +function clear(){ + var layersToRemove = []; + gpxedit.editableLayers.eachLayer(function (layer) { + delete gpxedit.layersData[layer.gpxedit_id]; + layersToRemove.push(layer); + }); + + for(var i=0; i droitplop\nplap yeye unnamedplop '); + + $('button#getButton').click(function(e){ + var req = { + path : $('input#getPath').val() + } + var url = OC.generateUrl('/apps/gpxedit/getgpx'); + $.post(url, req).done(function (response) { + clear(); + if (response.gpx === ''){ + alert('The file does not exist or it is not a gpx'); + } + else{ + parseGpx(response.gpx); + var bounds = gpxedit.editableLayers.getBounds(); + gpxedit.map.fitBounds(bounds, + {animate:true, paddingTopLeft: [parseInt($('#sidebar').css('width')), 0]} + ); + } + }); }); - parseGpx(' droitplop\nplap yeye unnamedplop '); }); diff --git a/templates/gpxcontent.php b/templates/gpxcontent.php index 37042a7..28aafcc 100644 --- a/templates/gpxcontent.php +++ b/templates/gpxcontent.php @@ -52,9 +52,18 @@ if (count($_['dirs']) === 0){

+ + +
+

+ +

+ + t('File saved')); ?> 

+
';