PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.7.5
Post Grid Gutenberg Blocks – PostX v2.7.5
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 2.7.5, at classes/Functions.php

2,066 lines 90.4 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 * Setup class.
20 *
21 * @since v.1.0.0
22 */
23 public function __construct() {
24 if (!isset($GLOBALS['ultp_settings'])) {
25 $GLOBALS['ultp_settings'] = get_option('ultp_options');
26 $GLOBALS['ultp_settings']['date_format'] = get_option('date_format');
27 $GLOBALS['ultp_settings']['time_format'] = get_option('time_format');
28 }
29 }
30
31 /**
32 * ID for the Builder Post or Normal Post
33 *
34 * @since v.2.3.1
35 * @return NUMBER | is Builder or not
36 */
37 public function get_ID() {
38 $id = $this->is_builder();
39 return $id ? $id : (function_exists('is_shop') ? (is_shop() ? wc_get_page_id('shop') : get_the_ID()) : get_the_ID() );
40 }
41
42 /**
43 * Checking Statement of Dynamic Site Builder
44 *
45 * @since v.2.3.1
46 * @return BOOLEAN | is Builder or not
47 */
48 public function is_archive_builder() {
49 $id = get_the_ID();
50 return get_post_type( $id ) == 'ultp_builder' ? get_post_meta( $id, '__ultp_builder_type', true ) : false;
51 }
52
53
54 /**
55 * Set Link with the Parameters
56 *
57 * @since v.1.1.0
58 * @return STRING | URL with Arg
59 */
60 public function get_premium_link( $url = '', $tag = 'go_premium' ) {
61 $url = $url ? $url : 'https://www.wpxpo.com/postx/pricing/';
62 $affiliate_id = apply_filters( 'ultp_affiliate_id', FALSE );
63 $arg = array( 'utm_source' => $tag );
64 if ( ! empty( $affiliate_id ) ) {
65 $arg[ 'ref' ] = esc_attr( $affiliate_id );
66 }
67 return add_query_arg( $arg, $url );
68 }
69
70
71 /**
72 * Get Width and Height of the Image
73 *
74 * @since v.1.1.0
75 * @return STRING | Image Size
76 */
77 public function get_size($name = '') {
78 global $_wp_additional_image_sizes;
79 $image_size = $name ? ( isset($_wp_additional_image_sizes[$name]) ? $_wp_additional_image_sizes[$name] : array_values($_wp_additional_image_sizes)[0] ) : array_values($_wp_additional_image_sizes)[0];
80
81 return ' width="'.$image_size['width'].'" height="'.$image_size['height'].'" ';
82 }
83
84
85 /**
86 * Image Placeholder
87 *
88 * @since v.1.1.0
89 * @return STRING | Image Placeholder
90 */
91 public function img_placeholder($type = 'small') {
92 switch ($type) {
93 case 'small':
94 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG4AAABLAQMAAACr9CA9AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABZJREFUOI1jYMADmEe5o9xR7iiXQi4A4BsA388WUyMAAAAASUVORK5CYII=';
95 break;
96
97 case 'wide':
98 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAKCAYAAADVTVykAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAB9JREFUeNpi/P//P8NAAiaGAQajDhh1wKgDRh0AEGAAQTcDEcKDrpMAAAAASUVORK5CYII=';
99 break;
100
101 case 'square':
102 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAApJREFUCJljYAAAAAIAAfRxZKYAAAAASUVORK5CYII=';
103 break;
104
105 case 'slider':
106 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKYAAABkCAMAAAA7drv6AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF////AAAAVcLTfgAAAAF0Uk5TAEDm2GYAAAAqSURBVHja7MEBDQAAAMKg909tDjegAAAAAAAAAAAAAAAAAAAAAH5NgAEAQTwAAWZtItYAAAAASUVORK5CYII=';
107 break;
108
109 default:
110 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYYAAADcAQMAAABOLJSDAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAACJJREFUaIHtwTEBAAAAwqD1T20ND6AAAAAAAAAAAAAA4N8AKvgAAUFIrrEAAAAASUVORK5CYII=';
111 break;
112 }
113 }
114
115
116 /**
117 * Quick Query
118 *
119 * @since v.1.1.0
120 * @return ARRAY | Query Arg
121 */
122 public function get_quick_query($prams, $args) {
123 switch ($prams['queryQuick']) {
124 case 'related_posts':
125 global $post;
126 $p_id = isset($post->ID) && $post->ID ? $post->ID : (isset($_POST['postId']) ? $_POST['postId'] : '');
127 if ($p_id) {
128 $args['post__not_in'] = array($p_id);
129 }
130 break;
131 case 'related_tag':
132 global $post;
133 $p_id = isset($post->ID) && $post->ID ? $post->ID : (isset($_POST['postId']) ? $_POST['postId'] : '');
134 if ($p_id) {
135 $args['tax_query'] = array(
136 array(
137 'taxonomy' => 'post_tag',
138 'terms' => $this->get_terms_id($p_id, 'post_tag'),
139 'field' => 'term_id',
140 )
141 );
142 $args['post__not_in'] = array($p_id);
143 }
144 break;
145 case 'related_category':
146 global $post;
147 $p_id = isset($post->ID) && $post->ID ? $post->ID : (isset($_POST['postId']) ? $_POST['postId'] : '');
148 if ($p_id) {
149 $args['tax_query'] = array(
150 array(
151 'taxonomy' => 'category',
152 'terms' => $this->get_terms_id($p_id, 'category'),
153 'field' => 'term_id',
154 )
155 );
156 $args['post__not_in'] = array($p_id);
157 }
158 break;
159 case 'related_cat_tag':
160 global $post;
161 $p_id = isset($post->ID) && $post->ID ? $post->ID : (isset($_POST['postId']) ? $_POST['postId'] : '');
162 if ($p_id) {
163 $args['tax_query'] = array(
164 array(
165 'taxonomy' => 'post_tag',
166 'terms' => $this->get_terms_id($p_id, 'post_tag'),
167 'field' => 'term_id',
168 ),
169 array(
170 'taxonomy' => 'category',
171 'terms' => $this->get_terms_id($p_id, 'category'),
172 'field' => 'term_id',
173 )
174 );
175 $args['post__not_in'] = array($p_id);
176 }
177 break;
178 case 'sticky_posts':
179 $sticky = get_option('sticky_posts');
180 if (is_array($sticky)) {
181 rsort($sticky);
182 $sticky = array_slice($sticky, 0, $args['posts_per_page']);
183 }
184 $args['ignore_sticky_posts'] = 1;
185 $args['post__in'] = $sticky;
186 break;
187 case 'latest_post_published':
188 $args['orderby'] = 'date';
189 $args['order'] = 'DESC';
190 $args['ignore_sticky_posts'] = 1;
191 break;
192 case 'latest_post_modified':
193 $args['orderby'] = 'modified';
194 $args['order'] = 'DESC';
195 $args['ignore_sticky_posts'] = 1;
196 break;
197 case 'oldest_post_published':
198 $args['orderby'] = 'date';
199 $args['order'] = 'ASC';
200 break;
201 case 'oldest_post_modified':
202 $args['orderby'] = 'modified';
203 $args['order'] = 'ASC';
204 break;
205 case 'alphabet_asc':
206 $args['orderby'] = 'title';
207 $args['order'] = 'ASC';
208 break;
209 case 'alphabet_desc':
210 $args['orderby'] = 'title';
211 $args['order'] = 'DESC';
212 break;
213 case 'random_post':
214 $args['orderby'] = 'rand';
215 $args['order'] = 'ASC';
216 break;
217 case 'random_post_7_days':
218 $args['orderby'] = 'rand';
219 $args['order'] = 'ASC';
220 $args['date_query'] = array( array( 'after' => '1 week ago') );
221 break;
222 case 'random_post_30_days':
223 $args['orderby'] = 'rand';
224 $args['order'] = 'ASC';
225 $args['date_query'] = array( array( 'after' => '1 month ago') );
226 break;
227 case 'most_comment':
228 $args['orderby'] = 'comment_count';
229 $args['order'] = 'DESC';
230 break;
231 case 'most_comment_1_day':
232 $args['orderby'] = 'comment_count';
233 $args['order'] = 'DESC';
234 $args['date_query'] = array( array( 'after' => '1 day ago') );
235 break;
236 case 'most_comment_7_days':
237 $args['orderby'] = 'comment_count';
238 $args['order'] = 'DESC';
239 $args['date_query'] = array( array( 'after' => '1 week ago') );
240 break;
241 case 'most_comment_30_days':
242 $args['orderby'] = 'comment_count';
243 $args['order'] = 'DESC';
244 $args['date_query'] = array( array( 'after' => '1 month ago') );
245 break;
246 case 'popular_post_1_day_view':
247 $args['meta_key'] = '__post_views_count';
248 $args['orderby'] = 'meta_value_num';
249 $args['order'] = 'DESC';
250 $args['date_query'] = array( array( 'after' => '1 day ago') );
251 break;
252 case 'popular_post_7_days_view':
253 $args['meta_key'] = '__post_views_count';
254 $args['orderby'] = 'meta_value_num';
255 $args['order'] = 'DESC';
256 $args['date_query'] = array( array( 'after' => '1 week ago') );
257 break;
258 case 'popular_post_30_days_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 month ago') );
263 break;
264 case 'popular_post_all_times_view':
265 $args['meta_key'] = '__post_views_count';
266 $args['orderby'] = 'meta_value_num';
267 $args['order'] = 'DESC';
268 break;
269 default:
270 # code...
271 break;
272 }
273 return $args;
274 }
275
276 /**
277 * Get All Term ID as Array
278 *
279 * @since v.2.4.12
280 * @return ARRAY | Query Arg
281 */
282 public function get_terms_id($id, $type) {
283 $data = array();
284 $arr = get_the_terms($id, $type);
285 if (is_array($arr)) {
286 foreach ($arr as $key => $val) {
287 $data[] = $val->term_id;
288 }
289 }
290 return $data;
291 }
292
293 /**
294 * Get All Reusable ID
295 *
296 * @since v.1.1.0
297 * @return ARRAY | Query Arg
298 */
299 public function reusable_id($post_id) {
300 $reusable_id = array();
301 if ($post_id) {
302 $post = get_post($post_id);
303 if (has_blocks($post->post_content)) {
304 $blocks = parse_blocks($post->post_content);
305 foreach ($blocks as $key => $value) {
306 if (isset($value['attrs']['ref'])) {
307 $reusable_id[] = $value['attrs']['ref'];
308 }
309 }
310 }
311 }
312 return $reusable_id;
313 }
314
315
316 /**
317 * Set CSS Style
318 *
319 * @since v.1.1.0
320 * @return ARRAY | Query Arg
321 */
322 public function set_css_style($post_id, $shortcode = false) {
323 if ($post_id) {
324 $upload_dir_url = wp_get_upload_dir();
325 $upload_css_dir_url = trailingslashit( $upload_dir_url['basedir'] );
326 $css_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
327
328 $css_dir_url = trailingslashit( $upload_dir_url['baseurl'] );
329 if (is_ssl()) {
330 $css_dir_url = str_replace('http://', 'https://', $css_dir_url);
331 }
332
333 // Reusable CSS
334 $reusable_id = ultimate_post()->reusable_id($post_id);
335 foreach ( $reusable_id as $id ) {
336 $reusable_dir_path = $upload_css_dir_url."ultimate-post/ultp-css-{$id}.css";
337 if (file_exists( $reusable_dir_path )) {
338 $css_url = $css_dir_url . "ultimate-post/ultp-css-{$id}.css";
339 wp_enqueue_style( "ultp-post-{$id}", $css_url, array(), ultimate_post()->get_setting('save_version'), 'all' );
340 }else{
341 $css = get_post_meta($id, '_ultp_css', true);
342 if( $css ) {
343 ultimate_post()->set_inline($css);
344 }
345 }
346 }
347
348 if (isset($_GET['et_fb']) || (isset($_GET['action']) && sanitize_key($_GET['action']) == 'elementor') || $shortcode) {
349 return ultimate_post()->set_inline(get_post_meta($post_id, '_ultp_css', true));
350 } else {
351 if (file_exists( $css_dir_path ) ) {
352 $css_url = $css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
353 wp_enqueue_style( "ultp-post-{$post_id}", $css_url, array(), ultimate_post()->get_setting('save_version'), 'all' );
354 } else {
355 $css = get_post_meta($post_id, '_ultp_css', true);
356 if( $css ) {
357 ultimate_post()->set_inline($css);
358 }
359 }
360 }
361 }
362 }
363
364
365 /**
366 * Get Global Plugin Settings
367 *
368 * @since v.1.0.0
369 * @param STRING | Key of the Option
370 * @return ARRAY | STRING
371 */
372 public function get_setting($key = '') {
373 $data = $GLOBALS['ultp_settings'];
374 if ($key != '') {
375 return isset($data[$key]) ? $data[$key] : '';
376 } else {
377 return $data;
378 }
379 }
380
381
382 /**
383 * Set Option Settings
384 *
385 * @since v.1.0.0
386 * @param STRING | Key of the Option (STRING), Value (STRING)
387 * @return NULL
388 */
389 public function set_setting($key = '', $val = '') {
390 if ($key != '') {
391 $data = $GLOBALS['ultp_settings'];
392 $data[$key] = $val;
393 update_option('ultp_options', $data);
394 $GLOBALS['ultp_settings'] = $data;
395 }
396 }
397
398
399 /**
400 * Get Image HTML
401 *
402 * @since v.1.0.0
403 * @param | URL (STRING) | size (STRING) | class (STRING) | alt (STRING)
404 * @return STRING
405 */
406 public function get_image_html($url = '', $size = 'full', $class = '', $alt = '', $lazy = '') {
407 $alt = $alt ? ' alt="'.$alt.'" ' : '';
408 $lazy_data = $lazy ? ' loading="lazy"' : '';
409 $class = $class ? ' class="'.$class.'" ' : '';
410 return '<img '.$lazy_data.$class.$alt.' src="'.$url.'" />';
411 }
412
413
414 /**
415 * Get Image HTML
416 *
417 * @since v.1.0.0
418 * @param | Attach ID (STRING) | size (STRING) | class (STRING) | alt (STRING)
419 * @return STRING
420 */
421 public function get_image($attach_id, $size = 'full', $class = '', $alt = '', $srcset = '', $lazy = '') {
422 $alt = $alt ? ' alt="'.$alt.'" ' : '';
423 $class = $class ? ' class="'.$class.'" ' : '';
424 $size = ( ultimate_post()->get_setting('disable_image_size') == 'yes' && strpos($size, 'ultp_layout_') !== false ) ? 'full' : $size;
425 $lazy_data = $lazy ? ' loading="lazy"' : '';
426 $srcset_data = $srcset ? ' srcset="'.esc_attr(wp_get_attachment_image_srcset($attach_id)).'"' : '';
427 return '<img '.$srcset_data.$lazy_data.$class.$alt.' src="'.wp_get_attachment_image_url( $attach_id, $size ).'" />';
428 }
429
430
431 /**
432 * Setup Initial Data Set
433 *
434 * @since v.1.0.0
435 * @return NULL
436 */
437 public function init_set_data() {
438 $data = get_option( 'ultp_options', array() );
439 $init_data = array(
440 'css_save_as' => 'wp_head',
441 'preloader_style' => 'style1',
442 'preloader_color' => '#037fff',
443 'container_width' => '1140',
444 'hide_import_btn' => '',
445 'disable_image_size'=> '',
446 'disable_view_cookies' => '',
447 'ultp_templates' => 'true',
448 'ultp_elementor' => 'true',
449 'ultp_table_of_content'=> 'true',
450 'ultp_builder' => 'true',
451 'post_grid_1' => 'yes',
452 'post_grid_2' => 'yes',
453 'post_grid_3' => 'yes',
454 'post_grid_4' => 'yes',
455 'post_grid_5' => 'yes',
456 'post_grid_6' => 'yes',
457 'post_grid_7' => 'yes',
458 'post_list_1' => 'yes',
459 'post_list_2' => 'yes',
460 'post_list_3' => 'yes',
461 'post_list_4' => 'yes',
462 'post_module_1' => 'yes',
463 'post_module_2' => 'yes',
464 'post_slider_1' => 'yes',
465 'heading' => 'yes',
466 'image' => 'yes',
467 'taxonomy' => 'yes',
468 'wrapper' => 'yes',
469 'news_ticker' => 'yes',
470 'builder_advance_post_meta' => 'yes',
471 'builder_archive_title' => 'yes',
472 'builder_author_box' => 'yes',
473 'builder_post_next_previous'=> 'yes',
474 'builder_post_author_meta' => 'yes',
475 'builder_post_breadcrumb' => 'yes',
476 'builder_post_category' => 'yes',
477 'builder_post_comment_count'=> 'yes',
478 'builder_post_comments' => 'yes',
479 'builder_post_content' => 'yes',
480 'builder_post_date_meta' => 'yes',
481 'builder_post_excerpt' => 'yes',
482 'builder_post_featured_image'=> 'yes',
483 'builder_post_reading_time' => 'yes',
484 'builder_post_social_share' => 'yes',
485 'builder_post_tag' => 'yes',
486 'builder_post_title' => 'yes',
487 'builder_post_view_count' => 'yes',
488 'save_version' => rand(1, 1000)
489 );
490 if (empty($data)) {
491 update_option('ultp_options', $init_data);
492 $GLOBALS['ultp_settings'] = $init_data;
493 } else {
494 foreach ($init_data as $key => $single) {
495 if (!isset($data[$key])) {
496 $data[$key] = $single;
497 }
498 }
499 update_option('ultp_options', $data);
500 $GLOBALS['ultp_settings'] = $data;
501 }
502 }
503
504
505 /**
506 * Get Excerpt Text
507 *
508 * @since v.1.0.0
509 * @param | Post ID (STRING) | Limit (NUMBER)
510 * @return STRING
511 */
512 public function excerpt( $post_id, $limit = 55 ) {
513 return apply_filters( 'the_excerpt', wp_trim_words( get_the_content( $post_id ) , $limit ) );
514 }
515
516 public function get_builder_attr($type) {
517 $builder_data = '';
518 if ($type == 'archiveBuilder') {
519 if (is_archive()) {
520 if (is_date()) {
521 if (is_year()) {
522 $builder_data = 'date###'.get_the_date('Y');
523 } else if (is_month() ) {
524 $builder_data = 'date###'.get_the_date('Y-n');
525 } else if (is_day() ) {
526 $builder_data = 'date###'.get_the_date('Y-n-j');
527 }
528 } else if (is_author()) {
529 $builder_data = 'author###'.get_the_author_meta('ID');
530 } else {
531 $obj = get_queried_object();
532 if (isset($obj->taxonomy)) {
533 $builder_data = 'taxonomy###'.$obj->taxonomy.'###'.$obj->slug;
534 }
535 }
536 } else if (is_search()) {
537 $builder_data = 'search###'.get_search_query(true);
538 }
539 }
540 return $builder_data ? 'data-builder="'.$builder_data.'"' : '';
541 }
542
543
544 public function is_builder($builder = '') {
545 $id = '';
546 $page_id = ultimate_post()->conditions('return');
547 if ($page_id && ultimate_post()->get_setting('ultp_builder')) {
548 $id = $page_id;
549 }
550 return $id;
551 }
552
553
554 /**
555 * Get Post Number Depending On Device
556 *
557 * @since v.2.5.4
558 * @param MULTIPLE | Attribute of Posts
559 * @return STRING
560 */
561 public function get_post_number($preDef, $prev, $current) {
562
563 $current = is_object($current)?json_decode(json_encode($current), true):$current;
564 if (['lg'=>$preDef,'sm'=>$preDef,'xs'=>$preDef] == $current) {
565 if ($preDef != $prev) {
566 return $prev;
567 }
568 }
569 if ($this->isDevice() == 'mobile') {
570 return $current['xs'];
571 } else if ($this->isDevice() == 'tablet') {
572 return $current['sm'];
573 } else {
574 return $current['lg'];
575 }
576 }
577
578
579 /**
580 * Get Post Number Depending On Device
581 *
582 * @since v.2.5.4
583 * @param NULL
584 * @return STRING | Device Type
585 */
586 public function isDevice(){
587 $useragent = isset($_SERVER['HTTP_USER_AGENT']) ? sanitize_key($_SERVER['HTTP_USER_AGENT']) : '';
588 if ($useragent) {
589 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))) {
590 return 'mobile';
591 } else if (preg_match('/(tablet|ipad|playbook)|(android(?!.*(mobi|opera mini)))/i', strtolower($useragent))) {
592 return 'tablet';
593 } else {
594 return 'desktop';
595 }
596 }
597 return 'desktop';
598 }
599
600
601 /**
602 * Get Raw Value from Objects
603 *
604 * @since v.2.5.3
605 * @param NULL
606 * @return STRING | Device Type
607 */
608 public function get_value($attr) {
609 $data = [];
610 if (is_array($attr)) {
611 foreach ($attr as $val) {
612 $data[] = $val->value;
613 }
614 }
615 return $data;
616 }
617
618
619 /**
620 * Query Builder
621 *
622 * @since v.1.0.0
623 * @param ARRAY | Attribute of the Query
624 * @return ARRAY
625 */
626 public function get_query($attr) {
627 $builder = isset($attr['builder']) ? $attr['builder'] : '';
628 $post_type = isset($attr['queryType']) ? $attr['queryType'] : 'post';
629 if ( $post_type == 'archiveBuilder' && ($builder || $this->is_builder($builder)) ) {
630 $archive_query = array();
631 if ($builder) {
632 $str = explode('###', $builder);
633 if (isset($str[0])) {
634 if ($str[0] == 'taxonomy') {
635 if (isset($str[1]) && isset($str[2])) {
636 $archive_query['tax_query'] = array(
637 array(
638 'taxonomy' => $str[1],
639 'field' => 'slug',
640 'terms' => $str[2]
641 )
642 );
643 }
644 } else if ($str[0] == 'author') {
645 if (isset($str[1])) {
646 $archive_query['author'] = $str[1];
647 }
648 } else if ($str[0] == 'search') {
649 if (isset($str[1])) {
650 $archive_query['s'] = $str[1];
651 }
652 } else if ($str[0] == 'date') {
653 if (isset($str[1])) {
654 $all_date = explode('-', $str[1]);
655 if (!empty($all_date)) {
656 $arg = array();
657 if (isset($all_date[0])) { $arg['year'] = $all_date[0]; }
658 if (isset($all_date[1])) { $arg['month'] = $all_date[1]; }
659 if (isset($all_date[2])) { $arg['day'] = $all_date[2]; }
660 $archive_query['date_query'][] = $arg;
661 }
662 }
663 }
664 }
665 } else {
666 global $wp_query;
667 $archive_query = $wp_query->query_vars;
668 }
669 $archive_query['posts_per_page'] = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
670 $archive_query['paged'] = isset($attr['paged']) ? $attr['paged'] : 1;
671 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
672 $offset = $this->get_offset($attr['queryOffset'], $archive_query);
673 $archive_query = array_merge($archive_query, $offset);
674 }
675
676 // Include Remove from Version 2.5.4
677 if (isset($attr['queryInclude']) && $attr['queryInclude']) {
678 $_include = explode(',', $attr['queryInclude']);
679 if (is_array($_include) && count($_include)) {
680 $archive_query['post__in'] = isset($archive_query['post__in']) ? array_merge($archive_query['post__in'], $_include) : $_include;
681 $archive_query['ignore_sticky_posts'] = 1;
682 $archive_query['orderby'] = 'post__in';
683 }
684 }
685
686 if (isset($attr['queryExclude']) && $attr['queryExclude']) {
687 $_exclude = (substr($attr['queryExclude'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryExclude'])) : explode(',', $attr['queryExclude']);
688 if (is_array($_exclude) && count($_exclude)) {
689 $archive_query['post__not_in'] = isset($archive_query['post__not_in']) ? array_merge($archive_query['post__not_in'], $_exclude) : $_exclude;
690 }
691 }
692
693
694 if(isset($attr['querySticky']) && $attr['querySticky']) {
695 if (filter_var($attr['querySticky'], FILTER_VALIDATE_BOOLEAN)) {
696 $sticky = get_option( 'sticky_posts', [] );
697 $archive_query['post__not_in'] = isset($archive_query['post__not_in']) ? array_merge($archive_query['post__not_in'], $sticky) : $sticky;
698 }
699 }
700
701 $archive_query['post_status'] = 'publish';
702 if (is_user_logged_in()) {
703 if( current_user_can('editor') || current_user_can('administrator') ) {
704 $archive_query['post_status'] = array('publish', 'private');
705 }
706 }
707
708 if(!isset($archive_query['orderby'])) {
709 $archive_query['orderby'] = isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date';
710 }
711
712 // Quick Query Support for Builder
713 if (isset($attr['queryQuick'])) {
714 if ($attr['queryQuick'] != '') {
715 $archive_query = ultimate_post()->get_quick_query($attr, $archive_query);
716 }
717 }
718
719 if (!isset($attr['ajaxCall'])) {
720 if(isset($attr['filterShow']) && $attr['filterShow']) {
721 if(isset($attr['filterType']) && isset($attr['filterValue'])) {
722 $filterValue = strlen($attr['filterValue']) > 2 ? $attr['filterValue'] : [];
723 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
724 if (count($filterValue) > 0 && $attr['filterType']) {
725 $final = array('relation' => 'OR');
726 foreach ($filterValue as $key => $val) {
727 $final[] = array(
728 'taxonomy' => $attr['filterType'],
729 'field' => 'slug',
730 'terms' => $val,
731 );
732 }
733 $archive_query['tax_query'] = $final;
734 }
735 }
736 }
737 }
738
739 return apply_filters('ultp_archive_query', $archive_query);
740 }
741
742 $query_args = array(
743 'posts_per_page' => isset($attr['queryNumber']) ? $attr['queryNumber'] : 3,
744 'post_type' => $post_type == 'archiveBuilder' ? 'post' : $post_type,
745 'orderby' => isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date',
746 'order' => isset($attr['queryOrder']) ? $attr['queryOrder'] : 'desc',
747 'paged' => isset($attr['paged']) ? $attr['paged'] : 1,
748 'post_status' => 'publish'
749 );
750
751 // For Private Post 'private'
752 if (is_user_logged_in()) {
753 if( current_user_can('editor') || current_user_can('administrator') ) {
754 $query_args['post_status'] = array('publish', 'private');
755 }
756 }
757
758 if ($attr['queryType'] == 'posts') {
759 if (isset($attr['queryPosts']) && $attr['queryPosts']) {
760 unset($query_args['post_type']);
761 $data = json_decode(isset($attr['queryPosts'])?$attr['queryPosts']:'[]');
762 $final = $this->get_value($data);
763 if (count($final) > 0) {
764 $query_args['post__in'] = $final;
765 $query_args['posts_per_page'] = -1;
766 }
767 $query_args['ignore_sticky_posts'] = 1;
768 return $query_args;
769 }
770 } else if ($attr['queryType'] == 'customPosts') {
771 if (isset($attr['queryCustomPosts']) && $attr['queryCustomPosts']) {
772 $query_args['post_type'] = $this->get_post_type();
773 $data = json_decode(isset($attr['queryCustomPosts'])?$attr['queryCustomPosts']:'[]');
774 $final = $this->get_value($data);
775 if (count($final) > 0) {
776 $query_args['post__in'] = $final;
777 $query_args['posts_per_page'] = -1;
778 }
779 $query_args['ignore_sticky_posts'] = 1;
780 return $query_args;
781 }
782 }
783
784 if (isset($attr['queryExcludeAuthor']) && $attr['queryExcludeAuthor']) {
785 $data = json_decode(isset($attr['queryExcludeAuthor'])?$attr['queryExcludeAuthor']:'[]');
786 $final = $this->get_value($data);
787 if (count($final) > 0) {
788 $query_args['author__not_in'] = $final;
789 }
790 }
791
792
793 if (isset($attr['queryOrderBy']) && isset($attr['metaKey'])) {
794 if ($attr['queryOrderBy'] == 'meta_value_num') {
795 $query_args['meta_key'] = $attr['metaKey'];
796 }
797 }
798
799 // Include Remove from Version 2.5.4
800 if (isset($attr['queryInclude']) && $attr['queryInclude']) {
801 $_include = explode(',', $attr['queryInclude']);
802 if (is_array($_include) && count($_include)) {
803 $query_args['post__in'] = isset($query_args['post__in']) ? array_merge($query_args['post__in'], $_include) : $_include;
804 $query_args['ignore_sticky_posts'] = 1;
805 $query_args['orderby'] = 'post__in';
806 }
807 }
808
809
810 if (isset($attr['queryTax'])) {
811 if (isset($attr['queryTaxValue'])) {
812 $tax_value = (strlen($attr['queryTaxValue']) > 2) ? $attr['queryTaxValue'] : [];
813 $tax_value = is_array($tax_value) ? $tax_value : json_decode($tax_value);
814
815 $tax_value = (isset($tax_value[0]) && is_object($tax_value[0])) ? $this->get_value($tax_value) : $tax_value;
816
817 if (is_array($tax_value) && count($tax_value) > 0) {
818 $relation = isset($attr['queryRelation']) ? $attr['queryRelation'] : 'OR';
819 $var = array('relation'=>$relation);
820 foreach ($tax_value as $val) {
821 $tax_name = $attr['queryTax'];
822 // For Custom Terms
823 if ($attr['queryTax'] == 'multiTaxonomy') {
824 $temp = explode('###', $val);
825 if (isset($temp[1])) {
826 $val = $temp[1];
827 $tax_name = $temp[0];
828 }
829 }
830
831 $var[] = array('taxonomy'=> $tax_name, 'field' => 'slug', 'terms' => $val );
832 }
833 if (count($var) > 1) {
834 $query_args['tax_query'] = $var;
835 }
836 }
837 }
838 }
839
840
841 if (isset($attr['queryExcludeTerm']) && $attr['queryExcludeTerm']) {
842 $temp = json_decode($attr['queryExcludeTerm']);
843 $_term = [];
844 foreach ($temp as $val) {
845 $temp = explode('###', $val->value);
846 if (isset($temp[1])) {
847 if (array_key_exists($temp[0], $_term)) {
848 $_term[$temp[0]][] = $temp[1];
849 } else {
850 $_term[$temp[0]] = array($temp[1]);
851 }
852 }
853 }
854 if (count($_term) > 0) {
855 $final = array('relation' => 'AND');
856 foreach ($_term as $key => $val) {
857 $final[] = array(
858 'taxonomy' => $key,
859 'field' => 'slug',
860 'terms' => $val,
861 'operator' => 'NOT IN',
862 );
863 }
864
865 if (array_key_exists('tax_query', $query_args)) {
866 $query_args['tax_query'] = array(
867 'relation' => 'AND',
868 $query_args['tax_query']
869 );
870 $query_args['tax_query'][] = $final;
871 } else {
872 $query_args['tax_query'] = $final;
873 }
874 }
875 }
876
877 if (isset($attr['queryExclude']) && $attr['queryExclude']) {
878 $_exclude = (substr($attr['queryExclude'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryExclude'])) : explode(',', $attr['queryExclude']);
879 if (is_array($_exclude) && count($_exclude)) {
880 $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $_exclude) : $_exclude;
881 }
882 }
883
884 if (isset($attr['queryUnique']) && $attr['queryUnique']) {
885 global $unique_ID;
886 if (isset($unique_ID[$attr['queryUnique']])) {
887 $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']];
888 }
889 }
890
891 if (isset($attr['queryQuick'])) {
892 if ($attr['queryQuick'] != '' && $post_type != 'archiveBuilder') {
893 $query_args = ultimate_post()->get_quick_query($attr, $query_args);
894 }
895 }
896
897 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
898 $offset = $this->get_offset($attr['queryOffset'], $query_args);
899 $query_args = array_merge($query_args, $offset);
900 }
901
902 if (isset($attr['queryAuthor']) && $attr['queryAuthor'] ) {
903 $_include = (substr($attr['queryAuthor'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryAuthor'])) : explode(',', $attr['queryAuthor']);
904 if (is_array($_include) && count($_include)) {
905 $query_args['author__in'] = $_include;
906 }
907 }
908
909 if(isset($attr['querySticky']) && $attr['querySticky']) {
910 if (filter_var($attr['querySticky'], FILTER_VALIDATE_BOOLEAN)) {
911 $sticky = get_option( 'sticky_posts', [] );
912 $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $sticky) : $sticky;
913 }
914 }
915
916 if (!isset($attr['ajaxCall'])) {
917 if(isset($attr['filterShow']) && $attr['filterShow']) {
918 if(isset($attr['filterType']) && isset($attr['filterValue'])) {
919 $filterValue = strlen($attr['filterValue']) > 2 ? $attr['filterValue'] : [];
920 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
921 if (count($filterValue) > 0 && $attr['filterType']) {
922 $final = array('relation' => 'OR');
923 foreach ($filterValue as $key => $val) {
924 $final[] = array(
925 'taxonomy' => $attr['filterType'],
926 'field' => 'slug',
927 'terms' => $val,
928 // 'operator' => '=',
929 );
930 }
931 $query_args['tax_query'] = $final;
932 }
933 }
934 }
935 }
936
937 $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
938
939 return apply_filters('ultp_frontend_query', $query_args);
940 }
941
942 function get_offset($queryOffset, $query_args) {
943 $query = array();
944 if ($query_args['paged'] > 1) {
945 $offset_post = wp_get_recent_posts($query_args, OBJECT);
946 if (count($offset_post) > 0 ) {
947 $offset = array();
948 for($x = count($offset_post); $x > count($offset_post) - $queryOffset; $x--) {
949 $offset[] = $offset_post[$x-1]->ID;
950 }
951 $query['post__not_in'] = $offset;
952 }
953 } else {
954 $query['offset'] = isset($queryOffset) ? $queryOffset : 0;
955 }
956 return $query;
957 }
958
959
960 /**
961 * Get Page Number
962 *
963 * @since v.1.0.0
964 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
965 * @return ARRAY
966 */
967 public function get_page_number($attr, $post_number) {
968 if ($post_number > 0) {
969 if (isset($attr['queryOffset']) && $attr['queryOffset']) {
970 $post_number = $post_number - (int)$attr['queryOffset'];
971 }
972 $post_per_page = isset($attr['queryNumber']) ? ($attr['queryNumber'] ? $attr['queryNumber'] : 1) : 3;
973 $pages = ceil($post_number/$post_per_page);
974 return $pages ? $pages : 1;
975 }else{
976 return 1;
977 }
978 }
979
980
981 /**
982 * Get Image Size
983 *
984 * @since v.1.0.0
985 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
986 * @return ARRAY
987 */
988 public function get_image_size() {
989 $sizes = get_intermediate_image_sizes();
990 $filter = array('full' => 'Full');
991 foreach ($sizes as $value) {
992 $title = ucwords(str_replace(array('_', '-'), array(' ', ' '), $value));
993 switch ($value) {
994 case 'thumbnail':
995 $title = $title.' [150x150]';
996 break;
997 case 'medium':
998 $title = $title.' [300x300]';
999 break;
1000 case 'large':
1001 $title = $title.' [1024x1024]';
1002 break;
1003 case 'ultp_layout_landscape_large':
1004 $title = $title.' [1200x800]';
1005 break;
1006 case 'ultp_layout_landscape':
1007 $title = $title.' [870x570]';
1008 break;
1009 case 'ultp_layout_portrait':
1010 $title = $title.' [600x900]';
1011 break;
1012 case 'ultp_layout_square':
1013 $title = $title.' [600x600]';
1014 break;
1015 default:
1016 break;
1017 }
1018 $filter[$value] = $title;
1019 }
1020 return $filter;
1021 }
1022
1023
1024 /**
1025 * Get All PostType Registered
1026 *
1027 * @since v.1.0.0
1028 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1029 * @return ARRAY
1030 */
1031 public function get_post_type() {
1032 $filter = apply_filters('ultp_public_post_type', true);
1033 $post_type = get_post_types( ($filter ? ['public' => true] : ''), 'names' );
1034 return array_diff($post_type, array( 'attachment' ));
1035 }
1036
1037
1038 /**
1039 * Get Pagination HTML
1040 *
1041 * @since v.1.0.0
1042 * @param | pages (NUMBER) | Pagination Nav (STRING) | Pagination Text |
1043 * @return STRING
1044 */
1045 public function pagination($pages = '', $paginationNav = '', $paginationText = '') {
1046 $html = '';
1047 $showitems = 3;
1048 $paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
1049 $paged = $paged ? $paged : 1;
1050 if ($pages == '') {
1051 global $wp_query;
1052 $pages = $wp_query->max_num_pages;
1053 if (!$pages) {
1054 $pages = 1;
1055 }
1056 }
1057 $data = ($paged>=3?[($paged-1),$paged,$paged+1]:[1,2,3]);
1058
1059 $paginationText = explode('|', $paginationText);
1060
1061 $prev_text = isset($paginationText[0]) ? $paginationText[0] : __("Previous", "ultimate-post");
1062 $next_text = isset($paginationText[1]) ? $paginationText[1] : __("Next", "ultimate-post");
1063
1064 if (1 != $pages) {
1065 $html .= '<ul class="ultp-pagination">';
1066 $display_none = 'style="display:none"';
1067 if ($pages > 4) {
1068 $html .= '<li class="ultp-prev-page-numbers" '.($paged==1?$display_none:"").'><a href="'.get_pagenum_link($paged-1).'">'.ultimate_post()->svg_icon('leftAngle2').' '.($paginationNav == 'textArrow' ? $prev_text : "").'</a></li>';
1069 }
1070 if ($pages > 4) {
1071 $html .= '<li class="ultp-first-pages" '.($paged<2?$display_none:"").' data-current="1"><a href="'.get_pagenum_link(1).'">1</a></li>';
1072 }
1073 if ($pages > 4) {
1074 $html .= '<li class="ultp-first-dot" '.($paged<2? $display_none : "").'><a href="#">...</a></li>';
1075 }
1076 foreach ($data as $i) {
1077 if ($pages >= $i) {
1078 $html .= ($paged == $i) ? '<li class="ultp-center-item pagination-active" data-current="'.$i.'"><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>':'<li class="ultp-center-item" data-current="'.$i.'"><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
1079 }
1080 }
1081 if ($pages > 4) {
1082 $html .= '<li class="ultp-last-dot" '.($pages<=$paged+1?$display_none:"").'><a href="#">...</a></li>';
1083 }
1084 if ($pages > 4) {
1085 $html .= '<li class="ultp-last-pages" '.($pages<=$paged+1?$display_none:"").' data-current="'.$pages.'"><a href="'.get_pagenum_link($pages).'">'.$pages.'</a></li>';
1086 }
1087 if ($paged != $pages) {
1088 $html .= '<li class="ultp-next-page-numbers"><a href="'.get_pagenum_link($paged + 1).'">'.($paginationNav == 'textArrow' ? $next_text : "").ultimate_post()->svg_icon('rightAngle2').'</a></li>';
1089 }
1090 $html .= '</ul>';
1091 }
1092 return $html;
1093 }
1094 public function svg_icon($ultp_icons = '') {
1095 $ultp_icon_lists = array(
1096 'eye' => file_get_contents(ULTP_PATH.'assets/img/setting/eye.svg'),
1097 'user' => file_get_contents(ULTP_PATH.'assets/img/setting/user.svg'),
1098 'calendar' => file_get_contents(ULTP_PATH.'assets/img/setting/calendar.svg'),
1099 'comment' => file_get_contents(ULTP_PATH.'assets/img/setting/comment.svg'),
1100 'book' => file_get_contents(ULTP_PATH.'assets/img/setting/book.svg'),
1101 'tag' => file_get_contents(ULTP_PATH.'assets/img/setting/tag.svg'),
1102 'clock' => file_get_contents(ULTP_PATH.'assets/img/setting/clock.svg'),
1103 'leftAngle' => file_get_contents(ULTP_PATH.'assets/img/setting/leftAngle.svg'),
1104 'rightAngle' => file_get_contents(ULTP_PATH.'assets/img/setting/rightAngle.svg'),
1105 'leftAngle2' => file_get_contents(ULTP_PATH.'assets/img/setting/leftAngle2.svg'),
1106 'rightAngle2' => file_get_contents(ULTP_PATH.'assets/img/setting/rightAngle2.svg'),
1107 'leftArrowLg' => file_get_contents(ULTP_PATH.'assets/img/setting/leftArrowLg.svg'),
1108 'rightArrowLg' => file_get_contents(ULTP_PATH.'assets/img/setting/rightArrowLg.svg'),
1109 'refresh' => file_get_contents(ULTP_PATH.'assets/img/setting/refresh.svg'),
1110 'upArrow' => file_get_contents(ULTP_PATH.'assets/img/setting/upArrow.svg'),
1111 'downArrow' => file_get_contents(ULTP_PATH.'assets/img/setting/downArrow.svg'),
1112 'arrowUp2' => file_get_contents(ULTP_PATH.'assets/img/setting/arrowUp2.svg'),
1113 'longArrowUp2' => file_get_contents(ULTP_PATH.'assets/img/setting/longArrowUp2.svg'),
1114 'caretArrow' => file_get_contents(ULTP_PATH.'assets/img/setting/caretArrow.svg'),
1115 'left' => file_get_contents(ULTP_PATH.'assets/img/setting/left.svg'),
1116 'center' => file_get_contents(ULTP_PATH.'assets/img/setting/center.svg'),
1117 'right' => file_get_contents(ULTP_PATH.'assets/img/setting/right.svg'),
1118 'justify' => file_get_contents(ULTP_PATH.'assets/img/setting/justify.svg'),
1119 'desktop' => file_get_contents(ULTP_PATH.'assets/img/setting/desktop.svg'),
1120 'laptop' => file_get_contents(ULTP_PATH.'assets/img/setting/laptop.svg'),
1121 'tablet' => file_get_contents(ULTP_PATH.'assets/img/setting/tablet.svg'),
1122 'mobile' => file_get_contents(ULTP_PATH.'assets/img/setting/mobile.svg'),
1123 'dimension' => file_get_contents(ULTP_PATH.'assets/img/setting/dimension.svg'),
1124 'setting' => file_get_contents(ULTP_PATH.'assets/img/setting/setting.svg'),
1125 'plus' => file_get_contents(ULTP_PATH.'assets/img/setting/plus.svg'),
1126 // Builder
1127 'commentCount1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount1.svg'),
1128 'commentCount2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount2.svg'),
1129 'commentCount3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount3.svg'),
1130 'commentCount4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount4.svg'),
1131 'commentCount5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount5.svg'),
1132 'commentCount6' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount6.svg'),
1133 'date1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/date_meta/date1.svg'),
1134 'date2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/date_meta/date2.svg'),
1135 'date3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/date_meta/date3.svg'),
1136 'date4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/date_meta/date4.svg'),
1137 'date5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/date_meta/date5.svg'),
1138 'author1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/author_meta/author1.svg'),
1139 'author2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/author_meta/author2.svg'),
1140 'author3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/author_meta/author3.svg'),
1141 'author4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/author_meta/author4.svg'),
1142 'author5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/author_meta/author5.svg'),
1143 'readingTime1' => file_get_contents(ULTP_PATH.
1144 '/assets/img/blocks/builder/reading_time/readingTime1.svg'),
1145 'readingTime2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/reading_time/readingTime2.svg'),
1146 'readingTime3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/reading_time/readingTime3.svg'),
1147 'readingTime4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/reading_time/readingTime4.svg'),
1148 'readingTime5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/reading_time/readingTime5.svg'),
1149 'viewCount1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount1.svg'),
1150 'viewCount2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount2.svg'),
1151 'viewCount3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount3.svg'),
1152 'viewCount4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount4.svg'),
1153 'viewCount5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount5.svg'),
1154 'viewCount6' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount6.svg'),
1155 'cat1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat1.svg'),
1156 'cat2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat2.svg'),
1157 'cat3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat3.svg'),
1158 'cat4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat4.svg'),
1159 'cat5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat5.svg'),
1160 'cat6' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat6.svg'),
1161 'cat7' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat7.svg'),
1162 'tag1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag1.svg'),
1163 'tag2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag2.svg'),
1164 'tag3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag3.svg'),
1165 'tag4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag4.svg'),
1166 'tag5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag5.svg'),
1167 'tag6' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag6.svg'),
1168 'rightArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/rightArrowLg.svg'),
1169 'share' => file_get_contents(ULTP_PATH.'assets/img/svg/share.svg'),
1170 'facebook' => file_get_contents(ULTP_PATH.'assets/img/svg/facebookIcon.svg'),
1171 'linkedin' => file_get_contents(ULTP_PATH.'assets/img/svg/linkedinIcon.svg'),
1172 'mail' => file_get_contents(ULTP_PATH.'assets/img/svg/mailIcon.svg'),
1173 'messenger' => file_get_contents(ULTP_PATH.'assets/img/svg/messengerIcon.svg'),
1174 'reddit' => file_get_contents(ULTP_PATH.'assets/img/svg/redditIcon.svg'),
1175 'twitter' => file_get_contents(ULTP_PATH.'assets/img/svg/twitterIcon.svg'),
1176 'whatsapp' => file_get_contents(ULTP_PATH.'assets/img/svg/whatsappIcon.svg'),
1177 'pinterest' => file_get_contents(ULTP_PATH.'assets/img/svg/pinIcon.svg'),
1178 'skype' => file_get_contents(ULTP_PATH.'assets/img/svg/skype.svg'),
1179 );
1180 if ($ultp_icons) {
1181 return $ultp_icon_lists[ $ultp_icons ];
1182 }
1183 }
1184
1185
1186 /**
1187 * Get Excerpt Word
1188 *
1189 * @since v.1.0.0
1190 * @param NUMBER | Character Length
1191 * @return STRING
1192 */
1193 public function excerpt_word($charlength = 200) {
1194 $html = '';
1195 $charlength++;
1196 $excerpt = get_the_excerpt();
1197 if (mb_strlen( $excerpt ) > $charlength ) {
1198 $subex = mb_substr( $excerpt, 0, $charlength );
1199 $exwords = explode( ' ', $subex );
1200 $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
1201 if ($excut < 0 ) {
1202 $html = mb_substr( $subex, 0, $excut );
1203 } else {
1204 $html = $subex;
1205 }
1206 $html .= '...';
1207 } else {
1208 $html = $excerpt;
1209 }
1210 return $html;
1211 }
1212
1213
1214 /**
1215 * Get Taxonomy Lists
1216 *
1217 * @since v.1.0.0
1218 * @param STRING | Taxonomy Slug
1219 * @return ARRAY
1220 */
1221 public function taxonomy( $prams = 'category' ) {
1222 $data = array();
1223 $terms = get_terms( $prams, array(
1224 'hide_empty' => false,
1225 ));
1226 if (!is_wp_error($terms)) {
1227 foreach ($terms as $val) {
1228 $data[urldecode_deep($val->slug)] = $val->name;
1229 }
1230 }
1231 return $data;
1232 }
1233
1234
1235 /**
1236 * Get Taxonomy Data Lists
1237 *
1238 * @since v.1.0.0
1239 * @param OBJECT | Taxonomy Object
1240 * @return ARRAY
1241 */
1242 public function get_tax_data($terms) {
1243 $temp = array();
1244 $image = '';
1245 $thumbnail_id = get_term_meta( $terms->term_id, 'ultp_category_image', true );
1246 if ($thumbnail_id) {
1247 $image = wp_get_attachment_url( $thumbnail_id );
1248 }
1249 $temp['url'] = get_term_link($terms);
1250 $temp['name'] = $terms->name;
1251 $temp['desc'] = $terms->description;
1252 $temp['count'] = $terms->count;
1253 $temp['image'] = $image;
1254 $color = get_term_meta($terms->term_id, 'ultp_category_color', true);
1255 $temp['color'] = $color ? $color : '#037fff';
1256 return $temp;
1257 }
1258
1259 public function get_category_data($catSlug, $number = 40, $type = '', $tax_slug = 'category') {
1260 $data = array();
1261 if ($type == 'child') {
1262 $image = '';
1263 if (!empty($catSlug)) {
1264 foreach ($catSlug as $cat) {
1265 $parent_term = get_term_by('slug', $cat, $tax_slug);
1266 if (!empty($parent_term)) {
1267 $term_data = get_terms($tax_slug, array(
1268 'hide_empty' => true,
1269 'parent' => $parent_term->term_id
1270 ));
1271 if (!empty($term_data)) {
1272 foreach ($term_data as $terms) {
1273 $data[] = $this->get_tax_data($terms);
1274 }
1275 }
1276 }
1277 }
1278 }
1279 } else if ($type == 'parent') {
1280 $term_data = get_terms( $tax_slug, array( 'hide_empty' => true, 'number' => $number, 'parent' => 0 ) );
1281 if (!empty($term_data)) {
1282 foreach ($term_data as $terms) {
1283 $data[] = $this->get_tax_data($terms);
1284 }
1285 }
1286 } else if ($type == 'custom') {
1287 foreach ($catSlug as $cat) {
1288 $terms = get_term_by('slug', $cat, $tax_slug);
1289 if (!empty($terms)) {
1290 $data[] = $this->get_tax_data($terms);
1291 }
1292 }
1293 } else {
1294 $term_data = get_terms($tax_slug, array('hide_empty' => true, 'number' => $number));
1295 if (!empty($term_data)) {
1296 foreach ($term_data as $terms) {
1297 $data[] = $this->get_tax_data($terms);
1298 }
1299 }
1300 }
1301 return $data;
1302 }
1303
1304
1305 /**
1306 * Get Next Previous HTML
1307 *
1308 * @since v.1.0.0
1309 * @param OBJECT | Taxonomy Object
1310 * @return STRING
1311 */
1312 public function next_prev() {
1313 $html = '';
1314 $html .= '<ul>';
1315 $html .= '<li>';
1316 $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
1317 $html .= ultimate_post()->svg_icon('leftAngle2').'<span class="screen-reader-text">'.esc_html__("Previous", "ultimate-post").'</span>';
1318 $html .= '</a>';
1319 $html .= '</li>';
1320 $html .= '<li>';
1321 $html .= '<a class="ultp-next-action">';
1322 $html .= ultimate_post()->svg_icon('rightAngle2').'<span class="screen-reader-text">'.esc_html__("Next", "ultimate-post").'</span>';
1323 $html .= '</a>';
1324 $html .= '</li>';
1325 $html .= '</ul>';
1326 return $html;
1327 }
1328
1329
1330 /**
1331 * Get Loading HTML
1332 *
1333 * @since v.1.0.0
1334 * @param NULL
1335 * @return STRING
1336 */
1337 public function loading() {
1338 $html = '';
1339 $style = ultimate_post()->get_setting('preloader_style');
1340 if ($style == 'style2') {
1341 $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
1342 } else {
1343 $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>';
1344 }
1345 return '<div class="ultp-loading">'.$html.'</div>';
1346 }
1347
1348
1349 /**
1350 * Get Filter HTML
1351 *
1352 * @since v.1.0.0
1353 * @param | Filter Text (STRING) | Filter Type (STRING) | Filter Value (ARRAY) | Filter Cat (ARRAY) | Filter Tag (ARRAY) |
1354 * @return STRING
1355 */
1356 public function filter($filterText = '', $filterType = '', $filterValue = '[]', $filterMobileText = '...', $filterMobile = true) {
1357 $html = '';
1358 $html .= '<ul '.($filterMobile ? 'class="ultp-flex-menu"' : '').' data-name="'.($filterMobileText ? $filterMobileText : '&nbsp;').'">';
1359 $cat = $this->taxonomy($filterType);
1360 if ($filterText) {
1361 $html .= '<li class="filter-item"><a class="filter-active" data-taxonomy="" href="#">'.$filterText.'</a></li>';
1362 }
1363
1364 if ($filterValue) {
1365 $filterValue = strlen($filterValue) > 2 ? $filterValue : [];
1366 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
1367 foreach ($filterValue as $val) {
1368 $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($cat[$val]) ? $cat[$val] : $val).'</a></li>';
1369 }
1370 }
1371 $html .= '</ul>';
1372 return $html;
1373 }
1374
1375
1376 /**
1377 * Check License Status
1378 *
1379 * @since v.2.4.2
1380 * @return BOOLEAN | Is pro license active or not
1381 */
1382 public function is_lc_active() {
1383 if (function_exists('ultimate_post_pro')) {
1384 return get_option('edd_ultp_license_status') == 'valid' ? true : false;
1385 }
1386 if (get_transient( 'ulpt_theme_enable' ) == 'integration') {
1387 return true;
1388 }
1389 return false;
1390 }
1391
1392
1393 /**
1394 * Get SEO Meta
1395 *
1396 * @since v.2.4.3
1397 * @param NUMBER | Post ID
1398 * @return STRING | SEO Meta Description or Excerpt
1399 */
1400 public function get_excerpt($post_id = 0, $showSeoMeta = 0, $showFullExcerpt = 0, $excerptLimit = 55) {
1401 $html = '';
1402 if ($showSeoMeta) {
1403 $str = '';
1404 if (function_exists('ultimate_post_pro') ) {
1405 if (ultimate_post()->get_setting('ultp_yoast') == 'true') {
1406 $str = method_exists( ultimate_post_pro(), 'get_yoast_meta' ) ? ultimate_post_pro()->get_yoast_meta($post_id) : '';
1407 } else if (ultimate_post()->get_setting('ultp_rankmath') == 'true') {
1408 $str = method_exists( ultimate_post_pro(), 'get_rankmath_meta' ) ? ultimate_post_pro()->get_rankmath_meta($post_id) : '';
1409 } else if (ultimate_post()->get_setting('ultp_aioseo') == 'true') {
1410 $str = method_exists( ultimate_post_pro(), 'get_aioseo_meta' ) ? ultimate_post_pro()->get_aioseo_meta($post_id) : '';
1411 } else if (ultimate_post()->get_setting('ultp_seopress') == 'true') {
1412 $str = method_exists( ultimate_post_pro(), 'get_seopress_meta' ) ? ultimate_post_pro()->get_seopress_meta($post_id) : '';
1413 } else if (ultimate_post()->get_setting('ultp_squirrly') == 'true') {
1414 $str = method_exists( ultimate_post_pro(), 'get_squirrly_meta' ) ? ultimate_post_pro()->get_squirrly_meta($post_id) : '';
1415 }
1416 }
1417 $html = $str ? $str : ultimate_post()->excerpt($post_id, $excerptLimit);
1418 } else {
1419 if ($showFullExcerpt == 0 ) {
1420 $html = ultimate_post()->excerpt($post_id, $excerptLimit);
1421 } else {
1422 $html = get_the_excerpt();
1423 }
1424 }
1425 return $html;
1426 }
1427
1428 /**
1429 * Set Inline CSS
1430 *
1431 * @since v.2.5.8
1432 * @param STRING | CSS
1433 * @return STRING | CSS with Style
1434 */
1435 public function set_inline($css) {
1436 return '<style type="text/css">'.wp_strip_all_tags($css).'</style>';
1437 }
1438
1439 /**
1440 * Array Sanitize Function
1441 *
1442 * @since v.2.6.0
1443 * @param ARRAY
1444 * @return ARRAY | Array of Sanitize
1445 */
1446 public function recursive_sanitize_text_field($array) {
1447 foreach ($array as $key => &$value) {
1448 if (is_array($value)) {
1449 $value = $this->recursive_sanitize_text_field($value);
1450 } else {
1451 $value = sanitize_text_field($value);
1452 }
1453 }
1454 return $array;
1455 }
1456
1457
1458 public function get_embeded_video($url, $autoPlay, $loop, $mute, $playback, $preload, $poster, $inline, $size) {
1459 $vidAutoPlay = $vidloop = $vidloop = $vidmute = $vidplayback = $vidPoster = $vidInline = "";
1460
1461 if($autoPlay){
1462 $vidAutoPlay = "autoplay";
1463 }
1464 if($poster){
1465 $vidPoster = 'poster="'.$poster["url"].'"';
1466 }
1467 if($loop){
1468 $vidloop = "loop";
1469 }
1470 if($mute){
1471 $vidmute = "muted";
1472 }
1473 if($playback){
1474 $vidplayback = "controls";
1475 }
1476 if($inline){
1477 $vidInline = "playsinline";
1478 }
1479 if (!empty($url)) {
1480 $embeded = wp_oembed_get($url, $size);
1481 if ($embeded == false) {
1482 $format = '';
1483 $url = strtolower($url);
1484 if (strpos($url, '.mp4')) {
1485 $format = 'mp4';
1486 } elseif (strpos($url, '.ogg')) {
1487 $format = 'ogg';
1488 } elseif (strpos($url, '.webm')) {
1489 $format = 'WebM';
1490 }
1491 $embeded = '<video
1492 '.$vidloop.'
1493 '.$vidmute.'
1494 '.$vidplayback.'
1495 preload="'.$preload.'"
1496 '.$vidAutoPlay.'
1497 '.$vidPoster.'
1498 '.$vidInline.'
1499 ><source src="' . $url . '" type="video/' . $format . '">' . __('Your browser does not support the video tag.', 'ultimate-post') . '</video>';
1500 return '<div class="ultp-video-wrapper">'.$embeded.'</div>';
1501 }
1502 return '<div class="ultp-video-wrapper ultp-embaded-video">'.$embeded.'</div>';
1503 } else {
1504 return false;
1505 }
1506 }
1507
1508 /**
1509 * Get Public taxonomy Lists
1510 *
1511 * @since v.2.7.0
1512 * @param NULL
1513 * @return ARRAY | Taxonomy Lists as array
1514 */
1515 public function get_taxonomy_list() {
1516 $taxonomy = get_taxonomies(array('public' => true));
1517 return empty($taxonomy) ? [] : array_keys($taxonomy);
1518 }
1519
1520 /**
1521 * Content Print
1522 *
1523 * @since v.2.7.0
1524 * @param NUMBER | Post ID
1525 * @return STRING | Content of the Post
1526 */
1527 public function content($post_id) {
1528 $content_post = get_post($post_id);
1529 $content = $content_post->post_content;
1530 $content = apply_filters('the_content', $content);
1531 $content = str_replace(']]>', ']]&gt;', $content);
1532 echo $content;
1533 }
1534
1535
1536 /**
1537 * String Part finder inside array
1538 *
1539 * @since v.2.7.0
1540 * @return ARRAY | String Part
1541 */
1542 public function in_string_part($part, $data, $isValue = false) {
1543 $return = false;
1544 foreach ($data as $val) {
1545 if (strpos($val, $part) !== false) {
1546 $return = $isValue ? $val : true;
1547 break;
1548 }
1549 }
1550 return $return;
1551 }
1552
1553 /**
1554 * Builder Conditions
1555 *
1556 * @since v.2.7.0
1557 * @param STRING | Type of Return
1558 * @return MIXED || ID or Path
1559 */
1560 public function conditions( $type = 'return' ) {
1561 $page_id = '';
1562
1563 $conditions = get_option('ultp_builder_conditions', array());
1564 if (isset($conditions['archive'])) {
1565 if (!empty($conditions['archive'])) {
1566 $taxonomy = (is_category() || is_tag() || is_tax()) ? get_queried_object() : (object)[];
1567 foreach ($conditions['archive'] as $key => $val) {
1568 if (is_archive()) {
1569 if (in_array('include/archive', $val)) {
1570 if ('publish' == get_post_status($key)) {
1571 $page_id = $key;
1572 }
1573 }
1574 if (in_array('exclude/archive', $val)) {
1575 if ('publish' == get_post_status($key)) {
1576 $page_id = '';
1577 }
1578 }
1579 if (is_category()) {
1580 if (in_array('include/archive/category', $val)) {
1581 if ('publish' == get_post_status($key)) {
1582 $page_id = $key;
1583 }
1584 }
1585 if (in_array('exclude/archive/category', $val)) {
1586 if ('publish' == get_post_status($key)) {
1587 $page_id = '';
1588 }
1589 }
1590 if (in_array('include/archive/category/'.$taxonomy->term_id, $val)) {
1591 if ('publish' == get_post_status($key)) {
1592 $page_id = $key;
1593 }
1594 }
1595 if (in_array('exclude/archive/category/'.$taxonomy->term_id, $val)) {
1596 if ('publish' == get_post_status($key)) {
1597 $page_id = '';
1598 }
1599 }
1600 if ($this->in_string_part('any_child_of', $val)) {
1601 if (in_array('include/archive/any_child_of_category', $val)) {
1602 if ('publish' == get_post_status($key)) {
1603 $page_id = $key;
1604 }
1605 }
1606 if (in_array('exclude/archive/any_child_of_category', $val)) {
1607 if ('publish' == get_post_status($key)) {
1608 $page_id = '';
1609 }
1610 }
1611 $data = $this->in_string_part('/archive/any_child_of_category/', $val, true);
1612 if ($data) {
1613 $data = explode("/",$data);
1614 if (isset($data[3]) && $data[3]) {
1615 if (term_is_ancestor_of($data[3], $taxonomy->term_id, 'category')) {
1616 if ('publish' == get_post_status($key)) {
1617 $page_id = $data[0] == 'exclude' ? '' : $key;
1618 }
1619 }
1620 }
1621 }
1622 } else {
1623 if ($this->in_string_part('child_of', $val)) {
1624 if (in_array('include/archive/child_of_category', $val)) {
1625 if ('publish' == get_post_status($key)) {
1626 $page_id = $key;
1627 }
1628 }
1629 if (in_array('exclude/archive/child_of_category', $val)) {
1630 if ('publish' == get_post_status($key)) {
1631 $page_id = '';
1632 }
1633 }
1634 if (in_array('include/archive/child_of_category/'.$taxonomy->parent, $val)) {
1635 if ('publish' == get_post_status($key)) {
1636 $page_id = $key;
1637 }
1638 }
1639 if (in_array('exclude/archive/child_of_category/'.$taxonomy->parent, $val)) {
1640 if ('publish' == get_post_status($key)) {
1641 $page_id = '';
1642 }
1643 }
1644 }
1645 }
1646 } else if (is_tag()) {
1647 if (in_array('include/archive/post_tag', $val)) {
1648 if ('publish' == get_post_status($key)) {
1649 $page_id = $key;
1650 }
1651 }
1652 if (in_array('exclude/archive/post_tag', $val)) {
1653 if ('publish' == get_post_status($key)) {
1654 $page_id = '';
1655 }
1656 }
1657 if (in_array('include/archive/post_tag/'.$taxonomy->term_id, $val)) {
1658 if ('publish' == get_post_status($key)) {
1659 $page_id = $key;
1660 }
1661 }
1662 if (in_array('exclude/archive/post_tag/'.$taxonomy->term_id, $val)) {
1663 if ('publish' == get_post_status($key)) {
1664 $page_id = '';
1665 }
1666 }
1667 } else if (is_tax()) {
1668 if (in_array('include/archive/'.$taxonomy->taxonomy, $val)) {
1669 if ('publish' == get_post_status($key)) {
1670 $page_id = $key;
1671 }
1672 }
1673 if (in_array('exclude/archive/'.$taxonomy->taxonomy, $val)) {
1674 if ('publish' == get_post_status($key)) {
1675 $page_id = '';
1676 }
1677 }
1678 if (in_array('include/archive/'.$taxonomy->taxonomy.'/'.$taxonomy->term_id, $val)) {
1679 if ('publish' == get_post_status($key)) {
1680 $page_id = $key;
1681 }
1682 }
1683 if (in_array('exclude/archive/'.$taxonomy->taxonomy.'/'.$taxonomy->term_id, $val)) {
1684 if ('publish' == get_post_status($key)) {
1685 $page_id = '';
1686 }
1687 }
1688 if ($this->in_string_part('any_child_of', $val)) {
1689 if (in_array('include/archive/any_child_of_'.$taxonomy->taxonomy, $val)) {
1690 if ('publish' == get_post_status($key)) {
1691 $page_id = $key;
1692 }
1693 }
1694 if (in_array('exclude/archive/any_child_of_'.$taxonomy->taxonomy, $val)) {
1695 if ('publish' == get_post_status($key)) {
1696 $page_id = '';
1697 }
1698 }
1699 $data = $this->in_string_part('/archive/any_child_of_'.$taxonomy->taxonomy.'/', $val, true);
1700 if ($data) {
1701 $data = explode("/",$data);
1702 if (isset($data[3]) && $data[3]) {
1703 if (term_is_ancestor_of($data[3], $taxonomy->term_id, $taxonomy->taxonomy)) {
1704 if ('publish' == get_post_status($key)) {
1705 $page_id = $data[0] == 'exclude' ? '' : $key;
1706 }
1707 }
1708 }
1709 }
1710 } else {
1711 if ($this->in_string_part('child_of', $val)) {
1712 if (in_array('include/archive/child_of_'.$taxonomy->taxonomy, $val)) {
1713 if ('publish' == get_post_status($key)) {
1714 $page_id = $key;
1715 }
1716 }
1717 if (in_array('exclude/archive/child_of_'.$taxonomy->taxonomy, $val)) {
1718 if ('publish' == get_post_status($key)) {
1719 $page_id = '';
1720 }
1721 }
1722 if (in_array('include/archive/child_of_'.$taxonomy->taxonomy.'/'.$taxonomy->parent, $val)) {
1723 if ('publish' == get_post_status($key)) {
1724 $page_id = $key;
1725 }
1726 }
1727 if (in_array('exclude/archive/child_of_'.$taxonomy->taxonomy.'/'.$taxonomy->parent, $val)) {
1728 if ('publish' == get_post_status($key)) {
1729 $page_id = '';
1730 }
1731 }
1732 }
1733 }
1734 } else if (is_date()) {
1735 if (in_array('include/archive/date', $val)) {
1736 if ('publish' == get_post_status($key)) {
1737 $page_id = $key;
1738 }
1739 }
1740 if (in_array('exclude/archive/date', $val)) {
1741 if ('publish' == get_post_status($key)) {
1742 $page_id = '';
1743 }
1744 }
1745 } else if (is_author()) {
1746 if (in_array('include/archive/author', $val)) {
1747 if ('publish' == get_post_status($key)) {
1748 $page_id = $key;
1749 }
1750 }
1751 if (in_array('exclude/archive/author', $val)) {
1752 if ('publish' == get_post_status($key)) {
1753 $page_id = '';
1754 }
1755 }
1756 $author_id = get_the_author_meta('ID');
1757 if (in_array('include/archive/author/'.$author_id, $val)) {
1758 if ('publish' == get_post_status($key)) {
1759 $page_id = $key;
1760 }
1761 }
1762 if (in_array('exclude/archive/author/'.$author_id, $val)) {
1763 if ('publish' == get_post_status($key)) {
1764 $page_id = '';
1765 }
1766 }
1767 }
1768 } else if (is_search()) {
1769 if (in_array('include/archive/search', $val)) {
1770 if ('publish' == get_post_status($key)) {
1771 $page_id = $key;
1772 }
1773 }
1774 if (in_array('exclude/archive/search', $val)) {
1775 if ('publish' == get_post_status($key)) {
1776 $page_id = '';
1777 }
1778 }
1779 }
1780 }
1781 }
1782 }
1783 // Singular
1784 if (isset($conditions['singular'])) {
1785 if (!empty($conditions['singular'])) {
1786 $obj = get_queried_object();
1787 $tax_list = $this->get_taxonomy_list();
1788 foreach ($conditions['singular'] as $key => $val) {
1789 if (is_singular()) {
1790 // Front Page
1791 if (is_front_page()) {
1792 if (in_array('include/singular/front_page', $val)) {
1793 if ('publish' == get_post_status($key)) {
1794 $page_id = $key;
1795 }
1796 }
1797 if (in_array('exclude/singular/front_page', $val)) {
1798 if ('publish' == get_post_status($key)) {
1799 $page_id = '';
1800 }
1801 }
1802 }
1803 // Author check
1804 if (in_array('singular/post_by_author', $val)) {
1805 $author_id = get_the_author_meta('ID');
1806 if (in_array('include/singular/post_by_author', $val)) {
1807 if ('publish' == get_post_status($key)) {
1808 $page_id = $key;
1809 }
1810 }
1811 if (in_array('exclude/singular/post_by_author', $val)) {
1812 if ('publish' == get_post_status($key)) {
1813 $page_id = '';
1814 }
1815 }
1816 if (in_array('include/singular/post_by_author/'.$obj->post_author, $val)) {
1817 if ('publish' == get_post_status($key)) {
1818 $page_id = $key;
1819 }
1820 }
1821 if (in_array('exclude/singular/post_by_author/'.$obj->post_author, $val)) {
1822 if ('publish' == get_post_status($key)) {
1823 $page_id = '';
1824 }
1825 }
1826 }
1827 // All Taxonomy
1828 if($this->in_string_part('/singular/in_', $val)) {
1829 foreach ($tax_list as $tax) {
1830 if ($this->in_string_part('singular/in_'.$tax.'_children', $val)) {
1831 // In Taxonomy Children
1832 if (in_array('include/singular/in_'.$tax.'_children', $val)) {
1833 if ('publish' == get_post_status($key)) {
1834 $page_id = $key;
1835 }
1836 }
1837 if (in_array('exclude/singular/in_'.$tax.'_children', $val)) {
1838 if ('publish' == get_post_status($key)) {
1839 $page_id = '';
1840 }
1841 }
1842 $data = $this->in_string_part('/singular/in_'.$tax.'_children/', $val, true);
1843 if ($data) {
1844 $data = explode("/", $data);
1845 if (isset($data[3]) && $data[3]) {
1846 if (is_object_in_term($obj->ID , $tax, $data[3] )) {
1847 if ('publish' == get_post_status($key)) {
1848 $page_id = $data[0] == 'exclude' ? '' : $key;
1849 }
1850 }
1851 }
1852 }
1853 } else {
1854 // IN Taxonomy
1855 if (in_array('include/singular/in_'.$tax, $val)) {
1856 if ('publish' == get_post_status($key)) {
1857 $page_id = $key;
1858 }
1859 }
1860 if (in_array('exclude/singular/in_'.$tax, $val)) {
1861 if ('publish' == get_post_status($key)) {
1862 $page_id = '';
1863 }
1864 }
1865 $data = $this->in_string_part('/singular/in_'.$tax.'/', $val, true);
1866 if ($data) {
1867 $data = explode("/",$data);
1868 if (isset($data[3]) && $data[3]) {
1869 if (is_object_in_term($obj->ID , $tax, $data[3] )) {
1870 if ('publish' == get_post_status($key)) {
1871 $page_id = $data[0] == 'exclude' ? '' : $key;
1872 }
1873 }
1874 }
1875 }
1876 }
1877 }
1878 }
1879 // All Post Type
1880 if (in_array('include/singular/'.$obj->post_type, $val)) {
1881 if ('publish' == get_post_status($key)) {
1882 $page_id = $key;
1883 }
1884 }
1885 if (in_array('exclude/singular/'.$obj->post_type, $val)) {
1886 if ('publish' == get_post_status($key)) {
1887 $page_id = '';
1888 }
1889 }
1890 if ($this->in_string_part('include/singular/'.$obj->post_type.'/'.$obj->ID, $val)) {
1891 if ('publish' == get_post_status($key)) {
1892 $page_id = $key;
1893 }
1894 }
1895 if ($this->in_string_part('exclude/singular/'.$obj->post_type.'/'.$obj->ID, $val)) {
1896 if ('publish' == get_post_status($key)) {
1897 $page_id = '';
1898 }
1899 }
1900 }
1901 }
1902 }
1903 }
1904
1905 if ($type == 'return') {
1906 return $page_id;
1907 }
1908 if ($type == 'includes') {
1909 return $page_id ? ULTP_PATH.'addons/builder/Archive_Template.php' : '';
1910 }
1911 }
1912
1913
1914 /**
1915 * Get Add Default Condition Data
1916 *
1917 * @since v.2.7.0
1918 * @return ARRAY | Default Data
1919 */
1920 public function builder_data() {
1921 $archive_data = [
1922 [
1923 'label' => 'All Archive',
1924 'value' => '',
1925 ],
1926 [
1927 'label' => 'Author Archive',
1928 'value' => 'author',
1929 'search' => 'author###'
1930 ],
1931 [
1932 'label' => 'Date Archive',
1933 'value' => 'date',
1934 ],
1935 [
1936 'label' => 'Search Results',
1937 'value' => 'search',
1938 ],
1939 ];
1940 $single_data = [
1941 [
1942 'label' => 'Front Page',
1943 'value' => 'front_page',
1944 ]
1945 ];
1946
1947 $post_type = get_post_types( ['public' => true], 'objects' );
1948 foreach ($post_type as $key => $type) {
1949 // Post Type
1950 $single_temp = [
1951 'label' => $type->label,
1952 'value' => $type->name,
1953 'search' => 'type###'.$type->name
1954 ];
1955 $archive_temp = [];
1956
1957 // Taxonomy
1958 $taxonomy = get_object_taxonomies( $type->name, 'objects' );
1959 if (!empty($taxonomy)) {
1960 $single_tax = $archive_tax = [];
1961 $single_tax[] = $single_temp;
1962
1963 $archive_temp = [
1964 'label' => $type->label . ' Archive',
1965 'value' => $type->name . '_archive',
1966 ];
1967 // $archive_tax[] = $archive_temp;
1968 foreach ($taxonomy as $key => $val) {
1969 if ($val->public) {
1970 $single_tax[] = [
1971 'label' => 'In ' . $val->label,
1972 'value' => 'in_' . $val->name,
1973 'search' => 'term###'.$val->name
1974 ];
1975 $archive_tax[] = [
1976 'label' => $val->label,
1977 'value' => $val->name,
1978 'search' => 'term###'.$val->name
1979 ];
1980
1981 if ($val->hierarchical) {
1982 // Hierarchical
1983 $single_tax[] = [
1984 'label' => 'In Child ' . $val->label,
1985 'value' => 'in_' . $val->name . '_children',
1986 'search' => 'term###'.$val->name
1987 ];
1988 $archive_tax[] = [
1989 'label' => 'Direct Child ' . $val->label . ' Of',
1990 'value' => 'child_of_' . $val->name,
1991 'search' => 'term###'.$val->name
1992 ];
1993 $archive_tax[] = [
1994 'label' => 'Any Child ' . $val->label . ' Of',
1995 'value' => 'any_child_of_' . $val->name,
1996 'search' => 'term###'.$val->name
1997 ];
1998 }
1999 }
2000 }
2001 // Author
2002 $single_tax[] = [
2003 'label' => 'Posts By Author',
2004 'value' => 'post_by_author',
2005 'search' => 'author###'
2006 ];
2007 $single_temp['attr'] = $single_tax;
2008 $archive_temp['attr'] = $archive_tax;
2009 }
2010 $single_data[] = $single_temp;
2011 if (!empty($archive_temp)) {
2012 $archive_data[] = $archive_temp;
2013 }
2014 }
2015
2016 return ['singular' => $single_data, 'archive' => $archive_data];
2017 }
2018
2019 /**
2020 * Get Date Default Format
2021 *
2022 * @since v.2.7.2
2023 * @return ARRAY | Default Data
2024 */
2025 public function get_format($format) {
2026 if ($format == 'default_date') {
2027 return $this->get_setting('date_format');
2028 } else if ($format == 'default_date_time') {
2029 return $this->get_setting('date_format').' '.$this->get_setting('time_format');
2030 } else {
2031 return $format;
2032 }
2033 }
2034
2035 public function pro_popup_html() { ?>
2036 <div class="ultp-popup-container popup-center">
2037 <div class="ultp-unlock-popup ultp-unlock-modal">
2038 <img src="<?php echo esc_url(ULTP_URL . '/assets/img/admin/dashboard/unlock-super-icon.svg'); ?>" alt="lock icon">
2039 <h4 class="ultp-md-heading ultp-mt25 ultp-mb25"><?php esc_html_e('Unlock 11+ Addons', 'ultimate-post'); ?></h4>
2040 <div class="ultp-popup-desc">
2041 <?php esc_html_e('We’re sorry, PostX Addons are not available on PostX free. Please upgrade to a PRO plan to unlock the add ons of your choice.', 'ultimate-post'); ?>
2042 </div>
2043 <a href="<?php echo esc_url(ultimate_post()->get_premium_link('', 'postx_dashboard_addons_popup')); ?>" class="ultp-popup-planbtn ultp-btn ultp-btn-warning ultp-mt25"><?php esc_html_e('Upgrade Plan', 'ultimate-post'); ?></a>
2044 <button class="ultp-popup-close"></button>
2045 </div>
2046 </div>
2047 <?php }
2048
2049 /**
2050 * Common Frontend and Backend CSS and JS Scripts
2051 *
2052 * @since v.1.0.0
2053 * @return NULL
2054 */
2055 public function register_scripts_common() {
2056 wp_enqueue_style('ultp-style', ULTP_URL.'assets/css/style.min.css', array(), ULTP_VER );
2057 wp_enqueue_script('ultp-script', ULTP_URL.'assets/js/ultp.min.js', array('jquery'), ULTP_VER, true);
2058 wp_localize_script('ultp-script', 'ultp_data_frontend', array(
2059 'url' => ULTP_URL,
2060 'ajax' => admin_url('admin-ajax.php'),
2061 'security' => wp_create_nonce('ultp-nonce')
2062 ));
2063 }
2064
2065 }
2066