PluginProbe ʕ •ᴥ•ʔ
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More / 3.6.1
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More v3.6.1
4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 trunk 1.0.0 2.0.0 2.0.1 2.0.2 2.0.3 3.0 3.0.1 3.0.2 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.2.0 3.2.1 3.2.2 3.2.4 3.2.5 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.4.5 3.4.6 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1
superb-blocks / src / gutenberg / block-api / class-recent-posts-controller.php
superb-blocks / src / gutenberg / block-api Last commit date
class-dynamic-block-assets.php 11 months ago class-recent-posts-controller.php 11 months ago
class-recent-posts-controller.php
118 lines
1 <?php
2
3 namespace SuperbAddons\Gutenberg\BlocksAPI\Controllers;
4
5 use SuperbAddons\Data\Controllers\LogController;
6 use Exception;
7
8 defined('ABSPATH') || exit();
9
10 class RecentPostsController
11 {
12 public static function DynamicRender($attributes, $content)
13 {
14 try {
15 if ((!$attributes['displayBlockOnFront'] && is_front_page()) ||
16 (!$attributes['displayBlockOnBlog'] && is_home()) ||
17 (!$attributes['displayBlockOnPagesPosts'] && !is_front_page() && !is_home())
18 ) {
19 return '<!-- Superb Recent Posts Block Hidden -->';
20 }
21 $excludecurrent = ($attributes['excludeCurrent'] && !is_front_page() && !is_home()) ? array(get_the_ID()) : array();
22 $recent_posts_args = array("numberposts" => $attributes['numberOfPosts'], "post_status" => "publish", "exclude" => $excludecurrent);
23
24 if (count($attributes['selectedCategories']) > 0) {
25 $recent_posts_args['category__in'] = $attributes['selectedCategories'];
26 }
27 if (count($attributes['selectedTags']) > 0) {
28 $recent_posts_args['tag__in'] = $attributes['selectedTags'];
29 }
30 $recent_posts_args = apply_filters('superbaddons_recent_posts_block_args', $recent_posts_args, $attributes);
31
32 $recent_posts = wp_get_recent_posts($recent_posts_args);
33
34 return self::Render($attributes, $recent_posts);
35 } catch (Exception $ex) {
36 LogController::HandleException($ex);
37 return;
38 }
39 }
40
41 private static function Render($attributes, $recent_posts)
42 {
43 ob_start();
44
45 // If no posts found
46 if (count($recent_posts) <= 0) : ?>
47 <div class="superbaddons-recentposts-wrapper">
48 <p style="font-weight:500;"><?php echo esc_html__("No posts found", "superb-blocks"); ?></p>
49 </div>
50 <?php return ob_get_clean();
51 endif;
52
53 // If posts found
54 ?>
55 <div class="superbaddons-recentposts-wrapper superbaddons-recentposts-alignment-<?php echo esc_attr($attributes['toolbarAlignment']); ?>">
56 <ul class="superbaddons-recentposts-list">
57 <?php
58 $wrapperTag = $attributes['IsInEditor'] ? 'span' : 'a';
59 foreach ($recent_posts as $post) {
60 $permalink = $attributes['IsInEditor'] ? "#" : get_permalink($post['ID']);
61 $the_post_title = $post['post_title'] === '' ? $post['post_name'] : $post['post_title'];
62 $temp_thumbnail_url = get_the_post_thumbnail_url($post['ID'], array($attributes['thumbnailSize'], $attributes['thumbnailSize']));
63 $thumbnail_url = !$temp_thumbnail_url ? SUPERBADDONS_ASSETS_PATH . '/img/post-thumbnail-placeholder.png' : $temp_thumbnail_url;
64 ?>
65 <li class="superbaddons-recentposts-item">
66 <<?php echo esc_html($wrapperTag); ?> href="<?php echo esc_url($permalink) ?>" <?php echo $attributes['linksTargetBlank'] && !$attributes['IsInEditor'] ? 'target="_blank"' : '' ?>>
67 <div class="superbaddons-recentposts-item-inner">
68 <?php if ($attributes['displayThumbnails'] && ($attributes['displayPlaceholderThumbnails'] || $temp_thumbnail_url !== false)) : ?>
69 <div class="superbaddons-recentposts-item-left">
70 <img width="<?php echo esc_attr($attributes['thumbnailSize']) ?>" height="<?php echo esc_attr($attributes['thumbnailSize']) ?>" src="<?php echo esc_url($thumbnail_url) ?>" <?php echo $attributes['imgBorderRadiusEnabled'] ? 'style="border-radius:' . esc_attr($attributes['imgBorderRadius'] / 2) . '%;"' : ""; ?> />
71 </div>
72 <?php endif; ?>
73 <div class="superbaddons-recentposts-item-right">
74 <?php if ($attributes['displayDate'] || $attributes['displayAuthor']) : ?>
75 <!-- Meta -->
76 <span style="font-size:<?php echo esc_attr($attributes['fontSizeMeta']) ?>px; color:<?php echo esc_attr($attributes['colorMeta']) ?>;">
77 <?php if ($attributes['displayDate']) : ?>
78 <time class="superbaddons-recentposts-item-date">
79 <?php echo esc_html(get_the_date(get_option('date_format', 'F j, Y'), $post['ID'])); ?>
80 </time>
81 <?php endif; ?>
82 <?php if ($attributes['displayAuthor']) : ?>
83 <span class="superbaddons-recentposts-item-author">
84 <?php echo esc_html(__("by", "superb-blocks") . " " . get_the_author_meta($attributes['useAuthorDisplayName'] ? 'display_name' : 'user_nicename', $post['post_author'])); ?>
85 </span>
86 <?php endif; ?>
87 </span>
88 <?php endif; ?>
89
90 <!-- Title -->
91 <span style="font-size:<?php echo esc_attr($attributes['fontSizeTitle']) ?>px; color:<?php echo esc_attr($attributes['colorTitle']) ?>;"><?php echo esc_html($the_post_title); ?></span>
92
93 <?php if ($attributes['displayExcerpt']) : ?>
94 <!-- Excerpt -->
95 <span style="font-size:<?php echo esc_attr($attributes['fontSizeExcerpt']) ?>px; color:<?php echo esc_attr($attributes['colorExcerpt']) ?>;">
96 <?php echo esc_html(wp_trim_words(excerpt_remove_blocks(strip_shortcodes($post['post_content'])), $attributes['excerptLength'], apply_filters('excerpt_more', ' ' . '[&hellip;]'))); ?>
97 </span>
98 <?php endif; ?>
99
100 <?php if ($attributes['displayCommentCount']) : ?>
101 <!-- Comment Count -->
102 <span style="font-size:<?php echo esc_attr($attributes['fontSizeCommentCount']); ?>px; color:<?php echo esc_attr($attributes['colorCommentCount']); ?>;">
103 <?php echo esc_html(get_comment_count($post['ID'])['approved'] . " " . __("comment(s)", "superb-blocks")); ?>
104 </span>
105 <?php endif; ?>
106 </div>
107 </div>
108 </<?php echo esc_html($wrapperTag) ?>>
109 </li>
110 <?php
111 }
112 ?>
113 </ul>
114 </div>
115 <?php return ob_get_clean();
116 }
117 }
118