PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.13
Post Grid Gutenberg Blocks – PostX v5.0.13
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_Module_2.php

Post_Module_2.php in Post Grid Gutenberg Blocks – PostX 5.0.13, at blocks/Post_Module_2.php

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