PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.20
Post Grid Gutenberg Blocks – PostX v5.0.20
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.20, at blocks/Post_Grid_4.php

445 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
23 // --------------------------
24 // Query Setting
25 // --------------------------
26 'queryQuick' => '',
27 'queryNumber' => 3,
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 // 'titleAnimColor' => 'black',
53 'headingShow' => true,
54 'excerptShow' => true,
55 'catShow' => true,
56 'metaShow' => true,
57 'showImage' => true,
58 'filterShow' => false,
59 'paginationShow' => false,
60 'readMore' => false,
61 'contentTag' => 'div',
62 'openInTab' => false,
63 'notFoundMessage' => 'No Post Found',
64
65 // --------------------------
66 // Heading Setting/Style
67 // --------------------------
68 'headingText' => 'Post Grid #4',
69 'headingURL' => '',
70 'headingBtnText' => 'View More',
71 'headingStyle' => 'style1',
72 'headingTag' => 'h2',
73 'headingAlign' => 'left',
74 'subHeadingShow' => false,
75 'subHeadingText' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ut sem augue. Sed at felis ut enim dignissim sodales.',
76
77 // --------------------------
78 // Title Setting/Style
79 // --------------------------
80 'titleTag' => 'h3',
81 'titleAnimation' => '',
82 'titlePosition' => true,
83 'titleLength' => 0,
84
85 // --------------------------
86 // Overlay Content Setting/Style
87 // --------------------------
88 'overlayContentPosition' => 'bottomPosition',
89
90 // --------------------------
91 // Content Setting/Style
92 // --------------------------
93 'showSeoMeta' => false,
94 'showSmallExcerpt' => false,
95 'showFullExcerpt' => false,
96 'excerptLimit' => 20,
97
98 // --------------------------
99 // Category Setting/Style
100 // --------------------------
101 'maxTaxonomy' => '30',
102 'taxonomy' => 'category',
103 'showSmallCat' => true,
104 'catStyle' => 'classic',
105 'catPosition' => 'aboveTitle',
106 'customCatColor' => false,
107 'seperatorLink' => admin_url( 'edit-tags.php?taxonomy=category' ),
108 'onlyCatColor' => false,
109
110 // --------------------------
111 // Meta Setting/Style
112 // --------------------------
113 'metaPosition' => 'top',
114 'metaStyle' => 'icon',
115 'authorLink' => true,
116 'metaSeparator' => 'dot',
117 'metaList' => '["metaAuthor","metaDate","metaRead"]',
118 'metaMinText' => 'min read',
119 'metaAuthorPrefix' => 'By',
120 'metaDateFormat' => 'M j, Y',
121 'metaListSmall' => '["metaAuthor","metaDate"]',
122
123 // --------------------------
124 // Image Setting/Style
125 // --------------------------
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' => 'flat',
131 'fallbackEnable' => true,
132 'fallbackImg' => '',
133 'imgSrcset' => false,
134 'imgLazy' => false,
135
136 // --------------------------
137 // Video Icon Setting
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' => 3 ),
200 'queryNumber2' => 4,
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-4',
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-4';
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 $attr['columnFlip'] = $attr['columnFlip'] == true;
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'] : '' ) . '">';
273 $wraper_before .= '<div class="ultp-block-wrapper">';
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-content-' . $attr['columnFlip'] . '">';
305 $idx = 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 // Post 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['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
403 if ( $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
422 // if ( $attr['advPaginationEnable'] && ($attr['paginationType'] == 'loadMore')) {
423 // $wraper_after .= '<span class="ultp-loadmore-insert-before"></span>';
424 // }
425
426 $wraper_after .= '</div>'; // ultp-block-items-wrap
427
428 // Navigation
429 if ( $attr['paginationShow'] && ( $attr['paginationType'] == 'navigation' ) && ( $attr['navPosition'] != 'topRight' ) ) {
430 include ULTP_PATH . 'blocks/template/navigation-after.php';
431 }
432
433 $wraper_after .= '</div>';
434 $wraper_after .= $pagi_block_html;
435 $wraper_after .= '</div>';
436
437 wp_reset_query();
438 } else {
439 $wraper_before .= ultimate_post()->get_no_result_found_html( $attr['notFoundMessage'] );
440 }
441
442 return $noAjax ? $post_loop : $wraper_before . $post_loop . $wraper_after;
443 }
444 }
445