PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.17
Post Grid Gutenberg Blocks – PostX v5.0.17
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.17, at blocks/Post_Grid_2.php

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