PluginProbe
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets / 4.1.13
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets v4.1.13
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 / alex-grid / module.php

module.php in Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets 4.1.13, at modules/alex-grid/module.php

234 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UltimatePostKit\Modules\AlexGrid;
3
4 use UltimatePostKit\Base\Ultimate_Post_Kit_Module_Base;
5 use UltimatePostKit\Traits\Global_Widget_Functions;
6 use Elementor\Icons_Manager;
7 use UltimatePostKit\Utils;
8
9 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
10
11 class Module extends Ultimate_Post_Kit_Module_Base {
12
13 use Global_Widget_Functions;
14
15 public function __construct() {
16 parent::__construct();
17
18 add_action('wp_ajax_nopriv_upk_alex_grid_loadmore_posts', [$this, 'callback_ajax_loadmore_posts']);
19 add_action('wp_ajax_upk_alex_grid_loadmore_posts', [$this, 'callback_ajax_loadmore_posts']);
20 }
21
22 public function get_name() {
23 return 'alex-grid';
24 }
25
26 public function get_widgets() {
27
28 $widgets = [
29 'Alex_Grid',
30 ];
31
32 return $widgets;
33 }
34
35 public function callback_ajax_loadmore_posts() {
36
37 // Security: Verify nonce
38 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'upk-site' ) ) {
39 wp_send_json_error( [ 'message' => esc_html__( 'Security verification failed', 'ultimate-post-kit' ) ], 403 );
40 wp_die();
41 }
42
43 $settings = [];
44
45 if ( isset( $_POST['settings'] ) && is_array( $_POST['settings'] ) ) {
46 $settings = map_deep( wp_unslash( $_POST['settings'] ), 'sanitize_text_field' );
47 }
48
49 $post_type = $settings['post_source'] ?? 'post';
50
51 // Security: Enforce query limits to prevent DoS
52 $per_page = isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 6;
53 $per_page = min( $per_page, 50 ); // Maximum 50 posts per request
54 $offset = isset( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 0;
55 $offset = min( $offset, 1000 ); // Maximum offset of 1000
56
57 // Security: Whitelist allowed post types
58 $allowed_post_types = [ 'post', 'page' ];
59 $allowed_post_types = apply_filters( 'upk_alex_grid_allowed_post_types', $allowed_post_types );
60 $post_type = in_array( $post_type, $allowed_post_types, true ) ? $post_type : 'post';
61
62 // Security: Whitelist orderby values
63 $allowed_orderby = [ 'date', 'title', 'modified', 'rand', 'comment_count', 'menu_order' ];
64 $posts_orderby = isset( $settings['posts_orderby'] ) && in_array( $settings['posts_orderby'], $allowed_orderby, true ) ? $settings['posts_orderby'] : 'date';
65
66 // Security: Whitelist order values
67 $posts_order = isset( $settings['posts_order'] ) && in_array( strtoupper( $settings['posts_order'] ), [ 'ASC', 'DESC' ], true ) ? strtoupper( $settings['posts_order'] ) : 'DESC';
68
69 $settings = array_merge(
70 [
71 'posts_source' => $post_type,
72 'posts_orderby' => $posts_orderby,
73 'posts_order' => $posts_order,
74 'posts_ignore_sticky_posts' => 'no',
75 'posts_only_with_featured_image' => 'no',
76 'posts_select_date' => '',
77 'posts_exclude_by' => [],
78 'posts_include_by' => [],
79 'posts_per_page' => $per_page,
80 'posts_offset' => $offset,
81 ],
82 $settings
83 );
84
85 $ajaxposts = $this->query_args( $settings );
86
87 // Security: Override post_status to ensure only published posts are shown
88 if ( ! current_user_can( 'edit_posts' ) ) {
89 $ajaxposts->query_vars['post_status'] = 'publish';
90 }
91
92 ob_start();
93 $found_posts = false;
94
95 if ($ajaxposts->have_posts()) :
96 while ($ajaxposts->have_posts()) :
97 $ajaxposts->the_post();
98 $found_posts = true;
99
100 $title = get_the_title();
101 $post_link = esc_url(get_permalink());
102 $image_src = wp_get_attachment_image_url(get_post_thumbnail_id(), 'large');
103 $image_src = $image_src ? esc_url($image_src) : esc_url(\Elementor\Utils::get_placeholder_image_src());
104 $category = wp_kses_post(upk_get_category($post_type));
105 $author_url = esc_url(get_author_posts_url(get_the_author_meta('ID')));
106 $author_name = esc_html(get_the_author());
107 $title_tag = Utils::get_valid_html_tag($settings['title_tags'] );
108
109 $onclick = '';
110 if (!empty($settings['global_link']) && $settings['global_link'] === 'yes') {
111 $onclick = ' onclick="window.open(\'' . $post_link . '\', \'_self\')"';
112 }
113
114 $date = '';
115 if (!empty($settings['human_diff_time']) && $settings['human_diff_time'] === 'yes') {
116 $date = ultimate_post_kit_post_time_diff(($settings['human_diff_time_short'] === 'yes') ? 'short' : '');
117 } else {
118 $date = esc_html(get_the_date());
119 }
120
121 $format_icons = [
122 'aside' => 'upk-icon-aside',
123 'gallery' => 'upk-icon-gallery',
124 'link' => 'upk-icon-link',
125 'image' => 'upk-icon-image',
126 'quote' => 'upk-icon-quote',
127 'status' => 'upk-icon-status',
128 'video' => 'upk-icon-video',
129 'audio' => 'upk-icon-music',
130 'chat' => 'upk-icon-chat',
131 ];
132
133 $post_format_icon = isset($format_icons[get_post_format()]) ? $format_icons[get_post_format()] : 'upk-icon-post';
134
135 ?>
136 <div <?php echo $onclick; ?> class="upk-item">
137 <div class="upk-image-wrap">
138 <img class="upk-img" src="<?php echo $image_src; ?>" alt="<?php echo esc_attr($title); ?>">
139
140 <?php if (
141 $settings['show_author'] === 'yes' ||
142 $settings['show_date'] === 'yes' ||
143 $settings['show_time'] === 'yes' ||
144 $settings['show_reading_time'] === 'yes'
145 ) : ?>
146 <div class="upk-meta">
147 <?php if ($settings['show_author'] === 'yes') : ?>
148 <div class="upk-author-img"><?php echo wp_kses_post(get_avatar(get_the_author_meta('ID'), 48)); ?></div>
149 <?php endif; ?>
150
151 <div>
152 <?php if ($settings['show_author'] === 'yes') : ?>
153 <div class="upk-author-name">
154 <a href="<?php echo $author_url; ?>"><?php echo $author_name; ?></a>
155 </div>
156 <?php endif; ?>
157
158 <div class="upk-flex upk-flex-middle upk-date-reading-wrap">
159 <?php if ($settings['show_date'] === 'yes') : ?>
160 <div data-separator="<?php echo esc_attr($settings['meta_separator']); ?>">
161 <div class="upk-date"><?php echo $date; ?></div>
162 <?php if ($settings['show_time'] === 'yes') : ?>
163 <div class="upk-post-time">
164 <i class="upk-icon-clock" aria-hidden="true"></i><?php echo esc_html(get_the_time()); ?>
165 </div>
166 <?php endif; ?>
167 </div>
168 <?php endif; ?>
169
170 <?php if (function_exists('_is_upk_pro_activated') && _is_upk_pro_activated() && $settings['show_reading_time'] === 'yes') : ?>
171 <div class="upk-reading-time" data-separator="<?php echo esc_attr($settings['meta_separator']); ?>">
172 <?php echo ultimate_post_kit_reading_time(get_the_content(), $settings['avg_reading_speed'], $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no'); ?>
173 </div>
174 <?php endif; ?>
175 </div>
176 </div>
177 </div>
178 <?php endif; ?>
179
180 <?php if ($settings['show_post_format'] === 'yes') : ?>
181 <div class="upk-post-format">
182 <a href="<?php echo $post_link; ?>">
183 <i class="<?php echo esc_attr($post_format_icon); ?>" aria-hidden="true"></i>
184 </a>
185 </div>
186 <?php endif; ?>
187 </div>
188
189 <div class="upk-content-wrap">
190 <div class="upk-content">
191 <?php if ($settings['show_category'] === 'yes') : ?>
192 <div class="upk-category"><?php echo $category; ?></div>
193 <?php endif; ?>
194
195 <?php if ($settings['show_title'] === 'yes') : ?>
196 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
197 <a class="title-animation-<?php echo esc_attr($settings['title_style']); ?>"
198 href="<?php echo $post_link; ?>"
199 title="<?php echo esc_attr($title); ?>"
200 <?php echo $settings['upk_link_new_tab'] === 'yes' ? 'target="_blank"' : ''; ?>
201 >
202 <?php echo esc_html($title); ?>
203 </a>
204 </<?php echo esc_attr( $title_tag); ?>>
205 <?php endif; ?>
206 </div>
207
208 <?php if ($settings['show_readmore'] === 'yes') : ?>
209 <div class="upk-button-wrap">
210 <a href="<?php echo $post_link; ?>"
211 class="upk-readmore"
212 target="<?php echo ($settings['upk_link_new_tab'] === 'yes') ? '_blank' : '_self'; ?>">
213 <span class="upk-readmore-icon"><span></span></span>
214 </a>
215 </div>
216 <?php endif; ?>
217 </div>
218 </div>
219 <?php
220 endwhile;
221 endif;
222
223 wp_reset_postdata();
224 $markup = ob_get_clean();
225
226 wp_send_json(
227 [
228 'success' => $found_posts,
229 'markup' => $found_posts ? $markup : esc_html__('No more found', 'ultimate-post-kit'),
230 ]
231 );
232 }
233 }
234