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 / src / 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 src/inc/block-posts-config/class-bs-post.php

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