PluginProbe
Leaflet Map / 3.4.5
Leaflet Map v3.4.5
3.4.7 3.4.6 trunk 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.11.5 2.12.0 2.13.0 2.14.0 2.15.0 2.16.0 2.16.1 2.16.2 2.17.0 2.17.1 2.17.2 2.17.3 2.18.0 2.19.0 2.19.1 All 49 releases
← All changes | shortcodes/class.marker-shortcode.php +62 -125 2.17.23.4.5 View file →
@@ -2,11 +2,9 @@
2 2 /**
3 3 * Marker Shortcode
4 4 *
5 5 * Use with [leaflet-marker ...]
6 - *
7 - * PHP Version 5.5
8 - *
6 + *
9 7 * @category Shortcode
10 8 * @author Benjamin J DeLong <ben@bozdoz.com>
11 9 */
12 10
@@ -23,18 +21,18 @@
23 21 class Leaflet_Marker_Shortcode extends Leaflet_Shortcode
24 22 {
25 23 /**
26 24 * Get Script for Shortcode
27 - *
25 + *
28 26 * @param string $atts could be an array
29 27 * @param string $content optional
30 - *
28 + *
31 29 * @return null
32 30 */
33 31 protected function getHTML($atts='', $content=null)
34 32 {
35 33 if (!empty($atts)) {
36 - extract($atts);
34 + extract($atts, EXTR_SKIP);
37 35 }
38 36
39 37 if (!empty($address)) {
40 38 include_once LEAFLET_MAP__PLUGIN_DIR . 'class.geocoder.php';
@@ -42,12 +40,18 @@
42 40 $lat = $location->lat;
43 41 $lng = $location->lng;
44 42 }
45 43
46 - /* add to user contributed lat lng */
44 + $lat_set = isset($lat) || isset($y);
45 + $lng_set = isset($lng) || isset($x);
46 +
47 47 $lat = empty($lat) ? ( empty($y) ? '0' : $y ) : $lat;
48 48 $lng = empty($lng) ? ( empty($x) ? '0' : $x ) : $lng;
49 49
50 + // validate lat/lng
51 + $lat = $this->LM->filter_float($lat);
52 + $lng = $this->LM->filter_float($lng);
53 +
50 54 $default_marker = 'L.marker';
51 55
52 56 if (isset($svg)) {
53 57 $svg = filter_var($svg, FILTER_VALIDATE_BOOLEAN);
@@ -72,8 +76,9 @@
72 76 'shadowUrl' => isset($shadowurl) ? $shadowurl : null,
73 77 'shadowSize' => isset($shadowsize) ? $shadowsize : null,
74 78 'shadowAnchor' => isset($shadowanchor) ? $shadowanchor : null,
75 79 'popupAnchor' => isset($popupanchor) ? $popupanchor : null,
80 + 'tooltipAnchor' => isset($tooltipanchor) ? $tooltipanchor : null,
76 81 'svg' => isset($svg) ? $svg : null,
77 82 'background' => isset($background) ? $background : null,
78 83 'iconClass' => isset($iconclass) ? $iconclass : null,
79 84 'color' => isset($color) ? $color : null
@@ -80,134 +85,66 @@
80 85 );
81 86
82 87 $args = array(
83 88 'draggable' => FILTER_VALIDATE_BOOLEAN,
84 - 'title' => FILTER_SANITIZE_STRING,
85 - 'alt' => FILTER_SANITIZE_STRING,
89 + 'title' => FILTER_SANITIZE_SPECIAL_CHARS,
90 + 'alt' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
86 91 'zIndexOffset' => FILTER_VALIDATE_INT,
87 92 'opacity' => FILTER_VALIDATE_FLOAT,
88 93 'iconUrl' => FILTER_SANITIZE_URL,
89 94 'shadowUrl' => FILTER_SANITIZE_URL,
90 - 'iconSize' => array(
91 - 'filter' => FILTER_SANITIZE_STRING,
92 - 'flags' => FILTER_FORCE_ARRAY
93 - ),
94 - 'iconAnchor' => array(
95 - 'filter' => FILTER_SANITIZE_STRING,
96 - 'flags' => FILTER_FORCE_ARRAY
97 - ),
98 - 'shadowSize' => array(
99 - 'filter' => FILTER_SANITIZE_STRING,
100 - 'flags' => FILTER_FORCE_ARRAY
101 - ),
102 - 'shadowAnchor' => array(
103 - 'filter' => FILTER_SANITIZE_STRING,
104 - 'flags' => FILTER_FORCE_ARRAY
105 - ),
106 - 'popupAnchor' => array(
107 - 'filter' => FILTER_SANITIZE_STRING,
108 - 'flags' => FILTER_FORCE_ARRAY
109 - ),
95 + 'iconSize' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
96 + 'iconAnchor' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
97 + 'shadowSize' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
98 + 'shadowAnchor' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
99 + 'popupAnchor' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
100 + 'tooltipAnchor' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
110 101 'svg' => FILTER_VALIDATE_BOOLEAN,
111 - 'background' => FILTER_SANITIZE_STRING,
112 - 'iconClass' => FILTER_SANITIZE_STRING,
113 - 'color' => FILTER_SANITIZE_STRING
102 + 'background' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
103 + 'iconClass' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
104 + 'color' => FILTER_SANITIZE_FULL_SPECIAL_CHARS
114 105 );
115 106
116 107 $options = $this->LM->json_sanitize($options, $args);
117 108
118 - if ($options === '[]') {
119 - $options = '{}';
109 + ob_start();
110 + ?>/*<script>*/
111 +var map = window.WPLeafletMapPlugin.getCurrentMap();
112 +var group = window.WPLeafletMapPlugin.getCurrentGroup();
113 +var marker_options = window.WPLeafletMapPlugin.getIconOptions(<?php echo $options; ?>);
114 +var marker = <?php echo $default_marker; ?>(
115 + [<?php echo $lat . ',' . $lng; ?>],
116 + marker_options
117 +);
118 +var is_image = map.is_image_map;
119 +<?php
120 +if (!$lat_set && !$lng_set) {
121 + /* update lat lng to previous map's center */
122 +?>
123 + marker.setLatLng( map.getCenter() );
124 +<?php
125 +}
126 +?>
127 +if (marker_options.draggable) {
128 + marker.on('dragend', function () {
129 + var latlng = this.getLatLng();
130 + var lat = latlng.lat;
131 + var lng = latlng.lng;
132 + if (is_image) {
133 + console.log('leaflet-marker y=' + lat + ' x=' + lng);
134 + } else {
135 + console.log('leaflet-marker lat=' + lat + ' lng=' + lng);
120 136 }
121 - ob_start();
122 - ?>
123 - <script>
124 - window.WPLeafletMapPlugin = window.WPLeafletMapPlugin || [];
125 - window.WPLeafletMapPlugin.push(function () {
126 - var marker_options = (function () {
127 - var _options = <?php echo $options; ?>;
128 - var iconArrays = [
129 - 'iconSize',
130 - 'iconAnchor',
131 - 'shadowSize',
132 - 'shadowAnchor',
133 - 'popupAnchor'
134 - ];
135 - var default_icon = L.Icon.Default.prototype.options;
136 - if (_options.iconUrl) {
137 - // arrays are strings, unfortunately...
138 - for (var i = 0, len = iconArrays.length; i < len; i++) {
139 - var option_name = iconArrays[i],
140 - option = _options[ option_name ];
141 - // convert "1,2" to [1, 2];
142 - if (option) {
143 - var arr = option.join('').split(',');
144 - // array.map for ie<9
145 - for (var j = 0, lenJ = arr.length; j < lenJ; j++) {
146 - arr[j] = Number(arr[j]);
147 - }
148 - _options[ option_name ] = arr;
149 - }
150 - }
151 - // default popupAnchor
152 - if (!_options.popupAnchor) {
153 - // set (roughly) to size of icon
154 - _options.popupAnchor = (function (i_size) {
155 - // copy array
156 - i_size = i_size.slice();
157 -
158 - // inverse coordinates
159 - i_size[0] = 0;
160 - i_size[1] *= -1;
161 - // bottom position on popup is 7px
162 - i_size[1] -= 3;
163 - return i_size;
164 - })(_options.iconSize || default_icon.iconSize);
165 - }
137 + });
138 +}
139 +marker.addTo( group );
140 +<?php
141 + $this->LM->add_popup_to_shape($atts, $content, 'marker');
142 +?>
143 +window.WPLeafletMapPlugin.markers.push( marker );
144 + <?php
166 145
167 - _options.icon = new L.Icon( _options );
168 - }
169 - return _options;
170 - })();
171 - var draggable = marker_options.draggable;
172 - var marker = <?php echo $default_marker; ?>(
173 - [<?php echo $lat . ',' . $lng; ?>],
174 - marker_options
175 - );
176 - var map = window.WPLeafletMapPlugin.getCurrentMap();
177 - var is_image = map.is_image_map;
178 - var group = window.WPLeafletMapPlugin.getCurrentGroup();
179 - <?php
180 - if (empty($lat) && empty($lng)) {
181 - /* update lat lng to previous map's center */
182 - ?>
183 - if (!is_image) {
184 - marker.setLatLng( map.getCenter() );
185 - } else {
186 - marker.setLatLng( [0, 0] );
187 - }
188 - <?php
189 - }
190 - ?>
191 - if (draggable) {
192 - marker.on('dragend', function () {
193 - var latlng = this.getLatLng(),
194 - lat = latlng.lat,
195 - lng = latlng.lng;
196 - if (is_image) {
197 - console.log('leaflet-marker y=' + lat + ' x=' + lng);
198 - } else {
199 - console.log('leaflet-marker lat=' + lat + ' lng=' + lng);
200 - }
201 - });
202 - }
203 - marker.addTo( group );
204 - <?php
205 - $this->LM->add_popup_to_shape($atts, $content, 'marker');
206 - ?>
207 - window.WPLeafletMapPlugin.markers.push( marker );
208 - }); // end add function
209 - </script>
210 - <?php
211 - return ob_get_clean();
146 + $script = ob_get_clean();
147 +
148 + return $this->wrap_script($script, 'WPLeafletMarkerShortcode');
212 149 }
213 -}
150 +}