PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.32
Post Grid Gutenberg Blocks – PostX v5.0.32
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 2.1.2 All 237 releases
ultimate-post / blocks / Post_List_2.php

Post_List_2.php in Post Grid Gutenberg Blocks – PostX 5.0.32, at blocks/Post_List_2.php

499 lines 18.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ULTP\blocks;
4
5 defined( 'ABSPATH' ) || exit;
6
7 class Post_List_2 {
8
9 public function __construct() {
10 add_action( 'init', array( $this, 'register' ) );
11 }
12
13 public function get_attributes() {
14
15 return array(
16 'blockId' => '',
17 'previewImg' => '',
18 // --------------------------
19 // Layout
20 // --------------------------
21 'layout' => 'layout1',
22 'infiniteScroll' => false,
23
24 /*
25 ============================
26 General Setting
27 ============================*/
28 'headingShow' => true,
29 'readMore' => true,
30 'excerptShow' => true,
31 'catShow' => true,
32 'metaShow' => true,
33 'showImage' => true,
34 'filterShow' => false,
35 'paginationShow' => true,
36 'contentTag' => 'div',
37 'openInTab' => false,
38 'titleShow' => true,
39 'titleStyle' => 'none',
40 /*
41 ============================
42 Query Setting
43 ============================*/
44 'queryQuick' => '',
45 'queryNumPosts' => (object) array( 'lg' => 5 ),
46 'queryNumber' => 5,
47 'queryType' => 'post',
48 'queryTax' => 'category',
49 'queryTaxValue' => '[]',
50 'queryRelation' => 'OR',
51 'queryOrderBy' => 'date',
52 'metaKey' => 'custom_meta_key',
53 'queryOrder' => 'desc',
54 // Include Remove from Version 2.5.4
55 'queryInclude' => '',
56 'queryExclude' => '[]',
57 'queryAuthor' => '[]',
58 'queryOffset' => '0',
59 'queryExcludeTerm' => '[]',
60 'queryExcludeAuthor' => '[]',
61 'querySticky' => true,
62 'queryUnique' => '',
63 'queryPosts' => '[]',
64 'queryCustomPosts' => '[]',
65 'notFoundMessage' => 'No Post Found',
66
67 /*
68 ============================
69 Heading Style
70 ============================*/
71 'headingText' => 'Post List #2',
72 'headingURL' => '',
73 'headingBtnText' => 'View More',
74 'headingStyle' => 'style1',
75 'headingTag' => 'h2',
76 'headingAlign' => 'left',
77 'subHeadingShow' => false,
78 'subHeadingText' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ut sem augue. Sed at felis ut enim dignissim sodales.',
79
80 /*
81 ============================
82 Title Style
83 ============================*/
84 'titleTag' => 'h3',
85 'titlePosition' => true,
86 'titleLength' => 0,
87
88 /*
89 ============================
90 Meta Setting
91 ============================*/
92 'showSmallMeta' => true,
93 'metaPosition' => 'top',
94 'metaStyle' => 'icon',
95 'metaSeparator' => 'dot',
96 'authorLink' => true,
97 'metaList' => '["metaAuthor","metaDate","metaRead"]',
98 'metaMinText' => 'min read',
99 'metaAuthorPrefix' => 'By',
100 'metaDateFormat' => 'M j, Y',
101 'metaListSmall' => '["metaAuthor","metaDate","metaRead"]',
102
103 /*
104 ============================
105 Category Style
106 ============================*/
107 'maxTaxonomy' => '30',
108 'taxonomy' => 'category',
109 'showSmallCat' => true,
110 'catStyle' => 'classic',
111 'catPosition' => 'aboveTitle',
112 'customCatColor' => false,
113 'seperatorLink' => admin_url( 'edit-tags.php?taxonomy=category' ),
114 'onlyCatColor' => false,
115
116 /*
117 ============================
118 Image Setting
119 ============================*/
120 'mobileImageTop' => false,
121 'imgFlip' => false,
122 'imgCrop' => 'full',
123 'imgCropSmall' => ( ultimate_post()->get_setting( 'disable_image_size' ) == 'yes' ? 'full' : 'ultp_layout_square' ),
124 'imgAnimation' => 'opacity',
125 'imgOverlay' => false,
126 'imgOverlayType' => 'default',
127 'fallbackEnable' => true,
128 'fallbackImg' => '',
129 'imgSrcset' => false,
130 'imgLazy' => false,
131
132 /*
133 ============================
134 Video Style
135 ============================*/
136 'vidIconEnable' => true,
137 'popupAutoPlay' => true,
138 'iconSize' => (object) array(
139 'lg' => '80',
140 'sm' => '50',
141 'xs' => '50',
142 'unit' => 'px',
143 ),
144 // by default should be off
145 'enablePopup' => false,
146 'enablePopupTitle' => true,
147
148 /*
149 ============================
150 Filter Setting
151 ============================*/
152 'filterBelowTitle' => false,
153 'filterType' => 'category',
154 'filterText' => 'all',
155 'filterValue' => '[]',
156 'filterMobile' => true,
157 'filterMobileText' => 'More',
158
159 /*
160 ============================
161 Pagination Style
162 ============================*/
163 'paginationType' => 'pagination',
164 'loadMoreText' => 'Load More',
165 'paginationText' => 'Previous|Next',
166 'paginationNav' => 'textArrow',
167 'paginationAjax' => true,
168 'navPosition' => 'topRight',
169
170 /*
171 ============================
172 Read more
173 ============================*/
174 'showSmallBtn' => true,
175 'readMoreText' => '',
176 'readMoreIcon' => '',
177
178 /*
179 ============================
180 Excerpt Style
181 ============================*/
182 'varticalAlign' => 'middle',
183 'showSeoMeta' => false,
184 'showSmallExcerpt' => true,
185 'showFullExcerpt' => false,
186 'fullExcerptLg' => false,
187 'excerptLimit' => 40,
188 'excerptLimitLg' => 70,
189
190 /*
191 ============================
192 Separator Style
193 ============================*/
194 'separatorShow' => true,
195
196 /*
197 ============================
198 Wrapper Style
199 ============================*/
200 'advanceId' => '',
201 'advanceZindex' => '',
202 'hideExtraLarge' => false,
203 'hideTablet' => false,
204 'hideMobile' => false,
205 'advanceCss' => '',
206 'currentPostId' => '',
207
208 // --------------------------------
209 // Advance Filter Block Compatibility
210 // --------------------------------
211 'advFilterEnable' => false,
212 'querySearch' => '',
213
214 // --------------------------------
215 // Pagination block compatibility
216 // --------------------------------
217 'advPaginationEnable' => false,
218 'defQueryTax' => array(),
219 'advRelation' => 'AND',
220
221 /*
222 ============================
223 Dynamic Content
224 ============================*/
225 'dcEnabled' => false,
226 'dcFields' => array(),
227 'dcSize' => 9,
228 );
229 }
230
231 public function register() {
232 register_block_type(
233 'ultimate-post/post-list-2',
234 array(
235 'editor_script' => 'ultp-blocks-editor-script',
236 'editor_style' => 'ultp-blocks-editor-css',
237 'render_callback' => array( $this, 'content' ),
238 )
239 );
240 }
241
242 public function content( $attr, $noAjax ) {
243 $attr = wp_parse_args( $attr, $this->get_attributes() );
244 global $unique_ID;
245
246 if ( ! $noAjax ) {
247 $paged = is_front_page() ? get_query_var( 'page' ) : get_query_var( 'paged' );
248 $attr['paged'] = $paged ? $paged : 1;
249 }
250 if ( $attr['queryUnique'] && isset( $attr['savedQueryUnique'] ) ) {
251 $unique_ID = $attr['savedQueryUnique'];
252 }
253
254 $block_name = 'post-list-2';
255 $vid_icon_redirect = true; // Its used for video icon do not remove it
256 $wraper_before = $wraper_after = $post_loop = '';
257 $attr['queryNumber'] = ultimate_post()->get_post_number( 5, $attr['queryNumber'], $attr['queryNumPosts'] );
258 $recent_posts = new \WP_Query( ultimate_post()->get_query( $attr ) );
259 $pageNum = ultimate_post()->get_page_number( $attr, $recent_posts->found_posts );
260 // Dummy Img Url
261 $dummy_url = ULTP_URL . 'assets/img/ultp-fallback-img.png';
262
263 // Loadmore and Unique content
264 if ( $attr['queryUnique'] && isset( $attr['loadMoreQueryUnique'] ) && $attr['paginationShow'] && ( $attr['paginationType'] == 'loadMore' ) ) {
265 $unique_ID = $attr['loadMoreQueryUnique'];
266 $current_unique_posts = $attr['ultp_current_unique_posts'];
267 }
268
269 $attr['className'] = isset( $attr['className'] ) && $attr['className'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['className'] ) : '';
270 $attr['align'] = isset( $attr['align'] ) && $attr['align'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['align'] ) : '';
271 $attr['advanceId'] = isset( $attr['advanceId'] ) ? sanitize_html_class( $attr['advanceId'] ) : '';
272 $attr['blockId'] = isset( $attr['blockId'] ) ? sanitize_html_class( $attr['blockId'] ) : '';
273 $attr['contentTag'] = in_array( $attr['contentTag'], ultimate_post()->ultp_allowed_block_tags() ) ? $attr['contentTag'] : 'div';
274 $attr['layout'] = sanitize_html_class( $attr['layout'] );
275 $attr['imgAnimation'] = sanitize_html_class( $attr['imgAnimation'] );
276 $attr['imgOverlayType'] = sanitize_html_class( $attr['imgOverlayType'] );
277 $attr['popupAutoPlay'] = $attr['popupAutoPlay'] == true;
278 $attr['readMoreText'] = wp_kses( $attr['readMoreText'], ultimate_post()->ultp_allowed_html_tags() );
279 $attr['varticalAlign'] = sanitize_html_class( $attr['varticalAlign'] );
280 $iscroll = '';
281 $wrap_data = '';
282 if ( $attr['infiniteScroll'] ) {
283 $iscroll = 'ultp-iscroll-active';
284 include ULTP_PATH . 'blocks/template/infinite_scroll_data.php';
285 }
286
287 if ( $recent_posts->have_posts() ) {
288
289 // Pagination Block Html
290 include ULTP_PATH . 'blocks/template/pagination_block.php';
291
292 $wraper_before .= '<div ' . ( $attr['advanceId'] ? 'id="' . $attr['advanceId'] . '" ' : '' ) . ' class="ultp-post-grid-block wp-block-ultimate-post-' . $block_name . ' ultp-block-' . $attr['blockId'] . '' . ( $attr['align'] ? ' align' . $attr['align'] : '' ) . '' . ( $attr['className'] ? ' ' . $attr['className'] : '' ) . '">';
293 $wraper_before .= '<div class="ultp-block-wrapper ' . $wrap_data . '">';
294
295 // Loading
296 $wraper_before .= ultimate_post()->postx_loading();
297
298 if ( $attr['headingShow'] || $attr['filterShow'] || $attr['paginationShow'] ) {
299 $wraper_before .= '<div class="ultp-heading-filter">';
300 $wraper_before .= '<div class="ultp-heading-filter-in">';
301
302 // Heading
303 include ULTP_PATH . 'blocks/template/heading.php';
304
305 if ( $attr['filterShow'] || $attr['paginationShow'] ) {
306 $wraper_before .= '<div class="ultp-filter-navigation">';
307
308 // Filter
309 if ( $attr['filterShow'] && $attr['queryType'] != 'posts' && $attr['queryType'] != 'customPosts' ) {
310 include ULTP_PATH . 'blocks/template/filter.php';
311 }
312
313 // Navigation
314 if ( $attr['paginationShow'] && ( $attr['paginationType'] == 'navigation' ) && ( $attr['navPosition'] == 'topRight' ) ) {
315 include ULTP_PATH . 'blocks/template/navigation-before.php';
316 }
317 $wraper_before .= '</div>';
318 }
319
320 $wraper_before .= '</div>';
321 $wraper_before .= '</div>';
322 }
323
324 $wraper_before .= '<div class="ultp-block-items-wrap ultp-block-content-' . $attr['varticalAlign'] . ( $attr['imgFlip'] ? ' ultp-block-content-true' : '' ) . ' ultp-' . $attr['layout'] . '">';
325 $idx = 0;
326 while ( $recent_posts->have_posts() ) :
327 $recent_posts->the_post();
328
329 $dcContent = array_fill( 0, $attr['dcSize'], '' );
330
331 if ( ultimate_post()->is_dc_active( $attr ) ) {
332 $dcContent = \ULTP\DCService::get_dc_content_for_block( $attr, $dcContent );
333 }
334
335 include ULTP_PATH . 'blocks/template/data.php';
336
337 include ULTP_PATH . 'blocks/template/category.php';
338
339 if ( $attr['queryUnique'] ) {
340 $unique_ID[ $attr['queryUnique'] ][] = $post_id;
341 $current_unique_posts[] = $post_id;
342 }
343
344 $post_loop .= '<' . $attr['contentTag'] . ' class="ultp-block-item ultp-block-media post-id-' . $post_id . '">';
345 $post_loop .= '<div class="ultp-block-content-wrap' . ( ( $idx === 0 ) ? ' ultp-first-postlist-2' : ' ultp-all-postlist-2' ) . '">';
346
347 $post_loop .= $idx === 0 ? $dcContent[8] : '';
348
349 if ( ( ( $post_thumb_id || $attr['fallbackEnable'] ) && $attr['showImage'] ) ) {
350 if ( $idx == 0 ) {
351 $post_loop .= '<div class="ultp-block-image ultp-block-image-' . $attr['imgAnimation'] . ( $attr['imgOverlay'] ? ' ultp-block-image-overlay ultp-block-image-' . $attr['imgOverlayType'] . ' ultp-block-image-' . $attr['imgOverlayType'] . $idx : '' ) . '">';
352 $post_loop .= '<a href="' . $titlelink . '" ' . ( $attr['openInTab'] ? 'target="_blank"' : '' ) . '>';
353 // Post Image Id
354 $block_img_id = $post_thumb_id ? $post_thumb_id : ( $attr['fallbackEnable'] && isset( $attr['fallbackImg']['id'] ) ? $attr['fallbackImg']['id'] : '' );
355 // Post Image
356 if ( $post_thumb_id || ( $attr['fallbackEnable'] && $block_img_id ) ) {
357 $post_loop .= ultimate_post()->get_image( $block_img_id, $attr['imgCrop'], '', $title, $attr['imgSrcset'], $attr['imgLazy'] );
358 } else {
359 $video = ultimate_post()->get_youtube_id( $post_video );
360 $post_loop .= '<img src="' . ( $video ? 'https://img.youtube.com/vi/' . $video . '/0.jpg' : $dummy_url ) . '" alt="dummy-img" />';
361 }
362 $post_loop .= '</a>';
363 if ( $post_video ) {
364 include ULTP_PATH . 'blocks/template/video_icon.php';
365 }
366 if ( ( $attr['catPosition'] != 'aboveTitle' ) && $attr['catShow'] ) {
367 $post_loop .= '<div class="ultp-category-img-grid">' . $category . '</div>';
368 }
369 $post_loop .= '</div>';
370 } elseif ( ( $attr['layout'] === 'layout1' ) || ( $attr['layout'] === 'layout4' ) ) {
371 $post_loop .= '<div class="ultp-block-image ultp-block-image-' . $attr['imgAnimation'] . ( $attr['imgOverlay'] ? ' ultp-block-image-overlay ultp-block-image-' . $attr['imgOverlayType'] . ' ultp-block-image-' . $attr['imgOverlayType'] . $idx : '' ) . '">';
372 if ( ( $attr['catPosition'] != 'aboveTitle' ) && $attr['showSmallCat'] && $attr['catShow'] ) {
373 $post_loop .= '<div class="ultp-category-img-grid">' . $category . '</div>';
374 }
375 $post_loop .= '<a href="' . $titlelink . '" ' . ( $attr['openInTab'] ? 'target="_blank"' : '' ) . '>';
376 // Post Image Id
377 $block_img_id = $post_thumb_id ? $post_thumb_id : ( $attr['fallbackEnable'] && isset( $attr['fallbackImg']['id'] ) ? $attr['fallbackImg']['id'] : '' );
378 // Post Image
379 if ( $post_thumb_id || ( $attr['fallbackEnable'] && $block_img_id ) ) {
380 $post_loop .= ultimate_post()->get_image( $block_img_id, $attr['imgCropSmall'], '', $title, $attr['imgSrcset'], $attr['imgLazy'] );
381 } else {
382 $video = ultimate_post()->get_youtube_id( $post_video );
383 $post_loop .= '<img src="' . ( $video ? 'https://img.youtube.com/vi/' . $video . '/0.jpg' : $dummy_url ) . '" alt="dummy-img" />';
384 }
385 $post_loop .= '</a>';
386 if ( $post_video ) {
387 include ULTP_PATH . 'blocks/template/video_icon.php';
388 }
389 $post_loop .= '</div>';
390 }
391 }
392 $post_loop .= '<div class="ultp-block-content">';
393
394 $post_loop .= $idx !== 0 ? $dcContent[8] : '';
395
396 $post_loop .= $dcContent[7];
397
398 // Category
399 if ( ( $attr['catPosition'] == 'aboveTitle' ) && ( $idx == 0 || $attr['showSmallCat'] ) && $attr['catShow'] ) {
400 $post_loop .= $category;
401 }
402
403 $post_loop .= $dcContent[6];
404
405 // Title
406 if ( $title && $attr['titleShow'] && $attr['titlePosition'] == 1 ) {
407 include ULTP_PATH . 'blocks/template/title.php';
408 }
409
410 $post_loop .= $dcContent[5];
411
412 // Meta Top
413 if ( $attr['metaShow'] && ( $idx == 0 || $attr['showSmallMeta'] ) && $attr['metaPosition'] == 'top' ) {
414 include ULTP_PATH . 'blocks/template/meta.php';
415 }
416
417 $post_loop .= $dcContent[4];
418
419 // Title
420 if ( $title && $attr['titleShow'] && $attr['titlePosition'] == 0 ) {
421 include ULTP_PATH . 'blocks/template/title.php';
422 }
423
424 $post_loop .= $dcContent[3];
425
426 // Excerpt
427 if ( ( $idx == 0 || $attr['showSmallExcerpt'] ) && $attr['excerptShow'] ) {
428 if ( $attr['layout'] != 'layout3' ) {
429 $excptLimit = $idx == 0 ? $attr['excerptLimitLg'] : $attr['excerptLimit'];
430 $showFullexcerpt = $idx == 0 ? $attr['fullExcerptLg'] : $attr['showFullExcerpt'];
431 } else {
432 $excptLimit = $attr['excerptLimit'];
433 $showFullexcerpt = $attr['showFullExcerpt'];
434 }
435 $post_loop .= '<div class="ultp-block-excerpt">' . ultimate_post()->get_excerpt( $post_id, $attr['showSeoMeta'], $attr['showFullExcerpt'], $excptLimit ) . '</div>';
436 }
437
438 $post_loop .= $dcContent[2];
439
440 // Read More
441 if ( $attr['readMore'] && ( $idx == 0 || $attr['showSmallBtn'] ) ) {
442 $post_loop .= '<div class="ultp-block-readmore"><a aria-label="' . $title . '" href="' . $titlelink . '" ' . ( $attr['openInTab'] ? 'target="_blank"' : '' ) . '>' . ( $attr['readMoreText'] ? $attr['readMoreText'] : esc_html__( 'Read More', 'ultimate-post' ) ) . ultimate_post()->get_svg_icon( $attr['readMoreIcon'] ) . '</a></div>';
443 }
444
445 $post_loop .= $dcContent[1];
446
447 // Meta Bottom
448 if ( $attr['metaShow'] && ( $idx == 0 || $attr['showSmallMeta'] ) && $attr['metaPosition'] == 'bottom' ) {
449 include ULTP_PATH . 'blocks/template/meta.php';
450 }
451
452 $post_loop .= $dcContent[0];
453
454 $post_loop .= '</div>';
455 $post_loop .= '</div>';
456 if ( $post_video && $attr['enablePopup'] && ( $attr['layout'] !== 'layout2' && $attr['layout'] !== 'layout3' || $idx == 0 ) ) {
457 include ULTP_PATH . 'blocks/template/video_popup.php';
458 }
459 $post_loop .= '</' . $attr['contentTag'] . '>';
460 ++$idx;
461 endwhile;
462 if ( $attr['queryUnique'] ) {
463 $post_loop .= "<span style='display: none;' class='ultp-current-unique-posts' data-ultp-unique-ids= " . wp_json_encode( $unique_ID ) . ' data-current-unique-posts= ' . wp_json_encode( $current_unique_posts ) . '> </span>';
464 }
465
466 // if ( ( $attr['paginationShow'] || $attr['advPaginationEnable'] ) && ($attr['paginationType'] == 'loadMore')) {
467 // $wraper_after .= '<span class="ultp-loadmore-insert-before"></span>';
468 // }
469
470 $wraper_after .= '</div>'; // ultp-block-items-wrap
471
472 // Load More
473 if ( $attr['paginationShow'] && ( $attr['paginationType'] == 'loadMore' ) ) {
474 include ULTP_PATH . 'blocks/template/loadmore.php';
475 }
476
477 // Navigation
478 if ( $attr['paginationShow'] && ( $attr['paginationType'] == 'navigation' ) && ( $attr['navPosition'] != 'topRight' ) ) {
479 include ULTP_PATH . 'blocks/template/navigation-after.php';
480 }
481
482 // Pagination
483 if ( $attr['paginationShow'] && ( $attr['paginationType'] == 'pagination' ) ) {
484 include ULTP_PATH . 'blocks/template/pagination.php';
485 }
486
487 $wraper_after .= '</div>';
488 $wraper_after .= $pagi_block_html;
489 $wraper_after .= '</div>';
490
491 wp_reset_query();
492 } else {
493 $wraper_before .= ultimate_post()->get_no_result_found_html( $attr['notFoundMessage'] );
494 }
495
496 return $noAjax ? $post_loop : $wraper_before . $post_loop . $wraper_after;
497 }
498 }
499