PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.4
Kubio AI Page Builder v2.8.4
2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / build / block-library / blocks / map / index.php
kubio / build / block-library / blocks / map Last commit date
block.json 4 years ago index.php 1 year ago
index.php
74 lines
1 <?php
2
3 namespace Kubio\Blocks;
4
5 use Kubio\Core\Blocks\BlockBase;
6 use Kubio\Core\Registry;
7
8 class MapBlock extends BlockBase {
9
10 const OUTER = 'outer';
11 const WRAPPER = 'wrapper';
12 const IFRAME = 'iframe';
13
14 public function __construct( $block, $autoload = true ) {
15 parent::__construct( $block, $autoload );
16 }
17
18 public function computed() {
19 return array(
20 'address' => $this->getAttribute( 'address' ),
21 'zoom' => $this->getAttribute( 'zoom' ),
22 );
23 }
24
25 public function mapPropsToElements() {
26 $address = $this->getAttribute( 'address' );
27 $zoom = $this->getAttribute( 'zoom' );
28 $key = $this->getAttribute( 'apiKey' );
29 if ( ! $address ) {
30 $address = 'New York';
31 }
32
33 $base_url = 'https://www.google.com/maps/embed/v1/place';
34 $no_api_base_url = 'https://maps.google.com/maps';
35
36 if ( $key ) {
37 $zoomArg = 'zoom';
38 $src = add_query_arg(
39 array(
40 'key' => $key,
41 'q' => $address,
42 ),
43 $base_url
44 );
45 } else {
46 $zoomArg = 'z';
47 $src = add_query_arg(
48 array(
49 'q' => $address,
50 'output' => 'embed',
51 'iwloc' => 'near',
52 ),
53 $no_api_base_url
54 );
55 }
56
57 if ( ! empty( $zoom['value'] ) ) {
58 $src = add_query_arg( array( $zoomArg => $zoom['value'] ), $src );
59 }
60
61 return array(
62 self::OUTER => array(),
63 self::WRAPPER => array(
64 'className' => 'frontend-wrapper',
65 ),
66 self::IFRAME => array(
67 'src' => esc_url( $src ),
68 ),
69 );
70 }
71 }
72
73 Registry::registerBlock( __DIR__, MapBlock::class );
74