PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.31
Post Grid Gutenberg Blocks – PostX v5.0.31
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_1.php

Post_List_1.php in Post Grid Gutenberg Blocks – PostX 5.0.31, at blocks/Post_List_1.php

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