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

177 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\EcmBookmarkList;
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-bookmark-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--bookmark__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--bookmark__list-item:hover',
37 $this->getListItemHoverCSS( $attributes ),
38 $this->getListItemHoverCSS( $attributes, 'Tablet' ),
39 $this->getListItemHoverCSS( $attributes, 'Mobile' ),
40
41 );
42 $css_generator->add_class_styles(
43 '{{WRAPPER}} .ecm-shortcode--bookmark__list',
44 $this->getListALignmentCSS( $attributes ),
45 $this->getListALignmentCSS( $attributes, 'Tablet' ),
46 $this->getListALignmentCSS( $attributes, 'Mobile' ),
47
48 );
49 $css_generator->add_class_styles(
50 '{{WRAPPER}} .ecm-shortcode--bookmark__list-title',
51 $this->getListTitleCSS( $attributes ),
52 $this->getListTitleCSS( $attributes, 'Tablet' ),
53 $this->getListTitleCSS( $attributes, 'Mobile' ),
54
55 );
56 $css_generator->add_class_styles(
57 '{{WRAPPER}} .ecm-shortcode--bookmark__list-date',
58 $this->getListDescriptionCSS( $attributes ),
59 $this->getListDescriptionCSS( $attributes, 'Tablet' ),
60 $this->getListDescriptionCSS( $attributes, 'Mobile' ),
61
62 );
63
64 $css_generator->add_class_styles(
65 '{{WRAPPER}}',
66 $this->getListNotFoundCSS($attributes),
67 $this->getListNotFoundCSS($attributes, 'Tablet'),
68 $this->getListNotFoundCSS($attributes, 'Mobile'),
69 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->getListNotFoundCSS($attributes, $device); } )
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_bookmark_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 getListItemHoverCSS( $attributes, $device = '' ) {
113 $css = [];
114 return array_merge(
115 $css,
116 BoxShadow::get_hover_css( $attributes['listBoxShadow'], '', $device ),
117 Border::get_hover_css( $attributes['listBorder'], '', $device )
118 );
119 }
120 public function getListALignmentCSS( $attributes, $device = '' ) {
121 $css = [];
122 $alignment_css = [];
123 $alignment_css['display'] = 'flex';
124
125 if ( ! empty( $attributes['listAlignment'][ 'value' . $device ] ) ) {
126 $alignment_css['align-items'] = $attributes['listAlignment'][ 'value' . $device ];
127 }
128 return array_merge(
129 $alignment_css,
130 );
131 }
132 public function getListTitleCSS( $attributes, $device = '' ) {
133 $css = [];
134 if ( $attributes['titleColor'] !== '' ) {
135 $css['color'] = $attributes['titleColor'];
136 }
137 $typographyValueGlobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : '';
138 $typography_css = ! empty( $attributes['titleTypography'] ) ? Typography::get_css( $attributes['titleTypography'], '', $device, $typographyValueGlobal ) : array();
139 $textShadowCss = ! empty( $attributes['titleTextShadow'] ) ? TextShadow::get_css( $attributes['titleTextShadow'], '', $device ) : array();
140 $textStrokeCss = ! empty( $attributes['titleTextStroke'] ) ? TextStroke::get_css( $attributes['titleTextStroke'], '', $device ) : array();
141
142 return array_merge(
143 $css,
144 $typography_css,
145 $textShadowCss,
146 $textStrokeCss
147 );
148 }
149 public function getListDescriptionCSS( $attributes, $device = '' ) {
150 $css = [];
151 if ( $attributes['desColor'] !== '' ) {
152 $css['color'] = $attributes['desColor'];
153 }
154 $typographyValueGlobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : '';
155 $typography_css = ! empty( $attributes['desTypography'] ) ? Typography::get_css( $attributes['desTypography'], '', $device, $typographyValueGlobal ) : array();
156 $textShadowCss = ! empty( $attributes['desTextShadow'] ) ? TextShadow::get_css( $attributes['desTextShadow'], '', $device ) : array();
157 $textStrokeCss = ! empty( $attributes['desTextStroke'] ) ? TextStroke::get_css( $attributes['desTextStroke'], '', $device ) : array();
158
159 return array_merge(
160 $css,
161 $typography_css,
162 $textShadowCss,
163 $textStrokeCss
164 );
165 }
166 public function getListNotFoundCSS( $attributes, $device = '' ) {
167 $css = [];
168 if ( ! empty( $attributes['notFoundAlignment'][ 'value' . $device ] ) ) {
169 $css['text-align'] = $attributes['notFoundAlignment'][ 'value' . $device ];
170 }
171 $color_css = ! empty( $attributes['notFoundColor'] ) ? [ 'color' => Color::get_css( $attributes['notFoundColor'] ) ] : [];
172 $typographyValueGlobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : '';
173 $typography_css = ! empty( $attributes['notFoundTypography'] ) ? Typography::get_css( $attributes['notFoundTypography'], '', $device, $typographyValueGlobal ) : [];
174 return array_merge( $css, $color_css, $typography_css );
175 }
176 }
177