PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.20
Post Grid Gutenberg Blocks – PostX v5.0.20
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.20, at blocks/Post_List_1.php

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