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

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

228 lines 11.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\MapleGrid;
3 use UltimatePostKit\Traits\Global_Widget_Functions;
4
5 use UltimatePostKit\Base\Ultimate_Post_Kit_Module_Base;
6 use UltimatePostKit\Utils;
7
8 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
9
10 class Module extends Ultimate_Post_Kit_Module_Base {
11
12 use Global_Widget_Functions;
13
14 public function __construct() {
15 parent::__construct();
16
17 add_action( 'wp_ajax_nopriv_upk_maple_grid_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
18 add_action( 'wp_ajax_upk_maple_grid_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
19 }
20
21 public function get_name() {
22 return 'maple-grid';
23 }
24
25 public function get_widgets() {
26
27 $widgets = [
28 'Maple_Grid',
29 ];
30
31 return $widgets;
32 }
33
34 public function callback_ajax_loadmore_posts() {
35
36 $settings = [];
37
38 if ( isset( $_POST['settings'] ) && is_array( $_POST['settings'] ) ) {
39 $settings = map_deep( wp_unslash( $_POST['settings'] ), 'sanitize_text_field' );
40 }
41
42 $post_type = $settings['posts_source'] ?? 'post';
43
44 $settings = array_merge(
45 [
46 'posts_source' => 'post',
47 'posts_orderby' => 'date',
48 'posts_order' => 'DESC',
49 'posts_ignore_sticky_posts' => 'no',
50 'posts_only_with_featured_image' => 'no',
51 'posts_select_date' => '',
52 'posts_exclude_by' => [],
53 'posts_include_by' => [],
54 'posts_per_page' => isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 0,
55 'posts_offset' => isset( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 0,
56 ],
57 $settings
58 );
59
60 $ajaxposts = $this->query_args( $settings );
61
62 ob_start();
63 $found_posts = false;
64
65 if ( $ajaxposts->have_posts() ) {
66 $placeholder = \Elementor\Utils::get_placeholder_image_src();
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
77 $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
78 $image_src = $image_src ? $image_src[0] : $placeholder;
79
80 $meta_sep = $settings['meta_separator'] ?? '-';
81 $grid_style = $settings['grid_style'] ?? '1';
82 $title_tag = Utils::get_valid_html_tag($settings['title_tags']);
83
84 $onclick = '';
85 if ( ! empty( $settings['global_link'] ) && $settings['global_link'] === 'yes' ) {
86 $onclick = 'onclick="window.open(\'' . esc_url( $post_link ) . '\', \'_self\')"';
87 }
88
89 ?>
90 <div <?php echo $onclick; ?> class="upk-item">
91 <div class="upk-item-box">
92 <div class="upk-image-wrap">
93 <div class="upk-main-image">
94 <img class="upk-img" src="<?php echo esc_url( $image_src ); ?>" alt="<?php echo esc_attr( $title ); ?>">
95 </div>
96
97 <?php if ( $settings['show_post_format'] === 'yes' && $grid_style !== '3' ) : ?>
98 <div class="upk-post-format">
99 <a href="<?php echo esc_url($post_link); ?>">
100 <?php if ( has_post_format( 'aside' ) ) : ?>
101 <i class="upk-icon-aside" aria-hidden="true"></i>
102 <?php elseif ( has_post_format( 'gallery' ) ) : ?>
103 <i class="upk-icon-gallery" aria-hidden="true"></i>
104 <?php elseif ( has_post_format( 'link' ) ) : ?>
105 <i class="upk-icon-link" aria-hidden="true"></i>
106 <?php elseif ( has_post_format( 'image' ) ) : ?>
107 <i class="upk-icon-image" aria-hidden="true"></i>
108 <?php elseif ( has_post_format( 'quote' ) ) : ?>
109 <i class="upk-icon-quote" aria-hidden="true"></i>
110 <?php elseif ( has_post_format( 'status' ) ) : ?>
111 <i class="upk-icon-status" aria-hidden="true"></i>
112 <?php elseif ( has_post_format( 'video' ) ) : ?>
113 <i class="upk-icon-video" aria-hidden="true"></i>
114 <?php elseif ( has_post_format( 'audio' ) ) : ?>
115 <i class="upk-icon-music" aria-hidden="true"></i>
116 <?php elseif ( has_post_format( 'chat' ) ) : ?>
117 <i class="upk-icon-chat" aria-hidden="true"></i>
118 <?php else : ?>
119 <i class="upk-icon-post" aria-hidden="true"></i>
120 <?php endif; ?>
121 </a>
122 </div>
123 <?php endif; ?>
124
125 <?php if ( ( $settings['show_category'] ?? 'yes' ) === 'yes' && $grid_style !== '3' ) : ?>
126 <div class="upk-category">
127 <?php echo wp_kses_post(upk_get_category( $post_type )); ?>
128 </div>
129 <?php endif; ?>
130 </div>
131
132 <div class="upk-content">
133 <div class="upk-content-inner">
134 <?php if ( ( $settings['show_author_avatar'] ?? 'yes' ) === 'yes' || ( $settings['show_author_name'] ?? 'yes' ) === 'yes' || ( $settings['show_date'] ?? 'yes' ) === 'yes' || ( $settings['show_reading_time'] ?? 'no' ) === 'yes' ) : ?>
135 <div class="upk-meta">
136 <?php if ( $grid_style !== '3' && ( $settings['show_author_avatar'] == 'yes' || $settings['show_author_name'] == 'yes' ) ) : ?>
137 <div class="upk-author">
138 <?php if ($settings['show_author_avatar'] == 'yes') : ?>
139 <?php echo wp_kses_post(get_avatar(get_the_author_meta('ID'), 36)); ?>
140 <?php endif; ?>
141
142 <?php if ($settings['show_author_name'] == 'yes') : ?>
143 <a class="author-name" href="<?php echo esc_url( get_author_posts_url(get_the_author_meta('ID')) ); ?>">
144 <?php echo esc_html( get_the_author() ); ?>
145 </a>
146 <?php endif; ?>
147 </div>
148 <?php endif; ?>
149
150 <?php if ( ( $settings['show_date'] ?? 'yes' ) === 'yes' ) : ?>
151 <div class="upk-blog-date" data-separator="<?php echo esc_html( $meta_sep ); ?>">
152 <div class="upk-blog-date">
153 <a class="date" href="#">
154 <i class="upk-icon-calendar" aria-hidden="true"></i>
155 <?php
156 if ( ( $settings['human_diff_time'] ?? 'no' ) === 'yes' ) {
157 echo esc_html( ultimate_post_kit_post_time_diff( ( ( $settings['human_diff_time_short'] ?? 'no' ) === 'yes' ) ? 'short' : '' ) );
158 } else {
159 echo get_the_date();
160 }
161 ?>
162 </a>
163 </div>
164 <?php if ( ( $settings['show_time'] ?? 'no' ) === 'yes' ) : ?>
165 <div class="upk-post-time">
166 <i class="upk-icon-clock" aria-hidden="true"></i>
167 <?php echo esc_html( get_the_time() ); ?>
168 </div>
169 <?php endif; ?>
170 </div>
171 <?php endif; ?>
172
173 <?php if ( function_exists( '_is_upk_pro_activated' ) && _is_upk_pro_activated() && function_exists( 'ultimate_post_kit_reading_time' ) && ( $settings['show_reading_time'] ?? '' ) === 'yes' ) : ?>
174 <div class="upk-reading-time" data-separator="<?php echo esc_html( $meta_sep ); ?>">
175 <?php echo esc_html( ultimate_post_kit_reading_time( get_the_content(), $settings['avg_reading_speed'] ?? 200 ) ); ?>
176 </div>
177 <?php endif; ?>
178 </div>
179 <?php endif; ?>
180
181 <?php if ( ! isset( $settings['show_title'] ) || $settings['show_title'] === 'yes' ) : ?>
182 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
183 <a
184 href="<?php echo esc_url($post_link); ?>"
185 title="<?php echo esc_attr( $title ); ?>"
186 class="title-animation-<?php echo esc_attr( $settings['title_style'] ); ?>"
187 <?php echo $settings['upk_link_new_tab'] === 'yes' ? 'target="_blank"' : ''; ?>
188 >
189 <?php echo esc_html( $title ); ?>
190 </a>
191 </<?php echo esc_attr( $title_tag ); ?>>
192 <?php endif; ?>
193
194 <?php if ( ( $settings['show_excerpt'] ?? 'yes' ) === 'yes' && $grid_style !== '3' ) : ?>
195 <div class="upk-text">
196 <?php
197 if ( has_excerpt() ) {
198 the_excerpt();
199 } else {
200 if ( function_exists( 'ultimate_post_kit_custom_excerpt' ) ) {
201 echo wp_kses_post( ultimate_post_kit_custom_excerpt( intval( $settings['excerpt_length'] ?? 20 ), false, '' ) );
202 } else {
203 echo esc_html( wp_trim_words( wp_strip_all_tags( get_the_content() ), intval( $settings['excerpt_length'] ?? 20 ) ) );
204 }
205 }
206 ?>
207 </div>
208 <?php endif; ?>
209 </div>
210 </div>
211 </div>
212 </div>
213 <?php
214 }
215 }
216
217 wp_reset_postdata();
218 $markup = ob_get_clean();
219
220 wp_send_json(
221 [
222 'success' => $found_posts,
223 'markup' => $found_posts ? $markup : esc_html__( 'No more found', 'ultimate-post-kit' ),
224 ]
225 );
226
227 }
228 }