| @@ -3,10 +3,8 @@ | ||
| 3 | 3 | * Line Shortcode |
| 4 | 4 | * |
| 5 | 5 | * Use with [leaflet-line ...] |
| 6 | 6 | * |
| 7 | - * PHP Version 5.5 | |
| 8 | - * | |
| 9 | 7 | * @category Shortcode |
| 10 | 8 | * @author Benjamin J DeLong <ben@bozdoz.com> |
| 11 | 9 | */ |
| 12 | 10 | |
| @@ -26,9 +24,9 @@ | ||
| 26 | 24 | * How leaflet renders the shape |
| 27 | 25 | * |
| 28 | 26 | * @var string $type |
| 29 | 27 | */ |
| 30 | - public static $type = 'line'; | |
| 28 | + protected $type = 'line'; | |
| 31 | 29 | |
| 32 | 30 | /** |
| 33 | 31 | * Get Script for Shortcode |
| 34 | 32 | * |
| @@ -39,9 +37,9 @@ | ||
| 39 | 37 | */ |
| 40 | 38 | protected function getHTML($atts='', $content=null) |
| 41 | 39 | { |
| 42 | 40 | if (!empty($atts)) { |
| 43 | - extract($atts); | |
| 41 | + extract($atts, EXTR_SKIP); | |
| 44 | 42 | } |
| 45 | 43 | |
| 46 | 44 | $style_json = $this->LM->get_style_json($atts); |
| 47 | 45 | |
| @@ -51,8 +49,10 @@ | ||
| 51 | 49 | if (!empty($fitline)) { |
| 52 | 50 | $fitbounds = $fitline; |
| 53 | 51 | } |
| 54 | 52 | |
| 53 | + $fitbounds = filter_var($fitbounds, FILTER_VALIDATE_BOOLEAN); | |
| 54 | + | |
| 55 | 55 | $locations = Array(); |
| 56 | 56 | |
| 57 | 57 | if (!empty($addresses)) { |
| 58 | 58 | include_once LEAFLET_MAP__PLUGIN_DIR . 'class.geocoder.php'; |
| @@ -80,16 +80,12 @@ | ||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | $location_json = json_encode($locations); |
| 83 | 83 | |
| 84 | - $class = self::getClass(); | |
| 85 | - | |
| 86 | - $type = $class::$type; | |
| 87 | - | |
| 88 | 84 | $js_factory = 'L.polyline'; |
| 89 | 85 | $collection = 'lines'; |
| 90 | 86 | |
| 91 | - if ($type == 'polygon') { | |
| 87 | + if ($this->type == 'polygon') { | |
| 92 | 88 | $js_factory = 'L.polygon'; |
| 93 | 89 | $locations = "[$location_json]"; |
| 94 | 90 | $collection = 'polygons'; |
| 95 | 91 | } |
| @@ -94,27 +90,23 @@ | ||
| 94 | 90 | $collection = 'polygons'; |
| 95 | 91 | } |
| 96 | 92 | |
| 97 | 93 | ob_start(); |
| 98 | - ?> | |
| 99 | - <script> | |
| 100 | - window.WPLeafletMapPlugin = window.WPLeafletMapPlugin || []; | |
| 101 | - window.WPLeafletMapPlugin.push(function () { | |
| 102 | - var previous_map = window.WPLeafletMapPlugin.getCurrentMap(), | |
| 103 | - shape = <?php echo $js_factory; ?>(<?php echo $location_json; ?>, <?php echo $style_json; ?>), | |
| 104 | - fitbounds = <?php echo $fitbounds; ?>, | |
| 105 | - group = window.WPLeafletMapPlugin.getCurrentGroup(); | |
| 106 | - shape.addTo( group ); | |
| 107 | - if (fitbounds) { | |
| 108 | - // zoom the map to the shape | |
| 109 | - previous_map.fitBounds( shape.getBounds() ); | |
| 110 | - } | |
| 111 | - <?php | |
| 112 | - $this->LM->add_popup_to_shape($atts, $content, 'shape'); | |
| 113 | - ?> | |
| 114 | - window.WPLeafletMapPlugin.<?php echo $collection; ?>.push( shape ); | |
| 115 | - }); | |
| 116 | - </script> | |
| 117 | - <?php | |
| 118 | - return ob_get_clean(); | |
| 94 | + ?>/*<script>*/ | |
| 95 | +var previous_map = window.WPLeafletMapPlugin.getCurrentMap(); | |
| 96 | +var group = window.WPLeafletMapPlugin.getCurrentGroup(); | |
| 97 | +var shape = <?php echo $js_factory; ?>(<?php echo $location_json; ?>, <?php echo $style_json; ?>); | |
| 98 | +var fitbounds = <?php echo $fitbounds ? '1' : '0'; ?>; | |
| 99 | +shape.addTo( group ); | |
| 100 | +if (fitbounds) { | |
| 101 | + // zoom the map to the shape | |
| 102 | + previous_map.fitBounds( shape.getBounds() ); | |
| 103 | +} | |
| 104 | +<?php | |
| 105 | + $this->LM->add_popup_to_shape($atts, $content, 'shape'); | |
| 106 | +?> | |
| 107 | +window.WPLeafletMapPlugin.<?php echo $collection; ?>.push( shape );<?php | |
| 108 | + $script = ob_get_clean(); | |
| 109 | + | |
| 110 | + return $this->wrap_script($script, 'WPLeafletLineShortcode'); | |
| 119 | 111 | } |
| 120 | 112 | } |