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

412 lines 18.0 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 $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 blockspare-hover-item '. $contentOrderClass;
160
161 if($layoutClass) {
162 $post_classes .= ' has-background';
163 } else {
164 $post_classes .= ' blockspare-hover-child';
165 }
166
167 $className='';
168
169 if(isset($attributes['full'])){
170 if($attributes['full']== 'blockspare-posts-block-full-layout-6' ){
171 $post_classes .= ' blockspare-hover-child';
172 $className .= 'hover-child';
173 }
174
175 }
176
177
178 /* Add sticky class */
179 if (is_sticky($post_id)) {
180 $post_classes .= ' sticky';
181 } else {
182 $post_classes .= null;
183 }
184 $post_classes .= ' has-background';
185 ?>
186 <div id="<?php echo esc_attr($post_id);?>" class="<?php echo esc_attr($post_classes).' '.$has_img_class; ?>">
187 <?php blockspare_post_image($attributes,$post_id,$category_class,$blockName, $className);?>
188 <?php blockspare_post_content($attributes,$post_id,$category_class,$blockName, $className);?>
189 </div>
190
191 <?php }?>
192
193 </div>
194 <?php
195 if($attributes['enablePagination']=='true' && $grid_query->max_num_pages >1){ ?>
196 <div class="bs_blockspare_loadmore blockspare-readmore-wrapper" data-layout="<?php echo $layoutClass; ?>" 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;?>">
197 <a href="#" class="blockspare-readmore">
198 <div class="ajax-loader"></div>
199 <span class="load-btn"><?php echo($attributes['loadMoreText']); ?></span>
200 </a>
201 </div><?php
202 }
203 ?>
204 </section>
205 </div>
206 <?php }
207
208 wp_reset_postdata();
209
210 }
211
212
213 function blockspare_post_image($attributes,$post_id,$cat_class ,$blockName=''){
214
215
216
217 /* Setup the featured image ID */
218 $post_thumb_id = get_post_thumbnail_id($post_id);
219
220
221 if (!empty($attributes['imageSize'])) {
222 $post_thumb_size = $attributes['imageSize'];
223 }
224
225 $content_order = false;
226 if($attributes['contentOrder']=='content-order-1' || $attributes['contentOrder']=='content-order-2'){
227 $content_order =true;
228 }
229 if($blockName == 'full'){
230 $content_order = true;
231 }
232
233 if (!empty($attributes['imageSize'])) {
234 $post_thumb_size = $attributes['imageSize'];
235 }
236
237
238
239 if(isset($attributes['enableFeatureImage']) && $attributes['enableFeatureImage'] == true){
240 ?>
241 <figure class="blockspare-posts-block-post-img">
242 <a href="<?php echo esc_url(get_permalink($post_id));?>" rel="bookmark" aria-hidden="true"
243 tabindex="-1">
244 <?php
245 if(has_post_thumbnail($post_id)){
246
247 echo wp_kses_post(wp_get_attachment_image($post_thumb_id, $post_thumb_size, '', ["class" => 'hover-child']));
248 }else{?>
249 <div class="bs-no-thumbnail-img"> </div>
250 <?php } ?>
251 </a>
252 <?php if ($attributes['displayPostCategory'] && $content_order==true){?>
253 <!-- Category -->
254 <div class="<?php echo esc_attr($cat_class);?>">
255 <?php blockspare_get_cat_tax_tags($attributes['taxType'],$post_id);?>
256 </div>
257 <!-- Category -->
258 <?php }?>
259 </figure>
260 <?php
261 }
262
263
264
265
266 }
267
268 function blockspare_post_content($attributes,$post_id,$cat_class,$blockName='', $className=''){
269 $content_order = false;
270 if($attributes['contentOrder']=='content-order-1' || $attributes['contentOrder']=='content-order-2'){
271 $content_order =true;
272 }
273 if($blockName =='full'){
274 $content_order =false;
275 }
276 ?>
277 <div class="blockspare-posts-block-post-content <?php echo esc_attr($className); ?> <?php echo esc_attr($attributes['contentOrder']); ?> <?php echo esc_attr($attributes['titleOnHover'])?>">
278 <div class="blockspare-posts-block-bg-overlay"></div>
279 <!-- blockspare-posts-block-post-grid-header -->
280 <header class="blockspare-posts-block-post-grid-header">
281 <?php if ($attributes['displayPostCategory'] && $content_order ==false) {?>
282 <!-- Category -->
283 <div class="<?php echo esc_attr($cat_class);?>">
284 <?php blockspare_get_cat_tax_tags($attributes['taxType'],$post_id);?>
285 </div>
286 <!-- Category -->
287 <?php }?>
288 <!-- blockspare-posts-block-post-grid-title -->
289
290 <h4 class="blockspare-posts-block-post-grid-title">
291 <a href="<?php echo esc_url(get_permalink($post_id)); ?>" class="blockspare-posts-block-title-link"
292 rel="bookmark">
293 <span><?php echo get_the_title(); ?></span>
294 </a>
295 </h4>
296
297 <!-- blockspare-posts-block-post-grid-title -->
298
299 <!-- blockspare-posts-block-post-grid-byline -->
300 <div class="blockspare-posts-block-post-grid-byline">
301 <!-- blockspare-posts-block-post-grid-author -->
302 <?php if (isset($attributes['displayPostAuthor']) && $attributes['displayPostAuthor'] =='true') {?>
303 <div class="blockspare-posts-block-post-grid-author">
304 <!-- <a class="blockspare-posts-block-text-link" href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID')));?>"
305 itemprop="url" rel="author">
306 <span itemprop="name">
307 <i class="<?php echo esc_attr($attributes['authorIcon']);?>"></i>
308 <?php echo esc_html(get_the_author_meta('display_name', get_the_author_meta('ID')));?>
309 </span>
310 </a> -->
311 <?php
312 $author_id = get_post_field( 'post_author', $post_id );
313 $blockspare_get_multiauthor= new BlocksapreMultiAuthorForFrontend();
314 $blockspare_get_multiauthor->blockspare_front_by_author($post_id,$attributes['authorIcon'],$author_id);
315 ?>
316 </div>
317 <?php }?>
318 <!-- blockspare-posts-block-post-grid-author -->
319
320 <!-- blockspare-posts-block-post-grid-date -->
321 <?php if(isset($attributes['displayPostDate']) && $attributes['displayPostDate'] =='true') {?>
322 <time datetime="<?php echo esc_attr(get_the_date('c', $post_id));?>"
323 class="blockspare-posts-block-post-grid-date" itemprop="datePublished">
324 <i class="<?php echo esc_attr($attributes['dateIcon']);?>"></i>
325 <?php echo esc_html(get_the_date('', $post_id));?>
326 </time>
327 <?php }?>
328 <!-- blockspare-posts-block-post-grid-date -->
329
330 <!-- comment_count -->
331 <?php if($attributes['enableComment'] =='true'){?>
332 <span class="comment_count">
333 <i class='<?php echo esc_attr($attributes['commentIcon']);?>'></i>
334 <?php echo esc_html(get_comments_number($post_id)); ?>
335 </span>
336 <?php }?>
337 <!-- comment_count -->
338 </div>
339 <!-- blockspare-posts-block-post-grid-byline -->
340 </header>
341 <!-- blockspare-posts-block-post-grid-header -->
342
343 <?php
344 $excerpt = blockspare_excerpt ($post_id,$attributes['excerptLength']);
345 $new_excerpt = apply_filters( 'the_excerpt', $excerpt );?>
346 <!-- blockspare-posts-block-post-grid-excerpt -->
347 <?php if ($attributes['displayPostExcerpt'] && $new_excerpt != null) { ?>
348 <div class="blockspare-posts-block-post-grid-excerpt">
349 <!-- blockspare-posts-block-post-grid-excerpt-content -->
350 <?php if (isset($attributes['displayPostExcerpt']) && $attributes['displayPostExcerpt'] =='true') { ?>
351 <div class="blockspare-posts-block-post-grid-excerpt-content">
352 <?php echo wp_kses_post($excerpt); ?>
353 </div>
354 <?php }?>
355 <!-- blockspare-posts-block-post-grid-excerpt-content -->
356 <!-- blockspare-posts-block-post-grid-more-link -->
357 <?php if (isset($attributes['displayPostLink']) && $attributes['displayPostLink'] =='true') { ?>
358 <p>
359 <a class="blockspare-posts-block-post-grid-more-link blockspare-posts-block-text-link"
360 href="<?php echo esc_url(get_permalink($post_id)); ?>" rel="bookmark">
361 <span><?php echo esc_html($attributes['readMoreText']); ?></span>
362 </a>
363 </p>
364 <?php }?>
365 <!-- blockspare-posts-block-post-grid-more-link -->
366 </div>
367 <?php }?>
368 <!-- blockspare-posts-block-post-grid-excerpt -->
369
370 </div>
371 <?php }
372
373
374 function bscheckFontfamily($fontFamily){
375
376 $fonts = '';
377 if($fontFamily!='Default' && $fontFamily !="undefined"){
378 $fonts = 'font-family:'.$fontFamily;
379 }
380 return $fonts;
381
382 }
383
384
385 function blockspare_excerpt($post_id,$length=''){
386 $excerpt = get_post_field(
387 'post_excerpt',
388 $post_id,
389 'display'
390 );
391
392 if ( empty( $excerpt ) ) {
393 $excerpt = preg_replace(
394 array(
395 '/\<figcaption>.*\<\/figcaption>/',
396 '/\[caption.*\[\/caption\]/',
397 ),
398 '',
399 get_the_content()
400 );
401 }
402
403 // Trim the excerpt if necessary.
404 if ( isset( $length ) ) {
405 $excerpt = wp_trim_words(
406 $excerpt,
407 $length
408 );
409 }
410
411 return $excerpt;
412 }