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
ablocks / includes / blocks / ecm-bookmark-button / block.php

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

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