PluginProbe
Post Grid Gutenberg Blocks – PostX / 4.1.22
Post Grid Gutenberg Blocks – PostX v4.1.22
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.22, at classes/Functions.php

2,556 lines 104.9 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 if ( isset($_GET['ultp_exclude']) ) { // Added support for search block exclude
797 $ultp_exclude = json_decode(stripslashes($_GET['ultp_exclude']), true);
798 if ( is_array($ultp_exclude) ) {
799 $all_types = get_post_types( array( 'public' => true ), 'names' );
800 $post_type = array_diff($all_types, $ultp_exclude);
801 $archive_query['post_type'] = $post_type;
802 }
803 }
804 }
805
806 return apply_filters('ultp_archive_query', $archive_query);
807 }
808
809 // When you use load more pagination block for a grid that did not have load more feature,
810 // the incoming posts would not align properly with the blocks design and looked bad.
811 // This fixes that.
812 if (
813 isset($attr['paginationType']) &&
814 isset($attr['queryNumber2']) &&
815 isset($attr['notFirstLoad']) &&
816 $attr['paginationType'] === "loadMore" &&
817 $attr['notFirstLoad']
818 ) {
819 $query_number = $attr['queryNumber2'];
820 // $query_number = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
821 } else {
822 $query_number = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
823 }
824
825 $paged = isset($attr['paged']) ? $attr['paged'] : 1;
826 $paged = ! wp_doing_ajax() &&
827 isset( $_GET[ $attr['blockId'] . '_page' ] ) &&
828 is_numeric( $_GET[ $attr['blockId'] . '_page' ] ) ?
829 intval($_GET[ $attr['blockId'] . '_page' ]) :
830 $paged;
831
832 $query_args = array(
833 'posts_per_page' => $query_number,
834 'post_type' => $post_type == 'archiveBuilder' ? 'post' : $post_type,
835 'orderby' => isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date',
836 'order' => isset($attr['queryOrder']) ? $attr['queryOrder'] : 'desc',
837 'paged' => $paged,
838 'post_status' => 'publish'
839 );
840
841 // For Private Post 'private'
842 if (is_user_logged_in()) {
843 if( current_user_can('editor') || current_user_can('administrator') ) {
844 $query_args['post_status'] = array('publish', 'private');
845 }
846 }
847
848 if ($attr['queryType'] == 'posts') {
849 if (isset($attr['queryPosts']) && $attr['queryPosts']) {
850 unset($query_args['post_type']);
851 $data = json_decode(isset($attr['queryPosts'])?$attr['queryPosts']:'[]');
852 $final = $this->get_value($data);
853 if (count($final) > 0) {
854 $query_args['post__in'] = $final;
855 // $query_args['posts_per_page'] = -1;
856 }
857 $query_args['ignore_sticky_posts'] = 1;
858 return $query_args;
859 }
860 } else if ($attr['queryType'] == 'customPosts') {
861 if (isset($attr['queryCustomPosts']) && $attr['queryCustomPosts']) {
862 $query_args['post_type'] = $this->get_post_type();
863 $data = json_decode(isset($attr['queryCustomPosts'])?$attr['queryCustomPosts']:'[]');
864 $final = $this->get_value($data);
865 if (count($final) > 0) {
866 $query_args['post__in'] = $final;
867 // $query_args['posts_per_page'] = -1;
868 }
869 $query_args['ignore_sticky_posts'] = 1;
870 return $query_args;
871 }
872 }
873
874 if (isset($attr['queryExcludeAuthor']) && $attr['queryExcludeAuthor']) {
875 $data = json_decode(isset($attr['queryExcludeAuthor'])?$attr['queryExcludeAuthor']:'[]');
876 $final = $this->get_value($data);
877 if (count($final) > 0) {
878 $query_args['author__not_in'] = $final;
879 }
880 }
881
882
883 if (isset($attr['queryOrderBy']) && isset($attr['metaKey'])) {
884 if ($attr['queryOrderBy'] == 'meta_value_num') {
885 $query_args['meta_key'] = $attr['metaKey'];
886 }
887 }
888
889 // Include Remove from Version 2.5.4
890 if (isset($attr['queryInclude']) && $attr['queryInclude']) {
891 $_include = explode(',', $attr['queryInclude']);
892 if (is_array($_include) && count($_include)) {
893 $query_args['post__in'] = isset($query_args['post__in']) ? array_merge($query_args['post__in'], $_include) : $_include;
894 $query_args['ignore_sticky_posts'] = 1;
895 $query_args['orderby'] = 'post__in';
896 }
897 }
898
899
900 if (isset($attr['queryTax'])) {
901 if (isset($attr['queryTaxValue'])) {
902 $var = $this->getFilterQueryArgs($attr);
903 if (isset($var) && count($var) > 1) {
904 $query_args['tax_query'] = $var;
905 }
906 }
907 }
908
909 if (isset($attr['queryExcludeTerm']) && $attr['queryExcludeTerm']) {
910 $temp = json_decode($attr['queryExcludeTerm']);
911 $_term = [];
912 foreach ($temp as $val) {
913 $temp = explode('###', $val->value);
914 if (isset($temp[1])) {
915 if ( is_array($_term) && array_key_exists($temp[0], $_term)) {
916 $_term[$temp[0]][] = $temp[1];
917 } else {
918 $_term[$temp[0]] = array($temp[1]);
919 }
920 }
921 }
922 if (count($_term) > 0) {
923 $final = array('relation' => 'AND');
924 foreach ($_term as $key => $val) {
925 $final[] = array(
926 'taxonomy' => $key,
927 'field' => 'slug',
928 'terms' => $val,
929 'operator' => 'NOT IN',
930 );
931 }
932
933 if ( is_array($query_args) && array_key_exists('tax_query', $query_args)) {
934 $query_args['tax_query'] = array(
935 'relation' => 'AND',
936 $query_args['tax_query']
937 );
938 $query_args['tax_query'][] = $final;
939 } else {
940 $query_args['tax_query'] = $final;
941 }
942 }
943 }
944
945 if (isset($attr['queryExclude']) && $attr['queryExclude']) {
946 $_exclude = (substr($attr['queryExclude'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryExclude'])) : explode(',', $attr['queryExclude']);
947 if (is_array($_exclude) && count($_exclude)) {
948 $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $_exclude) : $_exclude;
949 }
950 }
951
952 if (isset($attr['queryUnique']) && $attr['queryUnique']) {
953 global $unique_ID;
954 if (isset($unique_ID[$attr['queryUnique']])) {
955 $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']];
956 }
957 }
958 // exclude current post from Post blocks // v.2.9.6
959 if (is_single() && get_the_ID()) {
960 $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());
961 }
962
963 if (isset($attr['queryQuick'])) {
964 if ($attr['queryQuick'] != '' && $post_type != 'archiveBuilder') {
965 $query_args = ultimate_post()->get_quick_query($attr, $query_args);
966 }
967 }
968
969 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
970 $offset = $this->get_offset($attr['queryOffset'], $query_args);
971 $query_args = array_merge($query_args, $offset);
972 }
973
974 if (isset($attr['queryAuthor']) && $attr['queryAuthor'] ) {
975 $_include = (substr($attr['queryAuthor'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryAuthor'])) : explode(',', $attr['queryAuthor']);
976 if (is_array($_include) && count($_include)) {
977 $query_args['author__in'] = $_include;
978 }
979 }
980
981 if (isset($attr['querySearch']) && $attr['querySearch'] ) {
982 $query_args['s'] = $attr['querySearch'];
983 }
984
985 if(isset($attr['querySticky']) && $attr['querySticky']) {
986 if (filter_var($attr['querySticky'], FILTER_VALIDATE_BOOLEAN)) {
987 $sticky = get_option( 'sticky_posts', [] );
988 $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $sticky) : $sticky;
989 }
990 }
991
992 if (!isset($attr['ajaxCall'])) {
993 if(isset($attr['filterShow']) && $attr['filterShow'] && $attr['filterShow'] != 'false') {
994 if(isset($attr['checkFilter']) && isset($attr['queryTax']) && isset($attr['queryTaxValue']) ) {
995 $var = $this->getFilterQueryArgs($attr);
996 if (isset($var) && count($var) > 1) {
997 $query_args['tax_query'] = $var;
998 }
999 }
1000 else if(isset($attr['filterType']) && isset($attr['filterValue'])) {
1001 $filterValue = strlen($attr['filterValue']) > 2 ? $attr['filterValue'] : [];
1002 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
1003 if (is_array($filterValue) && count($filterValue) > 0 && $attr['filterType']) {
1004 $final = array('relation' => 'OR');
1005 foreach ($filterValue as $key => $val) {
1006 $final[] = array(
1007 'taxonomy' => $attr['filterType'],
1008 'field' => 'slug',
1009 'terms' => $val,
1010 // 'operator' => '=',
1011 );
1012 }
1013 $query_args['tax_query'] = $final;
1014 }
1015 }
1016 }
1017 }
1018
1019 // Advanced Filter Select Dropdown Default value
1020 // only on initial page load
1021 if (
1022 ! wp_doing_ajax() &&
1023 isset($attr['advFilterEnable']) &&
1024 $attr['advFilterEnable'] === true &&
1025 isset($attr['defQueryTax']) &&
1026 count($attr['defQueryTax']) > 0
1027 ) {
1028 $tax_query = array(
1029 'relation' =>
1030 isset($attr['advRelation']) &&
1031 ('AND' === $attr['advRelation'] || 'OR' === $attr['advRelation'])
1032 ? $attr['advRelation'] : 'AND'
1033 );
1034 $is_valid = false;
1035
1036 foreach ($attr['defQueryTax'] as $_ => $defQueryTaxValue) {
1037 $term = explode('###', $defQueryTaxValue);
1038
1039 // Validation
1040 if (
1041 ! in_array($term[0], array('category', 'tags', 'author', 'custom_tax'), true) ||
1042 '_all' === $term[1] ||
1043 empty( $term[1] )
1044 ) {
1045 continue;
1046 }
1047
1048 if ('author' === $term[0]) {
1049
1050 if ( ! is_numeric( $term[1] ) ) {
1051 continue;
1052 }
1053
1054 $query_args['author__in'] = $term[1];
1055 }
1056
1057 elseif( 'custom_tax' === $term[0] && isset( $attr['queryType'] ) ) {
1058 $post_type = sanitize_key($attr['queryType']);
1059 $slug = sanitize_key($term[1]);
1060
1061 // These are not custom post type
1062 if ( in_array($post_type, array('posts', 'customPosts'), true) ) {
1063 continue;
1064 }
1065
1066 $taxonomy = $this->get_taxonomy_by_term_slug( $post_type, $slug );
1067
1068 if (! empty($taxonomy)) {
1069 $q = array(
1070 'field' => 'slug',
1071 'taxonomy' => $taxonomy,
1072 'terms' => $slug
1073 );
1074
1075 $tax_query[] = $q;
1076 $is_valid = true;
1077 }
1078 }
1079
1080 else {
1081 if ( ! is_numeric( $term[1] ) ) {
1082 continue;
1083 }
1084
1085 $q = array(
1086 'field' => 'term_id',
1087 'taxonomy' => 'tags' === $term[0] ? 'post_tag' : 'category',
1088 'terms' => $term[1]
1089 );
1090
1091 $tax_query[] = $q;
1092 $is_valid = true;
1093 }
1094 }
1095
1096 if ($is_valid) {
1097 $query_args['tax_query'] = $tax_query;
1098 }
1099 }
1100
1101 $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
1102
1103 return apply_filters('ultp_frontend_query', $query_args);
1104 }
1105
1106 /**
1107 * Get Page Offset
1108 *
1109 * @since v.1.0.0
1110 * @param | Offset Number(NUMBER) | Query Arg(ARRAY)
1111 * @return ARRAY
1112 */
1113 function get_offset($queryOffset, $query_args) {
1114 $query = array();
1115 if ($query_args['paged'] > 1) {
1116 $offset_post = wp_get_recent_posts($query_args, OBJECT);
1117 if (count($offset_post) > 0 ) {
1118 $offset = array();
1119 for($x = count($offset_post); $x > count($offset_post) - $queryOffset; $x--) {
1120 $offset[] = $offset_post[$x-1]->ID;
1121 }
1122 $query['post__not_in'] = $offset;
1123 }
1124 } else {
1125 $query['offset'] = isset($queryOffset) ? $queryOffset : 0;
1126 }
1127 return $query;
1128 }
1129
1130
1131 /**
1132 * Get Page Number
1133 *
1134 * @since v.1.0.0
1135 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1136 * @return ARRAY
1137 */
1138 public function get_page_number($attr, $post_number) {
1139 if ($post_number > 0) {
1140 if (isset($attr['queryOffset']) && $attr['queryOffset']) {
1141 $post_number = $post_number - (int)$attr['queryOffset'];
1142 }
1143 $post_per_page = isset($attr['queryNumber']) ? ($attr['queryNumber'] ? $attr['queryNumber'] : 1) : 3;
1144 $pages = ceil($post_number/$post_per_page);
1145 return $pages ? $pages : 1;
1146 }else{
1147 return 1;
1148 }
1149 }
1150
1151
1152 /**
1153 * Get Image Size
1154 *
1155 * @since v.1.0.0
1156 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1157 * @return ARRAY
1158 */
1159 public function get_image_size() {
1160 $sizes = get_intermediate_image_sizes();
1161 $filter = array('full' => 'Full');
1162 foreach ($sizes as $value) {
1163 $title = ucwords(str_replace(array('_', '-', 'ultp'), array(' ', ' ', 'PostX'), $value));
1164 switch ($value) {
1165 case 'thumbnail':
1166 $title = $title.' [150x150]';
1167 break;
1168 case 'medium':
1169 $title = $title.' [300x300]';
1170 break;
1171 case 'large':
1172 $title = $title.' [1024x1024]';
1173 break;
1174 case 'ultp_layout_landscape_large':
1175 $title = $title.' [1200x800]';
1176 break;
1177 case 'ultp_layout_landscape':
1178 $title = $title.' [870x570]';
1179 break;
1180 case 'ultp_layout_portrait':
1181 $title = $title.' [600x900]';
1182 break;
1183 case 'ultp_layout_square':
1184 $title = $title.' [600x600]';
1185 break;
1186 default:
1187 break;
1188 }
1189 $filter[$value] = $title;
1190 }
1191 return $filter;
1192 }
1193
1194
1195 /**
1196 * Get All PostType Registered
1197 *
1198 * @since v.1.0.0
1199 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1200 * @return ARRAY
1201 */
1202 public function get_post_type() {
1203 $filter = apply_filters('ultp_public_post_type', true);
1204 $post_type = get_post_types( ($filter ? ['public' => true] : ''), 'names' );
1205 return array_diff($post_type, array( 'attachment' ));
1206 }
1207
1208 /**
1209 * Get Pagination Url
1210 *
1211 * @since v.2.8.9
1212 * @param | pageNo (NUMBER) | baseUrl (STRING)
1213 * @return STRING
1214 */
1215 public function generatePaginationUrl($pageNo , $baseUrl) {
1216 if($baseUrl) {
1217 $url = $baseUrl.($pageNo == 1? '' : "page/".$pageNo);
1218 }
1219 else {
1220 $url = get_pagenum_link($pageNo);
1221 }
1222 return $url;
1223 }
1224 /**
1225 * Get Pagination HTML
1226 *
1227 * @since v.1.0.0
1228 * @param | pages (NUMBER) | Pagination Nav (STRING) | Pagination Text |
1229 * @return STRING
1230 */
1231 public function pagination($pages = '', $paginationNav = '', $paginationText = '', $paginationAjax = true, $baseUrl = '', $blockId = '') {
1232 $html = '';
1233 $showitems = 3;
1234 $paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
1235 $paged = $paged ? $paged : 1;
1236
1237 $paged = ! wp_doing_ajax() &&
1238 isset( $_GET[ $blockId . '_page' ] ) &&
1239 is_numeric( $_GET[ $blockId . '_page' ] ) ?
1240 intval($_GET[ $blockId . '_page' ]) : $paged;
1241
1242 if ($pages == '') {
1243 global $wp_query;
1244 $pages = $wp_query->max_num_pages;
1245 if (!$pages) {
1246 $pages = 1;
1247 }
1248 }
1249
1250 $data = ($paged>=3?[($paged-1),$paged,$paged+1]:[1,2,3]);
1251
1252 $paginationText = explode('|', $paginationText);
1253
1254 $prev_text = isset($paginationText[0]) ? esc_html($paginationText[0]) : __("Previous", "ultimate-post");
1255 $next_text = isset($paginationText[1]) ? esc_html($paginationText[1]) : __("Next", "ultimate-post");
1256
1257 if (1 != $pages) {
1258 $html .= '<ul class="ultp-pagination">';
1259 $display_none = 'style="display:none"';
1260 if ($pages > 1) {
1261 $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>';
1262 }
1263 if ($pages > 3) {
1264 $html .= '<li class="ultp-first-pages" '.($paged < 2 ? $display_none : "").' data-current="1"><a href="'.$this->generatePaginationUrl(1, $baseUrl).'">1</a></li>';
1265 }
1266 if ($pages > 4) {
1267 $html .= '<li class="ultp-first-dot"'.($paged == 1 ? $display_none : "").'><a href="#">...</a></li>';
1268 }
1269 foreach ($data as $i) {
1270 if ( $pages > 3 && $pages == $i ) {
1271 continue;
1272 }
1273 if ($pages >= $i) {
1274 $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>';
1275 }
1276 }
1277 if ($pages > 4) {
1278 $html .= '<li class="ultp-last-dot" '.($pages <= $paged + 1 ? $display_none : "").'><a href="#">...</a></li>';
1279 }
1280 if ($pages > 3) {
1281 $html .= '<li class="ultp-last-pages" data-current="'.$pages.'"><a href="'.$this->generatePaginationUrl($pages, $baseUrl).'">'.$pages.'</a></li>';
1282 }
1283 if ($paged != $pages) {
1284 $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>';
1285 }
1286 $html .= '</ul>';
1287 }
1288 return $html;
1289 }
1290
1291 /**
1292 * Svg Icon Source
1293 *
1294 * @since v.1.0.0
1295 * @param string $ultp_icons
1296 * @return string
1297 */
1298 public function get_svg_icon( $ultp_icons = '' ) {
1299 $svg = '';
1300 if ( $ultp_icons ) {
1301 $svg = $this->get_path_file_contents(ULTP_PATH . 'assets/img/iconpack/' . $ultp_icons . '.svg');
1302 }
1303 return $svg;
1304 }
1305
1306 /**
1307 * Get Taxonomy Lists
1308 *
1309 * @since v.1.0.0
1310 * @param STRING | Taxonomy Slug
1311 * @return ARRAY
1312 */
1313 public function taxonomy( $prams = 'category' ) {
1314 $data = array();
1315
1316 $terms = get_terms( is_string($prams) ? array(
1317 'taxonomy' => $prams,
1318 'hide_empty' => false
1319 ) : $prams);
1320 if ( ! is_wp_error( $terms ) ) {
1321 foreach ( $terms as $val ) {
1322 $data[ urldecode_deep( $val->slug ) ] = $val->name;
1323 }
1324 }
1325 return $data;
1326 }
1327
1328
1329 /**
1330 * Get Taxonomy Lists
1331 *
1332 * @since v.2.9.0
1333 * @param STRING | Taxonomy Slug
1334 * @return ARRAY
1335 */
1336 public function builder_preview( $tax_slug, $number ) {
1337 $data = array();
1338 $term_data = get_terms( array( 'taxonomy' => $tax_slug, 'hide_empty' => true, 'number' => $number, 'parent' => 0 ) );
1339 if ( ! empty( $term_data ) ) {
1340 foreach ( $term_data as $terms ) {
1341 $data[] = $this->get_tax_data( $terms );
1342 }
1343 }
1344 return $data;
1345 }
1346
1347 /**
1348 * Get Taxonomy Data Lists
1349 *
1350 * @since v.1.0.0
1351 * @param OBJECT | Taxonomy Object
1352 * @return ARRAY
1353 */
1354 public function get_tax_data($terms) {
1355 $temp = array();
1356 $thumbnail_id = get_term_meta( $terms->term_id, 'ultp_category_image', true );
1357 $image_src = array();
1358 if ($thumbnail_id) {
1359 $image_sizes = ultimate_post()->get_image_size();
1360 foreach ($image_sizes as $key => $value) {
1361 $img_src = wp_get_attachment_image_src($thumbnail_id, $key, false);
1362 if( $img_src ) {
1363 $image_src[$key] = $img_src[0];
1364 }
1365 }
1366 }
1367 $temp['url'] = get_term_link($terms);
1368 $temp['thumbnail_id'] = $thumbnail_id;
1369 $temp['name'] = $terms->name;
1370 $temp['desc'] = $terms->description;
1371 $temp['count'] = $terms->count;
1372 $temp['image'] = $image_src;
1373 $color = get_term_meta($terms->term_id, 'ultp_category_color', true);
1374 $temp['color'] = $color ? $color : '#037fff';
1375 return $temp;
1376 }
1377
1378 public function get_category_data($catSlug, $number = 40, $type = '', $tax_slug = 'category', $archiveBuilder = '') {
1379 $data = array();
1380 if ($type == 'child') {
1381 if($archiveBuilder) {
1382 $data = $this->builder_preview( $tax_slug, $number );
1383 }
1384 else {
1385 if(is_category()) {
1386 $catSlug = array(get_queried_object()->slug);
1387 }
1388 $image = '';
1389 if (!empty($catSlug)) {
1390 foreach ($catSlug as $cat) {
1391 $parent_term = get_term_by('slug', $cat, $tax_slug);
1392 if (!empty($parent_term)) {
1393 $term_data = get_terms(array(
1394 'taxonomy' => $tax_slug,
1395 'hide_empty' => true,
1396 'number' => $number,
1397 'parent' => $parent_term->term_id
1398 ));
1399 if (!empty($term_data)) {
1400 foreach ($term_data as $terms) {
1401 $data[] = $this->get_tax_data($terms);
1402 }
1403 }
1404 }
1405 }
1406 }
1407 }
1408 } else if ($type == 'parent') {
1409 $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 ) );
1410 if($archiveBuilder && !empty($term_data)) {
1411 $term_data = array($term_data[0]);
1412 }
1413 if (!empty($term_data)) {
1414 foreach ($term_data as $terms) {
1415 if (!empty($terms->term_id)) {
1416 $data[] = $this->get_tax_data($terms);
1417 }
1418 }
1419 }
1420 } else if ($type == 'custom') {
1421 foreach ($catSlug as $cat) {
1422 $terms = get_term_by('slug', $cat, $tax_slug);
1423 if (!empty($terms)) {
1424 $data[] = $this->get_tax_data($terms);
1425 }
1426 }
1427 } else if ($type == 'immediate_child') {
1428 if($archiveBuilder) {
1429 $data = $this->builder_preview( $tax_slug, $number );
1430 } else {
1431 $id_ = get_queried_object();
1432 if (isset($id_->term_id)) {
1433 $term_data = get_terms( array( 'taxonomy' => $tax_slug, 'hide_empty' => true, 'number' => 100, 'parent' => $id_->term_id) );
1434 if (!empty($term_data)) {
1435 foreach ($term_data as $terms) {
1436 $data[] = $this->get_tax_data($terms);
1437 }
1438 }
1439 }
1440 }
1441 } else if ($type == 'allchild') {
1442 if($archiveBuilder) {
1443 $data = $this->builder_preview( $tax_slug, $number );
1444 } else {
1445 $id_ = get_queried_object();
1446 if (isset($id_->term_taxonomy_id)) {
1447 $termchildren = get_term_children( $id_->term_taxonomy_id, $tax_slug );
1448 foreach ($termchildren as $key => $value) {
1449 $terms = get_term_by('id', $value, $tax_slug);
1450 $data[] = $this->get_tax_data($terms);
1451 }
1452 }
1453 }
1454 } else if ($type == 'current_level') {
1455 if($archiveBuilder) {
1456 $data = $this->builder_preview( $tax_slug, $number );
1457 } else {
1458 $id_ = get_queried_object();
1459 if (isset($id_->parent)) {
1460 $term_data = get_terms( array('taxonomy' => $tax_slug, 'hide_empty' => true, 'number' => $number, 'parent' => $id_->parent ) );
1461 if (!empty($term_data)) {
1462 foreach ($term_data as $terms) {
1463 if ($terms->term_id != $id_->term_id) {
1464 $data[] = $this->get_tax_data($terms);
1465 }
1466 }
1467 }
1468 }
1469 }
1470 } else {
1471 $term_data = get_terms( array('taxonomy' => $tax_slug, 'hide_empty' => true, 'number' => $number));
1472 if (!empty($term_data)) {
1473 foreach ($term_data as $terms) {
1474 $data[] = $this->get_tax_data($terms);
1475 }
1476 }
1477 }
1478 return $data;
1479 }
1480
1481
1482 /**
1483 * Get Next Previous HTML
1484 *
1485 * @since v.1.0.0
1486 * @param OBJECT | Taxonomy Object
1487 * @return STRING
1488 */
1489 public function next_prev() {
1490 $html = '';
1491 $html .= '<ul>';
1492 $html .= '<li>';
1493 $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
1494 $html .= ultimate_post()->get_svg_icon('leftAngle2').'<span class="screen-reader-text">'.esc_html__("Previous", "ultimate-post").'</span>';
1495 $html .= '</a>';
1496 $html .= '</li>';
1497 $html .= '<li>';
1498 $html .= '<a class="ultp-next-action">';
1499 $html .= ultimate_post()->get_svg_icon('rightAngle2').'<span class="screen-reader-text">'.esc_html__("Next", "ultimate-post").'</span>';
1500 $html .= '</a>';
1501 $html .= '</li>';
1502 $html .= '</ul>';
1503 return $html;
1504 }
1505
1506
1507 /**
1508 * Get Loading HTML
1509 *
1510 * @since v.1.0.0
1511 * @param NULL
1512 * @return STRING
1513 */
1514 public function postx_loading() {
1515 $html = '';
1516 $style = ultimate_post()->get_setting('preloader_style');
1517 if ($style == 'style2') {
1518 $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
1519 } else {
1520 $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>';
1521 }
1522 return '<div class="ultp-loading">'.$html.'</div>';
1523 }
1524
1525
1526 /**
1527 * Get Filter HTML
1528 *
1529 * @since v.1.0.0
1530 * @param | Filter Text (STRING) | Filter Type (STRING) | Filter Value (ARRAY) | Filter Cat (ARRAY) | Filter Tag (ARRAY) |
1531 * @return STRING
1532 */
1533 public function filter_html($filterText = '', $filterType = '', $filterValue = '[]', $filterMobileText = '...', $filterMobile = true) {
1534 $html = '';
1535 $html .= '<ul '.($filterMobile ? 'class="ultp-flex-menu"' : '').' data-name="'.($filterMobileText ? $filterMobileText : '&nbsp;').'">';
1536 $cat = $this->taxonomy($filterType);
1537 if ($filterText) {
1538 $html .= '<li class="filter-item"><a class="filter-active" data-taxonomy="" href="#">'.$filterText.'</a></li>';
1539 }
1540 if ($filterValue) {
1541 $filterValue = strlen($filterValue) > 2 ? $filterValue : [];
1542 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
1543 if (is_array($filterValue) && count($filterValue)) {
1544 foreach ($filterValue as $val) {
1545 $val = isset($val->value) ? $val->value : $val;
1546 $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($cat[$val]) ? $cat[$val] : $val).'</a></li>';
1547 }
1548 }
1549 }
1550 $html .= '</ul>';
1551 return $html;
1552 }
1553
1554
1555 /**
1556 * Check License Status
1557 *
1558 * @since v.2.4.2
1559 * @return BOOLEAN | Is pro license active or not
1560 */
1561 public function is_lc_active() {
1562 if (function_exists('ultimate_post_pro')) {
1563 return get_option('edd_ultp_license_status') == 'valid' ? true : false;
1564 }
1565 return false;
1566 }
1567
1568
1569 /**
1570 * Get SEO Meta
1571 *
1572 * @since v.2.4.3
1573 * @param NUMBER | Post ID
1574 * @return STRING | SEO Meta Description or Excerpt
1575 */
1576 public function get_excerpt($post_id = 0, $showSeoMeta = 0, $showFullExcerpt = 0, $excerptLimit = 55) {
1577 $html = '';
1578 if ($showSeoMeta) {
1579 $str = '';
1580 if ( function_exists('ultimate_post_pro') ) {
1581 if ( ultimate_post()->get_setting('ultp_yoast') == 'true' ) {
1582 $str = method_exists( ultimate_post_pro(), 'get_yoast_meta' ) ? ultimate_post_pro()->get_yoast_meta($post_id) : '';
1583 } else if ( ultimate_post()->get_setting('ultp_rankmath') == 'true' ) {
1584 $str = method_exists( ultimate_post_pro(), 'get_rankmath_meta' ) ? ultimate_post_pro()->get_rankmath_meta($post_id) : '';
1585 } else if ( ultimate_post()->get_setting('ultp_aioseo') == 'true' ) {
1586 $str = method_exists( ultimate_post_pro(), 'get_aioseo_meta' ) ? ultimate_post_pro()->get_aioseo_meta($post_id) : '';
1587 } else if ( ultimate_post()->get_setting('ultp_seopress') == 'true' ) {
1588 $str = method_exists( ultimate_post_pro(), 'get_seopress_meta' ) ? ultimate_post_pro()->get_seopress_meta($post_id) : '';
1589 } else if ( ultimate_post()->get_setting('ultp_squirrly') == 'true' ) {
1590 $str = method_exists( ultimate_post_pro(), 'get_squirrly_meta' ) ? ultimate_post_pro()->get_squirrly_meta($post_id) : '';
1591 }
1592 }
1593 $html = $str ? $str : ultimate_post()->excerpt($post_id, $excerptLimit);
1594 } else {
1595 if ($showFullExcerpt == 0 ) {
1596 $html = ultimate_post()->excerpt($post_id, $excerptLimit);
1597 } else {
1598 $html = get_the_excerpt();
1599 }
1600 }
1601 return $html;
1602 }
1603
1604 public function get_embeded_video($url, $autoPlay, $loop, $mute, $playback, $preload, $poster, $inline, $size) {
1605 $vidAutoPlay = $vidloop = $vidloop = $vidmute = $vidplayback = $vidPoster = $vidInline = "";
1606
1607 if($autoPlay){
1608 $vidAutoPlay = "autoplay";
1609 }
1610 if($poster){
1611 $vidPoster = 'poster="'.$poster["url"].'"';
1612 }
1613 if($loop){
1614 $vidloop = "loop";
1615 }
1616 if($mute){
1617 $vidmute = "muted";
1618 }
1619 if($playback){
1620 $vidplayback = "controls";
1621 }
1622 if($inline){
1623 $vidInline = "playsinline";
1624 }
1625 if (!empty($url)) {
1626 $embeded = wp_oembed_get($url, $size);
1627 if ($embeded == false) {
1628 $format = '';
1629 $url = strtolower($url);
1630 if (strpos($url, '.mp4')) {
1631 $format = 'mp4';
1632 } elseif (strpos($url, '.ogg')) {
1633 $format = 'ogg';
1634 } elseif (strpos($url, '.webm')) {
1635 $format = 'WebM';
1636 }
1637 $embeded = '<video
1638 '.$vidloop.'
1639 '.$vidmute.'
1640 '.$vidplayback.'
1641 preload="'.$preload.'"
1642 '.$vidAutoPlay.'
1643 '.$vidPoster.'
1644 '.$vidInline.'
1645 class="ultp-video-html"
1646 ><source src="' . $url . '" type="video/' . $format . '">' . __('Your browser does not support the video tag.', 'ultimate-post') . '</video>';
1647 return '<div class="ultp-video-wrapper">'.$embeded.'</div>';
1648 }
1649 return '<div class="ultp-video-wrapper ultp-embaded-video">'.$embeded.'</div>';
1650 } else {
1651 return false;
1652 }
1653 }
1654
1655 /**
1656 * Get Public taxonomy Lists
1657 *
1658 * @since v.2.7.0
1659 * @param NULL
1660 * @return ARRAY | Taxonomy Lists as array
1661 */
1662 public function get_taxonomy_list() {
1663 $taxonomy = get_taxonomies(array('public' => true));
1664 return empty($taxonomy) ? [] : array_keys($taxonomy);
1665 }
1666
1667 /**
1668 * Content Print
1669 *
1670 * @since v.2.7.0
1671 * @param NUMBER | Post ID
1672 * @return STRING | Content of the Post
1673 */
1674 public function get_post_content($post_id, $builder_type = '') {
1675 $content_post = get_post($post_id);
1676 $content = $content_post->post_content;
1677 if($builder_type == 'divi' || $builder_type == 'elementor') {
1678 $content = apply_filters('the_content', $content);
1679 } else {
1680 global $wp_embed;
1681 $content = $wp_embed->autoembed( $content );
1682 $content = do_blocks($content);
1683 $content = do_shortcode($content);
1684 }
1685 $content = str_replace(']]>', ']]&gt;', $content);
1686 $content = preg_replace('%<p>&nbsp;\s*</p>%', '', $content);
1687 $content = preg_replace('/^(?:<br\s*\/?>\s*)+/', '', $content);
1688 echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1689 }
1690
1691 /**
1692 * String Part finder inside array
1693 *
1694 * @since v.2.7.0 updated 4.1.12
1695 * @return ARRAY | String Part
1696 */
1697 public function in_array_part($part, $data, $toR = '') {
1698 $res = array();
1699 foreach( $data as $key => $val ) {
1700 if ( strpos( $val, $part ) !== false ) {
1701 if ( $toR == 'bool' ) {
1702 return true;
1703 } else if ( $toR == 'value' ) {
1704 return $val;
1705 }
1706 $res[$key] = $val;
1707 }
1708 }
1709 if ( $toR == 'bool' ) {
1710 return false;
1711 } else if ( $toR == 'value' ) {
1712 return '';
1713 }
1714 return $res;
1715 }
1716
1717 /**
1718 * Builder Conditions
1719 *
1720 * @since v.2.7.0 updated 4.1.12
1721 * @param STRING | Type of Return
1722 * @return MIXED || ID or Path
1723 */
1724 public function builder_check_conditions( $type = 'return', $cus_condition = '' ) {
1725 $page_id = '';
1726 $conditions = $cus_condition ? $cus_condition : get_option('ultp_builder_conditions', array());
1727
1728 if ( $type == 'header' || $type == 'footer' ) {
1729 if ( !empty($conditions[$type]) ) {
1730 foreach( $conditions[$type] as $key => $val) {
1731 if ( 'publish' == get_post_status($key) && !empty($val) ) {
1732 if ( in_array('include/'.$type.'/entire_site', $val) ) {
1733 $page_id = $key;
1734 } else if ( in_array('exclude/'.$type.'/entire_site', $val) ) {
1735 $page_id = '';
1736 }
1737
1738 $c_page = ( is_archive() || is_search() ) ? 'archive' : 'singular';
1739 $hf_archive = $this->in_array_part($type.'/'.$c_page, $val, '');
1740 if ( !empty($hf_archive) ) {
1741 foreach($hf_archive as $k => $v) {
1742 if ( strpos($v, 'include/'.$type.'/'.$c_page) !== false ) {
1743 $temp = $this->builder_check_conditions('return_h', [$c_page => [$key => [str_replace($type."/", "", $v)]]]);
1744 $page_id = $temp ? $temp : $page_id;
1745 } else if (strpos($v, 'exclude/'.$type.'/'.$c_page) !== false) {
1746 $temp = $this->builder_check_conditions('return_f', [$c_page => [$key => [str_replace("exclude/".$type, "include", $v)]]]);
1747 $page_id = $temp ? '' : $page_id;
1748 }
1749 }
1750 }
1751 }
1752 }
1753 }
1754 } else {
1755 // 404 page
1756 if ( !empty($conditions['404']) && is_404() ) {
1757 foreach( $conditions['404'] as $key => $val ) {
1758 if ( 'publish' == get_post_status($key) ) {
1759 $page_id = $key;
1760 }
1761 }
1762 }
1763 // Singular or Front Page
1764 else if (
1765 (
1766 !empty($conditions['singular']) ||
1767 !empty($conditions['front_page'])
1768 ) &&
1769 (
1770 is_singular() ||
1771 is_front_page() ||
1772 is_home()
1773 )
1774 ) {
1775 $obj = get_queried_object();
1776 $queried_is_obj = is_object($obj);
1777 // front page only
1778 if (
1779 ( is_front_page() && is_home() ) ||
1780 ( is_home() && !$queried_is_obj ) ||
1781 ( is_singular() && is_front_page() && $queried_is_obj )
1782 ) {
1783 $f_conditions = [];
1784 if ( !empty($conditions['front_page']) ) {
1785 $f_conditions = $conditions['front_page'];
1786 } else if ( !empty($conditions['singular']) ) {
1787 $f_conditions = $conditions['singular'];
1788 }
1789 if ( !empty($f_conditions) ) {
1790 foreach( $f_conditions as $key => $val ) {
1791 if (
1792 ( is_array($val) && in_array('include/singular/front_page', $val) ) ||
1793 ( is_array($val) && in_array('include/front_page', $val) ) ||
1794 'include/front_page' == $val
1795 ) {
1796 if ( 'publish' == get_post_status($key) ) {
1797 $page_id = $key;
1798 }
1799 }
1800 }
1801 }
1802 }
1803 // Singular page
1804 else if ( !empty($conditions['singular']) ) {
1805 foreach( $conditions['singular'] as $key => $val ) {
1806 if ( 'publish' == get_post_status($key) ) {
1807 // All Post Type -----Prority 1
1808 if ( $queried_is_obj ) {
1809 if ( in_array('include/singular/'.$obj->post_type, $val) ) {
1810 $page_id = $key;
1811 } else if ( in_array('exclude/singular/'.$obj->post_type, $val) ) {
1812 $page_id = '';
1813 }
1814 }
1815
1816 $singular_in_tax = $this->in_array_part("/singular/in_", $val, '');
1817 if ( !empty($singular_in_tax) ) {
1818 $tax_list = $this->get_taxonomy_list();
1819 foreach( $tax_list as $tax ) {
1820 if ( in_array('include/singular/in_'.$tax.'_children', $singular_in_tax) ) {
1821 $page_id = $key;
1822 } else if ( in_array('exclude/singular/in_'.$tax.'_children', $singular_in_tax) ) {
1823 $page_id = '';
1824 }
1825
1826 if ( $queried_is_obj ) {
1827 $singular_in_tax_children = $this->in_array_part('/singular/in_'.$tax.'_children/', $singular_in_tax, '');
1828 foreach( $singular_in_tax_children as $v ) {
1829 $data = explode("/", $v);
1830 if ( isset($data[3]) && $data[3] ) {
1831 $childs = get_term_children( $data[3], $tax );
1832 if ( !empty($childs) && has_term($childs, $tax) ) {
1833 $page_id = $data[0] == 'exclude' ? '' : $key;
1834 }
1835 }
1836 }
1837 }
1838
1839 if ( in_array('include/singular/in_'.$tax, $singular_in_tax) ) {
1840 if ( $tax == "post_tag" && $queried_is_obj) {
1841 $cat = get_the_terms($obj->ID, "post_tag");
1842 if ( !empty( $cat ) ) {
1843 $page_id = $key;
1844 }
1845 } else {
1846 $page_id = $key;
1847 }
1848 } else if ( in_array('exclude/singular/in_'.$tax, $singular_in_tax) ) {
1849 $page_id = '';
1850 }
1851
1852 if ( $queried_is_obj ) {
1853 $singular_in_tax_only = $this->in_array_part('/singular/in_'.$tax.'/', $singular_in_tax, '');
1854 foreach( $singular_in_tax_only as $v ) {
1855 $data = explode("/", $v);
1856 if ( isset($data[3]) && $data[3] ) {
1857 if ( is_object_in_term($obj->ID , $tax, $data[3] ) ) {
1858 $page_id = $data[0] == 'exclude' ? '' : $key;
1859 }
1860 }
1861 }
1862 }
1863 }
1864 }
1865
1866 // Posts by author -----Prority 9
1867 if ( in_array('include/singular/post_by_author', $val) ) {
1868 $page_id = $key;
1869 } else if ( in_array('exclude/singular/post_by_author', $val) ) {
1870 $page_id = '';
1871 }
1872 if ( $queried_is_obj ) {
1873 if ( in_array('include/singular/post_by_author/'.$obj->post_author, $val) ) {
1874 $page_id = $key;
1875 } else if ( in_array('exclude/singular/post_by_author/'.$obj->post_author, $val) ) {
1876 $page_id = '';
1877 }
1878 // Post Type with specific id -----Prority 10
1879 if ( in_array('include/singular/'.$obj->post_type.'/'.$obj->ID, $val) ) {
1880 $page_id = $key;
1881 } else if ( in_array('exclude/singular/'.$obj->post_type.'/'.$obj->ID, $val) ) {
1882 $page_id = '';
1883 }
1884 }
1885 }
1886 }
1887 }
1888 }
1889
1890 // Archive and Search Page
1891 else if ( !empty($conditions['archive']) ) {
1892 // Search Page
1893 if ( is_search() ) {
1894 foreach( $conditions['archive'] as $key => $val ) {
1895 if ( 'publish' == get_post_status($key) ) {
1896 if ( in_array('include/archive/search', $val) ) {
1897 $page_id = $key;
1898 } else if ( in_array('exclude/archive/search', $val) ) {
1899 $page_id = '';
1900 }
1901 }
1902 }
1903 }
1904 // Archive Page
1905 else if ( is_archive() ) {
1906 $is_cat = is_category();
1907 $is_tag = is_tag();
1908 $is_tax = is_tax();
1909 $is_date = is_date();
1910 $is_author = is_author();
1911 $taxonomy = ( $is_cat || $is_tag || $is_tax ) ? get_queried_object() : (object)[];
1912
1913 foreach( $conditions['archive'] as $key => $val ) {
1914 if ( 'publish' == get_post_status($key) ) {
1915 // This section is for all archive page
1916 if ( in_array('include/archive', $val) ) {
1917 $page_id = $key;
1918 } else if ( in_array('exclude/archive', $val) ) {
1919 $page_id = '';
1920 }
1921 // For Category
1922 if ( $is_cat ) {
1923 // all category
1924 if ( in_array('include/archive/category', $val) ) {
1925 $page_id = $key;
1926 } else if ( in_array('exclude/archive/category', $val) ) {
1927 $page_id = '';
1928 }
1929 // specific category
1930 if ( in_array('include/archive/category/'.$taxonomy->term_id, $val) ) {
1931 $page_id = $key;
1932 } else if ( in_array('exclude/archive/category/'.$taxonomy->term_id, $val) ) {
1933 $page_id = '';
1934 }
1935
1936 // any child of category
1937 if ( in_array('include/archive/any_child_of_category', $val) ) {
1938 $page_id = $key;
1939 } else if ( in_array('exclude/archive/any_child_of_category', $val) ) {
1940 $page_id = '';
1941 }
1942
1943 $any_child_of_cat = $this->in_array_part("archive/any_child_of_category/", $val, '');
1944 if ( !empty($any_child_of_cat) ) {
1945 foreach( $any_child_of_cat as $v ) {
1946 $data = explode("/", $v);
1947 if ( isset($data[3]) && $data[3] ) {
1948 if ( term_is_ancestor_of($data[3], $taxonomy->term_id, 'category') ) {
1949 $page_id = $data[0] == 'exclude' ? '' : $key;
1950 }
1951 }
1952 }
1953 }
1954
1955 // all child of category
1956 if ( in_array('include/archive/child_of_category', $val) ) {
1957 $page_id = $key;
1958 } else if ( in_array('exclude/archive/child_of_category', $val) ) {
1959 $page_id = '';
1960 }
1961 // specific child of category
1962 if ( in_array('include/archive/child_of_category/'.$taxonomy->parent, $val) ) {
1963 $page_id = $key;
1964 } else if ( in_array('exclude/archive/child_of_category/'.$taxonomy->parent, $val) ) {
1965 $page_id = '';
1966 }
1967 }
1968 // For Tag
1969 else if ( $is_tag ) {
1970 if ( in_array('include/archive/post_tag', $val) ) {
1971 $page_id = $key;
1972 } else if ( in_array('exclude/archive/post_tag', $val) ) {
1973 $page_id = '';
1974 }
1975 if ( in_array('include/archive/post_tag/'.$taxonomy->term_id, $val) ) {
1976 $page_id = $key;
1977 } else if ( in_array('exclude/archive/post_tag/'.$taxonomy->term_id, $val) ) {
1978 $page_id = '';
1979 }
1980 }
1981 // Other taxonomy
1982 else if ( $is_tax ) {
1983 if ( in_array('include/archive/'.$taxonomy->taxonomy, $val) ) {
1984 $page_id = $key;
1985 } else if ( in_array('exclude/archive/'.$taxonomy->taxonomy, $val) ) {
1986 $page_id = '';
1987 }
1988
1989 if ( in_array('include/archive/'.$taxonomy->taxonomy.'/'.$taxonomy->term_id, $val) ) {
1990 $page_id = $key;
1991 } else if ( in_array('exclude/archive/'.$taxonomy->taxonomy.'/'.$taxonomy->term_id, $val) ) {
1992 $page_id = '';
1993 }
1994
1995 if ( in_array('include/archive/any_child_of_'.$taxonomy->taxonomy, $val) ) {
1996 $page_id = $key;
1997 } else if ( in_array('exclude/archive/any_child_of_'.$taxonomy->taxonomy, $val) ) {
1998 $page_id = '';
1999 }
2000
2001 $any_child_of_tax = $this->in_array_part('archive/any_child_of_'.$taxonomy->taxonomy.'/', $val, '');
2002 if ( !empty($any_child_of_tax) ) {
2003 foreach( $any_child_of_tax as $v ) {
2004 $data = explode("/", $v);
2005 if ( isset($data[3]) && $data[3] ) {
2006 if ( term_is_ancestor_of($data[3], $taxonomy->term_id, $taxonomy->taxonomy) ) {
2007 $page_id = $data[0] == 'exclude' ? '' : $key;
2008 }
2009 }
2010 }
2011 }
2012
2013 if ( in_array('include/archive/child_of_'.$taxonomy->taxonomy, $val) ) {
2014 $page_id = $key;
2015 } else if ( in_array('exclude/archive/child_of_'.$taxonomy->taxonomy, $val) ) {
2016 $page_id = '';
2017 }
2018
2019 if ( in_array('include/archive/child_of_'.$taxonomy->taxonomy.'/'.$taxonomy->parent, $val) ) {
2020 $page_id = $key;
2021 } else if ( in_array('exclude/archive/child_of_'.$taxonomy->taxonomy.'/'.$taxonomy->parent, $val) ) {
2022 $page_id = '';
2023 }
2024
2025 }
2026 // For Date
2027 else if ( $is_date ) {
2028 if ( in_array('include/archive/date', $val) ) {
2029 $page_id = $key;
2030 } else if ( in_array('exclude/archive/date', $val) ) {
2031 $page_id = '';
2032 }
2033 }
2034 // For Author
2035 else if ( $is_author ) {
2036 if ( in_array('include/archive/author', $val) ) {
2037 $page_id = $key;
2038 } else if ( in_array('exclude/archive/author', $val) ) {
2039 $page_id = '';
2040 }
2041 $author_id = get_the_author_meta('ID');
2042 if ( in_array('include/archive/author/'.$author_id, $val) ) {
2043 $page_id = $key;
2044 } else if ( in_array('exclude/archive/author/'.$author_id, $val) ) {
2045 $page_id = '';
2046 }
2047 }
2048 }
2049 }
2050 }
2051 }
2052 }
2053 return $page_id;
2054 }
2055
2056 /**
2057 * Get Date Default Format
2058 *
2059 * @since v.2.7.2
2060 * @return ARRAY | Default Data
2061 */
2062 public function get_format($format) {
2063 if ($format == 'default_date') {
2064 return get_option('date_format');
2065 } else if ($format == 'default_date_time') {
2066 return get_option('date_format').' '.get_option('time_format');
2067 } else {
2068 return $format;
2069 }
2070 }
2071
2072 /**
2073 * Common Frontend and Backend CSS and JS Scripts
2074 *
2075 * @since v.1.0.0
2076 * @return NULL
2077 */
2078 public function register_scripts_common() {
2079 if ( !( isset($GLOBALS['wp_scripts']) && isset($GLOBALS['wp_scripts']->registered) && isset($GLOBALS['wp_scripts']->registered['ultp-script']) ) ) {
2080 wp_enqueue_style('ultp-style', ULTP_URL.'assets/css/style.min.css', array(), ULTP_VER );
2081 wp_enqueue_script('ultp-script', ULTP_URL.'assets/js/ultp.min.js', array('jquery', 'wp-api-fetch'), ULTP_VER, true);
2082 wp_localize_script('ultp-script', 'ultp_data_frontend', array(
2083 'url' => ULTP_URL,
2084 'active' => ultimate_post()->is_lc_active(),
2085 'ultpSavedDLMode' => ultimate_post()->get_dl_mode(),
2086 'ajax' => admin_url('admin-ajax.php'),
2087 'security' => wp_create_nonce('ultp-nonce'),
2088 'home_url' => home_url(),
2089 'dark_logo' => get_option('ultp_site_dark_logo', false)
2090 ));
2091 }
2092 }
2093 /**
2094 * Get Dark Light Mode
2095 *
2096 * @since 4.0.0
2097 * @return string
2098 */
2099 public function get_dl_mode() {
2100 $data = get_option('postx_global', []);
2101 $mode = 'ultplight';
2102 if(!empty($data)) {
2103 $mode = isset($data['enableDark']) && $data['enableDark'] ? 'ultpdark' : 'ultplight';
2104 }
2105 return $mode;
2106 }
2107
2108 /**
2109 * Get Page Post Id ( Kadence element )
2110 *
2111 * @since v.2.8.9
2112 * @return NULL
2113 */
2114 public function get_page_post_id($blockId) {
2115 global $wpdb;
2116 $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
2117 // For FSE theme
2118 if ( !$post_meta ) {
2119 if ( wp_is_block_theme() ) {
2120 $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
2121 if ( isset($template->ID) ) {
2122 return $template->ID;
2123 }
2124 }
2125 }
2126 if ( $post_meta && isset($post_meta->post_id) ) {
2127 return $post_meta->post_id;
2128 }
2129 return ultimate_post()->get_ID();
2130 }
2131
2132
2133 /**
2134 * Get no Result found html
2135 *
2136 * @since v.2.9.0
2137 * @param STRING | No result found text
2138 * @return STRING | Taxonomy Lists as array
2139 */
2140 public function get_no_result_found_html($text) {
2141 return $text ? '<div class="ultp-not-found-message" role="alert">'.wp_kses($text, ultimate_post()->ultp_allowed_html_tags()).'</div>' : '';
2142 }
2143
2144 /**
2145 * Get all Saved Templates Lists
2146 *
2147 * @since v.2.9.9
2148 * @param STRING | No result found text
2149 * @return STRING | Taxonomy Lists as array
2150 */
2151 public function get_all_lists($post_type = 'post', $empty = '') {
2152 $args = array(
2153 'post_type' => $post_type,
2154 'post_status' => 'publish',
2155 'posts_per_page' => -1
2156 );
2157 $loop = new \WP_Query( $args );
2158 $data[ $empty ? $empty : '' ] = __( '- Select Template -', 'ultimate-post' );
2159 if($loop->have_posts()){
2160 foreach ( $loop->posts as $post ) {
2161 $data[$post->ID] = $post->post_title ;
2162 }
2163 }
2164 wp_reset_postdata();
2165 return $data;
2166 }
2167
2168 /**
2169 * Get ID from the Youtube URL
2170 *
2171 * @since v.3.1.7
2172 * @param STRING | No result found text
2173 * @return STRING | Taxonomy Lists as array
2174 */
2175 public function get_youtube_id($url = '') {
2176 if (strpos($url, 'youtu') !== false) {
2177 $reg = '/youtu(?:.*\/v\/|.*v\=|\.be\/)([A-Za-z0-9_\-]{11})/m';
2178 preg_match($reg, $url, $matches);
2179 if (isset($matches[1])) {
2180 return $matches[1];
2181 }
2182 }
2183 return false;
2184 }
2185
2186 /**
2187 * Get Option Value bypassing cache
2188 * Inspired By WordPress Core get_option
2189 * @since v.3.1.6
2190 * @param string $option Option Name.
2191 * @param boolean $default_value option default value.
2192 * @return mixed
2193 */
2194 public function get_option_without_cache($option, $default_value=false) {
2195 global $wpdb;
2196
2197 if ( is_scalar( $option ) ) {
2198 $option = trim( $option );
2199 }
2200
2201 if ( empty( $option ) ) {
2202 return false;
2203 }
2204
2205 $value = $default_value;
2206
2207 $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
2208
2209 if ( is_object( $row ) ) {
2210 $value = $row->option_value;
2211 } else {
2212 return apply_filters( "ultp_default_option_{$option}", $default_value, $option );
2213 }
2214
2215 return apply_filters( "ultp_option_{$option}", maybe_unserialize( $value ), $option );
2216 }
2217
2218 /**
2219 * Get Transient Value bypassing cache
2220 * Inspired By WordPress Core get_transient
2221 * @since v.3.1.6
2222 * @param string $transient Transient Name.
2223 * @return mixed
2224 */
2225 public function get_transient_without_cache($transient) {
2226 $transient_option = '_transient_' . $transient;
2227 $transient_timeout = '_transient_timeout_' . $transient;
2228 $timeout = $this->get_option_without_cache( $transient_timeout );
2229
2230 if ( false !== $timeout && $timeout < time() ) {
2231 delete_option( $transient_option );
2232 delete_option( $transient_timeout );
2233 $value = false;
2234 }
2235
2236 if ( ! isset( $value ) ) {
2237 $value = $this->get_option_without_cache( $transient_option );
2238 }
2239
2240 return apply_filters( "ultp_transient_{$transient}", $value, $transient );
2241 }
2242
2243 /**
2244 * Set transient without adding to the cache
2245 * Inspired By WordPress Core set_transient
2246 * @since v.3.1.6
2247 * @param string $transient Transient Name.
2248 * @param mixed $value Transient Value.
2249 * @param integer $expiration Time until expiration in seconds.
2250 * @return bool
2251 */
2252 public function set_transient_without_cache($transient, $value, $expiration = 0) {
2253 $expiration = (int) $expiration;
2254
2255 $transient_timeout = '_transient_timeout_' . $transient;
2256 $transient_option = '_transient_' . $transient;
2257
2258 $result = false;
2259
2260 if ( false === $this->get_option_without_cache( $transient_option ) ) {
2261 $autoload = 'yes';
2262 if ( $expiration ) {
2263 $autoload = 'no';
2264 $this->add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
2265 }
2266 $result = $this->add_option_without_cache( $transient_option, $value, $autoload );
2267 } else {
2268 /*
2269 * If expiration is requested, but the transient has no timeout option,
2270 * delete, then re-create transient rather than update.
2271 */
2272 $update = true;
2273
2274 if ( $expiration ) {
2275 if ( false === $this->get_option_without_cache( $transient_timeout ) ) {
2276 delete_option( $transient_option );
2277 $this->add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
2278 $result = $this->add_option_without_cache( $transient_option, $value, 'no' );
2279 $update = false;
2280 } else {
2281 update_option( $transient_timeout, time() + $expiration );
2282 }
2283 }
2284
2285 if ( $update ) {
2286 $result = update_option( $transient_option, $value );
2287 }
2288 }
2289
2290 return $result;
2291
2292 }
2293
2294 /**
2295 * Add option without adding to the cache
2296 * Inspired By WordPress Core set_transient
2297 * @since v.3.1.6
2298 * @param string $option option name.
2299 * @param string $value option value.
2300 * @param string $autoload whether to load wordpress startup.
2301 * @return bool
2302 */
2303 public function add_option_without_cache( $option, $value = '', $autoload = 'yes' ) {
2304 global $wpdb;
2305
2306
2307 if ( is_scalar( $option ) ) {
2308 $option = trim( $option );
2309 }
2310
2311 if ( empty( $option ) ) {
2312 return false;
2313 }
2314
2315 wp_protect_special_option( $option );
2316
2317 if ( is_object( $value ) ) {
2318 $value = clone $value;
2319 }
2320
2321 $value = sanitize_option( $option, $value );
2322
2323 /*
2324 * Make sure the option doesn't already exist.
2325 */
2326
2327 if ( apply_filters( "ultp_default_option_{$option}", false, $option, false ) !== $this->get_option_without_cache( $option ) ) {
2328 return false;
2329 }
2330
2331
2332 $serialized_value = maybe_serialize( $value );
2333 $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
2334
2335
2336 $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
2337 if ( ! $result ) {
2338 return false;
2339 }
2340
2341 return true;
2342 }
2343
2344 /**
2345 * permission_check_for_restapi
2346 * @since v.3.2.4
2347 * @param $post_id string/bool
2348 * @param $cap string
2349 * @return bool
2350 */
2351 public function permission_check_for_restapi( $post_id=false, $cap='' ) {
2352 $cap = $cap ? $cap : 'edit_others_posts';
2353 $is_passed = false;
2354 if($post_id) {
2355 $post_author =(int) get_post_field('post_author',$post_id);
2356 $is_passed = (int)get_current_user_id()===$post_author;
2357 }
2358 return $is_passed || current_user_can($cap);
2359 }
2360
2361 /**
2362 * Sanitize params
2363 * @param $params
2364 * @return array|bool|mixed|string
2365 * @since v.4.0.0
2366 */
2367 public function ultp_rest_sanitize_params($params) {
2368 if ( is_array($params) ) {
2369 return array_map(array($this,'ultp_rest_sanitize_params'),$params);
2370 } else {
2371 if( is_bool($params) ) {
2372 return rest_sanitize_boolean($params);
2373 } else if( is_object($params) ) {
2374 return $params;
2375 } else {
2376 return sanitize_text_field($params);
2377 }
2378 }
2379 }
2380
2381 /**
2382 * Get Adv Filter Data Attributes
2383 * @param array|null $attr
2384 * @param array|null $filter_attributes
2385 * @return string
2386 * @since v.3.2.5
2387 */
2388 public function get_adv_data_attrs($attr, $filter_attributes=null) {
2389 // Adv Filter Integration
2390 $adv_filter_dataset = array();
2391
2392 if ($filter_attributes) {
2393 $adv_filter_dataset[] = 'data-filter-value="' . htmlspecialchars($filter_attributes['queryTaxValue']) . '"';
2394 $adv_filter_dataset[] = 'data-filter-type="' . htmlspecialchars($filter_attributes['queryTax']) . '"';
2395
2396 $is_adv = isset($filter_attributes['isAdv']) ? $filter_attributes['isAdv'] : 0;
2397 $adv_filter_dataset[] = 'data-filter-is-adv="' . $is_adv . '"';
2398
2399 if ($is_adv) {
2400 if ( isset($filter_attributes['queryAuthor'] ) ) {
2401 $adv_filter_dataset[] = "data-filter-author='" . $filter_attributes['queryAuthor'] . "'";
2402 }
2403
2404 if ( isset($filter_attributes['queryOrder'] ) ) {
2405 $adv_filter_dataset[] = "data-filter-order='" . $filter_attributes['queryOrder'] . "'";
2406 }
2407
2408 if ( isset($filter_attributes['queryOrderBy'] ) ) {
2409 $adv_filter_dataset[] = "data-filter-orderby='" . $filter_attributes['queryOrderBy'] . "'";
2410 }
2411
2412 if ( isset($filter_attributes['search'] ) ) {
2413 $adv_filter_dataset[] = 'data-filter-search="' . $filter_attributes['search'] . '"';
2414 }
2415
2416 if ( isset($filter_attributes['queryQuick'] ) && $filter_attributes['queryQuick'] ) {
2417 $adv_filter_dataset[] = 'data-filter-adv-sort="' . $filter_attributes['queryQuick'] . '"';
2418 }
2419 }
2420 }
2421
2422 if ($attr && isset($attr['advFilterEnable']) && $attr['advFilterEnable']) {
2423 $adv_filter_dataset[] = 'data-filter-is-adv="1"';
2424 $adv_filter_dataset[] = 'data-filter-type="multiTaxonomy"';
2425
2426 $data_filter_value = isset($attr['filterValue']) && $attr['filterValue'] ? $attr['filterValue'] : "[]";
2427 $adv_filter_dataset[] = 'data-filter-value="' . htmlspecialchars($data_filter_value) . '"';
2428
2429 $data_author = isset($attr['queryAuthor']) && $attr['queryAuthor'] ? $attr['queryAuthor'] : "[]";
2430 $adv_filter_dataset[] = 'data-filter-author="' . $data_author . '"';
2431
2432 $data_order = isset($attr['queryOrder']) && $attr['queryOrder'] ? $attr['queryOrder'] : "DESC";
2433 $adv_filter_dataset[] = 'data-filter-order="' . $data_order . '"';
2434
2435 $data_orderby = isset($attr['queryOrderBy']) && $attr['queryOrderBy'] ? $attr['queryOrderBy'] : "date";
2436 $adv_filter_dataset[] = 'data-filter-orderby="' . $data_orderby . '"';
2437
2438 $adv_filter_dataset[] = 'data-filter-search="' . (isset($attr['querySearch']) ? $attr['querySearch'] : '') . '"';
2439
2440 $adv_filter_dataset[] = 'data-filter-adv-sort="' . (isset($attr['queryQuick']) ? $attr['queryQuick'] : '') . '"';
2441 }
2442
2443 $adv_filter_dataset = implode(' ', $adv_filter_dataset);
2444 return $adv_filter_dataset;
2445 }
2446
2447 /**
2448 * Custom Text kses
2449 * @param $params
2450 * @return array|bool|mixed|string
2451 * @since v.4.0.2
2452 */
2453 public function ultp_allowed_html_tags($extras=[]) {
2454 $allowed = array(
2455 'a' => array(
2456 'href' => true,
2457 'title' => true,
2458 ),
2459 'abbr' => array(
2460 'title' => true,
2461 ),
2462 'b' => array(),
2463 'br' => array(),
2464 'blockquote' => array(
2465 'cite' => true,
2466 ),
2467 'em' => array(),
2468 'i' => array(),
2469 'q' => array(
2470 'cite' => true,
2471 ),
2472 'strong' => array(),
2473 );
2474
2475 return array_merge($allowed, $extras);
2476 }
2477
2478 /**
2479 * Allowed Block Tags
2480 * @return array
2481 * @since v.4.0.2
2482 */
2483 public function ultp_allowed_block_tags($search='') {
2484 $array_lists = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'span', 'p', 'div', 'section', 'article' ];
2485 return $search ? in_array($search, $array_lists) : $array_lists ;
2486 }
2487
2488 /**
2489 * Formats datasets for html
2490 * @since v.4.0.2
2491 *
2492 * @param array $datasets
2493 * @return string
2494 */
2495 public function get_formatted_datasets(&$datasets) {
2496 $res = '';
2497 foreach($datasets as $key => $value) {
2498 $res .= ' data-' . $key . '="' . $value . '" ';
2499 }
2500 return $res;
2501 }
2502
2503 /**
2504 * Sanitizes a attributes after running necessary checks
2505 * @since v.4.1.0
2506 *
2507 * @param array $datasets
2508 * @return string
2509 */
2510 public function sanitize_attr(&$attr, $key, $sanitize_callback = null, $def_value = '') {
2511 return isset($attr[$key]) && $attr[$key] ?
2512 (
2513 $sanitize_callback ?
2514 $sanitize_callback($attr[$key]) :
2515 $attr[$key]
2516 )
2517 : $def_value;
2518 }
2519
2520 /**
2521 * Checks if dynamic content is active
2522 * @since v.4.1.1
2523 *
2524 * @return boolean
2525 */
2526 public function is_dc_active(&$attr) {
2527 if ( class_exists('\ULTP\DCService') ) {
2528 return \ULTP\DCService::is_dc_active($attr);
2529 }
2530 return false;
2531 }
2532
2533
2534 /**
2535 * Checks all the taxonomy of a post type for a given slug. Returns the taxonomy
2536 * if it exists.
2537 * @since v.4.1.16
2538 * @param string $post_type
2539 * @param string $slug
2540 *
2541 * @return string|null
2542 */
2543 public function get_taxonomy_by_term_slug($post_type, $slug) {
2544 $taxonomies = get_object_taxonomies( $post_type );
2545 foreach ( $taxonomies as $taxonomy ) {
2546 $res = get_term_by( 'slug', $slug, $taxonomy );
2547
2548 if ( ! empty( $res ) ) {
2549 return $taxonomy;
2550 }
2551 }
2552
2553 return null;
2554 }
2555 }
2556