Issues (2559)

app/Module/GoogleMaps.php (3 issues)

1
<?php
2
3
/**
4
 * webtrees: online genealogy
5
 * Copyright (C) 2025 webtrees development team
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
 */
17
18
declare(strict_types=1);
19
20
namespace Fisharebest\Webtrees\Module;
21
22
use Fisharebest\Webtrees\Auth;
0 ignored issues
show
The type Fisharebest\Webtrees\Auth was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use Fisharebest\Webtrees\FlashMessages;
0 ignored issues
show
The type Fisharebest\Webtrees\FlashMessages was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use Fisharebest\Webtrees\Http\Exceptions\HttpServerErrorException;
25
use Fisharebest\Webtrees\I18N;
0 ignored issues
show
The type Fisharebest\Webtrees\I18N was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
use Fisharebest\Webtrees\Validator;
27
use Psr\Http\Message\ResponseInterface;
28
use Psr\Http\Message\ServerRequestInterface;
29
30
use function e;
31
use function redirect;
32
33
/**
34
 * Class GoogleMaps - use maps within webtrees
35
 */
36
class GoogleMaps extends AbstractModule implements ModuleConfigInterface, ModuleMapProviderInterface
37
{
38
    use ModuleConfigTrait;
39
    use ModuleMapProviderTrait;
40
41
    /**
42
     * Name of the map provider.
43
     *
44
     * @return string
45
     */
46
    public function description(): string
47
    {
48
        $link = '<a href="https://www.google.com/maps" dir="ltr">www.google.com/maps</a>';
49
50
        // I18N: %s is a link/URL
51
        return I18N::translate('Create maps using %s.', $link);
52
    }
53
54
    public function isEnabledByDefault(): bool
55
    {
56
        return false;
57
    }
58
59
    /**
60
     * @return ResponseInterface
61
     */
62
    public function getAdminAction(): ResponseInterface
63
    {
64
        $this->layout = 'layouts/administration';
65
66
        $api_key = $this->getPreference('api_key');
67
68
        return $this->viewResponse('modules/google-maps/config', [
69
            'api_key' => $api_key,
70
            'title'   => $this->title(),
71
        ]);
72
    }
73
74
    /**
75
     * Name of the map provider.
76
     *
77
     * @return string
78
     */
79
    public function title(): string
80
    {
81
        return I18N::translate('Google™ maps');
82
    }
83
84
    /**
85
     * @param ServerRequestInterface $request
86
     *
87
     * @return ResponseInterface
88
     */
89
    public function postAdminAction(ServerRequestInterface $request): ResponseInterface
90
    {
91
        $api_key = Validator::parsedBody($request)->string('api_key');
92
93
        $this->setPreference('api_key', $api_key);
94
95
        FlashMessages::addMessage(I18N::translate('The preferences for the module “%s” have been updated.', $this->title()), 'success');
96
97
        return redirect($this->getConfigLink());
98
    }
99
100
    /**
101
     * Parameters to create a TileLayer in LeafletJs.
102
     *
103
     * @return array<object>
104
     */
105
    public function leafletJsTileLayers(): array
106
    {
107
        $api_key = $this->getPreference('api_key');
108
109
        if ($api_key === '') {
110
            $message = I18N::translate('This service requires an API key.');
111
112
            if (Auth::isAdmin()) {
113
                $message = '<a href="' . e($this->getConfigLink()) . '">' . $message . '</a>';
114
            }
115
116
            throw new HttpServerErrorException($message);
117
        }
118
119
        return [
120
            (object) [
121
                'GM_API_KEY'  => $api_key,
122
                'attribution' => 'Map data &copy2021 Google LLC <a href="https://www.google.com/intl/en-GB_US/help/terms_maps">Terms of use</a>',
123
                'default'     => true,
124
                'lyrs'        => 'm',
125
                'maxZoom'     => 20,
126
                'minZoom'     => 2,
127
                'subdomains'  => ['mt0', 'mt1', 'mt2', 'mt3'],
128
                'label'       => 'Streets',
129
                'url'         => 'https://{s}.google.com/vt/lyrs={lyrs}&x={x}&y={y}&z={z}',
130
                'localName'   => 'GoogleStreets',
131
            ],
132
            (object) [
133
                'GM_API_KEY'  => $api_key,
134
                'attribution' => 'Map data &copy2021 Google LLC <a href="https://www.google.com/intl/en-GB_US/help/terms_maps">Terms of use</a>',
135
                'default'     => false,
136
                'lyrs'        => 'y',
137
                'maxZoom'     => 20,
138
                'minZoom'     => 2,
139
                'subdomains'  => ['mt0', 'mt1', 'mt2', 'mt3'],
140
                'label'       => 'Hybrid',
141
                'url'         => 'https://{s}.google.com/vt/lyrs={lyrs}&x={x}&y={y}&z={z}',
142
                'localName'   => 'GoogleHybrid',
143
            ],
144
            (object) [
145
                'GM_API_KEY'  => $api_key,
146
                'attribution' => 'Map data &copy2021 Google LLC <a href="https://www.google.com/intl/en-GB_US/help/terms_maps">Terms of use</a>',
147
                'default'     => false,
148
                'lyrs'        => 's',
149
                'maxZoom'     => 20,
150
                'minZoom'     => 2,
151
                'subdomains'  => ['mt0', 'mt1', 'mt2', 'mt3'],
152
                'label'       => 'Satellite',
153
                'url'         => 'https://{s}.google.com/vt/lyrs={lyrs}&x={x}&y={y}&z={z}',
154
                'localName'   => 'GoogleSatellite',
155
            ],
156
            (object) [
157
                'GM_API_KEY'  => $api_key,
158
                'attribution' => 'Map data &copy2021 Google LLC <a href="https://www.google.com/intl/en-GB_US/help/terms_maps">Terms of use</a>',
159
                'default'     => false,
160
                'lyrs'        => 'p',
161
                'maxZoom'     => 20,
162
                'minZoom'     => 2,
163
                'subdomains'  => ['mt0', 'mt1', 'mt2', 'mt3'],
164
                'label'       => 'Terrain',
165
                'url'         => 'https://{s}.google.com/vt/lyrs={lyrs}&x={x}&y={y}&z={z}',
166
                'localName'   => 'GoogleTerrain',
167
            ],
168
        ];
169
    }
170
}
171