PluginProbe
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets / 4.2.0
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets v4.2.0
4.5.6 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 All 148 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.2.0, at traits/global-widget-functions.php

448 lines 11.5 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_attr(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_attr(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_attr(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 $title = get_the_title();
323 printf(
324 '<%1$s class="upk-title"><a href="%2$s" title="%5$s" class="title-animation-%4$s" aria-label="%5$s">%3$s</a></%1$s>',
325 esc_attr(Utils::get_valid_html_tag($settings['title_tags'])),
326 esc_url( get_permalink() ),
327 esc_html( $title ),
328 esc_attr($settings['title_style']),
329 esc_attr( $title )
330 );
331 apply_filters('upk/' . $widget_name . '/after/title', '');
332 }
333
334
335
336 function render_category() {
337 if (!$this->get_settings('show_category')) {
338 return;
339 }
340 ?>
341 <div class="upk-category">
342 <?php echo wp_kses_post( upk_get_category($this->get_settings('posts_source')) ); ?>
343 </div>
344 <?php
345 }
346
347 function render_date() {
348 $settings = $this->get_settings_for_display();
349 if (!$this->get_settings('show_date')) {
350 return;
351 }
352 $meta_separator = isset( $settings['meta_separator'] ) ? $settings['meta_separator'] : '.';
353 ?>
354 <div class="upk-date">
355 <?php if ($settings['human_diff_time'] == 'yes') {
356 echo esc_html( ultimate_post_kit_post_time_diff( ($settings['human_diff_time_short'] == 'yes') ? 'short' : '' ) );
357 } else {
358 echo get_the_date();
359 } ?>
360 </div>
361
362 <?php if ($settings['show_time']) : ?>
363 <div class="upk-post-time" data-separator="<?php echo esc_attr( $meta_separator ); ?>">
364 <i class="upk-icon-clock" aria-hidden="true"></i>
365 <?php echo esc_html( get_the_time() ); ?>
366 </div>
367 <?php endif; ?>
368 <?php
369 }
370
371 function render_excerpt($excerpt_length) {
372 $settings = $this->get_settings_for_display();
373
374 if (!$this->get_settings('show_excerpt')) {
375 return;
376 }
377 $strip_shortcode = $this->get_settings_for_display('strip_shortcode');
378
379 $ellipsis = isset($settings['ellipsis']) ? $settings['ellipsis'] : '' ;
380 ?>
381 <div class="upk-text">
382 <?php
383 if (has_excerpt()) {
384 the_excerpt();
385 } else {
386 echo wp_kses_post( ultimate_post_kit_custom_excerpt($excerpt_length, $strip_shortcode, $ellipsis) );
387 }
388 ?>
389 </div>
390 <?php
391 }
392
393 /**
394 * Localized comment count with label. Echo with esc_html().
395 *
396 * @param int $post_id Post ID, or 0 for current post in The Loop.
397 * @return string
398 */
399 protected function upk_get_formatted_comments_count( $post_id = 0 ) {
400 return Utils::get_formatted_comments_count( $post_id );
401 }
402
403 /**
404 * Localized comment count number only. Echo with esc_html().
405 *
406 * @param int $post_id Post ID, or 0 for current post in The Loop.
407 * @return string
408 */
409 protected function upk_get_localized_comment_count( $post_id = 0 ) {
410 return Utils::get_localized_comment_count( $post_id );
411 }
412
413 function render_post_format() {
414 $settings = $this->get_settings_for_display();
415
416 if (!$settings['show_post_format']) {
417 return;
418 }
419 ?>
420 <div class="upk-post-format">
421 <a href="<?php echo esc_url(get_permalink()) ?>">
422 <?php if (has_post_format('aside')) : ?>
423 <i class="upk-icon-aside" aria-hidden="true"></i>
424 <?php elseif (has_post_format('gallery')) : ?>
425 <i class="upk-icon-gallery" aria-hidden="true"></i>
426 <?php elseif (has_post_format('link')) : ?>
427 <i class="upk-icon-link" aria-hidden="true"></i>
428 <?php elseif (has_post_format('image')) : ?>
429 <i class="upk-icon-image" aria-hidden="true"></i>
430 <?php elseif (has_post_format('quote')) : ?>
431 <i class="upk-icon-quote" aria-hidden="true"></i>
432 <?php elseif (has_post_format('status')) : ?>
433 <i class="upk-icon-status" aria-hidden="true"></i>
434 <?php elseif (has_post_format('video')) : ?>
435 <i class="upk-icon-video" aria-hidden="true"></i>
436 <?php elseif (has_post_format('audio')) : ?>
437 <i class="upk-icon-music" aria-hidden="true"></i>
438 <?php elseif (has_post_format('chat')) : ?>
439 <i class="upk-icon-chat" aria-hidden="true"></i>
440 <?php else : ?>
441 <i class="upk-icon-post" aria-hidden="true"></i>
442 <?php endif; ?>
443 </a>
444 </div>
445 <?php
446 }
447 }
448