These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Class for the 'display_map' parser hooks. |
||
5 | * |
||
6 | * @since 0.7 |
||
7 | * |
||
8 | * @licence GNU GPL v2+ |
||
9 | * @author Jeroen De Dauw < [email protected] > |
||
10 | */ |
||
11 | class MapsDisplayMap extends ParserHook { |
||
12 | |||
13 | /** |
||
14 | * Gets the name of the parser hook. |
||
15 | * @see ParserHook::getName |
||
16 | * |
||
17 | * @since 0.7 |
||
18 | * |
||
19 | * @return string |
||
20 | */ |
||
21 | 4 | protected function getName() { |
|
22 | 4 | return 'display_map'; |
|
23 | } |
||
24 | |||
25 | /** |
||
26 | * @see ParserHook::getNames() |
||
27 | * |
||
28 | * @since 2.0 |
||
29 | * |
||
30 | * @return array |
||
31 | */ |
||
32 | 4 | protected function getNames() { |
|
33 | 4 | return [ $this->getName(), 'display_point', 'display_points', 'display_line' ]; |
|
34 | } |
||
35 | |||
36 | /** |
||
37 | * Returns an array containing the parameter info. |
||
38 | * @see ParserHook::getParameterInfo |
||
39 | * |
||
40 | * @since 0.7 |
||
41 | * |
||
42 | * @return array |
||
43 | */ |
||
44 | 5 | protected function getParameterInfo( $type ) { |
|
45 | 5 | $params = MapsMapper::getCommonParameters(); |
|
46 | |||
47 | 5 | $params['mappingservice']['feature'] = 'display_map'; |
|
48 | |||
49 | 5 | $params['coordinates'] = [ |
|
50 | 5 | 'type' => 'string', |
|
51 | 5 | 'aliases' => [ 'coords', 'location', 'address', 'addresses', 'locations', 'points' ], |
|
52 | 5 | 'default' => [], |
|
53 | 5 | 'islist' => true, |
|
54 | 5 | 'delimiter' => $type === ParserHook::TYPE_FUNCTION ? ';' : "\n", |
|
55 | 5 | 'message' => 'maps-displaymap-par-coordinates', |
|
56 | ]; |
||
57 | |||
58 | 5 | return array_merge( $params, self::getCommonMapParams() ); |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * Temporary hack. Do not rely upon. |
||
63 | * @since 3.0 |
||
64 | * @deprecated |
||
65 | * @return array |
||
66 | */ |
||
67 | 5 | public static function getCommonMapParams() { |
|
68 | 5 | global $egMapsDefaultTitle, $egMapsDefaultLabel; |
|
69 | |||
70 | 5 | $params['title'] = [ |
|
71 | 5 | 'name' => 'title', |
|
72 | 5 | 'default' => $egMapsDefaultTitle, |
|
73 | ]; |
||
74 | |||
75 | 5 | $params['label'] = [ |
|
76 | 5 | 'default' => $egMapsDefaultLabel, |
|
77 | 5 | 'aliases' => 'text', |
|
78 | ]; |
||
79 | |||
80 | 5 | $params['icon'] = [ |
|
81 | 5 | 'default' => '', // TODO: image param |
|
82 | ]; |
||
83 | |||
84 | 5 | $params['visitedicon'] = [ |
|
85 | 5 | 'default' => '', //TODO: image param |
|
86 | ]; |
||
87 | |||
88 | 5 | $params['lines'] = [ |
|
89 | 5 | 'type' => 'mapsline', |
|
90 | 5 | 'default' => [], |
|
91 | 5 | 'delimiter' => ';', |
|
92 | 5 | 'islist' => true, |
|
93 | ]; |
||
94 | |||
95 | 5 | $params['polygons'] = [ |
|
96 | 5 | 'type' => 'mapspolygon', |
|
97 | 5 | 'default' => [], |
|
98 | 5 | 'delimiter' => ';', |
|
99 | 5 | 'islist' => true, |
|
100 | ]; |
||
101 | |||
102 | 5 | $params['circles'] = [ |
|
103 | 5 | 'type' => 'mapscircle', |
|
104 | 5 | 'default' => [], |
|
105 | 5 | 'delimiter' => ';', |
|
106 | 5 | 'islist' => true, |
|
107 | ]; |
||
108 | |||
109 | 5 | $params['rectangles'] = [ |
|
110 | 5 | 'type' => 'mapsrectangle', |
|
111 | 5 | 'default' => [], |
|
112 | 5 | 'delimiter' => ';', |
|
113 | 5 | 'islist' => true, |
|
114 | ]; |
||
115 | |||
116 | 5 | $params['wmsoverlay'] = [ |
|
117 | 5 | 'type' => 'wmsoverlay', |
|
118 | 5 | 'default' => false, |
|
119 | 5 | 'delimiter' => ' ', |
|
120 | ]; |
||
121 | |||
122 | 5 | $params['maxzoom'] = [ |
|
123 | 5 | 'type' => 'integer', |
|
124 | 5 | 'default' => false, |
|
125 | 5 | 'manipulatedefault' => false, |
|
126 | 5 | 'dependencies' => 'minzoom', |
|
127 | ]; |
||
128 | |||
129 | 5 | $params['minzoom'] = [ |
|
130 | 5 | 'type' => 'integer', |
|
131 | 5 | 'default' => false, |
|
132 | 5 | 'manipulatedefault' => false, |
|
133 | 5 | 'lowerbound' => 0, |
|
134 | ]; |
||
135 | |||
136 | 5 | $params['copycoords'] = [ |
|
137 | 5 | 'type' => 'boolean', |
|
138 | 5 | 'default' => false, |
|
139 | ]; |
||
140 | |||
141 | 5 | $params['static'] = [ |
|
142 | 5 | 'type' => 'boolean', |
|
143 | 5 | 'default' => false, |
|
144 | ]; |
||
145 | |||
146 | // Give grep a chance to find the usages: |
||
147 | // maps-displaymap-par-title, maps-displaymap-par-label, maps-displaymap-par-icon, |
||
148 | // maps-displaymap-par-visitedicon, aps-displaymap-par-lines, maps-displaymap-par-polygons, |
||
149 | // maps-displaymap-par-circles, maps-displaymap-par-rectangles, maps-displaymap-par-wmsoverlay, |
||
150 | // maps-displaymap-par-maxzoom, maps-displaymap-par-minzoom, maps-displaymap-par-copycoords, |
||
151 | // maps-displaymap-par-static |
||
152 | 5 | foreach ( $params as $name => &$param ) { |
|
153 | 5 | if ( !array_key_exists( 'message', $param ) ) { |
|
154 | 5 | $param['message'] = 'maps-displaymap-par-' . $name; |
|
155 | 5 | } |
|
156 | 5 | } |
|
157 | |||
158 | 5 | return $params; |
|
159 | } |
||
160 | |||
161 | /** |
||
162 | * Returns the list of default parameters. |
||
163 | * @see ParserHook::getDefaultParameters |
||
164 | * |
||
165 | * @since 0.7 |
||
166 | * |
||
167 | * @return array |
||
168 | */ |
||
169 | 4 | protected function getDefaultParameters( $type ) { |
|
170 | 4 | return [ 'coordinates' ]; |
|
171 | } |
||
172 | |||
173 | /** |
||
174 | * Renders and returns the output. |
||
175 | * @see ParserHook::render |
||
176 | * |
||
177 | * @since 0.7 |
||
178 | * |
||
179 | * @param array $parameters |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | 4 | public function render( array $parameters ) { |
|
184 | 4 | $this->defaultMapZoom( $parameters ); |
|
185 | 4 | $this->trackMap(); |
|
186 | |||
187 | 4 | $renderer = new MapsDisplayMapRenderer( MapsMappingServices::getServiceInstance( $parameters['mappingservice'] ) ); |
|
0 ignored issues
–
show
|
|||
188 | |||
189 | 4 | return $renderer->renderMap( $parameters, $this->parser ); |
|
190 | } |
||
191 | |||
192 | 4 | private function defaultMapZoom( &$parameters ) { |
|
193 | 4 | $fullParams = $this->validator->getParameters(); |
|
194 | |||
195 | 4 | if ( array_key_exists( 'zoom', $fullParams ) && $fullParams['zoom']->wasSetToDefault() && count( $parameters['coordinates'] ) > 1 ) { |
|
196 | $parameters['zoom'] = false; |
||
197 | } |
||
198 | 4 | } |
|
199 | |||
200 | 4 | private function trackMap() { |
|
0 ignored issues
–
show
trackMap uses the super-global variable $GLOBALS which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
Loading history...
|
|||
201 | 4 | if ( $GLOBALS['egMapsEnableCategory'] ) { |
|
202 | $this->parser->addTrackingCategory( 'maps-tracking-category' ); |
||
203 | } |
||
204 | 4 | } |
|
205 | |||
206 | /** |
||
207 | * Returns the parser function options. |
||
208 | * @see ParserHook::getFunctionOptions |
||
209 | * |
||
210 | * @since 0.7 |
||
211 | * |
||
212 | * @return array |
||
213 | */ |
||
214 | 4 | protected function getFunctionOptions() { |
|
215 | return [ |
||
216 | 4 | 'noparse' => true, |
|
217 | 'isHTML' => true |
||
218 | 4 | ]; |
|
219 | } |
||
220 | |||
221 | /** |
||
222 | * @see ParserHook::getMessage() |
||
223 | * |
||
224 | * @since 1.0 |
||
225 | */ |
||
226 | public function getMessage() { |
||
227 | return 'maps-displaymap-description'; |
||
228 | } |
||
229 | |||
230 | } |
||
231 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.