PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.11.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.11.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 / ecm-claim-button / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.11.1, at includes/blocks/ecm-claim-button/block.php

181 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ABlocks\Blocks\EcmClaimButton;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use ABlocks\Classes\BlockBaseAbstract;
10 use ABlocks\Classes\CssGenerator;
11 use ABlocks\Helper;
12 use ABlocks\Controls\Typography;
13 use ABlocks\Controls\Background;
14 use ABlocks\Controls\Border;
15 use ABlocks\Controls\Dimensions;
16 use ABlocks\Controls\Range;
17 use ABlocks\Controls\BoxShadow;
18 use ABlocks\Controls\Color;
19 use ABlocks\Controls\Alignment;
20
21
22 class Block extends BlockBaseAbstract {
23 protected $block_name = 'ecm-claim-button';
24
25 public function build_css( $attributes ) {
26 $css_generator = new CssGenerator( $attributes, $this->block_name );
27
28 $css_generator->add_class_styles(
29 '{{WRAPPER}} .ecm-shortcode--claim',
30 $this->get_coutineu_button_wrapper_css( $attributes ),
31 $this->get_coutineu_button_wrapper_css( $attributes, 'Tablet' ),
32 $this->get_coutineu_button_wrapper_css( $attributes, 'Mobile' )
33 );
34 $css_generator->add_class_styles(
35 '{{WRAPPER}} .ecm-shortcode--claim button',
36 $this->get_coutineu_button_css( $attributes ),
37 $this->get_coutineu_button_css( $attributes, 'Tablet' ),
38 $this->get_coutineu_button_css( $attributes, 'Mobile' )
39 );
40 $css_generator->add_class_styles(
41 '{{WRAPPER}} .ecm-shortcode--claim button:hover',
42 $this->get_coutineu_button_hover_css( $attributes ),
43 $this->get_coutineu_button_hover_css( $attributes, 'Tablet' ),
44 $this->get_coutineu_button_hover_css( $attributes, 'Mobile' )
45 );
46 foreach ( [ '.ecm-shortcode--tooltip', '.ecm-shortcode--tooltip svg', '.ecm-shortcode--tooltip svg path' ] as $selector ) {
47 $css_generator->add_class_styles(
48 '{{WRAPPER}} ' . $selector,
49 $this->get_badge_css( $attributes, 'pendingBadgeFillColor', 'pendingBadgeSize' ),
50 $this->get_badge_css( $attributes, 'pendingBadgeFillColor', 'pendingBadgeSize', 'Tablet' ),
51 $this->get_badge_css( $attributes, 'pendingBadgeFillColor', 'pendingBadgeSize', 'Mobile' )
52 );
53 }
54 $css_generator->add_class_styles(
55 '{{WRAPPER}}.ablocks-block--ecm-claim-button',
56 $this->get_list_alignment_css( $attributes ),
57 $this->get_list_alignment_css( $attributes, 'Tablet' ),
58 $this->get_list_alignment_css( $attributes, 'Mobile' )
59 );
60 foreach ( [ '.ecm-shortcode--claim__message', '.ecm-shortcode--claim__message svg', '.ecm-shortcode--claim__message svg path' ] as $selector ) {
61 $css_generator->add_class_styles(
62 '{{WRAPPER}} ' . $selector,
63 $this->get_badge_css( $attributes, 'confirmationBandageFillColor', 'confirmationBandageSize', '', true ),
64 $this->get_badge_css( $attributes, 'confirmationBandageFillColor', 'confirmationBandageSize', 'Tablet', true ),
65 $this->get_badge_css( $attributes, 'confirmationBandageFillColor', 'confirmationBandageSize', 'Mobile', true )
66 );
67 }
68
69 return $css_generator->generate_css();
70 }
71
72 public function get_coutineu_button_wrapper_css( $attributes, $device = '' ) {
73 $css = [];
74 $alignment_css = [];
75 $css['display'] = 'flex';
76
77 if ( ! empty( $attributes['buttonAlignment'][ 'value' . $device ] ) ) {
78 $alignment_css['justify-content'] = $attributes['buttonAlignment'][ 'value' . $device ];
79 }
80
81 return array_merge(
82 $alignment_css,
83 $css,
84 );
85
86 }
87
88 public function get_coutineu_button_css( $attributes, $device = '' ) {
89 $css = [];
90
91 if ( $attributes['buttonColor'] !== '' ) {
92 $css['color'] = $attributes['buttonColor'];
93 }
94 if ( $attributes['buttonBackground'] !== '' ) {
95 $css['background'] = $attributes['buttonBackground'];
96 }
97 $typography = isset( $attributes['buttonTypography'] ) && is_array( $attributes['buttonTypography'] )
98 ? $attributes['buttonTypography']
99 : [];
100 $typographyValueGlobal = ( isset( $attributes['buttonTypographyGlobal'] ) ? $attributes['buttonTypographyGlobal'] : '' );
101
102 $typography_value = array_merge( $typography, [ 'font-weight' => '400' ] );
103
104 $cssPadding = ! empty( $attributes['padding'] ) ? Dimensions::get_css( $attributes['padding'], 'padding', $device ) : [];
105
106 return array_merge(
107 [ 'color' => Color::get_css( isset( $attributes['buttonColor'] ) ? $attributes['buttonColor'] : '' ) ],
108 [ 'background' => Color::get_css( isset( $attributes['buttonBackground'] ) ? $attributes['buttonBackground'] : '' ) ],
109 $css,
110 Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ),
111 Border::get_css( $attributes['buttonBorder'], '', $device ),
112 $cssPadding,
113 BoxShadow::get_css( $attributes['boxShadow'], '', $device ),
114 );
115 }
116
117 public function get_coutineu_button_hover_css( $attributes, $device = '' ) {
118 $hover_css = array_merge(
119 [ 'color' => Color::get_css( isset( $attributes['buttonColorH'] ) ? $attributes['buttonColorH'] : '' ) ],
120 [ 'background' => Color::get_css( isset( $attributes['buttonBackgroundH'] ) ? $attributes['buttonBackgroundH'] : '' ) ],
121 Border::get_hover_css( $attributes['buttonBorder'] ?? [], '', $device ),
122 BoxShadow::get_hover_css( $attributes['boxShadow'], '', $device ),
123 );
124
125 if ( ! empty( $hover_css['box-shadow'] ) ) {
126 $hover_css['box-shadow'] = $hover_css['box-shadow'] . ' !important';
127 } else {
128 $normal_shadow = BoxShadow::get_css( $attributes['boxShadow'], '', $device );
129 if ( ! empty( $normal_shadow['box-shadow'] ) ) {
130 $hover_css['box-shadow'] = $normal_shadow['box-shadow'] . ' !important';
131 }
132 }
133
134 return $hover_css;
135 }
136
137 public function get_badge_css( $attributes, $fill_key, $size_key, $device = '', $transparent_bg = false ) {
138 $base = [ 'fill' => Color::get_css( $attributes[ $fill_key ] ?? '' ) ];
139 if ( $transparent_bg ) {
140 $base['background'] = 'transparent';
141 }
142 $size_args = [
143 'attributeValue' => $attributes[ $size_key ],
144 'attribute_object_key' => 'value',
145 'isResponsive' => true,
146 'hasUnit' => true,
147 'defaultValue' => 20,
148 'unitDefaultValue' => 'px',
149 'device' => $device,
150 ];
151 return array_merge(
152 $base,
153 Range::get_css( array_merge( $size_args, [ 'property' => 'height' ] ) ),
154 Range::get_css( array_merge( $size_args, [ 'property' => 'width' ] ) )
155 );
156 }
157
158 public function get_list_alignment_css( $attributes, $device = '' ) {
159 $css = [ 'display' => 'flex', 'align-items' => 'center' ];
160 $alignment_css = [];
161
162 if ( ! empty( $attributes['listAlignment'][ 'value' . $device ] ) ) {
163 $alignment_css['justify-content'] = $attributes['listAlignment'][ 'value' . $device ];
164 }
165 return array_merge( $alignment_css, $css );
166 }
167
168
169 public function render_block_content( $attributes, $content, $block_instance ) {
170 $attr_array = [
171 'bookmark_text' => Helper::get_attribute_value( $attributes, 'bookmark_text' ),
172 'bookmarked_text' => Helper::get_attribute_value( $attributes, 'bookmarked_text' ),
173 'id' => Helper::get_attribute_value( $attributes, 'id' ),
174 ];
175
176 $shortcode = '[ecm_claim_button ' . Helper::attr_shortcode( $attr_array ) . ']';
177 echo do_shortcode( $shortcode );
178 }
179
180 }
181