PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.34
Post Grid Gutenberg Blocks – PostX v5.0.34
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_6.php

Post_Grid_6.php in Post Grid Gutenberg Blocks – PostX 5.0.34, at blocks/Post_Grid_6.php

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