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 / latest-post-block / posts-list / index.php

index.php in BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites 3.3.3, at inc/latest-post-block/posts-list/index.php

485 lines 19.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!function_exists('blockspare_render_block_core_latest_posts_list')) {
3 function blockspare_render_block_core_latest_posts_list($attributes)
4 {
5
6 if ($attributes['enablePagination']) {
7 wp_enqueue_script('blockspare-pagination-js');
8 }
9 ob_start();
10 $unq_class = mt_rand(100000, 999999);
11 $blockuniqueclass = '';
12
13 if ($attributes['enableTwoColumn']) {
14 $design = $attributes['design'] . ' list-col-2';
15 } else {
16 $design = $attributes['design'] . ' ' . $attributes['columns'];
17 }
18
19 if (!empty($attributes['uniqueClass'])) {
20 $blockuniqueclass = $attributes['uniqueClass'];
21 } else {
22 $blockuniqueclass = 'blockspare-posts-block-list-' . $unq_class;
23 }
24 $hasimgclass = 'featured-img-not-enabaled';
25 if ($attributes['enableFeatureImage'] == true) {
26 $hasimgclass = $attributes['imageSize'] . '-' . $attributes['ImageUnit'];
27
28 }
29 $blockName = 'post-list';
30 $layoutClass = false;
31 if ($attributes['design'] != 'blockspare-posts-block-list-layout-4' && $attributes['design'] != 'blockspare-posts-block-list-layout-5' && $attributes['design'] != 'blockspare-posts-block-list-layout-6') {
32 $layoutClass = true;
33 }
34
35 $block_class = 'blockspare-posts-block-is-list ' . $hasimgclass . ' has-gutter-' . $attributes['gutterSpace'];
36 if ($attributes['displayPostExcerpt'] == true) {
37 $block_class .= ' blockspare-post-expert-enabled';
38 }
39 if ($attributes['imageSize'] == 'thumbnail') {
40 $block_class .= ' blockspare-has-thumbnail-image';
41 }
42
43 $alignclass = blockspare_checkalignment($attributes['align']);
44 $class = "wp-block-blockspare-posts-block-blockspare-posts-block-latest-posts align" . $alignclass . " " . $attributes['blockHoverEffect'] . " " . $attributes['imageHoverEffect'];
45
46 if (isset($attributes['className'])) {
47 $class .= ' ' . $attributes['className'];
48 }
49
50 if ($attributes['animation']) {
51 $class .= ' blockspare-block-animation';
52 }
53 $class .= ' ' . $blockuniqueclass;?>
54 <div class="<?php echo esc_attr($class); ?>" blockspare-animation="<?php echo esc_attr($attributes['animation']); ?>">
55 <?php
56 echo blockspare_post_style_css($blockuniqueclass, $attributes);
57 blockspare_query_loop_and_wrapper($attributes, $block_class, $design, $blockName, $layoutClass);
58 ?>
59 </div>
60 <?php
61
62 return ob_get_clean();
63
64 }
65 }
66
67 /**
68 * Registers the post grid block on server
69 */
70 if (!function_exists('blockspare_register_block_core_latest_posts_list')) {
71 function blockspare_register_block_core_latest_posts_list()
72 {
73
74 if (!function_exists('register_block_type')) {
75 return;
76 }
77
78 ob_start();
79 include BLOCKSPARE_PLUGIN_DIR . 'inc/latest-post-block/posts-list/block.json';
80 $metadata = json_decode(ob_get_clean(), true);
81
82 /* Block attributes */
83 register_block_type(
84 'blockspare/blockspare-latest-posts-list',
85 array(
86 'attributes' => $metadata['attributes'],
87 'render_callback' => 'blockspare_render_block_core_latest_posts_list',
88 )
89 );
90 }
91
92 add_action('init', 'blockspare_register_block_core_latest_posts_list');
93 }
94
95 /**
96 * Create API fields for additional info
97 */
98 if (!function_exists('blockspare_post_register_rest_fields')) {
99 function blockspare_post_register_rest_fields()
100 {
101
102 register_rest_field('post', 'featured_image_urls',
103 array(
104 'get_callback' => 'blockspare_featured_image_urls',
105 'update_callback' => null,
106 'schema' => array(
107 'description' => __('Different sized featured images', 'blockspare'),
108 'type' => 'array',
109 ),
110 )
111 );
112
113 // Excer
114
115 /* Add author info */
116 register_rest_field(
117 'post',
118 'author_info',
119 array(
120 'get_callback' => 'blockspare_get_author_infos',
121 'update_callback' => null,
122 'schema' => null,
123 )
124 );
125
126 /* Add author info */
127 register_rest_field(
128 'post',
129 'category_info',
130 array(
131 'get_callback' => 'blockspare_get_category_infos',
132 'update_callback' => null,
133 'schema' => null,
134 )
135 );
136
137 /* Add author info */
138 register_rest_field(
139 'post',
140 'tag_info',
141 array(
142 'get_callback' => 'blockspare_get_tag_infos',
143 'update_callback' => null,
144 'schema' => null,
145 )
146 );
147
148 register_rest_field(
149 'post',
150 'comment_count',
151 array(
152 'get_callback' => 'blockspare_get_comment_count',
153 'update_callback' => null,
154 'schema' => null,
155 )
156 );
157 }
158
159 add_action('rest_api_init', 'blockspare_post_register_rest_fields');
160 }
161
162 /**
163 * Get author info for the rest field
164 *
165 * @param String $object The object type.
166 * @param String $field_name Name of the field to retrieve.
167 * @param String $request The current request object.
168 */
169 if (!function_exists('blockspare_get_author_infos')) {
170 function blockspare_get_author_infos($object, $field_name, $request)
171 {
172 if (!isset($object['author'])) {
173 return;
174 }
175
176 global $post;
177 $author_id = get_post_field('post_author', $object['author']);
178 $blocspare = new BlocksapreMultiAuthorForBackend();
179 $author_data = $blocspare->blockspare_by_author($post);
180 return $author_data;
181 }
182 }
183 if (!function_exists('blockspare_get_category_infos')) {
184 function blockspare_get_category_infos($object, $field_name, $request)
185 {
186 return get_the_category_list(' ', '', $object['id']);
187
188 }
189 }
190
191 if (!function_exists('blockspare_get_tag_infos')) {
192 function blockspare_get_tag_infos($object, $field_name, $request)
193 {
194
195 ob_start();
196 $cate_name = '';
197 if (!empty($object)) {
198 foreach ($object['categories'] as $cat_id) {
199 $cate_name = get_cat_name($cat_id);
200 }
201 }
202 ob_clean();
203 return $cate_name;
204
205 }
206 }
207
208 if (!function_exists('blockspare_get_comment_count')) {
209 function blockspare_get_comment_count($object, $field_name, $reques)
210 {
211
212 return get_comments_number($object['id']);
213
214 }
215 }
216
217 if (!function_exists('blockspare_featured_image_urls')) {
218 /**
219 * Get the different featured image sizes that the blog will use.
220 * Used in the custom REST API endpoint.
221 *
222 * @since 1.7
223 */
224 function blockspare_featured_image_urls($object, $field_name, $request)
225 {
226 return blockspare_featured_image_urls_from_url(!empty($object['featured_media']) ? $object['featured_media'] : '');
227 }
228 }
229
230 if (!function_exists('blockspare_featured_image_urls_from_url')) {
231 /**
232 * Get the different featured image sizes that the blog will use.
233 *
234 * @since 2.0
235 */
236 function blockspare_featured_image_urls_from_url($attachment_id)
237 {
238
239 $image = wp_get_attachment_image_src($attachment_id, 'full', false);
240 $sizes = get_intermediate_image_sizes();
241
242 $imageSizes = array(
243 'full' => is_array($image) ? $image : '',
244 );
245
246 foreach ($sizes as $size) {
247 $imageSizes[$size] = is_array($image) ? wp_get_attachment_image_src($attachment_id, $size, false) : '';
248 }
249
250 return $imageSizes;
251 }
252 }
253 if (!function_exists('blockspare_post_style_css')) {
254 function blockspare_post_style_css($blockuniqueclass, $attributes)
255 {
256
257 $block_content = '';
258 $block_content .= '<style type="text/css">';
259 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-wrap{
260 margin-top:' . $attributes['marginTop'] . 'px;
261 margin-bottom:' . $attributes['marginBottom'] . 'px;
262 margin-left:' . $attributes['marginLeft'] . 'px;
263 margin-right:' . $attributes['marginRight'] . 'px;
264 }';
265
266 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-content{
267 padding-top:' . $attributes['contentPaddingTop'] . 'px;
268 padding-right:' . $attributes['contentPaddingRight'] . 'px;
269 padding-bottom:' . $attributes['contentPaddingBottom'] . 'px;
270 padding-left:' . $attributes['contentPaddingLeft'] . 'px;
271 }';
272
273 blockspare_posts_category_style(
274 $block_content,
275 $attributes,
276 $blockuniqueclass,
277 $attributes['categoryTextColor'],
278 $attributes['categoryBackgroundColor'],
279 $attributes['categoryBorderColor'],
280 $attributes['secondCategoryTextColor'],
281 $attributes['secondCategoryBackgroundColor'],
282 $attributes['secondCategoryBorderColor'],
283 $attributes['thirdCategoryTextColor'],
284 $attributes['thirdCategoryBackgroundColor'],
285 $attributes['thirdCategoryBorderColor'],
286 );
287
288 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-byline{
289 margin-top:' . $attributes['metaMarginTop'] . 'px' . ';
290 margin-bottom:' . $attributes['metaMarginBottom'] . 'px' . ';
291 margin-left:' . $attributes['metaMarginLeft'] . 'px' . ';
292 margin-right:' . $attributes['metaMarginRight'] . 'px' . ';
293 }';
294
295 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-more-link{
296 margin-top:' . $attributes['moreLinkMarginTop'] . 'px' . ';
297 margin-bottom:' . $attributes['moreLinkMarginBottom'] . 'px' . ';
298 margin-left:' . $attributes['moreLinkMarginLeft'] . 'px' . ';
299 margin-right:' . $attributes['moreLinkMarginRight'] . 'px' . ';
300 }';
301
302 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-title a span{
303 color: ' . $attributes['postTitleColor'] . ';
304 }';
305
306 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-author a span{
307 color:' . $attributes['linkColor'] . ';
308 }';
309
310 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-more-link span{
311 color:' . $attributes['linkColor'] . ';
312 }';
313
314 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-date{
315 color:' . $attributes['generalColor'] . ';
316 }';
317
318 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-excerpt-content{
319 color:' . $attributes['generalColor'] . ';
320 }';
321
322 $block_content .= ' .' . $blockuniqueclass . ' .comment_count{
323 color:' . $attributes['generalColor'] . ';
324 }';
325
326 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-title{
327 margin-top:' . $attributes['titleMarginTop'] . 'px' . ';
328 margin-bottom:' . $attributes['titleMarginBottom'] . 'px' . ';
329 margin-left:' . $attributes['titleMarginLeft'] . 'px' . ';
330 margin-right:' . $attributes['titleMarginRight'] . 'px' . ';
331 }';
332
333 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-excerpt-content{
334 margin-top:' . $attributes['exceprtMarginTop'] . 'px' . ';
335 margin-bottom:' . $attributes['exceprtMarginBottom'] . 'px' . ';
336 margin-left:' . $attributes['exceprtMarginLeft'] . 'px' . ';
337 margin-right:' . $attributes['exceprtMarginRight'] . 'px' . ';
338 }';
339
340 $layoutstyle = explode('-', $attributes['design']);
341
342 if ($layoutstyle[5] > 3) {
343 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-single .blockspare-posts-block-post-img {
344 border-radius:' . $attributes['borderRadius'] . 'px' . ';
345 }';
346 if ($attributes['enableBoxShadow']) {
347 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-single .blockspare-posts-block-post-img {
348 box-shadow: ' . $attributes['xOffset'] . 'px ' . $attributes['yOffset'] . 'px ' . $attributes['blur'] . 'px ' . $attributes['spread'] . 'px ' . $attributes['shadowColor'] . ';
349 }';
350 }
351 } else {
352 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-single{
353 border-radius:' . $attributes['borderRadius'] . 'px' . ';
354 background-color:' . $attributes['backGroundColor'] . '
355 }';
356
357 if ($attributes['enableBoxShadow']) {
358 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-single{
359 box-shadow: ' . $attributes['xOffset'] . 'px ' . $attributes['yOffset'] . 'px ' . $attributes['blur'] . 'px ' . $attributes['spread'] . 'px ' . $attributes['shadowColor'] . ';
360 }';
361 }
362 }
363
364 //Title Hover
365
366 if ($attributes['titleOnHover'] == 'lpc-title-hover') {
367 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-content .blockspare-posts-block-title-link:hover span{
368 color: ' . $attributes['titleOnHoverColor'] . ';
369 }';
370 }
371
372 if ($attributes['titleOnHover'] == 'lpc-title-border') {
373 $block_content .= ' .' . $blockuniqueclass . ' .lpc-title-border .blockspare-posts-block-post-grid-title .blockspare-posts-block-title-link span:hover{
374 box-shadow: inset 0 -2px 0 0 ' . $attributes['titleOnHoverColor'] . ';
375 }';
376 }
377
378 //Font Settings
379
380 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-title a span{
381 font-size: ' . $attributes['postTitleFontSize'] . $attributes['titleFontSizeType'] . ';
382 ' . bscheckFontfamily($attributes['titleFontFamily']) . ';
383 ' . bscheckFontfamilyWeight($attributes['titleFontWeight']) . ';
384 line-height: ' . $attributes['postTitleLineHeight'] . ';
385 }';
386
387 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-content .blockspare-posts-block-post-grid-excerpt .blockspare-posts-block-post-grid-excerpt-content {
388 font-size:' . $attributes['descriptionFontSize'] . $attributes['descriptionFontSizeType'] . ';
389 ' . bscheckFontfamily($attributes['descriptionFontFamily']) . ';
390 ' . bscheckFontfamilyWeight($attributes['descriptionFontWeight']) . ';
391 }';
392
393 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-author a span {
394 font-size:' . $attributes['postMetaFontSize'] . $attributes['postMetaFontSizeType'] . ';
395 ' . bscheckFontfamily($attributes['postMetaFontFamily']) . ';
396 ' . bscheckFontfamilyWeight($attributes['postMetaFontWeight']) . ';
397 }';
398
399 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-date {
400 font-size:' . $attributes['postMetaFontSize'] . $attributes['postMetaFontSizeType'] . ';
401 ' . bscheckFontfamily($attributes['postMetaFontFamily']) . ';
402 ' . bscheckFontfamilyWeight($attributes['postMetaFontWeight']) . ';
403 }';
404
405 $block_content .= ' .' . $blockuniqueclass . ' .comment_count {
406 font-size:' . $attributes['postMetaFontSize'] . $attributes['postMetaFontSizeType'] . ';
407 ' . bscheckFontfamily($attributes['postMetaFontFamily']) . ';
408 ' . bscheckFontfamilyWeight($attributes['postMetaFontWeight']) . ';
409 }';
410
411 $block_content .= '@media (max-width: 1025px) { ';
412
413 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-title a span{
414 font-size: ' . $attributes['titleFontSizeTablet'] . $attributes['titleFontSizeType'] . ';
415 }';
416 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-content .blockspare-posts-block-post-grid-excerpt .blockspare-posts-block-post-grid-excerpt-content {
417 font-size:' . $attributes['descriptionFontSizeTablet'] . $attributes['descriptionFontSizeType'] . '
418 }';
419 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-author a span {
420 font-size:' . $attributes['postMetaFontSizeTablet'] . $attributes['postMetaFontSizeType'] . '
421 }';
422 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-date {
423 font-size:' . $attributes['postMetaFontSizeTablet'] . $attributes['postMetaFontSizeType'] . '
424 }';
425 $block_content .= ' .' . $blockuniqueclass . ' .comment_count {
426 font-size:' . $attributes['postMetaFontSizeTablet'] . $attributes['postMetaFontSizeType'] . '
427 }';
428
429 $block_content .= '}';
430
431 $block_content .= '@media (max-width: 767px) { ';
432
433 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-title a span{
434 font-size: ' . $attributes['titleFontSizeMobile'] . $attributes['titleFontSizeType'] . ';
435 }';
436 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-content .blockspare-posts-block-post-grid-excerpt .blockspare-posts-block-post-grid-excerpt-content {
437 font-size:' . $attributes['descriptionFontSizeMobile'] . $attributes['descriptionFontSizeType'] . '
438 }';
439 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-author a span {
440 font-size:' . $attributes['postMetaFontSizeMobile'] . $attributes['postMetaFontSizeType'] . '
441 }';
442 $block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-date {
443 font-size:' . $attributes['postMetaFontSizeMobile'] . $attributes['postMetaFontSizeType'] . '
444 }';
445 $block_content .= ' .' . $blockuniqueclass . ' .comment_count {
446 font-size:' . $attributes['postMetaFontSizeMobile'] . $attributes['postMetaFontSizeType'] . '
447 }';
448
449 $block_content .= '}';
450
451 //Pagination
452
453 if ($attributes['enablePagination']) {
454 if ($attributes['loadMoreStyle'] == 'bs-loadmore-solid') {
455 $block_content .= ' .' . $blockuniqueclass . ' .bs_blockspare_loadmore a.blockspare-readmore .load-btn{
456 color:' . $attributes['loadMoreSolidTextColor'] . ';
457 background-color:' . $attributes['loadMoreTextBgColor'] . ';
458 }';
459 $block_content .= ' .' . $blockuniqueclass . ' .bs_blockspare_loadmore a.blockspare-readmore .load-btn:hover{
460 color:' . $attributes['loadMoreSolidTextHoverColor'] . ';
461 background-color:' . $attributes['loadMoreTextBgHoverColor'] . ';
462 }';
463 } else {
464 $block_content .= ' .' . $blockuniqueclass . ' .bs_blockspare_loadmore a.blockspare-readmore .load-btn{
465 color:' . $attributes['loadMoreTextColor'] . ';
466 }';
467 $block_content .= ' .' . $blockuniqueclass . ' .bs_blockspare_loadmore a.blockspare-readmore .load-btn:hover{
468 color:' . $attributes['loadMoreTextHoverColor'] . ';
469 }';
470 }
471
472 $block_content .= ' .' . $blockuniqueclass . ' .bs_blockspare_loadmore{
473 text-align:' . $attributes['loadMoreAlignment'] . ';
474 }';
475 $block_content .= ' .' . $blockuniqueclass . ' .bs_blockspare_loadmore a.blockspare-readmore .ajax-loader-enabled{
476 border-top-color:' . $attributes['loadMoreColor'] . ';
477 }';
478 $block_content .= '}';
479 }
480
481 $block_content .= '</style>';
482 return $block_content;
483 }
484 }
485