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

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

239 lines 12.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\RambleGrid;
3 use UltimatePostKit\Traits\Global_Widget_Functions;
4 use Elementor\Icons_Manager;
5
6 use UltimatePostKit\Base\Ultimate_Post_Kit_Module_Base;
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_ramble_grid_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
19 add_action( 'wp_ajax_upk_ramble_grid_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
20 }
21
22 public function get_name() {
23 return 'ramble-grid';
24 }
25
26 public function get_widgets() {
27
28 $widgets = [
29 'Ramble_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 $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['posts_source'] ?? 'post';
50
51 $settings = array_merge(
52 [
53 'posts_source' => 'post',
54 'posts_orderby' => 'date',
55 'posts_order' => 'DESC',
56 'posts_ignore_sticky_posts' => 'no',
57 'posts_only_with_featured_image' => 'no',
58 'posts_select_date' => '',
59 'posts_exclude_by' => [],
60 'posts_include_by' => [],
61 'posts_per_page' => isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 0,
62 'posts_offset' => isset( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 0,
63 ],
64 $settings
65 );
66
67 // Fill display flags the request may have omitted (see trait) before the render loop reads them.
68 $settings = array_merge( $this->loadmore_display_defaults(), $settings );
69
70 $ajaxposts = $this->query_args( $settings );
71
72 ob_start();
73 $found_posts = false;
74
75 if ( $ajaxposts->have_posts() ) {
76
77 while ( $ajaxposts->have_posts() ) {
78 $ajaxposts->the_post();
79 $found_posts = true;
80
81 $title = get_the_title();
82 $post_link = esc_url( get_permalink() );
83 $author_url = esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
84 $author_name = esc_html( get_the_author() );
85 $meta_sep = $settings['meta_separator'] ?? '/';
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-image-wrap">
91 <?php $this->render_image(get_post_thumbnail_id(), 'large'); ?>
92
93 <div class="upk-content">
94 <div class="upk-default-show">
95 <div class="upk-date-cetagory-wrap">
96 <div class="upk-date">
97 <?php
98 if ($settings['show_date'] === 'yes' && $settings['human_diff_time'] !== 'yes') {
99 echo esc_html(get_the_date());
100 }
101 if ($settings['human_diff_time'] === 'yes') {
102 echo esc_html(ultimate_post_kit_post_time_diff($settings['human_diff_time_short'] !== 'yes' ? 'short' : ''));
103 }
104 ?>
105 </div>
106 <?php if ($settings['show_time'] === 'yes') : ?>
107 <div class="upk-post-time">
108 <i class="upk-icon-clock" aria-hidden="true"></i>
109 <?php echo esc_html(get_the_time()); ?>
110 </div>
111 <?php endif; ?>
112
113 <?php if ($settings['show_category'] === 'yes') : ?>
114 <div class="upk-category">
115 <?php echo wp_kses_post(upk_get_category($post_type)); ?>
116 </div>
117 <?php endif; ?>
118 </div>
119
120 <?php if ($settings['show_title'] === 'yes') : ?>
121 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
122 <a
123 href="<?php echo esc_url($post_link); ?>"
124 title="<?php echo esc_attr($title); ?>"
125 class="title-animation-<?php echo esc_attr($settings['title_style']); ?>"
126 >
127 <?php echo esc_html($title); ?>
128 </a>
129 </<?php echo esc_attr( $title_tag ); ?>>
130 <?php endif; ?>
131 </div>
132
133 <div class="upk-default-hide">
134 <?php if (
135 $settings['show_author_avatar'] === 'yes' ||
136 $settings['show_author_name'] === 'yes' ||
137 $settings['show_date'] === 'yes' ||
138 $settings['show_reading_time'] === 'yes'
139 ) : ?>
140 <div class="upk-meta">
141 <?php if ($settings['show_author_avatar'] === 'yes') : ?>
142 <div class="upk-author-image">
143 <?php echo wp_kses_post(get_avatar(get_the_author_meta('ID'), 48)); ?>
144 </div>
145 <?php endif; ?>
146
147 <div class="upk-author-name-date-wrap">
148 <?php if ($settings['show_author_name'] === 'yes') : ?>
149 <div class="upk-author-name">
150 <a href="<?php echo esc_url($author_url); ?>"><?php echo esc_html($author_name); ?></a>
151 </div>
152 <?php endif; ?>
153
154 <?php if ($settings['show_date'] === 'yes' || $settings['show_reading_time'] === 'yes') : ?>
155 <div class="upk-date-reading-time" data-separator="<?php echo esc_html($meta_sep); ?>">
156 <?php if ($settings['show_date'] === 'yes') : ?>
157 <div class="upk-date">
158 <?php
159 if ($settings['human_diff_time'] === 'yes') {
160 echo esc_html(ultimate_post_kit_post_time_diff(
161 (($settings['human_diff_time_short'] ?? 'no') === 'yes') ? 'short' : ''
162 ));
163 } else {
164 echo get_the_date();
165 }
166 ?>
167 </div>
168 <?php endif; ?>
169
170 <?php if (function_exists('_is_upk_pro_activated') && _is_upk_pro_activated() && function_exists('ultimate_post_kit_reading_time') && ($settings['show_reading_time'] ?? '') === 'yes') : ?>
171 <div class="upk-reading-time" data-separator="<?php echo esc_html($meta_sep); ?>">
172 <?php echo esc_html(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 <?php endif; ?>
177 </div>
178 </div>
179 <?php endif; ?>
180
181 <?php if ($settings['show_excerpt'] === 'yes') : ?>
182 <div class="upk-text">
183 <?php
184 if (has_excerpt()) {
185 the_excerpt();
186 } else {
187 if (function_exists('ultimate_post_kit_custom_excerpt')) {
188 echo wp_kses_post(ultimate_post_kit_custom_excerpt(ultimate_post_kit_clamp_excerpt_length($settings['excerpt_length'] ?? 20, 20), false, ''));
189 } else {
190 echo esc_html(wp_trim_words(wp_strip_all_tags(get_the_content()), ultimate_post_kit_clamp_excerpt_length($settings['excerpt_length'] ?? 20, 20)));
191 }
192 }
193 ?>
194 </div>
195 <?php endif; ?>
196 </div>
197 </div>
198
199 <div class="upk-btn-comments-wrap">
200 <div class="upk-btn-wrap upk-flex">
201 <?php if ($settings['show_readmore'] === 'yes') : ?>
202 <a href="<?php echo esc_url($post_link); ?>" class="upk-readmore" target="<?php echo esc_attr($settings['upk_link_new_tab'] === 'yes' ? '_blank' : '_self'); ?>">
203 <span class="upk-flex upk-flex-middle">
204 <?php echo esc_html($settings['readmore_text'] ?? __('Read More', 'ultimate-post-kit')); ?>
205 <?php $upk_readmore_icon = ultimate_post_kit_sanitize_request_icon($settings['readmore_icon'] ?? null); ?>
206 <?php if ($upk_readmore_icon) : ?>
207 <span class="upk-readmore-btn-icon upk-flex-align-<?php echo esc_attr($settings['icon_align']); ?>">
208 <?php Icons_Manager::render_icon($upk_readmore_icon, ['aria-hidden' => 'true', 'class' => 'fa-fw']); ?>
209 </span>
210 <?php endif; ?>
211 </span>
212 </a>
213 <?php endif; ?>
214 </div>
215
216 <?php if ($settings['show_comments'] === 'yes') : ?>
217 <div class="upk-comments">
218 <?php echo esc_html( $this->upk_get_formatted_comments_count( get_the_ID() ) ); ?>
219 </div>
220 <?php endif; ?>
221 </div>
222 </div>
223 </div>
224 <?php
225 }
226 }
227
228 wp_reset_postdata();
229 $markup = ob_get_clean();
230
231 wp_send_json(
232 [
233 'success' => $found_posts,
234 'markup' => $found_posts ? $markup : esc_html__( 'No more found', 'ultimate-post-kit' ),
235 ]
236 );
237 }
238 }
239