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

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

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