PluginProbe
Post Grid Gutenberg Blocks – PostX / 4.1.25
Post Grid Gutenberg Blocks – PostX v4.1.25
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 4.1.25, at blocks/Post_Module_2.php

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