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

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