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_Grid_2.php

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

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