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

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

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