PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.35
Post Grid Gutenberg Blocks – PostX v5.0.35
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_3.php

Post_List_3.php in Post Grid Gutenberg Blocks – PostX 5.0.35, at blocks/Post_List_3.php

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