Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

added possibility to load gpx track files #81

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ public function __construct (array $urlParams=array()) {
*/
$container->registerService('PageController', function($c) {
return new PageController(
$c->query('AppName'),
$c->query('AppName'),
$c->query('Request'),
$c->query('RootFolder'),
$c->query('UserId'),
$c->query('CacheManager'),
$c->query('DeviceMapper')
);
});
$container->registerService('LocationController', function($c) {
return new LocationController(
$c->query('AppName'),
$c->query('AppName'),
$c->query('Request'),
$c->query('LocationMapper'),
$c->query('DeviceMapper'),
Expand All @@ -66,6 +67,20 @@ public function __construct (array $urlParams=array()) {
);
});

$container->registerService('RootFolder', function($c) {
return $this->getContainer()->getServer()->getRootFolder();
});

/**
* Core
*/
$container->registerService('UserId', function($c) {
return \OCP\User::getUser();
});
$container->registerService('Db', function() {
return new Db();
});

}


Expand Down
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
array('name' => 'page#adresslookup', 'url' => '/adresslookup', 'verb' => 'GET'),
array('name' => 'page#geodecode', 'url' => '/geodecode', 'verb' => 'GET'),
array('name' => 'page#search', 'url' => '/search', 'verb' => 'GET'),
array('name' => 'page#getgpsfiles', 'url' => '/getgps', 'verb' => 'GET'),

array('name' => 'location#update', 'url' => '/api/1.0/location/update', 'verb' => 'GET'),
array('name' => 'location#add_device', 'url' => '/api/1.0/location/adddevice', 'verb' => 'POST'),
Expand Down
40 changes: 33 additions & 7 deletions controller/pagecontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@
use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Controller;
use \OCA\Maps\Db\CacheManager;
use \OCP\Files\Folder;
use \OCP\Files\IRootFolder;

class PageController extends Controller {

private $userId;
private $cacheManager;
private $rootF;
private $deviceMapper;
public function __construct($appName, IRequest $request, $userId,
public function __construct($appName, IRequest $request, $rootF, $userId,
CacheManager $cacheManager,
DeviceMapper $deviceMapper) {
parent::__construct($appName, $request);
$this -> userId = $userId;
$this -> cacheManager = $cacheManager;
$this -> deviceMapper = $deviceMapper;
$this -> rootF = $rootF;
}

/**
Expand Down Expand Up @@ -103,7 +107,7 @@ public function search() {
$kw = $this -> params('search');
$bbox = $this -> params('bbox');
$response = array('contacts'=>array(),'nodes'=>array(),'addresses'=>array());

$contacts = $cm -> search($kw, array('FN', 'ADR'));
foreach ($contacts as $r) {
$data = array();
Expand All @@ -123,7 +127,7 @@ public function search() {
}
}
//$response['addresses'] = (array)($this->doAdresslookup($kw));

return $response;
}

Expand All @@ -136,9 +140,9 @@ public function geodecode(){
$lat = $this->params('lat');
$lng = $this->params('lng');
$zoom = $this->params('zoom');

$hash = md5($lat.','.$lng.'@'.$zoom);

$checkCache = $this -> checkGeoCache($hash);
if(!$checkCache){
$url = 'http://nominatim.openstreetmap.org/reverse/?format=json&[email protected]&lat='.$lat.'&lng='. $lng.'&zoom=67108864';
Expand All @@ -151,7 +155,7 @@ public function geodecode(){
}
echo $response;
die();
}
}
/**
* Simply method that posts back the payload of the request
* @NoAdminRequired
Expand Down Expand Up @@ -214,7 +218,7 @@ private function getURL($url, $userAgent = true) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 900);
curl_setopt($ch, CURLOPT_TIMEOUT, 900);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if ($userAgent) {
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
Expand All @@ -233,4 +237,26 @@ private function getURL($url, $userAgent = true) {

}

public function getGpsFiles(){
$path = '/' . $this->userId . '/files/MyTracks';
if ($this->rootF->nodeExists($path)) {
$folder = $this->rootF->get($path);
} else {
$folder = $this->rootF->newFolder($path);
}
$nodes = $folder->getDirectoryListing();
$suffix = ".gpx";
foreach($nodes as $n){
if($n->getType() == \OCP\Files\FileInfo::TYPE_FILE){
$name = $n->getName();
if(substr_compare($name, $suffix, -strlen($suffix)) === 0){
$arr = array();
$arr['dir'] = $n->getParent()->getName();
$arr['file'] = $n->getName();
$files[] = $arr;
}
}
}
return $files;
}
}
Loading