PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.37
Post Grid Gutenberg Blocks – PostX v5.0.37
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_4.php

Post_Grid_4.php in Post Grid Gutenberg Blocks – PostX 5.0.37, at blocks/Post_Grid_4.php

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