1c9c6f2ecSGreg Roach<?php 2c9c6f2ecSGreg Roach 3c9c6f2ecSGreg Roach/** 4c9c6f2ecSGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 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 222bcd31b3SGreg Roachuse Fisharebest\Webtrees\FlashMessages; 23c9c6f2ecSGreg Roachuse Fisharebest\Webtrees\I18N; 242bcd31b3SGreg Roachuse Fisharebest\Webtrees\Site; 25748dbe15SGreg Roachuse Fisharebest\Webtrees\Validator; 262bcd31b3SGreg Roachuse Psr\Http\Message\ResponseInterface; 272bcd31b3SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 282bcd31b3SGreg Roach 292bcd31b3SGreg Roachuse function redirect; 30c9c6f2ecSGreg Roach 31c9c6f2ecSGreg Roach/** 32c9c6f2ecSGreg Roach * Class MapLocationGeonames - use geonames to find locations 33c9c6f2ecSGreg Roach */ 34c9c6f2ecSGreg Roachclass MapGeoLocationGeonames extends AbstractModule implements ModuleConfigInterface, ModuleMapGeoLocationInterface 35c9c6f2ecSGreg Roach{ 36c9c6f2ecSGreg Roach use ModuleConfigTrait; 37c9c6f2ecSGreg Roach use ModuleMapGeoLocationTrait; 38c9c6f2ecSGreg Roach 39c9c6f2ecSGreg Roach /** 40c9c6f2ecSGreg Roach * Name of the map provider. 41c9c6f2ecSGreg Roach * 42c9c6f2ecSGreg Roach * @return string 43c9c6f2ecSGreg Roach */ 44c9c6f2ecSGreg Roach public function title(): string 45c9c6f2ecSGreg Roach { 46c9c6f2ecSGreg Roach return /* I18N: https://www.geonames.org */ I18N::translate('GeoNames'); 47c9c6f2ecSGreg Roach } 482bcd31b3SGreg Roach 492bcd31b3SGreg Roach /** 502bcd31b3SGreg Roach * Should this module be enabled when it is first installed? 512bcd31b3SGreg Roach * 522bcd31b3SGreg Roach * @return bool 532bcd31b3SGreg Roach */ 542bcd31b3SGreg Roach public function isEnabledByDefault(): bool 552bcd31b3SGreg Roach { 562bcd31b3SGreg Roach return false; 572bcd31b3SGreg Roach } 582bcd31b3SGreg Roach 592bcd31b3SGreg Roach /** 602bcd31b3SGreg Roach * @return ResponseInterface 612bcd31b3SGreg Roach */ 622bcd31b3SGreg Roach public function getAdminAction(): ResponseInterface 632bcd31b3SGreg Roach { 642bcd31b3SGreg Roach $this->layout = 'layouts/administration'; 652bcd31b3SGreg Roach 662bcd31b3SGreg Roach // This was a global setting before it became a module setting... 672bcd31b3SGreg Roach $default = Site::getPreference('geonames'); 682bcd31b3SGreg Roach $username = $this->getPreference('username', $default); 692bcd31b3SGreg Roach 702bcd31b3SGreg Roach return $this->viewResponse('modules/geonames/config', [ 712bcd31b3SGreg Roach 'username' => $username, 722bcd31b3SGreg Roach 'title' => $this->title(), 732bcd31b3SGreg Roach ]); 742bcd31b3SGreg Roach } 752bcd31b3SGreg Roach 762bcd31b3SGreg Roach /** 772bcd31b3SGreg Roach * @param ServerRequestInterface $request 782bcd31b3SGreg Roach * 792bcd31b3SGreg Roach * @return ResponseInterface 802bcd31b3SGreg Roach */ 812bcd31b3SGreg Roach public function postAdminAction(ServerRequestInterface $request): ResponseInterface 822bcd31b3SGreg Roach { 83748dbe15SGreg Roach $api_key = Validator::parsedBody($request)->string('username'); 842bcd31b3SGreg Roach 85748dbe15SGreg Roach $this->setPreference('username', $api_key); 862bcd31b3SGreg Roach 872bcd31b3SGreg Roach FlashMessages::addMessage(I18N::translate('The preferences for the module “%s” have been updated.', $this->title()), 'success'); 882bcd31b3SGreg Roach 892bcd31b3SGreg Roach return redirect($this->getConfigLink()); 902bcd31b3SGreg Roach } 91c9c6f2ecSGreg Roach} 92