PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.17
Post Grid Gutenberg Blocks – PostX v5.0.17
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.17, at blocks/Post_List_2.php

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