PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.38
Post Grid Gutenberg Blocks – PostX v5.0.38
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_5.php

Post_Grid_5.php in Post Grid Gutenberg Blocks – PostX 5.0.38, at blocks/Post_Grid_5.php

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