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_4.php

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

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