PluginProbe
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets / trunk
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets vtrunk
4.5.4 4.2.1 4.2.2 4.2.3 4.5.0 4.5.2 4.5.3 4.2.0 4.1.18 4.1.17 4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 All 146 releases
ultimate-post-kit / modules / featured-list / module.php

module.php in Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets trunk, at modules/featured-list/module.php

219 lines 7.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UltimatePostKit\Modules\FeaturedList;
3 use UltimatePostKit\Traits\Global_Widget_Functions;
4
5 use UltimatePostKit\Base\Ultimate_Post_Kit_Module_Base;
6 use UltimatePostKit\Utils;
7
8 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
9
10 class Module extends Ultimate_Post_Kit_Module_Base {
11
12 use Global_Widget_Functions;
13
14 public function __construct() {
15 parent::__construct();
16
17 add_action( 'wp_ajax_nopriv_upk_featured_list_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
18 add_action( 'wp_ajax_upk_featured_list_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
19 }
20
21 public function get_name() {
22 return 'featured-list';
23 }
24
25 public function get_widgets() {
26
27 $widgets = [
28 'Featured_List',
29 ];
30
31 return $widgets;
32 }
33
34 public function callback_ajax_loadmore_posts() {
35 // Verify the front-end nonce (sent by UltimatePostKitConfig.nonce) before
36 // processing this public load-more request.
37 if ( ! check_ajax_referer( 'upk-site', 'nonce', false ) ) {
38 wp_send_json_error( array( 'message' => esc_html__( 'Security check failed.', 'ultimate-post-kit' ) ), 403 );
39 }
40
41
42 $settings = [];
43
44 if ( isset( $_POST['settings'] ) && is_array( $_POST['settings'] ) ) {
45 $settings = map_deep( wp_unslash( $_POST['settings'] ), 'sanitize_text_field' );
46 }
47
48 $settings = array_merge(
49 [
50 'posts_source' => 'post',
51 'posts_orderby' => 'date',
52 'posts_order' => 'DESC',
53 'posts_ignore_sticky_posts' => 'no',
54 'posts_only_with_featured_image' => 'no',
55 'posts_select_date' => '',
56 'posts_exclude_by' => [],
57 'posts_include_by' => [],
58 'posts_per_page' => isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 0,
59 'posts_offset' => isset( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 0,
60 ],
61 $settings
62 );
63
64 // Fill display flags the request may have omitted (see trait) before the render loop reads them.
65 $settings = array_merge( $this->loadmore_display_defaults(), $settings );
66
67 $ajaxposts = $this->query_args( $settings );
68
69 ob_start();
70 $found_posts = false;
71
72 if ( $ajaxposts->have_posts() ) {
73 $placeholder = \Elementor\Utils::get_placeholder_image_src();
74
75 while ( $ajaxposts->have_posts() ) {
76 $ajaxposts->the_post();
77 $found_posts = true;
78
79 $title = get_the_title();
80 $post_link = esc_url( get_permalink() );
81 $post_id = get_the_ID();
82
83 $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(), $settings['primary_thumbnail_size'] ?? 'medium' );
84 $image_src = $image_src ? $image_src[0] : $placeholder;
85
86 $title_tag = Utils::get_valid_html_tag($settings['title_tags']);
87
88 ?>
89 <div <?php if ( ! empty( $settings['global_link'] ) && $settings['global_link'] === 'yes' ) { printf( 'onclick="window.open(\'%s\', \'_self\')"', esc_url( $post_link ) ); } ?> class="upk-item">
90 <div class="upk-item-box">
91
92 <div class="upk-image-wrap">
93 <img class="upk-img" src="<?php echo esc_url( $image_src ); ?>" alt="<?php echo esc_attr( $title ); ?>">
94 </div>
95 <div class="upk-content">
96 <?php if ( $settings['show_counter_number'] === 'yes' && $settings['layout_style'] === 'style-1' ) : ?>
97 <div class="upk-counter"></div>
98 <?php endif; ?>
99
100 <div>
101 <?php if ( $settings['show_category'] === 'yes' ) : ?>
102 <div class="upk-category">
103 <?php
104 $post_type = $settings['posts_source'];
105 switch ($post_type) {
106 case 'campaign':
107 $taxonomy = 'campaign_category';
108 break;
109 case 'lightbox_library':
110 $taxonomy = 'ngg_tag';
111 break;
112 case 'give_forms':
113 $taxonomy = 'give_forms_category';
114 break;
115 case 'tribe_events':
116 $taxonomy = 'tribe_events_cat';
117 break;
118 case 'product':
119 $taxonomy = 'product_cat';
120 break;
121 default:
122 $taxonomy = 'category';
123 break;
124 }
125
126 $categories = get_the_terms(get_the_ID(), $taxonomy);
127
128 if ( $categories ) {
129 foreach ( $categories as $category ) {
130 $bg_color = strToHex($category->name);
131 echo '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '"><span style="background-color:' . esc_attr( $bg_color ) . '"></span>' . esc_html( $category->name ) . '</a>';
132 }
133 }
134 ?>
135 </div>
136 <?php endif; ?>
137
138 <?php if ( ! isset( $settings['show_title'] ) || $settings['show_title'] === 'yes' ) : ?>
139 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
140 <a
141 href="<?php echo esc_url($post_link); ?>"
142 title="<?php echo esc_attr( $title ); ?>"
143 class="title-animation-<?php echo esc_attr( $settings['title_style'] ?? '' ); ?>"
144 <?php echo $settings['upk_link_new_tab'] === 'yes' ? 'target="_blank"' : '' ?>
145 >
146 <?php echo esc_html( $title ); ?>
147 </a>
148 </<?php echo esc_attr( $title_tag ); ?>>
149 <?php endif; ?>
150
151 <?php if ( $settings['show_author'] === 'yes' || $settings['show_comments'] === 'yes' || $settings['show_date'] === 'yes' || $settings['show_reading_time'] === 'yes' ) : ?>
152 <div class="upk-featured-meta">
153 <?php if ( $settings['show_author'] === 'yes' ) : ?>
154 <div class="upk-author-name-wrap">
155 <span class="upk-by"><?php echo esc_html_x( 'by', 'Frontend', 'ultimate-post-kit' ); ?></span>
156 <a class="upk-author-name" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>">
157 <?php echo esc_html( get_the_author() ); ?>
158 </a>
159 </div>
160 <?php endif; ?>
161
162 <?php if ( $settings['show_date'] === 'yes' ) : ?>
163 <div data-separator="<?php echo esc_attr( $settings['meta_separator'] ?? '//' ); ?>">
164 <div class="upk-date">
165 <?php
166 if ($settings['show_date'] === 'yes' && $settings['human_diff_time'] !== 'yes') {
167 echo esc_html(get_the_date());
168 }
169 if ($settings['human_diff_time'] === 'yes') {
170 echo esc_html(ultimate_post_kit_post_time_diff($settings['human_diff_time_short'] === 'yes' ? 'short' : ''));
171 }
172 ?>
173 </div>
174
175 <?php if ($settings['show_time'] === 'yes') : ?>
176 <div class="upk-post-time">
177 <i class="upk-icon-clock" aria-hidden="true"></i>
178 <?php echo esc_html( get_the_time() ); ?>
179 </div>
180 <?php endif; ?>
181 </div>
182 <?php endif; ?>
183
184 <?php if ( $settings['show_comments'] === 'yes' ) : ?>
185 <div data-separator="<?php echo esc_attr( $settings['meta_separator'] ?? '//' ); ?>">
186 <div class="upk-featured-comments">
187 <?php echo esc_html( $this->upk_get_formatted_comments_count( $post_id ) ); ?>
188 </div>
189 </div>
190 <?php endif; ?>
191
192 <?php if ( _is_upk_pro_activated() && $settings['show_reading_time'] === 'yes' ) : ?>
193 <div class="upk-reading-time" data-separator="<?php echo esc_attr( $settings['meta_separator'] ?? '//' ); ?>">
194 <?php echo esc_html( ultimate_post_kit_reading_time( get_the_content(), $settings['avg_reading_speed'], $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no' ) ); ?>
195 </div>
196 <?php endif; ?>
197 </div>
198 <?php endif; ?>
199 </div>
200 </div>
201 </div>
202 </div>
203 <?php
204 }
205 }
206
207 wp_reset_postdata();
208 $markup = ob_get_clean();
209
210 wp_send_json(
211 [
212 'success' => $found_posts,
213 'markup' => $found_posts ? $markup : esc_html__( 'No more found', 'ultimate-post-kit' ),
214 ]
215 );
216
217 }
218 }
219