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

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