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.5 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 All 147 releases
ultimate-post-kit / traits / global-widget-functions.php

global-widget-functions.php in Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets 4.0.9, at traits/global-widget-functions.php

419 lines 10.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace UltimatePostKit\Traits;
4
5 use UltimatePostKit\Utils;
6
7 defined('ABSPATH') || die();
8
9 trait Global_Widget_Functions {
10
11 /**
12 * Render Ajax Qery Posts
13 */
14 function mapGroupControlQuery($term_ids = []) {
15 $terms = get_terms(
16 [
17 'term_taxonomy_id' => $term_ids,
18 'hide_empty' => false,
19 ]
20 );
21
22 $tax_terms_map = [];
23
24 foreach ($terms as $term) {
25 $taxonomy = $term->taxonomy;
26 $tax_terms_map[$taxonomy][] = $term->term_id;
27 }
28
29 return $tax_terms_map;
30 }
31 function query_args() {
32 extract($_POST['settings']);
33
34 // setmeta args
35 $args = [
36 'posts_per_page' => $_POST['per_page'],
37 'post_status' => 'publish',
38 'suppress_filters' => false,
39 'orderby' => $posts_orderby,
40 'order' => $posts_order,
41 'offset' => $_POST['offset'],
42 ];
43 /**
44 * set feature image
45 *
46 */
47 if (isset($posts_only_with_featured_image) && $posts_only_with_featured_image === 'yes') {
48 $args['meta_query'] = [
49 [
50 'key' => '_thumbnail_id',
51 'compare' => 'EXISTS',
52 ],
53 ];
54 }
55
56 /**
57 * set taxonomy query
58 */
59
60 /**
61 * set date query
62 */
63
64 $selected_date = $posts_select_date;
65
66 if (!empty($selected_date)) {
67 $date_query = [];
68
69 switch ($selected_date) {
70 case 'today':
71 $date_query['after'] = '-1 day';
72 break;
73
74 case 'week':
75 $date_query['after'] = '-1 week';
76 break;
77
78 case 'month':
79 $date_query['after'] = '-1 month';
80 break;
81
82 case 'quarter':
83 $date_query['after'] = '-3 month';
84 break;
85
86 case 'year':
87 $date_query['after'] = '-1 year';
88 break;
89
90 case 'exact':
91 $after_date = $posts_date_after;
92 if (!empty($after_date)) {
93 $date_query['after'] = $after_date;
94 }
95
96 $before_date = $posts_date_before;
97 if (!empty($before_date)) {
98 $date_query['before'] = $before_date;
99 }
100 $date_query['inclusive'] = true;
101 break;
102 }
103
104 if (!empty($date_query)) {
105 $args['date_query'] = $date_query;
106 }
107 }
108
109 $exclude_by = isset($posts_exclude_by) ? $posts_exclude_by : [];
110 $include_by = isset($posts_include_by) ? $posts_include_by : [];
111 $include_users = [];
112 $exclude_users = [];
113 // print_r($exclude_by);
114 /**
115 * ignore sticky post
116 */
117 if (!empty($exclude_by) && $posts_source === 'post' && $posts_ignore_sticky_posts === 'yes') {
118 $args['ignore_sticky_posts'] = true;
119 if (in_array('current_post', $exclude_by)) {
120 $args['post__not_in'] = [get_the_ID()];
121 }
122 }
123
124 /**
125 * set post type
126 */
127
128 if ($posts_source === 'manual_selection') {
129 /**
130 * Set Including Manually
131 */
132 $selected_ids = $posts_selected_ids;
133 $selected_ids = wp_parse_id_list($selected_ids);
134 $args['post_type'] = 'any';
135 if (!empty($selected_ids)) {
136 $args['post__in'] = $selected_ids;
137 }
138 $args['ignore_sticky_posts'] = 1;
139 } elseif ('current_query' === $posts_source) {
140 /**
141 * Make Current Query
142 */
143 $args = $GLOBALS['wp_query']->query_vars;
144 $args = apply_filters('element_pack/query/get_query_args/current_query', $args);
145 } elseif ('_related_post_type' === $posts_source) {
146 /**
147 * Set Related Query
148 */
149 $post_id = get_queried_object_id();
150 $related_post_id = is_singular() && (0 !== $post_id) ? $post_id : null;
151 $args['post_type'] = get_post_type($related_post_id);
152
153 // $include_by = $this->getGroupControlQueryParamBy('include');
154 if (in_array('authors', $include_by)) {
155 $args['author__in'] = wp_parse_id_list($settings['posts_include_author_ids']);
156 } else {
157 $args['author__in'] = get_post_field('post_author', $related_post_id);
158 }
159
160 // $exclude_by = $this->getGroupControlQueryParamBy('exclude');
161 if (in_array('authors', $exclude_by)) {
162 $args['author__not_in'] = wp_parse_id_list($posts_exclude_author_ids);
163 }
164
165 if (in_array('current_post', $exclude_by)) {
166 $args['post__not_in'] = [get_the_ID()];
167 }
168
169 $args['ignore_sticky_posts'] = 1;
170 $args = apply_filters('element_pack/query/get_query_args/related_query', $args);
171 } else {
172 $args['post_type'] = $posts_source;
173 $current_post = [];
174
175 /**
176 * Set Taxonomy && Set Authors
177 */
178 $include_terms = [];
179 $exclude_terms = [];
180 $terms_query = [];
181
182 /**
183 * Set exclude Terms
184 */
185 if (!empty($exclude_by)) {
186 if (in_array('authors', $exclude_by)) {
187 $exclude_users = wp_parse_id_list($posts_exclude_author_ids);
188 $include_users = array_diff($include_users, $exclude_users);
189 }
190 if (!empty($exclude_users)) {
191 $args['author__not_in'] = $exclude_users;
192 }
193 if (in_array('current_post', $exclude_by) && is_singular()) {
194 $current_post[] = get_the_ID();
195 }
196 if (in_array('manual_selection', $exclude_by)) {
197 $exclude_ids = $posts_exclude_ids;
198 $args['post__not_in'] = array_merge($current_post, wp_parse_id_list($exclude_ids));
199 }
200 if (in_array('terms', $exclude_by)) {
201 $exclude_terms = wp_parse_id_list($posts_exclude_term_ids);
202 $include_terms = array_diff($include_terms, $exclude_terms);
203 }
204 if (!empty($exclude_terms)) {
205 $tax_terms_map = $this->mapGroupControlQuery($exclude_terms);
206
207 foreach ($tax_terms_map as $tax => $terms) {
208 $terms_query[] = [
209 'taxonomy' => $tax,
210 'field' => 'term_id',
211 'terms' => $terms,
212 'operator' => 'NOT IN',
213 ];
214 }
215 }
216 }
217
218 /**
219 * Set include Terms
220 */
221 if (!empty($include_by)) {
222
223 if (in_array('authors', $include_by)) {
224 $include_users = wp_parse_id_list($posts_include_author_ids);
225 }
226 if (!empty($include_users)) {
227 $args['author__in'] = $include_users;
228 }
229 if (in_array('terms', $include_by)) {
230 $include_terms = wp_parse_id_list($posts_include_term_ids);
231 }
232 $tax_terms_map = $this->mapGroupControlQuery($include_terms);
233 foreach ($tax_terms_map as $tax => $terms) {
234 $terms_query[] = [
235 'taxonomy' => $tax,
236 'field' => 'term_id',
237 'terms' => $terms,
238 'operator' => 'IN',
239 ];
240 }
241 }
242
243
244 if (!empty($terms_query)) {
245 $args['tax_query'] = $terms_query;
246 $args['tax_query']['relation'] = 'AND';
247 }
248 }
249
250 $ajaxposts = new \WP_Query($args);
251 return $ajaxposts;
252 }
253
254 /**
255 * Render Ajax LoadMore
256 */
257 function render_ajax_loadmore() {
258 $settings = $this->get_settings_for_display();
259 if (!$this->get_settings('ajax_loadmore_enable')) {
260 return;
261 }
262 ?>
263 <div class="upk-loadmore-container">
264 <?php if ($settings['ajax_loadmore_btn'] == 'yes') : ?>
265 <span class="upk-loadmore-btn"><?php esc_html_e('Load More', 'ultimate-post-kit'); ?></span>
266 <?php elseif ($settings['ajax_loadmore_infinite_scroll'] == 'yes') : ?>
267 <div class="upk-ajax-loading" style="display: none;"></div>
268 <?php endif; ?>
269 </div>
270 <?php
271 }
272
273 /**
274 * New Image Render Method With Lazy Load Support
275 *
276 * @return void
277 */
278
279 function render_image($image_id, $size) {
280 $placeholder_image_src = Utils::get_placeholder_image_src();
281 $image_src = wp_get_attachment_image_src($image_id, $size);
282
283 if (!$image_src) {
284 printf('<img class="upk-img" src="%1$s" alt="%2$s">', esc_url($placeholder_image_src), esc_html(get_the_title()));
285 } else {
286 print(wp_get_attachment_image(
287 $image_id,
288 $size,
289 false,
290 [
291 'class' => 'upk-img',
292 'alt' => esc_html(get_the_title())
293 ]
294 ));
295 }
296 }
297
298 /**
299 * Old Image Render Method
300 * Not Using Anymore
301 * @return void
302 */
303 function __render_image($image_id, $size) {
304 $placeholder_image_src = Utils::get_placeholder_image_src();
305 $image_src = wp_get_attachment_image_src($image_id, $size);
306 if (!$image_src) {
307 $image_src = $placeholder_image_src;
308 } else {
309 $image_src = $image_src[0];
310 }
311 ?>
312 <img class="upk-img" src="<?php echo esc_url($image_src); ?>" alt="<?php echo esc_html(get_the_title()); ?>">
313 <?php
314 }
315
316 function render_title($widget_name) {
317 $settings = $this->get_settings_for_display();
318 if (!$this->get_settings('show_title')) {
319 return;
320 }
321 apply_filters('upk/' . $widget_name . '/before/title', '');
322 printf('<%1$s class="upk-title"><a href="%2$s" title="%3$s" class="title-animation-%4$s" >%3$s</a></%1$s>', esc_attr(Utils::get_valid_html_tag($settings['title_tags'])), esc_attr( get_permalink() ), esc_html( get_the_title() ), esc_attr($settings['title_style']));
323 apply_filters('upk/' . $widget_name . '/after/title', '');
324 }
325
326
327
328 function render_category() {
329 if (!$this->get_settings('show_category')) {
330 return;
331 }
332 ?>
333 <div class="upk-category">
334 <?php echo upk_get_category($this->get_settings('posts_source')); ?>
335 </div>
336 <?php
337 }
338
339 function render_date() {
340 $settings = $this->get_settings_for_display();
341 if (!$this->get_settings('show_date')) {
342 return;
343 }
344 ?>
345 <div class="upk-date">
346 <?php if ($settings['human_diff_time'] == 'yes') {
347 echo esc_html( ultimate_post_kit_post_time_diff( ($settings['human_diff_time_short'] == 'yes') ? 'short' : '' ) );
348 } else {
349 echo get_the_date();
350 } ?>
351 </div>
352
353 <?php if ($settings['show_time']) : ?>
354 <div class="upk-post-time">
355 <i class="upk-icon-clock" aria-hidden="true"></i>
356 <?php echo esc_html( get_the_time() ); ?>
357 </div>
358 <?php endif; ?>
359 <?php
360 }
361
362 function render_excerpt($excerpt_length) {
363 $settings = $this->get_settings_for_display();
364
365 if (!$this->get_settings('show_excerpt')) {
366 return;
367 }
368 $strip_shortcode = $this->get_settings_for_display('strip_shortcode');
369
370 $ellipsis = isset($settings['ellipsis']) ? $settings['ellipsis'] : '' ;
371 ?>
372 <div class="upk-text">
373 <?php
374 if (has_excerpt()) {
375 the_excerpt();
376 } else {
377 echo ultimate_post_kit_custom_excerpt($excerpt_length, $strip_shortcode, $ellipsis);
378 }
379 ?>
380 </div>
381 <?php
382 }
383
384 function render_post_format() {
385 $settings = $this->get_settings_for_display();
386
387 if (!$settings['show_post_format']) {
388 return;
389 }
390 ?>
391 <div class="upk-post-format">
392 <a href="<?php echo esc_url(get_permalink()) ?>">
393 <?php if (has_post_format('aside')) : ?>
394 <i class="upk-icon-aside" aria-hidden="true"></i>
395 <?php elseif (has_post_format('gallery')) : ?>
396 <i class="upk-icon-gallery" aria-hidden="true"></i>
397 <?php elseif (has_post_format('link')) : ?>
398 <i class="upk-icon-link" aria-hidden="true"></i>
399 <?php elseif (has_post_format('image')) : ?>
400 <i class="upk-icon-image" aria-hidden="true"></i>
401 <?php elseif (has_post_format('quote')) : ?>
402 <i class="upk-icon-quote" aria-hidden="true"></i>
403 <?php elseif (has_post_format('status')) : ?>
404 <i class="upk-icon-status" aria-hidden="true"></i>
405 <?php elseif (has_post_format('video')) : ?>
406 <i class="upk-icon-video" aria-hidden="true"></i>
407 <?php elseif (has_post_format('audio')) : ?>
408 <i class="upk-icon-music" aria-hidden="true"></i>
409 <?php elseif (has_post_format('chat')) : ?>
410 <i class="upk-icon-chat" aria-hidden="true"></i>
411 <?php else : ?>
412 <i class="upk-icon-post" aria-hidden="true"></i>
413 <?php endif; ?>
414 </a>
415 </div>
416 <?php
417 }
418 }
419