PluginProbe
Post Grid Gutenberg Blocks – PostX / 4.0.3
Post Grid Gutenberg Blocks – PostX v4.0.3
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_List_2.php

Post_List_2.php in Post Grid Gutenberg Blocks – PostX 4.0.3, at blocks/Post_List_2.php

416 lines 22.8 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_List_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 General Setting
24 ============================*/
25 'headingShow' => true,
26 'readMore' => true,
27 'excerptShow' => true,
28 'catShow' => true,
29 'metaShow' => true,
30 'showImage' => true,
31 'filterShow' => false,
32 'paginationShow' => true,
33 'contentTag' => 'div',
34 'openInTab' => false,
35 'titleShow' => true,
36 'titleStyle' => 'none',
37 /*============================
38 Query Setting
39 ============================*/
40 'queryQuick' => '',
41 'queryNumPosts' => (object)['lg'=>5],
42 'queryNumber' => 5,
43 'queryType' => 'post',
44 'queryTax' => 'category',
45 'queryTaxValue' => '[]',
46 'queryRelation' => 'OR',
47 'queryOrderBy' => 'date',
48 'metaKey' => 'custom_meta_key',
49 'queryOrder' => 'desc',
50 // Include Remove from Version 2.5.4
51 'queryInclude' => '',
52 'queryExclude' => '[]',
53 'queryAuthor' => '[]',
54 'queryOffset' => '0',
55 'queryExcludeTerm' => '[]',
56 'queryExcludeAuthor' => '[]',
57 'querySticky' => true,
58 'queryUnique' => '',
59 'queryPosts' => '[]',
60 'queryCustomPosts' => '[]',
61 'notFoundMessage' => 'No Post Found',
62
63 /*============================
64 Heading Style
65 ============================*/
66 'headingText' => 'Post List #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 Style
77 ============================*/
78 'titleTag' => 'h3',
79 'titlePosition' => true,
80 'titleLength' => 0,
81
82 /*============================
83 Meta Setting
84 ============================*/
85 'showSmallMeta' => true,
86 'metaPosition' => 'top',
87 'metaStyle' => 'icon',
88 'metaSeparator' => '',
89 'authorLink' => true,
90 'metaList' => '["metaAuthor","metaDate","metaRead"]',
91 'metaMinText' => 'min read',
92 'metaAuthorPrefix' => 'By',
93 'metaDateFormat' => 'M j, Y',
94 'metaListSmall' => '["metaAuthor","metaDate","metaRead"]',
95
96 /*============================
97 Category Style
98 ============================*/
99 'maxTaxonomy'=> '30',
100 'taxonomy' => 'category',
101 'showSmallCat' => true,
102 'catStyle' => 'classic',
103 'catPosition' => 'aboveTitle',
104 'customCatColor' => false,
105 'seperatorLink' => admin_url( 'edit-tags.php?taxonomy=category' ),
106 'onlyCatColor' => false,
107
108 /*============================
109 Image Setting
110 ============================*/
111 'mobileImageTop' => false,
112 'imgFlip' => false,
113 'imgCrop' => 'full',
114 'imgCropSmall' => (ultimate_post()->get_setting('disable_image_size') == 'yes' ? 'full' : 'ultp_layout_square'),
115 'imgAnimation' => 'opacity',
116 'imgOverlay' => false,
117 'imgOverlayType' => 'default',
118 'fallbackEnable' => true,
119 'fallbackImg' => '',
120 'imgSrcset' => false,
121 'imgLazy' => false,
122
123 /*============================
124 Video Style
125 ============================*/
126 'vidIconEnable' => true,
127 'popupAutoPlay' => true,
128 'iconSize' => (object)['lg'=>'80', 'sm'=> '50', 'xs'=> '50', 'unit' => 'px'],
129 // by default should be off
130 'enablePopup' => false,
131 'enablePopupTitle' => true,
132
133 /*============================
134 Filter Setting
135 ============================*/
136 'filterBelowTitle' => false,
137 'filterType' => 'category',
138 'filterText' => 'all',
139 'filterValue' => '[]',
140 'filterMobile' => true,
141 'filterMobileText' => 'More',
142
143 /*============================
144 Pagination Style
145 ============================*/
146 'paginationType' => 'pagination',
147 'loadMoreText' => 'Load More',
148 'paginationText' => 'Previous|Next',
149 'paginationNav' => 'textArrow',
150 'paginationAjax' => true,
151 'navPosition' => 'topRight',
152
153 /*============================
154 Read more
155 ============================*/
156 'showSmallBtn' => true,
157 'readMoreText' => '',
158 'readMoreIcon' => '',
159
160 /*============================
161 Excerpt Style
162 ============================*/
163 'varticalAlign' => 'middle',
164 'showSeoMeta' => false,
165 'showSmallExcerpt' => true,
166 'showFullExcerpt' => false,
167 'fullExcerptLg' => false,
168 'excerptLimit' => 40,
169 'excerptLimitLg' => 70,
170
171 /*============================
172 Separator Style
173 ============================*/
174 'separatorShow' => true,
175
176 /*============================
177 Wrapper Style
178 ============================*/
179 'advanceId' => '',
180 'advanceZindex' => '',
181 'hideExtraLarge' => false,
182 'hideTablet' => false,
183 'hideMobile' => false,
184 'advanceCss' => '',
185 'currentPostId' => '',
186 );
187 }
188
189 public function register() {
190 register_block_type( 'ultimate-post/post-list-2',
191 array(
192 'editor_script' => 'ultp-blocks-editor-script',
193 'editor_style' => 'ultp-blocks-editor-css',
194 'render_callback' => array($this, 'content')
195 )
196 );
197 }
198
199 public function content($attr, $noAjax) {
200 $attr = wp_parse_args($attr, $this->get_attributes());
201 global $unique_ID;
202
203 if (!$noAjax) {
204 $paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
205 $attr['paged'] = $paged ? $paged : 1;
206 }
207 if($attr['queryUnique'] && isset($attr['savedQueryUnique'])) {
208 $unique_ID = $attr['savedQueryUnique'];
209 }
210
211 $block_name = 'post-list-2';
212 $wraper_before = $wraper_after = $post_loop = '';
213 $attr['queryNumber'] = ultimate_post()->get_post_number(5, $attr['queryNumber'], $attr['queryNumPosts']);
214 $recent_posts = new \WP_Query( ultimate_post()->get_query( $attr ) );
215 $pageNum = ultimate_post()->get_page_number($attr, $recent_posts->found_posts);
216 // Dummy Img Url
217 $dummy_url = ULTP_URL.'assets/img/ultp-fallback-img.png';
218
219 // Loadmore and Unique content
220 if($attr['queryUnique'] && isset($attr['loadMoreQueryUnique']) && $attr['paginationShow'] && ($attr['paginationType'] == 'loadMore')) {
221 $unique_ID = $attr['loadMoreQueryUnique'];
222 $current_unique_posts = $attr['ultp_current_unique_posts'];
223 }
224
225 $attr['className'] = isset($attr['className']) && $attr['className'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['className']) : '';
226 $attr['align'] = isset($attr['align']) && $attr['align'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['align']) : '';
227 $attr['advanceId'] = isset($attr['advanceId']) ? sanitize_html_class( $attr['advanceId'] ) : '';
228 $attr['blockId'] = isset($attr['blockId']) ? sanitize_html_class( $attr['blockId'] ) : '';
229 $attr['contentTag'] = in_array( $attr['contentTag'], ultimate_post()->ultp_allowed_block_tags() ) ? $attr['contentTag'] : 'div';
230 $attr['layout'] = sanitize_html_class( $attr['layout'] );
231 $attr['imgAnimation'] = sanitize_html_class( $attr['imgAnimation'] );
232 $attr['imgOverlayType'] = sanitize_html_class( $attr['imgOverlayType'] );
233 $attr['popupAutoPlay'] = $attr['popupAutoPlay'] == true ;
234 $attr['readMoreText'] = wp_kses($attr['readMoreText'], ultimate_post()->ultp_allowed_html_tags());
235 $attr['varticalAlign'] = sanitize_html_class( $attr['varticalAlign'] );
236
237 if ($recent_posts->have_posts()) {
238
239 $wraper_before .= '<div '.( $attr['advanceId'] ? 'id="'.$attr['advanceId'].'" ':'').' class="wp-block-ultimate-post-'.$block_name.' ultp-block-'.$attr["blockId"].''.( $attr["align"] ? ' align' .$attr["align"]:'' ).''.( $attr["className"] ? ' '.$attr["className"]:'' ).'">';
240 $wraper_before .= '<div class="ultp-block-wrapper">';
241
242 // Loading
243 $wraper_before .= ultimate_post()->loading();
244
245 if ($attr['headingShow'] || $attr['filterShow'] || $attr['paginationShow']) {
246 $wraper_before .= '<div class="ultp-heading-filter">';
247 $wraper_before .= '<div class="ultp-heading-filter-in">';
248
249 // Heading
250 include ULTP_PATH.'blocks/template/heading.php';
251
252 if ($attr['filterShow'] || $attr['paginationShow']) {
253 $wraper_before .= '<div class="ultp-filter-navigation">';
254
255 // Filter
256 if($attr['filterShow'] && $attr['queryType'] != 'posts' && $attr['queryType'] != 'customPosts') {
257 include ULTP_PATH.'blocks/template/filter.php';
258 }
259
260 // Navigation
261 if ($attr['paginationShow'] && ($attr['paginationType'] == 'navigation') && ($attr['navPosition'] == 'topRight')) {
262 include ULTP_PATH.'blocks/template/navigation-before.php';
263 }
264 $wraper_before .= '</div>';
265 }
266
267 $wraper_before .= '</div>';
268 $wraper_before .= '</div>';
269 }
270
271 $wraper_before .= '<div class="ultp-block-items-wrap ultp-block-content-'.$attr['varticalAlign'].($attr['imgFlip'] ? ' ultp-block-content-true' : '').' ultp-'.$attr['layout'].'">';
272 $idx = 0;
273 while ( $recent_posts->have_posts() ): $recent_posts->the_post();
274
275 include ULTP_PATH.'blocks/template/data.php';
276
277 include ULTP_PATH.'blocks/template/category.php';
278
279 if ($attr['queryUnique']) {
280 $unique_ID[$attr['queryUnique']][] = $post_id;
281 $current_unique_posts[] = $post_id;
282 }
283
284 $post_loop .= '<'.$attr['contentTag'].' class="ultp-block-item ultp-block-media post-id-'.$post_id.'">';
285 $post_loop .= '<div class="ultp-block-content-wrap'.(($idx===0) ? ' ultp-first-postlist-2' : ' ultp-all-postlist-2').'">';
286
287 if((($post_thumb_id || $attr['fallbackEnable']) && $attr['showImage'])) {
288 if($idx == 0){
289 $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 : '' ).'">';
290 $post_loop .= '<a href="'.$titlelink.'" '.($attr['openInTab'] ? 'target="_blank"' : '').'>';
291 // Post Image Id
292 $block_img_id = $post_thumb_id ? $post_thumb_id : ($attr['fallbackEnable'] && isset($attr['fallbackImg']['id']) ? $attr['fallbackImg']['id'] : '');
293 // Post Image
294 if($post_thumb_id || ($attr['fallbackEnable'] && $block_img_id)) {
295 $post_loop .= ultimate_post()->get_image($block_img_id, $attr['imgCrop'], '', $title, $attr['imgSrcset'], $attr['imgLazy']);
296 } else {
297 $video = ultimate_post()->get_youtube_id($post_video);
298 $post_loop .= '<img src="'.($video ? 'https://img.youtube.com/vi/'.$video.'/0.jpg' : $dummy_url).'" alt="dummy-img" />';
299 }
300 $post_loop .= '</a>';
301 if($post_video){
302 $post_loop .= '<div enableAutoPlay="'.$attr['popupAutoPlay'].'" class="ultp-video-icon">'.ultimate_post()->svg_icon('play_line').'</div>';
303 }
304 if (($attr['catPosition'] != 'aboveTitle') && $attr['catShow'] ) {
305 $post_loop .= '<div class="ultp-category-img-grid">'.$category.'</div>';
306 }
307 $post_loop .= '</div>';
308 } else if(($attr['layout'] === 'layout1') || ($attr['layout'] === 'layout4')) {
309 $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 : '' ).'">';
310 if (($attr['catPosition'] != 'aboveTitle') && $attr['showSmallCat'] && $attr['catShow'] ) {
311 $post_loop .= '<div class="ultp-category-img-grid">'.$category.'</div>';
312 }
313 $post_loop .= '<a href="'.$titlelink.'" '.($attr['openInTab'] ? 'target="_blank"' : '').'>';
314 // Post Image Id
315 $block_img_id = $post_thumb_id ? $post_thumb_id : ($attr['fallbackEnable'] && isset($attr['fallbackImg']['id']) ? $attr['fallbackImg']['id'] : '');
316 // Post Image
317 if($post_thumb_id || ($attr['fallbackEnable'] && $block_img_id)) {
318 $post_loop .= ultimate_post()->get_image($block_img_id, $attr['imgCropSmall'], '', $title, $attr['imgSrcset'], $attr['imgLazy']);
319 } else {
320 $video = ultimate_post()->get_youtube_id($post_video);
321 $post_loop .= '<img src="'.($video ? 'https://img.youtube.com/vi/'.$video.'/0.jpg' : $dummy_url).'" alt="dummy-img" />';
322 }
323 $post_loop .= '</a>';
324 if($post_video){
325 $post_loop .= '<div enableAutoPlay="'.$attr['popupAutoPlay'].'" class="ultp-video-icon">'.ultimate_post()->svg_icon('play_line').'</div>';
326 }
327 $post_loop .= '</div>';
328 }
329 }
330 $post_loop .= '<div class="ultp-block-content">';
331
332 // Category
333 if (($attr['catPosition'] == 'aboveTitle') && ($idx == 0 || $attr['showSmallCat'] ) && $attr['catShow']) {
334 $post_loop .= $category;
335 }
336
337 // Title
338 if ($title && $attr['titleShow'] && $attr['titlePosition'] == 1) {
339 include ULTP_PATH.'blocks/template/title.php';
340 }
341
342 // Meta Top
343 if ($attr['metaShow'] && ($idx == 0 || $attr['showSmallMeta']) && $attr['metaPosition'] =='top' ) {
344 include ULTP_PATH.'blocks/template/meta.php';
345 }
346
347 // Title
348 if ($title && $attr['titleShow'] && $attr['titlePosition'] == 0) {
349 include ULTP_PATH.'blocks/template/title.php';
350 }
351
352 // Excerpt
353 if (($idx == 0 || $attr['showSmallExcerpt']) && $attr['excerptShow']) {
354 if($attr['layout'] != 'layout3' ){
355 $excptLimit = $idx == 0 ? $attr['excerptLimitLg'] : $attr['excerptLimit'];
356 $showFullexcerpt = $idx == 0 ? $attr['fullExcerptLg'] : $attr['showFullExcerpt'];
357 } else {
358 $excptLimit = $attr['excerptLimit'];
359 $showFullexcerpt = $attr['showFullExcerpt'];
360 }
361 $post_loop .= '<div class="ultp-block-excerpt">'.ultimate_post()->get_excerpt($post_id, $attr['showSeoMeta'], $attr['showFullExcerpt'], $excptLimit).'</div>';
362 }
363
364 // Read More
365 if ($attr['readMore'] && ($idx == 0 || $attr['showSmallBtn'])) {
366 $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()->svg_icon($attr['readMoreIcon']).'</a></div>';
367 }
368
369 // Meta Bottom
370 if ($attr['metaShow'] && ($idx == 0 || $attr['showSmallMeta']) && $attr['metaPosition'] =='bottom' ) {
371 include ULTP_PATH.'blocks/template/meta.php';
372 }
373 $post_loop .= '</div>';
374 $post_loop .= '</div>';
375 if($post_video && $attr['enablePopup'] && ($attr['layout'] !== 'layout2' && $attr['layout'] !== 'layout3' || $idx == 0)) {
376 include ULTP_PATH.'blocks/template/video_popup.php';
377 }
378 $post_loop .= '</'.$attr['contentTag'].'>';
379 $idx ++;
380 endwhile;
381 if($attr['queryUnique']) {
382 $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>";
383 }
384
385 if ($attr['paginationShow'] && ($attr['paginationType'] == 'loadMore')) {
386 $wraper_after .= '<span class="ultp-loadmore-insert-before"></span>';
387 }
388
389 $wraper_after .= '</div>';//ultp-block-items-wrap
390
391 // Load More
392 if ($attr['paginationShow'] && ($attr['paginationType'] == 'loadMore')) {
393 include ULTP_PATH.'blocks/template/loadmore.php';
394 }
395
396 // Navigation
397 if ($attr['paginationShow'] && ($attr['paginationType'] == 'navigation') && ($attr['navPosition'] != 'topRight')) {
398 include ULTP_PATH.'blocks/template/navigation-after.php';
399 }
400
401 // Pagination
402 if ($attr['paginationShow'] && ($attr['paginationType'] == 'pagination')) {
403 include ULTP_PATH.'blocks/template/pagination.php';
404 }
405
406 $wraper_after .= '</div>';
407 $wraper_after .= '</div>';
408
409 wp_reset_query();
410 }else {
411 $wraper_before .= ultimate_post()->get_no_result_found_html( $attr['notFoundMessage'] );
412 }
413
414 return $noAjax ? $post_loop : $wraper_before.$post_loop.$wraper_after;
415 }
416 }