PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.31
Post Grid Gutenberg Blocks – PostX v5.0.31
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_3.php

Post_Grid_3.php in Post Grid Gutenberg Blocks – PostX 5.0.31, at blocks/Post_Grid_3.php

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