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

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

394 lines 20.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_3{
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 //--------------------------
48 // General Setting
49 //--------------------------
50 'column' => '2',
51 'titleShow' => true,
52 'titleStyle' => 'none',
53 'headingShow' => true,
54 'excerptShow' => false,
55 'catShow' => true,
56 'metaShow' => true,
57 'showImage' => true,
58 'filterShow' => false,
59 'paginationShow' => false,
60 'readMore' => false,
61 'contentTag' => 'div',
62 'openInTab' => false,
63 'notFoundMessage' => 'No Post Found',
64
65 //--------------------------
66 // Heading Setting/Style
67 //--------------------------
68 'headingText' => 'Post Grid #3',
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 //--------------------------
79 // Title Setting/Style
80 //--------------------------
81 'titleTag' => 'h3',
82 'titleAnimation' => '',
83 'titlePosition' => true,
84 'titleLength' => 0,
85
86 //--------------------------
87 // Overlay Content Setting/Style
88 //--------------------------
89 'overlayContentPosition' => 'bottomPosition',
90
91 //--------------------------
92 // Content Setting/Style
93 //--------------------------
94 'showSeoMeta' => false,
95 'showSmallExcerpt' => false,
96 'showFullExcerpt' => false,
97 'excerptLimit' => 30,
98
99 //--------------------------
100 // Category Setting/Style
101 //--------------------------
102 'maxTaxonomy'=> '30',
103 'taxonomy' => 'category',
104 'showSmallCat' => true,
105 'catStyle' => 'classic',
106 'catPosition' => 'aboveTitle',
107 'customCatColor' => false,
108 'seperatorLink' => admin_url( 'edit-tags.php?taxonomy=category' ),
109 'onlyCatColor' => false,
110
111 //--------------------------
112 // Meta Setting/Style
113 //--------------------------
114 'showSmallMeta' => true,
115 'metaPosition' => 'top',
116 'metaStyle' => 'icon',
117 'authorLink' => true,
118 'metaSeparator' => 'dot',
119 'metaList' => '["metaAuthor","metaDate","metaRead"]',
120 'metaMinText' => 'min read',
121 'metaAuthorPrefix' => 'By',
122 'metaDateFormat' => 'M j, Y',
123 'metaListSmall' => '["metaAuthor","metaDate"]',
124
125 //--------------------------
126 // Image Setting/Style
127 //--------------------------
128 'imgCrop' => (ultimate_post()->get_setting('disable_image_size') == 'yes' ? 'full' : 'ultp_layout_landscape'),
129 'imgCropSmall' => (ultimate_post()->get_setting('disable_image_size') == 'yes' ? 'full' : 'ultp_layout_square'),
130 'imgAnimation' => 'roateLeft',
131 'imgOverlay' => true,
132 'imgOverlayType' => 'flat',
133 'fallbackEnable' => true,
134 'fallbackImg' => '',
135 'imgSrcset' => false,
136 'imgLazy' => false,
137
138 /*============================
139 Video Style
140 ============================*/
141 'vidIconEnable' => true,
142 'popupAutoPlay' => true,
143 'iconSize' => (object)['lg'=>'40', 'sm'=> '30', 'xs'=> '30', 'unit' => 'px'],
144 // by default should be off
145 'enablePopup' => false,
146 'enablePopupTitle' => true,
147
148 //--------------------------
149 // Read more Setting/Style
150 //--------------------------
151 'showSmallBtn' => false,
152 'readMoreText' => '',
153 'readMoreIcon' => 'rightArrowLg',
154
155 //--------------------------
156 // Filter Setting/Style
157 //--------------------------
158 'filterBelowTitle' => false,
159 'filterType' => 'category',
160 'filterText' => 'all',
161 'filterValue' => '[]',
162 'filterMobile' => true,
163 'filterMobileText' => 'More',
164
165 //--------------------------
166 // Pagination Setting/Style
167 //--------------------------
168 'paginationType' => 'loadMore',
169 'loadMoreText' => 'Load More',
170 'paginationText' => 'Previous|Next',
171 'paginationNav' => 'textArrow',
172 'paginationAjax' => true,
173 'navPosition' => 'topRight',
174
175 //--------------------------
176 // Wrapper Style
177 //--------------------------
178 'advanceId' => '',
179 'advanceZindex' => '',
180 'hideExtraLarge' => false,
181 'hideTablet' => false,
182 'hideMobile' => false,
183 'advanceCss' => '',
184 'currentPostId' => '',
185 );
186 }
187
188 public function register() {
189 register_block_type( 'ultimate-post/post-grid-3',
190 array(
191 'editor_script' => 'ultp-blocks-editor-script',
192 'editor_style' => 'ultp-blocks-editor-css',
193 'render_callback' => array($this, 'content')
194 )
195 );
196 }
197
198 public function content($attr, $noAjax) {
199 $attr = wp_parse_args($attr, $this->get_attributes());
200 global $unique_ID;
201
202 if (!$noAjax) {
203 $paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
204 $attr['paged'] = $paged ? $paged : 1;
205 }
206 if($attr['queryUnique'] && isset($attr['savedQueryUnique'])) {
207 $unique_ID = $attr['savedQueryUnique'];
208 }
209
210 $block_name = 'post-grid-3';
211 $wraper_before = $wraper_after = $post_loop = '';
212 $attr['queryNumber'] = ultimate_post()->get_post_number(5, $attr['queryNumber'], $attr['queryNumPosts']);
213 $recent_posts = new \WP_Query( ultimate_post()->get_query( $attr ) );
214 $pageNum = ultimate_post()->get_page_number($attr, $recent_posts->found_posts);
215 // Dummy Img Url
216 $dummy_url = ULTP_URL.'assets/img/ultp-fallback-img.png';
217
218 // Loadmore and Unique content
219 if($attr['queryUnique'] && isset($attr['loadMoreQueryUnique']) && $attr['paginationShow'] && ($attr['paginationType'] == 'loadMore')) {
220 $unique_ID = $attr['loadMoreQueryUnique'];
221 $current_unique_posts = $attr['ultp_current_unique_posts'];
222 }
223
224 $attr['className'] = isset($attr['className']) && $attr['className'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['className']) : '';
225 $attr['align'] = isset($attr['align']) && $attr['align'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['align']) : '';
226 $attr['advanceId'] = isset($attr['advanceId']) ? sanitize_html_class( $attr['advanceId'] ) : '';
227 $attr['blockId'] = isset($attr['blockId']) ? sanitize_html_class( $attr['blockId'] ) : '';
228 $attr['contentTag'] = in_array( $attr['contentTag'], ultimate_post()->ultp_allowed_block_tags() ) ? $attr['contentTag'] : 'div';
229 $attr['layout'] = sanitize_html_class( $attr['layout'] );
230 $attr['column'] = sanitize_html_class( $attr['column'] );
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['titleAnimation'] = sanitize_html_class( $attr['titleAnimation'] );
236 $attr['overlayContentPosition'] = sanitize_html_class( $attr['overlayContentPosition'] );
237
238 if ($recent_posts->have_posts()) {
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-row ultp-'.$attr['layout'].' ultp-block-column'.$attr["column"].'">';
272 $idx = ($attr['paginationShow'] && ($attr['paginationType'] == 'loadMore')) ? ( $noAjax ? 1 : 0 ) : 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 post-id-'.$post_id.($attr['titleAnimation'] ? ' ultp-animation-'.$attr['titleAnimation'] : '').'">';
285 $post_loop .= '<div class="ultp-block-content-wrap ultp-block-content-overlay">';
286
287 if(($post_thumb_id || $attr['fallbackEnable']) && $attr['showImage']) {
288 $post_loop .= '<div class="ultp-block-image ultp-block-image-'.$attr['imgAnimation'].($attr["imgOverlay"] ? ' ultp-block-image-overlay ultp-block-image-'.$attr["imgOverlayType"] : '' ).'">';
289 $post_loop .= '<a href="'.$titlelink.'" '.($attr['openInTab'] ? 'target="_blank"' : '').'>';
290 // Image Size
291 $imgSize = $idx == 0 ? $attr['imgCrop'] : $attr['imgCropSmall'];
292 // Post Image Id
293 $block_img_id = $post_thumb_id ? $post_thumb_id : ($attr['fallbackEnable'] && isset($attr['fallbackImg']['id']) ? $attr['fallbackImg']['id'] : '');
294 // Post Image
295 if($post_thumb_id || ($attr['fallbackEnable'] && $block_img_id)) {
296 $post_loop .= ultimate_post()->get_image( $block_img_id, $imgSize, '', $title, $attr['imgSrcset'], $attr['imgLazy']);
297 } else {
298 $video = ultimate_post()->get_youtube_id($post_video);
299 $post_loop .= '<img src="'.($video ? 'https://img.youtube.com/vi/'.$video.'/0.jpg' : $dummy_url).'" alt="dummy-img" />';
300 }
301 $post_loop .= '</a>';
302 if($post_video){
303 $post_loop .= '<div enableAutoPlay="'.$attr['popupAutoPlay'].'" class="ultp-video-icon">'.ultimate_post()->svg_icon('play_line').'</div>';
304 }
305 if (($attr['catPosition'] != 'aboveTitle') && ($idx == 0 || $attr['showSmallCat']) && $attr['catShow'] ) {
306 $post_loop .= '<div class="ultp-category-img-grid">'.$category.'</div>';
307 }
308 $post_loop .= '</div>';
309 } else {
310 if($post_video){
311 $post_loop .= '<div enableAutoPlay="'.$attr['popupAutoPlay'].'" class="ultp-video-icon">'.ultimate_post()->svg_icon('play_line').'</div>';
312 }
313 $post_loop .= '<div class="ultp-block-image ultp-block-empty-image"></div>';
314 }
315 $post_loop .= '<div class="ultp-block-content ultp-block-content-'.$attr['overlayContentPosition'].'">';
316 $post_loop .= '<div class="ultp-block-content-inner">';
317 // Category
318 if (($attr['catPosition'] == 'aboveTitle') && ($idx == 0 || $attr['showSmallCat'] ) && $attr['catShow']) {
319 $post_loop .= $category;
320 }
321
322 // Title
323 if ($title && $attr['titleShow'] && $attr['titlePosition'] == 1) {
324 include ULTP_PATH.'blocks/template/title.php';
325 }
326
327 // Meta
328 if ($attr['metaShow'] && ($idx == 0 || $attr['showSmallMeta']) && $attr['metaPosition'] =='top' ) {
329 include ULTP_PATH.'blocks/template/meta.php';
330 }
331
332 // Title
333 if ($title && $attr['titleShow'] && $attr['titlePosition'] == 0) {
334 include ULTP_PATH.'blocks/template/title.php';
335 }
336
337 // Excerpt
338 if (($idx == 0 || $attr['showSmallExcerpt']) && $attr['excerptShow']) {
339 $post_loop .= '<div class="ultp-block-excerpt">'.ultimate_post()->get_excerpt($post_id, $attr['showSeoMeta'], $attr['showFullExcerpt'], $attr['excerptLimit']).'</div>';
340 }
341
342 // Read More
343 if ($attr['readMore'] && ($idx == 0 || $attr['showSmallBtn'])) {
344 $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>';
345 }
346
347 // Meta Bottom
348 if ($attr['metaShow'] && ($idx == 0 || $attr['showSmallMeta']) && $attr['metaPosition'] =='bottom' ) {
349 include ULTP_PATH.'blocks/template/meta.php';
350 }
351 $post_loop .= '</div>';
352 $post_loop .= '</div>';
353 $post_loop .= '</div>';
354 if($post_video && $attr['enablePopup']) {
355 include ULTP_PATH.'blocks/template/video_popup.php';
356 }
357 $post_loop .= '</'.$attr['contentTag'].'>';
358 $idx ++;
359 endwhile;
360 if($attr['queryUnique']) {
361 $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>";
362 }
363 if ($attr['paginationShow'] && ($attr['paginationType'] == 'loadMore')) {
364 $wraper_after .= '<span class="ultp-loadmore-insert-before"></span>';
365 }
366
367 $wraper_after .= '</div>';//ultp-block-items-wrap
368
369 // Load More
370 if ($attr['paginationShow'] && ($attr['paginationType'] == 'loadMore')) {
371 include ULTP_PATH.'blocks/template/loadmore.php';
372 }
373
374 // Navigation
375 if ($attr['paginationShow'] && ($attr['paginationType'] == 'navigation') && ($attr['navPosition'] != 'topRight')) {
376 include ULTP_PATH.'blocks/template/navigation-after.php';
377 }
378
379 // Pagination
380 if ($attr['paginationShow'] && ($attr['paginationType'] == 'pagination')) {
381 include ULTP_PATH.'blocks/template/pagination.php';
382 }
383
384 $wraper_after .= '</div>';
385 $wraper_after .= '</div>';
386
387 wp_reset_query();
388 }else {
389 $wraper_before .= ultimate_post()->get_no_result_found_html( $attr['notFoundMessage'] );
390 }
391
392 return $noAjax ? $post_loop : $wraper_before.$post_loop.$wraper_after;
393 }
394 }