PluginProbe
Post Grid Gutenberg Blocks – PostX / 1.2.2
Post Grid Gutenberg Blocks – PostX v1.2.2
5.0.41 5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 All 238 releases
← All changes | blocks/Image.php +569 -143 5.0.281.2.2 View file →
@@ -1,159 +1,585 @@
1 1 <?php
2 2 namespace ULTP\blocks;
3 3
4 -defined( 'ABSPATH' ) || exit;
4 +defined('ABSPATH') || exit;
5 5
6 -class Image {
6 +class Image{
7 + public function __construct() {
8 + add_action('init', array($this, 'register'));
9 + }
10 + public function get_attributes($default = false){
7 11
8 - public function __construct() {
9 - add_action( 'init', array( $this, 'register' ) );
10 - }
11 - public function get_attributes() {
12 - return array(
13 - 'blockId' => '',
14 - 'previewImg' => '',
15 - // Image Settings
16 - 'imageUpload' => (object) array(
17 - 'id' => '999999',
18 - 'url' => ULTP_URL . 'assets/img/ultp-placeholder.jpg',
19 - ),
20 - 'darkImgEnable' => false,
21 - 'darkImage' => (object) array(
22 - 'id' => '999999',
23 - 'url' => ULTP_URL . 'assets/img/ultp-placeholder.jpg',
24 - ),
25 - 'linkType' => 'link',
26 - 'imgLink' => '',
27 - 'linkTarget' => '_blank',
28 - 'imgAlt' => 'Image',
29 - 'imgAlignment' => array( 'lg' => 'left' ),
30 - 'imgCrop' => 'full',
31 - 'imgAnimation' => 'none',
32 - 'imgMargin' => (object) array( 'lg' => '' ),
33 - 'imgOverlay' => false,
34 - 'imgOverlayType' => 'default',
35 - 'imgSrcset' => false,
36 - 'imgLazy' => false,
37 - // Heading Setting/Style
38 - 'headingText' => 'This is a Image Example',
39 - 'headingEnable' => false,
40 - 'alignment' => array( 'lg' => 'left' ),
41 - // Button Settings
42 - 'buttonEnable' => false,
43 - 'btnText' => 'Free Download',
44 - 'btnLink' => '#',
45 - 'btnTarget' => '_blank',
46 - 'btnPosition' => 'centerCenter',
47 - // Style
12 + $attributes = array(
13 + 'blockId' => [
14 + 'type' => 'string',
15 + 'default' => '',
16 + ],
17 + //--------------------------
18 + // Image Setting/Style
19 + //--------------------------
20 + 'imageUpload' => [
21 + 'type' => 'object',
22 + 'default' => (object)[ 'id'=>'999999', 'url' => ULTP_URL.'assets/img/ultp-placeholder.jpg' ],
23 + ],
24 + 'linkType' => [
25 + 'type' => 'string',
26 + 'default' => 'link',
27 + ],
28 + 'imgLink' => [
29 + 'type' => 'string',
30 + 'default' => '',
31 + ],
32 + 'linkTarget' => [
33 + 'type' => 'string',
34 + 'default' => '_blank',
35 + ],
36 + 'imgAlt' => [
37 + 'type' => 'string',
38 + 'default' => 'Image',
39 + ],
40 + 'imgAlignment' => [
41 + 'type' => 'object',
42 + 'default' => ['md' => 'left'],
43 + 'style' => [
44 + (object)[
45 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper {text-align: {{imgAlignment}};}'
46 + ],
47 + ],
48 + ],
49 + 'imgWidth' => [
50 + 'type' => 'object',
51 + 'default' => (object)['lg' =>'', 'unit' =>'px'],
52 + 'style' => [
53 + (object)[
54 + 'selector'=>'{{ULTP}} .ultp-image-block { max-width: {{imgWidth}}; }'
55 + ],
56 + ],
57 + ],
58 + 'imgHeight' => [
59 + 'type' => 'object',
60 + 'default' => (object)['lg' =>'', 'unit' =>'px'],
61 + 'style' => [
62 + (object)[
63 + 'selector'=>'{{ULTP}} .ultp-image-block {object-fit: cover; height: {{imgHeight}}; } {{ULTP}} .ultp-image-block .ultp-image {height: 100%;object-fit: cover; }'
64 + ],
65 + ],
66 + ],
67 + 'imgAnimation' => [
68 + 'type' => 'string',
69 + 'default' => 'none',
70 + ],
71 + 'imgGrayScale' => [
72 + 'type' => 'object',
73 + 'default' => (object)['lg' =>'0', 'unit' =>'%'],
74 + 'style' => [
75 + (object)[
76 + 'selector'=>'{{ULTP}} .ultp-image { filter: grayscale({{imgGrayScale}}); }'
77 + ],
78 + ],
79 + ],
80 + 'imgHoverGrayScale' => [
81 + 'type' => 'object',
82 + 'default' => (object)['lg' =>'0', 'unit' =>'%'],
83 + 'style' => [
84 + (object)[
85 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper:hover .ultp-image { filter: grayscale({{imgHoverGrayScale}}); }'
86 + ],
87 + ],
88 + ],
89 + 'imgRadius' => [
90 + 'type' => 'object',
91 + 'default' => (object)['lg' =>'', 'unit' =>'px'],
92 + 'style' => [
93 + (object)[
94 + 'selector'=>'{{ULTP}} .ultp-image-block { border-radius:{{imgRadius}}; }'
95 + ],
96 + ],
97 + ],
98 + 'imgHoverRadius' => [
99 + 'type' => 'object',
100 + 'default' => (object)['lg' =>'', 'unit' =>'px'],
101 + 'style' => [
102 + (object)[
103 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper:hover .ultp-image-block { border-radius:{{imgHoverRadius}}; }'
104 + ],
105 + ],
106 + ],
107 + 'imgShadow' => [
108 + 'type' => 'object',
109 + 'default' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'],
110 + 'style' => [
111 + (object)[
112 + 'selector'=>'{{ULTP}} .ultp-image-block'
113 + ],
114 + ],
115 + ],
116 + 'imgHoverShadow' => [
117 + 'type' => 'object',
118 + 'default' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'],
119 + 'style' => [
120 + (object)[
121 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper:hover .ultp-image-block'
122 + ],
123 + ],
124 + ],
125 + 'imgMargin' => [
126 + 'type' => 'object',
127 + 'default' => (object)['lg'=>''],
128 + 'style' => [
129 + (object)[
130 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper { margin: {{imgMargin}}; }'
131 + ],
132 + ],
133 + ],
134 + 'imgOverlay' => [
135 + 'type' => 'boolean',
136 + 'default' => false,
137 + ],
138 + 'imgOverlayType' => [
139 + 'type' => 'string',
140 + 'default' => 'default',
141 + 'style' => [
142 + (object)[
143 + 'depends' => [
144 + (object)['key'=>'imgOverlay','condition'=>'==','value'=>true],
145 + ]
146 + ],
147 + ]
148 + ],
149 + 'overlayColor' => [
150 + 'type' => 'object',
151 + 'default' => (object)['openColor' => 1, 'type' => 'color', 'color' => '#0e1523'],
152 + 'style' => [
153 + (object)[
154 + 'depends' => [
155 + (object)['key'=>'imgOverlayType','condition'=>'==','value'=>'custom'],
156 + ],
157 + 'selector'=>'{{ULTP}} .ultp-image-block::before'
158 + ],
159 + ],
48 160
49 - 'advanceId' => '',
50 - 'advanceZindex' => '',
51 - 'hideExtraLarge' => false,
52 - 'hideTablet' => false,
53 - 'hideMobile' => false,
54 - 'advanceCss' => '',
55 - );
56 - }
161 + ],
162 + 'imgOpacity' => [
163 + 'type' => 'string',
164 + 'default' => .7,
165 + 'style' => [
166 + (object)[
167 + 'depends' => [
168 + (object)['key'=>'imgOverlayType','condition'=>'==','value'=>'custom'],
169 + ],
170 + 'selector'=>'{{ULTP}} .ultp-image-block::before { opacity: {{imgOpacity}}; }'
171 + ],
172 + ],
173 + ],
57 174
58 - public function register() {
59 - register_block_type(
60 - 'ultimate-post/image',
61 - array(
62 - 'editor_script' => 'ultp-blocks-editor-script',
63 - 'editor_style' => 'ultp-blocks-editor-css',
64 - 'render_callback' => array( $this, 'content' ),
65 - )
66 - );
67 - }
175 + //Caption
176 + 'headingText' => [
177 + 'type' => 'string',
178 + 'default' => 'This is a Image Example',
179 + ],
180 + 'headingEnable' => [
181 + 'type' => 'boolean',
182 + 'default' => false
183 + ],
184 + 'headingColor' => [
185 + 'type' => 'string',
186 + 'default' => '',
187 + 'style' => [
188 + (object)[
189 + 'depends' => [
190 + (object)['key'=>'headingEnable','condition'=>'==','value'=>true],
191 + ],
192 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper .ultp-image-caption { color:{{headingColor}}; }'
193 + ],
194 + ],
195 + ],
196 + 'alignment' => [
197 + 'type' => 'object',
198 + 'default' => ['md' => 'left'],
199 + 'style' => [
200 + (object)[
201 + 'depends' => [
202 + (object)['key'=>'headingEnable','condition'=>'==','value'=>true],
203 + ],
204 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper .ultp-image-caption {text-align: {{alignment}};}'
205 + ],
206 + ],
207 + ],
208 + 'headingTypo' => [
209 + 'type' => 'object',
210 + 'default' => (object)['openTypography' => 1,'size' => (object)['lg' => '14', 'unit' => 'px'], 'height' => (object)['lg' => '', 'unit' => 'px'],'decoration' => '', 'transform' => '', 'family'=>'','weight'=>''],
211 + 'style' => [
212 + (object)[
213 + 'depends' => [
214 + (object)['key'=>'headingEnable','condition'=>'==','value'=>true],
215 + ],
216 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper .ultp-image-caption'
217 + ],
218 + ],
219 + ],
220 + 'headingMargin' => [
221 + 'type' => 'object',
222 + 'default' => (object)['lg' =>(object)['top' => '','bottom' => '','left' => '', 'right' => '', 'unit' =>'px']],
223 + 'style' => [
224 + (object)[
225 + 'depends' => [
226 + (object)['key'=>'headingEnable','condition'=>'==','value'=>true],
227 + ],
228 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper .ultp-image-caption { margin:{{headingMargin}}; }'
229 + ],
230 + ],
231 + ],
68 232
69 - public function content( $attr, $noAjax ) {
70 - $attr = wp_parse_args( $attr, $this->get_attributes() );
71 233
72 - // Dynamic Content
73 - if ( ultimate_post()->is_dc_active( $attr ) ) {
234 + //--------------------------
235 + // Button Setting & Style
236 + //--------------------------
237 + 'buttonEnable' => [
238 + 'type' => 'boolean',
239 + 'default' => false
240 + ],
241 + 'btnText' => [
242 + 'type' => 'string',
243 + 'default' => 'Free Download',
244 + ],
245 + 'btnLink' => [
246 + 'type' => 'string',
247 + 'default' => '#',
248 + ],
249 + 'btnTarget' => [
250 + 'type' => 'string',
251 + 'default' => '_blank',
252 + ],
253 + 'btnPosition' => [
254 + 'type' => 'string',
255 + 'default' => 'centerCenter',
256 + ],
74 257
75 - // Dark Image
76 - $dark_image_content_src = $attr['dc']['darkImage']['contentSrc'];
77 - $dark_image_post_id = $attr['dc']['darkImage']['postId'];
258 + //style
259 + 'btnTypo' => [
260 + 'type' => 'object',
261 + 'default' => (object)['openTypography' => 1, 'size' => (object)['lg' =>14, 'unit' =>'px'], 'height' => (object)['lg' =>20, 'unit' =>'px'], 'spacing' => (object)['lg' =>0, 'unit' =>'px'], 'transform' => 'capitalize', 'weight' => '', 'decoration' => 'none','family'=>'' ],
262 + 'style' => [
263 + (object)[
264 + 'depends' => [
265 + (object)['key'=>'linkType','condition'=>'==','value'=>'button'],
266 + ],
267 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper .ultp-image-button a'
268 + ],
269 + ],
270 + ],
271 + 'btnColor' => [
272 + 'type' => 'string',
273 + 'default' => '#fff',
274 + 'style' => [
275 + (object)[
276 + 'depends' => [
277 + (object)['key'=>'linkType','condition'=>'==','value'=>'button'],
278 + ],
279 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper .ultp-image-button a { color:{{btnColor}}; }'
280 + ],
281 + ],
282 + ],
283 + 'btnBgColor' => [
284 + 'type' => 'object',
285 + 'default' => (object)['openColor' => 1,'type' => 'color', 'color' => '#1740f5'],
286 + 'style' => [
287 + (object)[
288 + 'depends' => [
289 + (object)['key'=>'linkType','condition'=>'==','value'=>'button'],
290 + ],
291 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper .ultp-image-button a'
292 + ],
293 + ],
294 + ],
295 + 'btnBorder' => [
296 + 'type' => 'object',
297 + 'default' => (object)['openBorder'=>0, 'width' => (object)[ 'top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4','type' => 'solid' ],
298 + 'style' => [
299 + (object)[
300 + 'depends' => [
301 + (object)['key'=>'linkType','condition'=>'==','value'=>'button'],
302 + ],
303 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper .ultp-image-button a'
304 + ],
305 + ],
306 + ],
307 + 'btnRadius' => [
308 + 'type' => 'object',
309 + 'default' => (object)['lg' =>'2', 'unit' =>'px'],
310 + 'style' => [
311 + (object)[
312 + 'depends' => [
313 + (object)['key'=>'linkType','condition'=>'==','value'=>'button'],
314 + ],
315 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper .ultp-image-button a { border-radius:{{btnRadius}}; }'
316 + ],
317 + ],
318 + ],
319 + 'btnShadow' => [
320 + 'type' => 'object',
321 + 'default' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'],
322 + 'style' => [
323 + (object)[
324 + 'depends' => [
325 + (object)['key'=>'linkType','condition'=>'==','value'=>'button'],
326 + ],
327 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper .ultp-image-button a'
328 + ],
329 + ],
330 + ],
331 + 'btnHoverColor' => [
332 + 'type' => 'string',
333 + 'default' => '#fff',
334 + 'style' => [
335 + (object)[
336 + 'depends' => [
337 + (object)['key'=>'linkType','condition'=>'==','value'=>'button'],
338 + ],
339 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper .ultp-image-button a:hover { color:{{btnHoverColor}}; }'
340 + ],
341 + ],
342 + ],
343 + 'btnBgHoverColor' => [
344 + 'type' => 'object',
345 + 'default' => (object)['openColor' => 1,'type' => 'color', 'color' => '#1239e2'],
346 + 'style' => [
347 + (object)[
348 + 'depends' => [
349 + (object)['key'=>'linkType','condition'=>'==','value'=>'button'],
350 + ],
351 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper .ultp-image-button a:hover'
352 + ],
353 + ],
354 + ],
355 + 'btnHoverBorder' => [
356 + 'type' => 'object',
357 + 'default' => (object)['openBorder'=>0, 'width' => (object)[ 'top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4','type' => 'solid' ],
358 + 'style' => [
359 + (object)[
360 + 'depends' => [
361 + (object)['key'=>'linkType','condition'=>'==','value'=>'button'],
362 + ],
363 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper .ultp-image-button a:hover'
364 + ],
365 + ],
366 + ],
367 + 'btnHoverRadius' => [
368 + 'type' => 'object',
369 + 'default' => (object)['lg' =>'', 'unit' =>'px'],
370 + 'style' => [
371 + (object)[
372 + 'depends' => [
373 + (object)['key'=>'linkType','condition'=>'==','value'=>'button'],
374 + ],
375 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper .ultp-image-button a:hover { border-radius:{{btnHoverRadius}}; }'
376 + ],
377 + ],
378 + ],
379 + 'btnHoverShadow' => [
380 + 'type' => 'object',
381 + 'default' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'],
382 + 'style' => [
383 + (object)[
384 + 'depends' => [
385 + (object)['key'=>'linkType','condition'=>'==','value'=>'button'],
386 + ],
387 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper .ultp-image-button a:hover'
388 + ],
389 + ],
390 + ],
391 + 'btnSacing' => [
392 + 'type' => 'object',
393 + 'default' => (object)['lg' =>(object)['top' => 0,'bottom' => 0,'left' => 0,'right' => 0, 'unit' =>'px']],
394 + 'style' => [
395 + (object)[
396 + 'depends' => [
397 + (object)['key'=>'linkType','condition'=>'==','value'=>'button'],
398 + ],
399 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper .ultp-image-button a { margin:{{btnSacing}}; }'
400 + ],
401 + ],
402 + ],
403 + 'btnPadding' => [
404 + 'type' => 'object',
405 + 'default' => (object)['lg' =>(object)['top' => "6",'bottom' => "6",'left' => "12",'right' => "12", 'unit' =>'px']],
406 + 'style' => [
407 + (object)[
408 + 'depends' => [
409 + (object)['key'=>'linkType','condition'=>'==','value'=>'button'],
410 + ],
411 + 'selector'=>'{{ULTP}} .ultp-image-block-wrapper .ultp-image-button a { padding:{{btnPadding}}; }'
412 + ],
413 + ],
414 + ],
78 415
79 - if ( is_string( $dark_image_content_src ) && $attr['dcEnabled']['darkImage'] ) {
80 - $attr['darkImage']['url'] = \ULTP\DCService::get_dc_content_for_image( $dark_image_post_id, $dark_image_content_src );
81 - }
416 + //--------------------------
417 + // Wrapper Style
418 + //--------------------------
419 + 'wrapBg' => [
420 + 'type' => 'object',
421 + 'default' => (object)['openColor' => 0, 'type' => 'color', 'color' => '#f5f5f5'],
422 + 'style' => [
423 + (object)[
424 + 'selector'=>'{{ULTP}} .ultp-block-wrapper'
425 + ],
426 + ],
427 + ],
428 + 'wrapBorder' => [
429 + 'type' => 'object',
430 + 'default' => (object)['openBorder'=>0, 'width' =>(object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4','type' => 'solid'],
431 + 'style' => [
432 + (object)[
433 + 'selector'=>'{{ULTP}} .ultp-block-wrapper'
434 + ],
435 + ],
436 + ],
437 + 'wrapShadow' => [
438 + 'type' => 'object',
439 + 'default' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'],
440 + 'style' => [
441 + (object)[
442 + 'selector'=>'{{ULTP}} .ultp-block-wrapper'
443 + ],
444 + ],
445 + ],
446 + 'wrapRadius' => [
447 + 'type' => 'object',
448 + 'default' => (object)['lg' =>'', 'unit' =>'px'],
449 + 'style' => [
450 + (object)[
451 + 'selector'=>'{{ULTP}} .ultp-block-wrapper { border-radius:{{wrapRadius}}; }'
452 + ],
453 + ],
454 + ],
455 + 'wrapHoverBackground' => [
456 + 'type' => 'object',
457 + 'default' => (object)['openColor' => 0, 'type' => 'color', 'color' => '#1740f5'],
458 + 'style' => [
459 + (object)[
460 + 'selector'=>'{{ULTP}} .ultp-block-wrapper:hover'
461 + ],
462 + ],
463 + ],
464 + 'wrapHoverBorder' => [
465 + 'type' => 'object',
466 + 'default' => (object)['openBorder'=>0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4','type' => 'solid'],
467 + 'style' => [
468 + (object)[
469 + 'selector'=>'{{ULTP}} .ultp-block-wrapper:hover'
470 + ],
471 + ],
472 + ],
473 + 'wrapHoverRadius' => [
474 + 'type' => 'object',
475 + 'default' => (object)['lg' =>'', 'unit' =>'px'],
476 + 'style' => [
477 + (object)[
478 + 'selector'=>'{{ULTP}} .ultp-block-wrapper:hover { border-radius:{{wrapHoverRadius}}; }'
479 + ],
480 + ],
481 + ],
482 + 'wrapHoverShadow' => [
483 + 'type' => 'object',
484 + 'default' => (object)['openShadow' => 0, 'width' => (object)['top' => 1, 'right' => 1, 'bottom' => 1, 'left' => 1],'color' => '#009fd4'],
485 + 'style' => [
486 + (object)[
487 + 'selector'=>'{{ULTP}} .ultp-block-wrapper:hover'
488 + ],
489 + ],
490 + ],
491 + 'wrapMargin' => [
492 + 'type' => 'object',
493 + 'default' => (object)['lg' =>(object)['top' => '','bottom' => '', 'unit' =>'px']],
494 + 'style' => [
495 + (object)[
496 + 'selector'=>'{{ULTP}} .ultp-block-wrapper { margin:{{wrapMargin}}; }'
497 + ],
498 + ],
499 + ],
500 + 'wrapOuterPadding' => [
501 + 'type' => 'object',
502 + 'default' => (object)['lg' =>(object)['top' => '','bottom' => '','left' => '', 'right' => '', 'unit' =>'px']],
503 + 'style' => [
504 + (object)[
505 + 'selector'=>'{{ULTP}} .ultp-block-wrapper { padding:{{wrapOuterPadding}}; }'
506 + ],
507 + ],
508 + ],
509 + 'advanceId' => [
510 + 'type' => 'string',
511 + 'default' => '',
512 + ],
513 + 'advanceZindex' => [
514 + 'type' => 'number',
515 + 'default' => '',
516 + 'style' => [
517 + (object)[
518 + 'selector' => '{{ULTP}} {z-index:{{advanceZindex}};}'
519 + ],
520 + ],
521 + ],
522 + 'advanceCss' => [
523 + 'type' => 'string',
524 + 'default' => '',
525 + 'style' => [(object)['selector' => '']],
526 + ]
82 527
83 - // Image
84 - $image_content_src = $attr['dc']['imageUpload']['contentSrc'];
85 - $image_post_id = $attr['dc']['imageUpload']['postId'];
528 + );
529 +
530 + if( $default ){
531 + $temp = array();
532 + foreach ($attributes as $key => $value) {
533 + if( isset($value['default']) ){
534 + $temp[$key] = $value['default'];
535 + }
536 + }
537 + return $temp;
538 + }else{
539 + return $attributes;
540 + }
541 + }
86 542
87 - if ( is_string( $image_content_src ) && $attr['dcEnabled']['imageUpload'] ) {
88 - $attr['imageUpload']['url'] = \ULTP\DCService::get_dc_content_for_image( $image_post_id, $image_content_src );
89 - }
543 + public function register() {
544 + register_block_type( 'ultimate-post/image',
545 + array(
546 + 'attributes' => $this->get_attributes(),
547 + 'description' => __( 'Show heading or title with ultimate controls.' ),
548 + 'keywords' => [ __( 'heading' ), __( 'title' ), __( 'section' ) ],
549 + 'render_callback' => array($this, 'content')
550 + )
551 + );
552 + }
90 553
91 - // imgLink
92 - $img_link_link_src = $attr['dc']['imgLink']['linkSrc'];
93 - $img_link_post_id = $attr['dc']['imgLink']['postId'];
94 - if ( is_string( $img_link_link_src ) && $attr['dcEnabled']['imgLink'] ) {
95 - if ( str_starts_with( $img_link_link_src, 'link_' ) ) {
96 - $attr['imgLink'] = \ULTP\DCService::get_link( $img_link_post_id, $img_link_link_src );
97 - }
98 - }
554 + public function content($attr, $noAjax) {
555 + $wraper_before = '';
556 + $block_name = 'image';
557 + $attr['headingShow'] = true;
558 + $wraper_before .= '<div '.($attr['advanceId']?'id="'.$attr['advanceId'].'" ':'').' class="wp-block-ultimate-post-'.$block_name.' ultp-block-'.$attr["blockId"].' '.(isset($attr["className"])?$attr["className"]:'').'">';
559 + $wraper_before .= '<div class="ultp-block-wrapper">';
560 + $wraper_before .= '<figure class="ultp-image-block-wrapper">';
561 + $wraper_before .= '<div class="ultp-image-block ultp-image-block-'.$attr['imgAnimation'].($attr["imgOverlay"] ? ' ultp-image-block-overlay ultp-image-block-'.$attr["imgOverlayType"] : '' ).'">';
562 + // Single Image
563 + $img_arr = (array)$attr['imageUpload'];
564 + if( !empty($img_arr) ){
565 + if( ($attr['linkType'] == 'link') && $attr['imgLink'] ){
566 + $wraper_before .= '<a href="'.$attr['imgLink'].'" target="'.$attr['linkTarget'].'"><img class="ultp-image" src="'.$img_arr['url'].'" alt="'.$attr['imgAlt'].'" /></a>';
567 + } else {
568 + $wraper_before .= '<img class="ultp-image" src="'.$img_arr['url'].'" alt="'.$attr['imgAlt'].'" />';
569 + }
570 + }
571 + if( $attr['btnLink'] && ($attr['linkType'] == 'button') ){
572 + $wraper_before .= '<div class="ultp-image-button ultp-image-button-'.$attr['btnPosition'].'"><a href="'.$attr['btnLink'].'" target="'.$attr['btnTarget'].'">'.$attr['btnText'].'</a></div>';
573 + }
574 + $wraper_before .= '</div>';
575 + if( $attr['headingEnable'] == 1 ){
576 + $wraper_before .= '<figcaption class="ultp-image-caption">'.$attr['headingText'].'</figcaption>';
577 + }
578 + $wraper_before .= '</figure>';
579 + $wraper_before .= '</div>';
580 + $wraper_before .= '</div>';
99 581
100 - // btnLink
101 - $btn_link_link_src = $attr['dc']['btnLink']['linkSrc'];
102 - $btn_link_post_id = $attr['dc']['btnLink']['postId'];
103 - if ( is_string( $btn_link_link_src ) && $attr['dcEnabled']['btnLink'] ) {
104 - if ( str_starts_with( $btn_link_link_src, 'link_' ) ) {
105 - $attr['btnLink'] = \ULTP\DCService::get_link( $btn_link_post_id, $btn_link_link_src );
106 - }
107 - }
108 - }
582 + return $wraper_before;
583 + }
109 584
110 - $wraper_before = '';
111 - $block_name = 'image';
112 - $attr['headingShow'] = true;
113 - $darkImageArr = (array) $attr['darkImage'];
114 - $darkImg = array(
115 - 'enable' => $attr['darkImgEnable'],
116 - 'url' => isset( $darkImageArr['url'] ) ? $darkImageArr['url'] : ULTP_URL . 'assets/img/ultp-placeholder.jpg',
117 - 'srcset' => ( $attr['imgSrcset'] && isset( $darkImageArr['id'] ) ) ? ' srcset="' . esc_attr( wp_get_attachment_image_srcset( $darkImageArr['id'] ) ) . '"' : '',
118 - );
119 -
120 - $attr['className'] = isset( $attr['className'] ) && $attr['className'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['className'] ) : '';
121 - $attr['align'] = isset( $attr['align'] ) && $attr['align'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['align'] ) : '';
122 - $attr['advanceId'] = isset( $attr['advanceId'] ) ? sanitize_html_class( $attr['advanceId'] ) : '';
123 - $attr['blockId'] = isset( $attr['blockId'] ) ? sanitize_html_class( $attr['blockId'] ) : '';
124 - $attr['imgAnimation'] = sanitize_html_class( $attr['imgAnimation'] );
125 - $attr['imgOverlayType'] = sanitize_html_class( $attr['imgOverlayType'] );
126 - $allowed_html_tags = ultimate_post()->ultp_allowed_html_tags();
127 - $attr['btnText'] = wp_kses( $attr['btnText'], $allowed_html_tags );
128 - $attr['headingText'] = wp_kses( $attr['headingText'], $allowed_html_tags );
129 -
130 - $wraper_before .= '<div ' . ( $attr['advanceId'] ? 'id="' . $attr['advanceId'] . '" ' : '' ) . ' class="wp-block-ultimate-post-' . $block_name . ' ultp-block-' . $attr['blockId'] . '' . ( $attr['align'] ? ' align' . $attr['align'] : '' ) . '' . ( $attr['className'] ? ' ' . $attr['className'] : '' ) . '">';
131 - $wraper_before .= '<div class="ultp-block-wrapper">';
132 - $wraper_before .= '<figure class="ultp-image-block-wrapper">';
133 - $wraper_before .= '<div class="ultp-image-block ultp-image-block-' . $attr['imgAnimation'] . ( $attr['imgOverlay'] ? ' ultp-image-block-overlay ultp-image-block-' . $attr['imgOverlayType'] : '' ) . '">';
134 - // Single Image
135 - $img_arr = (array) $attr['imageUpload'];
136 - $img_url = ( isset( $img_arr['size'] ) && isset( $img_arr['size'][ $attr['imgCrop'] ] ) ) ? ( isset( $img_arr['size'][ $attr['imgCrop'] ]['url'] ) ? $img_arr['size'][ $attr['imgCrop'] ]['url'] : $img_arr['size'][ $attr['imgCrop'] ] ) : $img_arr['url'];
137 - if ( ! empty( $img_arr ) ) {
138 - $srcset_data = $attr['imgSrcset'] ? ' srcset="' . esc_attr( wp_get_attachment_image_srcset( $img_arr['id'] ) ) . '"' : '';
139 - if ( $attr['linkType'] == 'link' && $attr['imgLink'] ) {
140 - $wraper_before .= '<a href="' . esc_url( $attr['imgLink'] ) . '" target="' . sanitize_html_class( $attr['linkTarget'] ) . '">' . ultimate_post()->get_image_html( $img_url, 'full', 'ultp-image', $attr['imgAlt'], $attr['imgLazy'], $darkImg, $srcset_data ) . '</a>';
141 - } else {
142 - // $wraper_before .= ultimate_post()->get_image_html($img_arr['url'], 'full', 'ultp-image', $attr['imgAlt'], $attr['imgLazy'], $darkImg);
143 - $wraper_before .= ultimate_post()->get_image_html( $img_url, 'full', 'ultp-image', $attr['imgAlt'], $attr['imgLazy'], $darkImg, $srcset_data );
144 - }
145 - }
146 - if ( $attr['btnLink'] && $attr['linkType'] == 'button' ) {
147 - $wraper_before .= '<div class="ultp-image-button ultp-image-button-' . sanitize_html_class( $attr['btnPosition'] ) . '"><a href="' . esc_url( $attr['btnLink'] ) . '" target="' . sanitize_html_class( $attr['btnTarget'] ) . '">' . $attr['btnText'] . '</a></div>';
148 - }
149 - $wraper_before .= '</div>';
150 - if ( $attr['headingEnable'] == 1 ) {
151 - $wraper_before .= '<figcaption class="ultp-image-caption">' . $attr['headingText'] . '</figcaption>';
152 - }
153 - $wraper_before .= '</figure>';
154 - $wraper_before .= '</div>';
155 - $wraper_before .= '</div>';
156 -
157 - return $wraper_before;
158 - }
159 -}
585 +}