From d868b3de33307414e31ac89507ca16876e7dc15b Mon Sep 17 00:00:00 2001 From: hupe13 <73023225+hupe13@users.noreply.github.com> Date: Mon, 26 Dec 2022 15:06:17 +0100 Subject: [PATCH 1/7] readme.md, shortcode helper, tile url corrected URL to reference.html#path https://github.com/bozdoz/wp-plugin-leaflet-map/issues/188#issue-1500122245: Shortcode Helper obfuscate tile url: https://github.com/bozdoz/wp-plugin-leaflet-map/issues/187#issue-1498774222 --- README.md | 6 +- readme.txt | 16 ++--- scripts/shortcode-helper.js | 4 +- shortcodes/class.map-shortcode.php | 108 ++++++++++++++--------------- 4 files changed, 67 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index dc99a84..3dfba7a 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ Add a popup to the line by adding text to the content of the shortcode: | `addresses`, `latlngs`, or `coordinates` | For geocoded addresses, latitude/longitude, or x/y coordinates for Image Maps; ex: `[leaflet-line latlngs="41, 29; 44, 18"]` or addresses: `[leaflet-line addresses="Istanbul; Sarajevo"]` | | `fitbounds` | Fit the map to the bounds of the line (instead of whatever center you gave the map originally) | -And the following Shape Options. See https://leafletjs.com/reference-1.3.4.html#path for details. +And the following Shape Options. See https://leafletjs.com/reference.html#path for details. 'stroke', 'color', 'weight', 'opacity', 'lineCap', 'lineJoin', 'dashArray', 'dashOffset' 'fill', 'fillColor', 'fillOpacity', 'fillRule', 'className' @@ -248,7 +248,7 @@ Add a circle to the map by adding `[leaflet-circle]`. You can specify the positi | `fitbounds` | Fit the map to the bounds of the circle (instead of whatever center you gave the map originally) | | radius | Radius of the circle in meters | -Includes all style options: See https://leafletjs.com/reference-1.3.4.html#path +Includes all style options: See https://leafletjs.com/reference.html#path --- @@ -279,7 +279,7 @@ Or you can add a geojson shape via a url: | `popupanchor` | Set the anchor position of the popup: e.g. "40,60" for 40px left 60px top | | `tooltipanchor` | Set the anchor position of the tooltip: e.g. "40,60" for 40px left 60px top | -Includes all style options: See https://leafletjs.com/reference-1.3.4.html#path. Also, if you want to add feature +Includes all style options: See https://leafletjs.com/reference.html#path. Also, if you want to add feature properties to the popups, use the inner content and curly brackets to substitute the values: `[leaflet-geojson]Field A = {field_a}[/leaflet-geojson]`. diff --git a/readme.txt b/readme.txt index 29f259c..062d9fe 100644 --- a/readme.txt +++ b/readme.txt @@ -64,9 +64,9 @@ Add a link to the popup messages the same way you would add any other link with Add a line to the map by adding `[leaflet-line]`. You can specify the postions with a list separated by semi-colon `;` or bar `|` using lat/lng: `[leaflet-line latlngs="41, 29; 44, 18"]` or addresses: `[leaflet-line addresses="Istanbul; Sarajevo"]`, or x/y coordinates for image maps. -Add a circle to the map by adding `[leaflet-circle]`. You can specify the position using `lat` and `lng` and the radius in meters using `radius`. You can also customize the style using [Leaflet's Path options](https://leafletjs.com/reference-1.3.4.html#path-option). Example: `[leaflet-circle message="max distance" lng=5.117909610271454 lat=52.097914814706094 radius=17500 color="#0DC143" fillOpacity=0.1]`. +Add a circle to the map by adding `[leaflet-circle]`. You can specify the position using `lat` and `lng` and the radius in meters using `radius`. You can also customize the style using [Leaflet's Path options](https://leafletjs.com/reference.html#path-option). Example: `[leaflet-circle message="max distance" lng=5.117909610271454 lat=52.097914814706094 radius=17500 color="#0DC143" fillOpacity=0.1]`. -Or you can add a geojson shape via a url (make sure you are allowed to access it if it's not hosted on your own server): `[leaflet-geojson src="https://example.com/path/to.geojson"]`. Add custom popups with field names; try out the default src file and fields like so: +Or you can add a geojson shape via a url (make sure you are allowed to access it if it's not hosted on your own server): `[leaflet-geojson src="https://example.com/path/to.geojson"]`. Add custom popups with field names; try out the default src file and fields like so: ` [leaflet-map fitbounds] @@ -177,7 +177,7 @@ For more FAQs, please visit the [FAQ section on GitHub here](https://github.com/ * actual bugfix to multiple or missing enqueue map scripts = 2.23.1 = -* possible bugfix to failing to enqueue map when shortcode rendered +* possible bugfix to failing to enqueue map when shortcode rendered = 2.23.0 = * Added iconUrl to leaflet-geojson shortcode. @@ -294,7 +294,7 @@ For more FAQs, please visit the [FAQ section on GitHub here](https://github.com/ * Added string interpolation for GeoJSON popups to use feature properties (thanks to [@geraldo](https://github.com/geraldo)) = 2.9.1 = -* Fixes for PHP 7.2: made all method arguments identical +* Fixes for PHP 7.2: made all method arguments identical * Added minified JavaScript files for site speed = 2.8.6 = @@ -355,13 +355,13 @@ For more FAQs, please visit the [FAQ section on GitHub here](https://github.com/ * Added basic marker icon support (with attributes "iconUrl", "iconAnchor", etc.); = 2.6.0 = -* Changes to map creation which may solve an occasional marker creation JavaScript error +* Changes to map creation which may solve an occasional marker creation JavaScript error * Added more attributes to marker shortcode (draggable, title, alt, opacity) * Added doubleClickZoom global, database option to globally disable double click zooming (by default), because it's more inline with disabling scroll zooming by default. Box zooming on the other hand is more intentional = 2.5.0 = -* Some improvements to the codebase; -* added the same styling options for lines as there are for geojson; +* Some improvements to the codebase; +* added the same styling options for lines as there are for geojson; * added popups to lines, as there are for markers; * added an example to the shortcode admin page for the style attributes on lines; * added code and another example for disabling all map interactions (all zooms, keyboard, etc); @@ -553,7 +553,7 @@ Fixed array_filter on some older PHP versions Fixed possible JavaScript error "Unexpected token <"; fix was to remove spaces = 2.6.0 = -Changes to map creation which may solve an occasional marker creation JavaScript error +Changes to map creation which may solve an occasional marker creation JavaScript error = 2.0.2 = OpenStreetMap.org has an SSL certificate (osm.org didn't) diff --git a/scripts/shortcode-helper.js b/scripts/shortcode-helper.js index 203c550..6f19280 100644 --- a/scripts/shortcode-helper.js +++ b/scripts/shortcode-helper.js @@ -11,7 +11,7 @@ function update_marker() { var latlng = marker_1.getLatLng(); marker_input.value = - '[leaflet-marker lat=' + latlng.lat + ' lng=' + latlng.lng + ']'; + '[leaflet-marker lat=' + latlng.lat + ' lng=' + latlng.lng + ']My Marker[/leaflet-marker]'; } function update_map() { @@ -24,7 +24,7 @@ latlng.lng + ' zoom=' + map_1.getZoom() + - ']'; + ']My Marker[/leaflet-marker]'; // update marker if outside of bounds if (!bounds.contains(marker_1.getLatLng())) { diff --git a/shortcodes/class.map-shortcode.php b/shortcodes/class.map-shortcode.php index a76c268..509e9db 100644 --- a/shortcodes/class.map-shortcode.php +++ b/shortcodes/class.map-shortcode.php @@ -2,10 +2,10 @@ /** * Map Shortcode * - * Displays map with [leaflet-map ...atts] + * Displays map with [leaflet-map ...atts] * * JavaScript equivalent : L.map("id"); - * + * * @category Shortcode * @author Benjamin J DeLong */ @@ -13,7 +13,7 @@ // Exit if accessed directly if (!defined('ABSPATH')) { exit; -} +} require_once LEAFLET_MAP__PLUGIN_DIR . 'shortcodes/class.shortcode.php'; @@ -33,8 +33,8 @@ public function __construct() } /** - * Enqueue Scripts and Styles for Leaflet - * + * Enqueue Scripts and Styles for Leaflet + * * @return null */ protected function enqueue() @@ -47,7 +47,7 @@ protected function enqueue() wp_enqueue_script('leaflet_mapquest_plugin'); } - // enqueue user-defined scripts + // enqueue user-defined scripts // ! will fire for each map do_action('leaflet_map_enqueue'); } @@ -55,8 +55,8 @@ protected function enqueue() /** * Merge shortcode options with default options * - * @param array|string $atts key value pairs from shortcode - * + * @param array|string $atts key value pairs from shortcode + * * @return array new atts, which is actually an array */ protected function getAtts($atts='') @@ -66,42 +66,42 @@ protected function getAtts($atts='') $settings = Leaflet_Map_Plugin_Settings::init(); - $atts['zoom'] = array_key_exists('zoom', $atts) ? + $atts['zoom'] = array_key_exists('zoom', $atts) ? $zoom : $settings->get('default_zoom'); - $atts['height'] = empty($height) ? + $atts['height'] = empty($height) ? $settings->get('default_height') : $height; $atts['width'] = empty($width) ? $settings->get('default_width') : $width; - $atts['zoomcontrol'] = isset($zoomControl) + $atts['zoomcontrol'] = isset($zoomControl) ? $zoomControl - : (array_key_exists('zoomcontrol', $atts) - ? $zoomcontrol + : (array_key_exists('zoomcontrol', $atts) + ? $zoomcontrol : $settings->get('show_zoom_controls')); - $atts['min_zoom'] = array_key_exists('min_zoom', $atts) ? + $atts['min_zoom'] = array_key_exists('min_zoom', $atts) ? $min_zoom : $settings->get('default_min_zoom'); - $atts['max_zoom'] = empty($max_zoom) ? + $atts['max_zoom'] = empty($max_zoom) ? $settings->get('default_max_zoom') : $max_zoom; $atts['scrollwheel'] = isset($scrollWheelZoom) ? $scrollWheelZoom - : (array_key_exists('scrollwheel', $atts) - ? $scrollwheel + : (array_key_exists('scrollwheel', $atts) + ? $scrollwheel : $settings->get('scroll_wheel_zoom')); - $atts['doubleclickzoom'] = array_key_exists('doubleclickzoom', $atts) ? + $atts['doubleclickzoom'] = array_key_exists('doubleclickzoom', $atts) ? $doubleclickzoom : $settings->get('double_click_zoom'); - + // @deprecated backwards-compatible fit_markers - $atts['fit_markers'] = array_key_exists('fit_markers', $atts) ? + $atts['fit_markers'] = array_key_exists('fit_markers', $atts) ? $fit_markers : $settings->get('fit_markers'); // fitbounds is what it should be called @since v2.12.0 - $atts['fitbounds'] = array_key_exists('fitbounds', $atts) ? + $atts['fitbounds'] = array_key_exists('fitbounds', $atts) ? $fitbounds : $atts['fit_markers']; /* allow percent, but add px for ints */ $atts['height'] .= is_numeric($atts['height']) ? 'px' : ''; - $atts['width'] .= is_numeric($atts['width']) ? 'px' : ''; + $atts['width'] .= is_numeric($atts['width']) ? 'px' : ''; - /* - need to allow 0 or empty for removal of attribution + /* + need to allow 0 or empty for removal of attribution */ if (!array_key_exists('attribution', $atts)) { $atts['attribution'] = $settings->get('default_attribution'); @@ -113,15 +113,15 @@ protected function getAtts($atts='') 'closePopupOnClick' => isset($closePopupOnClick) ? $closePopupOnClick : (isset($closepopuponclick) - ? $closepopuponclick + ? $closepopuponclick : null), - 'trackResize' => isset($trackResize) + 'trackResize' => isset($trackResize) ? $trackResize - : (isset($trackresize) - ? $trackresize + : (isset($trackresize) + ? $trackresize : null), - 'boxZoom' => isset($boxzoom) - ? $boxzoom + 'boxZoom' => isset($boxzoom) + ? $boxzoom : (isset($boxZoom) ? $boxZoom : null), @@ -143,7 +143,7 @@ protected function getAtts($atts='') // filter out nulls $map_options = $this->LM->filter_null($map_options); - + // custom field for moving to JavaScript $map_options['fitBounds'] = $atts['fitbounds']; @@ -171,7 +171,7 @@ protected function getAtts($atts='') // custom field for moving to javascript // filter out any unwanted HTML tags (including img) $map_options['attribution'] = wp_kses_post($atts['attribution']); - + // wrap as JSON $atts['map_options'] = json_encode($map_options); @@ -179,7 +179,7 @@ protected function getAtts($atts='') $raw_map_options = array(); foreach($map_options as $key=>$val) { $original_value = isset($atts[$key]) ? $atts[$key] : null; - + $liquid = $this->LM->liquid($original_value); if ($liquid && isset($liquid['raw']) && $liquid['raw']) { @@ -198,7 +198,7 @@ protected function getAtts($atts='') 'zoomOffset' => empty($zoomoffset) ? $settings->get('zoomoffset') : $zoomoffset, 'noWrap' => filter_var(empty($nowrap) ? $settings->get('tile_no_wrap') : $nowrap, FILTER_VALIDATE_BOOLEAN) ); - + $tile_layer_options = $this->LM->filter_empty_string($tile_layer_options); $tile_layer_options = $this->LM->filter_null($tile_layer_options); @@ -217,25 +217,25 @@ protected function getAtts($atts='') ); $atts = $this->LM->sanitize_inclusive($atts, $validations); - + return $atts; } /** * Get the div tag for the map to instantiate - * + * * @param string $height * @param string $width - * + * * @return string HTML div element */ protected function getDiv($height, $width) { // div does not get wrapped in script tags ob_start(); ?> -
get('default_lat') : $lat; $lng = empty($lng) ? $settings->get('default_lng') : $lng; - + // validate lat/lng $lat = $this->LM->filter_float($lat); $lng = $this->LM->filter_float($lng); @@ -279,14 +279,14 @@ protected function getHTML($atts='', $content=null) } else { $tileurl = empty($tileurl) ? $settings->get('map_tile_url') : $tileurl; } - + $detect_retina = empty($detect_retina) ? $settings->get('detect_retina') : $detect_retina; $detect_retina = filter_var($detect_retina, FILTER_VALIDATE_BOOLEAN); $tile_min_zoom = $minZoom; $tile_max_zoom = $maxZoom; - + // fix #114 tilelayer zoom with detect_retina if ($detect_retina && $minZoom == $maxZoom) { $tile_min_zoom = 'undefined'; @@ -294,28 +294,28 @@ protected function getHTML($atts='', $content=null) } /* should be iterated for multiple maps */ - ob_start(); + ob_start(); ?>/*