PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / 3.1.4
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites v3.1.4
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.4, at inc/block-posts-config/class-bs-post.php

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