PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.32
Post Grid Gutenberg Blocks – PostX v5.0.32
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_Grid_1.php

Post_Grid_1.php in Post Grid Gutenberg Blocks – PostX 5.0.32, at blocks/Post_Grid_1.php

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