PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / 3.1.1
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites v3.1.1
4.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.1.2 2.5.0 2.5.3 2.6.1 All 38 releases
blockspare / inc / block-posts-config / class-bs-post.php

class-bs-post.php in BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites 3.1.1, at inc/block-posts-config/class-bs-post.php

436 lines 19.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly.
4 }
5
6
7 function blockspare_post_query($attributes){
8
9 $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
10
11 if ( isset( $attributes['categories'] ) && ! empty( $attributes['categories'] ) && is_array( $attributes['categories'] ) ) {
12 $categories = array();
13 $i = 1;
14 foreach ( $attributes['categories'] as $key => $value ) {
15 $categories[] = $value['value'];
16 }
17 } else {
18 $categories = array();
19 }
20
21 if ( isset( $attributes['tags'] ) && ! empty( $attributes['tags'] ) && is_array( $attributes['tags'] ) ) {
22 $tags = array();
23 $i = 1;
24 foreach ( $attributes['tags'] as $key => $value ) {
25 $tags[] = $value['value'];
26 }
27 } else {
28 $tags = array();
29 }
30
31 /* Setup the query */
32 $currentID = get_the_ID();
33 $query_args = array(
34 'posts_per_page' => $attributes['postsToShow'],
35 'post_status' => 'publish',
36 'order' => $attributes['order'],
37 'orderby' => $attributes['orderBy'],
38 'offset' => ($attributes['enablePagination']=='true')?'':$attributes['offset'],
39 'post_type' => $attributes['postType'],
40 'ignore_sticky_posts' => 1,
41 'paged'=>$paged,
42 'post__not_in'=>array($currentID)
43 );
44
45 if($attributes['taxType'] =='category'){
46 $query_args['category__in'] =$categories;
47
48 }
49 if($attributes['taxType'] =='post_tag'){
50 $query_args['tag__in'] =$tags;
51
52 }
53
54
55 if($attributes['taxType'] !='category' && $attributes['taxType'] != 'post_tag'){
56
57 $tax_type = $attributes['taxType'];
58 if ( $tax_type ) {
59 if(!empty($categories)){
60 $query_args['tax_query'][] = array(
61 'taxonomy' => ( isset( $tax_type ) ) ? $tax_type : 'category',
62 'field' => 'id',
63 'terms' => $categories,
64 'operator' => 'IN' ,
65 );
66 } }
67 }
68 /* Setup the query */
69 $grid_query = new WP_Query($query_args);
70 return $grid_query;
71 }
72
73 function blockspare_query_loop_and_wrapper($attributes,$blockclass ='',$design='',$blockName='', $layoutClass=false){
74 $unq_class = mt_rand(100000,999999);
75 $blockuniqueclass = '';
76
77 if(!empty($attributes['uniqueClass'])){
78 $blockuniqueclass = $attributes['uniqueClass'];
79 }else{
80 $blockuniqueclass = 'blockspare-posts-block-list-'.$unq_class;
81 }
82
83 $grid_query = blockspare_post_query($attributes);
84 if ($grid_query->have_posts()) {
85 $alignclass = blockspare_checkalignment($attributes['align']);
86
87
88 /* Build the block classes */
89 $class = "wp-block-blockspare-posts-block-blockspare-posts-block-latest-posts align".$alignclass." ".$attributes['blockHoverEffect'] ;
90
91 if (isset($attributes['className'])) {
92 $class .= ' ' . $attributes['className'];
93 }
94
95 if( $attributes['animation']){
96 $class .=' blockspare-block-animation';
97 }
98
99
100
101 $list_layout_class = $design;
102 $listgridClass = $blockclass . " " ;
103
104 // if($blockName=='' ){
105 // $listgridClass .= "column-" . $attributes['columns'];
106 // }
107
108
109 /* Layout orientation class */
110 $grid_class = 'blockspare-posts-block-latest-post-wrap ' . $listgridClass . ' ' . $list_layout_class ;
111 $class .= ' ' . $blockuniqueclass;
112 $category_class = 'blockspare-posts-block-post-category';
113
114 if($attributes['categoryLayoutOption'] =='none'){
115 $category_class .= ' has-no-category-style';
116 } ?>
117 <!-- <div class="<?php echo esc_attr($class);?>" blockspare-animation=<?php echo esc_attr( $attributes['animation'] )?>> -->
118 <section class="blockspare-posts-block-post-wrap">
119 <div class="<?php echo esc_attr($grid_class);?>" >
120 <?php while ($grid_query->have_posts()) {
121 $grid_query->the_post();
122
123 /* Setup the post ID */
124 $post_id = get_the_ID();
125
126 /* Setup the featured image ID */
127 $post_thumb_id = get_post_thumbnail_id($post_id);
128
129 $has_img_class = '';
130
131 if (!$post_thumb_id) {
132 $has_img_class = "post-has-no-image";
133 }
134
135
136
137
138 // if(isset($attributes['full'])){
139 // if($attributes['full']== 'blockspare-posts-block-full-layout-4' ){
140 // $attributes['enableEqualHeight'] = false;
141 // }
142
143 // }
144
145
146 if($attributes['enableEqualHeight']){
147 $has_img_class .=' bs-has-equal-height';
148 }
149 $contentOrderClass ='';
150 if($attributes['contentOrder']=='content-order-1'){
151 $contentOrderClass .= 'contentorderone';
152 }
153 if( $attributes['contentOrder']=='content-order-2'){
154 $contentOrderClass .= 'contentordertwo';
155 }
156
157 /* Setup the post classes */
158 $post_classes = 'blockspare-posts-block-post-single blockspare-hover-item '. $contentOrderClass;
159
160 if($layoutClass) {
161 $post_classes .= ' has-background';
162 } else {
163 $post_classes .= ' blockspare-hover-child';
164 }
165
166 $className='';
167
168 if(isset($attributes['full'])){
169 if($attributes['full']== 'blockspare-posts-block-full-layout-6' ){
170 $post_classes .= ' blockspare-hover-child';
171 $className .= 'hover-child';
172 }
173
174 }
175
176
177 /* Add sticky class */
178 if (is_sticky($post_id)) {
179 $post_classes .= ' sticky';
180 } else {
181 $post_classes .= null;
182 }
183 $post_classes .= ' has-background';
184 ?>
185 <div id="<?php echo esc_attr($post_id);?>" class="<?php echo esc_attr($post_classes).' '.$has_img_class; ?>">
186 <?php blockspare_post_image($attributes,$post_id,$category_class,$blockName, $className);?>
187 <?php blockspare_post_content($attributes,$post_id,$category_class,$blockName, $className);?>
188 </div>
189
190 <?php } ?>
191
192 </div>
193 <?php
194 if($attributes['enablePagination']=='true' && $grid_query->max_num_pages >1){
195 $loadmore_class = '';
196 if($attributes['loadMoreStyle']){
197 $loadmore_class = $attributes['loadMoreStyle'];
198 }
199 if($attributes['loadMoreAlignment']){
200 $loadmore_class .= ' bs_blockspare_loadmore_' . $attributes['loadMoreAlignment'];
201 }
202 ?>
203 <div class="bs_blockspare_loadmore blockspare-readmore-wrapper <?php echo esc_attr($loadmore_class);?>" data-layout="<?php echo $layoutClass; ?>" block-name="<?php echo esc_attr($blockName)?>" data-page='2' blockspare-att=<?php echo "'" . wp_kses_post(wp_json_encode($attributes))."'";?> max-paged="<?php echo $grid_query->max_num_pages;?>">
204 <a href="#" class="blockspare-readmore">
205 <div class="load-btn "><?php echo($attributes['loadMoreText']); ?><span class="ajax-loader"></span></div>
206 </a>
207 </div><?php
208 }
209 ?>
210 </section>
211 <!-- </div> -->
212 <?php }
213
214 wp_reset_postdata();
215
216 }
217
218
219 function blockspare_post_image($attributes,$post_id,$cat_class ,$blockName=''){
220
221
222
223 /* Setup the featured image ID */
224 $post_thumb_id = get_post_thumbnail_id($post_id);
225
226
227 if (!empty($attributes['imageSize'])) {
228 $post_thumb_size = $attributes['imageSize'];
229 }
230
231 $content_order = false;
232 if($attributes['contentOrder']=='content-order-1' || $attributes['contentOrder']=='content-order-2'){
233 $content_order =true;
234 }
235 if($blockName == 'full'){
236 $content_order = true;
237 }
238
239 if (!empty($attributes['imageSize'])) {
240 $post_thumb_size = $attributes['imageSize'];
241 }
242
243
244
245
246 if(isset($attributes['enableFeatureImage']) && $attributes['enableFeatureImage'] == 'true'){
247 ?>
248 <figure class="blockspare-posts-block-post-img hover-child">
249 <a href="<?php echo esc_url(get_permalink($post_id));?>" rel="bookmark" aria-hidden="true"
250 tabindex="-1">
251 <?php
252 if(has_post_thumbnail($post_id)){
253
254 echo wp_kses_post(wp_get_attachment_image($post_thumb_id, $post_thumb_size));
255 }else{ ?>
256 <div class="bs-no-thumbnail-img"> </div>
257 <?php } ?>
258 </a>
259 <?php if ($attributes['displayPostCategory'] =='true'&& $content_order==true){ ?>
260 <!-- Category -->
261 <div class="<?php echo esc_attr($cat_class);?>">
262 <?php blockspare_get_cat_tax_tags($attributes['taxType'],$post_id);?>
263 </div>
264 <!-- Category -->
265 <?php } ?>
266 </figure>
267 <?php
268 }
269
270
271
272
273 }
274
275 function blockspare_post_content($attributes,$post_id,$cat_class,$blockName='', $className=''){
276 $content_order = false;
277 if($attributes['contentOrder']=='content-order-1' || $attributes['contentOrder']=='content-order-2'){
278 $content_order =true;
279 }
280 if($blockName =='full'){
281 $content_order =false;
282 }
283 ?>
284 <div class="blockspare-posts-block-post-content <?php echo esc_attr($className); ?> <?php echo esc_attr($attributes['contentOrder']); ?> <?php echo esc_attr($attributes['titleOnHover'])?>">
285 <div class="blockspare-posts-block-bg-overlay"></div>
286 <!-- blockspare-posts-block-post-grid-header -->
287 <header class="blockspare-posts-block-post-grid-header">
288 <!--display category when feature image is disable -->
289 <?php if ($attributes['displayPostCategory']=='true' && $attributes['enableFeatureImage']!='true') {?>
290 <!-- Category -->
291 <div class="<?php echo esc_attr($cat_class);?>">
292 <?php blockspare_get_cat_tax_tags($attributes['taxType'],$post_id,$attributes['postType']);?>
293 </div>
294 <!-- Category -->
295 <?php }?>
296 <!--display category when feature image is enable-->
297 <?php if ($attributes['displayPostCategory']=='true' && $attributes['enableFeatureImage']=='true' && $content_order ==false) {?>
298 <!-- Category -->
299 <div class="<?php echo esc_attr($cat_class);?>">
300 <?php blockspare_get_cat_tax_tags($attributes['taxType'],$post_id,$attributes['postType']);?>
301 </div>
302 <!-- Category -->
303 <?php }?>
304 <!-- blockspare-posts-block-post-grid-title -->
305
306 <h4 class="blockspare-posts-block-post-grid-title">
307 <a href="<?php echo esc_url(get_permalink($post_id)); ?>" class="blockspare-posts-block-title-link"
308 rel="bookmark">
309 <span><?php echo get_the_title(); ?></span>
310 </a>
311 </h4>
312
313 <!-- blockspare-posts-block-post-grid-title -->
314
315 <!-- blockspare-posts-block-post-grid-byline -->
316 <div class="blockspare-posts-block-post-grid-byline">
317 <!-- blockspare-posts-block-post-grid-author -->
318 <?php if (isset($attributes['displayPostAuthor']) && $attributes['displayPostAuthor'] =='true') { ?>
319 <div class="blockspare-posts-block-post-grid-author">
320 <!-- <a class="blockspare-posts-block-text-link" href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID')));?>"
321 itemprop="url" rel="author">
322 <span itemprop="name">
323 <i class="<?php echo esc_attr($attributes['authorIcon']);?>"></i>
324 <?php echo esc_html(get_the_author_meta('display_name', get_the_author_meta('ID')));?>
325 </span>
326 </a> -->
327 <?php
328 $author_id = get_post_field( 'post_author', $post_id );
329 $blockspare_get_multiauthor= new BlocksapreMultiAuthorForFrontend();
330 $blockspare_get_multiauthor->blockspare_front_by_author($post_id,$attributes['authorIcon'],$author_id);
331 ?>
332 </div>
333 <?php } ?>
334 <!-- blockspare-posts-block-post-grid-author -->
335
336 <!-- blockspare-posts-block-post-grid-date -->
337 <?php if(isset($attributes['displayPostDate']) && $attributes['displayPostDate'] =='true') { ?>
338 <time datetime="<?php echo esc_attr(get_the_date('c', $post_id));?>" class="blockspare-posts-block-post-grid-date" itemprop="datePublished"><i class="<?php echo esc_attr($attributes['dateIcon']);?>"></i><?php echo esc_html(get_the_date('', $post_id));?></time>
339 <?php } ?>
340 <!-- blockspare-posts-block-post-grid-date -->
341
342 <!-- comment_count -->
343 <?php if($attributes['enableComment'] =='true'){ ?>
344 <span class="comment_count"><i class='<?php echo esc_attr($attributes['commentIcon']);?>'></i><?php echo esc_html(get_comments_number($post_id)); ?></span>
345 <?php } ?>
346 <!-- comment_count -->
347 </div>
348 <!-- blockspare-posts-block-post-grid-byline -->
349 </header>
350 <!-- blockspare-posts-block-post-grid-header -->
351
352 <?php
353 $excerpt = blockspare_excerpt ($post_id,$attributes['excerptLength']);
354 $new_excerpt = apply_filters( 'the_excerpt', $excerpt );?>
355 <!-- blockspare-posts-block-post-grid-excerpt -->
356 <?php if ($attributes['displayPostExcerpt']=='true' && $new_excerpt != null) { ?>
357 <div class="blockspare-posts-block-post-grid-excerpt">
358 <!-- blockspare-posts-block-post-grid-excerpt-content -->
359 <?php if (isset($attributes['displayPostExcerpt']) && $attributes['displayPostExcerpt'] =='true') { ?>
360 <div class="blockspare-posts-block-post-grid-excerpt-content">
361 <?php echo wp_kses_post($excerpt); ?>
362 </div>
363 <?php } ?>
364 <!-- blockspare-posts-block-post-grid-excerpt-content -->
365 <!-- blockspare-posts-block-post-grid-more-link -->
366 <?php if (isset($attributes['displayPostLink']) && $attributes['displayPostLink'] =='true') { ?>
367 <p>
368 <a class="blockspare-posts-block-post-grid-more-link blockspare-posts-block-text-link"
369 href="<?php echo esc_url(get_permalink($post_id)); ?>" rel="bookmark">
370 <span><?php echo esc_html($attributes['readMoreText']); ?></span>
371 </a>
372 </p>
373 <?php } ?>
374 <!-- blockspare-posts-block-post-grid-more-link -->
375 </div>
376 <?php } ?>
377 <!-- blockspare-posts-block-post-grid-excerpt -->
378
379 </div>
380 <?php }
381
382
383 function bscheckFontfamily($fontFamily){
384
385 $fonts = '';
386 if($fontFamily!='Default' && $fontFamily !="undefined"){
387 $fonts = 'font-family:'.$fontFamily;
388 }
389 return $fonts;
390
391 }
392
393 function bscheckFontfamilyWeight($fontFamilyWeight){
394
395
396
397 $fontsweight = '';
398 if($fontFamilyWeight!='' && $fontFamilyWeight !="undefined"){
399 $fontsweight = 'font-weight:'.$fontFamilyWeight;
400 }
401 return $fontsweight;
402
403 }
404
405
406 function blockspare_excerpt($post_id,$length=''){
407 $excerpt = get_post_field(
408 'post_excerpt',
409 $post_id,
410 'display'
411 );
412
413 $excerpt =preg_replace( '~^(\s*(?:&nbsp;)?)*~i', '', $excerpt );
414
415 if ( empty( $excerpt ) ) {
416 $excerpt = preg_replace(
417 array(
418 '/\<figcaption>.*\<\/figcaption>/',
419 '/\[caption.*\[\/caption\]/',
420 '`[[^]]*]`'
421 ),
422 '',
423 get_the_content()
424 );
425 }
426
427 // Trim the excerpt if necessary.
428 if ( isset( $length ) ) {
429 $excerpt = wp_trim_words(
430 $excerpt,
431 $length
432 );
433 }
434
435 return $excerpt;
436 }