PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.0
2.14.0 2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 81 releases
← All changes | includes/blocks/map/block.php +38 -15 2.9.1 → 2.14.0 View file →
@@ -1,9 +1,14 @@
1 1 <?php
2 2 namespace ABlocks\Blocks\Map;
3 3
4 +if ( ! defined( 'ABSPATH' ) ) {
5 + exit;
6 +}
7 +
4 8 use ABlocks\Classes\BlockBaseAbstract;
5 9 use ABlocks\Classes\CssGenerator;
10 +use ABlocks\Classes\CssGeneratorV2;
6 11 use ABlocks\Controls\CssFilter;
7 12 use ABlocks\Controls\Range;
8 13
9 14 class Block extends BlockBaseAbstract {
@@ -10,9 +15,9 @@
10 15 protected $block_name = 'map';
11 16 protected $style_depends = [ 'ablocks-leaflet-style', 'ablocks-leaflet-full-screen-style' ];
12 17 protected $script_depends = [ 'ablocks-leaflet-script', 'ablocks-leaflet-full-screen-script' ];
13 18
14 - public function build_css( $attributes ) {
19 + public function build_css_v1( $attributes ) {
15 20 $css_generator = new CssGenerator( $attributes, $this->block_name );
16 21
17 22 $css_generator->add_class_styles(
18 23 '{{WRAPPER}} .ablocks-map-block',
@@ -17,14 +22,34 @@
17 22 $css_generator->add_class_styles(
18 23 '{{WRAPPER}} .ablocks-map-block',
19 24 $this->get_map_size_css( $attributes ),
20 25 $this->get_map_size_css( $attributes, 'Tablet' ),
21 - $this->get_map_size_css( $attributes, 'Mobile' )
26 + $this->get_map_size_css( $attributes, 'Mobile' ),
27 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_map_size_css( $attributes, $device ); } )
22 28 );
23 29
24 30 return $css_generator->generate_css();
25 31 }
32 + public function build_css_v2( $attributes ) {
33 + $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
26 34
35 + $css_generator->add_class_styles(
36 + '{{WRAPPER}} .ablocks-map-block',
37 + $this->get_map_size_css( $attributes ),
38 + $this->get_map_size_css( $attributes, 'Tablet' ),
39 + $this->get_map_size_css( $attributes, 'Mobile' ),
40 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_map_size_css( $attributes, $device ); } )
41 + );
42 +
43 + return $css_generator->generate_css();
44 + }
45 + public function build_css( $attributes ) {
46 + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
47 + return $this->build_css_v2( $attributes );
48 + }
49 + return $this->build_css_v1( $attributes );
50 + }
51 +
27 52 private function get_map_size_css( $attributes, $device = '' ) {
28 53 $size_css = [];
29 54
30 55 if ( ! empty( $attributes['mapWidth'][ 'value' . $device ] ) ) {
@@ -72,9 +97,9 @@
72 97 foreach ( $array as $key => &$value ) {
73 98 if ( is_array( $value ) ) {
74 99 $value = self::escaping_array_data( $value );
75 100 } else {
76 - $value = esc_attr( $value );
101 + $value = esc_attr( sanitize_text_field( $value ) );
77 102 }
78 103 }
79 104 return $array;
80 105 }
@@ -85,26 +110,24 @@
85 110 $custom_icon_url = esc_url( $attributes['iconImageUrl'] );
86 111 } else {
87 112 $custom_icon_url = esc_url( ABLOCKS_ASSETS_URL . 'images/marker-icon.png' );
88 113 }
114 +
89 115 $settings = array(
90 - 'mapMarkerList' => $this->escaping_array_data( isset( $attributes['mapMarkerList'] ) ? $attributes['mapMarkerList'] : array() ),
91 - 'mapZoom' => isset( $attributes['mapZoom'] ) ? esc_attr( $attributes['mapZoom'] ) : 10,
92 - 'scrollWheelZoom' => isset( $attributes['scrollWheelZoom'] ) ? esc_attr( $attributes['scrollWheelZoom'] ) : false,
93 - 'mapType' => isset( $attributes['mapType'] ) ? esc_attr( $attributes['mapType'] ) : 'GM',
94 - 'centerIndex' => isset( $attributes['centerIndex'] ) ? intval( esc_attr( $attributes['centerIndex'] ) ) : 0,
95 - 'defaultMarkerIcon' => $custom_icon_url,
96 - 'iconHeight' => isset( $attributes['iconHeight'] ) ? esc_attr( $attributes['iconHeight'] ) : 40,
97 - 'iconWidth' => isset( $attributes['iconWidth'] ) ? esc_attr( $attributes['iconWidth'] ) : 25,
116 + 'mapMarkerList' => $this->escaping_array_data( is_array( $attributes['mapMarkerList'] ?? null ) ? $attributes['mapMarkerList'] : [] ),
117 + 'mapZoom' => isset( $attributes['mapZoom'] ) ? intval( $attributes['mapZoom'] ) : 10,
118 + 'scrollWheelZoom' => isset( $attributes['scrollWheelZoom'] ) ? filter_var( $attributes['scrollWheelZoom'], FILTER_VALIDATE_BOOLEAN ) : false,
119 + 'mapType' => isset( $attributes['mapType'] ) ? sanitize_text_field( $attributes['mapType'] ) : 'GM',
120 + 'centerIndex' => isset( $attributes['centerIndex'] ) ? intval( $attributes['centerIndex'] ) : 0,
121 + 'defaultMarkerIcon' => $custom_icon_url,
122 + 'iconHeight' => isset( $attributes['iconHeight'] ) ? sanitize_text_field( $attributes['iconHeight'] ) : 40,
123 + 'iconWidth' => isset( $attributes['iconWidth'] ) ? sanitize_text_field( $attributes['iconWidth'] ) : 25,
98 124 );
99 125
100 126 ob_start();
101 127 ?>
102 128 <div
103 - data-settings='<?php
104 - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
105 - echo htmlspecialchars( wp_json_encode( $settings ), ENT_QUOTES, 'UTF-8' );
106 - ?>'
129 + data-settings='<?php echo esc_attr( wp_json_encode( $settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ) ); ?>'
107 130 class="ablocks-map-block"
108 131 >
109 132 </div>
110 133 <?php