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/heading/block.php +218 -0 2.7.5 → 2.14.0 View file →
@@ -1,0 +1,218 @@
1 +<?php
2 +namespace ABlocks\Blocks\Heading;
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\Alignment;
12 +use ABlocks\Controls\Typography;
13 +use ABlocks\Controls\TextShadow;
14 +use ABlocks\Controls\TextStroke;
15 +use ABlocks\Controls\Color;
16 +
17 +class Block extends BlockBaseAbstract {
18 + protected $block_name = 'heading';
19 +
20 + public function build_css_v1( $attributes ) {
21 + $css_generator = new CssGenerator( $attributes, $this->block_name );
22 + $css_generator->add_class_styles(
23 + '{{WRAPPER}}',
24 + $this->get_wrapper_css( $attributes ),
25 + $this->get_wrapper_css( $attributes, 'Tablet' ),
26 + $this->get_wrapper_css( $attributes, 'Mobile' ),
27 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } )
28 + );
29 +
30 + $css_generator->add_class_styles(
31 + '{{WRAPPER}} .ablocks-heading-text',
32 + $this->get_heading_text_css( $attributes ),
33 + $this->get_heading_text_css( $attributes, 'Tablet' ),
34 + $this->get_heading_text_css( $attributes, 'Mobile' ),
35 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_heading_text_css( $attributes, $device ); } )
36 + );
37 +
38 + $desktop_heading_a_styles = $this->get_heading_a_css( $attributes );
39 + $css_generator->add_class_styles(
40 + '{{WRAPPER}}.ablocks-block--heading a',
41 + $desktop_heading_a_styles,
42 + );
43 +
44 + $css_generator->add_class_styles(
45 + '{{WRAPPER}} .ablocks-animated-text path',
46 + $this->get_svg_path_css( $attributes ),
47 + $this->get_svg_path_css( $attributes, 'Tablet' ),
48 + $this->get_svg_path_css( $attributes, 'Mobile' ),
49 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_svg_path_css( $attributes, $device ); } )
50 + );
51 +
52 + $css_generator->add_class_styles(
53 + '{{WRAPPER}} .ablocks-animated-text',
54 + $this->get_heading_general_css( $attributes ),
55 + $this->get_heading_general_css( $attributes, 'Tablet' ),
56 + $this->get_heading_general_css( $attributes, 'Mobile' ),
57 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_heading_general_css( $attributes, $device ); } )
58 + );
59 +
60 + $css_generator->add_class_styles(
61 + '{{WRAPPER}} .ablocks-animated-text-wrapper',
62 + $this->get_heading_animated_css( $attributes ),
63 + $this->get_heading_animated_css( $attributes, 'Tablet' ),
64 + $this->get_heading_animated_css( $attributes, 'Mobile' ),
65 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_heading_animated_css( $attributes, $device ); } )
66 + );
67 +
68 + return $css_generator->generate_css();
69 + }
70 + public function build_css_v2( $attributes ) {
71 + $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
72 + $css_generator->add_class_styles(
73 + '{{WRAPPER}}',
74 + $this->get_wrapper_css( $attributes ),
75 + $this->get_wrapper_css( $attributes, 'Tablet' ),
76 + $this->get_wrapper_css( $attributes, 'Mobile' ),
77 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } )
78 + );
79 +
80 + $css_generator->add_class_styles(
81 + '{{WRAPPER}} .ablocks-heading-text',
82 + $this->get_heading_text_css( $attributes ),
83 + $this->get_heading_text_css( $attributes, 'Tablet' ),
84 + $this->get_heading_text_css( $attributes, 'Mobile' ),
85 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_heading_text_css( $attributes, $device ); } )
86 + );
87 + $desktop_heading_a_styles = $this->get_heading_a_css( $attributes );
88 + $css_generator->add_class_styles(
89 + '{{WRAPPER}}.ablocks-block--heading a',
90 + $desktop_heading_a_styles,
91 + );
92 + if ( ! empty( $attributes['isAnimated'] ) ) {
93 + $css_generator->add_class_styles(
94 + '{{WRAPPER}} .ablocks-animated-text path',
95 + $this->get_svg_path_css( $attributes ),
96 + $this->get_svg_path_css( $attributes, 'Tablet' ),
97 + $this->get_svg_path_css( $attributes, 'Mobile' ),
98 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_svg_path_css( $attributes, $device ); } )
99 + );
100 +
101 + $css_generator->add_class_styles(
102 + '{{WRAPPER}} .ablocks-animated-text',
103 + $this->get_heading_general_css( $attributes ),
104 + $this->get_heading_general_css( $attributes, 'Tablet' ),
105 + $this->get_heading_general_css( $attributes, 'Mobile' ),
106 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_heading_general_css( $attributes, $device ); } )
107 + );
108 +
109 + $css_generator->add_class_styles(
110 + '{{WRAPPER}} .ablocks-animated-text-wrapper',
111 + $this->get_heading_animated_css( $attributes ),
112 + $this->get_heading_animated_css( $attributes, 'Tablet' ),
113 + $this->get_heading_animated_css( $attributes, 'Mobile' ),
114 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_heading_animated_css( $attributes, $device ); } )
115 + );
116 + }//end if
117 +
118 + return $css_generator->generate_css();
119 + }
120 +
121 + public function build_css( $attributes ) {
122 + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
123 + return $this->build_css_v2( $attributes );
124 + }
125 + return $this->build_css_v1( $attributes );
126 + }
127 +
128 + public function get_wrapper_css( $attributes, $device = '' ) {
129 + return isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], 'text-align', $device ) : [];
130 + }
131 + public function get_heading_text_css( $attributes, $device = '' ) {
132 + $typographyValueGlobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : '';
133 + $typography_css = ! empty( $attributes['typography'] ) ? Typography::get_css( $attributes['typography'], '', $device, $typographyValueGlobal ) : array();
134 + $textShadowCss = ! empty( $attributes['textShadow'] ) ? TextShadow::get_css( $attributes['textShadow'], '', $device ) : array();
135 + $textStrokeCss = ! empty( $attributes['textStroke'] ) ? TextStroke::get_css( $attributes['textStroke'], '', $device ) : array();
136 +
137 + return array_merge( [
138 + 'color' => Color::get_css( isset( $attributes['textColor'] ) ? $attributes['textColor'] : '' ),
139 + ], $typography_css, $textShadowCss, $textStrokeCss );
140 + }
141 +
142 + public function get_heading_a_css( $attributes ) {
143 + $decoration = isset( $attributes ['typography']['decoration'] ) ? $attributes['typography'] ['decoration'] : '';
144 + if ( ! empty( $decoration ) ) {
145 + return array( 'text-decoration' => $decoration ); }
146 + return array();
147 + }
148 +
149 + public function render_block_content( $attributes, $content, $block_instance ) {
150 + if ( ! isset( $block_instance->context['postId'] ) ) {
151 + return '';
152 + }
153 + $title = get_the_title();
154 + if ( ! $title ) {
155 + return '';
156 + }
157 + $tag_name = 'h2';
158 + if ( ! empty( $attributes['headingTag'] ) ) {
159 + $tag_name = $attributes['headingTag'];
160 + }
161 + return sprintf(
162 + '<%1$s>%2$s</%1$s>',
163 + $tag_name,
164 + $title
165 + );
166 + }
167 +
168 +
169 + public function get_svg_path_css( $attributes, $device = '' ) {
170 + $count = ! empty( $attributes['isInfiniteLoop'] ) ? 'infinite' : 1;
171 +
172 + $highlightStrokeWidth = isset( $attributes['highlightStrokeWidth'] ) && is_array( $attributes['highlightStrokeWidth'] ) ? $attributes['highlightStrokeWidth'] : [];
173 + $unit = $highlightStrokeWidth[ 'valueUnit' . $device ] ?? $highlightStrokeWidth['valueUnit'] ?? 'px';
174 + $value = $highlightStrokeWidth[ 'value' . $device ] ?? $highlightStrokeWidth['value'] ?? 10;
175 + $stroke_width = $value . $unit;
176 + $highlightDuration = isset( $attributes['highlightDuration'] ) ? $attributes['highlightDuration'] : 0;
177 + $highlightDelay = isset( $attributes['highlightDelay'] ) ? $attributes['highlightDelay'] : 0;
178 +
179 + return array_merge(
180 + [
181 + 'stroke' => Color::get_css(
182 + isset( $attributes['highlightColor'] )
183 + ? $attributes['highlightColor']
184 + : '#000'
185 + )
186 + ],
187 + [
188 + 'stroke-width' => $stroke_width,
189 + 'animation' => 'draw-auto ' . ( $highlightDuration + $highlightDelay ) . 'ms forwards ' . $count
190 + ]
191 + );
192 + }
193 +
194 +
195 +
196 + public function get_heading_general_css( $attributes, $device = '' ) {
197 + $typographyValueGlobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : '';
198 + $typography_value = isset( $attributes['typography'] ) ? $attributes['typography'] : [];
199 + $stock_unit_value = isset( $attributes['textStroke'] ) ? $attributes['textStroke'] : [];
200 + return array_merge(
201 + [ 'color' => Color::get_css( isset( $attributes['textColor'] ) ? $attributes['textColor'] : '' ) ],
202 + Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ),
203 + TextStroke::get_css( $stock_unit_value, '', $device ),
204 + TextShadow::get_css( isset( $attributes['textShadow'] ) ? $attributes['textShadow'] : [], '', $device )
205 + );
206 + }
207 +
208 + public function get_heading_animated_css( $attributes, $device = '' ) {
209 + $typography_value = isset( $attributes['animatedTypography'] ) ? $attributes['animatedTypography'] : [];
210 + $stroke_unit_value = isset( $attributes['animatedTextStroke'] ) ? $attributes['animatedTextStroke'] : [];
211 + return array_merge(
212 + [ 'color' => Color::get_css( isset( $attributes['animatedTextColor'] ) ? $attributes['animatedTextColor'] : '' ) ],
213 + Typography::get_css( $typography_value, '', $device ),
214 + TextStroke::get_css( $stroke_unit_value, '', $device ),
215 + TextShadow::get_css( isset( $attributes['animatedTextShadow'] ) ? $attributes['animatedTextShadow'] : [], '', $device )
216 + );
217 + }
218 +}