PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.26
Post Grid Gutenberg Blocks – PostX v5.0.26
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.26, at blocks/Post_Grid_3.php

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