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

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