Skip to content
This repository was archived by the owner on Nov 2, 2018. It is now read-only.
Merged
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
10 changes: 9 additions & 1 deletion appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use \OCA\Maps\Db\DeviceMapper;
use \OCA\Maps\Db\LocationMapper;
use \OCA\Maps\Db\FavoriteMapper;
use \OCA\Maps\Db\ApiKeyMapper;
use \OCA\Maps\Controller\PageController;
use \OCA\Maps\Controller\LocationController;
use \OCA\Maps\Controller\FavoriteController;
Expand All @@ -41,7 +42,8 @@ public function __construct (array $urlParams=array()) {
$c->query('Request'),
$c->query('UserId'),
$c->query('CacheManager'),
$c->query('DeviceMapper')
$c->query('DeviceMapper'),
$c->query('ApiKeyMapper')
);
});
$container->registerService('LocationController', function($c) {
Expand Down Expand Up @@ -89,6 +91,12 @@ public function __construct (array $urlParams=array()) {
$server->getDb()
);
});
$container->registerService('ApiKeyMapper', function($c) use ($server) {
/** @var SimpleContainer $c */
return new ApiKeyMapper(
$server->getDb()
);
});

}

Expand Down
23 changes: 23 additions & 0 deletions appinfo/database.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,27 @@
</field>
</declaration>
</table>
<table>
<name>*dbprefix*maps_apikeys</name>
<declaration>
<field>
<name>id</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<autoincrement>1</autoincrement>
<length>41</length>
</field>
<field>
<name>user_id</name>
<type>text</type>
<length>64</length>
</field>
<field>
<name>api_key</name>
<type>text</type>
<length>64</length>
</field>
</declaration>
</table>
</database>
4 changes: 4 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,9 @@
array('name' => 'favorite#get_favorites', 'url' => '/api/1.0/favorite/getFavorites', 'verb' => 'POST'),
array('name' => 'favorite#remove_favorite', 'url' => '/api/1.0/favorite/removeFromFavorites', 'verb' => 'POST'),
array('name' => 'favorite#update_favorite', 'url' => '/api/1.0/favorite/updateFavorite', 'verb' => 'POST'),
array('name' => 'favorite#get_favorites_by_name', 'url' => '/api/1.0/favorite/getFavoritesByName', 'verb' => 'POST'),

array('name' => 'apikey#get_key', 'url' => '/api/1.0/apikey/getKey', 'verb' => 'POST'),
array('name' => 'apikey#add_key', 'url' => '/api/1.0/apikey/addKey', 'verb' => 'POST'),

)));
103 changes: 103 additions & 0 deletions controller/apikeycontroller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php
/**
* ownCloud - maps
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Vinzenz Rosenkranz <[email protected]>
* @copyright Vinzenz Rosenkranz 2015
*/

namespace OCA\Maps\Controller;

use OCA\Maps\Db\ApiKey;
use OCA\Maps\Db\ApiKeyMapper;
use \OCP\IRequest;
use \OCP\AppFramework\Http\JSONResponse;
use \OCP\AppFramework\ApiController;


class ApiKeyController extends ApiController {

private $userId;
private $apiKeyMapper;

public function __construct($appName, IRequest $request, ApiKeyMapper $apiKeyMapper, $userId) {
parent::__construct($appName, $request);
$this->apiKeyMapper = $apiKeyMapper;
$this->userId = $userId;
}

/**
* @NoAdminRequired
*
* @param $key string
* @param $id int
* @return JSONResponse
*/
public function updateKey($key, $id) {

$apikey = new ApiKey();
$apikey->setId($id);
$apikey->setApiKey($key);

/* Only save apiKey if it exists in db */
try {
$this->apiKeyMapper->find($id);
return new JSONResponse($this->apiKeyMapper->update($apikey));
} catch(\OCP\AppFramework\Db\DoesNotExistException $e) {
return new JSONResponse([
'error' => $e->getMessage()
]);
}
}

/**
* @NoAdminRequired
*
* @param $key string
* @return JSONResponse
*/
public function addKey($key){
$apikey = new ApiKey();
$apikey->setApiKey($key);
$apikey->setUserId($this->userId);

/* @var $apikey ApiKey */
$apikey = $this->apiKeyMapper->insert($apikey);

$response = array('id'=> $apikey->getId());
return new JSONResponse($response);
}

/**
* @NoAdminRequired
*
* @return JSONResponse
*/
public function getKey(){
$apikey = new ApiKey();
try {
$apikey = $this->apiKeyMapper->findByUser($this->userId);
} catch(\OCP\AppFramework\Db\DoesNotExistException $e) {
$apikey->setUserId($this->userId);
}
return new JSONResponse($apikey);
}

/**
* @NoAdminRequired
*
* @param $id int
* @return JSONResponse
*/
public function removeApiKey($id){
$apikey = $this->apiKeyMapper->find($id);
if($apikey->userId == $this->userId) {
$this->apiKeyMapper->delete($apikey);
}
return new JSONResponse();
}

}
12 changes: 12 additions & 0 deletions controller/favoritecontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ public function getFavorites(){
return new JSONResponse($favorites);
}

/**
* @NoAdminRequired
*
* @param $name string
*
* @return JSONResponse
*/
public function getFavoritesByName($name){
$favorites = $this->favoriteMapper->findByName($name);
return new JSONResponse($favorites);
}

/**
* @NoAdminRequired
*
Expand Down
36 changes: 28 additions & 8 deletions controller/pagecontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

namespace OCA\Maps\Controller;

use \OCA\Maps\Db\ApiKey;
use \OCA\Maps\Db\DeviceMapper;
use \OCA\Maps\Db\ApiKeyMapper;
use \OCP\IRequest;
use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Controller;
Expand All @@ -22,13 +24,16 @@ class PageController extends Controller {
private $userId;
private $cacheManager;
private $deviceMapper;
private $apiKeyMapper;
public function __construct($appName, IRequest $request, $userId,
CacheManager $cacheManager,
DeviceMapper $deviceMapper) {
DeviceMapper $deviceMapper,
ApiKeyMapper $apiKeyMapper) {
parent::__construct($appName, $request);
$this -> userId = $userId;
$this -> cacheManager = $cacheManager;
$this -> deviceMapper = $deviceMapper;
$this -> apiKeyMapper = $apiKeyMapper;
}

/**
Expand All @@ -52,10 +57,25 @@ public function index() {
// marker icons
$csp->addAllowedImageDomain('https://api.tiles.mapbox.com');
// inline images
$csp->addAllowedScriptDomain('data:');
$csp->addAllowedImageDomain('data:');
//overpasslayer api
$csp->addAllowedConnectDomain('http://overpass-api.de/api/interpreter?');
$tmpkey = new ApiKey();
try {
$tmpkey = $this->apiKeyMapper->findByUser($this->userId);
} catch(\OCP\AppFramework\Db\DoesNotExistException $e) {
$tmpkey->setUserId($this->userId);
}
if($tmpkey->apiKey != null && strlen($tmpkey->apiKey) > 0) {
// mapzen geocoder
$csp->addAllowedConnectDomain('http://search.mapzen.com/v1/search?');
$csp->addAllowedConnectDomain('http://search.mapzen.com/v1/reverse?');
} else {
// nominatim geocoder
$csp->addAllowedScriptDomain('http://nominatim.openstreetmap.org/search?q=*');
$csp->addAllowedScriptDomain('http://nominatim.openstreetmap.org/reverse');
$csp->addAllowedConnectDomain('http://router.project-osrm.org');
}
$response->setContentSecurityPolicy($csp);
}
return $response;
Expand Down Expand Up @@ -106,7 +126,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 @@ -126,7 +146,7 @@ public function search() {
}
}
//$response['addresses'] = (array)($this->doAdresslookup($kw));

return $response;
}

Expand All @@ -139,9 +159,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 @@ -154,7 +174,7 @@ public function geodecode(){
}
echo $response;
die();
}
}
/**
* Simply method that posts back the payload of the request
* @NoAdminRequired
Expand Down Expand Up @@ -217,7 +237,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 Down
104 changes: 104 additions & 0 deletions css/leaflet/Control.Geocoder.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
.leaflet-control-geocoder {
background: white;
}

.leaflet-control-geocoder a, .leaflet-control-geocoder .leaflet-control-geocoder-icon {
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-bottom: none;
display: inline-block;
}

.leaflet-control-geocoder .leaflet-control-geocoder-alternatives a {
width: inherit;
height: inherit;
line-height: inherit;
}

.leaflet-control-geocoder a:hover, .leaflet-control-geocoder .leaflet-control-geocoder-icon:hover {
border-bottom: none;
display: inline-block;
}

.leaflet-control-geocoder-form {
display: none;
vertical-align: middle;
}
.leaflet-control-geocoder-expanded .leaflet-control-geocoder-form {
display: inline-block;
}
.leaflet-control-geocoder-form input {
font-size: 120%;
border: 0;
background-color: transparent;
width: 246px;
}
.leaflet-control-geocoder-icon {
background-image: url(images/geocoder.png);
background-repeat: no-repeat;
background-position: center;
}
.leaflet-control-geocoder-throbber .leaflet-control-geocoder-icon {
background-image: url(images/throbber.gif);
}

.leaflet-control-geocoder-form-no-error {
display: none;
}

.leaflet-control-geocoder-form input:focus {
outline: none;
}

.leaflet-control-geocoder-form button {
display: none;
}
.leaflet-control-geocoder-error {
margin-top: 8px;
margin-left: 8px;
display: block;
color: #444;
}
.leaflet-control-geocoder-alternatives {
display: block;
width: 272px;
list-style: none;
padding: 0;
margin: 0;
}

.leaflet-control-geocoder-alternatives-minimized {
display: none;
height: 0;
}
.leaflet-control-geocoder-alternatives li {
white-space: nowrap;
display: block;
overflow: hidden;
padding: 5px 8px;
text-overflow: ellipsis;
border-bottom: 1px solid #ccc;
cursor: pointer;
}

.leaflet-control-geocoder-alternatives li a, .leaflet-control-geocoder-alternatives li a:hover {
width: inherit;
height: inherit;
line-height: inherit;
background: inherit;
border-radius: inherit;
text-align: left;
}

.leaflet-control-geocoder-alternatives li:last-child {
border-bottom: none;
}
.leaflet-control-geocoder-alternatives li:hover, .leaflet-control-geocoder-selected {
background-color: #f5f5f5;
}
.leaflet-control-geocoder-address-detail {

}
.leaflet-control-geocoder-address-context {
color: #666;
}
Binary file added css/leaflet/images/geocoder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added css/leaflet/images/throbber.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading