PluginProbe
Post Grid Gutenberg Blocks – PostX / 4.1.21
Post Grid Gutenberg Blocks – PostX v4.1.21
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 4.1.21, at blocks/Post_Module_1.php

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