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 / coupon / block.php

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

147 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\Coupon;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\BlockBaseAbstract;
9 use ABlocks\Classes\CssGenerator;
10 use ABlocks\Controls\Range;
11 use ABlocks\Controls\Dimensions;
12 use ABlocks\Controls\Icon;
13 use ABlocks\Controls\Alignment;
14 use ABlocks\Controls\Typography;
15 use ABlocks\Controls\Border;
16 use ABlocks\Controls\TextShadow;
17
18
19
20 class Block extends BlockBaseAbstract {
21 protected $block_name = 'coupon';
22
23 public function build_css( $attributes ) {
24 $css_generator = new CssGenerator( $attributes );
25
26 $css_generator->add_class_styles(
27 '{{WRAPPER}}',
28 $this->get_wrapper_css( $attributes ),
29 $this->get_wrapper_css( $attributes, 'Tablet' ),
30 $this->get_wrapper_css( $attributes, 'Mobile' )
31 );
32
33 $css_generator->add_class_styles(
34 '{{WRAPPER}} .ablocks-icon-wrap',
35 Icon::get_wrapper_css( $attributes ),
36 Icon::get_wrapper_css( $attributes, 'Tablet' ),
37 Icon::get_wrapper_css( $attributes, 'Mobile' )
38 );
39
40 $css_generator->add_class_styles(
41 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
42 Icon::get_element_image_css( $attributes ),
43 Icon::get_element_image_css( $attributes, 'Tablet' ),
44 Icon::get_element_image_css( $attributes, 'Mobile' )
45 );
46 $css_generator->add_class_styles(
47 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover',
48 Icon::get_element_image_hover_css( $attributes ),
49 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
50 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
51 );
52 $css_generator->add_class_styles(
53 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
54 Icon::get_element_css( $attributes ),
55 Icon::get_element_css( $attributes, 'Tablet' ),
56 Icon::get_element_css( $attributes, 'Mobile' ),
57 );
58 $css_generator->add_class_styles(
59 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover',
60 Icon::get_element_image_hover_css( $attributes ),
61 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
62 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
63 );
64
65 $css_generator->add_class_styles(
66 '{{WRAPPER}} .ablocks-coupon-code',
67 $this->get_coupon_text_css( $attributes ),
68 $this->get_coupon_text_css( $attributes, 'Tablet' ),
69 $this->get_coupon_text_css( $attributes, 'Mobile' )
70 );
71
72 $css_generator->add_class_styles(
73 '{{WRAPPER}} .ablocks-coupon-clipboard',
74 $this->get_btn_text_css( $attributes ),
75 $this->get_btn_text_css( $attributes, 'Tablet' ),
76 $this->get_btn_text_css( $attributes, 'Mobile' )
77 );
78
79 return $css_generator->generate_css();
80 }
81
82
83 public function get_wrapper_css( $attributes, $device = '' ) {
84 $css = [];
85
86 if ( isset( $attributes['position'][ 'value' . $device ] ) ) {
87 $css['justify-content'] = $attributes['position'][ 'value' . $device ];
88 }
89
90 return $css;
91 }
92
93 public function get_button_hover_css( $attributes, $device = '' ) {
94 $css = [];
95
96 if ( isset( $attributes['textColorH'] ) ) {
97 $css['color'] = $attributes['textColorH'];
98 }
99 if ( isset( $attributes['backgroundH'] ) ) {
100 $css['background'] = $attributes['backgroundH'];
101 }
102
103 return array_merge(
104 isset( $attributes['padding'] ) ? Dimensions::get_css( $attributes['padding'], 'padding', $device ) : [],
105 $css
106 );
107 }
108
109
110 public function get_coupon_text_css( $attributes, $device = '' ) {
111 $css = [
112 'color' => $attributes['couponCodeColor'],
113 'background' => $attributes['couponCodeBgColor'],
114 ];
115
116 return array_merge(
117 $css,
118 isset( $attributes['couponBorder'] ) ? Border::get_css( $attributes['couponBorder'], '', $device ) : [],
119 isset( $attributes['couponPadding'] ) ? Dimensions::get_css( $attributes['couponPadding'], 'padding', $device ) : [],
120 Typography::get_css( $attributes['couponTypography'], '', $device ),
121 TextShadow::get_css( $attributes['couponTextShadow'], '', $device )
122 );
123 }
124
125 public function get_btn_text_css( $attributes, $device = '' ) {
126 $css = [
127 'color' => $attributes['couponBtnTextColor'],
128 'background' => $attributes['couponBtnBgColor'],
129 ];
130
131 return array_merge(
132 $css,
133 Border::get_css( $attributes['buttonBorder'], '', $device ),
134 Dimensions::get_css( $attributes['buttonPadding'], 'padding', $device ),
135 Typography::get_css( $attributes['buttonTypography'], '', $device ),
136 TextShadow::get_css( $attributes['buttonTextShadow'], '', $device )
137 );
138 }
139
140 public function get_icon_css( $attributes, $device = '' ) {
141
142 return ! empty( $attributes['iconRotate'] ) ? [ 'transform' => 'rotate(' . $attributes['iconRotate'] . 'deg)' ] : [];
143
144 }
145
146 }
147