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

169 lines 5.9 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\EcmBookmarkButton;
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
20
21 class Block extends BlockBaseAbstract {
22 protected $block_name = 'ecm-bookmark-button';
23
24 public function build_css( $attributes ) {
25 $css_generator = new CssGenerator( $attributes, $this->block_name );
26
27 $css_generator->add_class_styles(
28 '{{WRAPPER}} .ecm-shortcode--bookmark',
29 $this->get_coutineu_button_wrapper_css( $attributes ),
30 $this->get_coutineu_button_wrapper_css( $attributes, 'Tablet' ),
31 $this->get_coutineu_button_wrapper_css( $attributes, 'Mobile' )
32 );
33 $css_generator->add_class_styles(
34 '{{WRAPPER}} .ecm-shortcode--bookmark button',
35 $this->get_coutineu_button_css( $attributes ),
36 $this->get_coutineu_button_css( $attributes, 'Tablet' ),
37 $this->get_coutineu_button_css( $attributes, 'Mobile' )
38 );
39 $css_generator->add_class_styles(
40 '{{WRAPPER}} .ecm-shortcode--bookmark button:hover',
41 $this->get_coutineu_button_hover_css( $attributes ),
42 $this->get_coutineu_button_hover_css( $attributes, 'Tablet' ),
43 $this->get_coutineu_button_hover_css( $attributes, 'Mobile' )
44 );
45 $css_generator->add_class_styles(
46 '{{WRAPPER}} .ecm-shortcode--bookmark button svg',
47 $this->get_coutineu_button_button_badge_css( $attributes ),
48 $this->get_coutineu_button_button_badge_css( $attributes, 'Tablet' ),
49 $this->get_coutineu_button_button_badge_css( $attributes, 'Mobile' )
50 );
51 $css_generator->add_class_styles(
52 '{{WRAPPER}} .ecm-shortcode--bookmark button svg path',
53 $this->get_badge_fill_color_css( $attributes ),
54 $this->get_badge_fill_color_css( $attributes ),
55 $this->get_badge_fill_color_css( $attributes )
56 );
57
58 return $css_generator->generate_css();
59 }
60
61 public function get_coutineu_button_wrapper_css( $attributes, $device = '' ) {
62 $css = [];
63 $alignment_css = [];
64 $css['display'] = 'flex';
65
66 if ( ! empty( $attributes['buttonAlignment'][ 'value' . $device ] ) ) {
67 $alignment_css['align-items'] = $attributes['buttonAlignment'][ 'value' . $device ];
68 }
69
70 return array_merge(
71 $alignment_css,
72 $css,
73 );
74
75 }
76
77 public function get_coutineu_button_css( $attributes, $device = '' ) {
78 $css = [];
79
80 if ( $attributes['buttonColor'] !== '' ) {
81 $css['color'] = $attributes['buttonColor'];
82 }
83 if ( $attributes['buttonBackground'] !== '' ) {
84 $css['background'] = $attributes['buttonBackground'];
85 }
86 $typography = isset( $attributes['buttonTypography'] ) && is_array( $attributes['buttonTypography'] )
87 ? $attributes['buttonTypography']
88 : [];
89 $typographyValueGlobal = ( isset( $attributes['buttonTypographyGlobal'] ) ? $attributes['buttonTypographyGlobal'] : '' );
90
91 $typography_value = array_merge( $typography, [ 'font-weight' => '400' ] );
92
93 if ( ! empty( $attributes['padding'] ) ) {
94 $cssPadding = Dimensions::get_css( $attributes['padding'], 'padding', $device );
95 }
96
97 return array_merge(
98 [ 'color' => Color::get_css( isset( $attributes['buttonColor'] ) ? $attributes['buttonColor'] : '' ) ],
99 [ 'background' => Color::get_css( isset( $attributes['buttonBackground'] ) ? $attributes['buttonBackground'] : '' ) ],
100 $css,
101 Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ),
102 Border::get_css( $attributes['buttonBorder'], '', $device ),
103 $cssPadding,
104 BoxShadow::get_css( $attributes['boxShadow'], '', $device ),
105 );
106 }
107
108 public function get_coutineu_button_hover_css( $attributes, $device = '' ) {
109 return array_merge(
110 [ 'color' => Color::get_css( isset( $attributes ['buttonColorH'] ) ? $attributes['buttonColorH'] : '' ) ],
111 [ 'background' => Color::get_css( isset( $attributes['buttonBackgroundH'] ) ? $attributes['buttonBackgroundH'] : '' ) ],
112 Border::get_hover_css( $attributes['buttonBorder'] ?? [], '', $device ),
113 BoxShadow::get_hover_css( $attributes['boxShadow'], '', $device ),
114 );
115
116 }
117 public function get_coutineu_button_button_badge_css( $attributes, $device = '' ) {
118 return array_merge(
119 Range::get_css([
120 'attributeValue' => $attributes['badgeSize'],
121 'attribute_object_key' => 'value',
122 'isResponsive' => true,
123 'hasUnit' => true,
124 'defaultValue' => 30,
125 'unitDefaultValue' => 'px',
126 'property' => 'width',
127 'device' => $device,
128 ]),
129 Range::get_css([
130 'attributeValue' => $attributes['badgeSize'],
131 'attribute_object_key' => 'value',
132 'isResponsive' => true,
133 'hasUnit' => true,
134 'defaultValue' => 30,
135 'unitDefaultValue' => 'px',
136 'property' => 'height',
137 'device' => $device,
138 ])
139 );
140
141 }
142
143 public function get_badge_fill_color_css( $attributes ) {
144 $fill_color = Color::get_css( isset( $attributes['badgeFillColor'] ) ? $attributes['badgeFillColor'] : '' );
145 return $fill_color ? [ 'fill' => $fill_color ] : [];
146 }
147
148 public function render_block_content( $attributes, $content, $block_instance ) {
149 $attr_array = [
150 'bookmark_text' => Helper::get_attribute_value( $attributes, 'bookmark_text' ),
151 'bookmarked_text' => Helper::get_attribute_value( $attributes, 'bookmarked_text' ),
152 'id' => Helper::get_attribute_value( $attributes, 'id' ),
153 ];
154
155 // if ( isset( $block_instance->context['postId'] ) && ! empty( $block_instance->context['postId'] ) && empty( $attr_array['product_id'] ) ) {
156 // $attr_array['product_id'] = $block_instance->context['postId'];
157 // }
158
159 // // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
160 // if ( isset( $_GET['context'] ) && 'edit' === sanitize_text_field( $_GET['context'] ) ) {
161 // $attr_array['dummy'] = true;
162 // }
163
164 $shortcode = '[ecm_bookmark_button ' . Helper::attr_shortcode( $attr_array ) . ']';
165 echo do_shortcode( $shortcode );
166 }
167
168 }
169