PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.34
Post Grid Gutenberg Blocks – PostX v5.0.34
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_4.php

Post_List_4.php in Post Grid Gutenberg Blocks – PostX 5.0.34, at blocks/Post_List_4.php

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