PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.4
Post Grid Gutenberg Blocks – PostX v5.0.4
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_1.php

Post_Module_1.php in Post Grid Gutenberg Blocks – PostX 5.0.4, at blocks/Post_Module_1.php

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