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

425 lines 18.4 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 ?>
200 <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;?>">
201 <a href="#" class="blockspare-readmore">
202 <div class="ajax-loader"></div>
203 <span class="load-btn"><?php echo($attributes['loadMoreText']); ?></span>
204 </a>
205 </div><?php
206 }
207 ?>
208 </section>
209 </div>
210 <?php }
211
212 wp_reset_postdata();
213
214 }
215
216
217 function blockspare_post_image($attributes,$post_id,$cat_class ,$blockName=''){
218
219
220
221 /* Setup the featured image ID */
222 $post_thumb_id = get_post_thumbnail_id($post_id);
223
224
225 if (!empty($attributes['imageSize'])) {
226 $post_thumb_size = $attributes['imageSize'];
227 }
228
229 $content_order = false;
230 if($attributes['contentOrder']=='content-order-1' || $attributes['contentOrder']=='content-order-2'){
231 $content_order =true;
232 }
233 if($blockName == 'full'){
234 $content_order = true;
235 }
236
237 if (!empty($attributes['imageSize'])) {
238 $post_thumb_size = $attributes['imageSize'];
239 }
240
241
242
243
244 if(isset($attributes['enableFeatureImage']) && $attributes['enableFeatureImage'] == 'true'){
245 ?>
246 <figure class="blockspare-posts-block-post-img">
247 <a href="<?php echo esc_url(get_permalink($post_id));?>" rel="bookmark" aria-hidden="true"
248 tabindex="-1">
249 <?php
250 if(has_post_thumbnail($post_id)){
251
252 echo wp_kses_post(wp_get_attachment_image($post_thumb_id, $post_thumb_size, '', ["class" => 'hover-child']));
253 }else{ ?>
254 <div class="bs-no-thumbnail-img"> </div>
255 <?php } ?>
256 </a>
257 <?php if ($attributes['displayPostCategory'] =='true'&& $content_order==true){ ?>
258 <!-- Category -->
259 <div class="<?php echo esc_attr($cat_class);?>">
260 <?php blockspare_get_cat_tax_tags($attributes['taxType'],$post_id);?>
261 </div>
262 <!-- Category -->
263 <?php } ?>
264 </figure>
265 <?php
266 }
267
268
269
270
271 }
272
273 function blockspare_post_content($attributes,$post_id,$cat_class,$blockName='', $className=''){
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 =false;
280 }
281 ?>
282 <div class="blockspare-posts-block-post-content <?php echo esc_attr($className); ?> <?php echo esc_attr($attributes['contentOrder']); ?> <?php echo esc_attr($attributes['titleOnHover'])?>">
283 <div class="blockspare-posts-block-bg-overlay"></div>
284 <!-- blockspare-posts-block-post-grid-header -->
285 <header class="blockspare-posts-block-post-grid-header">
286 <?php if ($attributes['displayPostCategory']=='true' && $content_order ==false) { ?>
287 <!-- Category -->
288 <div class="<?php echo esc_attr($cat_class);?>">
289 <?php blockspare_get_cat_tax_tags($attributes['taxType'],$post_id);?>
290 </div>
291 <!-- Category -->
292 <?php } ?>
293 <!-- blockspare-posts-block-post-grid-title -->
294
295 <h4 class="blockspare-posts-block-post-grid-title">
296 <a href="<?php echo esc_url(get_permalink($post_id)); ?>" class="blockspare-posts-block-title-link"
297 rel="bookmark">
298 <span><?php echo get_the_title(); ?></span>
299 </a>
300 </h4>
301
302 <!-- blockspare-posts-block-post-grid-title -->
303
304 <!-- blockspare-posts-block-post-grid-byline -->
305 <div class="blockspare-posts-block-post-grid-byline">
306 <!-- blockspare-posts-block-post-grid-author -->
307 <?php if (isset($attributes['displayPostAuthor']) && $attributes['displayPostAuthor'] =='true') { ?>
308 <div class="blockspare-posts-block-post-grid-author">
309 <!-- <a class="blockspare-posts-block-text-link" href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID')));?>"
310 itemprop="url" rel="author">
311 <span itemprop="name">
312 <i class="<?php echo esc_attr($attributes['authorIcon']);?>"></i>
313 <?php echo esc_html(get_the_author_meta('display_name', get_the_author_meta('ID')));?>
314 </span>
315 </a> -->
316 <?php
317 $author_id = get_post_field( 'post_author', $post_id );
318 $blockspare_get_multiauthor= new BlocksapreMultiAuthorForFrontend();
319 $blockspare_get_multiauthor->blockspare_front_by_author($post_id,$attributes['authorIcon'],$author_id);
320 ?>
321 </div>
322 <?php } ?>
323 <!-- blockspare-posts-block-post-grid-author -->
324
325 <!-- blockspare-posts-block-post-grid-date -->
326 <?php if(isset($attributes['displayPostDate']) && $attributes['displayPostDate'] =='true') { ?>
327 <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>
328 <?php } ?>
329 <!-- blockspare-posts-block-post-grid-date -->
330
331 <!-- comment_count -->
332 <?php if($attributes['enableComment'] =='true'){ ?>
333 <span class="comment_count"><i class='<?php echo esc_attr($attributes['commentIcon']);?>'></i><?php echo esc_html(get_comments_number($post_id)); ?></span>
334 <?php } ?>
335 <!-- comment_count -->
336 </div>
337 <!-- blockspare-posts-block-post-grid-byline -->
338 </header>
339 <!-- blockspare-posts-block-post-grid-header -->
340
341 <?php
342 $excerpt = blockspare_excerpt ($post_id,$attributes['excerptLength']);
343 $new_excerpt = apply_filters( 'the_excerpt', $excerpt );?>
344 <!-- blockspare-posts-block-post-grid-excerpt -->
345 <?php if ($attributes['displayPostExcerpt']=='true' && $new_excerpt != null) { ?>
346 <div class="blockspare-posts-block-post-grid-excerpt">
347 <!-- blockspare-posts-block-post-grid-excerpt-content -->
348 <?php if (isset($attributes['displayPostExcerpt']) && $attributes['displayPostExcerpt'] =='true') { ?>
349 <div class="blockspare-posts-block-post-grid-excerpt-content">
350 <?php echo wp_kses_post($excerpt); ?>
351 </div>
352 <?php } ?>
353 <!-- blockspare-posts-block-post-grid-excerpt-content -->
354 <!-- blockspare-posts-block-post-grid-more-link -->
355 <?php if (isset($attributes['displayPostLink']) && $attributes['displayPostLink'] =='true') { ?>
356 <p>
357 <a class="blockspare-posts-block-post-grid-more-link blockspare-posts-block-text-link"
358 href="<?php echo esc_url(get_permalink($post_id)); ?>" rel="bookmark">
359 <span><?php echo esc_html($attributes['readMoreText']); ?></span>
360 </a>
361 </p>
362 <?php } ?>
363 <!-- blockspare-posts-block-post-grid-more-link -->
364 </div>
365 <?php } ?>
366 <!-- blockspare-posts-block-post-grid-excerpt -->
367
368 </div>
369 <?php }
370
371
372 function bscheckFontfamily($fontFamily){
373
374 $fonts = '';
375 if($fontFamily!='Default' && $fontFamily !="undefined"){
376 $fonts = 'font-family:'.$fontFamily;
377 }
378 return $fonts;
379
380 }
381
382 function bscheckFontfamilyWeight($fontFamilyWeight){
383
384
385
386 $fontsweight = '';
387 if($fontFamilyWeight!='' && $fontFamilyWeight !="undefined"){
388 $fontsweight = 'font-weight:'.$fontFamilyWeight;
389 }
390 return $fontsweight;
391
392 }
393
394
395 function blockspare_excerpt($post_id,$length=''){
396 $excerpt = get_post_field(
397 'post_excerpt',
398 $post_id,
399 'display'
400 );
401
402 $excerpt =preg_replace( '~^(\s*(?:&nbsp;)?)*~i', '', $excerpt );
403
404 if ( empty( $excerpt ) ) {
405 $excerpt = preg_replace(
406 array(
407 '/\<figcaption>.*\<\/figcaption>/',
408 '/\[caption.*\[\/caption\]/',
409 '`[[^]]*]`'
410 ),
411 '',
412 get_the_content()
413 );
414 }
415
416 // Trim the excerpt if necessary.
417 if ( isset( $length ) ) {
418 $excerpt = wp_trim_words(
419 $excerpt,
420 $length
421 );
422 }
423
424 return $excerpt;
425 }