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

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

162 lines 5.0 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\EcmUpvote;
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\TextShadow;
20 use ABlocks\Controls\TextStroke;
21
22 class Block extends BlockBaseAbstract {
23 protected $block_name = 'ecm-upvote';
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--upvote',
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--upvote .content-manager-btn',
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--upvote .content-manager-btn: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
47 $css_generator->add_class_styles(
48 '{{WRAPPER}} .ecm-shortcode--upvote .content-manager-btn svg',
49 $this->get_coutineu_button_button_badge_css( $attributes ),
50 $this->get_coutineu_button_button_badge_css( $attributes, 'Tablet' ),
51 $this->get_coutineu_button_button_badge_css( $attributes, 'Mobile' )
52 );
53 $css_generator->add_class_styles(
54 '{{WRAPPER}} .ecm-shortcode--upvote .content-manager-btn svg path',
55 $this->get_badge_fill_color_css( $attributes ),
56 $this->get_badge_fill_color_css( $attributes ),
57 $this->get_badge_fill_color_css( $attributes )
58 );
59
60 return $css_generator->generate_css();
61 }
62
63 public function render_block_content( $attributes, $content, $block_instance ) {
64 $attr_array = [
65 'text' => Helper::get_attribute_value( $attributes, 'text' ),
66 ];
67
68 $shortcode = '[ecm_upvote ' . Helper::attr_shortcode( $attr_array ) . ']';
69 echo do_shortcode( $shortcode );
70 }
71
72 public function get_coutineu_button_wrapper_css( $attributes, $device = '' ) {
73 $css = [];
74 $alignment_css = [];
75 $alignment_css['display'] = 'flex';
76 $alignment_css['flex-direction'] = 'column';
77
78 if ( ! empty( $attributes['buttonAlignment'][ 'value' . $device ] ) ) {
79 $alignment_css['align-items'] = $attributes['buttonAlignment'][ 'value' . $device ];
80 }
81
82 return array_merge(
83 $alignment_css,
84 $css,
85 );
86
87 }
88
89 public function get_coutineu_button_css( $attributes, $device = '' ) {
90 $css = [];
91
92 if ( $attributes['buttonColor'] !== '' ) {
93 $css['color'] = $attributes['buttonColor'];
94 }
95 if ( $attributes['buttonBackground'] !== '' ) {
96 $css['background'] = $attributes['buttonBackground'];
97 }
98
99 if ( ! empty( $attributes['padding'] ) ) {
100 $cssPadding = Dimensions::get_css( $attributes['padding'], 'padding', $device );
101 }
102
103 return array_merge(
104 [ 'color' => Color::get_css( isset( $attributes['buttonColor'] ) ? $attributes['buttonColor'] : '' ) ],
105 [ 'background' => Color::get_css( isset( $attributes['buttonBackground'] ) ? $attributes['buttonBackground'] : '' ) ],
106 $css,
107 Border::get_css( $attributes['buttonBorder'], '', $device ),
108 $cssPadding,
109 BoxShadow::get_css( $attributes['boxShadow'], '', $device ),
110 );
111 }
112
113 public function get_coutineu_button_hover_css( $attributes, $device = '' ) {
114 $css = [];
115
116 if ( ! empty( $attributes['buttonColorH'] ) ) {
117 $css['color'] = Color::get_css( $attributes['buttonColorH'] );
118 }
119 if ( ! empty( $attributes['buttonBackgroundH'] ) ) {
120 $css['background'] = Color::get_css( $attributes['buttonBackgroundH'] );
121 }
122
123 return array_merge(
124 $css,
125 Border::get_hover_css( $attributes['buttonBorder'], '', $device ),
126 BoxShadow::get_hover_css( $attributes['boxShadow'], $device ),
127 );
128 }
129
130 public function get_coutineu_button_button_badge_css( $attributes, $device = '' ) {
131 return array_merge(
132 Range::get_css([
133 'attributeValue' => $attributes['badgeSize'],
134 'attribute_object_key' => 'value',
135 'isResponsive' => true,
136 'hasUnit' => true,
137 'defaultValue' => 30,
138 'unitDefaultValue' => 'px',
139 'property' => 'width',
140 'device' => $device,
141 ]),
142 Range::get_css([
143 'attributeValue' => $attributes['badgeSize'],
144 'attribute_object_key' => 'value',
145 'isResponsive' => true,
146 'hasUnit' => true,
147 'defaultValue' => 30,
148 'unitDefaultValue' => 'px',
149 'property' => 'height',
150 'device' => $device,
151 ])
152 );
153
154 }
155
156 public function get_badge_fill_color_css( $attributes ) {
157 $fill_color = Color::get_css( isset( $attributes['badgeFillColor'] ) ? $attributes['badgeFillColor'] : '' );
158 return $fill_color ? [ 'fill' => $fill_color ] : [];
159 }
160
161 }
162