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

234 lines 12.3 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
37 $settings = [];
38
39 if ( isset( $_POST['settings'] ) && is_array( $_POST['settings'] ) ) {
40 $settings = map_deep( wp_unslash( $_POST['settings'] ), 'sanitize_text_field' );
41 }
42
43 $post_type = $settings['posts_source'] ?? 'post';
44
45 $settings = array_merge(
46 [
47 'posts_source' => 'post',
48 'posts_orderby' => 'date',
49 'posts_order' => 'DESC',
50 'posts_ignore_sticky_posts' => 'no',
51 'posts_only_with_featured_image' => 'no',
52 'posts_select_date' => '',
53 'posts_exclude_by' => [],
54 'posts_include_by' => [],
55 'posts_per_page' => isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 0,
56 'posts_offset' => isset( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 0,
57 ],
58 $settings
59 );
60
61 $ajaxposts = $this->query_args( $settings );
62
63 ob_start();
64 $found_posts = false;
65
66 if ( $ajaxposts->have_posts() ) {
67
68 while ( $ajaxposts->have_posts() ) {
69 $ajaxposts->the_post();
70 $found_posts = true;
71
72 $title = get_the_title();
73 $post_link = esc_url( get_permalink() );
74 $author_url = esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
75 $author_name = esc_html( get_the_author() );
76 $meta_sep = $settings['meta_separator'] ?? '/';
77 $title_tag = Utils::get_valid_html_tag($settings['title_tags']);
78
79 $onclick = '';
80 if ( ! empty( $settings['global_link'] ) && $settings['global_link'] === 'yes' ) {
81 $onclick = 'onclick="window.open(\'' . esc_url( $post_link ) . '\', \'_self\')"';
82 }
83
84 ?>
85 <div <?php echo $onclick; ?> class="upk-item">
86 <div class="upk-image-wrap">
87 <?php $this->render_image(get_post_thumbnail_id(), 'large'); ?>
88
89 <div class="upk-content">
90 <div class="upk-default-show">
91 <div class="upk-date-cetagory-wrap">
92 <div class="upk-date">
93 <?php
94 if ($settings['show_date'] === 'yes' && $settings['human_diff_time'] !== 'yes') {
95 echo esc_html(get_the_date());
96 }
97 if ($settings['human_diff_time'] === 'yes') {
98 echo esc_html(ultimate_post_kit_post_time_diff($settings['human_diff_time_short'] !== 'yes' ? 'short' : ''));
99 }
100 ?>
101 </div>
102 <?php if ($settings['show_time'] === 'yes') : ?>
103 <div class="upk-post-time">
104 <i class="upk-icon-clock" aria-hidden="true"></i>
105 <?php echo esc_html(get_the_time()); ?>
106 </div>
107 <?php endif; ?>
108
109 <?php if ($settings['show_category'] === 'yes') : ?>
110 <div class="upk-category">
111 <?php echo wp_kses_post(upk_get_category($post_type)); ?>
112 </div>
113 <?php endif; ?>
114 </div>
115
116 <?php if ($settings['show_title'] === 'yes') : ?>
117 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
118 <a
119 href="<?php echo esc_url($post_link); ?>"
120 title="<?php echo esc_attr($title); ?>"
121 class="title-animation-<?php echo esc_attr($settings['title_style']); ?>"
122 >
123 <?php echo esc_html($title); ?>
124 </a>
125 </<?php echo esc_attr( $title_tag ); ?>>
126 <?php endif; ?>
127 </div>
128
129 <div class="upk-default-hide">
130 <?php if (
131 $settings['show_author_avatar'] === 'yes' ||
132 $settings['show_author_name'] === 'yes' ||
133 $settings['show_date'] === 'yes' ||
134 $settings['show_reading_time'] === 'yes'
135 ) : ?>
136 <div class="upk-meta">
137 <?php if ($settings['show_author_avatar'] === 'yes') : ?>
138 <div class="upk-author-image">
139 <?php echo wp_kses_post(get_avatar(get_the_author_meta('ID'), 48)); ?>
140 </div>
141 <?php endif; ?>
142
143 <div class="upk-author-name-date-wrap">
144 <?php if ($settings['show_author_name'] === 'yes') : ?>
145 <div class="upk-author-name">
146 <a href="<?php echo esc_url($author_url); ?>"><?php echo esc_html($author_name); ?></a>
147 </div>
148 <?php endif; ?>
149
150 <?php if ($settings['show_date'] === 'yes' || $settings['show_reading_time'] === 'yes') : ?>
151 <div class="upk-date-reading-time" data-separator="<?php echo esc_html($meta_sep); ?>">
152 <?php if ($settings['show_date'] === 'yes') : ?>
153 <div class="upk-date">
154 <?php
155 if ($settings['human_diff_time'] === 'yes') {
156 echo esc_html(ultimate_post_kit_post_time_diff(
157 (($settings['human_diff_time_short'] ?? 'no') === 'yes') ? 'short' : ''
158 ));
159 } else {
160 echo get_the_date();
161 }
162 ?>
163 </div>
164 <?php endif; ?>
165
166 <?php if (function_exists('_is_upk_pro_activated') && _is_upk_pro_activated() && function_exists('ultimate_post_kit_reading_time') && ($settings['show_reading_time'] ?? '') === 'yes') : ?>
167 <div class="upk-reading-time" data-separator="<?php echo esc_html($meta_sep); ?>">
168 <?php echo esc_html(ultimate_post_kit_reading_time(get_the_content(), $settings['avg_reading_speed'], $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no' ) ); ?>
169 </div>
170 <?php endif; ?>
171 </div>
172 <?php endif; ?>
173 </div>
174 </div>
175 <?php endif; ?>
176
177 <?php if ($settings['show_excerpt'] === 'yes') : ?>
178 <div class="upk-text">
179 <?php
180 if (has_excerpt()) {
181 the_excerpt();
182 } else {
183 if (function_exists('ultimate_post_kit_custom_excerpt')) {
184 echo wp_kses_post(ultimate_post_kit_custom_excerpt(intval($settings['excerpt_length'] ?? 20), false, ''));
185 } else {
186 echo esc_html(wp_trim_words(wp_strip_all_tags(get_the_content()), intval($settings['excerpt_length'] ?? 20)));
187 }
188 }
189 ?>
190 </div>
191 <?php endif; ?>
192 </div>
193 </div>
194
195 <div class="upk-btn-comments-wrap">
196 <div class="upk-btn-wrap upk-flex">
197 <?php if ($settings['show_readmore'] === 'yes') : ?>
198 <a href="<?php echo esc_url($post_link); ?>" class="upk-readmore" target="<?php echo esc_attr($settings['upk_link_new_tab'] === 'yes' ? '_blank' : '_self'); ?>">
199 <span class="upk-flex upk-flex-middle">
200 <?php echo esc_html($settings['readmore_text'] ?? __('Read More', 'ultimate-post-kit')); ?>
201 <?php if ($settings['readmore_icon']['value']) : ?>
202 <span class="upk-readmore-btn-icon upk-flex-align-<?php echo esc_attr($settings['icon_align']); ?>">
203 <?php Icons_Manager::render_icon($settings['readmore_icon'], ['aria-hidden' => 'true', 'class' => 'fa-fw']); ?>
204 </span>
205 <?php endif; ?>
206 </span>
207 </a>
208 <?php endif; ?>
209 </div>
210
211 <?php if ($settings['show_comments'] === 'yes') : ?>
212 <div class="upk-comments">
213 <?php echo absint(get_comments_number()); ?> <?php echo esc_html_x('Comments', 'Frontend', 'ultimate-post-kit'); ?>
214 </div>
215 <?php endif; ?>
216 </div>
217 </div>
218 </div>
219 <?php
220 }
221 }
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