Skip to content
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
1 change: 0 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class Application extends App implements IBootstrap {
public const APP_ID = 'integration_openstreetmap';
public const OSM_URL = 'https://www.openstreetmap.org';

public const DEFAULT_MAPTILER_API_KEY = 'get_your_own_OpIi9ZULNHzrESv6T2vL';
public const DEFAULT_SEARCH_LOCATION_ENABLED_VALUE = '0';
public const DEFAULT_PROXY_OSM_VALUE = '1';

Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/OsmAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function nominatimSearch(
'namedetails' => $namedetails,
'extratags' => $extratags,
];
$searchResults = $this->osmAPIService->searchLocation($this->userId, $q, $rformat, $extraParams, 0, $limit);
$searchResults = $this->osmAPIService->searchLocation($q, $rformat, $extraParams, 0, $limit);
if (isset($searchResults['error'])) {
return new DataResponse('', Http::STATUS_BAD_REQUEST);
}
Expand Down
6 changes: 5 additions & 1 deletion lib/Listener/CSPListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class CSPListener implements IEventListener {
public function __construct(
private IRequest $request,
private IAppConfig $appConfig,
private ?string $userId,
) {
}

Expand All @@ -56,7 +57,10 @@ public function handle(Event $event): void {
->addAllowedFrameDomain('https://www.openstreetmap.org')
->addAllowedImageDomain('https://*.tile.openstreetmap.org');

$proxyOsm = $this->appConfig->getValueString(Application::APP_ID, 'proxy_osm', Application::DEFAULT_PROXY_OSM_VALUE) === '1';
// we do not proxy on public pages
$proxyOsm = $this->userId === null
? false
: $this->appConfig->getValueString(Application::APP_ID, 'proxy_osm', Application::DEFAULT_PROXY_OSM_VALUE) === '1';
if (!$proxyOsm) {
$policy
->addAllowedConnectDomain('https://*.openstreetmap.org')
Expand Down
15 changes: 14 additions & 1 deletion lib/Listener/OsmReferenceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,25 @@ public function handle(Event $event): void {
return;
}

$maptilerApiKey = $this->appConfig->getValueString(Application::APP_ID, 'maptiler_api_key', Application::DEFAULT_MAPTILER_API_KEY) ?: Application::DEFAULT_MAPTILER_API_KEY;
$maptilerApiKey = $this->appConfig->getValueString(Application::APP_ID, 'maptiler_api_key');
$userConfig = [
'maptiler_api_key' => $maptilerApiKey,
];
$this->initialState->provideInitialState('api-keys', $userConfig);

// public pages
if ($this->userId === null) {
$this->initialState->provideInitialState('prefer-osm-frame', false);
$this->initialState->provideInitialState('proxy-map-requests', false);
if ($maptilerApiKey === '') {
$this->initialState->provideInitialState('last-map-state', [
'mapStyle' => 'osmRaster',
]);
}
Util::addScript(Application::APP_ID, Application::APP_ID . '-referenceLocation');
return;
}

$preferSimpleOsmIframe = $this->userConfig->getValueString($this->userId, Application::APP_ID, 'prefer_simple_osm_iframe', '0') === '1';
$this->initialState->provideInitialState('prefer-osm-frame', $preferSimpleOsmIframe);
$proxyMapRequests = $this->appConfig->getValueString(Application::APP_ID, 'proxy_osm', Application::DEFAULT_PROXY_OSM_VALUE) === '1';
Expand Down
18 changes: 16 additions & 2 deletions lib/Reference/BingReferenceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace OCA\Osm\Reference;

use OCA\Osm\AppInfo\Application;
use OCP\Collaboration\Reference\IPublicReferenceProvider;
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\IReferenceManager;
use OCP\Collaboration\Reference\IReferenceProvider;
Expand All @@ -32,7 +33,7 @@
use OCP\Config\IUserConfig;
use OCP\IAppConfig;

class BingReferenceProvider implements IReferenceProvider {
class BingReferenceProvider implements IReferenceProvider, IPublicReferenceProvider {

private const RICH_OBJECT_TYPE = Application::APP_ID . '_location';

Expand All @@ -50,14 +51,20 @@ public function __construct(
*/
public function matchReference(string $referenceText): bool {
$adminLinkPreviewEnabled = $this->appConfig->getValueString(Application::APP_ID, 'link_preview_enabled', '1') === '1';
$userLinkPreviewEnabled = $this->userConfig->getValueString($this->userId, Application::APP_ID, 'link_preview_enabled', '1') === '1';
$userLinkPreviewEnabled = $this->userId === null
? true
: $this->userConfig->getValueString($this->userId, Application::APP_ID, 'link_preview_enabled', '1') === '1';
if (!$adminLinkPreviewEnabled || !$userLinkPreviewEnabled) {
return false;
}

return $this->getCoordinates($referenceText) !== null;
}

public function resolveReferencePublic(string $referenceText, string $sharingToken): ?IReference {
return $this->resolveReference($referenceText);
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -152,6 +159,13 @@ public function getCacheKey(string $referenceId): ?string {
return $referenceId;
}

/**
* @inheritDoc
*/
public function getCacheKeyPublic(string $referenceId, string $sharingToken): ?string {
return null;
}

/**
* @param string $userId
* @return void
Expand Down
18 changes: 16 additions & 2 deletions lib/Reference/DuckduckgoReferenceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace OCA\Osm\Reference;

use OCA\Osm\AppInfo\Application;
use OCP\Collaboration\Reference\IPublicReferenceProvider;
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\IReferenceManager;
use OCP\Collaboration\Reference\IReferenceProvider;
Expand All @@ -32,7 +33,7 @@
use OCP\Config\IUserConfig;
use OCP\IAppConfig;

class DuckduckgoReferenceProvider implements IReferenceProvider {
class DuckduckgoReferenceProvider implements IReferenceProvider, IPublicReferenceProvider {

private const RICH_OBJECT_TYPE = Application::APP_ID . '_location';

Expand All @@ -50,14 +51,20 @@ public function __construct(
*/
public function matchReference(string $referenceText): bool {
$adminLinkPreviewEnabled = $this->appConfig->getValueString(Application::APP_ID, 'link_preview_enabled', '1') === '1';
$userLinkPreviewEnabled = $this->userConfig->getValueString($this->userId, Application::APP_ID, 'link_preview_enabled', '1') === '1';
$userLinkPreviewEnabled = $this->userId === null
? true
: $this->userConfig->getValueString($this->userId, Application::APP_ID, 'link_preview_enabled', '1') === '1';
if (!$adminLinkPreviewEnabled || !$userLinkPreviewEnabled) {
return false;
}

return $this->getCoordinates($referenceText) !== null;
}

public function resolveReferencePublic(string $referenceText, string $sharingToken): ?IReference {
return $this->resolveReference($referenceText);
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -119,6 +126,13 @@ public function getCacheKey(string $referenceId): ?string {
return $referenceId;
}

/**
* @inheritDoc
*/
public function getCacheKeyPublic(string $referenceId, string $sharingToken): ?string {
return null;
}

/**
* @param string $userId
* @return void
Expand Down
20 changes: 17 additions & 3 deletions lib/Reference/GoogleMapsReferenceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCA\Osm\AppInfo\Application;
use OCA\Osm\Service\OsmAPIService;
use OCA\Osm\Service\UtilsService;
use OCP\Collaboration\Reference\IPublicReferenceProvider;
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\IReferenceManager;
use OCP\Collaboration\Reference\IReferenceProvider;
Expand All @@ -36,7 +37,7 @@

use OCP\IURLGenerator;

class GoogleMapsReferenceProvider implements IReferenceProvider {
class GoogleMapsReferenceProvider implements IReferenceProvider, IPublicReferenceProvider {

private const RICH_OBJECT_TYPE = Application::APP_ID . '_location';

Expand All @@ -57,22 +58,28 @@ public function __construct(
*/
public function matchReference(string $referenceText): bool {
$adminLinkPreviewEnabled = $this->appConfig->getValueString(Application::APP_ID, 'link_preview_enabled', '1') === '1';
$userLinkPreviewEnabled = $this->userConfig->getValueString($this->userId, Application::APP_ID, 'link_preview_enabled', '1') === '1';
$userLinkPreviewEnabled = $this->userId === null
? true
: $this->userConfig->getValueString($this->userId, Application::APP_ID, 'link_preview_enabled', '1') === '1';
if (!$adminLinkPreviewEnabled || !$userLinkPreviewEnabled) {
return false;
}

return $this->getCoordinates($referenceText) !== null;
}

public function resolveReferencePublic(string $referenceText, string $sharingToken): ?IReference {
return $this->resolveReference($referenceText);
}

/**
* @inheritDoc
*/
public function resolveReference(string $referenceText): ?IReference {
if ($this->matchReference($referenceText)) {
$coords = $this->getCoordinates($referenceText);
if ($coords !== null) {
$pointInfo = $this->osmAPIService->geocode($this->userId, $coords['lat'], $coords['lon'], false);
$pointInfo = $this->osmAPIService->geocode($coords['lat'], $coords['lon'], false);
if (!isset($pointInfo['error'])) {
$pointInfo['url'] = $referenceText;
$reference = new Reference($referenceText);
Expand Down Expand Up @@ -248,6 +255,13 @@ public function getCacheKey(string $referenceId): ?string {
return $referenceId;
}

/**
* @inheritDoc
*/
public function getCacheKeyPublic(string $referenceId, string $sharingToken): ?string {
return null;
}

/**
* @param string $userId
* @return void
Expand Down
20 changes: 17 additions & 3 deletions lib/Reference/HereMapsReferenceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use OCA\Osm\AppInfo\Application;
use OCA\Osm\Service\OsmAPIService;
use OCP\Collaboration\Reference\IPublicReferenceProvider;
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\IReferenceManager;
use OCP\Collaboration\Reference\IReferenceProvider;
Expand All @@ -35,7 +36,7 @@

use OCP\IURLGenerator;

class HereMapsReferenceProvider implements IReferenceProvider {
class HereMapsReferenceProvider implements IReferenceProvider, IPublicReferenceProvider {

private const RICH_OBJECT_TYPE = Application::APP_ID . '_location';

Expand All @@ -55,22 +56,28 @@ public function __construct(
*/
public function matchReference(string $referenceText): bool {
$adminLinkPreviewEnabled = $this->appConfig->getValueString(Application::APP_ID, 'link_preview_enabled', '1') === '1';
$userLinkPreviewEnabled = $this->userConfig->getValueString($this->userId, Application::APP_ID, 'link_preview_enabled', '1') === '1';
$userLinkPreviewEnabled = $this->userId === null
? true
: $this->userConfig->getValueString($this->userId, Application::APP_ID, 'link_preview_enabled', '1') === '1';
if (!$adminLinkPreviewEnabled || !$userLinkPreviewEnabled) {
return false;
}

return $this->getCoordinates($referenceText) !== null;
}

public function resolveReferencePublic(string $referenceText, string $sharingToken): ?IReference {
return $this->resolveReference($referenceText);
}

/**
* @inheritDoc
*/
public function resolveReference(string $referenceText): ?IReference {
if ($this->matchReference($referenceText)) {
$coords = $this->getCoordinates($referenceText);
if ($coords !== null) {
$pointInfo = $this->osmAPIService->geocode($this->userId, $coords['lat'], $coords['lon'], false);
$pointInfo = $this->osmAPIService->geocode($coords['lat'], $coords['lon'], false);
if (!isset($pointInfo['error'])) {
$pointInfo['url'] = $referenceText;
$reference = new Reference($referenceText);
Expand Down Expand Up @@ -173,6 +180,13 @@ public function getCacheKey(string $referenceId): ?string {
return $referenceId;
}

/**
* @inheritDoc
*/
public function getCacheKeyPublic(string $referenceId, string $sharingToken): ?string {
return null;
}

/**
* @param string $userId
* @return void
Expand Down
20 changes: 17 additions & 3 deletions lib/Reference/OsmLocationReferenceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCA\Osm\AppInfo\Application;
use OCA\Osm\Service\OsmAPIService;
use OCA\Osm\Service\UtilsService;
use OCP\Collaboration\Reference\IPublicReferenceProvider;
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\IReferenceManager;
use OCP\Collaboration\Reference\IReferenceProvider;
Expand All @@ -36,7 +37,7 @@

use OCP\IURLGenerator;

class OsmLocationReferenceProvider implements IReferenceProvider {
class OsmLocationReferenceProvider implements IReferenceProvider, IPublicReferenceProvider {

private const RICH_OBJECT_TYPE = Application::APP_ID . '_location';

Expand All @@ -57,22 +58,28 @@ public function __construct(
*/
public function matchReference(string $referenceText): bool {
$adminLinkPreviewEnabled = $this->appConfig->getValueString(Application::APP_ID, 'link_preview_enabled', '1') === '1';
$userLinkPreviewEnabled = $this->userConfig->getValueString($this->userId, Application::APP_ID, 'link_preview_enabled', '1') === '1';
$userLinkPreviewEnabled = $this->userId === null
? true
: $this->userConfig->getValueString($this->userId, Application::APP_ID, 'link_preview_enabled', '1') === '1';
if (!$adminLinkPreviewEnabled || !$userLinkPreviewEnabled) {
return false;
}

return $this->getCoordinates($referenceText) !== null || $this->getLocationTypeId($referenceText) !== null;
}

public function resolveReferencePublic(string $referenceText, string $sharingToken): ?IReference {
return $this->resolveReference($referenceText);
}

/**
* @inheritDoc
*/
public function resolveReference(string $referenceText): ?IReference {
if ($this->matchReference($referenceText)) {
$coords = $this->getCoordinates($referenceText);
$locationTypeId = $this->getLocationTypeId($referenceText);
$locationInfo = $this->osmAPIService->getLocationInfo($this->userId, $locationTypeId['id'], $locationTypeId['type']);
$locationInfo = $this->osmAPIService->getLocationInfo($locationTypeId['id'], $locationTypeId['type']);
if ($locationInfo !== null) {
$locationInfo['url'] = $referenceText;
$reference = new Reference($referenceText);
Expand Down Expand Up @@ -185,6 +192,13 @@ public function getCacheKey(string $referenceId): ?string {
return $referenceId;
}

/**
* @inheritDoc
*/
public function getCacheKeyPublic(string $referenceId, string $sharingToken): ?string {
return null;
}

/**
* @param string $userId
* @return void
Expand Down
Loading
Loading