PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.3
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.3
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / blocks / includes / template.php

template.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.3, at blocks/includes/template.php

940 lines 33.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Table of Contents block for Smart Post Show.
4 *
5 * @package Smart_Post_Show_Pro
6 * @subpackage Smart_Post_Show_Pro/blocks/includes
7 */
8
9 namespace SmartPostShow\Blocks;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 die;
13 }
14
15 /**
16 * Post Content render Class.
17 */
18 class Template {
19
20
21
22 /**
23 * Renders the post carousel template.
24 *
25 * @param array $attributes The block attributes.
26 * @param array $post_query The post query data.
27 * @param string $pagination_type Optional. The pagination type. Default is empty string.
28 * @return void
29 */
30 public static function post_carousel( $attributes, $post_query, $pagination_type = '' ) {
31 $carousel_style = $attributes['carouselStyle'] ?? '';
32
33 ob_start();
34 foreach ( $post_query as $data ) {
35 if ( 'ticker' == $carousel_style ) {
36 ?>
37 <div class="sp_marquee-item sp-slide-item">
38 <?php self::template_one( $attributes, $data ); ?>
39 </div>
40 <?php
41 } else {
42 ?>
43 <div class="swiper-slide sp-slide-item">
44 <?php self::template_one( $attributes, $data ); ?>
45 </div>
46 <?php
47 }
48 }
49 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
50 echo ob_get_clean();
51 }
52
53
54
55 /**
56 * Renders the carousel two template.
57 *
58 * @param array $attributes The block attributes.
59 * @param array $post_query The post query data.
60 * @param string $pagination_type Optional. The pagination type. Default is empty string.
61 * @return void
62 */
63 public static function post_carousel_two( $attributes, $post_query, $pagination_type = '' ) {
64 $carousel_style = $attributes['carouselStyle'] ?? '';
65
66 ob_start();
67 foreach ( $post_query as $data ) {
68 if ( 'ticker' == $carousel_style ) {
69 ?>
70 <div class="sp_marquee-item sp-slide-item">
71 <?php self::template_one( $attributes, $data ); ?>
72 </div>
73 <?php
74 } else {
75 ?>
76 <div class="swiper-slide sp-slide-item">
77 <?php self::template_one( $attributes, $data ); ?>
78 </div>
79 <?php
80 }
81 }
82 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
83 echo ob_get_clean();
84 }
85
86
87 /**
88 * Renders the post slider template.
89 *
90 * @param array $attributes The block attributes.
91 * @param array $post_query The post query data.
92 * @param string $pagination_type Optional. The pagination type. Default is empty string.
93 * @return void
94 */
95 public static function post_slider( $attributes, $post_query, $pagination_type = '' ) {
96 ob_start();
97 foreach ( $post_query as $data ) {
98 ?>
99 <div class="swiper-slide sp-slide-item">
100 <?php self::template_one( $attributes, $data ); ?>
101 </div>
102 <?php
103 }
104 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
105 echo ob_get_clean();
106 }
107 /**
108 * Renders the post slider two template.
109 *
110 * @param array $attributes The block attributes.
111 * @param array $post_query The post query data.
112 * @param string $pagination_type Optional. The pagination type. Default is empty string.
113 * @return void
114 */
115 public static function post_slider_two( $attributes, $post_query, $pagination_type = '' ) {
116 ob_start();
117 foreach ( $post_query as $data ) {
118 ?>
119 <div class="swiper-slide sp-slide-item">
120 <?php self::template_one( $attributes, $data ); ?>
121 </div>
122 <?php
123 }
124 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
125 echo ob_get_clean();
126 }
127 /**
128 * Render grid one template.
129 *
130 * @param array $attributes Block attributes.
131 * @param array $post_query Post query data.
132 * @param string $pagination_type Pagination type (optional).
133 */
134 public static function post_grid_one( $attributes, $post_query, $pagination_type = '' ) {
135 $layout = $attributes['blockLayoutName'] ?? '';
136 $skip_items_for_grid_top_section = array(
137 'grid-one-layout-one' => 0,
138 'grid-one-layout-three' => 1,
139 'grid-one-layout-four' => 1,
140 'grid-one-layout-five' => 0,
141 'grid-one-layout-six' => 2,
142 'grid-one-layout-six-updated' => 4,
143 'grid-one-layout-seven' => 4,
144 'grid-one-layout-eight' => 3,
145 'grid-one-layout-nine' => 3,
146 );
147
148 $large_item_part_one = array_slice( $post_query, 0, 1 );
149 $large_item_part_two = array_slice( $post_query, 1, $skip_items_for_grid_top_section[ $layout ] );
150
151 $skip_items = ( 'grid-one-layout-one' === $layout || 'grid-one-layout-five' === $layout ) || wp_is_mobile() ? 0 : $skip_items_for_grid_top_section[ $layout ] + 1;
152
153 $hide_part = array( 'readMoreButton', 'taxonomy', 'excerpt' );
154 $hide_part_small_items = array();
155
156 switch ( $layout ) {
157 case 'grid-one-layout-six':
158 case 'grid-one-layout-six-updated':
159 case 'grid-one-layout-seven':
160 case 'grid-one-layout-eight':
161 case 'grid-one-layout-nine':
162 $hide_part_small_items = array( 'excerpt', 'taxonomy', 'readMoreButton' );
163 break;
164 case 'grid-one-layout-three':
165 case 'grid-one-layout-four':
166 $hide_part = array();
167 break;
168 }
169 ob_start();
170 if ( 'load-more' === $pagination_type ) { // When data load by ajax and pagination type is load more.
171 foreach ( $post_query as $data ) {
172 self::template_one( $attributes, $data, $hide_part_small_items );
173 }
174 } else {
175 if ( ! wp_is_mobile() && ! in_array(
176 $layout,
177 array(
178 'grid-one-layout-one',
179 'grid-one-layout-five',
180 ),
181 true
182 ) ) {
183 ?>
184 <div class="sp-smart-post-static-grid-contents">
185 <div class="sp-smart-post-large-item-part-one">
186 <?php
187 foreach ( $large_item_part_one as $data ) {
188 self::template_one( $attributes, $data );
189 }
190 ?>
191 </div>
192 <div class="sp-smart-post-large-item-part-two">
193 <?php
194 foreach ( $large_item_part_two as $data ) {
195 self::template_one( $attributes, $data, $hide_part );
196 }
197 ?>
198 </div>
199 </div>
200 <?php } ?>
201 <div class="sp-smart-post-dynamic-grid-contents">
202 <?php
203 foreach ( array_slice( $post_query, $skip_items ) as $data ) {
204 self::template_one( $attributes, $data, $hide_part_small_items );
205 }
206 ?>
207 </div>
208 <?php
209 }
210 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
211 echo ob_get_clean();
212 }
213 /**
214 * Renders the grid two template.
215 *
216 * @param array $attributes The block attributes.
217 * @param array $post_query The post query data.
218 * @param string $pagination_type Optional. The pagination type. Default is empty string.
219 * @return void
220 */
221 public static function post_grid_two( $attributes, $post_query, $pagination_type = '' ) {
222 ob_start();
223 foreach ( $post_query as $data ) {
224 ?>
225 <?php self::template_one( $attributes, $data ); ?>
226 <?php
227 }
228 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
229 echo ob_get_clean();
230 }
231
232 /**
233 * Renders the grid three template.
234 *
235 * @param array $attributes The block attributes.
236 * @param array $post_query The post query data.
237 * @param string $pagination_type Optional. The pagination type. Default is empty string.
238 * @return void
239 */
240 public static function post_grid_three( $attributes, $post_query, $pagination_type = '' ) {
241 $layout = $attributes['blockLayoutName'] ?? '';
242 $skip_items_for_grid_top_section = array(
243 'grid-three-layout-one' => 2,
244 'grid-three-layout-two' => 2,
245 'grid-three-layout-three' => 1,
246 'grid-three-layout-four' => 0,
247 'grid-three-layout-five' => 3,
248 );
249 $large_item_part_one = array_slice( $post_query, 0, $skip_items_for_grid_top_section[ $layout ] );
250 $large_item_part_two = array_slice( $post_query, $skip_items_for_grid_top_section[ $layout ] );
251 ob_start();
252 if ( 'load-more' === $pagination_type ) { // When data load by ajax and pagination type is load more.
253 foreach ( $post_query as $data ) {
254 self::template_one( $attributes, $data );
255 }
256 } else {
257 ?>
258 <div class="sp-smart-post-static-grid-contents sp-smart-post-background-layout <?php echo esc_attr( $layout ); ?>">
259 <?php
260 foreach ( $large_item_part_one as $data ) {
261 self::template_one( $attributes, $data );
262 }
263 ?>
264 </div>
265 <div class="sp-smart-post-dynamic-grid-contents sp-smart-post-background-layout <?php echo esc_attr( $layout ); ?>">
266 <?php
267 foreach ( $large_item_part_two as $data ) {
268 self::template_one( $attributes, $data );
269 }
270 ?>
271 </div>
272 <?php
273 }
274 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
275 echo ob_get_clean();
276 }
277
278 /**
279 * Render grid four template.
280 *
281 * @param array $attributes Block attributes.
282 * @param array $post_query Post query data.
283 * @param string $pagination_type Pagination type (optional).
284 */
285 public static function post_grid_four( $attributes, $post_query, $pagination_type = '' ) {
286 $layout = $attributes['postGridLayout'] ?? '';
287
288 $skip_items_for_grid_top_section = array(
289 'grid-four-layout-one' => 5,
290 'grid-four-layout-two' => 5,
291 'grid-four-layout-three' => 5,
292 'grid-four-layout-four' => 4,
293 'grid-four-layout-five' => 4,
294 'grid-four-layout-six' => 3,
295 );
296
297 $large_item_part_one = array_slice( $post_query, 0, $skip_items_for_grid_top_section[ $layout ] );
298
299 $skip_post = $skip_items_for_grid_top_section[ $layout ];
300
301 $large_item_part_two = array_slice( $post_query, $skip_post );
302
303 ob_start();
304
305 if ( 'load-more' === $pagination_type ) {
306 foreach ( $post_query as $data ) {
307 self::template_one( $attributes, $data );
308 }
309 } else {
310 ?>
311 <div class="sp-smart-show-pro grid-four-container <?php echo esc_attr( $layout ); ?>">
312 <div class="sp-smart-post-grid-four-static-contents sp-smart-post-background-layout">
313 <?php
314 foreach ( $large_item_part_one as $data ) {
315 self::template_one( $attributes, $data );
316 }
317 ?>
318 </div>
319 <div class="sp-smart-post-dynamic-grid-contents sp-smart-post-background-layout">
320 <?php
321 foreach ( $large_item_part_two as $data ) {
322 self::template_one( $attributes, $data );
323 }
324 ?>
325 </div>
326 </div>
327 <?php
328 }
329 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
330 echo ob_get_clean();
331 }
332
333 /**
334 * Render grid five template.
335 *
336 * @param array $attributes Block attributes.
337 * @param array $post_query Post query data.
338 * @param string $pagination_type Pagination type (optional).
339 */
340 public static function post_grid_five( $attributes, $post_query, $pagination_type = '' ) {
341 $layout = $attributes['postGridLayout'] ?? '';
342
343 $skip_items_for_grid_top_section = in_array( $layout, array( 'grid-five-layout-one', 'grid-five-layout-two', 'grid-five-layout-three' ), true ) ? 3 : 4;
344
345 $large_item_part_one = array_slice( $post_query, 0, $skip_items_for_grid_top_section );
346 $skip_post = $skip_items_for_grid_top_section;
347 $large_item_part_two = array_slice( $post_query, $skip_post );
348
349 ob_start();
350
351 if ( 'load-more' === $pagination_type ) {
352 foreach ( $post_query as $data ) {
353 self::template_one( $attributes, $data );
354 }
355 } else {
356 ?>
357
358 <div class="sp-smart-post-grid-five-dynamic-contents sp-smart-post-background-layout <?php echo esc_attr( $layout ); ?>">
359 <?php
360 foreach ( $large_item_part_one as $data ) {
361 self::template_one( $attributes, $data );
362 }
363 ?>
364 </div>
365 <div class="sp-smart-post-grid-five-static-contents sp-smart-post-background-layout <?php echo esc_attr( $layout ); ?>">
366 <?php
367 foreach ( $large_item_part_two as $data ) {
368 self::template_one( $attributes, $data );
369 }
370 ?>
371 </div>
372 <?php
373 }
374 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
375 echo ob_get_clean();
376 }
377 /**
378 * Render grid six template.
379 *
380 * @param array $attributes Block attributes.
381 * @param array $post_query Post query data.
382 * @param string $pagination_type Pagination type (optional).
383 */
384 public static function post_grid_six( $attributes, $post_query, $pagination_type = '' ) {
385 $layout = $attributes['postGridLayout'] ?? '';
386 // Define the number of items to skip for the top section based on the layout.
387 $skip_items_for_grid_top_section = in_array( $layout, array( 'grid-six-layout-one', 'grid-six-layout-two' ), true ) ? 1 : 2;
388 $large_item_part_one = array_slice( $post_query, 0, $skip_items_for_grid_top_section );
389
390 $skip_post = $skip_items_for_grid_top_section;
391
392 $large_item_part_two = array_slice( $post_query, $skip_post );
393
394 ob_start();
395
396 if ( 'load-more' === $pagination_type ) {
397 foreach ( $post_query as $data ) {
398 self::template_one( $attributes, $data );
399 }
400 } else {
401 ?>
402 <div class="sp-smart-post-grid-six-large-contents <?php echo 'grid-six-layout-four' === $layout ? 'sp-smart-post-background-layout' : ''; ?> <?php echo esc_attr( $layout ); ?>">
403 <?php
404 foreach ( $large_item_part_one as $data ) {
405 self::template_one( $attributes, $data );
406 }
407 ?>
408 </div>
409 <div class="sp-smart-post-grid-six-dynamic-contents <?php echo 'grid-six-layout-one' === $layout ? 'sp-smart-post-background-layout' : ''; ?> <?php echo esc_attr( $layout ); ?>">
410 <?php
411 foreach ( $large_item_part_two as $data ) {
412 self::template_one( $attributes, $data );
413 }
414 ?>
415 </div>
416 <?php
417 }
418 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
419 echo ob_get_clean();
420 }
421 /**
422 * Render timeline one template.
423 *
424 * @param array $attributes Block attributes.
425 * @param array $post_query Post query data.
426 * @param string $pagination_type Pagination type (optional).
427 */
428 public static function post_timeline_one( $attributes, $post_query, $pagination_type = '' ) {
429 ob_start();
430 foreach ( $post_query as $data ) {
431 ?>
432 <div class="sp-smart-post-timeline-one-post-container">
433 <div class="sp-smart-indicator">
434 <div class="sp-smart-indicator-circle"></div>
435 <div class="sp-smart-indicator-arrow"></div>
436 </div>
437 <?php self::template_one( $attributes, $data ); ?>
438 </div>
439 <?php
440 }
441 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
442 echo ob_get_clean();
443 }
444 /**
445 * Render timeline one template.
446 *
447 * @param array $attributes Block attributes.
448 * @param array $post_query Post query data.
449 * @param string $pagination_type Pagination type (optional).
450 */
451 public static function post_list_three( $attributes, $post_query, $pagination_type = '' ) {
452 $show_hide_divider = $attributes['showHideDivider'] ?? false;
453 $layout = $attributes['postListLayout'] ?? '';
454 $overlay_type = isset( $attributes['imageOverlayColor'] ) ? $attributes['imageOverlayColor'] : 'no-overlay';
455 $attributes['layout'] = $layout;
456 $bg_class = in_array( $layout, array( 'sp-smart-post-list-three-layout-three', 'sp-smart-post-list-three-layout-four' ), true ) ? ' sp-smart-post-background-layout' : '';
457
458 $image_overlay_class = in_array( $layout, array( 'sp-smart-post-list-three-layout-three', 'sp-smart-post-list-three-layout-four' ), true ) ? $overlay_type : '';
459
460 $large_item_length =
461 'sp-smart-post-list-three-layout-six' === $layout ? 4 : 2;
462
463 // Some content part hide (title part, meta data part).
464 $hide_part = array();
465 switch ( $layout ) {
466 case 'sp-smart-post-list-three-layout-one':
467 case 'sp-smart-post-list-three-layout-three':
468 $hide_part = array( 'excerpt', 'readMoreButton' );
469 break;
470 case 'sp-smart-post-list-three-layout-two':
471 case 'sp-smart-post-list-three-layout-four':
472 case 'sp-smart-post-list-three-layout-five':
473 case 'sp-smart-post-list-three-layout-six':
474 $hide_part = array( 'taxonomy', 'excerpt', 'readMoreButton', 'feature_image' );
475 break;
476 }
477
478 ob_start();
479 if ( 'load-more' === $pagination_type ) { // When data load by ajax and pagination type is load more.
480 foreach ( $post_query as $data ) {
481 ?>
482 <div class="sp-smart-post-list-item">
483 <?php if ( $show_hide_divider ) { ?>
484 <div class="sp-smart-post-list-divider"></div>
485 <?php } ?>
486 <?php self::template_one( $attributes, $data, $hide_part ); ?>
487 </div>
488 <?php
489 }
490 } else {
491 ?>
492 <div class='sp-smart-post-large-items<?php echo esc_attr( $bg_class ); ?>'>
493 <?php
494 foreach ( array_slice( $post_query, 0, $large_item_length ) as $data ) {
495 ?>
496 <div class="sp-smart-post-list-item">
497 <?php self::template_one( $attributes, $data ); ?>
498 </div>
499 <?php
500 }
501 ?>
502 </div>
503 <div class='sp-smart-post-small-items'>
504 <?php
505 foreach ( array_slice( $post_query, $large_item_length ) as $data ) {
506 ?>
507 <div class="sp-smart-post-list-item">
508 <?php if ( $show_hide_divider ) { ?>
509 <div class="sp-smart-post-list-divider"></div>
510 <?php } ?>
511 <?php self::template_one( $attributes, $data, $hide_part ); ?>
512 </div>
513 <?php
514 }
515 ?>
516 </div>
517 <?php
518 }
519 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
520 echo ob_get_clean();
521 }
522
523 /**
524 * Render timeline one template.
525 *
526 * @param array $attributes Block attributes.
527 * @param array $post_query Post query data.
528 * @param string $pagination_type Pagination type (optional).
529 */
530 public static function post_timeline_two( $attributes, $post_query, $pagination_type = '' ) {
531 ob_start();
532 foreach ( $post_query as $data ) {
533 ?>
534 <div class="sp-smart-post-timeline-one-post-container">
535 <div class="sp-smart-indicator">
536 <div class="sp-smart-indicator-circle"></div>
537 <div class="sp-smart-indicator-arrow"></div>
538 </div>
539 <?php self::template_one( $attributes, $data ); ?>
540 </div>
541 <?php
542 }
543 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
544 echo ob_get_clean();
545 }
546 /**
547 * Render list one template.
548 *
549 * @param array $attributes Block attributes.
550 * @param array $post_query Post query data.
551 */
552 public static function post_list_one( $attributes, $post_query ) {
553 $layout = $attributes['postListLayout'] ?? '';
554
555 $show_hide_divider = $attributes['showHideDivider'] ?? false;
556
557 $hide_part = array();
558 if ( 'list-one-layout-five' === $layout || 'list-one-layout-six' === $layout ) {
559 $hide_part = 'list-one-layout-five' === $layout ? array( 'title', 'metadata' ) : array( 'title' );
560 }
561
562 ob_start();
563 foreach ( $post_query as $data ) {
564 ?>
565 <div class="sp-smart-post-show-list-one-card-wrapper">
566 <?php self::template_one( $attributes, $data, $hide_part ); ?>
567 </div>
568 <?php if ( $show_hide_divider ) { ?>
569 <div class="sp-smart-post-list-divider"></div>
570 <?php } ?>
571 <?php
572 }
573 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
574 echo ob_get_clean();
575 }
576 /**
577 * Render list two template.
578 *
579 * @param array $attributes Block attributes.
580 * @param array $post_query Post query data.
581 * @param string $pagination_type Pagination type (optional).
582 */
583 public static function post_list_two( $attributes, $post_query, $pagination_type = '' ) {
584 $layout = $attributes['postListLayout'] ?? '';
585
586 $bg_class = in_array( $layout, array( 'sp-smart-post-list-two-layout-one', 'sp-smart-post-list-two-layout-two', 'sp-smart-post-list-two-layout-five', 'sp-smart-post-list-two-layout-six' ), true ) ? ' sp-smart-post-background-layout' : '';
587 $show_hide_divider = $attributes['showHideDivider'] ?? false;
588 // Some content part hide (title part, meta data part).
589 $hide_part = array();
590 switch ( $layout ) {
591 case 'sp-smart-post-list-two-layout-two':
592 case 'sp-smart-post-list-two-layout-four':
593 $hide_part = array( 'excerpt', 'readMoreButton' );
594 break;
595 case 'sp-smart-post-list-two-layout-five':
596 case 'sp-smart-post-list-two-layout-six':
597 case 'sp-smart-post-list-two-layout-eight':
598 $hide_part = array( 'taxonomy', 'excerpt', 'readMoreButton', 'feature_image' );
599 break;
600 case 'sp-smart-post-list-two-layout-seven':
601 $hide_part = array( 'taxonomy', 'readMoreButton', 'feature_image' );
602 break;
603 }
604 ob_start();
605 if ( 'load-more' === $pagination_type ) { // When data load by ajax and pagination type is load more.
606 foreach ( $post_query as $data ) {
607 ?>
608 <div class="sp-smart-post-list-item">
609 <?php self::template_one( $attributes, $data, $hide_part ); ?>
610 </div>
611 <?php if ( $show_hide_divider ) { ?>
612 <div class="sp-smart-post-list-divider"></div>
613 <?php } ?>
614 <?php
615 }
616 } else {
617 ?>
618 <div class='sp-smart-post-large-items<?php echo esc_attr( $bg_class ); ?>'>
619 <?php
620 foreach ( array_slice( $post_query, 0, 1 ) as $data ) {
621 ?>
622 <div class="sp-smart-post-list-item">
623 <?php self::template_one( $attributes, $data ); ?>
624 </div>
625 <?php
626 }
627 ?>
628 </div>
629 <?php if ( $show_hide_divider ) { ?>
630 <div class="sp-smart-post-list-divider"></div>
631 <?php } ?>
632 <div class='sp-smart-post-small-items'>
633 <?php
634 foreach ( array_slice( $post_query, 1 ) as $data ) {
635 ?>
636 <div class="sp-smart-post-list-item">
637 <?php self::template_one( $attributes, $data, $hide_part ); ?>
638 </div>
639 <?php if ( $show_hide_divider ) { ?>
640 <div class="sp-smart-post-list-divider"></div>
641 <?php } ?>
642 <?php
643 }
644 ?>
645 </div>
646 <?php
647 }
648 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
649 echo ob_get_clean();
650 }
651
652 /**
653 * Retrieves pagination block attributes from inner blocks.
654 *
655 * @param object $blocks The blocks object containing inner blocks.
656 */
657 public static function pagination_attributes( $blocks ) {
658 $attributes = array();
659 if ( ! isset( $blocks->inner_blocks ) ) {
660 return;
661 }
662 // Check how many inner blocks are available.
663 $item_count = $blocks->inner_blocks->count();
664
665 for ( $index = 1; $index <= $item_count; $index++ ) {
666 // Get the inner block data.
667 $inner_block = $blocks->inner_blocks->current();
668 // If the inner block is a pagination block, get its attributes.
669 if ( 'sp-smart-post-show/pagination' === $inner_block->name ) {
670 $attributes = $inner_block->attributes;
671 break;
672 }
673 }
674 return $attributes;
675 }
676
677 /**
678 * Renders the loop template for a single post item.
679 *
680 * @param array $attributes Block attributes.
681 * @param array $data Post data for the current item.
682 * @param array $hide_part Parts to hide in the template.
683 */
684 public static function loop_template( $attributes, $data, $hide_part ) {
685 $content_part_array = isset( $attributes['contentPartArray'] ) ? $attributes['contentPartArray'] : array();
686
687 $orientation = $attributes['contentOrientation'] ?? 'orientation_one';
688 $category_position = $attributes['catTabCategoryPosition'] ?? '';
689
690 $social_share_icon_position = isset( $attributes['socialShareIconPosition'] ) ? $attributes['socialShareIconPosition'] : '';
691
692 $social_icon_display_type = isset( $attributes['socialIconDisplayType'] ) ? $attributes['socialIconDisplayType'] : 'inline-icon';
693
694 $show_social_share = ( 'inline-icon' === $social_icon_display_type || '' === $social_share_icon_position ) ? true : false;
695
696 $content_part = array(
697 'taxonomy' => ( empty( $category_position ) && 'orientation_three' !== $orientation && 'orientation_four' !== $orientation ) ? Template_Part::category( $attributes, $data ) : null,
698 'title' => Template_Part::title( $attributes, $data ),
699 'metadata' => Template_Part::meta_data( $attributes, $data ),
700 'excerpt' => Template_Part::excerpt( $attributes, $data ),
701 'readMoreButton' => Template_Part::read_more_button( $attributes, $data ),
702 'socialShare' => $show_social_share ? Template_Part::social_share( $attributes, $data ) : null,
703 'starRating' => Template_Part::star_rating( $attributes, $data ),
704 'price' => Template_Part::price( $attributes, $data ),
705 'addToCart' => Template_Part::add_to_cart( $attributes, $data ),
706 );
707
708 ob_start();
709
710 if ( ! in_array( 'feature_image', $hide_part, true ) ) {
711 Template_Part::feature_image( $attributes, $data );
712 }
713 ?>
714
715 <div class="sp-smart-post-template-one-content">
716 <div class="sp-smart-post-card-content">
717 <?php
718 foreach ( $content_part_array as $part ) {
719 if ( ! in_array( $part['value'], $hide_part, true ) ) {
720 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
721 echo $content_part[ $part['value'] ];
722 }
723 }
724 ?>
725 </div>
726 </div>
727 <?php
728 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
729 echo ob_get_clean();
730 }
731
732 /**
733 * Template one function.
734 *
735 * @param array $attributes Block attributes.
736 * @param array $data Post data for the current item.
737 * @param array $hide_part Parts to hide in the template.
738 */
739 public static function template_one( $attributes, $data, $hide_part = array() ) {
740 $layout = $attributes['layout'] ?? '';
741 $content_align_h = isset( $attributes['contentHorizontalPosition'] ) ? $attributes['contentHorizontalPosition'] : 'left';
742 $image_position = isset( $attributes['imagePosition'] ) ? $attributes['imagePosition'] : '';
743 $img_overlay_type = isset( $attributes['imageOverlayType'] ) ? $attributes['imageOverlayType'] : '';
744 $img_overlay_class = 'background' === $image_position ? ' overlay-type-' . $img_overlay_type : '';
745 $post_card_class = 'content-' . $content_align_h . $img_overlay_class;
746 ob_start();
747 ?>
748 <div class="sp-smart-post-card <?php echo esc_attr( $post_card_class ); ?>">
749 <?php
750 if ( 'list-one-layout-five' === $layout || 'list-one-layout-six' === $layout ) {
751 echo '<div class="sp-smart-post-list-one-layout-top">';
752 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
753 echo Template_Part::title( $attributes, $data );
754 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
755 echo 'list-one-layout-five' === $layout ? Template_Part::meta_data( $attributes, $data ) : '';
756 echo '</div>';
757 }
758 ?>
759 <?php echo ( 'list-one-layout-five' === $layout || 'list-one-layout-six' === $layout ) ? '<div class="sp-smart-post-list-one-layout-bottom">' : ''; ?>
760
761 <?php self::loop_template( $attributes, $data, $hide_part ); ?>
762
763 <?php echo ( 'list-one-layout-five' === $layout || 'list-one-layout-six' === $layout ) ? '</div>' : ''; ?>
764 </div>
765 <?php
766 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
767 echo ob_get_clean();
768 }
769
770 /**
771 * Thumbnail Template function.
772 *
773 * @param array $attributes Block attributes.
774 * @param array $data Post data for the current item.
775 * @param array $hide_part Parts to hide in the template.
776 */
777 public static function thumb_template( $attributes, $data, $hide_part = array() ) {
778
779 $layout = $attributes['thumbnailSliderTwoLayout'] ?? '';
780 $progress_bar = 'thumbnail-slider-two-layout-two' === $layout;
781
782 ob_start();
783 ?>
784 <div class="sp-smart-post-card sp-smart-post-thumbs-template">
785 <?php ( ! in_array( 'feature_image', $hide_part, true ) ) ? Template_Part::feature_image( $attributes, $data, false ) : null; ?>
786 <div class='sp-smart-post-template-one-content'>
787 <div class="sp-smart-post-card-content">
788 <?php
789 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
790 echo ( ! in_array( 'taxonomy', $hide_part, true ) ) ? Template_Part::category( $attributes, $data ) : null;
791 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
792 echo ( ! in_array( 'title', $hide_part, true ) ) ? Template_Part::title( $attributes, $data, $progress_bar ) : null;
793 ?>
794
795 </div>
796 </div>
797 </div>
798 <?php
799 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
800 echo ob_get_clean();
801 }
802
803 /**
804 * Smart search Template function.
805 *
806 * @param array $attributes Block attributes.
807 * @param array $post_query Post data for the current item.
808 * @param array $pagination_type Pagination type (optional).
809 */
810 public static function smart_search( $attributes, $post_query, $pagination_type = '' ) {
811 $show_date = isset( $attributes['showDate'] ) ? $attributes['showDate'] : false;
812 $show_author = isset( $attributes['showAuthor'] ) ? $attributes['showAuthor'] : false;
813 $show_excerpt = isset( $attributes['showExcerpt'] ) ? $attributes['showExcerpt'] : false;
814 $excerpt_limit = isset( $attributes['excerptLimit'] ) ? $attributes['excerptLimit'] : 20;
815 $title_global_typo_class = isset( $attributes['titleGlobalTypography']['class'] ) ? $attributes['titleGlobalTypography']['class'] : '';
816 $meta_global_typo = isset( $attributes['searchResultMetaGlobalTypography'] ) ? $attributes['searchResultMetaGlobalTypography'] : '';
817 $meta_global_typo_class = isset( $attributes['searchResultMetaGlobalTypography']['class'] ) ? $attributes['searchResultMetaGlobalTypography']['class'] : '';
818 $show_taxonomy = isset( $attributes['showTaxonomy'] ) ? $attributes['showTaxonomy'] : false;
819 $search_result_display_type = $attributes['searchResultDisplayType'] ?? '';
820 $show_image = isset( $attributes['showImage'] ) ? $attributes['showImage'] : false;
821
822 $excerpt_attr = array(
823 'excerptShow' => $show_excerpt,
824 'excerptType' => 'limited',
825 'excerpt_ending_points' => '...',
826 'excerptLength' => $excerpt_limit,
827 'excerptGlobalTypography' => $meta_global_typo,
828 );
829
830 $placeholder_img = SP_PC_URL . 'public/assets/img/placeholder.png';
831 ob_start();
832 foreach ( $post_query as $data ) {
833 $permalink = isset( $data['link'] ) ? $data['link'] : '';
834 $image_alt_text = 'alt="' . ( ! empty( $data['image_alt'] ) ? esc_attr( $data['image_alt'] ) : esc_attr( $data['title'] ) ) . '"';
835 $post_thumbnail_url = isset( $data['post_thumbnail_url'] ) ? $data['post_thumbnail_url'] : false;
836 $feature_image = $post_thumbnail_url ? '<img src="' . esc_url( $post_thumbnail_url ) . '" ' . $image_alt_text . ' loading="lazy" />' : '';
837 $feature_image = ! empty( $feature_image ) ? $feature_image : '<img src="' . $placeholder_img . '" ' . $image_alt_text . ' />';
838 $title = isset( $data['title'] ) ? $data['title'] : '';
839 ?>
840 <div class="sp-smart-post-search-item">
841 <?php if ( 'smart-search-result-layout-two' !== $search_result_display_type && $show_image ) { ?>
842 <div class="sp-smart-post-search-item-img">
843 <a href="<?php echo esc_attr( $permalink ); ?>">
844 <?php
845 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
846 echo $feature_image;
847 ?>
848 </a>
849 </div>
850 <?php } ?>
851
852 <div class="sp-smart-post-search-item-desc">
853 <?php
854 if ( $show_taxonomy && ! empty( $data['categories'] ) ) {
855 ?>
856 <div class="sp-smart-post-categories
857 <?php
858 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
859 echo $meta_global_typo_class;
860 ?>
861 ">
862 <?php
863 foreach ( $data['categories'] as $category ) {
864 ?>
865 <span class="sp-smart-post-category">
866 <?php
867 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
868 echo $category;
869 ?>
870 </span>
871 <?php
872 }
873 ?>
874 </div>
875 <?php
876 }
877 ?>
878
879 <a href="<?php echo esc_attr( $permalink ); ?>" class="sp-smart-post-search-item-title
880 <?php
881 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
882 echo $title_global_typo_class;
883 ?>
884 ">
885 <?php
886 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
887 echo $title;
888 ?>
889 </a>
890
891 <?php
892 if ( $show_excerpt ) {
893 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
894 echo Template_Part::excerpt( $excerpt_attr, $data );
895 }
896 if ( $show_author || $show_date ) {
897 ?>
898 <div class="sp-smart-post-meta-list
899 <?php
900 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
901 echo $meta_global_typo_class;
902 ?>
903 ">
904 <?php
905 if ( $show_author ) {
906 ?>
907 <span class='sp-smart-post-meta'>
908 <?php
909 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
910 echo $data['author'] ?? '';
911 ?>
912 , </span>
913 <?php
914 }
915 ?>
916 <?php
917 if ( $show_date ) {
918 ?>
919 <span class='sp-smart-post-meta'>
920 <?php
921 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
922 echo $data['date'] ?? '';
923 ?>
924 </span>
925 <?php
926 }
927 ?>
928 </div>
929 <?php
930 }
931 ?>
932 </div>
933 </div>
934 <?php
935 }
936 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here.
937 echo ob_get_clean();
938 }
939 }
940