PluginProbe
Post Grid Gutenberg Blocks – PostX / 4.1.21
Post Grid Gutenberg Blocks – PostX v4.1.21
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / classes / Functions.php

Functions.php in Post Grid Gutenberg Blocks – PostX 4.1.21, at classes/Functions.php

2,546 lines 104.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Common Functions.
4 *
5 * @package ULTP\Functions
6 * @since v.1.0.0
7 */
8 namespace ULTP;
9
10 defined('ABSPATH') || exit;
11
12 /**
13 * Functions class.
14 */
15
16 class Functions{
17
18 /**
19 * @since v.3.2.4
20 * Instance of the class.
21 *
22 * @var Functions | null
23 */
24 private static $instance = null;
25
26 /**
27 * Setup class.
28 *
29 * @since v.1.0.0
30 */
31 public function __construct() {
32
33 }
34
35 /**
36 * Gets the instance of \ULTP\Functions class
37 *
38 * @return Functions
39 * @since v.3.2.4
40 */
41 public static function get_instance()
42 {
43 if (!isset ($GLOBALS['ultp_settings'])) {
44 $GLOBALS['ultp_settings'] = get_option('ultp_options');
45 }
46
47 if (is_null(self::$instance)) {
48 self::$instance = new self();
49 }
50
51 return self::$instance;
52 }
53
54 /**
55 * ID for the Builder Post or Normal Post
56 *
57 * @since v.2.3.1
58 * @return NUMBER | is Builder or not
59 */
60 public function get_ID() {
61 $id = $this->is_builder();
62 return $id ? $id : (function_exists('is_shop') ? (is_shop() ? wc_get_page_id('shop') : get_the_ID()) : get_the_ID() );
63 }
64
65 /**
66 * Checking Statement of Dynamic Site Builder
67 *
68 * @since v.2.3.1
69 * @return BOOLEAN | is Builder or not
70 */
71 public function is_archive_builder() {
72 $id = get_the_ID();
73 return get_post_type( $id ) == 'ultp_builder' ? get_post_meta( $id, '__ultp_builder_type', true ) : false;
74 }
75
76 /**
77 * Set Link with the Parameters
78 *
79 * @since v.1.1.0
80 * @return STRING | URL with Arg
81 */
82 public function get_premium_link( $url = '', $tag = 'go_premium') {
83 $url_list = array(
84 // PostX Dashboard Menu
85 'menu_save_temp_pro' => array(
86 'utm_source' => 'postx-menu',
87 'utm_medium' => 'ST-go_pro',
88 'utm_campaign' => 'postx-dashboard'
89 ),
90 // PostX Dashboard
91 'dashboard_go_pro' => array(
92 'utm_source' => 'db-postx-plugin',
93 'utm_medium' => 'left-menu-upgrade',
94 'utm_campaign' => 'postx-dashboard'
95 ),
96 'dashboard_db_banner' => array(
97 'utm_source' => 'postx-ad',
98 'utm_medium' => 'DB-banner',
99 'utm_campaign' => 'postx-dashboard'
100 ),
101 // Plugin Directory
102 'plugin_dir_pro' => array(
103 'utm_source' => 'db-postx-plugin',
104 'utm_medium' => 'upgrade',
105 'utm_campaign' => 'postx-dashboard'
106 ),
107 'plugin_dir_support' => array(
108 'utm_source' => 'postx_plugin',
109 'utm_medium' => 'support',
110 'utm_campaign' => 'postx-dashboard'
111 )
112 );
113 $url = $url ? $url : 'https://www.wpxpo.com/postx/pricing/';
114 $affiliate_id = apply_filters( 'ultp_affiliate_id', FALSE );
115 $arg = array();
116 if($tag && isset($url_list[$tag])){
117 $arg = $url_list[$tag];
118 } else {
119 $arg = array( 'utm_source' => $tag );
120 }
121 if ( ! empty( $affiliate_id ) ) {
122 $arg[ 'ref' ] = esc_attr( $affiliate_id );
123 }
124 return add_query_arg( $arg, $url );
125 }
126
127
128 /**
129 * Quick Query
130 *
131 * @since v.1.1.0
132 * @return ARRAY | Query Arg
133 */
134 public function get_quick_query($prams, $args) {
135 switch ($prams['queryQuick']) {
136 case 'related_posts':
137 global $post;
138 $p_id = isset($post->ID) && $post->ID ? $post->ID : (isset($_POST['postId']) ? sanitize_text_field($_POST['postId']) : ''); //phpcs:disable WordPress.Security.NonceVerification.Missing
139 if ($p_id) {
140 $args['post__not_in'] = array($p_id);
141 }
142 break;
143 case 'related_tag':
144 global $post;
145 $p_id = isset($post->ID) && $post->ID ? $post->ID : (isset($prams['current_post']) && $prams['current_post'] ? $prams['current_post'] : (isset($_POST['postId']) ? sanitize_text_field($_POST['postId']) : '')); //phpcs:disable ordPress.Security.NonceVerification.Missing
146 if ($p_id) {
147 $args['tax_query'] = array(
148 array(
149 'taxonomy' => 'post_tag',
150 'terms' => $this->get_terms_id($p_id, 'post_tag'),
151 'field' => 'term_id',
152 )
153 );
154 $args['post__not_in'] = array($p_id);
155 }
156 break;
157 case 'related_category':
158 global $post;
159 $p_id = isset($post->ID) && $post->ID ? $post->ID : (isset($prams['current_post']) && $prams['current_post'] ? $prams['current_post'] : (isset($_POST['postId']) ? sanitize_text_field($_POST['postId']) : '')); //phpcs:disable ordPress.Security.NonceVerification.Missing
160 if ($p_id) {
161 $args['tax_query'] = array(
162 array(
163 'taxonomy' => 'category',
164 'terms' => $this->get_terms_id($p_id, 'category'),
165 'field' => 'term_id',
166 )
167 );
168 $args['post__not_in'] = array($p_id);
169 }
170 break;
171 case 'related_cat_tag':
172 global $post;
173 $p_id = isset($post->ID) && $post->ID ? $post->ID : (isset($prams['current_post']) && $prams['current_post'] ? $prams['current_post'] : (isset($_POST['postId']) ? sanitize_text_field($_POST['postId']) : '')); //phpcs:disable ordPress.Security.NonceVerification.Missing
174 if ($p_id) {
175 $args['tax_query'] = array(
176 array(
177 'taxonomy' => 'post_tag',
178 'terms' => $this->get_terms_id($p_id, 'post_tag'),
179 'field' => 'term_id',
180 ),
181 array(
182 'taxonomy' => 'category',
183 'terms' => $this->get_terms_id($p_id, 'category'),
184 'field' => 'term_id',
185 )
186 );
187 $args['post__not_in'] = array($p_id);
188 }
189 break;
190 case 'sticky_posts':
191 $sticky = get_option('sticky_posts');
192 if (is_array($sticky)) {
193 rsort($sticky);
194 // $sticky = array_slice($sticky, 0, $args['posts_per_page']);
195 }
196 $args['ignore_sticky_posts'] = 1;
197 $args['post__in'] = $sticky;
198 break;
199 case 'latest_post_published':
200 $args['orderby'] = 'date';
201 $args['order'] = 'DESC';
202 $args['ignore_sticky_posts'] = 1;
203 break;
204 case 'latest_post_modified':
205 $args['orderby'] = 'modified';
206 $args['order'] = 'DESC';
207 $args['ignore_sticky_posts'] = 1;
208 break;
209 case 'oldest_post_published':
210 $args['orderby'] = 'date';
211 $args['order'] = 'ASC';
212 break;
213 case 'oldest_post_modified':
214 $args['orderby'] = 'modified';
215 $args['order'] = 'ASC';
216 break;
217 case 'alphabet_asc':
218 $args['orderby'] = 'title';
219 $args['order'] = 'ASC';
220 break;
221 case 'alphabet_desc':
222 $args['orderby'] = 'title';
223 $args['order'] = 'DESC';
224 break;
225 case 'random_post':
226 $args['orderby'] = 'rand';
227 $args['order'] = 'ASC';
228 break;
229 case 'random_post_7_days':
230 $args['orderby'] = 'rand';
231 $args['order'] = 'ASC';
232 $args['date_query'] = array( array( 'after' => '1 week ago') );
233 break;
234 case 'random_post_30_days':
235 $args['orderby'] = 'rand';
236 $args['order'] = 'ASC';
237 $args['date_query'] = array( array( 'after' => '1 month ago') );
238 break;
239 case 'most_comment':
240 $args['orderby'] = 'comment_count';
241 $args['order'] = 'DESC';
242 break;
243 case 'most_comment_1_day':
244 $args['orderby'] = 'comment_count';
245 $args['order'] = 'DESC';
246 $args['date_query'] = array( array( 'after' => '1 day ago') );
247 break;
248 case 'most_comment_7_days':
249 $args['orderby'] = 'comment_count';
250 $args['order'] = 'DESC';
251 $args['date_query'] = array( array( 'after' => '1 week ago') );
252 break;
253 case 'most_comment_30_days':
254 $args['orderby'] = 'comment_count';
255 $args['order'] = 'DESC';
256 $args['date_query'] = array( array( 'after' => '1 month ago') );
257 break;
258 case 'popular_post_1_day_view':
259 $args['meta_key'] = '__post_views_count';
260 $args['orderby'] = 'meta_value_num';
261 $args['order'] = 'DESC';
262 $args['date_query'] = array( array( 'after' => '1 day ago') );
263 break;
264 case 'popular_post_7_days_view':
265 $args['meta_key'] = '__post_views_count';
266 $args['orderby'] = 'meta_value_num';
267 $args['order'] = 'DESC';
268 $args['date_query'] = array( array( 'after' => '1 week ago') );
269 break;
270 case 'popular_post_30_days_view':
271 $args['meta_key'] = '__post_views_count';
272 $args['orderby'] = 'meta_value_num';
273 $args['order'] = 'DESC';
274 $args['date_query'] = array( array( 'after' => '1 month ago') );
275 break;
276 case 'popular_post_all_times_view':
277 $args['meta_key'] = '__post_views_count';
278 $args['orderby'] = 'meta_value_num';
279 $args['order'] = 'DESC';
280 break;
281 default:
282 # code...
283 break;
284 }
285 return $args;
286 }
287
288 /**
289 * Get All Term ID as Array
290 *
291 * @since v.2.4.12
292 * @return ARRAY | Query Arg
293 */
294 public function get_terms_id($id, $type) {
295 $data = array();
296 $arr = get_the_terms($id, $type);
297 if (is_array($arr)) {
298 foreach ($arr as $key => $val) {
299 $data[] = $val->term_id;
300 }
301 }
302 return $data;
303 }
304
305 /**
306 * Get All Reusable ID
307 *
308 * @since v.1.1.0
309 * @return ARRAY | Query Arg
310 */
311 public function get_reusable_ids( $post_id ) {
312 $reusable_id = array();
313 if ( $post_id ) {
314 $post = get_post($post_id);
315 if ( isset($post->post_content) ) {
316 if (
317 has_blocks($post->post_content) &&
318 strpos($post->post_content, 'wp:block') &&
319 strpos($post->post_content, '"ref"') !== false
320 ) {
321 $blocks = parse_blocks($post->post_content);
322 foreach ($blocks as $key => $value) {
323 if ( isset($value['attrs']['ref']) ) {
324 $reusable_id[] = $value['attrs']['ref'];
325 }
326 }
327 }
328 }
329 }
330 return $reusable_id;
331 }
332
333 /**
334 * get directory file contents
335 *
336 * @since v.4.1.8
337 * @return ARRAY | Query Arg
338 */
339 public function get_path_file_contents($path) {
340 global $wp_filesystem;
341 if (! $wp_filesystem ) {
342 require_once( ABSPATH . 'wp-admin/includes/file.php' );
343 $init_fs = WP_Filesystem();
344 if ( !$init_fs ) {
345 return '';
346 }
347 }
348
349 if ( $wp_filesystem->exists($path) ) {
350 return $wp_filesystem->get_contents($path);
351 } else {
352 return '';
353 }
354 }
355
356 /**
357 * build css for inline printing // used for some builder
358 *
359 * @since v.4.1.8
360 * @return ARRAY | Query Arg
361 */
362 public function build_css_for_inline_print( $post_id, $call_common=true ) {
363 if ( $post_id ) {
364 $upload_dir_url = wp_get_upload_dir();
365 $upload_css_dir_url = trailingslashit( $upload_dir_url['basedir'] );
366
367 $css_dir_url = trailingslashit( $upload_dir_url['baseurl'] );
368 if ( is_ssl() ) {
369 $css_dir_url = str_replace('http://', 'https://', $css_dir_url);
370 }
371 $reusable_css = '';
372 $reusable_id = $this->get_reusable_ids($post_id);
373 if ( !empty($reusable_id) ) {
374 foreach ( $reusable_id as $id ) {
375 $reusable_dir_path = $upload_css_dir_url."ultimate-post/ultp-css-{$id}.css";
376 if (file_exists( $reusable_dir_path )) {
377 $reusable_css .= $this->get_path_file_contents($reusable_dir_path);
378 } else {
379 $reusable_css .= get_post_meta($reusable_id, '_ultp_css', true);
380 }
381 }
382 }
383
384 $css_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
385 $css = '';
386 if (file_exists( $css_dir_path ) ) {
387 $css = $this->get_path_file_contents($css_dir_path);
388 } else {
389 $css = get_post_meta($post_id, '_ultp_css', true);
390 }
391 if ( $reusable_css.$css ) {
392 if ( $call_common ) {
393 $this->register_scripts_common();
394 }
395 return '<style id="ultp-post-'.$post_id.'" type="text/css">'.wp_strip_all_tags($reusable_css.$css).'</style>';
396 }
397 }
398 return '';
399 }
400
401
402 /**
403 * Get Global Plugin Settings
404 *
405 * @since v.1.0.0
406 * @param STRING | Key of the Option
407 * @return ARRAY | STRING
408 */
409 public function get_setting($key = '') {
410 $data = $GLOBALS['ultp_settings'];
411 if ($key != '') {
412 return isset($data[$key]) ? $data[$key] : '';
413 } else {
414 return $data;
415 }
416 }
417
418
419 /**
420 * Set Option Settings
421 *
422 * @since v.1.0.0
423 * @param STRING | Key of the Option (STRING), Value (STRING)
424 * @return NULL
425 */
426 public function set_setting($key = '', $val = '') {
427 if ($key != '') {
428 $data = $GLOBALS['ultp_settings'];
429 $data[$key] = $val;
430 update_option('ultp_options', $data);
431 $GLOBALS['ultp_settings'] = $data;
432 do_action('ultp_settings_updated',$key,$val);
433 }
434 }
435
436
437 /**
438 * Get Image HTML
439 *
440 * @since v.1.0.0
441 * @param | URL (STRING) | size (STRING) | class (STRING) | alt (STRING)
442 * @return STRING
443 */
444 public function get_image_html($url = '', $size = 'full', $class = '', $alt = '', $lazy = '', $darkImg=[], $srcset = '') {
445 $class = sanitize_html_class($class);
446 $alt = preg_replace('/[^A-Za-z0-9_ -]/', '', $alt);
447 $hasDarkImage = ( $darkImg['enable'] && $darkImg['url'] ) ? ' ultp-light-image-block ' : '';
448 $alt = $alt ? ' alt="'.$alt.'" ' : '';
449 $lazy_data = $lazy ? ' loading="lazy"' : '';
450
451 $dlMode = isset($_COOKIE['ultplocalDLMode']) ? $_COOKIE['ultplocalDLMode'] : ultimate_post()->get_dl_mode();
452
453 $lightMode = $hasDarkImage ? ( $dlMode == 'ultplight' ? '' : 'inactive ' ) : '';
454 $darkMode = $hasDarkImage ? ( $hasDarkImage && $dlMode == 'ultpdark' ? '' : ' inactive ' ) : '';
455
456 $image = '<img '.$lazy_data.$srcset.' class="'.$class.$hasDarkImage.$lightMode.'" '.$alt.' src="'.esc_url($url).'" />';
457 if( $hasDarkImage ) {
458 $image .= '<img '.$lazy_data.$darkImg['srcset'].' class="'.$class.$darkMode.' ultp-dark-image-block " '.$alt.' src="'.esc_url($darkImg['url']).'" />';
459 }
460 return $image;
461 }
462
463
464 /**
465 * Get Image HTML
466 *
467 * @since v.1.0.0
468 * @param | Attach ID (STRING) | size (STRING) | class (STRING) | alt (STRING)
469 * @return STRING
470 */
471 public function get_image($attach_id, $size = 'full', $class = '', $alt = '', $srcset = '', $lazy = '') {
472 $img_alt = get_post_meta($attach_id, '_wp_attachment_image_alt', true);
473 $alt = $img_alt ? $img_alt : $alt;
474 $alt = $alt ? ' alt="'.esc_html($alt).'" ' : '';
475 $class = $class ? ' class="'.$class.'" ' : '';
476 $size = ( ultimate_post()->get_setting('disable_image_size') == 'yes' && strpos($size, 'ultp_layout_') !== false ) ? 'full' : $size;
477 $lazy_data = $lazy ? ' loading="lazy"' : '';
478 $srcset_data = $srcset ? ' srcset="'.esc_attr(wp_get_attachment_image_srcset($attach_id)).'"' : '';
479 return '<img '.$srcset_data.$lazy_data.$class.$alt.' src="'.wp_get_attachment_image_url( $attach_id, $size ).'" />';
480 }
481
482
483 /**
484 * Get Excerpt Text
485 *
486 * @since v.1.0.0
487 * @param | Post ID (STRING) | Limit (NUMBER)
488 * @return STRING
489 */
490 public function excerpt( $post_id, $limit = 55 ) {
491 $content = preg_replace('/(\[postx_template[\s\w="]*)]/m', '', get_the_excerpt( $post_id )); // Remove postx_template shortcode form Content
492 return apply_filters( 'the_excerpt', wp_trim_words($content, $limit) );
493 }
494
495 /**
496 * Builder Attributes
497 *
498 * @since v.1.0.0
499 * @param STRING type
500 * @return STRING
501 */
502 public function get_builder_attr($type) {
503 $builder_data = '';
504 if ($type == 'archiveBuilder') {
505 if (is_archive()) {
506 if (is_date()) {
507 if (is_year()) {
508 $builder_data = 'date###'.get_the_date('Y');
509 } else if (is_month() ) {
510 $builder_data = 'date###'.get_the_date('Y-n');
511 } else if (is_day() ) {
512 $builder_data = 'date###'.get_the_date('Y-n-j');
513 }
514 } else if (is_author()) {
515 $builder_data = 'author###'.get_the_author_meta('ID');
516 } else {
517 $obj = get_queried_object();
518 if (isset($obj->taxonomy)) {
519 $builder_data = 'taxonomy###'.$obj->taxonomy.'###'.$obj->slug;
520 }
521 }
522 } else if (is_search()) {
523 $builder_data = 'search###'.get_search_query(true);
524 }
525 }
526 return $builder_data ? 'data-builder="'.$builder_data.'"' : '';
527 }
528
529
530 public function is_builder($builder = '') {
531 $id = '';
532 if ( ultimate_post()->get_setting('ultp_builder') != 'false' ) {
533 $page_id = ultimate_post()->builder_check_conditions('return_ib');
534 if ( $page_id ) {
535 $id = $page_id;
536 }
537 }
538 return $id;
539 }
540
541
542 /**
543 * Get Post Number Depending On Device
544 *
545 * @since v.2.5.4
546 * @param MULTIPLE | Attribute of Posts
547 * @return STRING
548 */
549 public function get_post_number($preDef, $prev, $current) {
550
551 $current = is_object($current) ? json_decode(wp_json_encode($current), true) : $current;
552 if ( ['lg'=> $preDef, 'sm'=> $preDef, 'xs'=> $preDef] == $current ) {
553 if ( $preDef != $prev ) {
554 return $prev;
555 }
556 }
557
558 $lg = isset($current['lg']) ? $current['lg'] : $prev;
559 $sm = isset($current['sm']) ? $current['sm'] : $lg;
560 $xs = isset($current['xs']) ? $current['xs'] : $lg;
561 if ( $lg == $sm && $sm == $xs ) {
562 return $lg;
563 } else {
564 global $ultpDevide;
565 $currentDevice = !empty($ultpDevide) ? $ultpDevide : $this->isDevice();
566 if ( $currentDevice == 'mobile' ) {
567 return $xs;
568 } else if ( $currentDevice == 'tablet' ) {
569 return $sm;
570 } else {
571 return $lg;
572 }
573 }
574 }
575
576
577 /**
578 * Get Post Number Depending On Device
579 *
580 * @since v.2.5.4
581 * @param NULL
582 * @return STRING | Device Type
583 */
584 public function isDevice(){
585 $useragent = isset($_SERVER['HTTP_USER_AGENT']) ? sanitize_key($_SERVER['HTTP_USER_AGENT']) : '';
586 $device = 'desktop';
587 if ( $useragent ) {
588 if ( preg_match('/(tablet|ipad|playbook)|(android(?!.*(mobi|opera mini)))/i', strtolower($useragent)) ) {
589 $device = 'tablet';
590 } else if ( preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($useragent,0,4))) {
591 $device = 'mobile';
592 }
593 }
594 global $ultpDevide;
595 $ultpDevide = $device;
596 return $device;
597 }
598
599
600 /**
601 * Get Raw Value from Objects
602 *
603 * @since v.2.5.3
604 * @param NULL
605 * @return STRING | Device Type
606 */
607 public function get_value($attr) {
608 $data = [];
609 if ( is_array($attr) ) {
610 foreach ($attr as $val) {
611 $data[] = $val->value;
612 }
613 }
614 return $data;
615 }
616
617 /**
618 * QueryArgs for Filter
619 *
620 * @since v.2.8.9
621 * @param ARRAY | Attribute of the Query
622 * @return ARRAY
623 */
624 public function getFilterQueryArgs( $attr ) {
625 $tax_value = (strlen($attr['queryTaxValue']) > 2) ? $attr['queryTaxValue'] : [];
626 $tax_value = is_array($tax_value) ? $tax_value : json_decode($tax_value);
627
628 $tax_value = (isset($tax_value[0]) && is_object($tax_value[0])) ? $this->get_value($tax_value) : $tax_value;
629
630 if (is_array($tax_value) && count($tax_value) > 0) {
631 $relation = isset($attr['queryRelation']) ? $attr['queryRelation'] : 'OR';
632
633 // Adv Filter Query Relation Override
634 if (isset($attr['advFilterEnable']) && $attr['advFilterEnable'] === true && isset($attr['advRelation'])) {
635 $relation = 'AND' === $attr['advRelation'] || 'OR' === $attr['advRelation'] ? $attr['advRelation'] : $relation;
636 }
637
638 $var = array('relation'=>$relation);
639 foreach ($tax_value as $val) {
640 $tax_name = $attr['queryTax'];
641 // For Custom Terms
642 if ($attr['queryTax'] == 'multiTaxonomy') {
643 $temp = explode('###', $val);
644 if (isset($temp[1])) {
645
646 if ($temp[1] === "_all") {
647 continue;
648 }
649
650 $val = $temp[1];
651 $tax_name = $temp[0];
652 }
653 }
654 $var[] = array('taxonomy'=> $tax_name, 'field' => 'slug', 'terms' => $val );
655 }
656
657 }
658 return isset($var) ? $var : [];
659 }
660
661 /**
662 * Query Builder
663 *
664 * @since v.1.0.0
665 * @param ARRAY | Attribute of the Query
666 * @return ARRAY
667 */
668 public function get_query($attr) {
669 $builder = isset($attr['builder']) ? $attr['builder'] : '';
670 $post_type = isset($attr['queryType']) ? $attr['queryType'] : 'post';
671 if ( $post_type == 'archiveBuilder' && ($builder || $this->is_builder($builder)) ) {
672 $archive_query = array();
673 if ($builder) {
674 $str = explode('###', $builder);
675 if (isset($str[0])) {
676 if ($str[0] == 'taxonomy') {
677 if (isset($str[1]) && isset($str[2])) {
678 $archive_query['tax_query'] = array(
679 array(
680 'taxonomy' => $str[1],
681 'field' => 'slug',
682 'terms' => $str[2]
683 )
684 );
685 }
686 } else if ($str[0] == 'author') {
687 if (isset($str[1])) {
688 $archive_query['author'] = $str[1];
689 }
690 } else if ($str[0] == 'search') {
691 if (isset($str[1])) {
692 $archive_query['s'] = $str[1];
693 }
694 } else if ($str[0] == 'date') {
695 if (isset($str[1])) {
696 $all_date = explode('-', $str[1]);
697 if (!empty($all_date)) {
698 $arg = array();
699 if (isset($all_date[0])) { $arg['year'] = $all_date[0]; }
700 if (isset($all_date[1])) { $arg['month'] = $all_date[1]; }
701 if (isset($all_date[2])) { $arg['day'] = $all_date[2]; }
702 $archive_query['date_query'][] = $arg;
703 }
704 }
705 }
706 }
707 } else {
708 global $wp_query;
709 $archive_query = $wp_query->query_vars;
710 }
711 $archive_query['posts_per_page'] = isset($attr['queryNumber']) ? $attr['queryNumber'] : 1;
712 $archive_query['paged'] = isset($attr['paged']) ? $attr['paged'] : 1;
713
714 $archive_query['paged'] = ! wp_doing_ajax() && isset( $_GET[ $attr['blockId'] . '_page' ] ) && is_numeric( $_GET[ $attr['blockId'] . '_page' ] ) ?
715 intval($_GET[ $attr['blockId'] . '_page' ]) :
716 $archive_query['paged'];
717
718 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
719 $offset = $this->get_offset($attr['queryOffset'], $archive_query);
720 $archive_query = array_merge($archive_query, $offset);
721 }
722
723 // Include Remove from Version 2.5.4
724 if (isset($attr['queryInclude']) && $attr['queryInclude']) {
725 $_include = explode(',', $attr['queryInclude']);
726 if (is_array($_include) && count($_include)) {
727 $archive_query['post__in'] = isset($archive_query['post__in']) ? array_merge($archive_query['post__in'], $_include) : $_include;
728 $archive_query['ignore_sticky_posts'] = 1;
729 $archive_query['orderby'] = 'post__in';
730 }
731 }
732
733 if (isset($attr['queryExclude']) && $attr['queryExclude']) {
734 $_exclude = (substr($attr['queryExclude'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryExclude'])) : explode(',', $attr['queryExclude']);
735 if (is_array($_exclude) && count($_exclude)) {
736 $archive_query['post__not_in'] = isset($archive_query['post__not_in']) ? array_merge($archive_query['post__not_in'], $_exclude) : $_exclude;
737 }
738 }
739
740
741 if(isset($attr['querySticky']) && $attr['querySticky']) {
742 if (filter_var($attr['querySticky'], FILTER_VALIDATE_BOOLEAN)) {
743 $sticky = get_option( 'sticky_posts', [] );
744 $archive_query['post__not_in'] = isset($archive_query['post__not_in']) ? array_merge($archive_query['post__not_in'], $sticky) : $sticky;
745 }
746 }
747 // ===============
748 if (isset($attr['queryUnique']) && $attr['queryUnique']) {
749 global $unique_ID;
750 if (isset($unique_ID[$attr['queryUnique']])) {
751 $archive_query['post__not_in'] = isset($archive_query['post__not_in']) ? array_merge($archive_query['post__not_in'], $unique_ID[$attr['queryUnique']]) : $unique_ID[$attr['queryUnique']];
752 }
753 }
754 // ===============
755
756 $archive_query['post_status'] = 'publish';
757 if (is_user_logged_in()) {
758 if( current_user_can('editor') || current_user_can('administrator') ) {
759 $archive_query['post_status'] = array('publish', 'private');
760 }
761 }
762
763 if(!isset($archive_query['orderby'])) {
764 $archive_query['orderby'] = isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date';
765 }
766
767 // Quick Query Support for Builder
768 if (isset($attr['queryQuick'])) {
769 if ($attr['queryQuick'] != '') {
770 $archive_query = ultimate_post()->get_quick_query($attr, $archive_query);
771 }
772 }
773
774 if (!isset($attr['ajaxCall'])) {
775 if(isset($attr['filterShow']) && $attr['filterShow'] && $attr['filterShow'] != 'false') {
776 if(isset($attr['filterType']) && isset($attr['filterValue']) ) {
777 $filterValue = strlen($attr['filterValue']) > 2 ? $attr['filterValue'] : [];
778 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
779 if (count($filterValue) > 0 && $attr['filterType']) {
780 $final = array('relation' => 'OR');
781 foreach ($filterValue as $key => $val) {
782 $final[] = array(
783 'taxonomy' => $attr['filterType'],
784 'field' => 'slug',
785 'terms' => $val,
786 );
787 }
788 $archive_query['tax_query'] = $final;
789 }
790 }
791 }
792 }
793 // from v.3.0.7 - for search builder
794 if(is_search()){
795 $archive_query['orderby'] = 'relevance';
796 }
797
798 return apply_filters('ultp_archive_query', $archive_query);
799 }
800
801 // When you use load more pagination block for a grid that did not have load more feature,
802 // the incoming posts would not align properly with the blocks design and looked bad.
803 // This fixes that.
804 if (
805 isset($attr['paginationType']) &&
806 isset($attr['queryNumber2']) &&
807 isset($attr['notFirstLoad']) &&
808 $attr['paginationType'] === "loadMore" &&
809 $attr['notFirstLoad']
810 ) {
811 $query_number = $attr['queryNumber2'];
812 // $query_number = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
813 } else {
814 $query_number = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
815 }
816
817 $paged = isset($attr['paged']) ? $attr['paged'] : 1;
818 $paged = ! wp_doing_ajax() &&
819 isset( $_GET[ $attr['blockId'] . '_page' ] ) &&
820 is_numeric( $_GET[ $attr['blockId'] . '_page' ] ) ?
821 intval($_GET[ $attr['blockId'] . '_page' ]) :
822 $paged;
823
824 $query_args = array(
825 'posts_per_page' => $query_number,
826 'post_type' => $post_type == 'archiveBuilder' ? 'post' : $post_type,
827 'orderby' => isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date',
828 'order' => isset($attr['queryOrder']) ? $attr['queryOrder'] : 'desc',
829 'paged' => $paged,
830 'post_status' => 'publish'
831 );
832
833 // For Private Post 'private'
834 if (is_user_logged_in()) {
835 if( current_user_can('editor') || current_user_can('administrator') ) {
836 $query_args['post_status'] = array('publish', 'private');
837 }
838 }
839
840 if ($attr['queryType'] == 'posts') {
841 if (isset($attr['queryPosts']) && $attr['queryPosts']) {
842 unset($query_args['post_type']);
843 $data = json_decode(isset($attr['queryPosts'])?$attr['queryPosts']:'[]');
844 $final = $this->get_value($data);
845 if (count($final) > 0) {
846 $query_args['post__in'] = $final;
847 // $query_args['posts_per_page'] = -1;
848 }
849 $query_args['ignore_sticky_posts'] = 1;
850 return $query_args;
851 }
852 } else if ($attr['queryType'] == 'customPosts') {
853 if (isset($attr['queryCustomPosts']) && $attr['queryCustomPosts']) {
854 $query_args['post_type'] = $this->get_post_type();
855 $data = json_decode(isset($attr['queryCustomPosts'])?$attr['queryCustomPosts']:'[]');
856 $final = $this->get_value($data);
857 if (count($final) > 0) {
858 $query_args['post__in'] = $final;
859 // $query_args['posts_per_page'] = -1;
860 }
861 $query_args['ignore_sticky_posts'] = 1;
862 return $query_args;
863 }
864 }
865
866 if (isset($attr['queryExcludeAuthor']) && $attr['queryExcludeAuthor']) {
867 $data = json_decode(isset($attr['queryExcludeAuthor'])?$attr['queryExcludeAuthor']:'[]');
868 $final = $this->get_value($data);
869 if (count($final) > 0) {
870 $query_args['author__not_in'] = $final;
871 }
872 }
873
874
875 if (isset($attr['queryOrderBy']) && isset($attr['metaKey'])) {
876 if ($attr['queryOrderBy'] == 'meta_value_num') {
877 $query_args['meta_key'] = $attr['metaKey'];
878 }
879 }
880
881 // Include Remove from Version 2.5.4
882 if (isset($attr['queryInclude']) && $attr['queryInclude']) {
883 $_include = explode(',', $attr['queryInclude']);
884 if (is_array($_include) && count($_include)) {
885 $query_args['post__in'] = isset($query_args['post__in']) ? array_merge($query_args['post__in'], $_include) : $_include;
886 $query_args['ignore_sticky_posts'] = 1;
887 $query_args['orderby'] = 'post__in';
888 }
889 }
890
891
892 if (isset($attr['queryTax'])) {
893 if (isset($attr['queryTaxValue'])) {
894 $var = $this->getFilterQueryArgs($attr);
895 if (isset($var) && count($var) > 1) {
896 $query_args['tax_query'] = $var;
897 }
898 }
899 }
900
901 if (isset($attr['queryExcludeTerm']) && $attr['queryExcludeTerm']) {
902 $temp = json_decode($attr['queryExcludeTerm']);
903 $_term = [];
904 foreach ($temp as $val) {
905 $temp = explode('###', $val->value);
906 if (isset($temp[1])) {
907 if ( is_array($_term) && array_key_exists($temp[0], $_term)) {
908 $_term[$temp[0]][] = $temp[1];
909 } else {
910 $_term[$temp[0]] = array($temp[1]);
911 }
912 }
913 }
914 if (count($_term) > 0) {
915 $final = array('relation' => 'AND');
916 foreach ($_term as $key => $val) {
917 $final[] = array(
918 'taxonomy' => $key,
919 'field' => 'slug',
920 'terms' => $val,
921 'operator' => 'NOT IN',
922 );
923 }
924
925 if ( is_array($query_args) && array_key_exists('tax_query', $query_args)) {
926 $query_args['tax_query'] = array(
927 'relation' => 'AND',
928 $query_args['tax_query']
929 );
930 $query_args['tax_query'][] = $final;
931 } else {
932 $query_args['tax_query'] = $final;
933 }
934 }
935 }
936
937 if (isset($attr['queryExclude']) && $attr['queryExclude']) {
938 $_exclude = (substr($attr['queryExclude'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryExclude'])) : explode(',', $attr['queryExclude']);
939 if (is_array($_exclude) && count($_exclude)) {
940 $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $_exclude) : $_exclude;
941 }
942 }
943
944 if (isset($attr['queryUnique']) && $attr['queryUnique']) {
945 global $unique_ID;
946 if (isset($unique_ID[$attr['queryUnique']])) {
947 $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $unique_ID[$attr['queryUnique']]) : $unique_ID[$attr['queryUnique']];
948 }
949 }
950 // exclude current post from Post blocks // v.2.9.6
951 if (is_single() && get_the_ID()) {
952 $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], array(get_the_ID())) : array(get_the_ID());
953 }
954
955 if (isset($attr['queryQuick'])) {
956 if ($attr['queryQuick'] != '' && $post_type != 'archiveBuilder') {
957 $query_args = ultimate_post()->get_quick_query($attr, $query_args);
958 }
959 }
960
961 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
962 $offset = $this->get_offset($attr['queryOffset'], $query_args);
963 $query_args = array_merge($query_args, $offset);
964 }
965
966 if (isset($attr['queryAuthor']) && $attr['queryAuthor'] ) {
967 $_include = (substr($attr['queryAuthor'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryAuthor'])) : explode(',', $attr['queryAuthor']);
968 if (is_array($_include) && count($_include)) {
969 $query_args['author__in'] = $_include;
970 }
971 }
972
973 if (isset($attr['querySearch']) && $attr['querySearch'] ) {
974 $query_args['s'] = $attr['querySearch'];
975 }
976
977 if(isset($attr['querySticky']) && $attr['querySticky']) {
978 if (filter_var($attr['querySticky'], FILTER_VALIDATE_BOOLEAN)) {
979 $sticky = get_option( 'sticky_posts', [] );
980 $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $sticky) : $sticky;
981 }
982 }
983
984 if (!isset($attr['ajaxCall'])) {
985 if(isset($attr['filterShow']) && $attr['filterShow'] && $attr['filterShow'] != 'false') {
986 if(isset($attr['checkFilter']) && isset($attr['queryTax']) && isset($attr['queryTaxValue']) ) {
987 $var = $this->getFilterQueryArgs($attr);
988 if (isset($var) && count($var) > 1) {
989 $query_args['tax_query'] = $var;
990 }
991 }
992 else if(isset($attr['filterType']) && isset($attr['filterValue'])) {
993 $filterValue = strlen($attr['filterValue']) > 2 ? $attr['filterValue'] : [];
994 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
995 if (is_array($filterValue) && count($filterValue) > 0 && $attr['filterType']) {
996 $final = array('relation' => 'OR');
997 foreach ($filterValue as $key => $val) {
998 $final[] = array(
999 'taxonomy' => $attr['filterType'],
1000 'field' => 'slug',
1001 'terms' => $val,
1002 // 'operator' => '=',
1003 );
1004 }
1005 $query_args['tax_query'] = $final;
1006 }
1007 }
1008 }
1009 }
1010
1011 // Advanced Filter Select Dropdown Default value
1012 // only on initial page load
1013 if (
1014 ! wp_doing_ajax() &&
1015 isset($attr['advFilterEnable']) &&
1016 $attr['advFilterEnable'] === true &&
1017 isset($attr['defQueryTax']) &&
1018 count($attr['defQueryTax']) > 0
1019 ) {
1020 $tax_query = array(
1021 'relation' =>
1022 isset($attr['advRelation']) &&
1023 ('AND' === $attr['advRelation'] || 'OR' === $attr['advRelation'])
1024 ? $attr['advRelation'] : 'AND'
1025 );
1026 $is_valid = false;
1027
1028 foreach ($attr['defQueryTax'] as $_ => $defQueryTaxValue) {
1029 $term = explode('###', $defQueryTaxValue);
1030
1031 // Validation
1032 if (
1033 ! in_array($term[0], array('category', 'tags', 'author', 'custom_tax'), true) ||
1034 '_all' === $term[1] ||
1035 empty( $term[1] )
1036 ) {
1037 continue;
1038 }
1039
1040 if ('author' === $term[0]) {
1041
1042 if ( ! is_numeric( $term[1] ) ) {
1043 continue;
1044 }
1045
1046 $query_args['author__in'] = $term[1];
1047 }
1048
1049 elseif( 'custom_tax' === $term[0] && isset( $attr['queryType'] ) ) {
1050 $post_type = sanitize_key($attr['queryType']);
1051 $slug = sanitize_key($term[1]);
1052
1053 // These are not custom post type
1054 if ( in_array($post_type, array('posts', 'customPosts'), true) ) {
1055 continue;
1056 }
1057
1058 $taxonomy = $this->get_taxonomy_by_term_slug( $post_type, $slug );
1059
1060 if (! empty($taxonomy)) {
1061 $q = array(
1062 'field' => 'slug',
1063 'taxonomy' => $taxonomy,
1064 'terms' => $slug
1065 );
1066
1067 $tax_query[] = $q;
1068 $is_valid = true;
1069 }
1070 }
1071
1072 else {
1073 if ( ! is_numeric( $term[1] ) ) {
1074 continue;
1075 }
1076
1077 $q = array(
1078 'field' => 'term_id',
1079 'taxonomy' => 'tags' === $term[0] ? 'post_tag' : 'category',
1080 'terms' => $term[1]
1081 );
1082
1083 $tax_query[] = $q;
1084 $is_valid = true;
1085 }
1086 }
1087
1088 if ($is_valid) {
1089 $query_args['tax_query'] = $tax_query;
1090 }
1091 }
1092
1093 $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
1094
1095 return apply_filters('ultp_frontend_query', $query_args);
1096 }
1097
1098 /**
1099 * Get Page Offset
1100 *
1101 * @since v.1.0.0
1102 * @param | Offset Number(NUMBER) | Query Arg(ARRAY)
1103 * @return ARRAY
1104 */
1105 function get_offset($queryOffset, $query_args) {
1106 $query = array();
1107 if ($query_args['paged'] > 1) {
1108 $offset_post = wp_get_recent_posts($query_args, OBJECT);
1109 if (count($offset_post) > 0 ) {
1110 $offset = array();
1111 for($x = count($offset_post); $x > count($offset_post) - $queryOffset; $x--) {
1112 $offset[] = $offset_post[$x-1]->ID;
1113 }
1114 $query['post__not_in'] = $offset;
1115 }
1116 } else {
1117 $query['offset'] = isset($queryOffset) ? $queryOffset : 0;
1118 }
1119 return $query;
1120 }
1121
1122
1123 /**
1124 * Get Page Number
1125 *
1126 * @since v.1.0.0
1127 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1128 * @return ARRAY
1129 */
1130 public function get_page_number($attr, $post_number) {
1131 if ($post_number > 0) {
1132 if (isset($attr['queryOffset']) && $attr['queryOffset']) {
1133 $post_number = $post_number - (int)$attr['queryOffset'];
1134 }
1135 $post_per_page = isset($attr['queryNumber']) ? ($attr['queryNumber'] ? $attr['queryNumber'] : 1) : 3;
1136 $pages = ceil($post_number/$post_per_page);
1137 return $pages ? $pages : 1;
1138 }else{
1139 return 1;
1140 }
1141 }
1142
1143
1144 /**
1145 * Get Image Size
1146 *
1147 * @since v.1.0.0
1148 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1149 * @return ARRAY
1150 */
1151 public function get_image_size() {
1152 $sizes = get_intermediate_image_sizes();
1153 $filter = array('full' => 'Full');
1154 foreach ($sizes as $value) {
1155 $title = ucwords(str_replace(array('_', '-', 'ultp'), array(' ', ' ', 'PostX'), $value));
1156 switch ($value) {
1157 case 'thumbnail':
1158 $title = $title.' [150x150]';
1159 break;
1160 case 'medium':
1161 $title = $title.' [300x300]';
1162 break;
1163 case 'large':
1164 $title = $title.' [1024x1024]';
1165 break;
1166 case 'ultp_layout_landscape_large':
1167 $title = $title.' [1200x800]';
1168 break;
1169 case 'ultp_layout_landscape':
1170 $title = $title.' [870x570]';
1171 break;
1172 case 'ultp_layout_portrait':
1173 $title = $title.' [600x900]';
1174 break;
1175 case 'ultp_layout_square':
1176 $title = $title.' [600x600]';
1177 break;
1178 default:
1179 break;
1180 }
1181 $filter[$value] = $title;
1182 }
1183 return $filter;
1184 }
1185
1186
1187 /**
1188 * Get All PostType Registered
1189 *
1190 * @since v.1.0.0
1191 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1192 * @return ARRAY
1193 */
1194 public function get_post_type() {
1195 $filter = apply_filters('ultp_public_post_type', true);
1196 $post_type = get_post_types( ($filter ? ['public' => true] : ''), 'names' );
1197 return array_diff($post_type, array( 'attachment' ));
1198 }
1199
1200 /**
1201 * Get Pagination Url
1202 *
1203 * @since v.2.8.9
1204 * @param | pageNo (NUMBER) | baseUrl (STRING)
1205 * @return STRING
1206 */
1207 public function generatePaginationUrl($pageNo , $baseUrl) {
1208 if($baseUrl) {
1209 $url = $baseUrl.($pageNo == 1? '' : "page/".$pageNo);
1210 }
1211 else {
1212 $url = get_pagenum_link($pageNo);
1213 }
1214 return $url;
1215 }
1216 /**
1217 * Get Pagination HTML
1218 *
1219 * @since v.1.0.0
1220 * @param | pages (NUMBER) | Pagination Nav (STRING) | Pagination Text |
1221 * @return STRING
1222 */
1223 public function pagination($pages = '', $paginationNav = '', $paginationText = '', $paginationAjax = true, $baseUrl = '', $blockId = '') {
1224 $html = '';
1225 $showitems = 3;
1226 $paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
1227 $paged = $paged ? $paged : 1;
1228
1229 $paged = ! wp_doing_ajax() &&
1230 isset( $_GET[ $blockId . '_page' ] ) &&
1231 is_numeric( $_GET[ $blockId . '_page' ] ) ?
1232 intval($_GET[ $blockId . '_page' ]) : $paged;
1233
1234 if ($pages == '') {
1235 global $wp_query;
1236 $pages = $wp_query->max_num_pages;
1237 if (!$pages) {
1238 $pages = 1;
1239 }
1240 }
1241
1242 $data = ($paged>=3?[($paged-1),$paged,$paged+1]:[1,2,3]);
1243
1244 $paginationText = explode('|', $paginationText);
1245
1246 $prev_text = isset($paginationText[0]) ? esc_html($paginationText[0]) : __("Previous", "ultimate-post");
1247 $next_text = isset($paginationText[1]) ? esc_html($paginationText[1]) : __("Next", "ultimate-post");
1248
1249 if (1 != $pages) {
1250 $html .= '<ul class="ultp-pagination">';
1251 $display_none = 'style="display:none"';
1252 if ($pages > 1) {
1253 $html .= '<li class="ultp-prev-page-numbers" '.($paged == 1 ? $display_none : "").'><a href="'.$this->generatePaginationUrl($paged-1, $baseUrl).'">'.ultimate_post()->get_svg_icon('leftAngle2').' '.($paginationNav == 'textArrow' ? $prev_text : "").'</a></li>';
1254 }
1255 if ($pages > 3) {
1256 $html .= '<li class="ultp-first-pages" '.($paged < 2 ? $display_none : "").' data-current="1"><a href="'.$this->generatePaginationUrl(1, $baseUrl).'">1</a></li>';
1257 }
1258 if ($pages > 4) {
1259 $html .= '<li class="ultp-first-dot"'.($paged == 1 ? $display_none : "").'><a href="#">...</a></li>';
1260 }
1261 foreach ($data as $i) {
1262 if ( $pages > 3 && $pages == $i ) {
1263 continue;
1264 }
1265 if ($pages >= $i) {
1266 $html .= ($paged == $i) ? '<li class="ultp-center-item pagination-active" data-current="'.$i.'"><a href="'.$this->generatePaginationUrl($i, $baseUrl).'">'.$i.'</a></li>':'<li class="ultp-center-item" data-current="'.$i.'" '.( ( $pages > 4 && $paged == 2 && $i == 1 && !$paginationAjax ) ? $display_none : "").'><a href="'.$this->generatePaginationUrl($i, $baseUrl).'">'.$i.'</a></li>';
1267 }
1268 }
1269 if ($pages > 4) {
1270 $html .= '<li class="ultp-last-dot" '.($pages <= $paged + 1 ? $display_none : "").'><a href="#">...</a></li>';
1271 }
1272 if ($pages > 3) {
1273 $html .= '<li class="ultp-last-pages" data-current="'.$pages.'"><a href="'.$this->generatePaginationUrl($pages, $baseUrl).'">'.$pages.'</a></li>';
1274 }
1275 if ($paged != $pages) {
1276 $html .= '<li class="ultp-next-page-numbers"><a href="'.$this->generatePaginationUrl($paged + 1, $baseUrl).'">'.($paginationNav == 'textArrow' ? $next_text : "").ultimate_post()->get_svg_icon('rightAngle2').'</a></li>';
1277 }
1278 $html .= '</ul>';
1279 }
1280 return $html;
1281 }
1282
1283 /**
1284 * Svg Icon Source
1285 *
1286 * @since v.1.0.0
1287 * @param string $ultp_icons
1288 * @return string
1289 */
1290 public function get_svg_icon( $ultp_icons = '' ) {
1291 $svg = '';
1292 if ( $ultp_icons ) {
1293 $svg = $this->get_path_file_contents(ULTP_PATH . 'assets/img/iconpack/' . $ultp_icons . '.svg');
1294 }
1295 return $svg;
1296 }
1297
1298 /**
1299 * Get Taxonomy Lists
1300 *
1301 * @since v.1.0.0
1302 * @param STRING | Taxonomy Slug
1303 * @return ARRAY
1304 */
1305 public function taxonomy( $prams = 'category' ) {
1306 $data = array();
1307
1308 $terms = get_terms( is_string($prams) ? array(
1309 'taxonomy' => $prams,
1310 'hide_empty' => false
1311 ) : $prams);
1312 if ( ! is_wp_error( $terms ) ) {
1313 foreach ( $terms as $val ) {
1314 $data[ urldecode_deep( $val->slug ) ] = $val->name;
1315 }
1316 }
1317 return $data;
1318 }
1319
1320
1321 /**
1322 * Get Taxonomy Lists
1323 *
1324 * @since v.2.9.0
1325 * @param STRING | Taxonomy Slug
1326 * @return ARRAY
1327 */
1328 public function builder_preview( $tax_slug, $number ) {
1329 $data = array();
1330 $term_data = get_terms( array( 'taxonomy' => $tax_slug, 'hide_empty' => true, 'number' => $number, 'parent' => 0 ) );
1331 if ( ! empty( $term_data ) ) {
1332 foreach ( $term_data as $terms ) {
1333 $data[] = $this->get_tax_data( $terms );
1334 }
1335 }
1336 return $data;
1337 }
1338
1339 /**
1340 * Get Taxonomy Data Lists
1341 *
1342 * @since v.1.0.0
1343 * @param OBJECT | Taxonomy Object
1344 * @return ARRAY
1345 */
1346 public function get_tax_data($terms) {
1347 $temp = array();
1348 $thumbnail_id = get_term_meta( $terms->term_id, 'ultp_category_image', true );
1349 $image_src = array();
1350 if ($thumbnail_id) {
1351 $image_sizes = ultimate_post()->get_image_size();
1352 foreach ($image_sizes as $key => $value) {
1353 $img_src = wp_get_attachment_image_src($thumbnail_id, $key, false);
1354 if( $img_src ) {
1355 $image_src[$key] = $img_src[0];
1356 }
1357 }
1358 }
1359 $temp['url'] = get_term_link($terms);
1360 $temp['thumbnail_id'] = $thumbnail_id;
1361 $temp['name'] = $terms->name;
1362 $temp['desc'] = $terms->description;
1363 $temp['count'] = $terms->count;
1364 $temp['image'] = $image_src;
1365 $color = get_term_meta($terms->term_id, 'ultp_category_color', true);
1366 $temp['color'] = $color ? $color : '#037fff';
1367 return $temp;
1368 }
1369
1370 public function get_category_data($catSlug, $number = 40, $type = '', $tax_slug = 'category', $archiveBuilder = '') {
1371 $data = array();
1372 if ($type == 'child') {
1373 if($archiveBuilder) {
1374 $data = $this->builder_preview( $tax_slug, $number );
1375 }
1376 else {
1377 if(is_category()) {
1378 $catSlug = array(get_queried_object()->slug);
1379 }
1380 $image = '';
1381 if (!empty($catSlug)) {
1382 foreach ($catSlug as $cat) {
1383 $parent_term = get_term_by('slug', $cat, $tax_slug);
1384 if (!empty($parent_term)) {
1385 $term_data = get_terms(array(
1386 'taxonomy' => $tax_slug,
1387 'hide_empty' => true,
1388 'number' => $number,
1389 'parent' => $parent_term->term_id
1390 ));
1391 if (!empty($term_data)) {
1392 foreach ($term_data as $terms) {
1393 $data[] = $this->get_tax_data($terms);
1394 }
1395 }
1396 }
1397 }
1398 }
1399 }
1400 } else if ($type == 'parent') {
1401 $term_data = is_category() ? array(get_term(get_queried_object()->parent, 'category')) : get_terms( array( 'taxonomy' => $tax_slug,'hide_empty' => true, 'number' => $number, 'parent' => 0 ) );
1402 if($archiveBuilder && !empty($term_data)) {
1403 $term_data = array($term_data[0]);
1404 }
1405 if (!empty($term_data)) {
1406 foreach ($term_data as $terms) {
1407 if (!empty($terms->term_id)) {
1408 $data[] = $this->get_tax_data($terms);
1409 }
1410 }
1411 }
1412 } else if ($type == 'custom') {
1413 foreach ($catSlug as $cat) {
1414 $terms = get_term_by('slug', $cat, $tax_slug);
1415 if (!empty($terms)) {
1416 $data[] = $this->get_tax_data($terms);
1417 }
1418 }
1419 } else if ($type == 'immediate_child') {
1420 if($archiveBuilder) {
1421 $data = $this->builder_preview( $tax_slug, $number );
1422 } else {
1423 $id_ = get_queried_object();
1424 if (isset($id_->term_id)) {
1425 $term_data = get_terms( array( 'taxonomy' => $tax_slug, 'hide_empty' => true, 'number' => 100, 'parent' => $id_->term_id) );
1426 if (!empty($term_data)) {
1427 foreach ($term_data as $terms) {
1428 $data[] = $this->get_tax_data($terms);
1429 }
1430 }
1431 }
1432 }
1433 } else if ($type == 'allchild') {
1434 if($archiveBuilder) {
1435 $data = $this->builder_preview( $tax_slug, $number );
1436 } else {
1437 $id_ = get_queried_object();
1438 if (isset($id_->term_taxonomy_id)) {
1439 $termchildren = get_term_children( $id_->term_taxonomy_id, $tax_slug );
1440 foreach ($termchildren as $key => $value) {
1441 $terms = get_term_by('id', $value, $tax_slug);
1442 $data[] = $this->get_tax_data($terms);
1443 }
1444 }
1445 }
1446 } else if ($type == 'current_level') {
1447 if($archiveBuilder) {
1448 $data = $this->builder_preview( $tax_slug, $number );
1449 } else {
1450 $id_ = get_queried_object();
1451 if (isset($id_->parent)) {
1452 $term_data = get_terms( array('taxonomy' => $tax_slug, 'hide_empty' => true, 'number' => $number, 'parent' => $id_->parent ) );
1453 if (!empty($term_data)) {
1454 foreach ($term_data as $terms) {
1455 if ($terms->term_id != $id_->term_id) {
1456 $data[] = $this->get_tax_data($terms);
1457 }
1458 }
1459 }
1460 }
1461 }
1462 } else {
1463 $term_data = get_terms( array('taxonomy' => $tax_slug, 'hide_empty' => true, 'number' => $number));
1464 if (!empty($term_data)) {
1465 foreach ($term_data as $terms) {
1466 $data[] = $this->get_tax_data($terms);
1467 }
1468 }
1469 }
1470 return $data;
1471 }
1472
1473
1474 /**
1475 * Get Next Previous HTML
1476 *
1477 * @since v.1.0.0
1478 * @param OBJECT | Taxonomy Object
1479 * @return STRING
1480 */
1481 public function next_prev() {
1482 $html = '';
1483 $html .= '<ul>';
1484 $html .= '<li>';
1485 $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
1486 $html .= ultimate_post()->get_svg_icon('leftAngle2').'<span class="screen-reader-text">'.esc_html__("Previous", "ultimate-post").'</span>';
1487 $html .= '</a>';
1488 $html .= '</li>';
1489 $html .= '<li>';
1490 $html .= '<a class="ultp-next-action">';
1491 $html .= ultimate_post()->get_svg_icon('rightAngle2').'<span class="screen-reader-text">'.esc_html__("Next", "ultimate-post").'</span>';
1492 $html .= '</a>';
1493 $html .= '</li>';
1494 $html .= '</ul>';
1495 return $html;
1496 }
1497
1498
1499 /**
1500 * Get Loading HTML
1501 *
1502 * @since v.1.0.0
1503 * @param NULL
1504 * @return STRING
1505 */
1506 public function postx_loading() {
1507 $html = '';
1508 $style = ultimate_post()->get_setting('preloader_style');
1509 if ($style == 'style2') {
1510 $html .= '<div class="ultp-loading-spinner" style="width:100%;height:100%"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>';//ultp-block-items-wrap
1511 } else {
1512 $html .= '<div class="ultp-loading-blocks" style="width:100%;height:100%;"><div style="left: 0;top: 0;animation-delay:0s;"></div><div style="left: 21px;top: 0;animation-delay:0.125s;"></div><div style="left: 42px;top: 0;animation-delay:0.25s;"></div><div style="left: 0;top: 21px;animation-delay:0.875s;"></div><div style="left: 42px;top: 21px;animation-delay:0.375s;"></div><div style="left: 0;top: 42px;animation-delay:0.75s;"></div><div style="left: 42px;top: 42px;animation-delay:0.625s;"></div><div style="left: 21px;top: 42px;animation-delay:0.5s;"></div></div>';
1513 }
1514 return '<div class="ultp-loading">'.$html.'</div>';
1515 }
1516
1517
1518 /**
1519 * Get Filter HTML
1520 *
1521 * @since v.1.0.0
1522 * @param | Filter Text (STRING) | Filter Type (STRING) | Filter Value (ARRAY) | Filter Cat (ARRAY) | Filter Tag (ARRAY) |
1523 * @return STRING
1524 */
1525 public function filter_html($filterText = '', $filterType = '', $filterValue = '[]', $filterMobileText = '...', $filterMobile = true) {
1526 $html = '';
1527 $html .= '<ul '.($filterMobile ? 'class="ultp-flex-menu"' : '').' data-name="'.($filterMobileText ? $filterMobileText : '&nbsp;').'">';
1528 $cat = $this->taxonomy($filterType);
1529 if ($filterText) {
1530 $html .= '<li class="filter-item"><a class="filter-active" data-taxonomy="" href="#">'.$filterText.'</a></li>';
1531 }
1532 if ($filterValue) {
1533 $filterValue = strlen($filterValue) > 2 ? $filterValue : [];
1534 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
1535 if (is_array($filterValue) && count($filterValue)) {
1536 foreach ($filterValue as $val) {
1537 $val = isset($val->value) ? $val->value : $val;
1538 $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($cat[$val]) ? $cat[$val] : $val).'</a></li>';
1539 }
1540 }
1541 }
1542 $html .= '</ul>';
1543 return $html;
1544 }
1545
1546
1547 /**
1548 * Check License Status
1549 *
1550 * @since v.2.4.2
1551 * @return BOOLEAN | Is pro license active or not
1552 */
1553 public function is_lc_active() {
1554 if (function_exists('ultimate_post_pro')) {
1555 return get_option('edd_ultp_license_status') == 'valid' ? true : false;
1556 }
1557 return false;
1558 }
1559
1560
1561 /**
1562 * Get SEO Meta
1563 *
1564 * @since v.2.4.3
1565 * @param NUMBER | Post ID
1566 * @return STRING | SEO Meta Description or Excerpt
1567 */
1568 public function get_excerpt($post_id = 0, $showSeoMeta = 0, $showFullExcerpt = 0, $excerptLimit = 55) {
1569 $html = '';
1570 if ($showSeoMeta) {
1571 $str = '';
1572 if ( function_exists('ultimate_post_pro') ) {
1573 if ( ultimate_post()->get_setting('ultp_yoast') == 'true' ) {
1574 $str = method_exists( ultimate_post_pro(), 'get_yoast_meta' ) ? ultimate_post_pro()->get_yoast_meta($post_id) : '';
1575 } else if ( ultimate_post()->get_setting('ultp_rankmath') == 'true' ) {
1576 $str = method_exists( ultimate_post_pro(), 'get_rankmath_meta' ) ? ultimate_post_pro()->get_rankmath_meta($post_id) : '';
1577 } else if ( ultimate_post()->get_setting('ultp_aioseo') == 'true' ) {
1578 $str = method_exists( ultimate_post_pro(), 'get_aioseo_meta' ) ? ultimate_post_pro()->get_aioseo_meta($post_id) : '';
1579 } else if ( ultimate_post()->get_setting('ultp_seopress') == 'true' ) {
1580 $str = method_exists( ultimate_post_pro(), 'get_seopress_meta' ) ? ultimate_post_pro()->get_seopress_meta($post_id) : '';
1581 } else if ( ultimate_post()->get_setting('ultp_squirrly') == 'true' ) {
1582 $str = method_exists( ultimate_post_pro(), 'get_squirrly_meta' ) ? ultimate_post_pro()->get_squirrly_meta($post_id) : '';
1583 }
1584 }
1585 $html = $str ? $str : ultimate_post()->excerpt($post_id, $excerptLimit);
1586 } else {
1587 if ($showFullExcerpt == 0 ) {
1588 $html = ultimate_post()->excerpt($post_id, $excerptLimit);
1589 } else {
1590 $html = get_the_excerpt();
1591 }
1592 }
1593 return $html;
1594 }
1595
1596 public function get_embeded_video($url, $autoPlay, $loop, $mute, $playback, $preload, $poster, $inline, $size) {
1597 $vidAutoPlay = $vidloop = $vidloop = $vidmute = $vidplayback = $vidPoster = $vidInline = "";
1598
1599 if($autoPlay){
1600 $vidAutoPlay = "autoplay";
1601 }
1602 if($poster){
1603 $vidPoster = 'poster="'.$poster["url"].'"';
1604 }
1605 if($loop){
1606 $vidloop = "loop";
1607 }
1608 if($mute){
1609 $vidmute = "muted";
1610 }
1611 if($playback){
1612 $vidplayback = "controls";
1613 }
1614 if($inline){
1615 $vidInline = "playsinline";
1616 }
1617 if (!empty($url)) {
1618 $embeded = wp_oembed_get($url, $size);
1619 if ($embeded == false) {
1620 $format = '';
1621 $url = strtolower($url);
1622 if (strpos($url, '.mp4')) {
1623 $format = 'mp4';
1624 } elseif (strpos($url, '.ogg')) {
1625 $format = 'ogg';
1626 } elseif (strpos($url, '.webm')) {
1627 $format = 'WebM';
1628 }
1629 $embeded = '<video
1630 '.$vidloop.'
1631 '.$vidmute.'
1632 '.$vidplayback.'
1633 preload="'.$preload.'"
1634 '.$vidAutoPlay.'
1635 '.$vidPoster.'
1636 '.$vidInline.'
1637 class="ultp-video-html"
1638 ><source src="' . $url . '" type="video/' . $format . '">' . __('Your browser does not support the video tag.', 'ultimate-post') . '</video>';
1639 return '<div class="ultp-video-wrapper">'.$embeded.'</div>';
1640 }
1641 return '<div class="ultp-video-wrapper ultp-embaded-video">'.$embeded.'</div>';
1642 } else {
1643 return false;
1644 }
1645 }
1646
1647 /**
1648 * Get Public taxonomy Lists
1649 *
1650 * @since v.2.7.0
1651 * @param NULL
1652 * @return ARRAY | Taxonomy Lists as array
1653 */
1654 public function get_taxonomy_list() {
1655 $taxonomy = get_taxonomies(array('public' => true));
1656 return empty($taxonomy) ? [] : array_keys($taxonomy);
1657 }
1658
1659 /**
1660 * Content Print
1661 *
1662 * @since v.2.7.0
1663 * @param NUMBER | Post ID
1664 * @return STRING | Content of the Post
1665 */
1666 public function get_post_content($post_id, $builder_type = '') {
1667 $content_post = get_post($post_id);
1668 $content = $content_post->post_content;
1669 if($builder_type == 'divi' || $builder_type == 'elementor') {
1670 $content = apply_filters('the_content', $content);
1671 } else {
1672 $content = do_blocks($content);
1673 $content = do_shortcode($content);
1674 }
1675 $content = str_replace(']]>', ']]&gt;', $content);
1676 $content = preg_replace('%<p>&nbsp;\s*</p>%', '', $content);
1677 $content = preg_replace('/^(?:<br\s*\/?>\s*)+/', '', $content);
1678 echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1679 }
1680
1681 /**
1682 * String Part finder inside array
1683 *
1684 * @since v.2.7.0 updated 4.1.12
1685 * @return ARRAY | String Part
1686 */
1687 public function in_array_part($part, $data, $toR = '') {
1688 $res = array();
1689 foreach( $data as $key => $val ) {
1690 if ( strpos( $val, $part ) !== false ) {
1691 if ( $toR == 'bool' ) {
1692 return true;
1693 } else if ( $toR == 'value' ) {
1694 return $val;
1695 }
1696 $res[$key] = $val;
1697 }
1698 }
1699 if ( $toR == 'bool' ) {
1700 return false;
1701 } else if ( $toR == 'value' ) {
1702 return '';
1703 }
1704 return $res;
1705 }
1706
1707 /**
1708 * Builder Conditions
1709 *
1710 * @since v.2.7.0 updated 4.1.12
1711 * @param STRING | Type of Return
1712 * @return MIXED || ID or Path
1713 */
1714 public function builder_check_conditions( $type = 'return', $cus_condition = '' ) {
1715 $page_id = '';
1716 $conditions = $cus_condition ? $cus_condition : get_option('ultp_builder_conditions', array());
1717
1718 if ( $type == 'header' || $type == 'footer' ) {
1719 if ( !empty($conditions[$type]) ) {
1720 foreach( $conditions[$type] as $key => $val) {
1721 if ( 'publish' == get_post_status($key) && !empty($val) ) {
1722 if ( in_array('include/'.$type.'/entire_site', $val) ) {
1723 $page_id = $key;
1724 } else if ( in_array('exclude/'.$type.'/entire_site', $val) ) {
1725 $page_id = '';
1726 }
1727
1728 $c_page = ( is_archive() || is_search() ) ? 'archive' : 'singular';
1729 $hf_archive = $this->in_array_part($type.'/'.$c_page, $val, '');
1730 if ( !empty($hf_archive) ) {
1731 foreach($hf_archive as $k => $v) {
1732 if ( strpos($v, 'include/'.$type.'/'.$c_page) !== false ) {
1733 $temp = $this->builder_check_conditions('return_h', [$c_page => [$key => [str_replace($type."/", "", $v)]]]);
1734 $page_id = $temp ? $temp : $page_id;
1735 } else if (strpos($v, 'exclude/'.$type.'/'.$c_page) !== false) {
1736 $temp = $this->builder_check_conditions('return_f', [$c_page => [$key => [str_replace("exclude/".$type, "include", $v)]]]);
1737 $page_id = $temp ? '' : $page_id;
1738 }
1739 }
1740 }
1741 }
1742 }
1743 }
1744 } else {
1745 // 404 page
1746 if ( !empty($conditions['404']) && is_404() ) {
1747 foreach( $conditions['404'] as $key => $val ) {
1748 if ( 'publish' == get_post_status($key) ) {
1749 $page_id = $key;
1750 }
1751 }
1752 }
1753 // Singular or Front Page
1754 else if (
1755 (
1756 !empty($conditions['singular']) ||
1757 !empty($conditions['front_page'])
1758 ) &&
1759 (
1760 is_singular() ||
1761 is_front_page() ||
1762 is_home()
1763 )
1764 ) {
1765 $obj = get_queried_object();
1766 $queried_is_obj = is_object($obj);
1767 // front page only
1768 if (
1769 ( is_front_page() && is_home() ) ||
1770 ( is_home() && !$queried_is_obj ) ||
1771 ( is_singular() && is_front_page() && $queried_is_obj )
1772 ) {
1773 $f_conditions = [];
1774 if ( !empty($conditions['front_page']) ) {
1775 $f_conditions = $conditions['front_page'];
1776 } else if ( !empty($conditions['singular']) ) {
1777 $f_conditions = $conditions['singular'];
1778 }
1779 if ( !empty($f_conditions) ) {
1780 foreach( $f_conditions as $key => $val ) {
1781 if (
1782 ( is_array($val) && in_array('include/singular/front_page', $val) ) ||
1783 ( is_array($val) && in_array('include/front_page', $val) ) ||
1784 'include/front_page' == $val
1785 ) {
1786 if ( 'publish' == get_post_status($key) ) {
1787 $page_id = $key;
1788 }
1789 }
1790 }
1791 }
1792 }
1793 // Singular page
1794 else if ( !empty($conditions['singular']) ) {
1795 foreach( $conditions['singular'] as $key => $val ) {
1796 if ( 'publish' == get_post_status($key) ) {
1797 // All Post Type -----Prority 1
1798 if ( $queried_is_obj ) {
1799 if ( in_array('include/singular/'.$obj->post_type, $val) ) {
1800 $page_id = $key;
1801 } else if ( in_array('exclude/singular/'.$obj->post_type, $val) ) {
1802 $page_id = '';
1803 }
1804 }
1805
1806 $singular_in_tax = $this->in_array_part("/singular/in_", $val, '');
1807 if ( !empty($singular_in_tax) ) {
1808 $tax_list = $this->get_taxonomy_list();
1809 foreach( $tax_list as $tax ) {
1810 if ( in_array('include/singular/in_'.$tax.'_children', $singular_in_tax) ) {
1811 $page_id = $key;
1812 } else if ( in_array('exclude/singular/in_'.$tax.'_children', $singular_in_tax) ) {
1813 $page_id = '';
1814 }
1815
1816 if ( $queried_is_obj ) {
1817 $singular_in_tax_children = $this->in_array_part('/singular/in_'.$tax.'_children/', $singular_in_tax, '');
1818 foreach( $singular_in_tax_children as $v ) {
1819 $data = explode("/", $v);
1820 if ( isset($data[3]) && $data[3] ) {
1821 $childs = get_term_children( $data[3], $tax );
1822 if ( !empty($childs) && has_term($childs, $tax) ) {
1823 $page_id = $data[0] == 'exclude' ? '' : $key;
1824 }
1825 }
1826 }
1827 }
1828
1829 if ( in_array('include/singular/in_'.$tax, $singular_in_tax) ) {
1830 if ( $tax == "post_tag" && $queried_is_obj) {
1831 $cat = get_the_terms($obj->ID, "post_tag");
1832 if ( !empty( $cat ) ) {
1833 $page_id = $key;
1834 }
1835 } else {
1836 $page_id = $key;
1837 }
1838 } else if ( in_array('exclude/singular/in_'.$tax, $singular_in_tax) ) {
1839 $page_id = '';
1840 }
1841
1842 if ( $queried_is_obj ) {
1843 $singular_in_tax_only = $this->in_array_part('/singular/in_'.$tax.'/', $singular_in_tax, '');
1844 foreach( $singular_in_tax_only as $v ) {
1845 $data = explode("/", $v);
1846 if ( isset($data[3]) && $data[3] ) {
1847 if ( is_object_in_term($obj->ID , $tax, $data[3] ) ) {
1848 $page_id = $data[0] == 'exclude' ? '' : $key;
1849 }
1850 }
1851 }
1852 }
1853 }
1854 }
1855
1856 // Posts by author -----Prority 9
1857 if ( in_array('include/singular/post_by_author', $val) ) {
1858 $page_id = $key;
1859 } else if ( in_array('exclude/singular/post_by_author', $val) ) {
1860 $page_id = '';
1861 }
1862 if ( $queried_is_obj ) {
1863 if ( in_array('include/singular/post_by_author/'.$obj->post_author, $val) ) {
1864 $page_id = $key;
1865 } else if ( in_array('exclude/singular/post_by_author/'.$obj->post_author, $val) ) {
1866 $page_id = '';
1867 }
1868 // Post Type with specific id -----Prority 10
1869 if ( in_array('include/singular/'.$obj->post_type.'/'.$obj->ID, $val) ) {
1870 $page_id = $key;
1871 } else if ( in_array('exclude/singular/'.$obj->post_type.'/'.$obj->ID, $val) ) {
1872 $page_id = '';
1873 }
1874 }
1875 }
1876 }
1877 }
1878 }
1879
1880 // Archive and Search Page
1881 else if ( !empty($conditions['archive']) ) {
1882 // Search Page
1883 if ( is_search() ) {
1884 foreach( $conditions['archive'] as $key => $val ) {
1885 if ( 'publish' == get_post_status($key) ) {
1886 if ( in_array('include/archive/search', $val) ) {
1887 $page_id = $key;
1888 } else if ( in_array('exclude/archive/search', $val) ) {
1889 $page_id = '';
1890 }
1891 }
1892 }
1893 }
1894 // Archive Page
1895 else if ( is_archive() ) {
1896 $is_cat = is_category();
1897 $is_tag = is_tag();
1898 $is_tax = is_tax();
1899 $is_date = is_date();
1900 $is_author = is_author();
1901 $taxonomy = ( $is_cat || $is_tag || $is_tax ) ? get_queried_object() : (object)[];
1902
1903 foreach( $conditions['archive'] as $key => $val ) {
1904 if ( 'publish' == get_post_status($key) ) {
1905 // This section is for all archive page
1906 if ( in_array('include/archive', $val) ) {
1907 $page_id = $key;
1908 } else if ( in_array('exclude/archive', $val) ) {
1909 $page_id = '';
1910 }
1911 // For Category
1912 if ( $is_cat ) {
1913 // all category
1914 if ( in_array('include/archive/category', $val) ) {
1915 $page_id = $key;
1916 } else if ( in_array('exclude/archive/category', $val) ) {
1917 $page_id = '';
1918 }
1919 // specific category
1920 if ( in_array('include/archive/category/'.$taxonomy->term_id, $val) ) {
1921 $page_id = $key;
1922 } else if ( in_array('exclude/archive/category/'.$taxonomy->term_id, $val) ) {
1923 $page_id = '';
1924 }
1925
1926 // any child of category
1927 if ( in_array('include/archive/any_child_of_category', $val) ) {
1928 $page_id = $key;
1929 } else if ( in_array('exclude/archive/any_child_of_category', $val) ) {
1930 $page_id = '';
1931 }
1932
1933 $any_child_of_cat = $this->in_array_part("archive/any_child_of_category/", $val, '');
1934 if ( !empty($any_child_of_cat) ) {
1935 foreach( $any_child_of_cat as $v ) {
1936 $data = explode("/", $v);
1937 if ( isset($data[3]) && $data[3] ) {
1938 if ( term_is_ancestor_of($data[3], $taxonomy->term_id, 'category') ) {
1939 $page_id = $data[0] == 'exclude' ? '' : $key;
1940 }
1941 }
1942 }
1943 }
1944
1945 // all child of category
1946 if ( in_array('include/archive/child_of_category', $val) ) {
1947 $page_id = $key;
1948 } else if ( in_array('exclude/archive/child_of_category', $val) ) {
1949 $page_id = '';
1950 }
1951 // specific child of category
1952 if ( in_array('include/archive/child_of_category/'.$taxonomy->parent, $val) ) {
1953 $page_id = $key;
1954 } else if ( in_array('exclude/archive/child_of_category/'.$taxonomy->parent, $val) ) {
1955 $page_id = '';
1956 }
1957 }
1958 // For Tag
1959 else if ( $is_tag ) {
1960 if ( in_array('include/archive/post_tag', $val) ) {
1961 $page_id = $key;
1962 } else if ( in_array('exclude/archive/post_tag', $val) ) {
1963 $page_id = '';
1964 }
1965 if ( in_array('include/archive/post_tag/'.$taxonomy->term_id, $val) ) {
1966 $page_id = $key;
1967 } else if ( in_array('exclude/archive/post_tag/'.$taxonomy->term_id, $val) ) {
1968 $page_id = '';
1969 }
1970 }
1971 // Other taxonomy
1972 else if ( $is_tax ) {
1973 if ( in_array('include/archive/'.$taxonomy->taxonomy, $val) ) {
1974 $page_id = $key;
1975 } else if ( in_array('exclude/archive/'.$taxonomy->taxonomy, $val) ) {
1976 $page_id = '';
1977 }
1978
1979 if ( in_array('include/archive/'.$taxonomy->taxonomy.'/'.$taxonomy->term_id, $val) ) {
1980 $page_id = $key;
1981 } else if ( in_array('exclude/archive/'.$taxonomy->taxonomy.'/'.$taxonomy->term_id, $val) ) {
1982 $page_id = '';
1983 }
1984
1985 if ( in_array('include/archive/any_child_of_'.$taxonomy->taxonomy, $val) ) {
1986 $page_id = $key;
1987 } else if ( in_array('exclude/archive/any_child_of_'.$taxonomy->taxonomy, $val) ) {
1988 $page_id = '';
1989 }
1990
1991 $any_child_of_tax = $this->in_array_part('archive/any_child_of_'.$taxonomy->taxonomy.'/', $val, '');
1992 if ( !empty($any_child_of_tax) ) {
1993 foreach( $any_child_of_tax as $v ) {
1994 $data = explode("/", $v);
1995 if ( isset($data[3]) && $data[3] ) {
1996 if ( term_is_ancestor_of($data[3], $taxonomy->term_id, $taxonomy->taxonomy) ) {
1997 $page_id = $data[0] == 'exclude' ? '' : $key;
1998 }
1999 }
2000 }
2001 }
2002
2003 if ( in_array('include/archive/child_of_'.$taxonomy->taxonomy, $val) ) {
2004 $page_id = $key;
2005 } else if ( in_array('exclude/archive/child_of_'.$taxonomy->taxonomy, $val) ) {
2006 $page_id = '';
2007 }
2008
2009 if ( in_array('include/archive/child_of_'.$taxonomy->taxonomy.'/'.$taxonomy->parent, $val) ) {
2010 $page_id = $key;
2011 } else if ( in_array('exclude/archive/child_of_'.$taxonomy->taxonomy.'/'.$taxonomy->parent, $val) ) {
2012 $page_id = '';
2013 }
2014
2015 }
2016 // For Date
2017 else if ( $is_date ) {
2018 if ( in_array('include/archive/date', $val) ) {
2019 $page_id = $key;
2020 } else if ( in_array('exclude/archive/date', $val) ) {
2021 $page_id = '';
2022 }
2023 }
2024 // For Author
2025 else if ( $is_author ) {
2026 if ( in_array('include/archive/author', $val) ) {
2027 $page_id = $key;
2028 } else if ( in_array('exclude/archive/author', $val) ) {
2029 $page_id = '';
2030 }
2031 $author_id = get_the_author_meta('ID');
2032 if ( in_array('include/archive/author/'.$author_id, $val) ) {
2033 $page_id = $key;
2034 } else if ( in_array('exclude/archive/author/'.$author_id, $val) ) {
2035 $page_id = '';
2036 }
2037 }
2038 }
2039 }
2040 }
2041 }
2042 }
2043 return $page_id;
2044 }
2045
2046 /**
2047 * Get Date Default Format
2048 *
2049 * @since v.2.7.2
2050 * @return ARRAY | Default Data
2051 */
2052 public function get_format($format) {
2053 if ($format == 'default_date') {
2054 return get_option('date_format');
2055 } else if ($format == 'default_date_time') {
2056 return get_option('date_format').' '.get_option('time_format');
2057 } else {
2058 return $format;
2059 }
2060 }
2061
2062 /**
2063 * Common Frontend and Backend CSS and JS Scripts
2064 *
2065 * @since v.1.0.0
2066 * @return NULL
2067 */
2068 public function register_scripts_common() {
2069 if ( !( isset($GLOBALS['wp_scripts']) && isset($GLOBALS['wp_scripts']->registered) && isset($GLOBALS['wp_scripts']->registered['ultp-script']) ) ) {
2070 wp_enqueue_style('ultp-style', ULTP_URL.'assets/css/style.min.css', array(), ULTP_VER );
2071 wp_enqueue_script('ultp-script', ULTP_URL.'assets/js/ultp.min.js', array('jquery', 'wp-api-fetch'), ULTP_VER, true);
2072 wp_localize_script('ultp-script', 'ultp_data_frontend', array(
2073 'url' => ULTP_URL,
2074 'active' => ultimate_post()->is_lc_active(),
2075 'ultpSavedDLMode' => ultimate_post()->get_dl_mode(),
2076 'ajax' => admin_url('admin-ajax.php'),
2077 'security' => wp_create_nonce('ultp-nonce'),
2078 'home_url' => home_url(),
2079 'dark_logo' => get_option('ultp_site_dark_logo', false)
2080 ));
2081 }
2082 }
2083 /**
2084 * Get Dark Light Mode
2085 *
2086 * @since 4.0.0
2087 * @return string
2088 */
2089 public function get_dl_mode() {
2090 $data = get_option('postx_global', []);
2091 $mode = 'ultplight';
2092 if(!empty($data)) {
2093 $mode = isset($data['enableDark']) && $data['enableDark'] ? 'ultpdark' : 'ultplight';
2094 }
2095 return $mode;
2096 }
2097
2098 /**
2099 * Get Page Post Id ( Kadence element )
2100 *
2101 * @since v.2.8.9
2102 * @return NULL
2103 */
2104 public function get_page_post_id($blockId) {
2105 global $wpdb;
2106 $post_meta = $wpdb->get_row($wpdb->prepare("SELECT post_id FROM " . $wpdb->prefix . "postmeta WHERE meta_key=%s AND meta_value LIKE %s", '_ultp_css', '%.ultp-block-'.$blockId.'%')); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
2107 // For FSE theme
2108 if ( !$post_meta ) {
2109 if ( wp_is_block_theme() ) {
2110 $template = $wpdb->get_row($wpdb->prepare("SELECT ID FROM " . $wpdb->prefix . "posts WHERE post_content LIKE %s", '%"blockId":"'.$blockId.'"%')); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
2111 if ( isset($template->ID) ) {
2112 return $template->ID;
2113 }
2114 }
2115 }
2116 if ( $post_meta && isset($post_meta->post_id) ) {
2117 return $post_meta->post_id;
2118 }
2119 return ultimate_post()->get_ID();
2120 }
2121
2122
2123 /**
2124 * Get no Result found html
2125 *
2126 * @since v.2.9.0
2127 * @param STRING | No result found text
2128 * @return STRING | Taxonomy Lists as array
2129 */
2130 public function get_no_result_found_html($text) {
2131 return $text ? '<div class="ultp-not-found-message" role="alert">'.wp_kses($text, ultimate_post()->ultp_allowed_html_tags()).'</div>' : '';
2132 }
2133
2134 /**
2135 * Get all Saved Templates Lists
2136 *
2137 * @since v.2.9.9
2138 * @param STRING | No result found text
2139 * @return STRING | Taxonomy Lists as array
2140 */
2141 public function get_all_lists($post_type = 'post', $empty = '') {
2142 $args = array(
2143 'post_type' => $post_type,
2144 'post_status' => 'publish',
2145 'posts_per_page' => -1
2146 );
2147 $loop = new \WP_Query( $args );
2148 $data[ $empty ? $empty : '' ] = __( '- Select Template -', 'ultimate-post' );
2149 if($loop->have_posts()){
2150 foreach ( $loop->posts as $post ) {
2151 $data[$post->ID] = $post->post_title ;
2152 }
2153 }
2154 wp_reset_postdata();
2155 return $data;
2156 }
2157
2158 /**
2159 * Get ID from the Youtube URL
2160 *
2161 * @since v.3.1.7
2162 * @param STRING | No result found text
2163 * @return STRING | Taxonomy Lists as array
2164 */
2165 public function get_youtube_id($url = '') {
2166 if (strpos($url, 'youtu') !== false) {
2167 $reg = '/youtu(?:.*\/v\/|.*v\=|\.be\/)([A-Za-z0-9_\-]{11})/m';
2168 preg_match($reg, $url, $matches);
2169 if (isset($matches[1])) {
2170 return $matches[1];
2171 }
2172 }
2173 return false;
2174 }
2175
2176 /**
2177 * Get Option Value bypassing cache
2178 * Inspired By WordPress Core get_option
2179 * @since v.3.1.6
2180 * @param string $option Option Name.
2181 * @param boolean $default_value option default value.
2182 * @return mixed
2183 */
2184 public function get_option_without_cache($option, $default_value=false) {
2185 global $wpdb;
2186
2187 if ( is_scalar( $option ) ) {
2188 $option = trim( $option );
2189 }
2190
2191 if ( empty( $option ) ) {
2192 return false;
2193 }
2194
2195 $value = $default_value;
2196
2197 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
2198
2199 if ( is_object( $row ) ) {
2200 $value = $row->option_value;
2201 } else {
2202 return apply_filters( "ultp_default_option_{$option}", $default_value, $option );
2203 }
2204
2205 return apply_filters( "ultp_option_{$option}", maybe_unserialize( $value ), $option );
2206 }
2207
2208 /**
2209 * Get Transient Value bypassing cache
2210 * Inspired By WordPress Core get_transient
2211 * @since v.3.1.6
2212 * @param string $transient Transient Name.
2213 * @return mixed
2214 */
2215 public function get_transient_without_cache($transient) {
2216 $transient_option = '_transient_' . $transient;
2217 $transient_timeout = '_transient_timeout_' . $transient;
2218 $timeout = $this->get_option_without_cache( $transient_timeout );
2219
2220 if ( false !== $timeout && $timeout < time() ) {
2221 delete_option( $transient_option );
2222 delete_option( $transient_timeout );
2223 $value = false;
2224 }
2225
2226 if ( ! isset( $value ) ) {
2227 $value = $this->get_option_without_cache( $transient_option );
2228 }
2229
2230 return apply_filters( "ultp_transient_{$transient}", $value, $transient );
2231 }
2232
2233 /**
2234 * Set transient without adding to the cache
2235 * Inspired By WordPress Core set_transient
2236 * @since v.3.1.6
2237 * @param string $transient Transient Name.
2238 * @param mixed $value Transient Value.
2239 * @param integer $expiration Time until expiration in seconds.
2240 * @return bool
2241 */
2242 public function set_transient_without_cache($transient, $value, $expiration = 0) {
2243 $expiration = (int) $expiration;
2244
2245 $transient_timeout = '_transient_timeout_' . $transient;
2246 $transient_option = '_transient_' . $transient;
2247
2248 $result = false;
2249
2250 if ( false === $this->get_option_without_cache( $transient_option ) ) {
2251 $autoload = 'yes';
2252 if ( $expiration ) {
2253 $autoload = 'no';
2254 $this->add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
2255 }
2256 $result = $this->add_option_without_cache( $transient_option, $value, $autoload );
2257 } else {
2258 /*
2259 * If expiration is requested, but the transient has no timeout option,
2260 * delete, then re-create transient rather than update.
2261 */
2262 $update = true;
2263
2264 if ( $expiration ) {
2265 if ( false === $this->get_option_without_cache( $transient_timeout ) ) {
2266 delete_option( $transient_option );
2267 $this->add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
2268 $result = $this->add_option_without_cache( $transient_option, $value, 'no' );
2269 $update = false;
2270 } else {
2271 update_option( $transient_timeout, time() + $expiration );
2272 }
2273 }
2274
2275 if ( $update ) {
2276 $result = update_option( $transient_option, $value );
2277 }
2278 }
2279
2280 return $result;
2281
2282 }
2283
2284 /**
2285 * Add option without adding to the cache
2286 * Inspired By WordPress Core set_transient
2287 * @since v.3.1.6
2288 * @param string $option option name.
2289 * @param string $value option value.
2290 * @param string $autoload whether to load wordpress startup.
2291 * @return bool
2292 */
2293 public function add_option_without_cache( $option, $value = '', $autoload = 'yes' ) {
2294 global $wpdb;
2295
2296
2297 if ( is_scalar( $option ) ) {
2298 $option = trim( $option );
2299 }
2300
2301 if ( empty( $option ) ) {
2302 return false;
2303 }
2304
2305 wp_protect_special_option( $option );
2306
2307 if ( is_object( $value ) ) {
2308 $value = clone $value;
2309 }
2310
2311 $value = sanitize_option( $option, $value );
2312
2313 /*
2314 * Make sure the option doesn't already exist.
2315 */
2316
2317 if ( apply_filters( "ultp_default_option_{$option}", false, $option, false ) !== $this->get_option_without_cache( $option ) ) {
2318 return false;
2319 }
2320
2321
2322 $serialized_value = maybe_serialize( $value );
2323 $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
2324
2325
2326 $result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $serialized_value, $autoload ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
2327 if ( ! $result ) {
2328 return false;
2329 }
2330
2331 return true;
2332 }
2333
2334 /**
2335 * permission_check_for_restapi
2336 * @since v.3.2.4
2337 * @param $post_id string/bool
2338 * @param $cap string
2339 * @return bool
2340 */
2341 public function permission_check_for_restapi( $post_id=false, $cap='' ) {
2342 $cap = $cap ? $cap : 'edit_others_posts';
2343 $is_passed = false;
2344 if($post_id) {
2345 $post_author =(int) get_post_field('post_author',$post_id);
2346 $is_passed = (int)get_current_user_id()===$post_author;
2347 }
2348 return $is_passed || current_user_can($cap);
2349 }
2350
2351 /**
2352 * Sanitize params
2353 * @param $params
2354 * @return array|bool|mixed|string
2355 * @since v.4.0.0
2356 */
2357 public function ultp_rest_sanitize_params($params) {
2358 if ( is_array($params) ) {
2359 return array_map(array($this,'ultp_rest_sanitize_params'),$params);
2360 } else {
2361 if( is_bool($params) ) {
2362 return rest_sanitize_boolean($params);
2363 } else if( is_object($params) ) {
2364 return $params;
2365 } else {
2366 return sanitize_text_field($params);
2367 }
2368 }
2369 }
2370
2371 /**
2372 * Get Adv Filter Data Attributes
2373 * @param array|null $attr
2374 * @param array|null $filter_attributes
2375 * @return string
2376 * @since v.3.2.5
2377 */
2378 public function get_adv_data_attrs($attr, $filter_attributes=null) {
2379 // Adv Filter Integration
2380 $adv_filter_dataset = array();
2381
2382 if ($filter_attributes) {
2383 $adv_filter_dataset[] = 'data-filter-value="' . htmlspecialchars($filter_attributes['queryTaxValue']) . '"';
2384 $adv_filter_dataset[] = 'data-filter-type="' . htmlspecialchars($filter_attributes['queryTax']) . '"';
2385
2386 $is_adv = isset($filter_attributes['isAdv']) ? $filter_attributes['isAdv'] : 0;
2387 $adv_filter_dataset[] = 'data-filter-is-adv="' . $is_adv . '"';
2388
2389 if ($is_adv) {
2390 if ( isset($filter_attributes['queryAuthor'] ) ) {
2391 $adv_filter_dataset[] = "data-filter-author='" . $filter_attributes['queryAuthor'] . "'";
2392 }
2393
2394 if ( isset($filter_attributes['queryOrder'] ) ) {
2395 $adv_filter_dataset[] = "data-filter-order='" . $filter_attributes['queryOrder'] . "'";
2396 }
2397
2398 if ( isset($filter_attributes['queryOrderBy'] ) ) {
2399 $adv_filter_dataset[] = "data-filter-orderby='" . $filter_attributes['queryOrderBy'] . "'";
2400 }
2401
2402 if ( isset($filter_attributes['search'] ) ) {
2403 $adv_filter_dataset[] = 'data-filter-search="' . $filter_attributes['search'] . '"';
2404 }
2405
2406 if ( isset($filter_attributes['queryQuick'] ) && $filter_attributes['queryQuick'] ) {
2407 $adv_filter_dataset[] = 'data-filter-adv-sort="' . $filter_attributes['queryQuick'] . '"';
2408 }
2409 }
2410 }
2411
2412 if ($attr && isset($attr['advFilterEnable']) && $attr['advFilterEnable']) {
2413 $adv_filter_dataset[] = 'data-filter-is-adv="1"';
2414 $adv_filter_dataset[] = 'data-filter-type="multiTaxonomy"';
2415
2416 $data_filter_value = isset($attr['filterValue']) && $attr['filterValue'] ? $attr['filterValue'] : "[]";
2417 $adv_filter_dataset[] = 'data-filter-value="' . htmlspecialchars($data_filter_value) . '"';
2418
2419 $data_author = isset($attr['queryAuthor']) && $attr['queryAuthor'] ? $attr['queryAuthor'] : "[]";
2420 $adv_filter_dataset[] = 'data-filter-author="' . $data_author . '"';
2421
2422 $data_order = isset($attr['queryOrder']) && $attr['queryOrder'] ? $attr['queryOrder'] : "DESC";
2423 $adv_filter_dataset[] = 'data-filter-order="' . $data_order . '"';
2424
2425 $data_orderby = isset($attr['queryOrderBy']) && $attr['queryOrderBy'] ? $attr['queryOrderBy'] : "date";
2426 $adv_filter_dataset[] = 'data-filter-orderby="' . $data_orderby . '"';
2427
2428 $adv_filter_dataset[] = 'data-filter-search="' . (isset($attr['querySearch']) ? $attr['querySearch'] : '') . '"';
2429
2430 $adv_filter_dataset[] = 'data-filter-adv-sort="' . (isset($attr['queryQuick']) ? $attr['queryQuick'] : '') . '"';
2431 }
2432
2433 $adv_filter_dataset = implode(' ', $adv_filter_dataset);
2434 return $adv_filter_dataset;
2435 }
2436
2437 /**
2438 * Custom Text kses
2439 * @param $params
2440 * @return array|bool|mixed|string
2441 * @since v.4.0.2
2442 */
2443 public function ultp_allowed_html_tags($extras=[]) {
2444 $allowed = array(
2445 'a' => array(
2446 'href' => true,
2447 'title' => true,
2448 ),
2449 'abbr' => array(
2450 'title' => true,
2451 ),
2452 'b' => array(),
2453 'br' => array(),
2454 'blockquote' => array(
2455 'cite' => true,
2456 ),
2457 'em' => array(),
2458 'i' => array(),
2459 'q' => array(
2460 'cite' => true,
2461 ),
2462 'strong' => array(),
2463 );
2464
2465 return array_merge($allowed, $extras);
2466 }
2467
2468 /**
2469 * Allowed Block Tags
2470 * @return array
2471 * @since v.4.0.2
2472 */
2473 public function ultp_allowed_block_tags($search='') {
2474 $array_lists = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'span', 'p', 'div', 'section', 'article' ];
2475 return $search ? in_array($search, $array_lists) : $array_lists ;
2476 }
2477
2478 /**
2479 * Formats datasets for html
2480 * @since v.4.0.2
2481 *
2482 * @param array $datasets
2483 * @return string
2484 */
2485 public function get_formatted_datasets(&$datasets) {
2486 $res = '';
2487 foreach($datasets as $key => $value) {
2488 $res .= ' data-' . $key . '="' . $value . '" ';
2489 }
2490 return $res;
2491 }
2492
2493 /**
2494 * Sanitizes a attributes after running necessary checks
2495 * @since v.4.1.0
2496 *
2497 * @param array $datasets
2498 * @return string
2499 */
2500 public function sanitize_attr(&$attr, $key, $sanitize_callback = null, $def_value = '') {
2501 return isset($attr[$key]) && $attr[$key] ?
2502 (
2503 $sanitize_callback ?
2504 $sanitize_callback($attr[$key]) :
2505 $attr[$key]
2506 )
2507 : $def_value;
2508 }
2509
2510 /**
2511 * Checks if dynamic content is active
2512 * @since v.4.1.1
2513 *
2514 * @return boolean
2515 */
2516 public function is_dc_active(&$attr) {
2517 if ( class_exists('\ULTP\DCService') ) {
2518 return \ULTP\DCService::is_dc_active($attr);
2519 }
2520 return false;
2521 }
2522
2523
2524 /**
2525 * Checks all the taxonomy of a post type for a given slug. Returns the taxonomy
2526 * if it exists.
2527 * @since v.4.1.16
2528 * @param string $post_type
2529 * @param string $slug
2530 *
2531 * @return string|null
2532 */
2533 public function get_taxonomy_by_term_slug($post_type, $slug) {
2534 $taxonomies = get_object_taxonomies( $post_type );
2535 foreach ( $taxonomies as $taxonomy ) {
2536 $res = get_term_by( 'slug', $slug, $taxonomy );
2537
2538 if ( ! empty( $res ) ) {
2539 return $taxonomy;
2540 }
2541 }
2542
2543 return null;
2544 }
2545 }
2546