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

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

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