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

395 lines 17.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=''){
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 $animation_class = '';
96 if( $attributes['animation']){
97 $animation_class='blockspare-block-animation';
98 }
99
100
101
102 $list_layout_class = $design;
103 $listgridClass = $blockclass . " " ;
104
105 if($blockName=='' ){
106 $listgridClass .= "column-" . $attributes['columns'];
107 }
108
109
110 /* Layout orientation class */
111 $grid_class = $blockuniqueclass . ' blockspare-posts-block-latest-post-wrap ' . $listgridClass . ' ' . $list_layout_class.' '.$animation_class ;
112
113 $category_class = 'blockspare-posts-block-post-category';
114
115 if($attributes['categoryLayoutOption'] =='none'){
116 $category_class .= ' has-no-category-style';
117 }?>
118 <div class="<?php echo esc_attr($class);?>">
119 <section class="blockspare-posts-block-post-wrap">
120 <div class="<?php echo esc_attr($grid_class);?>" blockspare-animation=<?php echo esc_attr( $attributes['animation'] )?>>
121 <?php while ($grid_query->have_posts()) {
122 $grid_query->the_post();
123
124 /* Setup the post ID */
125 $post_id = get_the_ID();
126
127 /* Setup the featured image ID */
128 $post_thumb_id = get_post_thumbnail_id($post_id);
129
130 $has_img_class = '';
131
132 if (!$post_thumb_id) {
133 $has_img_class = "post-has-no-image";
134 }
135
136
137
138
139 // if(isset($attributes['full'])){
140 // if($attributes['full']== 'blockspare-posts-block-full-layout-4' ){
141 // $attributes['enableEqualHeight'] = false;
142 // }
143
144 // }
145
146
147 if($attributes['enableEqualHeight']){
148 $has_img_class .=' bs-has-equal-height';
149 }
150 $contentOrderClass ='';
151 if($attributes['contentOrder']=='content-order-1'){
152 $contentOrderClass .= 'contentorderone';
153 }
154 if( $attributes['contentOrder']=='content-order-2'){
155 $contentOrderClass .= 'contentordertwo';
156 }
157
158 /* Setup the post classes */
159 $post_classes = 'blockspare-posts-block-post-single '. $contentOrderClass;
160
161 /* Add sticky class */
162 if (is_sticky($post_id)) {
163 $post_classes .= ' sticky';
164 } else {
165 $post_classes .= null;
166 }
167 $post_classes .= ' has-background';
168 ?>
169 <div id="<?php echo esc_attr($post_id);?>" class="<?php echo esc_attr($post_classes).' '.$has_img_class; ?>">
170 <?php blockspare_post_image($attributes,$post_id,$category_class,$blockName);?>
171 <?php blockspare_post_content($attributes,$post_id,$category_class,$blockName);?>
172 </div>
173
174 <?php }?>
175
176 </div>
177 <?php
178 if($attributes['enablePagination']=='true' && $grid_query->max_num_pages >1){ ?>
179 <div class="bs_blockspare_loadmore blockspare-readmore-wrapper" block-name="tile" data-page='2' blockspare-att=<?php echo "'" . wp_kses_post(wp_json_encode($attributes))."'";?> max-paged="<?php echo $grid_query->max_num_pages;?>">
180 <a href="#" class="blockspare-readmore">
181 <div class="ajax-loader"></div>
182 <span class="load-btn"><?php echo($attributes['loadMoreText']); ?></span>
183 </a>
184 </div><?php
185 }
186 ?>
187 </section>
188 </div>
189 <?php }
190
191 wp_reset_postdata();
192
193 }
194
195
196 function blockspare_post_image($attributes,$post_id,$cat_class ,$blockName=''){
197
198
199
200 /* Setup the featured image ID */
201 $post_thumb_id = get_post_thumbnail_id($post_id);
202
203
204 if (!empty($attributes['imageSize'])) {
205 $post_thumb_size = $attributes['imageSize'];
206 }
207
208 $content_order = false;
209 if($attributes['contentOrder']=='content-order-1' || $attributes['contentOrder']=='content-order-2'){
210 $content_order =true;
211 }
212 if($blockName == 'full'){
213 $content_order = true;
214 }
215
216 if (!empty($attributes['imageSize'])) {
217 $post_thumb_size = $attributes['imageSize'];
218 }
219
220
221
222 if(isset($attributes['enableFeatureImage']) && $attributes['enableFeatureImage'] == true){
223 ?>
224 <figure class="blockspare-posts-block-post-img">
225 <a href="<?php echo esc_url(get_permalink($post_id));?>" rel="bookmark" aria-hidden="true"
226 tabindex="-1">
227 <?php
228 if(has_post_thumbnail($post_id)){
229
230 echo wp_kses_post(wp_get_attachment_image($post_thumb_id, $post_thumb_size));
231 }else{?>
232 <div class="bs-no-thumbnail-img"> </div>
233 <?php } ?>
234 </a>
235 <?php if ($attributes['displayPostCategory'] && $content_order==true){?>
236 <!-- Category -->
237 <div class="<?php echo esc_attr($cat_class);?>">
238 <?php blockspare_get_cat_tax_tags($attributes['taxType'],$post_id);?>
239 </div>
240 <!-- Category -->
241 <?php }?>
242 </figure>
243 <?php
244 }
245
246
247
248
249 }
250
251 function blockspare_post_content($attributes,$post_id,$cat_class,$blockName=''){
252 $content_order = false;
253 if($attributes['contentOrder']=='content-order-1' || $attributes['contentOrder']=='content-order-2'){
254 $content_order =true;
255 }
256 if($blockName =='full'){
257 $content_order =false;
258 }
259 ?>
260 <div class="blockspare-posts-block-post-content <?php echo esc_attr($attributes['contentOrder']); ?> <?php echo esc_attr($attributes['titleOnHover'])?>">
261 <div class="blockspare-posts-block-bg-overlay"></div>
262 <!-- blockspare-posts-block-post-grid-header -->
263 <header class="blockspare-posts-block-post-grid-header">
264 <?php if ($attributes['displayPostCategory'] && $content_order ==false) {?>
265 <!-- Category -->
266 <div class="<?php echo esc_attr($cat_class);?>">
267 <?php blockspare_get_cat_tax_tags($attributes['taxType'],$post_id);?>
268 </div>
269 <!-- Category -->
270 <?php }?>
271 <!-- blockspare-posts-block-post-grid-title -->
272
273 <h4 class="blockspare-posts-block-post-grid-title">
274 <a href="<?php echo esc_url(get_permalink($post_id)); ?>" class="blockspare-posts-block-title-link"
275 rel="bookmark">
276 <span><?php echo get_the_title(); ?></span>
277 </a>
278 </h4>
279
280 <!-- blockspare-posts-block-post-grid-title -->
281
282 <!-- blockspare-posts-block-post-grid-byline -->
283 <div class="blockspare-posts-block-post-grid-byline">
284 <!-- blockspare-posts-block-post-grid-author -->
285 <?php if (isset($attributes['displayPostAuthor']) && $attributes['displayPostAuthor'] =='true') {?>
286 <div class="blockspare-posts-block-post-grid-author">
287 <!-- <a class="blockspare-posts-block-text-link" href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID')));?>"
288 itemprop="url" rel="author">
289 <span itemprop="name">
290 <i class="<?php echo esc_attr($attributes['authorIcon']);?>"></i>
291 <?php echo esc_html(get_the_author_meta('display_name', get_the_author_meta('ID')));?>
292 </span>
293 </a> -->
294 <?php
295 $author_id = get_post_field( 'post_author', $post_id );
296 $blockspare_get_multiauthor= new BlocksapreMultiAuthorForFrontend();
297 $blockspare_get_multiauthor->blockspare_front_by_author($post_id,$attributes['authorIcon'],$author_id);
298 ?>
299 </div>
300 <?php }?>
301 <!-- blockspare-posts-block-post-grid-author -->
302
303 <!-- blockspare-posts-block-post-grid-date -->
304 <?php if(isset($attributes['displayPostDate']) && $attributes['displayPostDate'] =='true') {?>
305 <time datetime="<?php echo esc_attr(get_the_date('c', $post_id));?>"
306 class="blockspare-posts-block-post-grid-date" itemprop="datePublished">
307 <i class="<?php echo esc_attr($attributes['dateIcon']);?>"></i>
308 <?php echo esc_html(get_the_date('', $post_id));?>
309 </time>
310 <?php }?>
311 <!-- blockspare-posts-block-post-grid-date -->
312
313 <!-- comment_count -->
314 <?php if($attributes['enableComment'] =='true'){?>
315 <span class="comment_count">
316 <i class='<?php echo esc_attr($attributes['commentIcon']);?>'></i>
317 <?php echo esc_html(get_comments_number($post_id)); ?>
318 </span>
319 <?php }?>
320 <!-- comment_count -->
321 </div>
322 <!-- blockspare-posts-block-post-grid-byline -->
323 </header>
324 <!-- blockspare-posts-block-post-grid-header -->
325
326 <?php
327 $excerpt = blockspare_excerpt ($post_id,$attributes['excerptLength']);
328 $new_excerpt = apply_filters( 'the_excerpt', $excerpt );?>
329 <!-- blockspare-posts-block-post-grid-excerpt -->
330 <?php if ($attributes['displayPostExcerpt'] && $new_excerpt != null || isset($attributes['displayPostLink'])) { ?>
331 <div class="blockspare-posts-block-post-grid-excerpt">
332 <!-- blockspare-posts-block-post-grid-excerpt-content -->
333 <?php if (isset($attributes['displayPostExcerpt']) && $attributes['displayPostExcerpt'] =='true') { ?>
334 <div class="blockspare-posts-block-post-grid-excerpt-content">
335 <?php echo wp_kses_post($excerpt); ?>
336 </div>
337 <?php }?>
338 <!-- blockspare-posts-block-post-grid-excerpt-content -->
339 <!-- blockspare-posts-block-post-grid-more-link -->
340 <?php if (isset($attributes['displayPostLink']) && $attributes['displayPostLink'] =='true') { ?>
341 <p>
342 <a class="blockspare-posts-block-post-grid-more-link blockspare-posts-block-text-link"
343 href="<?php echo esc_url(get_permalink($post_id)); ?>" rel="bookmark">
344 <span><?php echo esc_html($attributes['readMoreText']); ?></span>
345 </a>
346 </p>
347 <?php }?>
348 <!-- blockspare-posts-block-post-grid-more-link -->
349 </div>
350 <?php }?>
351 <!-- blockspare-posts-block-post-grid-excerpt -->
352
353 </div>
354 <?php }
355
356
357 function bscheckFontfamily($fontFamily){
358
359 $fonts = '';
360 if($fontFamily!='Default' && $fontFamily !="undefined"){
361 $fonts = 'font-family:'.$fontFamily;
362 }
363 return $fonts;
364
365 }
366
367
368 function blockspare_excerpt($post_id,$length=''){
369 $excerpt = get_post_field(
370 'post_excerpt',
371 $post_id,
372 'display'
373 );
374
375 if ( empty( $excerpt ) ) {
376 $excerpt = preg_replace(
377 array(
378 '/\<figcaption>.*\<\/figcaption>/',
379 '/\[caption.*\[\/caption\]/',
380 ),
381 '',
382 get_the_content()
383 );
384 }
385
386 // Trim the excerpt if necessary.
387 if ( isset( $length ) ) {
388 $excerpt = wp_trim_words(
389 $excerpt,
390 $length
391 );
392 }
393
394 return $excerpt;
395 }