PluginProbe
Getwid – Gutenberg Blocks / 2.0.7
Getwid – Gutenberg Blocks v2.0.7
3.0.2 3.0.1 3.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.2.0 trunk 1.8.7 1.9.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9
getwid / includes / blocks / template-parts / post-featured-background-image.php

post-featured-background-image.php in Getwid – Gutenberg Blocks 2.0.7, at includes/blocks/template-parts/post-featured-background-image.php

290 lines 10.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Getwid\Blocks;
4
5 class PostFeaturedBackgroundImage extends \Getwid\Blocks\AbstractBlock {
6
7 protected static $blockName = 'getwid/template-post-featured-background-image';
8 protected static $assetsHandle = 'getwid/template-parts';
9
10 public function __construct() {
11
12 parent::__construct( self::$blockName );
13
14 register_block_type(
15 self::$blockName,
16 array(
17 'attributes' => array(
18 'imageSize' => array(
19 'type' => 'string',
20 'default' => 'large'
21 ),
22 'linkTo' => array(
23 'type' => 'string',
24 'default' => 'none'
25 ),
26
27 //Content
28 'minHeight' => array(
29 'type' => 'string'
30 ),
31 'contentMaxWidth' => array(
32 'type' => 'number'
33 ),
34
35 // Padding
36 'paddingTopValue' => array(
37 'type' => 'string'
38 ),
39 'paddingBottomValue' => array(
40 'type' => 'string'
41 ),
42 'paddingLeftValue' => array(
43 'type' => 'string'
44 ),
45 'paddingRightValue' => array(
46 'type' => 'string'
47 ),
48 'paddingTop' => array(
49 'type' => 'string',
50 'default' => ''
51 ),
52 'paddingBottom' => array(
53 'type' => 'string',
54 'default' => ''
55 ),
56 'paddingLeft' => array(
57 'type' => 'string',
58 'default' => ''
59 ),
60 'paddingRight' => array(
61 'type' => 'string',
62 'default' => ''
63 ),
64 'paddingTopTablet' => array(
65 'type' => 'string',
66 'default' => ''
67 ),
68 'paddingBottomTablet' => array(
69 'type' => 'string',
70 'default' => ''
71 ),
72 'paddingLeftTablet' => array(
73 'type' => 'string',
74 'default' => ''
75 ),
76 'paddingRightTablet' => array(
77 'type' => 'string',
78 'default' => ''
79 ),
80 'paddingTopMobile' => array(
81 'type' => 'string',
82 'default' => ''
83 ),
84 'paddingBottomMobile' => array(
85 'type' => 'string',
86 'default' => ''
87 ),
88 'paddingLeftMobile' => array(
89 'type' => 'string',
90 'default' => ''
91 ),
92 'paddingRightMobile' => array(
93 'type' => 'string',
94 'default' => ''
95 ),
96
97 //Alignment
98 'verticalAlign' => array(
99 'type' => 'string',
100 'default' => 'center'
101 ),
102 'verticalAlignTablet' => array(
103 'type' => 'string',
104 'default' => ''
105 ),
106 'verticalAlignMobile' => array(
107 'type' => 'string',
108 'default' => ''
109 ),
110 'horizontalAlign' => array(
111 'type' => 'string',
112 'default' => 'center'
113 ),
114 'horizontalAlignTablet' => array(
115 'type' => 'string',
116 'default' => ''
117 ),
118 'horizontalAlignMobile' => array(
119 'type' => 'string',
120 'default' => ''
121 ),
122
123 //foreground
124 'foregroundOpacity' => array(
125 'type' => 'number',
126 'default' => 35
127 ),
128 'foregroundColor' => array(
129 'type' => 'string'
130 ),
131 'foregroundFilter' => array(
132 'type' => 'string'
133 ),
134 'foregroundGradientType' => array(
135 'type' => 'string'
136 ),
137 'foregroundGradientFirstColor' => array(
138 'type' => 'string'
139 ),
140 'foregroundGradientFirstColorLocation' => array(
141 'type' => 'number',
142 'default' => 0
143 ),
144 'foregroundGradientSecondColor' => array(
145 'type' => 'string'
146 ),
147 'foregroundGradientSecondColorLocation' => array(
148 'type' => 'number',
149 'default' => 100
150 ),
151 'foregroundGradientAngle' => array(
152 'type' => 'number',
153 'default' => 180
154 ),
155 'className' => array(
156 'type' => 'string'
157 ),
158 ),
159 'render_callback' => [ $this, 'render_callback' ],
160 )
161 );
162 }
163
164 public function block_frontend_assets() {
165
166 if ( is_admin() ) {
167 return;
168 }
169
170 if ( FALSE == getwid()->assetsOptimization()->load_assets_on_demand() ) {
171 return;
172 }
173
174 add_filter( 'getwid/optimize/assets',
175 function ( $assets ) {
176 $assets[] = self::$assetsHandle;
177 $assets[] = getwid()->settings()->getPrefix() . '-blocks-common';
178
179 return $assets;
180 }
181 );
182
183 add_filter( 'getwid/optimize/should_load_common_css', '__return_true' );
184
185 $rtl = is_rtl() ? '.rtl' : '';
186
187 wp_enqueue_style(
188 self::$assetsHandle,
189 getwid_get_plugin_url( 'assets/blocks/template-parts/style' . $rtl . '.css' ),
190 [],
191 getwid()->settings()->getVersion()
192 );
193 }
194
195 public function render_callback( $attributes, $content ) {
196
197 //Not BackEnd render if we view from template page
198 if ( ( get_post_type() == getwid()->postTemplatePart()->postType ) || ( get_post_type() == 'revision' ) ) {
199 return $content;
200 }
201
202 $block_name = 'wp-block-getwid-template-post-featured-background-image';
203 $wrapper_class = $block_name;
204
205 if ( isset( $attributes[ 'className' ] ) ) {
206 $wrapper_class .= ' ' . esc_attr( $attributes[ 'className' ] );
207 }
208
209 if ( isset( $attributes[ 'linkTo' ] ) && $attributes[ 'linkTo' ] != 'none' ) {
210 $wrapper_class .= ' has-link has-link-to-' . $attributes[ 'linkTo' ];
211 }
212
213 $wrapper_style = '';
214 //Classes
215 if ( isset( $attributes[ 'minHeight' ] ) ) {
216 $wrapper_style .= 'min-height: ' . esc_attr( $attributes[ 'minHeight' ] ) . ';';
217 }
218
219 $imageSize = ( ( isset( $attributes[ 'imageSize' ] ) && $attributes[ 'imageSize' ] ) ? $attributes[ 'imageSize' ] : 'post-thumbnail' );
220
221 $current_post = get_post( get_the_ID() );
222
223 //Content Slide style
224 $content_container_style = '';
225
226 if ( isset( $attributes[ 'contentMaxWidth' ] ) ) {
227 $content_container_style .= 'max-width: '.esc_attr( $attributes[ 'contentMaxWidth' ] ) . 'px;';
228 }
229
230 //Padding
231 $content_container_class = $block_name.'__content';
232
233 getwid_custom_paddings_style_and_class( $wrapper_style, $wrapper_class, $attributes );
234
235 getwid_custom_alignment_classes( $wrapper_class, $attributes );
236
237
238 //Foreground style
239 $foreground_style = '';
240 $foreground_class = $block_name.'__foreground';
241
242 if ( isset( $attributes[ 'foregroundGradientType' ] ) ) {
243 getwid_custom_gradient_styles( 'foreground', $foreground_style, $attributes );
244 }
245
246 if ( isset( $attributes[ 'foregroundOpacity' ] ) && $attributes[ 'foregroundOpacity' ] != 35 ) {
247 $foreground_class .= ' getwid-opacity-' . esc_attr( $attributes[ 'foregroundOpacity' ] );
248 }
249
250 if ( isset( $attributes[ 'foregroundColor' ] ) ) {
251 $foreground_style .= 'background-color: ' . esc_attr( $attributes[ 'foregroundColor' ] ) . ';';
252 }
253
254 if ( isset( $attributes[ 'foregroundFilter' ] ) ) {
255 $foreground_style .= 'mix-blend-mode: ' . esc_attr( $attributes[ 'foregroundFilter' ] ) . ';';
256 }
257
258 $result = '';
259
260 $extra_attr = array(
261 'block_name' => $block_name,
262 'wrapper_class' => $wrapper_class,
263 'wrapper_style' => $wrapper_style,
264 'current_post' => $current_post,
265 'imageSize' => $imageSize,
266
267 'content_container_style' => $content_container_style,
268 'content_container_class' => $content_container_class,
269
270 'foreground_style' => $foreground_style,
271 'foreground_class' => $foreground_class,
272 'content' => $content
273 );
274
275 if ( ( has_post_thumbnail() ) || strlen( $content ) ) {
276 ob_start();
277
278 getwid_get_template_part( 'template-parts/post-featured-background-image', $attributes, false, $extra_attr );
279
280 $result = ob_get_clean();
281 }
282
283 $this->block_frontend_assets();
284
285 return $result;
286 }
287 }
288
289 new \Getwid\Blocks\PostFeaturedBackgroundImage();
290