1c9c6f2ecSGreg Roach<?php 2c9c6f2ecSGreg Roach 3c9c6f2ecSGreg Roach/** 4c9c6f2ecSGreg Roach * webtrees: online genealogy 55bfc6897SGreg Roach * Copyright (C) 2022 webtrees development team 6c9c6f2ecSGreg Roach * This program is free software: you can redistribute it and/or modify 7c9c6f2ecSGreg Roach * it under the terms of the GNU General Public License as published by 8c9c6f2ecSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9c9c6f2ecSGreg Roach * (at your option) any later version. 10c9c6f2ecSGreg Roach * This program is distributed in the hope that it will be useful, 11c9c6f2ecSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12c9c6f2ecSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13c9c6f2ecSGreg Roach * GNU General Public License for more details. 14c9c6f2ecSGreg Roach * You should have received a copy of the GNU General Public License 15c9c6f2ecSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16c9c6f2ecSGreg Roach */ 17c9c6f2ecSGreg Roach 18c9c6f2ecSGreg Roachdeclare(strict_types=1); 19c9c6f2ecSGreg Roach 20c9c6f2ecSGreg Roachnamespace Fisharebest\Webtrees\Module; 21c9c6f2ecSGreg Roach 22c9c6f2ecSGreg Roachuse Fisharebest\Webtrees\FlashMessages; 23c9c6f2ecSGreg Roachuse Fisharebest\Webtrees\I18N; 24*748dbe15SGreg Roachuse Fisharebest\Webtrees\Validator; 25c9c6f2ecSGreg Roachuse Psr\Http\Message\ResponseInterface; 26c9c6f2ecSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 27c9c6f2ecSGreg Roach 28c9c6f2ecSGreg Roachuse function redirect; 29c9c6f2ecSGreg Roach 30c9c6f2ecSGreg Roach/** 31c9c6f2ecSGreg Roach * Class HereMaps - use maps within webtrees 32c9c6f2ecSGreg Roach */ 33c9c6f2ecSGreg Roachclass HereMaps extends AbstractModule implements ModuleConfigInterface, ModuleMapProviderInterface 34c9c6f2ecSGreg Roach{ 35c9c6f2ecSGreg Roach use ModuleConfigTrait; 36c9c6f2ecSGreg Roach use ModuleMapProviderTrait; 37c9c6f2ecSGreg Roach 38c9c6f2ecSGreg Roach /** 39c9c6f2ecSGreg Roach * Name of the map provider. 40c9c6f2ecSGreg Roach * 41c9c6f2ecSGreg Roach * @return string 42c9c6f2ecSGreg Roach */ 43c9c6f2ecSGreg Roach public function description(): string 44c9c6f2ecSGreg Roach { 45c9c6f2ecSGreg Roach $link = '<a href="https://www.here.com" dir="ltr">www.here.com</a>'; 46c9c6f2ecSGreg Roach 47c9c6f2ecSGreg Roach // I18N: %s is a link/URL 48c9c6f2ecSGreg Roach return I18N::translate('Create maps using %s.', $link); 49c9c6f2ecSGreg Roach } 50c9c6f2ecSGreg Roach 51c9c6f2ecSGreg Roach /** 52c9c6f2ecSGreg Roach * Should this module be enabled when it is first installed? 53c9c6f2ecSGreg Roach * 54c9c6f2ecSGreg Roach * @return bool 55c9c6f2ecSGreg Roach */ 56c9c6f2ecSGreg Roach public function isEnabledByDefault(): bool 57c9c6f2ecSGreg Roach { 58c9c6f2ecSGreg Roach return false; 59c9c6f2ecSGreg Roach } 60c9c6f2ecSGreg Roach 61c9c6f2ecSGreg Roach /** 62c9c6f2ecSGreg Roach * @return ResponseInterface 63c9c6f2ecSGreg Roach */ 64c9c6f2ecSGreg Roach public function getAdminAction(): ResponseInterface 65c9c6f2ecSGreg Roach { 66c9c6f2ecSGreg Roach $this->layout = 'layouts/administration'; 67c9c6f2ecSGreg Roach 68c9c6f2ecSGreg Roach $api_key = $this->getPreference('api_key'); 69c9c6f2ecSGreg Roach 70c9c6f2ecSGreg Roach return $this->viewResponse('modules/here-maps/config', [ 71c9c6f2ecSGreg Roach 'api_key' => $api_key, 72c9c6f2ecSGreg Roach 'title' => $this->title(), 73c9c6f2ecSGreg Roach ]); 74c9c6f2ecSGreg Roach } 75c9c6f2ecSGreg Roach 76c9c6f2ecSGreg Roach /** 77c9c6f2ecSGreg Roach * Name of the map provider. 78c9c6f2ecSGreg Roach * 79c9c6f2ecSGreg Roach * @return string 80c9c6f2ecSGreg Roach */ 81c9c6f2ecSGreg Roach public function title(): string 82c9c6f2ecSGreg Roach { 839fb58c9eSGreg Roach return /* I18N: https://wego.here.com */ I18N::translate('Here maps'); 84c9c6f2ecSGreg Roach } 85c9c6f2ecSGreg Roach 86c9c6f2ecSGreg Roach /** 87c9c6f2ecSGreg Roach * @param ServerRequestInterface $request 88c9c6f2ecSGreg Roach * 89c9c6f2ecSGreg Roach * @return ResponseInterface 90c9c6f2ecSGreg Roach */ 91c9c6f2ecSGreg Roach public function postAdminAction(ServerRequestInterface $request): ResponseInterface 92c9c6f2ecSGreg Roach { 93*748dbe15SGreg Roach $api_key = Validator::parsedBody($request)->string('api_key'); 94c9c6f2ecSGreg Roach 95*748dbe15SGreg Roach $this->setPreference('api_key', $api_key); 96c9c6f2ecSGreg Roach 97c9c6f2ecSGreg Roach FlashMessages::addMessage(I18N::translate('The preferences for the module “%s” have been updated.', $this->title()), 'success'); 98c9c6f2ecSGreg Roach 99c9c6f2ecSGreg Roach return redirect($this->getConfigLink()); 100c9c6f2ecSGreg Roach } 101c9c6f2ecSGreg Roach 102c9c6f2ecSGreg Roach /** 103c9c6f2ecSGreg Roach * Parameters to create a TileLayer in LeafletJs. 104c9c6f2ecSGreg Roach * 105c9c6f2ecSGreg Roach * @return array<object> 106c9c6f2ecSGreg Roach */ 107c9c6f2ecSGreg Roach public function leafletJsTileLayers(): array 108c9c6f2ecSGreg Roach { 109c9c6f2ecSGreg Roach $api_key = $this->getPreference('api_key'); 110c9c6f2ecSGreg Roach 111c9c6f2ecSGreg Roach return [ 112c9c6f2ecSGreg Roach (object) [ 11349f2029cSGreg Roach 'apiKey' => $api_key, 114c9c6f2ecSGreg Roach 'attribution' => '<a href="https://legal.here.com/en/terms/serviceterms/us">Terms of use</a> ©1987-2021 HERE', 115c9c6f2ecSGreg Roach 'base' => 'base', 116c9c6f2ecSGreg Roach 'format' => 'png8', 117c9c6f2ecSGreg Roach 'label' => 'Normal', 118c9c6f2ecSGreg Roach 'mapID' => 'newest', 119ca91f642SDavid Drury 'maxZoom' => 19, 120c9c6f2ecSGreg Roach 'minZoom' => 2, 121c9c6f2ecSGreg Roach 'size' => 512, 122c9c6f2ecSGreg Roach 'subdomains' => ['1', '2', '3', '4'], 123c9c6f2ecSGreg Roach 'type' => 'maptile', 124c9c6f2ecSGreg Roach 'url' => 'https://{s}.{base}.maps.ls.hereapi.com/maptile/2.1/{type}/{mapID}/{variant}/{z}/{x}/{y}/{size}/{format}?apiKey={apiKey}', 125c9c6f2ecSGreg Roach 'variant' => 'normal.day', 126c9c6f2ecSGreg Roach ], 127c9c6f2ecSGreg Roach (object) [ 12849f2029cSGreg Roach 'apiKey' => $api_key, 129c9c6f2ecSGreg Roach 'attribution' => '<a href="https://legal.here.com/en/terms/serviceterms/us">Terms of use</a> ©1987-2021 HERE', 130c9c6f2ecSGreg Roach 'base' => 'base', 131c9c6f2ecSGreg Roach 'format' => 'png8', 132c9c6f2ecSGreg Roach 'label' => 'Grey', 133c9c6f2ecSGreg Roach 'mapID' => 'newest', 134ca91f642SDavid Drury 'maxZoom' => 19, 135c9c6f2ecSGreg Roach 'minZoom' => 2, 136c9c6f2ecSGreg Roach 'size' => 512, 137c9c6f2ecSGreg Roach 'subdomains' => ['1', '2', '3', '4'], 138c9c6f2ecSGreg Roach 'type' => 'maptile', 139c9c6f2ecSGreg Roach 'url' => 'https://{s}.{base}.maps.ls.hereapi.com/maptile/2.1/{type}/{mapID}/{variant}/{z}/{x}/{y}/{size}/{format}?apiKey={apiKey}', 140c9c6f2ecSGreg Roach 'variant' => 'normal.day.grey', 141c9c6f2ecSGreg Roach ], 142c9c6f2ecSGreg Roach (object) [ 14331daae99SGreg Roach 'apiKey' => $api_key, 144c9c6f2ecSGreg Roach 'attribution' => '<a href="https://legal.here.com/en/terms/serviceterms/us">Terms of use</a> ©1987-2021 HERE', 145c9c6f2ecSGreg Roach 'base' => 'aerial', 146c9c6f2ecSGreg Roach 'format' => 'png8', 147c9c6f2ecSGreg Roach 'label' => 'Terrain', 148c9c6f2ecSGreg Roach 'mapID' => 'newest', 149ca91f642SDavid Drury 'maxZoom' => 19, 150c9c6f2ecSGreg Roach 'minZoom' => 2, 151c9c6f2ecSGreg Roach 'size' => 512, 152c9c6f2ecSGreg Roach 'subdomains' => ['1', '2', '3', '4'], 153c9c6f2ecSGreg Roach 'type' => 'maptile', 154c9c6f2ecSGreg Roach 'url' => 'https://{s}.{base}.maps.ls.hereapi.com/maptile/2.1/{type}/{mapID}/{variant}/{z}/{x}/{y}/{size}/{format}?apiKey={apiKey}', 155c9c6f2ecSGreg Roach 'variant' => 'terrain.day', 156c9c6f2ecSGreg Roach ], 157c9c6f2ecSGreg Roach ]; 158c9c6f2ecSGreg Roach } 159c9c6f2ecSGreg Roach} 160