diff --git a/CHANGELOG.md b/CHANGELOG.md
index bd335ea..1a12484 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,3 +5,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
+### Added
+- ability to load kml and csv (unicsv format) files
+ [#1](https://gitlab.com/eneiluj/gpxedit-oc/issues/1) @eneiluj
diff --git a/controller/pagecontroller.php b/controller/pagecontroller.php
index 8b693a8..c0248a0 100644
--- a/controller/pagecontroller.php
+++ b/controller/pagecontroller.php
@@ -181,6 +181,53 @@ class PageController extends Controller {
return $response;
}
+
+ /**
+ * convert the given file (csv or kml) to gpx and return its content
+ */
+ public function toGpx($file){
+ $gpsbabel_path = getProgramPath('gpsbabel');
+ $data_folder = $this->userAbsoluteDataPath;
+ $tempdir = $data_folder.'/../cache/'.rand();
+ mkdir($tempdir);
+
+ $filename = $file->getName();
+ $filecontent = $file->getContent();
+ $file_clear_path = $tempdir.'/'.$filename;
+ $gpx_target_clear_path = $tempdir.'/'.$filename.'.gpx';
+ file_put_contents($file_clear_path, $filecontent);
+
+ if (endswith($file->getName(), '.KML') or endswith($file->getName(), '.kml')){
+ $fmt = 'kml';
+ }
+ else if (endswith($file->getName(), '.csv') or endswith($file->getName(), '.CSV')){
+ $fmt = 'unicsv';
+ }
+ $args = Array('-i', $fmt, '-f', $file_clear_path, '-o',
+ 'gpx', '-F', $gpx_target_clear_path);
+ $cmdparams = '';
+ foreach($args as $arg){
+ $shella = escapeshellarg($arg);
+ $cmdparams .= " $shella";
+ }
+ exec(
+ escapeshellcmd(
+ $gpsbabel_path.' '.$cmdparams
+ ),
+ $output, $returnvar
+ );
+ if (file_exists($gpx_target_clear_path)){
+ $gpx_clear_content = file_get_contents($gpx_target_clear_path);
+ }
+ else{
+ $gpx_clear_content = '';
+ }
+
+ delTree($tempdir);
+
+ return $gpx_clear_content;
+ }
+
/**
*
* @NoAdminRequired
@@ -192,20 +239,22 @@ class PageController extends Controller {
$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
+ if ($file->getType() === \OCP\Files\FileInfo::TYPE_FILE){
+ if (endswith($file->getName(), '.GPX') or endswith($file->getName(), '.gpx')){
+ $gpxContent = $file->getContent();
+ }
+ else if (getProgramPath('gpsbabel') !== null and
+ (endswith($file->getName(), '.KML') or endswith($file->getName(), '.kml') or
+ endswith($file->getName(), '.CSV') or endswith($file->getName(), '.csv'))
+ ){
+ $gpxContent = $this->toGpx($file);
+ }
}
else{
$file = null;
}
}
- if ($file !== null){
- $gpxContent = $file->getContent();
- }
-
$response = new DataResponse(
[
'gpx'=>$gpxContent
@@ -285,6 +334,7 @@ class PageController extends Controller {
public function getdircontent($dir) {
$userFolder = \OC::$server->getUserFolder();
$userfolder_path = $userFolder->getPath();
+ $gpsbabelpath = getProgramPath('gpsbabel');
$responseTxt = '
';
//error_log('DIR : '.$dir);
@@ -297,9 +347,18 @@ class PageController extends Controller {
if ($elem->getType() === \OCP\Files\FileInfo::TYPE_FOLDER){
$responseTxt .= '- '.$elem->getName().'
';
}
- else if ($elem->getType() === \OCP\Files\FileInfo::TYPE_FILE and
- (endswith($elempath, '.gpx') or endswith($elempath, '.GPX'))){
- $responseTxt .= '- '.$elem->getName().'
';
+ else if ($elem->getType() === \OCP\Files\FileInfo::TYPE_FILE){
+ if (endswith($elempath, '.gpx') or endswith($elempath, '.GPX')){
+ $responseTxt .= '- '.$elem->getName().'
';
+ }
+ else if ($gpsbabelpath !== null and
+ (endswith($elempath, '.csv') or endswith($elempath, '.CSV'))){
+ $responseTxt .= '- '.$elem->getName().'
';
+ }
+ else if ($gpsbabelpath !== null and
+ (endswith($elempath, '.kml') or endswith($elempath, '.KML'))){
+ $responseTxt .= '- '.$elem->getName().'
';
+ }
}
}
}
diff --git a/css/jQueryFileTree.min.css b/css/jQueryFileTree.min.css
index 26ae4b7..a92eb84 100644
--- a/css/jQueryFileTree.min.css
+++ b/css/jQueryFileTree.min.css
@@ -1 +1 @@
-UL.jqueryFileTree{font-family:Verdana,sans-serif;font-size:11px;line-height:18px;padding:0;margin:0;display:none}UL.jqueryFileTree LI{list-style:none;padding:0 0 0 20px;margin:0;white-space:nowrap}UL.jqueryFileTree LI.directory{background:url(jqfileImages/directory.png) left top no-repeat}UL.jqueryFileTree LI.directory-locked{background:url(jqfileImages/directory-lock.png) left top no-repeat}UL.jqueryFileTree LI.expanded{background:url(jqfileImages/folder_open.png) left top no-repeat}UL.jqueryFileTree LI.gpx{background:url(jqfileImages/gpx.png) left top no-repeat}UL.jqueryFileTree LI.file{background:url(jqfileImages/file.png) left top no-repeat}UL.jqueryFileTree LI.file-locked{background:url(jqfileImages/file-lock.png) left top no-repeat!important}UL.jqueryFileTree LI.wait{background:url(jqfileImages/spinner.gif) left top no-repeat}UL.jqueryFileTree LI.selected>a{font-weight:700}UL.jqueryFileTree LI.ext_3gp{background:url(jqfileImages/film.png) left top no-repeat}UL.jqueryFileTree LI.ext_afp,UL.jqueryFileTree LI.ext_afpa,UL.jqueryFileTree LI.ext_asp,UL.jqueryFileTree LI.ext_aspx{background:url(jqfileImages/code.png) left top no-repeat}UL.jqueryFileTree LI.ext_avi{background:url(jqfileImages/film.png) left top no-repeat}UL.jqueryFileTree LI.ext_bat{background:url(jqfileImages/application.png) left top no-repeat}UL.jqueryFileTree LI.ext_bmp{background:url(jqfileImages/picture.png) left top no-repeat}UL.jqueryFileTree LI.ext_c,UL.jqueryFileTree LI.ext_cfm,UL.jqueryFileTree LI.ext_cgi{background:url(jqfileImages/code.png) left top no-repeat}UL.jqueryFileTree LI.ext_com{background:url(jqfileImages/application.png) left top no-repeat}UL.jqueryFileTree LI.ext_cpp{background:url(jqfileImages/code.png) left top no-repeat}UL.jqueryFileTree LI.ext_css{background:url(jqfileImages/css.png) left top no-repeat}UL.jqueryFileTree LI.ext_doc{background:url(jqfileImages/doc.png) left top no-repeat}UL.jqueryFileTree LI.ext_exe{background:url(jqfileImages/application.png) left top no-repeat}UL.jqueryFileTree LI.ext_gif{background:url(jqfileImages/picture.png) left top no-repeat}UL.jqueryFileTree LI.ext_fla{background:url(jqfileImages/flash.png) left top no-repeat}UL.jqueryFileTree LI.ext_h{background:url(jqfileImages/code.png) left top no-repeat}UL.jqueryFileTree LI.ext_htm,UL.jqueryFileTree LI.ext_html{background:url(jqfileImages/html.png) left top no-repeat}UL.jqueryFileTree LI.ext_jar{background:url(jqfileImages/java.png) left top no-repeat}UL.jqueryFileTree LI.ext_jpeg,UL.jqueryFileTree LI.ext_jpg{background:url(jqfileImages/picture.png) left top no-repeat}UL.jqueryFileTree LI.ext_js{background:url(jqfileImages/script.png) left top no-repeat}UL.jqueryFileTree LI.ext_lasso{background:url(jqfileImages/code.png) left top no-repeat}UL.jqueryFileTree LI.ext_log{background:url(jqfileImages/txt.png) left top no-repeat}UL.jqueryFileTree LI.ext_m4p{background:url(jqfileImages/music.png) left top no-repeat}UL.jqueryFileTree LI.ext_mov{background:url(jqfileImages/film.png) left top no-repeat}UL.jqueryFileTree LI.ext_mp3{background:url(jqfileImages/music.png) left top no-repeat}UL.jqueryFileTree LI.ext_mp4,UL.jqueryFileTree LI.ext_mpeg,UL.jqueryFileTree LI.ext_mpg{background:url(jqfileImages/film.png) left top no-repeat}UL.jqueryFileTree LI.ext_ogg{background:url(jqfileImages/music.png) left top no-repeat}UL.jqueryFileTree LI.ext_ogv{background:url(jqfileImages/film.png) left top no-repeat}UL.jqueryFileTree LI.ext_pcx{background:url(jqfileImages/picture.png) left top no-repeat}UL.jqueryFileTree LI.ext_pdf{background:url(jqfileImages/pdf.png) left top no-repeat}UL.jqueryFileTree LI.ext_php{background:url(jqfileImages/php.png) left top no-repeat}UL.jqueryFileTree LI.ext_png{background:url(jqfileImages/picture.png) left top no-repeat}UL.jqueryFileTree LI.ext_ppt{background:url(jqfileImages/ppt.png) left top no-repeat}UL.jqueryFileTree LI.ext_psd{background:url(jqfileImages/psd.png) left top no-repeat}UL.jqueryFileTree LI.ext_pl,UL.jqueryFileTree LI.ext_py{background:url(jqfileImages/script.png) left top no-repeat}UL.jqueryFileTree LI.ext_rb,UL.jqueryFileTree LI.ext_rbx,UL.jqueryFileTree LI.ext_rhtml{background:url(jqfileImages/ruby.png) left top no-repeat}UL.jqueryFileTree LI.ext_rpm{background:url(jqfileImages/linux.png) left top no-repeat}UL.jqueryFileTree LI.ext_ruby{background:url(jqfileImages/ruby.png) left top no-repeat}UL.jqueryFileTree LI.ext_sql{background:url(jqfileImages/db.png) left top no-repeat}UL.jqueryFileTree LI.ext_swf{background:url(jqfileImages/flash.png) left top no-repeat}UL.jqueryFileTree LI.ext_tif,UL.jqueryFileTree LI.ext_tiff{background:url(jqfileImages/picture.png) left top no-repeat}UL.jqueryFileTree LI.ext_txt{background:url(jqfileImages/txt.png) left top no-repeat}UL.jqueryFileTree LI.ext_vb{background:url(jqfileImages/code.png) left top no-repeat}UL.jqueryFileTree LI.ext_wav{background:url(jqfileImages/music.png) left top no-repeat}UL.jqueryFileTree LI.ext_webm,UL.jqueryFileTree LI.ext_wmv{background:url(jqfileImages/film.png) left top no-repeat}UL.jqueryFileTree LI.ext_xls{background:url(jqfileImages/xls.png) left top no-repeat}UL.jqueryFileTree LI.ext_xml{background:url(jqfileImages/code.png) left top no-repeat}UL.jqueryFileTree LI.ext_zip{background:url(jqfileImages/zip.png) left top no-repeat}UL.jqueryFileTree A{color:#333;text-decoration:none;display:inline-block;padding:0 2px;cursor:pointer}UL.jqueryFileTree A:hover{background:#BDF}
+UL.jqueryFileTree{font-family:Verdana,sans-serif;font-size:11px;line-height:18px;padding:0;margin:0;display:none}UL.jqueryFileTree LI{list-style:none;padding:0 0 0 20px;margin:0;white-space:nowrap}UL.jqueryFileTree LI.directory{background:url(jqfileImages/directory.png) left top no-repeat}UL.jqueryFileTree LI.directory-locked{background:url(jqfileImages/directory-lock.png) left top no-repeat}UL.jqueryFileTree LI.expanded{background:url(jqfileImages/folder_open.png) left top no-repeat}UL.jqueryFileTree LI.gpx{background:url(jqfileImages/gpx.png) left top no-repeat}UL.jqueryFileTree LI.kml{background:url(jqfileImages/kml.png) left top no-repeat}UL.jqueryFileTree LI.csv{background:url(jqfileImages/csv.png) left top no-repeat}UL.jqueryFileTree LI.file{background:url(jqfileImages/file.png) left top no-repeat}UL.jqueryFileTree LI.file-locked{background:url(jqfileImages/file-lock.png) left top no-repeat!important}UL.jqueryFileTree LI.wait{background:url(jqfileImages/spinner.gif) left top no-repeat}UL.jqueryFileTree LI.selected>a{font-weight:700}UL.jqueryFileTree LI.ext_3gp{background:url(jqfileImages/film.png) left top no-repeat}UL.jqueryFileTree LI.ext_afp,UL.jqueryFileTree LI.ext_afpa,UL.jqueryFileTree LI.ext_asp,UL.jqueryFileTree LI.ext_aspx{background:url(jqfileImages/code.png) left top no-repeat}UL.jqueryFileTree LI.ext_avi{background:url(jqfileImages/film.png) left top no-repeat}UL.jqueryFileTree LI.ext_bat{background:url(jqfileImages/application.png) left top no-repeat}UL.jqueryFileTree LI.ext_bmp{background:url(jqfileImages/picture.png) left top no-repeat}UL.jqueryFileTree LI.ext_c,UL.jqueryFileTree LI.ext_cfm,UL.jqueryFileTree LI.ext_cgi{background:url(jqfileImages/code.png) left top no-repeat}UL.jqueryFileTree LI.ext_com{background:url(jqfileImages/application.png) left top no-repeat}UL.jqueryFileTree LI.ext_cpp{background:url(jqfileImages/code.png) left top no-repeat}UL.jqueryFileTree LI.ext_css{background:url(jqfileImages/css.png) left top no-repeat}UL.jqueryFileTree LI.ext_doc{background:url(jqfileImages/doc.png) left top no-repeat}UL.jqueryFileTree LI.ext_exe{background:url(jqfileImages/application.png) left top no-repeat}UL.jqueryFileTree LI.ext_gif{background:url(jqfileImages/picture.png) left top no-repeat}UL.jqueryFileTree LI.ext_fla{background:url(jqfileImages/flash.png) left top no-repeat}UL.jqueryFileTree LI.ext_h{background:url(jqfileImages/code.png) left top no-repeat}UL.jqueryFileTree LI.ext_htm,UL.jqueryFileTree LI.ext_html{background:url(jqfileImages/html.png) left top no-repeat}UL.jqueryFileTree LI.ext_jar{background:url(jqfileImages/java.png) left top no-repeat}UL.jqueryFileTree LI.ext_jpeg,UL.jqueryFileTree LI.ext_jpg{background:url(jqfileImages/picture.png) left top no-repeat}UL.jqueryFileTree LI.ext_js{background:url(jqfileImages/script.png) left top no-repeat}UL.jqueryFileTree LI.ext_lasso{background:url(jqfileImages/code.png) left top no-repeat}UL.jqueryFileTree LI.ext_log{background:url(jqfileImages/txt.png) left top no-repeat}UL.jqueryFileTree LI.ext_m4p{background:url(jqfileImages/music.png) left top no-repeat}UL.jqueryFileTree LI.ext_mov{background:url(jqfileImages/film.png) left top no-repeat}UL.jqueryFileTree LI.ext_mp3{background:url(jqfileImages/music.png) left top no-repeat}UL.jqueryFileTree LI.ext_mp4,UL.jqueryFileTree LI.ext_mpeg,UL.jqueryFileTree LI.ext_mpg{background:url(jqfileImages/film.png) left top no-repeat}UL.jqueryFileTree LI.ext_ogg{background:url(jqfileImages/music.png) left top no-repeat}UL.jqueryFileTree LI.ext_ogv{background:url(jqfileImages/film.png) left top no-repeat}UL.jqueryFileTree LI.ext_pcx{background:url(jqfileImages/picture.png) left top no-repeat}UL.jqueryFileTree LI.ext_pdf{background:url(jqfileImages/pdf.png) left top no-repeat}UL.jqueryFileTree LI.ext_php{background:url(jqfileImages/php.png) left top no-repeat}UL.jqueryFileTree LI.ext_png{background:url(jqfileImages/picture.png) left top no-repeat}UL.jqueryFileTree LI.ext_ppt{background:url(jqfileImages/ppt.png) left top no-repeat}UL.jqueryFileTree LI.ext_psd{background:url(jqfileImages/psd.png) left top no-repeat}UL.jqueryFileTree LI.ext_pl,UL.jqueryFileTree LI.ext_py{background:url(jqfileImages/script.png) left top no-repeat}UL.jqueryFileTree LI.ext_rb,UL.jqueryFileTree LI.ext_rbx,UL.jqueryFileTree LI.ext_rhtml{background:url(jqfileImages/ruby.png) left top no-repeat}UL.jqueryFileTree LI.ext_rpm{background:url(jqfileImages/linux.png) left top no-repeat}UL.jqueryFileTree LI.ext_ruby{background:url(jqfileImages/ruby.png) left top no-repeat}UL.jqueryFileTree LI.ext_sql{background:url(jqfileImages/db.png) left top no-repeat}UL.jqueryFileTree LI.ext_swf{background:url(jqfileImages/flash.png) left top no-repeat}UL.jqueryFileTree LI.ext_tif,UL.jqueryFileTree LI.ext_tiff{background:url(jqfileImages/picture.png) left top no-repeat}UL.jqueryFileTree LI.ext_txt{background:url(jqfileImages/txt.png) left top no-repeat}UL.jqueryFileTree LI.ext_vb{background:url(jqfileImages/code.png) left top no-repeat}UL.jqueryFileTree LI.ext_wav{background:url(jqfileImages/music.png) left top no-repeat}UL.jqueryFileTree LI.ext_webm,UL.jqueryFileTree LI.ext_wmv{background:url(jqfileImages/film.png) left top no-repeat}UL.jqueryFileTree LI.ext_xls{background:url(jqfileImages/xls.png) left top no-repeat}UL.jqueryFileTree LI.ext_xml{background:url(jqfileImages/code.png) left top no-repeat}UL.jqueryFileTree LI.ext_zip{background:url(jqfileImages/zip.png) left top no-repeat}UL.jqueryFileTree A{color:#333;text-decoration:none;display:inline-block;padding:0 2px;cursor:pointer}UL.jqueryFileTree A:hover{background:#BDF}
diff --git a/css/jqfileImages/csv.png b/css/jqfileImages/csv.png
new file mode 100644
index 0000000..57e1956
Binary files /dev/null and b/css/jqfileImages/csv.png differ
diff --git a/css/jqfileImages/kml.png b/css/jqfileImages/kml.png
new file mode 100644
index 0000000..6bf141f
Binary files /dev/null and b/css/jqfileImages/kml.png differ