PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.26
Post Grid Gutenberg Blocks – PostX v5.0.26
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.26, at blocks/Post_Grid_5.php

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