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

216 lines 7.9 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 // Verify the front-end nonce (sent by UltimatePostKitConfig.nonce) before
37 // processing this public load-more request.
38 if ( ! check_ajax_referer( 'upk-site', 'nonce', false ) ) {
39 wp_send_json_error( array( 'message' => esc_html__( 'Security check failed.', 'ultimate-post-kit' ) ), 403 );
40 }
41
42
43 // Security: Verify nonce
44 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'upk-site' ) ) {
45 wp_send_json_error( [ 'message' => esc_html__( 'Security verification failed', 'ultimate-post-kit' ) ], 403 );
46 wp_die();
47 }
48
49 $settings = [];
50
51 if ( isset( $_POST['settings'] ) && is_array( $_POST['settings'] ) ) {
52 $settings = map_deep( wp_unslash( $_POST['settings'] ), 'sanitize_text_field' );
53 }
54
55 // NOTE: the request-derived values below are NOT the ones the query is built from.
56 // query_args() is declared without parameters and re-reads $_POST['settings']
57 // itself, so anything merged into $settings here is discarded. The query is
58 // constrained inside query_args(): post_status is pinned to 'publish', per_page
59 // is clamped to 1..100, and post_type is restricted to publicly visible post
60 // types by ultimate_post_kit_sanitize_public_post_type(). The defaults are kept
61 // only so the render loop below has the keys it expects.
62 $settings = array_merge(
63 [
64 'posts_source' => 'post',
65 'posts_orderby' => 'date',
66 'posts_order' => 'DESC',
67 'posts_ignore_sticky_posts' => 'no',
68 'posts_only_with_featured_image' => 'no',
69 'posts_select_date' => '',
70 'posts_exclude_by' => [],
71 'posts_include_by' => [],
72 ],
73 $settings
74 );
75
76 $ajaxposts = $this->query_args( $settings );
77
78 ob_start();
79 $found_posts = false;
80
81 if ($ajaxposts->have_posts()) :
82 while ($ajaxposts->have_posts()) :
83 $ajaxposts->the_post();
84 $found_posts = true;
85
86 $title = get_the_title();
87 $post_link = esc_url(get_permalink());
88 $image_src = wp_get_attachment_image_url(get_post_thumbnail_id(), 'large');
89 $image_src = $image_src ? esc_url($image_src) : esc_url(\Elementor\Utils::get_placeholder_image_src());
90 $category = wp_kses_post(upk_get_category($post_type));
91 $author_url = esc_url(get_author_posts_url(get_the_author_meta('ID')));
92 $author_name = esc_html(get_the_author());
93 $title_tag = Utils::get_valid_html_tag($settings['title_tags'] );
94
95 $meta_separator = isset( $settings['meta_separator'] ) ? $settings['meta_separator'] : '|';
96
97
98 $date = '';
99 if (!empty($settings['human_diff_time']) && $settings['human_diff_time'] === 'yes') {
100 $date = ultimate_post_kit_post_time_diff(($settings['human_diff_time_short'] === 'yes') ? 'short' : '');
101 } else {
102 $date = esc_html(get_the_date());
103 }
104
105 $format_icons = [
106 'aside' => 'upk-icon-aside',
107 'gallery' => 'upk-icon-gallery',
108 'link' => 'upk-icon-link',
109 'image' => 'upk-icon-image',
110 'quote' => 'upk-icon-quote',
111 'status' => 'upk-icon-status',
112 'video' => 'upk-icon-video',
113 'audio' => 'upk-icon-music',
114 'chat' => 'upk-icon-chat',
115 ];
116
117 $post_format_icon = isset($format_icons[get_post_format()]) ? $format_icons[get_post_format()] : 'upk-icon-post';
118
119 ?>
120 <div <?php if ( ! empty( $settings['global_link'] ) && $settings['global_link'] === 'yes' ) { printf( 'onclick="window.open(\'%s\', \'_self\')"', esc_url( $post_link ) ); } ?> class="upk-item">
121 <div class="upk-image-wrap">
122 <img class="upk-img" src="<?php echo esc_url( $image_src ); ?>" alt="<?php echo esc_attr($title); ?>">
123
124 <?php if (
125 $settings['show_author'] === 'yes' ||
126 $settings['show_date'] === 'yes' ||
127 $settings['show_time'] === 'yes' ||
128 $settings['show_reading_time'] === 'yes'
129 ) : ?>
130 <div class="upk-meta">
131 <?php if ($settings['show_author'] === 'yes') : ?>
132 <div class="upk-author-img"><?php echo wp_kses_post(get_avatar(get_the_author_meta('ID'), 48)); ?></div>
133 <?php endif; ?>
134
135 <div>
136 <?php if ($settings['show_author'] === 'yes') : ?>
137 <div class="upk-author-name">
138 <a href="<?php echo esc_url( $author_url ); ?>"><?php echo esc_html( $author_name ); ?></a>
139 </div>
140 <?php endif; ?>
141
142 <div class="upk-flex upk-flex-middle upk-date-reading-wrap">
143 <?php if ( $settings['show_date'] === 'yes' ) : ?>
144 <div class="upk-date"><?php echo esc_html( $date ); ?></div>
145 <?php if ( $settings['show_time'] === 'yes' ) : ?>
146 <div class="upk-post-time" data-separator="<?php echo esc_attr( $meta_separator ); ?>">
147 <i class="upk-icon-clock" aria-hidden="true"></i><?php echo esc_html( get_the_time() ); ?>
148 </div>
149 <?php endif; ?>
150 <?php endif; ?>
151
152 <?php if ( function_exists( '_is_upk_pro_activated' ) && _is_upk_pro_activated() && $settings['show_reading_time'] === 'yes' ) : ?>
153 <div class="upk-reading-time" data-separator="<?php echo esc_attr( $meta_separator ); ?>">
154 <?php echo wp_kses_post( ultimate_post_kit_reading_time( get_the_content(), $settings['avg_reading_speed'], $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no' ) ); ?>
155 </div>
156 <?php endif; ?>
157 </div>
158 </div>
159 </div>
160 <?php endif; ?>
161
162 <?php if ($settings['show_post_format'] === 'yes') : ?>
163 <div class="upk-post-format">
164 <a href="<?php echo esc_url( $post_link ); ?>">
165 <i class="<?php echo esc_attr($post_format_icon); ?>" aria-hidden="true"></i>
166 </a>
167 </div>
168 <?php endif; ?>
169 </div>
170
171 <div class="upk-content-wrap">
172 <div class="upk-content">
173 <?php if ($settings['show_category'] === 'yes') : ?>
174 <div class="upk-category"><?php echo wp_kses_post( $category ); ?></div>
175 <?php endif; ?>
176
177 <?php if ($settings['show_title'] === 'yes') : ?>
178 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
179 <a class="title-animation-<?php echo esc_attr($settings['title_style']); ?>"
180 href="<?php echo esc_url( $post_link ); ?>"
181 title="<?php echo esc_attr($title); ?>"
182 <?php echo $settings['upk_link_new_tab'] === 'yes' ? 'target="_blank"' : ''; ?>
183 >
184 <?php echo esc_html($title); ?>
185 </a>
186 </<?php echo esc_attr( $title_tag); ?>>
187 <?php endif; ?>
188 </div>
189
190 <?php if ($settings['show_readmore'] === 'yes') : ?>
191 <div class="upk-button-wrap">
192 <a href="<?php echo esc_url( $post_link ); ?>"
193 class="upk-readmore"
194 target="<?php echo ($settings['upk_link_new_tab'] === 'yes') ? '_blank' : '_self'; ?>">
195 <span class="upk-readmore-icon"><span></span></span>
196 </a>
197 </div>
198 <?php endif; ?>
199 </div>
200 </div>
201 <?php
202 endwhile;
203 endif;
204
205 wp_reset_postdata();
206 $markup = ob_get_clean();
207
208 wp_send_json(
209 [
210 'success' => $found_posts,
211 'markup' => $found_posts ? $markup : esc_html__('No more found', 'ultimate-post-kit'),
212 ]
213 );
214 }
215 }
216