Plugin Directory

Changeset 2401199 for leaflet-map


Ignore:
Timestamp:
10/17/2020 12:39:43 AM (5 years ago)
Author:
bozdoz
Message:

v2.20.0: Adds tap and advanced raw filters to map options

Location:
leaflet-map
Files:
16 edited
1 copied

Legend:

Unmodified
Added
Removed
  • leaflet-map/tags/2.20.0/README.md

    r2400542 r2401199  
    132132| `tileurl`                    | 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' |
    133133| `subdomains`                 | 'abc'                                                |
     134| `tap`                        | true                                                 |
    134135
    135136---
  • leaflet-map/tags/2.20.0/class.admin.php

    r2267880 r2401199  
    104104    {
    105105        wp_enqueue_style('leaflet_admin_stylesheet');
    106         wp_enqueue_script('custom_plugin_js', plugins_url('scripts/shortcode-helper.min.js', LEAFLET_MAP__PLUGIN_FILE), Array('leaflet_js'), false);
     106       
     107        if (defined('WP_DEBUG') && WP_DEBUG) {
     108            $minified = '';
     109        } else {
     110            $minified = '.min';
     111        }
     112
     113        wp_enqueue_script('custom_plugin_js', plugins_url(sprintf('scripts/shortcode-helper%s.js', $minified), LEAFLET_MAP__PLUGIN_FILE), Array('leaflet_js'), false);
    107114
    108115        include 'templates/shortcode-helper.php';
  • leaflet-map/tags/2.20.0/class.leaflet-map.php

    r2400542 r2401199  
    348348        return Leaflet_Map_Plugin_Settings::init();
    349349    }
     350
     351    /**
     352     * Parses liquid tags from a string
     353     *
     354     * @param string $str
     355     *
     356     * @return array|null
     357     */
     358    public function liquid ($str) {
     359        if (!is_string($str)) {
     360            return null;
     361        }
     362        $templateRegex = "/\{ *(.*?) *\}/";
     363        preg_match_all($templateRegex, $str, $matches);
     364               
     365        if (!$matches[1]) {
     366            return null;
     367        }
     368       
     369        $str = $matches[1][0];
     370
     371        $tags = explode(' | ', $str);
     372
     373        $original = array_shift($tags);
     374
     375        if (!$tags) {
     376            return null;
     377        }
     378
     379        $output = array();
     380
     381        foreach ($tags as $tag) {
     382            $tagParts = explode(': ', $tag);
     383            $tagName = array_shift($tagParts);
     384            $tagValue = implode(': ', $tagParts) || true;
     385
     386            $output[$tagName] = $tagValue;
     387        }
     388
     389        // preserve the original
     390        $output['original'] = $original;
     391
     392        return $output;
     393    }
     394
     395    /**
     396     * Renders a json-like string, removing quotes for values
     397     *
     398     * allows JavaScript variables to be added directly
     399     *
     400     * @return string
     401     */
     402    public function rawDict ($arr) {
     403        $obj = '{';
     404       
     405        foreach ($arr as $key=>$val) {
     406            $obj .= "\"$key\": $val,";
     407        }
     408
     409        $obj .= '}';
     410
     411        return $obj;
     412    }
    350413}
  • leaflet-map/tags/2.20.0/leaflet-map.php

    r2400542 r2401199  
    99 * Text Domain: leaflet-map
    1010 * Domain Path: /languages/
    11  * Version: 2.19.1
     11 * Version: 2.20.0
    1212 * License: GPL2
    1313 * Leaflet Map is free software: you can redistribute it and/or modify
     
    3030}
    3131
    32 define('LEAFLET_MAP__PLUGIN_VERSION', '2.19.1');
     32define('LEAFLET_MAP__PLUGIN_VERSION', '2.20.0');
    3333define('LEAFLET_MAP__PLUGIN_FILE', __FILE__);
    3434define('LEAFLET_MAP__PLUGIN_DIR', plugin_dir_path(__FILE__));
  • leaflet-map/tags/2.20.0/readme.txt

    r2400542 r2401199  
    88Requires at least: 4.6
    99Tested up to: 5.5.1
    10 Version: 2.19.1
    11 Stable tag: 2.19.1
     10Version: 2.20.0
     11Stable tag: 2.20.0
    1212License: GPLv2
    1313License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    142142== Changelog ==
    143143
     144= 2.20.0 =
     145* Adds tap and !tap option to [leaflet-map]
     146* Adds (advanced) raw filter syntax for map options: [leaflet-map dragging="{!L.Browser.mobile | raw}"]
     147
    144148= 2.19.1 =
    145149* Bumps leaflet version to 1.7.1
  • leaflet-map/tags/2.20.0/shortcodes/class.image-shortcode.php

    r2340086 r2401199  
    6060                    doubleClickZoom: <?php echo $doubleclickzoom; ?>,
    6161                    attributionControl: false
    62                 }, <?php echo $more_options; ?>, {
     62                }, <?php echo $map_options; ?>, {
    6363                    crs: L.CRS.Simple
    6464                });
  • leaflet-map/tags/2.20.0/shortcodes/class.map-shortcode.php

    r2400542 r2401199  
    7272            $settings->get('default_height') : $height;
    7373        $atts['width'] = empty($width) ? $settings->get('default_width') : $width;
    74         $atts['zoomcontrol'] = array_key_exists('zoomcontrol', $atts) ?
    75             $zoomcontrol : $settings->get('show_zoom_controls');
     74        $atts['zoomcontrol'] = isset($zoomControl)
     75            ? $zoomControl
     76            : (array_key_exists('zoomcontrol', $atts)
     77                ? $zoomcontrol
     78                : $settings->get('show_zoom_controls'));
    7679        $atts['min_zoom'] = array_key_exists('min_zoom', $atts) ?
    7780            $min_zoom : $settings->get('default_min_zoom');
    7881        $atts['max_zoom'] = empty($max_zoom) ?
    7982            $settings->get('default_max_zoom') : $max_zoom;
    80         $atts['scrollwheel'] = array_key_exists('scrollwheel', $atts)
    81             ? $scrollwheel
    82             : $settings->get('scroll_wheel_zoom');
     83        $atts['scrollwheel'] = isset($scrollWheelZoom)
     84            ? $scrollWheelZoom
     85            : (array_key_exists('scrollwheel', $atts)
     86                ? $scrollwheel
     87                : $settings->get('scroll_wheel_zoom'));
    8388        $atts['doubleclickzoom'] = array_key_exists('doubleclickzoom', $atts) ?
    8489            $doubleclickzoom : $settings->get('double_click_zoom');
     
    123128        }
    124129
    125         /* allow a bunch of other options */
     130        /* allow a bunch of other (boolean) options */
    126131        // http://leafletjs.com/reference.html#map
    127         $more_options = array(
    128             'closePopupOnClick' => isset($closepopuponclick) ?
    129                 $closepopuponclick : null,
    130             'trackResize' => isset($trackresize) ? $trackresize : null,
    131             'boxZoom' => (isset($boxzoom)
     132        $map_options = array(
     133            'closePopupOnClick' => isset($closePopupOnClick)
     134                ? $closePopupOnClick
     135                : (isset($closepopuponclick)
     136                    ? $closepopuponclick
     137                    : null),
     138            'trackResize' => isset($trackResize)
     139                ? $trackResize
     140                : (isset($trackresize)
     141                    ? $trackresize
     142                    : null),
     143            'boxZoom' => isset($boxzoom)
    132144                ? $boxzoom
    133                 : isset($boxZoom))
     145                : (isset($boxZoom)
    134146                    ? $boxZoom
    135                     : null,
     147                    : null),
    136148            'touchZoom' => isset($touchZoom) ? $touchZoom : null,
    137149            'dragging' => isset($dragging) ? $dragging : null,
    138150            'keyboard' => isset($keyboard) ? $keyboard : null,
     151            'zoomAnimation' => isset($zoomAnimation) ?  $zoomAnimation : null,
     152            'fadeAnimation' => isset($fadeAnimation) ?  $fadeAnimation : null,
     153            'markerZoomAnimation' => isset($markerZoomAnimation) ?  $markerZoomAnimation : null,
     154            'inertia' => isset($inertia) ?  $inertia : null,
     155            'worldCopyJump' => isset($worldCopyJump) ?  $worldCopyJump : null,
     156            'tap' => isset($tap) ? $tap : null,
     157            'bounceAtZoomLimits' => isset($bounceAtZoomLimits) ? $bounceAtZoomLimits : null,
    139158        );
    140159
    141160        // filter out nulls
    142         $more_options = $this->LM->filter_null($more_options);
     161        $map_options = $this->LM->filter_null($map_options);
    143162       
    144163        // custom field for moving to JavaScript
    145         $more_options['fitBounds'] = $atts['fitbounds'];
     164        $map_options['fitBounds'] = $atts['fitbounds'];
    146165
    147166        // change string booleans to booleans
    148         $more_options = filter_var_array($more_options, FILTER_VALIDATE_BOOLEAN);
     167        $map_options = filter_var_array($map_options, FILTER_VALIDATE_BOOLEAN);
    149168
    150169        if ($maxBounds) {
    151             $more_options['maxBounds'] = $maxBounds;
     170            $map_options['maxBounds'] = $maxBounds;
    152171        }
    153172
    154173        // custom field for moving to javascript
    155         $more_options['attribution'] = $atts['attribution'];
     174        $map_options['attribution'] = $atts['attribution'];
    156175
    157176        // wrap as JSON
    158         $atts['more_options'] = json_encode($more_options);
     177        $atts['map_options'] = json_encode($map_options);
     178
     179        // get raw variables, allowing for JavaScript variables in values
     180        $raw_map_options = array();
     181        foreach($map_options as $key=>$val) {
     182            $original_value = isset($atts[$key]) ? $atts[$key] : null;
     183           
     184            $liquid = $this->LM->liquid($original_value);
     185
     186            if ($liquid && isset($liquid['raw']) && $liquid['raw']) {
     187                // raw leaves original value un-quoted
     188                $raw_map_options[$key] = $liquid['original'];
     189            }
     190        }
     191
     192        $atts['raw_map_options'] = $this->LM->rawDict($raw_map_options);
    159193
    160194        return $atts;
     
    231265                    doubleClickZoom: <?php echo $doubleclickzoom; ?>,
    232266                    attributionControl: false
    233                 }, <?php echo $more_options; ?>);
     267                }, <?php echo $map_options; ?>,
     268                <?php echo $raw_map_options; ?>);
    234269            window.WPLeafletMapPlugin.createMap(options)
    235270                .setView(<?php
  • leaflet-map/tags/2.20.0/shortcodes/class.shortcode.php

    r2267880 r2401199  
    1717abstract class Leaflet_Shortcode
    1818{
     19    /**
     20     * @var Leaflet_Map
     21     */
    1922    protected $LM;
    2023
     
    4043     * Instantiate class and get HTML for shortcode
    4144     *
    42      * @param array  $atts    string|array
    43      * @param string $content Optional
     45     * @param array|string|null $atts    string|array
     46     * @param string|null      $content Optional
    4447     *
    45      * @return string (see above)
     48     * @return string HTML
    4649     */
    4750    public static function shortcode($atts = '', $content = null)
  • leaflet-map/trunk/README.md

    r2400542 r2401199  
    132132| `tileurl`                    | 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' |
    133133| `subdomains`                 | 'abc'                                                |
     134| `tap`                        | true                                                 |
    134135
    135136---
  • leaflet-map/trunk/class.admin.php

    r2267880 r2401199  
    104104    {
    105105        wp_enqueue_style('leaflet_admin_stylesheet');
    106         wp_enqueue_script('custom_plugin_js', plugins_url('scripts/shortcode-helper.min.js', LEAFLET_MAP__PLUGIN_FILE), Array('leaflet_js'), false);
     106       
     107        if (defined('WP_DEBUG') && WP_DEBUG) {
     108            $minified = '';
     109        } else {
     110            $minified = '.min';
     111        }
     112
     113        wp_enqueue_script('custom_plugin_js', plugins_url(sprintf('scripts/shortcode-helper%s.js', $minified), LEAFLET_MAP__PLUGIN_FILE), Array('leaflet_js'), false);
    107114
    108115        include 'templates/shortcode-helper.php';
  • leaflet-map/trunk/class.leaflet-map.php

    r2400542 r2401199  
    348348        return Leaflet_Map_Plugin_Settings::init();
    349349    }
     350
     351    /**
     352     * Parses liquid tags from a string
     353     *
     354     * @param string $str
     355     *
     356     * @return array|null
     357     */
     358    public function liquid ($str) {
     359        if (!is_string($str)) {
     360            return null;
     361        }
     362        $templateRegex = "/\{ *(.*?) *\}/";
     363        preg_match_all($templateRegex, $str, $matches);
     364               
     365        if (!$matches[1]) {
     366            return null;
     367        }
     368       
     369        $str = $matches[1][0];
     370
     371        $tags = explode(' | ', $str);
     372
     373        $original = array_shift($tags);
     374
     375        if (!$tags) {
     376            return null;
     377        }
     378
     379        $output = array();
     380
     381        foreach ($tags as $tag) {
     382            $tagParts = explode(': ', $tag);
     383            $tagName = array_shift($tagParts);
     384            $tagValue = implode(': ', $tagParts) || true;
     385
     386            $output[$tagName] = $tagValue;
     387        }
     388
     389        // preserve the original
     390        $output['original'] = $original;
     391
     392        return $output;
     393    }
     394
     395    /**
     396     * Renders a json-like string, removing quotes for values
     397     *
     398     * allows JavaScript variables to be added directly
     399     *
     400     * @return string
     401     */
     402    public function rawDict ($arr) {
     403        $obj = '{';
     404       
     405        foreach ($arr as $key=>$val) {
     406            $obj .= "\"$key\": $val,";
     407        }
     408
     409        $obj .= '}';
     410
     411        return $obj;
     412    }
    350413}
  • leaflet-map/trunk/leaflet-map.php

    r2400542 r2401199  
    99 * Text Domain: leaflet-map
    1010 * Domain Path: /languages/
    11  * Version: 2.19.1
     11 * Version: 2.20.0
    1212 * License: GPL2
    1313 * Leaflet Map is free software: you can redistribute it and/or modify
     
    3030}
    3131
    32 define('LEAFLET_MAP__PLUGIN_VERSION', '2.19.1');
     32define('LEAFLET_MAP__PLUGIN_VERSION', '2.20.0');
    3333define('LEAFLET_MAP__PLUGIN_FILE', __FILE__);
    3434define('LEAFLET_MAP__PLUGIN_DIR', plugin_dir_path(__FILE__));
  • leaflet-map/trunk/readme.txt

    r2400542 r2401199  
    88Requires at least: 4.6
    99Tested up to: 5.5.1
    10 Version: 2.19.1
    11 Stable tag: 2.19.1
     10Version: 2.20.0
     11Stable tag: 2.20.0
    1212License: GPLv2
    1313License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    142142== Changelog ==
    143143
     144= 2.20.0 =
     145* Adds tap and !tap option to [leaflet-map]
     146* Adds (advanced) raw filter syntax for map options: [leaflet-map dragging="{!L.Browser.mobile | raw}"]
     147
    144148= 2.19.1 =
    145149* Bumps leaflet version to 1.7.1
  • leaflet-map/trunk/shortcodes/class.image-shortcode.php

    r2340086 r2401199  
    6060                    doubleClickZoom: <?php echo $doubleclickzoom; ?>,
    6161                    attributionControl: false
    62                 }, <?php echo $more_options; ?>, {
     62                }, <?php echo $map_options; ?>, {
    6363                    crs: L.CRS.Simple
    6464                });
  • leaflet-map/trunk/shortcodes/class.map-shortcode.php

    r2400542 r2401199  
    7272            $settings->get('default_height') : $height;
    7373        $atts['width'] = empty($width) ? $settings->get('default_width') : $width;
    74         $atts['zoomcontrol'] = array_key_exists('zoomcontrol', $atts) ?
    75             $zoomcontrol : $settings->get('show_zoom_controls');
     74        $atts['zoomcontrol'] = isset($zoomControl)
     75            ? $zoomControl
     76            : (array_key_exists('zoomcontrol', $atts)
     77                ? $zoomcontrol
     78                : $settings->get('show_zoom_controls'));
    7679        $atts['min_zoom'] = array_key_exists('min_zoom', $atts) ?
    7780            $min_zoom : $settings->get('default_min_zoom');
    7881        $atts['max_zoom'] = empty($max_zoom) ?
    7982            $settings->get('default_max_zoom') : $max_zoom;
    80         $atts['scrollwheel'] = array_key_exists('scrollwheel', $atts)
    81             ? $scrollwheel
    82             : $settings->get('scroll_wheel_zoom');
     83        $atts['scrollwheel'] = isset($scrollWheelZoom)
     84            ? $scrollWheelZoom
     85            : (array_key_exists('scrollwheel', $atts)
     86                ? $scrollwheel
     87                : $settings->get('scroll_wheel_zoom'));
    8388        $atts['doubleclickzoom'] = array_key_exists('doubleclickzoom', $atts) ?
    8489            $doubleclickzoom : $settings->get('double_click_zoom');
     
    123128        }
    124129
    125         /* allow a bunch of other options */
     130        /* allow a bunch of other (boolean) options */
    126131        // http://leafletjs.com/reference.html#map
    127         $more_options = array(
    128             'closePopupOnClick' => isset($closepopuponclick) ?
    129                 $closepopuponclick : null,
    130             'trackResize' => isset($trackresize) ? $trackresize : null,
    131             'boxZoom' => (isset($boxzoom)
     132        $map_options = array(
     133            'closePopupOnClick' => isset($closePopupOnClick)
     134                ? $closePopupOnClick
     135                : (isset($closepopuponclick)
     136                    ? $closepopuponclick
     137                    : null),
     138            'trackResize' => isset($trackResize)
     139                ? $trackResize
     140                : (isset($trackresize)
     141                    ? $trackresize
     142                    : null),
     143            'boxZoom' => isset($boxzoom)
    132144                ? $boxzoom
    133                 : isset($boxZoom))
     145                : (isset($boxZoom)
    134146                    ? $boxZoom
    135                     : null,
     147                    : null),
    136148            'touchZoom' => isset($touchZoom) ? $touchZoom : null,
    137149            'dragging' => isset($dragging) ? $dragging : null,
    138150            'keyboard' => isset($keyboard) ? $keyboard : null,
     151            'zoomAnimation' => isset($zoomAnimation) ?  $zoomAnimation : null,
     152            'fadeAnimation' => isset($fadeAnimation) ?  $fadeAnimation : null,
     153            'markerZoomAnimation' => isset($markerZoomAnimation) ?  $markerZoomAnimation : null,
     154            'inertia' => isset($inertia) ?  $inertia : null,
     155            'worldCopyJump' => isset($worldCopyJump) ?  $worldCopyJump : null,
     156            'tap' => isset($tap) ? $tap : null,
     157            'bounceAtZoomLimits' => isset($bounceAtZoomLimits) ? $bounceAtZoomLimits : null,
    139158        );
    140159
    141160        // filter out nulls
    142         $more_options = $this->LM->filter_null($more_options);
     161        $map_options = $this->LM->filter_null($map_options);
    143162       
    144163        // custom field for moving to JavaScript
    145         $more_options['fitBounds'] = $atts['fitbounds'];
     164        $map_options['fitBounds'] = $atts['fitbounds'];
    146165
    147166        // change string booleans to booleans
    148         $more_options = filter_var_array($more_options, FILTER_VALIDATE_BOOLEAN);
     167        $map_options = filter_var_array($map_options, FILTER_VALIDATE_BOOLEAN);
    149168
    150169        if ($maxBounds) {
    151             $more_options['maxBounds'] = $maxBounds;
     170            $map_options['maxBounds'] = $maxBounds;
    152171        }
    153172
    154173        // custom field for moving to javascript
    155         $more_options['attribution'] = $atts['attribution'];
     174        $map_options['attribution'] = $atts['attribution'];
    156175
    157176        // wrap as JSON
    158         $atts['more_options'] = json_encode($more_options);
     177        $atts['map_options'] = json_encode($map_options);
     178
     179        // get raw variables, allowing for JavaScript variables in values
     180        $raw_map_options = array();
     181        foreach($map_options as $key=>$val) {
     182            $original_value = isset($atts[$key]) ? $atts[$key] : null;
     183           
     184            $liquid = $this->LM->liquid($original_value);
     185
     186            if ($liquid && isset($liquid['raw']) && $liquid['raw']) {
     187                // raw leaves original value un-quoted
     188                $raw_map_options[$key] = $liquid['original'];
     189            }
     190        }
     191
     192        $atts['raw_map_options'] = $this->LM->rawDict($raw_map_options);
    159193
    160194        return $atts;
     
    231265                    doubleClickZoom: <?php echo $doubleclickzoom; ?>,
    232266                    attributionControl: false
    233                 }, <?php echo $more_options; ?>);
     267                }, <?php echo $map_options; ?>,
     268                <?php echo $raw_map_options; ?>);
    234269            window.WPLeafletMapPlugin.createMap(options)
    235270                .setView(<?php
  • leaflet-map/trunk/shortcodes/class.shortcode.php

    r2267880 r2401199  
    1717abstract class Leaflet_Shortcode
    1818{
     19    /**
     20     * @var Leaflet_Map
     21     */
    1922    protected $LM;
    2023
     
    4043     * Instantiate class and get HTML for shortcode
    4144     *
    42      * @param array  $atts    string|array
    43      * @param string $content Optional
     45     * @param array|string|null $atts    string|array
     46     * @param string|null      $content Optional
    4447     *
    45      * @return string (see above)
     48     * @return string HTML
    4649     */
    4750    public static function shortcode($atts = '', $content = null)
Note: See TracChangeset for help on using the changeset viewer.