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

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

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