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

2,091 lines 91.0 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 'post_slider_2' => 'yes',
466 'heading' => 'yes',
467 'image' => 'yes',
468 'taxonomy' => 'yes',
469 'wrapper' => 'yes',
470 'news_ticker' => 'yes',
471 'builder_advance_post_meta' => 'yes',
472 'builder_archive_title' => 'yes',
473 'builder_author_box' => 'yes',
474 'builder_post_next_previous'=> 'yes',
475 'builder_post_author_meta' => 'yes',
476 'builder_post_breadcrumb' => 'yes',
477 'builder_post_category' => 'yes',
478 'builder_post_comment_count'=> 'yes',
479 'builder_post_comments' => 'yes',
480 'builder_post_content' => 'yes',
481 'builder_post_date_meta' => 'yes',
482 'builder_post_excerpt' => 'yes',
483 'builder_post_featured_image'=> 'yes',
484 'builder_post_reading_time' => 'yes',
485 'builder_post_social_share' => 'yes',
486 'builder_post_tag' => 'yes',
487 'builder_post_title' => 'yes',
488 'builder_post_view_count' => 'yes',
489 'save_version' => rand(1, 1000)
490 );
491 if (empty($data)) {
492 update_option('ultp_options', $init_data);
493 $GLOBALS['ultp_settings'] = $init_data;
494 } else {
495 foreach ($init_data as $key => $single) {
496 if (!isset($data[$key])) {
497 $data[$key] = $single;
498 }
499 }
500 update_option('ultp_options', $data);
501 $GLOBALS['ultp_settings'] = $data;
502 }
503 }
504
505
506 /**
507 * Get Excerpt Text
508 *
509 * @since v.1.0.0
510 * @param | Post ID (STRING) | Limit (NUMBER)
511 * @return STRING
512 */
513 public function excerpt( $post_id, $limit = 55 ) {
514 return apply_filters( 'the_excerpt', wp_trim_words( get_the_content( $post_id ) , $limit ) );
515 }
516
517 /**
518 * Builder Attributes
519 *
520 * @since v.1.0.0
521 * @param STRING type
522 * @return STRING
523 */
524 public function get_builder_attr($type) {
525 $builder_data = '';
526 if ($type == 'archiveBuilder') {
527 if (is_archive()) {
528 if (is_date()) {
529 if (is_year()) {
530 $builder_data = 'date###'.get_the_date('Y');
531 } else if (is_month() ) {
532 $builder_data = 'date###'.get_the_date('Y-n');
533 } else if (is_day() ) {
534 $builder_data = 'date###'.get_the_date('Y-n-j');
535 }
536 } else if (is_author()) {
537 $builder_data = 'author###'.get_the_author_meta('ID');
538 } else {
539 $obj = get_queried_object();
540 if (isset($obj->taxonomy)) {
541 $builder_data = 'taxonomy###'.$obj->taxonomy.'###'.$obj->slug;
542 }
543 }
544 } else if (is_search()) {
545 $builder_data = 'search###'.get_search_query(true);
546 }
547 }
548 return $builder_data ? 'data-builder="'.$builder_data.'"' : '';
549 }
550
551
552 public function is_builder($builder = '') {
553 $id = '';
554 $page_id = ultimate_post()->conditions('return');
555 if ($page_id && ultimate_post()->get_setting('ultp_builder')) {
556 $id = $page_id;
557 }
558 return $id;
559 }
560
561
562 /**
563 * Get Post Number Depending On Device
564 *
565 * @since v.2.5.4
566 * @param MULTIPLE | Attribute of Posts
567 * @return STRING
568 */
569 public function get_post_number($preDef, $prev, $current) {
570
571 $current = is_object($current)?json_decode(json_encode($current), true):$current;
572 if (['lg'=>$preDef,'sm'=>$preDef,'xs'=>$preDef] == $current) {
573 if ($preDef != $prev) {
574 return $prev;
575 }
576 }
577 if ($this->isDevice() == 'mobile') {
578 return $current['xs'];
579 } else if ($this->isDevice() == 'tablet') {
580 return $current['sm'];
581 } else {
582 return $current['lg'];
583 }
584 }
585
586
587 /**
588 * Get Post Number Depending On Device
589 *
590 * @since v.2.5.4
591 * @param NULL
592 * @return STRING | Device Type
593 */
594 public function isDevice(){
595 $useragent = isset($_SERVER['HTTP_USER_AGENT']) ? sanitize_key($_SERVER['HTTP_USER_AGENT']) : '';
596 if ($useragent) {
597 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))) {
598 return 'mobile';
599 } else if (preg_match('/(tablet|ipad|playbook)|(android(?!.*(mobi|opera mini)))/i', strtolower($useragent))) {
600 return 'tablet';
601 } else {
602 return 'desktop';
603 }
604 }
605 return 'desktop';
606 }
607
608
609 /**
610 * Get Raw Value from Objects
611 *
612 * @since v.2.5.3
613 * @param NULL
614 * @return STRING | Device Type
615 */
616 public function get_value($attr) {
617 $data = [];
618 if (is_array($attr)) {
619 foreach ($attr as $val) {
620 $data[] = $val->value;
621 }
622 }
623 return $data;
624 }
625
626
627 /**
628 * Query Builder
629 *
630 * @since v.1.0.0
631 * @param ARRAY | Attribute of the Query
632 * @return ARRAY
633 */
634 public function get_query($attr) {
635 $builder = isset($attr['builder']) ? $attr['builder'] : '';
636 $post_type = isset($attr['queryType']) ? $attr['queryType'] : 'post';
637 if ( $post_type == 'archiveBuilder' && ($builder || $this->is_builder($builder)) ) {
638 $archive_query = array();
639 if ($builder) {
640 $str = explode('###', $builder);
641 if (isset($str[0])) {
642 if ($str[0] == 'taxonomy') {
643 if (isset($str[1]) && isset($str[2])) {
644 $archive_query['tax_query'] = array(
645 array(
646 'taxonomy' => $str[1],
647 'field' => 'slug',
648 'terms' => $str[2]
649 )
650 );
651 }
652 } else if ($str[0] == 'author') {
653 if (isset($str[1])) {
654 $archive_query['author'] = $str[1];
655 }
656 } else if ($str[0] == 'search') {
657 if (isset($str[1])) {
658 $archive_query['s'] = $str[1];
659 }
660 } else if ($str[0] == 'date') {
661 if (isset($str[1])) {
662 $all_date = explode('-', $str[1]);
663 if (!empty($all_date)) {
664 $arg = array();
665 if (isset($all_date[0])) { $arg['year'] = $all_date[0]; }
666 if (isset($all_date[1])) { $arg['month'] = $all_date[1]; }
667 if (isset($all_date[2])) { $arg['day'] = $all_date[2]; }
668 $archive_query['date_query'][] = $arg;
669 }
670 }
671 }
672 }
673 } else {
674 global $wp_query;
675 $archive_query = $wp_query->query_vars;
676 }
677 $archive_query['posts_per_page'] = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
678 $archive_query['paged'] = isset($attr['paged']) ? $attr['paged'] : 1;
679 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
680 $offset = $this->get_offset($attr['queryOffset'], $archive_query);
681 $archive_query = array_merge($archive_query, $offset);
682 }
683
684 // Include Remove from Version 2.5.4
685 if (isset($attr['queryInclude']) && $attr['queryInclude']) {
686 $_include = explode(',', $attr['queryInclude']);
687 if (is_array($_include) && count($_include)) {
688 $archive_query['post__in'] = isset($archive_query['post__in']) ? array_merge($archive_query['post__in'], $_include) : $_include;
689 $archive_query['ignore_sticky_posts'] = 1;
690 $archive_query['orderby'] = 'post__in';
691 }
692 }
693
694 if (isset($attr['queryExclude']) && $attr['queryExclude']) {
695 $_exclude = (substr($attr['queryExclude'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryExclude'])) : explode(',', $attr['queryExclude']);
696 if (is_array($_exclude) && count($_exclude)) {
697 $archive_query['post__not_in'] = isset($archive_query['post__not_in']) ? array_merge($archive_query['post__not_in'], $_exclude) : $_exclude;
698 }
699 }
700
701
702 if(isset($attr['querySticky']) && $attr['querySticky']) {
703 if (filter_var($attr['querySticky'], FILTER_VALIDATE_BOOLEAN)) {
704 $sticky = get_option( 'sticky_posts', [] );
705 $archive_query['post__not_in'] = isset($archive_query['post__not_in']) ? array_merge($archive_query['post__not_in'], $sticky) : $sticky;
706 }
707 }
708
709 $archive_query['post_status'] = 'publish';
710 if (is_user_logged_in()) {
711 if( current_user_can('editor') || current_user_can('administrator') ) {
712 $archive_query['post_status'] = array('publish', 'private');
713 }
714 }
715
716 if(!isset($archive_query['orderby'])) {
717 $archive_query['orderby'] = isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date';
718 }
719
720 // Quick Query Support for Builder
721 if (isset($attr['queryQuick'])) {
722 if ($attr['queryQuick'] != '') {
723 $archive_query = ultimate_post()->get_quick_query($attr, $archive_query);
724 }
725 }
726
727 if (!isset($attr['ajaxCall'])) {
728 if(isset($attr['filterShow']) && $attr['filterShow']) {
729 if(isset($attr['filterType']) && isset($attr['filterValue'])) {
730 $filterValue = strlen($attr['filterValue']) > 2 ? $attr['filterValue'] : [];
731 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
732 if (count($filterValue) > 0 && $attr['filterType']) {
733 $final = array('relation' => 'OR');
734 foreach ($filterValue as $key => $val) {
735 $final[] = array(
736 'taxonomy' => $attr['filterType'],
737 'field' => 'slug',
738 'terms' => $val,
739 );
740 }
741 $archive_query['tax_query'] = $final;
742 }
743 }
744 }
745 }
746
747 return apply_filters('ultp_archive_query', $archive_query);
748 }
749
750 $query_args = array(
751 'posts_per_page' => isset($attr['queryNumber']) ? $attr['queryNumber'] : 3,
752 'post_type' => $post_type == 'archiveBuilder' ? 'post' : $post_type,
753 'orderby' => isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date',
754 'order' => isset($attr['queryOrder']) ? $attr['queryOrder'] : 'desc',
755 'paged' => isset($attr['paged']) ? $attr['paged'] : 1,
756 'post_status' => 'publish'
757 );
758
759 // For Private Post 'private'
760 if (is_user_logged_in()) {
761 if( current_user_can('editor') || current_user_can('administrator') ) {
762 $query_args['post_status'] = array('publish', 'private');
763 }
764 }
765
766 if ($attr['queryType'] == 'posts') {
767 if (isset($attr['queryPosts']) && $attr['queryPosts']) {
768 unset($query_args['post_type']);
769 $data = json_decode(isset($attr['queryPosts'])?$attr['queryPosts']:'[]');
770 $final = $this->get_value($data);
771 if (count($final) > 0) {
772 $query_args['post__in'] = $final;
773 $query_args['posts_per_page'] = -1;
774 }
775 $query_args['ignore_sticky_posts'] = 1;
776 return $query_args;
777 }
778 } else if ($attr['queryType'] == 'customPosts') {
779 if (isset($attr['queryCustomPosts']) && $attr['queryCustomPosts']) {
780 $query_args['post_type'] = $this->get_post_type();
781 $data = json_decode(isset($attr['queryCustomPosts'])?$attr['queryCustomPosts']:'[]');
782 $final = $this->get_value($data);
783 if (count($final) > 0) {
784 $query_args['post__in'] = $final;
785 $query_args['posts_per_page'] = -1;
786 }
787 $query_args['ignore_sticky_posts'] = 1;
788 return $query_args;
789 }
790 }
791
792 if (isset($attr['queryExcludeAuthor']) && $attr['queryExcludeAuthor']) {
793 $data = json_decode(isset($attr['queryExcludeAuthor'])?$attr['queryExcludeAuthor']:'[]');
794 $final = $this->get_value($data);
795 if (count($final) > 0) {
796 $query_args['author__not_in'] = $final;
797 }
798 }
799
800
801 if (isset($attr['queryOrderBy']) && isset($attr['metaKey'])) {
802 if ($attr['queryOrderBy'] == 'meta_value_num') {
803 $query_args['meta_key'] = $attr['metaKey'];
804 }
805 }
806
807 // Include Remove from Version 2.5.4
808 if (isset($attr['queryInclude']) && $attr['queryInclude']) {
809 $_include = explode(',', $attr['queryInclude']);
810 if (is_array($_include) && count($_include)) {
811 $query_args['post__in'] = isset($query_args['post__in']) ? array_merge($query_args['post__in'], $_include) : $_include;
812 $query_args['ignore_sticky_posts'] = 1;
813 $query_args['orderby'] = 'post__in';
814 }
815 }
816
817
818 if (isset($attr['queryTax'])) {
819 if (isset($attr['queryTaxValue'])) {
820 $tax_value = (strlen($attr['queryTaxValue']) > 2) ? $attr['queryTaxValue'] : [];
821 $tax_value = is_array($tax_value) ? $tax_value : json_decode($tax_value);
822
823 $tax_value = (isset($tax_value[0]) && is_object($tax_value[0])) ? $this->get_value($tax_value) : $tax_value;
824
825 if (is_array($tax_value) && count($tax_value) > 0) {
826 $relation = isset($attr['queryRelation']) ? $attr['queryRelation'] : 'OR';
827 $var = array('relation'=>$relation);
828 foreach ($tax_value as $val) {
829 $tax_name = $attr['queryTax'];
830 // For Custom Terms
831 if ($attr['queryTax'] == 'multiTaxonomy') {
832 $temp = explode('###', $val);
833 if (isset($temp[1])) {
834 $val = $temp[1];
835 $tax_name = $temp[0];
836 }
837 }
838
839 $var[] = array('taxonomy'=> $tax_name, 'field' => 'slug', 'terms' => $val );
840 }
841 if (count($var) > 1) {
842 $query_args['tax_query'] = $var;
843 }
844 }
845 }
846 }
847
848
849 if (isset($attr['queryExcludeTerm']) && $attr['queryExcludeTerm']) {
850 $temp = json_decode($attr['queryExcludeTerm']);
851 $_term = [];
852 foreach ($temp as $val) {
853 $temp = explode('###', $val->value);
854 if (isset($temp[1])) {
855 if (array_key_exists($temp[0], $_term)) {
856 $_term[$temp[0]][] = $temp[1];
857 } else {
858 $_term[$temp[0]] = array($temp[1]);
859 }
860 }
861 }
862 if (count($_term) > 0) {
863 $final = array('relation' => 'AND');
864 foreach ($_term as $key => $val) {
865 $final[] = array(
866 'taxonomy' => $key,
867 'field' => 'slug',
868 'terms' => $val,
869 'operator' => 'NOT IN',
870 );
871 }
872
873 if (array_key_exists('tax_query', $query_args)) {
874 $query_args['tax_query'] = array(
875 'relation' => 'AND',
876 $query_args['tax_query']
877 );
878 $query_args['tax_query'][] = $final;
879 } else {
880 $query_args['tax_query'] = $final;
881 }
882 }
883 }
884
885 if (isset($attr['queryExclude']) && $attr['queryExclude']) {
886 $_exclude = (substr($attr['queryExclude'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryExclude'])) : explode(',', $attr['queryExclude']);
887 if (is_array($_exclude) && count($_exclude)) {
888 $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $_exclude) : $_exclude;
889 }
890 }
891
892 if (isset($attr['queryUnique']) && $attr['queryUnique']) {
893 global $unique_ID;
894 if (isset($unique_ID[$attr['queryUnique']])) {
895 $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']];
896 }
897 }
898
899 if (isset($attr['queryQuick'])) {
900 if ($attr['queryQuick'] != '' && $post_type != 'archiveBuilder') {
901 $query_args = ultimate_post()->get_quick_query($attr, $query_args);
902 }
903 }
904
905 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
906 $offset = $this->get_offset($attr['queryOffset'], $query_args);
907 $query_args = array_merge($query_args, $offset);
908 }
909
910 if (isset($attr['queryAuthor']) && $attr['queryAuthor'] ) {
911 $_include = (substr($attr['queryAuthor'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryAuthor'])) : explode(',', $attr['queryAuthor']);
912 if (is_array($_include) && count($_include)) {
913 $query_args['author__in'] = $_include;
914 }
915 }
916
917 if(isset($attr['querySticky']) && $attr['querySticky']) {
918 if (filter_var($attr['querySticky'], FILTER_VALIDATE_BOOLEAN)) {
919 $sticky = get_option( 'sticky_posts', [] );
920 $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $sticky) : $sticky;
921 }
922 }
923
924 if (!isset($attr['ajaxCall'])) {
925 if(isset($attr['filterShow']) && $attr['filterShow']) {
926 if(isset($attr['filterType']) && isset($attr['filterValue'])) {
927 $filterValue = strlen($attr['filterValue']) > 2 ? $attr['filterValue'] : [];
928 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
929 if (is_array($filterValue) && count($filterValue) > 0 && $attr['filterType']) {
930 $final = array('relation' => 'OR');
931 foreach ($filterValue as $key => $val) {
932 $final[] = array(
933 'taxonomy' => $attr['filterType'],
934 'field' => 'slug',
935 'terms' => $val,
936 // 'operator' => '=',
937 );
938 }
939 $query_args['tax_query'] = $final;
940 }
941 }
942 }
943 }
944
945 $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
946
947 return apply_filters('ultp_frontend_query', $query_args);
948 }
949
950 /**
951 * Get Page Offset
952 *
953 * @since v.1.0.0
954 * @param | Offset Number(NUMBER) | Query Arg(ARRAY)
955 * @return ARRAY
956 */
957 function get_offset($queryOffset, $query_args) {
958 $query = array();
959 if ($query_args['paged'] > 1) {
960 $offset_post = wp_get_recent_posts($query_args, OBJECT);
961 if (count($offset_post) > 0 ) {
962 $offset = array();
963 for($x = count($offset_post); $x > count($offset_post) - $queryOffset; $x--) {
964 $offset[] = $offset_post[$x-1]->ID;
965 }
966 $query['post__not_in'] = $offset;
967 }
968 } else {
969 $query['offset'] = isset($queryOffset) ? $queryOffset : 0;
970 }
971 return $query;
972 }
973
974
975 /**
976 * Get Page Number
977 *
978 * @since v.1.0.0
979 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
980 * @return ARRAY
981 */
982 public function get_page_number($attr, $post_number) {
983 if ($post_number > 0) {
984 if (isset($attr['queryOffset']) && $attr['queryOffset']) {
985 $post_number = $post_number - (int)$attr['queryOffset'];
986 }
987 $post_per_page = isset($attr['queryNumber']) ? ($attr['queryNumber'] ? $attr['queryNumber'] : 1) : 3;
988 $pages = ceil($post_number/$post_per_page);
989 return $pages ? $pages : 1;
990 }else{
991 return 1;
992 }
993 }
994
995
996 /**
997 * Get Image Size
998 *
999 * @since v.1.0.0
1000 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1001 * @return ARRAY
1002 */
1003 public function get_image_size() {
1004 $sizes = get_intermediate_image_sizes();
1005 $filter = array('full' => 'Full');
1006 foreach ($sizes as $value) {
1007 $title = ucwords(str_replace(array('_', '-'), array(' ', ' '), $value));
1008 switch ($value) {
1009 case 'thumbnail':
1010 $title = $title.' [150x150]';
1011 break;
1012 case 'medium':
1013 $title = $title.' [300x300]';
1014 break;
1015 case 'large':
1016 $title = $title.' [1024x1024]';
1017 break;
1018 case 'ultp_layout_landscape_large':
1019 $title = $title.' [1200x800]';
1020 break;
1021 case 'ultp_layout_landscape':
1022 $title = $title.' [870x570]';
1023 break;
1024 case 'ultp_layout_portrait':
1025 $title = $title.' [600x900]';
1026 break;
1027 case 'ultp_layout_square':
1028 $title = $title.' [600x600]';
1029 break;
1030 default:
1031 break;
1032 }
1033 $filter[$value] = $title;
1034 }
1035 return $filter;
1036 }
1037
1038
1039 /**
1040 * Get All PostType Registered
1041 *
1042 * @since v.1.0.0
1043 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1044 * @return ARRAY
1045 */
1046 public function get_post_type() {
1047 $filter = apply_filters('ultp_public_post_type', true);
1048 $post_type = get_post_types( ($filter ? ['public' => true] : ''), 'names' );
1049 return array_diff($post_type, array( 'attachment' ));
1050 }
1051
1052
1053 /**
1054 * Get Pagination HTML
1055 *
1056 * @since v.1.0.0
1057 * @param | pages (NUMBER) | Pagination Nav (STRING) | Pagination Text |
1058 * @return STRING
1059 */
1060 public function pagination($pages = '', $paginationNav = '', $paginationText = '') {
1061 $html = '';
1062 $showitems = 3;
1063 $paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
1064 $paged = $paged ? $paged : 1;
1065 if ($pages == '') {
1066 global $wp_query;
1067 $pages = $wp_query->max_num_pages;
1068 if (!$pages) {
1069 $pages = 1;
1070 }
1071 }
1072 $data = ($paged>=3?[($paged-1),$paged,$paged+1]:[1,2,3]);
1073
1074 $paginationText = explode('|', $paginationText);
1075
1076 $prev_text = isset($paginationText[0]) ? $paginationText[0] : __("Previous", "ultimate-post");
1077 $next_text = isset($paginationText[1]) ? $paginationText[1] : __("Next", "ultimate-post");
1078
1079 if (1 != $pages) {
1080 $html .= '<ul class="ultp-pagination">';
1081 $display_none = 'style="display:none"';
1082 if ($pages > 4) {
1083 $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>';
1084 }
1085 if ($pages > 4) {
1086 $html .= '<li class="ultp-first-pages" '.($paged<2?$display_none:"").' data-current="1"><a href="'.get_pagenum_link(1).'">1</a></li>';
1087 }
1088 if ($pages > 4) {
1089 $html .= '<li class="ultp-first-dot" '.($paged<2? $display_none : "").'><a href="#">...</a></li>';
1090 }
1091 foreach ($data as $i) {
1092 if ($pages >= $i) {
1093 $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>';
1094 }
1095 }
1096 if ($pages > 4) {
1097 $html .= '<li class="ultp-last-dot" '.($pages<=$paged+1?$display_none:"").'><a href="#">...</a></li>';
1098 }
1099 if ($pages > 4) {
1100 $html .= '<li class="ultp-last-pages" '.($pages<=$paged+1?$display_none:"").' data-current="'.$pages.'"><a href="'.get_pagenum_link($pages).'">'.$pages.'</a></li>';
1101 }
1102 if ($paged != $pages) {
1103 $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>';
1104 }
1105 $html .= '</ul>';
1106 }
1107 return $html;
1108 }
1109
1110 /**
1111 * Svg Icon Source
1112 *
1113 * @since v.1.0.0
1114 * @param STRING | String Name
1115 * @return STRING
1116 */
1117 public function svg_icon($ultp_icons = '') {
1118 $ultp_icon_lists = array(
1119 'eye' => file_get_contents(ULTP_PATH.'assets/img/setting/eye.svg'),
1120 'user' => file_get_contents(ULTP_PATH.'assets/img/setting/user.svg'),
1121 'calendar' => file_get_contents(ULTP_PATH.'assets/img/setting/calendar.svg'),
1122 'comment' => file_get_contents(ULTP_PATH.'assets/img/setting/comment.svg'),
1123 'book' => file_get_contents(ULTP_PATH.'assets/img/setting/book.svg'),
1124 'tag' => file_get_contents(ULTP_PATH.'assets/img/setting/tag.svg'),
1125 'clock' => file_get_contents(ULTP_PATH.'assets/img/setting/clock.svg'),
1126 'leftAngle' => file_get_contents(ULTP_PATH.'assets/img/setting/leftAngle.svg'),
1127 'rightAngle' => file_get_contents(ULTP_PATH.'assets/img/setting/rightAngle.svg'),
1128 'leftAngle2' => file_get_contents(ULTP_PATH.'assets/img/setting/leftAngle2.svg'),
1129 'rightAngle2' => file_get_contents(ULTP_PATH.'assets/img/setting/rightAngle2.svg'),
1130 'leftArrowLg' => file_get_contents(ULTP_PATH.'assets/img/setting/leftArrowLg.svg'),
1131 'rightArrowLg' => file_get_contents(ULTP_PATH.'assets/img/setting/rightArrowLg.svg'),
1132 'refresh' => file_get_contents(ULTP_PATH.'assets/img/setting/refresh.svg'),
1133 'upArrow' => file_get_contents(ULTP_PATH.'assets/img/setting/upArrow.svg'),
1134 'downArrow' => file_get_contents(ULTP_PATH.'assets/img/setting/downArrow.svg'),
1135 'arrowUp2' => file_get_contents(ULTP_PATH.'assets/img/setting/arrowUp2.svg'),
1136 'longArrowUp2' => file_get_contents(ULTP_PATH.'assets/img/setting/longArrowUp2.svg'),
1137 'caretArrow' => file_get_contents(ULTP_PATH.'assets/img/setting/caretArrow.svg'),
1138 'left' => file_get_contents(ULTP_PATH.'assets/img/setting/left.svg'),
1139 'center' => file_get_contents(ULTP_PATH.'assets/img/setting/center.svg'),
1140 'right' => file_get_contents(ULTP_PATH.'assets/img/setting/right.svg'),
1141 'justify' => file_get_contents(ULTP_PATH.'assets/img/setting/justify.svg'),
1142 'desktop' => file_get_contents(ULTP_PATH.'assets/img/setting/desktop.svg'),
1143 'laptop' => file_get_contents(ULTP_PATH.'assets/img/setting/laptop.svg'),
1144 'tablet' => file_get_contents(ULTP_PATH.'assets/img/setting/tablet.svg'),
1145 'mobile' => file_get_contents(ULTP_PATH.'assets/img/setting/mobile.svg'),
1146 'dimension' => file_get_contents(ULTP_PATH.'assets/img/setting/dimension.svg'),
1147 'setting' => file_get_contents(ULTP_PATH.'assets/img/setting/setting.svg'),
1148 'plus' => file_get_contents(ULTP_PATH.'assets/img/setting/plus.svg'),
1149 // Builder
1150 'commentCount1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount1.svg'),
1151 'commentCount2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount2.svg'),
1152 'commentCount3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount3.svg'),
1153 'commentCount4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount4.svg'),
1154 'commentCount5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount5.svg'),
1155 'commentCount6' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount6.svg'),
1156 'date1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/date_meta/date1.svg'),
1157 'date2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/date_meta/date2.svg'),
1158 'date3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/date_meta/date3.svg'),
1159 'date4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/date_meta/date4.svg'),
1160 'date5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/date_meta/date5.svg'),
1161 'author1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/author_meta/author1.svg'),
1162 'author2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/author_meta/author2.svg'),
1163 'author3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/author_meta/author3.svg'),
1164 'author4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/author_meta/author4.svg'),
1165 'author5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/author_meta/author5.svg'),
1166 'readingTime1' => file_get_contents(ULTP_PATH.
1167 '/assets/img/blocks/builder/reading_time/readingTime1.svg'),
1168 'readingTime2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/reading_time/readingTime2.svg'),
1169 'readingTime3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/reading_time/readingTime3.svg'),
1170 'readingTime4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/reading_time/readingTime4.svg'),
1171 'readingTime5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/reading_time/readingTime5.svg'),
1172 'viewCount1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount1.svg'),
1173 'viewCount2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount2.svg'),
1174 'viewCount3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount3.svg'),
1175 'viewCount4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount4.svg'),
1176 'viewCount5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount5.svg'),
1177 'viewCount6' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount6.svg'),
1178 'cat1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat1.svg'),
1179 'cat2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat2.svg'),
1180 'cat3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat3.svg'),
1181 'cat4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat4.svg'),
1182 'cat5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat5.svg'),
1183 'cat6' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat6.svg'),
1184 'cat7' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat7.svg'),
1185 'tag1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag1.svg'),
1186 'tag2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag2.svg'),
1187 'tag3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag3.svg'),
1188 'tag4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag4.svg'),
1189 'tag5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag5.svg'),
1190 'tag6' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag6.svg'),
1191 'rightArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/rightArrowLg.svg'),
1192 'share' => file_get_contents(ULTP_PATH.'assets/img/svg/share.svg'),
1193 'facebook' => file_get_contents(ULTP_PATH.'assets/img/svg/facebookIcon.svg'),
1194 'linkedin' => file_get_contents(ULTP_PATH.'assets/img/svg/linkedinIcon.svg'),
1195 'mail' => file_get_contents(ULTP_PATH.'assets/img/svg/mailIcon.svg'),
1196 'messenger' => file_get_contents(ULTP_PATH.'assets/img/svg/messengerIcon.svg'),
1197 'reddit' => file_get_contents(ULTP_PATH.'assets/img/svg/redditIcon.svg'),
1198 'twitter' => file_get_contents(ULTP_PATH.'assets/img/svg/twitterIcon.svg'),
1199 'whatsapp' => file_get_contents(ULTP_PATH.'assets/img/svg/whatsappIcon.svg'),
1200 'pinterest' => file_get_contents(ULTP_PATH.'assets/img/svg/pinIcon.svg'),
1201 'skype' => file_get_contents(ULTP_PATH.'assets/img/svg/skype.svg'),
1202 );
1203 if ($ultp_icons) {
1204 return $ultp_icon_lists[ $ultp_icons ];
1205 }
1206 }
1207
1208
1209 /**
1210 * Get Excerpt Word
1211 *
1212 * @since v.1.0.0
1213 * @param NUMBER | Character Length
1214 * @return STRING
1215 */
1216 public function excerpt_word($charlength = 200) {
1217 $html = '';
1218 $charlength++;
1219 $excerpt = get_the_excerpt();
1220 if (mb_strlen( $excerpt ) > $charlength ) {
1221 $subex = mb_substr( $excerpt, 0, $charlength );
1222 $exwords = explode( ' ', $subex );
1223 $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
1224 if ($excut < 0 ) {
1225 $html = mb_substr( $subex, 0, $excut );
1226 } else {
1227 $html = $subex;
1228 }
1229 $html .= '...';
1230 } else {
1231 $html = $excerpt;
1232 }
1233 return $html;
1234 }
1235
1236
1237 /**
1238 * Get Taxonomy Lists
1239 *
1240 * @since v.1.0.0
1241 * @param STRING | Taxonomy Slug
1242 * @return ARRAY
1243 */
1244 public function taxonomy( $prams = 'category' ) {
1245 $data = array();
1246 $terms = get_terms( $prams, array(
1247 'hide_empty' => false,
1248 ));
1249 if (!is_wp_error($terms)) {
1250 foreach ($terms as $val) {
1251 $data[urldecode_deep($val->slug)] = $val->name;
1252 }
1253 }
1254 return $data;
1255 }
1256
1257
1258 /**
1259 * Get Taxonomy Data Lists
1260 *
1261 * @since v.1.0.0
1262 * @param OBJECT | Taxonomy Object
1263 * @return ARRAY
1264 */
1265 public function get_tax_data($terms) {
1266 $temp = array();
1267 $image = '';
1268 $thumbnail_id = get_term_meta( $terms->term_id, 'ultp_category_image', true );
1269 if ($thumbnail_id) {
1270 $image = wp_get_attachment_url( $thumbnail_id );
1271 }
1272 $temp['url'] = get_term_link($terms);
1273 $temp['name'] = $terms->name;
1274 $temp['desc'] = $terms->description;
1275 $temp['count'] = $terms->count;
1276 $temp['image'] = $image;
1277 $color = get_term_meta($terms->term_id, 'ultp_category_color', true);
1278 $temp['color'] = $color ? $color : '#037fff';
1279 return $temp;
1280 }
1281
1282 public function get_category_data($catSlug, $number = 40, $type = '', $tax_slug = 'category') {
1283 $data = array();
1284 if ($type == 'child') {
1285 $image = '';
1286 if (!empty($catSlug)) {
1287 foreach ($catSlug as $cat) {
1288 $parent_term = get_term_by('slug', $cat, $tax_slug);
1289 if (!empty($parent_term)) {
1290 $term_data = get_terms($tax_slug, array(
1291 'hide_empty' => true,
1292 'parent' => $parent_term->term_id
1293 ));
1294 if (!empty($term_data)) {
1295 foreach ($term_data as $terms) {
1296 $data[] = $this->get_tax_data($terms);
1297 }
1298 }
1299 }
1300 }
1301 }
1302 } else if ($type == 'parent') {
1303 $term_data = get_terms( $tax_slug, array( 'hide_empty' => true, 'number' => $number, 'parent' => 0 ) );
1304 if (!empty($term_data)) {
1305 foreach ($term_data as $terms) {
1306 $data[] = $this->get_tax_data($terms);
1307 }
1308 }
1309 } else if ($type == 'custom') {
1310 foreach ($catSlug as $cat) {
1311 $terms = get_term_by('slug', $cat, $tax_slug);
1312 if (!empty($terms)) {
1313 $data[] = $this->get_tax_data($terms);
1314 }
1315 }
1316 } else {
1317 $term_data = get_terms($tax_slug, array('hide_empty' => true, 'number' => $number));
1318 if (!empty($term_data)) {
1319 foreach ($term_data as $terms) {
1320 $data[] = $this->get_tax_data($terms);
1321 }
1322 }
1323 }
1324 return $data;
1325 }
1326
1327
1328 /**
1329 * Get Next Previous HTML
1330 *
1331 * @since v.1.0.0
1332 * @param OBJECT | Taxonomy Object
1333 * @return STRING
1334 */
1335 public function next_prev() {
1336 $html = '';
1337 $html .= '<ul>';
1338 $html .= '<li>';
1339 $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
1340 $html .= ultimate_post()->svg_icon('leftAngle2').'<span class="screen-reader-text">'.esc_html__("Previous", "ultimate-post").'</span>';
1341 $html .= '</a>';
1342 $html .= '</li>';
1343 $html .= '<li>';
1344 $html .= '<a class="ultp-next-action">';
1345 $html .= ultimate_post()->svg_icon('rightAngle2').'<span class="screen-reader-text">'.esc_html__("Next", "ultimate-post").'</span>';
1346 $html .= '</a>';
1347 $html .= '</li>';
1348 $html .= '</ul>';
1349 return $html;
1350 }
1351
1352
1353 /**
1354 * Get Loading HTML
1355 *
1356 * @since v.1.0.0
1357 * @param NULL
1358 * @return STRING
1359 */
1360 public function loading() {
1361 $html = '';
1362 $style = ultimate_post()->get_setting('preloader_style');
1363 if ($style == 'style2') {
1364 $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
1365 } else {
1366 $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>';
1367 }
1368 return '<div class="ultp-loading">'.$html.'</div>';
1369 }
1370
1371
1372 /**
1373 * Get Filter HTML
1374 *
1375 * @since v.1.0.0
1376 * @param | Filter Text (STRING) | Filter Type (STRING) | Filter Value (ARRAY) | Filter Cat (ARRAY) | Filter Tag (ARRAY) |
1377 * @return STRING
1378 */
1379 public function filter($filterText = '', $filterType = '', $filterValue = '[]', $filterMobileText = '...', $filterMobile = true) {
1380 $html = '';
1381 $html .= '<ul '.($filterMobile ? 'class="ultp-flex-menu"' : '').' data-name="'.($filterMobileText ? $filterMobileText : '&nbsp;').'">';
1382 $cat = $this->taxonomy($filterType);
1383 if ($filterText) {
1384 $html .= '<li class="filter-item"><a class="filter-active" data-taxonomy="" href="#">'.$filterText.'</a></li>';
1385 }
1386
1387 if ($filterValue) {
1388 $filterValue = strlen($filterValue) > 2 ? $filterValue : [];
1389 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
1390 if (is_array($filterValue) && count($filterValue)) {
1391 foreach ($filterValue as $val) {
1392 $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($cat[$val]) ? $cat[$val] : $val).'</a></li>';
1393 }
1394 }
1395 }
1396 $html .= '</ul>';
1397 return $html;
1398 }
1399
1400
1401 /**
1402 * Check License Status
1403 *
1404 * @since v.2.4.2
1405 * @return BOOLEAN | Is pro license active or not
1406 */
1407 public function is_lc_active() {
1408 if (function_exists('ultimate_post_pro')) {
1409 return get_option('edd_ultp_license_status') == 'valid' ? true : false;
1410 }
1411 if (get_transient( 'ulpt_theme_enable' ) == 'integration') {
1412 return true;
1413 }
1414 return false;
1415 }
1416
1417
1418 /**
1419 * Get SEO Meta
1420 *
1421 * @since v.2.4.3
1422 * @param NUMBER | Post ID
1423 * @return STRING | SEO Meta Description or Excerpt
1424 */
1425 public function get_excerpt($post_id = 0, $showSeoMeta = 0, $showFullExcerpt = 0, $excerptLimit = 55) {
1426 $html = '';
1427 if ($showSeoMeta) {
1428 $str = '';
1429 if (function_exists('ultimate_post_pro') ) {
1430 if (ultimate_post()->get_setting('ultp_yoast') == 'true') {
1431 $str = method_exists( ultimate_post_pro(), 'get_yoast_meta' ) ? ultimate_post_pro()->get_yoast_meta($post_id) : '';
1432 } else if (ultimate_post()->get_setting('ultp_rankmath') == 'true') {
1433 $str = method_exists( ultimate_post_pro(), 'get_rankmath_meta' ) ? ultimate_post_pro()->get_rankmath_meta($post_id) : '';
1434 } else if (ultimate_post()->get_setting('ultp_aioseo') == 'true') {
1435 $str = method_exists( ultimate_post_pro(), 'get_aioseo_meta' ) ? ultimate_post_pro()->get_aioseo_meta($post_id) : '';
1436 } else if (ultimate_post()->get_setting('ultp_seopress') == 'true') {
1437 $str = method_exists( ultimate_post_pro(), 'get_seopress_meta' ) ? ultimate_post_pro()->get_seopress_meta($post_id) : '';
1438 } else if (ultimate_post()->get_setting('ultp_squirrly') == 'true') {
1439 $str = method_exists( ultimate_post_pro(), 'get_squirrly_meta' ) ? ultimate_post_pro()->get_squirrly_meta($post_id) : '';
1440 }
1441 }
1442 $html = $str ? $str : ultimate_post()->excerpt($post_id, $excerptLimit);
1443 } else {
1444 if ($showFullExcerpt == 0 ) {
1445 $html = ultimate_post()->excerpt($post_id, $excerptLimit);
1446 } else {
1447 $html = get_the_excerpt();
1448 }
1449 }
1450 return $html;
1451 }
1452
1453 /**
1454 * Set Inline CSS
1455 *
1456 * @since v.2.5.8
1457 * @param STRING | CSS
1458 * @return STRING | CSS with Style
1459 */
1460 public function set_inline($css) {
1461 return '<style type="text/css">'.wp_strip_all_tags($css).'</style>';
1462 }
1463
1464 /**
1465 * Array Sanitize Function
1466 *
1467 * @since v.2.6.0
1468 * @param ARRAY
1469 * @return ARRAY | Array of Sanitize
1470 */
1471 public function recursive_sanitize_text_field($array) {
1472 foreach ($array as $key => &$value) {
1473 if (is_array($value)) {
1474 $value = $this->recursive_sanitize_text_field($value);
1475 } else {
1476 $value = sanitize_text_field($value);
1477 }
1478 }
1479 return $array;
1480 }
1481
1482
1483 public function get_embeded_video($url, $autoPlay, $loop, $mute, $playback, $preload, $poster, $inline, $size) {
1484 $vidAutoPlay = $vidloop = $vidloop = $vidmute = $vidplayback = $vidPoster = $vidInline = "";
1485
1486 if($autoPlay){
1487 $vidAutoPlay = "autoplay";
1488 }
1489 if($poster){
1490 $vidPoster = 'poster="'.$poster["url"].'"';
1491 }
1492 if($loop){
1493 $vidloop = "loop";
1494 }
1495 if($mute){
1496 $vidmute = "muted";
1497 }
1498 if($playback){
1499 $vidplayback = "controls";
1500 }
1501 if($inline){
1502 $vidInline = "playsinline";
1503 }
1504 if (!empty($url)) {
1505 $embeded = wp_oembed_get($url, $size);
1506 if ($embeded == false) {
1507 $format = '';
1508 $url = strtolower($url);
1509 if (strpos($url, '.mp4')) {
1510 $format = 'mp4';
1511 } elseif (strpos($url, '.ogg')) {
1512 $format = 'ogg';
1513 } elseif (strpos($url, '.webm')) {
1514 $format = 'WebM';
1515 }
1516 $embeded = '<video
1517 '.$vidloop.'
1518 '.$vidmute.'
1519 '.$vidplayback.'
1520 preload="'.$preload.'"
1521 '.$vidAutoPlay.'
1522 '.$vidPoster.'
1523 '.$vidInline.'
1524 ><source src="' . $url . '" type="video/' . $format . '">' . __('Your browser does not support the video tag.', 'ultimate-post') . '</video>';
1525 return '<div class="ultp-video-wrapper">'.$embeded.'</div>';
1526 }
1527 return '<div class="ultp-video-wrapper ultp-embaded-video">'.$embeded.'</div>';
1528 } else {
1529 return false;
1530 }
1531 }
1532
1533 /**
1534 * Get Public taxonomy Lists
1535 *
1536 * @since v.2.7.0
1537 * @param NULL
1538 * @return ARRAY | Taxonomy Lists as array
1539 */
1540 public function get_taxonomy_list() {
1541 $taxonomy = get_taxonomies(array('public' => true));
1542 return empty($taxonomy) ? [] : array_keys($taxonomy);
1543 }
1544
1545 /**
1546 * Content Print
1547 *
1548 * @since v.2.7.0
1549 * @param NUMBER | Post ID
1550 * @return STRING | Content of the Post
1551 */
1552 public function content($post_id) {
1553 $content_post = get_post($post_id);
1554 $content = $content_post->post_content;
1555 $content = apply_filters('the_content', $content);
1556 $content = str_replace(']]>', ']]&gt;', $content);
1557 echo $content;
1558 }
1559
1560
1561 /**
1562 * String Part finder inside array
1563 *
1564 * @since v.2.7.0
1565 * @return ARRAY | String Part
1566 */
1567 public function in_string_part($part, $data, $isValue = false) {
1568 $return = false;
1569 foreach ($data as $val) {
1570 if (strpos($val, $part) !== false) {
1571 $return = $isValue ? $val : true;
1572 break;
1573 }
1574 }
1575 return $return;
1576 }
1577
1578 /**
1579 * Builder Conditions
1580 *
1581 * @since v.2.7.0
1582 * @param STRING | Type of Return
1583 * @return MIXED || ID or Path
1584 */
1585 public function conditions( $type = 'return' ) {
1586 $page_id = '';
1587
1588 $conditions = get_option('ultp_builder_conditions', array());
1589 if (isset($conditions['archive'])) {
1590 if (!empty($conditions['archive'])) {
1591 $taxonomy = (is_category() || is_tag() || is_tax()) ? get_queried_object() : (object)[];
1592 foreach ($conditions['archive'] as $key => $val) {
1593 if (is_archive()) {
1594 if (in_array('include/archive', $val)) {
1595 if ('publish' == get_post_status($key)) {
1596 $page_id = $key;
1597 }
1598 }
1599 if (in_array('exclude/archive', $val)) {
1600 if ('publish' == get_post_status($key)) {
1601 $page_id = '';
1602 }
1603 }
1604 if (is_category()) {
1605 if (in_array('include/archive/category', $val)) {
1606 if ('publish' == get_post_status($key)) {
1607 $page_id = $key;
1608 }
1609 }
1610 if (in_array('exclude/archive/category', $val)) {
1611 if ('publish' == get_post_status($key)) {
1612 $page_id = '';
1613 }
1614 }
1615 if (in_array('include/archive/category/'.$taxonomy->term_id, $val)) {
1616 if ('publish' == get_post_status($key)) {
1617 $page_id = $key;
1618 }
1619 }
1620 if (in_array('exclude/archive/category/'.$taxonomy->term_id, $val)) {
1621 if ('publish' == get_post_status($key)) {
1622 $page_id = '';
1623 }
1624 }
1625 if ($this->in_string_part('any_child_of', $val)) {
1626 if (in_array('include/archive/any_child_of_category', $val)) {
1627 if ('publish' == get_post_status($key)) {
1628 $page_id = $key;
1629 }
1630 }
1631 if (in_array('exclude/archive/any_child_of_category', $val)) {
1632 if ('publish' == get_post_status($key)) {
1633 $page_id = '';
1634 }
1635 }
1636 $data = $this->in_string_part('/archive/any_child_of_category/', $val, true);
1637 if ($data) {
1638 $data = explode("/",$data);
1639 if (isset($data[3]) && $data[3]) {
1640 if (term_is_ancestor_of($data[3], $taxonomy->term_id, 'category')) {
1641 if ('publish' == get_post_status($key)) {
1642 $page_id = $data[0] == 'exclude' ? '' : $key;
1643 }
1644 }
1645 }
1646 }
1647 } else {
1648 if ($this->in_string_part('child_of', $val)) {
1649 if (in_array('include/archive/child_of_category', $val)) {
1650 if ('publish' == get_post_status($key)) {
1651 $page_id = $key;
1652 }
1653 }
1654 if (in_array('exclude/archive/child_of_category', $val)) {
1655 if ('publish' == get_post_status($key)) {
1656 $page_id = '';
1657 }
1658 }
1659 if (in_array('include/archive/child_of_category/'.$taxonomy->parent, $val)) {
1660 if ('publish' == get_post_status($key)) {
1661 $page_id = $key;
1662 }
1663 }
1664 if (in_array('exclude/archive/child_of_category/'.$taxonomy->parent, $val)) {
1665 if ('publish' == get_post_status($key)) {
1666 $page_id = '';
1667 }
1668 }
1669 }
1670 }
1671 } else if (is_tag()) {
1672 if (in_array('include/archive/post_tag', $val)) {
1673 if ('publish' == get_post_status($key)) {
1674 $page_id = $key;
1675 }
1676 }
1677 if (in_array('exclude/archive/post_tag', $val)) {
1678 if ('publish' == get_post_status($key)) {
1679 $page_id = '';
1680 }
1681 }
1682 if (in_array('include/archive/post_tag/'.$taxonomy->term_id, $val)) {
1683 if ('publish' == get_post_status($key)) {
1684 $page_id = $key;
1685 }
1686 }
1687 if (in_array('exclude/archive/post_tag/'.$taxonomy->term_id, $val)) {
1688 if ('publish' == get_post_status($key)) {
1689 $page_id = '';
1690 }
1691 }
1692 } else if (is_tax()) {
1693 if (in_array('include/archive/'.$taxonomy->taxonomy, $val)) {
1694 if ('publish' == get_post_status($key)) {
1695 $page_id = $key;
1696 }
1697 }
1698 if (in_array('exclude/archive/'.$taxonomy->taxonomy, $val)) {
1699 if ('publish' == get_post_status($key)) {
1700 $page_id = '';
1701 }
1702 }
1703 if (in_array('include/archive/'.$taxonomy->taxonomy.'/'.$taxonomy->term_id, $val)) {
1704 if ('publish' == get_post_status($key)) {
1705 $page_id = $key;
1706 }
1707 }
1708 if (in_array('exclude/archive/'.$taxonomy->taxonomy.'/'.$taxonomy->term_id, $val)) {
1709 if ('publish' == get_post_status($key)) {
1710 $page_id = '';
1711 }
1712 }
1713 if ($this->in_string_part('any_child_of', $val)) {
1714 if (in_array('include/archive/any_child_of_'.$taxonomy->taxonomy, $val)) {
1715 if ('publish' == get_post_status($key)) {
1716 $page_id = $key;
1717 }
1718 }
1719 if (in_array('exclude/archive/any_child_of_'.$taxonomy->taxonomy, $val)) {
1720 if ('publish' == get_post_status($key)) {
1721 $page_id = '';
1722 }
1723 }
1724 $data = $this->in_string_part('/archive/any_child_of_'.$taxonomy->taxonomy.'/', $val, true);
1725 if ($data) {
1726 $data = explode("/",$data);
1727 if (isset($data[3]) && $data[3]) {
1728 if (term_is_ancestor_of($data[3], $taxonomy->term_id, $taxonomy->taxonomy)) {
1729 if ('publish' == get_post_status($key)) {
1730 $page_id = $data[0] == 'exclude' ? '' : $key;
1731 }
1732 }
1733 }
1734 }
1735 } else {
1736 if ($this->in_string_part('child_of', $val)) {
1737 if (in_array('include/archive/child_of_'.$taxonomy->taxonomy, $val)) {
1738 if ('publish' == get_post_status($key)) {
1739 $page_id = $key;
1740 }
1741 }
1742 if (in_array('exclude/archive/child_of_'.$taxonomy->taxonomy, $val)) {
1743 if ('publish' == get_post_status($key)) {
1744 $page_id = '';
1745 }
1746 }
1747 if (in_array('include/archive/child_of_'.$taxonomy->taxonomy.'/'.$taxonomy->parent, $val)) {
1748 if ('publish' == get_post_status($key)) {
1749 $page_id = $key;
1750 }
1751 }
1752 if (in_array('exclude/archive/child_of_'.$taxonomy->taxonomy.'/'.$taxonomy->parent, $val)) {
1753 if ('publish' == get_post_status($key)) {
1754 $page_id = '';
1755 }
1756 }
1757 }
1758 }
1759 } else if (is_date()) {
1760 if (in_array('include/archive/date', $val)) {
1761 if ('publish' == get_post_status($key)) {
1762 $page_id = $key;
1763 }
1764 }
1765 if (in_array('exclude/archive/date', $val)) {
1766 if ('publish' == get_post_status($key)) {
1767 $page_id = '';
1768 }
1769 }
1770 } else if (is_author()) {
1771 if (in_array('include/archive/author', $val)) {
1772 if ('publish' == get_post_status($key)) {
1773 $page_id = $key;
1774 }
1775 }
1776 if (in_array('exclude/archive/author', $val)) {
1777 if ('publish' == get_post_status($key)) {
1778 $page_id = '';
1779 }
1780 }
1781 $author_id = get_the_author_meta('ID');
1782 if (in_array('include/archive/author/'.$author_id, $val)) {
1783 if ('publish' == get_post_status($key)) {
1784 $page_id = $key;
1785 }
1786 }
1787 if (in_array('exclude/archive/author/'.$author_id, $val)) {
1788 if ('publish' == get_post_status($key)) {
1789 $page_id = '';
1790 }
1791 }
1792 }
1793 } else if (is_search()) {
1794 if (in_array('include/archive/search', $val)) {
1795 if ('publish' == get_post_status($key)) {
1796 $page_id = $key;
1797 }
1798 }
1799 if (in_array('exclude/archive/search', $val)) {
1800 if ('publish' == get_post_status($key)) {
1801 $page_id = '';
1802 }
1803 }
1804 }
1805 }
1806 }
1807 }
1808 // Singular
1809 if (isset($conditions['singular'])) {
1810 if (!empty($conditions['singular'])) {
1811 $obj = get_queried_object();
1812 $tax_list = $this->get_taxonomy_list();
1813 foreach ($conditions['singular'] as $key => $val) {
1814 if (is_singular()) {
1815 // Front Page
1816 if (is_front_page()) {
1817 if (in_array('include/singular/front_page', $val)) {
1818 if ('publish' == get_post_status($key)) {
1819 $page_id = $key;
1820 }
1821 }
1822 if (in_array('exclude/singular/front_page', $val)) {
1823 if ('publish' == get_post_status($key)) {
1824 $page_id = '';
1825 }
1826 }
1827 }
1828 // Author check
1829 if (in_array('singular/post_by_author', $val)) {
1830 $author_id = get_the_author_meta('ID');
1831 if (in_array('include/singular/post_by_author', $val)) {
1832 if ('publish' == get_post_status($key)) {
1833 $page_id = $key;
1834 }
1835 }
1836 if (in_array('exclude/singular/post_by_author', $val)) {
1837 if ('publish' == get_post_status($key)) {
1838 $page_id = '';
1839 }
1840 }
1841 if (in_array('include/singular/post_by_author/'.$obj->post_author, $val)) {
1842 if ('publish' == get_post_status($key)) {
1843 $page_id = $key;
1844 }
1845 }
1846 if (in_array('exclude/singular/post_by_author/'.$obj->post_author, $val)) {
1847 if ('publish' == get_post_status($key)) {
1848 $page_id = '';
1849 }
1850 }
1851 }
1852 // All Taxonomy
1853 if($this->in_string_part('/singular/in_', $val)) {
1854 foreach ($tax_list as $tax) {
1855 if ($this->in_string_part('singular/in_'.$tax.'_children', $val)) {
1856 // In Taxonomy Children
1857 if (in_array('include/singular/in_'.$tax.'_children', $val)) {
1858 if ('publish' == get_post_status($key)) {
1859 $page_id = $key;
1860 }
1861 }
1862 if (in_array('exclude/singular/in_'.$tax.'_children', $val)) {
1863 if ('publish' == get_post_status($key)) {
1864 $page_id = '';
1865 }
1866 }
1867 $data = $this->in_string_part('/singular/in_'.$tax.'_children/', $val, true);
1868 if ($data) {
1869 $data = explode("/", $data);
1870 if (isset($data[3]) && $data[3]) {
1871 if (is_object_in_term($obj->ID , $tax, $data[3] )) {
1872 if ('publish' == get_post_status($key)) {
1873 $page_id = $data[0] == 'exclude' ? '' : $key;
1874 }
1875 }
1876 }
1877 }
1878 } else {
1879 // IN Taxonomy
1880 if (in_array('include/singular/in_'.$tax, $val)) {
1881 if ('publish' == get_post_status($key)) {
1882 $page_id = $key;
1883 }
1884 }
1885 if (in_array('exclude/singular/in_'.$tax, $val)) {
1886 if ('publish' == get_post_status($key)) {
1887 $page_id = '';
1888 }
1889 }
1890 $data = $this->in_string_part('/singular/in_'.$tax.'/', $val, true);
1891 if ($data) {
1892 $data = explode("/",$data);
1893 if (isset($data[3]) && $data[3]) {
1894 if (is_object_in_term($obj->ID , $tax, $data[3] )) {
1895 if ('publish' == get_post_status($key)) {
1896 $page_id = $data[0] == 'exclude' ? '' : $key;
1897 }
1898 }
1899 }
1900 }
1901 }
1902 }
1903 }
1904 // All Post Type
1905 if (in_array('include/singular/'.$obj->post_type, $val)) {
1906 if ('publish' == get_post_status($key)) {
1907 $page_id = $key;
1908 }
1909 }
1910 if (in_array('exclude/singular/'.$obj->post_type, $val)) {
1911 if ('publish' == get_post_status($key)) {
1912 $page_id = '';
1913 }
1914 }
1915 if ($this->in_string_part('include/singular/'.$obj->post_type.'/'.$obj->ID, $val)) {
1916 if ('publish' == get_post_status($key)) {
1917 $page_id = $key;
1918 }
1919 }
1920 if ($this->in_string_part('exclude/singular/'.$obj->post_type.'/'.$obj->ID, $val)) {
1921 if ('publish' == get_post_status($key)) {
1922 $page_id = '';
1923 }
1924 }
1925 }
1926 }
1927 }
1928 }
1929
1930 if ($type == 'return') {
1931 return $page_id;
1932 }
1933 if ($type == 'includes') {
1934 return $page_id ? ULTP_PATH.'addons/builder/Archive_Template.php' : '';
1935 }
1936 }
1937
1938
1939 /**
1940 * Get Add Default Condition Data
1941 *
1942 * @since v.2.7.0
1943 * @return ARRAY | Default Data
1944 */
1945 public function builder_data() {
1946 $archive_data = [
1947 [
1948 'label' => 'All Archive',
1949 'value' => '',
1950 ],
1951 [
1952 'label' => 'Author Archive',
1953 'value' => 'author',
1954 'search' => 'author###'
1955 ],
1956 [
1957 'label' => 'Date Archive',
1958 'value' => 'date',
1959 ],
1960 [
1961 'label' => 'Search Results',
1962 'value' => 'search',
1963 ],
1964 ];
1965 $single_data = [
1966 [
1967 'label' => 'Front Page',
1968 'value' => 'front_page',
1969 ]
1970 ];
1971
1972 $post_type = get_post_types( ['public' => true], 'objects' );
1973 foreach ($post_type as $key => $type) {
1974 // Post Type
1975 $single_temp = [
1976 'label' => $type->label,
1977 'value' => $type->name,
1978 'search' => 'type###'.$type->name
1979 ];
1980 $archive_temp = [];
1981
1982 // Taxonomy
1983 $taxonomy = get_object_taxonomies( $type->name, 'objects' );
1984 if (!empty($taxonomy)) {
1985 $single_tax = $archive_tax = [];
1986 $single_tax[] = $single_temp;
1987
1988 $archive_temp = [
1989 'label' => $type->label . ' Archive',
1990 'value' => $type->name . '_archive',
1991 ];
1992 // $archive_tax[] = $archive_temp;
1993 foreach ($taxonomy as $key => $val) {
1994 if ($val->public) {
1995 $single_tax[] = [
1996 'label' => 'In ' . $val->label,
1997 'value' => 'in_' . $val->name,
1998 'search' => 'term###'.$val->name
1999 ];
2000 $archive_tax[] = [
2001 'label' => $val->label,
2002 'value' => $val->name,
2003 'search' => 'term###'.$val->name
2004 ];
2005
2006 if ($val->hierarchical) {
2007 // Hierarchical
2008 $single_tax[] = [
2009 'label' => 'In Child ' . $val->label,
2010 'value' => 'in_' . $val->name . '_children',
2011 'search' => 'term###'.$val->name
2012 ];
2013 $archive_tax[] = [
2014 'label' => 'Direct Child ' . $val->label . ' Of',
2015 'value' => 'child_of_' . $val->name,
2016 'search' => 'term###'.$val->name
2017 ];
2018 $archive_tax[] = [
2019 'label' => 'Any Child ' . $val->label . ' Of',
2020 'value' => 'any_child_of_' . $val->name,
2021 'search' => 'term###'.$val->name
2022 ];
2023 }
2024 }
2025 }
2026 // Author
2027 $single_tax[] = [
2028 'label' => 'Posts By Author',
2029 'value' => 'post_by_author',
2030 'search' => 'author###'
2031 ];
2032 $single_temp['attr'] = $single_tax;
2033 $archive_temp['attr'] = $archive_tax;
2034 }
2035 $single_data[] = $single_temp;
2036 if (!empty($archive_temp)) {
2037 $archive_data[] = $archive_temp;
2038 }
2039 }
2040
2041 return ['singular' => $single_data, 'archive' => $archive_data];
2042 }
2043
2044 /**
2045 * Get Date Default Format
2046 *
2047 * @since v.2.7.2
2048 * @return ARRAY | Default Data
2049 */
2050 public function get_format($format) {
2051 if ($format == 'default_date') {
2052 return $this->get_setting('date_format');
2053 } else if ($format == 'default_date_time') {
2054 return $this->get_setting('date_format').' '.$this->get_setting('time_format');
2055 } else {
2056 return $format;
2057 }
2058 }
2059
2060 public function pro_popup_html() { ?>
2061 <div class="ultp-popup-container popup-center">
2062 <div class="ultp-unlock-popup ultp-unlock-modal">
2063 <img src="<?php echo esc_url(ULTP_URL . '/assets/img/admin/dashboard/unlock-super-icon.svg'); ?>" alt="lock icon">
2064 <h4 class="ultp-md-heading ultp-mt25 ultp-mb25"><?php esc_html_e('Unlock 11+ Addons', 'ultimate-post'); ?></h4>
2065 <div class="ultp-popup-desc">
2066 <?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'); ?>
2067 </div>
2068 <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>
2069 <button class="ultp-popup-close"></button>
2070 </div>
2071 </div>
2072 <?php }
2073
2074 /**
2075 * Common Frontend and Backend CSS and JS Scripts
2076 *
2077 * @since v.1.0.0
2078 * @return NULL
2079 */
2080 public function register_scripts_common() {
2081 wp_enqueue_style('ultp-style', ULTP_URL.'assets/css/style.min.css', array(), ULTP_VER );
2082 wp_enqueue_script('ultp-script', ULTP_URL.'assets/js/ultp.min.js', array('jquery'), ULTP_VER, true);
2083 wp_localize_script('ultp-script', 'ultp_data_frontend', array(
2084 'url' => ULTP_URL,
2085 'ajax' => admin_url('admin-ajax.php'),
2086 'security' => wp_create_nonce('ultp-nonce')
2087 ));
2088 }
2089
2090 }
2091