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 +138 -0 2.7.6 → 2.14.0 View file →
@@ -1,0 +1,138 @@
1 +<?php
2 +namespace ABlocks\Blocks\Map;
3 +
4 +if ( ! defined( 'ABSPATH' ) ) {
5 + exit;
6 +}
7 +
8 +use ABlocks\Classes\BlockBaseAbstract;
9 +use ABlocks\Classes\CssGenerator;
10 +use ABlocks\Classes\CssGeneratorV2;
11 +use ABlocks\Controls\CssFilter;
12 +use ABlocks\Controls\Range;
13 +
14 +class Block extends BlockBaseAbstract {
15 + protected $block_name = 'map';
16 + protected $style_depends = [ 'ablocks-leaflet-style', 'ablocks-leaflet-full-screen-style' ];
17 + protected $script_depends = [ 'ablocks-leaflet-script', 'ablocks-leaflet-full-screen-script' ];
18 +
19 + public function build_css_v1( $attributes ) {
20 + $css_generator = new CssGenerator( $attributes, $this->block_name );
21 +
22 + $css_generator->add_class_styles(
23 + '{{WRAPPER}} .ablocks-map-block',
24 + $this->get_map_size_css( $attributes ),
25 + $this->get_map_size_css( $attributes, 'Tablet' ),
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 ); } )
28 + );
29 +
30 + return $css_generator->generate_css();
31 + }
32 + public function build_css_v2( $attributes ) {
33 + $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
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 +
52 + private function get_map_size_css( $attributes, $device = '' ) {
53 + $size_css = [];
54 +
55 + if ( ! empty( $attributes['mapWidth'][ 'value' . $device ] ) ) {
56 + $width_value = $attributes['mapWidth'][ 'value' . $device ];
57 + $width_unit = $attributes['mapWidth'][ 'valueUnit' . $device ] ?? '%';
58 + $size_css['width'] = $width_value . $width_unit;
59 + }
60 +
61 + if ( ! empty( $attributes['mapHeight'][ 'value' . $device ] ) ) {
62 + $height_value = $attributes['mapHeight'][ 'value' . $device ];
63 + $height_unit = ! empty( $attributes['mapHeight'][ 'valueUnit' . $device ] )
64 + ? $attributes['mapHeight'][ 'valueUnit' . $device ]
65 + : 'px';
66 +
67 + $size_css['height'] = $height_value . $height_unit;
68 + }
69 +
70 + return array_merge(
71 + Range::get_css([
72 + 'attributeValue' => $attributes['mapWidth'],
73 + 'attribute_object_key' => 'value',
74 + 'isResponsive' => true,
75 + 'defaultValue' => 100,
76 + 'hasUnit' => true,
77 + 'unitDefaultValue' => '%',
78 + 'property' => 'width',
79 + 'device' => $device,
80 + ]),
81 + Range::get_css([
82 + 'attributeValue' => $attributes['mapHeight'],
83 + 'attribute_object_key' => 'value',
84 + 'isResponsive' => true,
85 + 'defaultValue' => 500,
86 + 'hasUnit' => true,
87 + 'unitDefaultValue' => 'px',
88 + 'property' => 'height',
89 + 'device' => $device,
90 + ]),
91 + $size_css,
92 + isset( $attributes['cssFilter'] ) ? CssFilter::get_css( $attributes['cssFilter'], '', $device ) : []
93 + );
94 + }
95 +
96 + public static function escaping_array_data( $array ) {
97 + foreach ( $array as $key => &$value ) {
98 + if ( is_array( $value ) ) {
99 + $value = self::escaping_array_data( $value );
100 + } else {
101 + $value = esc_attr( sanitize_text_field( $value ) );
102 + }
103 + }
104 + return $array;
105 + }
106 +
107 + public function render_block_content( $attributes, $content, $block_instance ) {
108 + $custom_icon_url = '';
109 + if ( isset( $attributes['iconImageUrl'] ) && ! empty( $attributes['iconImageUrl'] ) ) {
110 + $custom_icon_url = esc_url( $attributes['iconImageUrl'] );
111 + } else {
112 + $custom_icon_url = esc_url( ABLOCKS_ASSETS_URL . 'images/marker-icon.png' );
113 + }
114 +
115 + $settings = array(
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,
124 + );
125 +
126 + ob_start();
127 + ?>
128 + <div
129 + data-settings='<?php echo esc_attr( wp_json_encode( $settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ) ); ?>'
130 + class="ablocks-map-block"
131 + >
132 + </div>
133 + <?php
134 + $output = ob_get_clean();
135 + return $output;
136 + }
137 +
138 +}