PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.19
Post Grid Gutenberg Blocks – PostX v5.0.19
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.19, at blocks/Post_List_3.php

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