PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.1
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 1.1.2 All 80 releases
ablocks / includes / blocks / map / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.9.1, at includes/blocks/map/block.php

116 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\Map;
3
4 use ABlocks\Classes\BlockBaseAbstract;
5 use ABlocks\Classes\CssGenerator;
6 use ABlocks\Controls\CssFilter;
7 use ABlocks\Controls\Range;
8
9 class Block extends BlockBaseAbstract {
10 protected $block_name = 'map';
11 protected $style_depends = [ 'ablocks-leaflet-style', 'ablocks-leaflet-full-screen-style' ];
12 protected $script_depends = [ 'ablocks-leaflet-script', 'ablocks-leaflet-full-screen-script' ];
13
14 public function build_css( $attributes ) {
15 $css_generator = new CssGenerator( $attributes, $this->block_name );
16
17 $css_generator->add_class_styles(
18 '{{WRAPPER}} .ablocks-map-block',
19 $this->get_map_size_css( $attributes ),
20 $this->get_map_size_css( $attributes, 'Tablet' ),
21 $this->get_map_size_css( $attributes, 'Mobile' )
22 );
23
24 return $css_generator->generate_css();
25 }
26
27 private function get_map_size_css( $attributes, $device = '' ) {
28 $size_css = [];
29
30 if ( ! empty( $attributes['mapWidth'][ 'value' . $device ] ) ) {
31 $width_value = $attributes['mapWidth'][ 'value' . $device ];
32 $width_unit = $attributes['mapWidth'][ 'valueUnit' . $device ] ?? '%';
33 $size_css['width'] = $width_value . $width_unit;
34 }
35
36 if ( ! empty( $attributes['mapHeight'][ 'value' . $device ] ) ) {
37 $height_value = $attributes['mapHeight'][ 'value' . $device ];
38 $height_unit = ! empty( $attributes['mapHeight'][ 'valueUnit' . $device ] )
39 ? $attributes['mapHeight'][ 'valueUnit' . $device ]
40 : 'px';
41
42 $size_css['height'] = $height_value . $height_unit;
43 }
44
45 return array_merge(
46 Range::get_css([
47 'attributeValue' => $attributes['mapWidth'],
48 'attribute_object_key' => 'value',
49 'isResponsive' => true,
50 'defaultValue' => 100,
51 'hasUnit' => true,
52 'unitDefaultValue' => '%',
53 'property' => 'width',
54 'device' => $device,
55 ]),
56 Range::get_css([
57 'attributeValue' => $attributes['mapHeight'],
58 'attribute_object_key' => 'value',
59 'isResponsive' => true,
60 'defaultValue' => 500,
61 'hasUnit' => true,
62 'unitDefaultValue' => 'px',
63 'property' => 'height',
64 'device' => $device,
65 ]),
66 $size_css,
67 isset( $attributes['cssFilter'] ) ? CssFilter::get_css( $attributes['cssFilter'], '', $device ) : []
68 );
69 }
70
71 public static function escaping_array_data( $array ) {
72 foreach ( $array as $key => &$value ) {
73 if ( is_array( $value ) ) {
74 $value = self::escaping_array_data( $value );
75 } else {
76 $value = esc_attr( $value );
77 }
78 }
79 return $array;
80 }
81
82 public function render_block_content( $attributes, $content, $block_instance ) {
83 $custom_icon_url = '';
84 if ( isset( $attributes['iconImageUrl'] ) && ! empty( $attributes['iconImageUrl'] ) ) {
85 $custom_icon_url = esc_url( $attributes['iconImageUrl'] );
86 } else {
87 $custom_icon_url = esc_url( ABLOCKS_ASSETS_URL . 'images/marker-icon.png' );
88 }
89 $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,
98 );
99
100 ob_start();
101 ?>
102 <div
103 data-settings='<?php
104 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
105 echo htmlspecialchars( wp_json_encode( $settings ), ENT_QUOTES, 'UTF-8' );
106 ?>'
107 class="ablocks-map-block"
108 >
109 </div>
110 <?php
111 $output = ob_get_clean();
112 return $output;
113 }
114
115 }
116