PluginProbe
WowOptin: Next-Gen Popup Maker – Create Stunning Popups and Optins for Lead Generation / trunk
WowOptin: Next-Gen Popup Maker – Create Stunning Popups and Optins for Lead Generation vtrunk
1.4.48 1.4.47 1.4.46 1.4.45 1.4.44 1.4.43 1.4.42 1.4.41 1.4.40 1.4.39 1.4.38 1.4.37 1.4.36 1.1.2 1.2.0 1.2.1 1.2.2 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 All 64 releases
optin / includes / abstracts / class-base-block.php

class-base-block.php in WowOptin: Next-Gen Popup Maker – Create Stunning Popups and Optins for Lead Generation trunk, at includes/abstracts/class-base-block.php

124 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore
2
3 namespace OPTN\Includes\Abstracts;
4
5 use OPTN\Includes\Utils\BlockUtils;
6 use OPTN\Includes\Utils\Utils;
7
8 defined( 'ABSPATH' ) || exit;
9
10 /**
11 * Abstract Base Block Class
12 */
13 abstract class BaseBlock implements Block {
14 /**
15 * Block data
16 *
17 * @var object
18 */
19 protected $data;
20
21 /**
22 * Block data
23 *
24 * @var object
25 */
26 protected $post_data;
27
28 /**
29 * Block constructor.
30 *
31 * @param object $data block data.
32 * @param object|null $post_data post data.
33 */
34 public function __construct( $data, $post_data = null ) {
35 $this->data = $data;
36 $this->post_data = $post_data;
37 }
38
39 /**
40 * Generate block html
41 *
42 * @return string
43 */
44 public function generate() {
45 $version = $this->get_version();
46
47 $func = 'v' . $version;
48
49 if ( method_exists( $this, $func ) ) {
50 return $this->$func();
51 }
52
53 Utils::log_error( "No block version found for {$this->get_block_name()} Version: {$version}" );
54
55 return '';
56 }
57
58 /**
59 * Default block html
60 *
61 * @return string
62 */
63 abstract protected function v1();
64
65 /**
66 * Get block version
67 *
68 * @return string|null
69 */
70 protected function get_version() {
71 return isset( $this->data->attributes->version ) ? $this->data->attributes->version : '1';
72 }
73
74 /**
75 * Get block name
76 *
77 * @return string
78 */
79 abstract protected function get_block_name();
80
81 /**
82 * Block html attrs
83 *
84 * @return array
85 */
86 protected function get_common_html_attr_array() {
87
88 // Custom classes.
89 $cls = '';
90 if ( isset( $this->data->attributes->customClasses ) && is_string( $this->data->attributes->customClasses ) ) {
91 $cls = explode( ',', $this->data->attributes->customClasses );
92 $cls = array_map( 'sanitize_html_class', $cls );
93 $cls = implode( ' ', $cls );
94 }
95
96 $data = array(
97 'class' => array(
98 'optn-block',
99 'optn-block-' . $this->get_block_name(),
100 'optn-' . esc_attr( $this->data->clientId ),
101 $cls,
102 BlockUtils::get_resp_hide_classes( $this->data->attributes ),
103 ),
104 'id' => esc_attr( $this->data->clientId ),
105 'data-optn-block-version' => esc_attr( $this->get_version() ),
106 );
107
108 if ( ! empty( $this->data->attributes->fixed ) ) {
109 $data['class'][] = 'optn-block-fixed';
110 }
111
112 if ( 'columns' !== $this->get_block_name() ) {
113 $pos = array(
114 'top' => $this->data->attributes->top,
115 'left' => $this->data->attributes->left,
116 'transform' => $this->data->attributes->transform,
117 );
118 $data['data-optn-pos'] = htmlspecialchars( wp_json_encode( $pos ) );
119 }
120
121 return $data;
122 }
123 }
124