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

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