PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.12.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.12.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 1.1.2 All 80 releases
ablocks / includes / blocks / ecm-upvote-list / block.php

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

179 lines 5.8 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\EcmUpvoteList;
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-list';
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__list-item',
30 $this->getListCSS( $attributes ),
31 $this->getListCSS( $attributes, 'Tablet' ),
32 $this->getListCSS( $attributes, 'Mobile' ),
33
34 );
35 $css_generator->add_class_styles(
36 '{{WRAPPER}} .ecm-shortcode--upvote__list',
37 $this->getListALignmentCSS( $attributes ),
38 $this->getListALignmentCSS( $attributes, 'Tablet' ),
39 $this->getListALignmentCSS( $attributes, 'Mobile' ),
40
41 );
42 $css_generator->add_class_styles(
43 '{{WRAPPER}} .ecm-shortcode--upvote__list-title',
44 $this->getListTitleCSS( $attributes ),
45 $this->getListTitleCSS( $attributes, 'Tablet' ),
46 $this->getListTitleCSS( $attributes, 'Mobile' ),
47
48 );
49 $css_generator->add_class_styles(
50 '{{WRAPPER}} .ecm-shortcode--upvote__list-date',
51 $this->getListDescriptionCSS( $attributes ),
52 $this->getListDescriptionCSS( $attributes, 'Tablet' ),
53 $this->getListDescriptionCSS( $attributes, 'Mobile' ),
54
55 );
56
57 $css_generator->add_class_styles(
58 '{{WRAPPER}} ul.ecm-shortcode--upvote__list',
59 $this->getListStyleCSS( $attributes ),
60 $this->getListStyleCSS( $attributes, 'Tablet' ),
61 $this->getListStyleCSS( $attributes, 'Mobile' ),
62
63 );
64
65 $css_generator->add_class_styles(
66 '{{WRAPPER}} .ecm-shortcode--upvote__list-item:hover',
67 $this->getListHoverCSS( $attributes ),
68 $this->getListHoverCSS( $attributes, 'Tablet' ),
69 $this->getListHoverCSS( $attributes, 'Mobile' ),
70 );
71
72 return $css_generator->generate_css();
73 }
74
75 public function render_block_content( $attributes, $content, $block_instance ) {
76 $attr_array = [
77 'user_id' => Helper::get_attribute_value( $attributes, 'user_id' ),
78 'not_found_text' => Helper::get_attribute_value( $attributes, 'not_found_text' ),
79 ];
80
81 $shortcode = '[ecm_upvote_list ' . Helper::attr_shortcode( $attr_array ) . ']';
82 echo do_shortcode( $shortcode );
83 }
84
85 public function getListCSS( $attributes, $device = '' ) {
86 $css = [];
87 $cssPadding = [];
88 if ( $attributes['listBackground'] !== '' ) {
89 $css['background'] = $attributes['listBackground'];
90 }
91 if ( ! empty( $attributes['listPadding'] ) ) {
92 $cssPadding = Dimensions::get_css( $attributes['listPadding'], 'padding', $device );
93 }
94 return array_merge(
95 [ 'background' => Color::get_css( isset( $attributes['listBackground'] ) ? $attributes['listBackground'] : '' ) ],
96 $css,
97 Range::get_css([
98 'attributeValue' => $attributes['listWidth'],
99 'attribute_object_key' => 'value',
100 'isResponsive' => true,
101 'hasUnit' => true,
102 'defaultValue' => 33,
103 'unitDefaultValue' => '%',
104 'property' => 'width',
105 'device' => $device,
106 ]),
107 Border::get_css( $attributes['listBorder'], '', $device ),
108 $cssPadding,
109 BoxShadow::get_css( $attributes['listBoxShadow'], '', $device ),
110 );
111 }
112 public function getListALignmentCSS( $attributes, $device = '' ) {
113 $css = [];
114 $css['display'] = 'flex';
115 $css['flex-direction'] = 'column';
116 $alignment_css = [];
117
118 if ( ! empty( $attributes['listAlignment'][ 'value' . $device ] ) ) {
119 $alignment_css['align-items'] = $attributes['listAlignment'][ 'value' . $device ];
120 }
121 return array_merge(
122 $alignment_css,
123 $css
124 );
125 }
126 public function getListTitleCSS( $attributes, $device = '' ) {
127 $css = [];
128 if ( $attributes['titleColor'] !== '' ) {
129 $css['color'] = $attributes['titleColor'];
130 }
131 $typographyValueGlobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : '';
132 $typography_css = ! empty( $attributes['titleTypography'] ) ? Typography::get_css( $attributes['titleTypography'], '', $device, $typographyValueGlobal ) : array();
133 $textShadowCss = ! empty( $attributes['titleTextShadow'] ) ? TextShadow::get_css( $attributes['titleTextShadow'], '', $device ) : array();
134 $textStrokeCss = ! empty( $attributes['titleTextStroke'] ) ? TextStroke::get_css( $attributes['titleTextStroke'], '', $device ) : array();
135
136 return array_merge(
137 $css,
138 $typography_css,
139 $textShadowCss,
140 $textStrokeCss
141 );
142 }
143 public function getListDescriptionCSS( $attributes, $device = '' ) {
144 $css = [];
145 if ( $attributes['desColor'] !== '' ) {
146 $css['color'] = $attributes['desColor'];
147 }
148 $typographyValueGlobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : '';
149 $typography_css = ! empty( $attributes['desTypography'] ) ? Typography::get_css( $attributes['desTypography'], '', $device, $typographyValueGlobal ) : array();
150 $textShadowCss = ! empty( $attributes['desTextShadow'] ) ? TextShadow::get_css( $attributes['desTextShadow'], '', $device ) : array();
151 $textStrokeCss = ! empty( $attributes['desTextStroke'] ) ? TextStroke::get_css( $attributes['desTextStroke'], '', $device ) : array();
152
153 return array_merge(
154 $css,
155 $typography_css,
156 $textShadowCss,
157 $textStrokeCss
158 );
159 }
160
161 public function getListStyleCSS( $attributes, $device = '' ) {
162 $css = [];
163 if ( $attributes['listStyle'] !== '' ) {
164 $css['list-style'] = $attributes['listStyle'];
165 }
166 return array_merge(
167 $css,
168 );
169 }
170
171 public function getListHoverCSS( $attributes, $device = '' ) {
172 return array_merge(
173 Border::get_hover_css( $attributes['listBorder'], '', $device ),
174 BoxShadow::get_hover_css( $attributes['listBoxShadow'], '', $device )
175 );
176 }
177
178 }
179