PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.17
Post Grid Gutenberg Blocks – PostX v5.0.17
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.17, at blocks/Post_Grid_6.php

449 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
268 // Pagination Block Html
269 include ULTP_PATH . 'blocks/template/pagination_block.php';
270
271 $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'] : '' ) . '">';
272 $wraper_before .= '<div class="ultp-block-wrapper">';
273
274 // Loading
275 $wraper_before .= ultimate_post()->postx_loading();
276
277 if ( $attr['headingShow'] || $attr['filterShow'] || $attr['paginationShow'] ) {
278 $wraper_before .= '<div class="ultp-heading-filter">';
279 $wraper_before .= '<div class="ultp-heading-filter-in">';
280
281 // Heading
282 include ULTP_PATH . 'blocks/template/heading.php';
283
284 if ( $attr['filterShow'] || $attr['paginationShow'] ) {
285 $wraper_before .= '<div class="ultp-filter-navigation">';
286
287 // Filter
288 if ( $attr['filterShow'] && $attr['queryType'] != 'posts' && $attr['queryType'] != 'customPosts' ) {
289 include ULTP_PATH . 'blocks/template/filter.php';
290 }
291
292 // Navigation
293 if ( $attr['paginationShow'] && ( $attr['paginationType'] == 'navigation' ) && ( $attr['navPosition'] == 'topRight' ) ) {
294 include ULTP_PATH . 'blocks/template/navigation-before.php';
295 }
296 $wraper_before .= '</div>';
297 }
298
299 $wraper_before .= '</div>';
300 $wraper_before .= '</div>';
301 }
302
303 $wraper_before .= '<div class="ultp-block-items-wrap ultp-block-row ultp-' . $attr['layout'] . ' ultp-block-content-' . ( $attr['columnFlip'] ? 'true' : 'false' ) . '">';
304 $idx = 0;
305 while ( $recent_posts->have_posts() ) :
306 $recent_posts->the_post();
307
308 $dcContent = array_fill( 0, $attr['dcSize'], '' );
309
310 if ( ultimate_post()->is_dc_active( $attr ) ) {
311 $dcContent = \ULTP\DCService::get_dc_content_for_block( $attr, $dcContent );
312 }
313
314 include ULTP_PATH . 'blocks/template/data.php';
315
316 include ULTP_PATH . 'blocks/template/category.php';
317
318 if ( $attr['queryUnique'] ) {
319 $unique_ID[ $attr['queryUnique'] ][] = $post_id;
320 $current_unique_posts[] = $post_id;
321 }
322
323 $post_loop .= '<' . $attr['contentTag'] . ' class="ultp-block-item post-id-' . $post_id . ' ultp-block-item-' . $idx . ( $attr['titleAnimation'] ? ' ultp-animation-' . $attr['titleAnimation'] : '' ) . '">';
324 $post_loop .= '<div class="ultp-block-content-wrap ultp-block-content-overlay">';
325
326 if ( ( $post_thumb_id || $attr['fallbackEnable'] ) && $attr['showImage'] ) {
327 $post_loop .= '<div class="ultp-block-image ultp-block-image-' . $attr['imgAnimation'] . ( $attr['imgOverlay'] ? ' ultp-block-image-overlay ultp-block-image-' . $attr['imgOverlayType'] : '' ) . '">';
328 $srcset = $attr['imgSrcset'] ? 'srcset="' . esc_attr( wp_get_attachment_image_srcset( $post_thumb_id ) ) . '"' : '';
329 $post_loop .= '<a href="' . $titlelink . '" ' . ( $attr['openInTab'] ? 'target="_blank"' : '' ) . '>';
330 // Post Image Size
331 $imgSize = $idx == 0 ? $attr['imgCrop'] : $attr['imgCropSmall'];
332 // Image
333 if ( $post_thumb_id && $post_thumb_id ) {
334 $post_loop .= '<img ' . ( $attr['imgLazy'] ? ' loading="lazy"' : '' ) . ' ' . $srcset . ' alt="' . esc_attr( $title ) . '" src="' . wp_get_attachment_image_url( $post_thumb_id, $imgSize ) . '" />';
335 } elseif ( $attr['fallbackEnable'] ) {
336 if ( isset( $attr['fallbackImg']['id'] ) ) {
337 // User Define Fallback Image
338 $post_loop .= ultimate_post()->get_image( $attr['fallbackImg']['id'], $imgSize, '', $title, $attr['imgSrcset'], $attr['imgLazy'] );
339 } else {
340 // Default Fallback Image
341 $video = ultimate_post()->get_youtube_id( $post_video );
342 $post_loop .= '<img src="' . ( $video ? 'https://img.youtube.com/vi/' . $video . '/0.jpg' : $dummy_url ) . '" alt="dummy-img" />';
343 }
344 }
345 $post_loop .= '</a>';
346 if ( ( $attr['catPosition'] != 'aboveTitle' ) && ( $idx == 0 || $attr['showSmallCat'] ) && $attr['catShow'] ) {
347 $post_loop .= '<div class="ultp-category-img-grid">' . $category . '</div>';
348 }
349 $post_loop .= '</div>';
350 if ( $post_video ) {
351 include ULTP_PATH . 'blocks/template/video_icon.php';
352 }
353 } else {
354 if ( $post_video ) {
355 include ULTP_PATH . 'blocks/template/video_icon.php';
356 }
357 $post_loop .= '<div class="ultp-block-image ultp-block-empty-image"></div>';
358 }
359 $post_loop .= '<div class="ultp-block-content ultp-block-content-' . $attr['overlayContentPosition'] . '">';
360 $post_loop .= '<div class="ultp-block-content-inner">';
361
362 $post_loop .= $dcContent[7];
363
364 // Category
365 if ( ( $attr['catPosition'] == 'aboveTitle' ) && ( $idx == 0 || $attr['showSmallCat'] ) && $attr['catShow'] ) {
366 $post_loop .= $category;
367 }
368
369 $post_loop .= $dcContent[6];
370
371 // Title
372 if ( $title && $attr['titleShow'] && $attr['titlePosition'] == 1 ) {
373 include ULTP_PATH . 'blocks/template/title.php';
374 }
375
376 $post_loop .= $dcContent[5];
377
378 // Meta
379 if ( ( $idx == 0 || $attr['showSmallMeta'] ) && $attr['metaShow'] && $attr['metaPosition'] == 'top' ) {
380 include ULTP_PATH . 'blocks/template/meta.php';
381 }
382
383 $post_loop .= $dcContent[4];
384
385 // Title
386 if ( $title && $attr['titleShow'] && $attr['titlePosition'] == 0 ) {
387 include ULTP_PATH . 'blocks/template/title.php';
388 }
389
390 $post_loop .= $dcContent[3];
391
392 // Excerpt
393 if ( ( $idx == 0 || $attr['showSmallExcerpt'] ) && $attr['excerptShow'] ) {
394 $post_loop .= '<div class="ultp-block-excerpt">' . ultimate_post()->get_excerpt( $post_id, $attr['showSeoMeta'], $attr['showFullExcerpt'], $attr['excerptLimit'] ) . '</div>';
395 }
396
397 $post_loop .= $dcContent[2];
398
399 // Read More
400 if ( $attr['readMore'] && ( $idx == 0 || $attr['showSmallBtn'] ) ) {
401 $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>';
402 }
403
404 $post_loop .= $dcContent[1];
405
406 // Meta
407 if ( ( $idx == 0 || $attr['showSmallMeta'] ) && $attr['metaShow'] && $attr['metaPosition'] == 'bottom' ) {
408 include ULTP_PATH . 'blocks/template/meta.php';
409 }
410
411 $post_loop .= $dcContent[0];
412
413 $post_loop .= '</div>';
414 $post_loop .= '</div>';
415 $post_loop .= '</div>';
416 if ( $post_video && $attr['enablePopup'] ) {
417 include ULTP_PATH . 'blocks/template/video_popup.php';
418 }
419 $post_loop .= '</' . $attr['contentTag'] . '>';
420 ++$idx;
421 endwhile;
422 if ( $attr['queryUnique'] ) {
423 $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>';
424 }
425
426 // if ( $attr['advPaginationEnable'] && ($attr['paginationType'] == 'loadMore')) {
427 // $wraper_after .= '<span class="ultp-loadmore-insert-before"></span>';
428 // }
429
430 $wraper_after .= '</div>'; // ultp-block-items-wrap
431
432 // Navigation
433 if ( $attr['paginationShow'] && ( $attr['paginationType'] == 'navigation' ) && ( $attr['navPosition'] != 'topRight' ) ) {
434 include ULTP_PATH . 'blocks/template/navigation-after.php';
435 }
436
437 $wraper_after .= '</div>';
438 $wraper_after .= $pagi_block_html;
439 $wraper_after .= '</div>';
440
441 wp_reset_query();
442 } else {
443 $wraper_before .= ultimate_post()->get_no_result_found_html( $attr['notFoundMessage'] );
444 }
445
446 return $noAjax ? $post_loop : $wraper_before . $post_loop . $wraper_after;
447 }
448 }
449