PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.36
Post Grid Gutenberg Blocks – PostX v5.0.36
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_2.php

Post_Grid_2.php in Post Grid Gutenberg Blocks – PostX 5.0.36, at blocks/Post_Grid_2.php

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