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

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

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