PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.18
Post Grid Gutenberg Blocks – PostX v5.0.18
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_7.php

Post_Grid_7.php in Post Grid Gutenberg Blocks – PostX 5.0.18, at blocks/Post_Grid_7.php

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