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 / alex-grid / module.php

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

219 lines 8.1 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 // Fill display flags the request may have omitted (see trait) before the render loop reads them.
77 $settings = array_merge( $this->loadmore_display_defaults(), $settings );
78
79 $ajaxposts = $this->query_args( $settings );
80
81 ob_start();
82 $found_posts = false;
83
84 if ($ajaxposts->have_posts()) :
85 while ($ajaxposts->have_posts()) :
86 $ajaxposts->the_post();
87 $found_posts = true;
88
89 $title = get_the_title();
90 $post_link = esc_url(get_permalink());
91 $image_src = wp_get_attachment_image_url(get_post_thumbnail_id(), 'large');
92 $image_src = $image_src ? esc_url($image_src) : esc_url(\Elementor\Utils::get_placeholder_image_src());
93 $category = wp_kses_post(upk_get_category($settings['posts_source'] ?? 'post'));
94 $author_url = esc_url(get_author_posts_url(get_the_author_meta('ID')));
95 $author_name = esc_html(get_the_author());
96 $title_tag = Utils::get_valid_html_tag($settings['title_tags'] );
97
98 $meta_separator = isset( $settings['meta_separator'] ) ? $settings['meta_separator'] : '|';
99
100
101 $date = '';
102 if (!empty($settings['human_diff_time']) && $settings['human_diff_time'] === 'yes') {
103 $date = ultimate_post_kit_post_time_diff(($settings['human_diff_time_short'] === 'yes') ? 'short' : '');
104 } else {
105 $date = esc_html(get_the_date());
106 }
107
108 $format_icons = [
109 'aside' => 'upk-icon-aside',
110 'gallery' => 'upk-icon-gallery',
111 'link' => 'upk-icon-link',
112 'image' => 'upk-icon-image',
113 'quote' => 'upk-icon-quote',
114 'status' => 'upk-icon-status',
115 'video' => 'upk-icon-video',
116 'audio' => 'upk-icon-music',
117 'chat' => 'upk-icon-chat',
118 ];
119
120 $post_format_icon = isset($format_icons[get_post_format()]) ? $format_icons[get_post_format()] : 'upk-icon-post';
121
122 ?>
123 <div <?php if ( ! empty( $settings['global_link'] ) && $settings['global_link'] === 'yes' ) { printf( 'onclick="window.open(\'%s\', \'_self\')"', esc_url( $post_link ) ); } ?> class="upk-item">
124 <div class="upk-image-wrap">
125 <img class="upk-img" src="<?php echo esc_url( $image_src ); ?>" alt="<?php echo esc_attr($title); ?>">
126
127 <?php if (
128 $settings['show_author'] === 'yes' ||
129 $settings['show_date'] === 'yes' ||
130 $settings['show_time'] === 'yes' ||
131 $settings['show_reading_time'] === 'yes'
132 ) : ?>
133 <div class="upk-meta">
134 <?php if ($settings['show_author'] === 'yes') : ?>
135 <div class="upk-author-img"><?php echo wp_kses_post(get_avatar(get_the_author_meta('ID'), 48)); ?></div>
136 <?php endif; ?>
137
138 <div>
139 <?php if ($settings['show_author'] === 'yes') : ?>
140 <div class="upk-author-name">
141 <a href="<?php echo esc_url( $author_url ); ?>"><?php echo esc_html( $author_name ); ?></a>
142 </div>
143 <?php endif; ?>
144
145 <div class="upk-flex upk-flex-middle upk-date-reading-wrap">
146 <?php if ( $settings['show_date'] === 'yes' ) : ?>
147 <div class="upk-date"><?php echo esc_html( $date ); ?></div>
148 <?php if ( $settings['show_time'] === 'yes' ) : ?>
149 <div class="upk-post-time" data-separator="<?php echo esc_attr( $meta_separator ); ?>">
150 <i class="upk-icon-clock" aria-hidden="true"></i><?php echo esc_html( get_the_time() ); ?>
151 </div>
152 <?php endif; ?>
153 <?php endif; ?>
154
155 <?php if ( function_exists( '_is_upk_pro_activated' ) && _is_upk_pro_activated() && $settings['show_reading_time'] === 'yes' ) : ?>
156 <div class="upk-reading-time" data-separator="<?php echo esc_attr( $meta_separator ); ?>">
157 <?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' ) ); ?>
158 </div>
159 <?php endif; ?>
160 </div>
161 </div>
162 </div>
163 <?php endif; ?>
164
165 <?php if ($settings['show_post_format'] === 'yes') : ?>
166 <div class="upk-post-format">
167 <a href="<?php echo esc_url( $post_link ); ?>">
168 <i class="<?php echo esc_attr($post_format_icon); ?>" aria-hidden="true"></i>
169 </a>
170 </div>
171 <?php endif; ?>
172 </div>
173
174 <div class="upk-content-wrap">
175 <div class="upk-content">
176 <?php if ($settings['show_category'] === 'yes') : ?>
177 <div class="upk-category"><?php echo wp_kses_post( $category ); ?></div>
178 <?php endif; ?>
179
180 <?php if ($settings['show_title'] === 'yes') : ?>
181 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
182 <a class="title-animation-<?php echo esc_attr($settings['title_style']); ?>"
183 href="<?php echo esc_url( $post_link ); ?>"
184 title="<?php echo esc_attr($title); ?>"
185 <?php echo $settings['upk_link_new_tab'] === 'yes' ? 'target="_blank"' : ''; ?>
186 >
187 <?php echo esc_html($title); ?>
188 </a>
189 </<?php echo esc_attr( $title_tag); ?>>
190 <?php endif; ?>
191 </div>
192
193 <?php if ($settings['show_readmore'] === 'yes') : ?>
194 <div class="upk-button-wrap">
195 <a href="<?php echo esc_url( $post_link ); ?>"
196 class="upk-readmore"
197 target="<?php echo ($settings['upk_link_new_tab'] === 'yes') ? '_blank' : '_self'; ?>">
198 <span class="upk-readmore-icon"><span></span></span>
199 </a>
200 </div>
201 <?php endif; ?>
202 </div>
203 </div>
204 <?php
205 endwhile;
206 endif;
207
208 wp_reset_postdata();
209 $markup = ob_get_clean();
210
211 wp_send_json(
212 [
213 'success' => $found_posts,
214 'markup' => $found_posts ? $markup : esc_html__('No more found', 'ultimate-post-kit'),
215 ]
216 );
217 }
218 }
219