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

2,805 lines 125.5 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 * Checking Archive Child Builder
54 *
55 * @since v.2.8.6
56 * @return STRING | archive child builder
57 */
58 public function is_archive_child_builder() {
59 $id = get_the_ID();
60 $builder_type = get_post_type( $id ) == 'ultp_builder' ? get_post_meta( $id, '__ultp_builder_type', true ) : false;
61 if($builder_type) {
62 $settings = get_option('ultp_builder_conditions', array());
63 $conditons = $settings[$builder_type][$id];
64 $conditions_length = sizeof($conditons) > 1 ? 'multiple' : 'single';
65 foreach ($conditons as $conditon) {
66 if(strpos($conditon,'singular/front_page') > -1) {
67 return $conditions_length.'#singular/front_page';
68 }
69 }
70 }
71 return '';
72 }
73
74
75 /**
76 * Set Link with the Parameters
77 *
78 * @since v.1.1.0
79 * @return STRING | URL with Arg
80 */
81 public function get_premium_link( $url = '', $tag = 'go_premium') {
82 $url_list = array(
83 // PostX Dashboard Menu
84 'menu_started_details' => array(
85 'utm_source' => 'postx-menu',
86 'utm_medium' => 'started-plugin_details',
87 'utm_campaign' => 'postx-dashboard'
88 ),
89 'menu_started_template_library' => array(
90 'utm_source' => 'postx-menu',
91 'utm_medium' => 'started-library',
92 'utm_campaign' => 'postx-dashboard'
93 ),
94 'menu_started_more_features' => array(
95 'utm_source' => 'postx-menu',
96 'utm_medium' => 'started-more_features',
97 'utm_campaign' => 'postx-dashboard'
98 ),
99 'menu_started_explore' => array(
100 'utm_source' => 'postx-menu',
101 'utm_medium' => 'started-explore_more',
102 'utm_campaign' => 'postx-dashboard'
103 ),
104 'menu_started_changelog' => array(
105 'utm_source' => 'postx-menu',
106 'utm_medium' => 'started-changelog',
107 'utm_campaign' => 'postx-dashboard'
108 ),
109 'menu_started_upgrade_pro' => array(
110 'utm_source' => 'postx-menu',
111 'utm_medium' => 'started-upgrade_pro' ,
112 'utm_campaign' => 'postx-dashboard'
113 ),
114 'menu_tutorial_upgrade' => array(
115 'utm_source' => 'postx-menu',
116 'utm_medium' => 'tutorials-upgrade_pro',
117 'utm_campaign' => 'postx-dashboard'
118 ),
119 'menu_settings_upgrade-pro' => array(
120 'utm_source' => 'postx-menu',
121 'utm_medium' => 'settings-upgrade_pro',
122 'utm_campaign' => 'postx-dashboard'
123 ),
124 'menu_topbar' => array(
125 'utm_source' => 'postx-menu',
126 'utm_medium' => 'topbar',
127 'utm_campaign' => 'postx-dashboard'
128 ),
129 'menu_addons_popup' => array(
130 'utm_source' => 'postx-menu',
131 'utm_medium' => 'addons-upgrade_plan_popup',
132 'utm_campaign' => 'postx-dashboard'
133 ),
134 'menu_save_temp_pro' => array(
135 'utm_source' => 'postx-menu',
136 'utm_medium' => 'ST-go_pro',
137 'utm_campaign' => 'postx-dashboard'
138 ),
139 // PostX Dashboard
140 'dashboard_go_pro' => array(
141 'utm_source' => 'postx-main_menu',
142 'utm_medium' => 'go_pro',
143 'utm_campaign' => 'postx-dashboard'
144 ),
145 'dashboard_db_banner' => array(
146 'utm_source' => 'postx-ad',
147 'utm_medium' => 'DB-banner',
148 'utm_campaign' => 'postx-dashboard'
149 ),
150 // Plugin Directory
151 'plugin_dir_pro' => array(
152 'utm_source' => 'postx_plugin',
153 'utm_medium' => 'go_pro',
154 'utm_campaign' => 'postx-dashboard'
155 ),
156 'plugin_dir_home' => array(
157 'utm_source' => 'postx_plugin',
158 'utm_medium' => 'wpxpo',
159 'utm_campaign' => 'postx-dashboard'
160 ),
161 'plugin_dir_support' => array(
162 'utm_source' => 'postx_plugin',
163 'utm_medium' => 'support',
164 'utm_campaign' => 'postx-dashboard'
165 ),
166 'plugin_dir_postx' => array(
167 'utm_source' => 'postx_plugin',
168 'utm_medium' => 'postx',
169 'utm_campaign' => 'postx-dashboard'
170 ),
171 );
172
173 $url = $url ? $url : 'https://www.wpxpo.com/postx/pricing/';
174 $affiliate_id = apply_filters( 'ultp_affiliate_id', FALSE );
175 $arg = array();
176 if($tag && isset($url_list[$tag])){
177 $arg = $url_list[$tag];
178 } else {
179 $arg = array( 'utm_source' => $tag );
180 }
181 if ( ! empty( $affiliate_id ) ) {
182 $arg[ 'ref' ] = esc_attr( $affiliate_id );
183 }
184 return add_query_arg( $arg, $url );
185 }
186
187
188 /**
189 * Get Width and Height of the Image
190 *
191 * @since v.1.1.0
192 * @return STRING | Image Size
193 */
194 public function get_size($name = '') {
195 global $_wp_additional_image_sizes;
196 $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];
197
198 return ' width="'.$image_size['width'].'" height="'.$image_size['height'].'" ';
199 }
200
201
202 /**
203 * Image Placeholder
204 *
205 * @since v.1.1.0
206 * @return STRING | Image Placeholder
207 */
208 public function img_placeholder($type = 'small') {
209 switch ($type) {
210 case 'small':
211 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG4AAABLAQMAAACr9CA9AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABZJREFUOI1jYMADmEe5o9xR7iiXQi4A4BsA388WUyMAAAAASUVORK5CYII=';
212 break;
213
214 case 'wide':
215 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAKCAYAAADVTVykAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAB9JREFUeNpi/P//P8NAAiaGAQajDhh1wKgDRh0AEGAAQTcDEcKDrpMAAAAASUVORK5CYII=';
216 break;
217
218 case 'square':
219 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAApJREFUCJljYAAAAAIAAfRxZKYAAAAASUVORK5CYII=';
220 break;
221
222 case 'slider':
223 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKYAAABkCAMAAAA7drv6AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF////AAAAVcLTfgAAAAF0Uk5TAEDm2GYAAAAqSURBVHja7MEBDQAAAMKg909tDjegAAAAAAAAAAAAAAAAAAAAAH5NgAEAQTwAAWZtItYAAAAASUVORK5CYII=';
224 break;
225
226 default:
227 return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYYAAADcAQMAAABOLJSDAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAACJJREFUaIHtwTEBAAAAwqD1T20ND6AAAAAAAAAAAAAA4N8AKvgAAUFIrrEAAAAASUVORK5CYII=';
228 break;
229 }
230 }
231
232
233 /**
234 * Quick Query
235 *
236 * @since v.1.1.0
237 * @return ARRAY | Query Arg
238 */
239 public function get_quick_query($prams, $args) {
240 switch ($prams['queryQuick']) {
241 case 'related_posts':
242 global $post;
243 $p_id = isset($post->ID) && $post->ID ? $post->ID : (isset($_POST['postId']) ? $_POST['postId'] : '');
244 if ($p_id) {
245 $args['post__not_in'] = array($p_id);
246 }
247 break;
248 case 'related_tag':
249 global $post;
250 $p_id = isset($post->ID) && $post->ID ? $post->ID : (isset($_POST['postId']) ? $_POST['postId'] : '');
251 if ($p_id) {
252 $args['tax_query'] = array(
253 array(
254 'taxonomy' => 'post_tag',
255 'terms' => $this->get_terms_id($p_id, 'post_tag'),
256 'field' => 'term_id',
257 )
258 );
259 $args['post__not_in'] = array($p_id);
260 }
261 break;
262 case 'related_category':
263 global $post;
264 $p_id = isset($post->ID) && $post->ID ? $post->ID : (isset($_POST['postId']) ? $_POST['postId'] : '');
265 if ($p_id) {
266 $args['tax_query'] = array(
267 array(
268 'taxonomy' => 'category',
269 'terms' => $this->get_terms_id($p_id, 'category'),
270 'field' => 'term_id',
271 )
272 );
273 $args['post__not_in'] = array($p_id);
274 }
275 break;
276 case 'related_cat_tag':
277 global $post;
278 $p_id = isset($post->ID) && $post->ID ? $post->ID : (isset($_POST['postId']) ? $_POST['postId'] : '');
279 if ($p_id) {
280 $args['tax_query'] = array(
281 array(
282 'taxonomy' => 'post_tag',
283 'terms' => $this->get_terms_id($p_id, 'post_tag'),
284 'field' => 'term_id',
285 ),
286 array(
287 'taxonomy' => 'category',
288 'terms' => $this->get_terms_id($p_id, 'category'),
289 'field' => 'term_id',
290 )
291 );
292 $args['post__not_in'] = array($p_id);
293 }
294 break;
295 case 'sticky_posts':
296 $sticky = get_option('sticky_posts');
297 if (is_array($sticky)) {
298 rsort($sticky);
299 $sticky = array_slice($sticky, 0, $args['posts_per_page']);
300 }
301 $args['ignore_sticky_posts'] = 1;
302 $args['post__in'] = $sticky;
303 break;
304 case 'latest_post_published':
305 $args['orderby'] = 'date';
306 $args['order'] = 'DESC';
307 $args['ignore_sticky_posts'] = 1;
308 break;
309 case 'latest_post_modified':
310 $args['orderby'] = 'modified';
311 $args['order'] = 'DESC';
312 $args['ignore_sticky_posts'] = 1;
313 break;
314 case 'oldest_post_published':
315 $args['orderby'] = 'date';
316 $args['order'] = 'ASC';
317 break;
318 case 'oldest_post_modified':
319 $args['orderby'] = 'modified';
320 $args['order'] = 'ASC';
321 break;
322 case 'alphabet_asc':
323 $args['orderby'] = 'title';
324 $args['order'] = 'ASC';
325 break;
326 case 'alphabet_desc':
327 $args['orderby'] = 'title';
328 $args['order'] = 'DESC';
329 break;
330 case 'random_post':
331 $args['orderby'] = 'rand';
332 $args['order'] = 'ASC';
333 break;
334 case 'random_post_7_days':
335 $args['orderby'] = 'rand';
336 $args['order'] = 'ASC';
337 $args['date_query'] = array( array( 'after' => '1 week ago') );
338 break;
339 case 'random_post_30_days':
340 $args['orderby'] = 'rand';
341 $args['order'] = 'ASC';
342 $args['date_query'] = array( array( 'after' => '1 month ago') );
343 break;
344 case 'most_comment':
345 $args['orderby'] = 'comment_count';
346 $args['order'] = 'DESC';
347 break;
348 case 'most_comment_1_day':
349 $args['orderby'] = 'comment_count';
350 $args['order'] = 'DESC';
351 $args['date_query'] = array( array( 'after' => '1 day ago') );
352 break;
353 case 'most_comment_7_days':
354 $args['orderby'] = 'comment_count';
355 $args['order'] = 'DESC';
356 $args['date_query'] = array( array( 'after' => '1 week ago') );
357 break;
358 case 'most_comment_30_days':
359 $args['orderby'] = 'comment_count';
360 $args['order'] = 'DESC';
361 $args['date_query'] = array( array( 'after' => '1 month ago') );
362 break;
363 case 'popular_post_1_day_view':
364 $args['meta_key'] = '__post_views_count';
365 $args['orderby'] = 'meta_value_num';
366 $args['order'] = 'DESC';
367 $args['date_query'] = array( array( 'after' => '1 day ago') );
368 break;
369 case 'popular_post_7_days_view':
370 $args['meta_key'] = '__post_views_count';
371 $args['orderby'] = 'meta_value_num';
372 $args['order'] = 'DESC';
373 $args['date_query'] = array( array( 'after' => '1 week ago') );
374 break;
375 case 'popular_post_30_days_view':
376 $args['meta_key'] = '__post_views_count';
377 $args['orderby'] = 'meta_value_num';
378 $args['order'] = 'DESC';
379 $args['date_query'] = array( array( 'after' => '1 month ago') );
380 break;
381 case 'popular_post_all_times_view':
382 $args['meta_key'] = '__post_views_count';
383 $args['orderby'] = 'meta_value_num';
384 $args['order'] = 'DESC';
385 break;
386 default:
387 # code...
388 break;
389 }
390 return $args;
391 }
392
393 /**
394 * Get All Term ID as Array
395 *
396 * @since v.2.4.12
397 * @return ARRAY | Query Arg
398 */
399 public function get_terms_id($id, $type) {
400 $data = array();
401 $arr = get_the_terms($id, $type);
402 if (is_array($arr)) {
403 foreach ($arr as $key => $val) {
404 $data[] = $val->term_id;
405 }
406 }
407 return $data;
408 }
409
410 /**
411 * Get All Reusable ID
412 *
413 * @since v.1.1.0
414 * @return ARRAY | Query Arg
415 */
416 public function reusable_id($post_id) {
417 $reusable_id = array();
418 if ($post_id) {
419 $post = get_post($post_id);
420 if (has_blocks($post->post_content)) {
421 $blocks = parse_blocks($post->post_content);
422 foreach ($blocks as $key => $value) {
423 if (isset($value['attrs']['ref'])) {
424 $reusable_id[] = $value['attrs']['ref'];
425 }
426 }
427 }
428 }
429 return $reusable_id;
430 }
431
432
433 /**
434 * Set CSS Style
435 *
436 * @since v.1.1.0
437 * @return ARRAY | Query Arg
438 */
439 public function set_css_style($post_id, $shortcode = false) {
440 if ($post_id) {
441 $upload_dir_url = wp_get_upload_dir();
442 $upload_css_dir_url = trailingslashit( $upload_dir_url['basedir'] );
443 $css_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
444
445 $css_dir_url = trailingslashit( $upload_dir_url['baseurl'] );
446 if (is_ssl()) {
447 $css_dir_url = str_replace('http://', 'https://', $css_dir_url);
448 }
449
450 // Reusable CSS
451 $reusable_id = ultimate_post()->reusable_id($post_id);
452 foreach ( $reusable_id as $id ) {
453 $reusable_dir_path = $upload_css_dir_url."ultimate-post/ultp-css-{$id}.css";
454 if (file_exists( $reusable_dir_path )) {
455 $css_url = $css_dir_url . "ultimate-post/ultp-css-{$id}.css";
456 wp_enqueue_style( "ultp-post-{$id}", $css_url, array(), ultimate_post()->get_setting('save_version'), 'all' );
457 }else{
458 $css = get_post_meta($id, '_ultp_css', true);
459 if( $css ) {
460 ultimate_post()->set_inline($css);
461 }
462 }
463 }
464
465 if (isset($_GET['et_fb']) || (isset($_GET['action']) && sanitize_key($_GET['action']) == 'elementor') || $shortcode) {
466 return ultimate_post()->set_inline(get_post_meta($post_id, '_ultp_css', true));
467 } else {
468 if (file_exists( $css_dir_path ) ) {
469 $css_url = $css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
470 wp_enqueue_style( "ultp-post-{$post_id}", $css_url, array(), ultimate_post()->get_setting('save_version'), 'all' );
471 } else {
472 $css = get_post_meta($post_id, '_ultp_css', true);
473 if( $css ) {
474 ultimate_post()->set_inline($css);
475 }
476 }
477 }
478 }
479 }
480
481
482 /**
483 * Get Global Plugin Settings
484 *
485 * @since v.1.0.0
486 * @param STRING | Key of the Option
487 * @return ARRAY | STRING
488 */
489 public function get_setting($key = '') {
490 $data = $GLOBALS['ultp_settings'];
491 if ($key != '') {
492 return isset($data[$key]) ? $data[$key] : '';
493 } else {
494 return $data;
495 }
496 }
497
498
499 /**
500 * Set Option Settings
501 *
502 * @since v.1.0.0
503 * @param STRING | Key of the Option (STRING), Value (STRING)
504 * @return NULL
505 */
506 public function set_setting($key = '', $val = '') {
507 if ($key != '') {
508 $data = $GLOBALS['ultp_settings'];
509 $data[$key] = $val;
510 update_option('ultp_options', $data);
511 $GLOBALS['ultp_settings'] = $data;
512 }
513 }
514
515
516 /**
517 * Get Image HTML
518 *
519 * @since v.1.0.0
520 * @param | URL (STRING) | size (STRING) | class (STRING) | alt (STRING)
521 * @return STRING
522 */
523 public function get_image_html($url = '', $size = 'full', $class = '', $alt = '', $lazy = '') {
524 $alt = $alt ? ' alt="'.$alt.'" ' : '';
525 $lazy_data = $lazy ? ' loading="lazy"' : '';
526 $class = $class ? ' class="'.$class.'" ' : '';
527 return '<img '.$lazy_data.$class.$alt.' src="'.$url.'" />';
528 }
529
530
531 /**
532 * Get Image HTML
533 *
534 * @since v.1.0.0
535 * @param | Attach ID (STRING) | size (STRING) | class (STRING) | alt (STRING)
536 * @return STRING
537 */
538 public function get_image($attach_id, $size = 'full', $class = '', $alt = '', $srcset = '', $lazy = '') {
539 $img_alt = get_post_meta($attach_id, '_wp_attachment_image_alt', true);
540 $alt = $img_alt ? $img_alt : $alt;
541 $alt = $alt ? ' alt="'.$alt.'" ' : '';
542 $class = $class ? ' class="'.$class.'" ' : '';
543 $size = ( ultimate_post()->get_setting('disable_image_size') == 'yes' && strpos($size, 'ultp_layout_') !== false ) ? 'full' : $size;
544 $lazy_data = $lazy ? ' loading="lazy"' : '';
545 $srcset_data = $srcset ? ' srcset="'.esc_attr(wp_get_attachment_image_srcset($attach_id)).'"' : '';
546 return '<img '.$srcset_data.$lazy_data.$class.$alt.' src="'.wp_get_attachment_image_url( $attach_id, $size ).'" />';
547 }
548
549
550 /**
551 * Setup Initial Data Set
552 *
553 * @since v.1.0.0
554 * @return NULL
555 */
556 public function init_set_data() {
557 $data = get_option( 'ultp_options', array() );
558 $init_data = array(
559 'css_save_as' => 'wp_head',
560 'preloader_style' => 'style1',
561 'preloader_color' => '#037fff',
562 'container_width' => '1140',
563 'hide_import_btn' => '',
564 'disable_image_size'=> '',
565 'disable_view_cookies' => '',
566 'disable_google_font' => '',
567 'ultp_templates' => 'true',
568 'ultp_elementor' => 'true',
569 'ultp_table_of_content'=> 'true',
570 'ultp_builder' => 'true',
571 'post_grid_1' => 'yes',
572 'post_grid_2' => 'yes',
573 'post_grid_3' => 'yes',
574 'post_grid_4' => 'yes',
575 'post_grid_5' => 'yes',
576 'post_grid_6' => 'yes',
577 'post_grid_7' => 'yes',
578 'post_list_1' => 'yes',
579 'post_list_2' => 'yes',
580 'post_list_3' => 'yes',
581 'post_list_4' => 'yes',
582 'post_module_1' => 'yes',
583 'post_module_2' => 'yes',
584 'post_slider_1' => 'yes',
585 'post_slider_2' => 'yes',
586 'heading' => 'yes',
587 'image' => 'yes',
588 'taxonomy' => 'yes',
589 'wrapper' => 'yes',
590 'news_ticker' => 'yes',
591 'builder_advance_post_meta' => 'yes',
592 'builder_archive_title' => 'yes',
593 'builder_author_box' => 'yes',
594 'builder_post_next_previous'=> 'yes',
595 'builder_post_author_meta' => 'yes',
596 'builder_post_breadcrumb' => 'yes',
597 'builder_post_category' => 'yes',
598 'builder_post_comment_count'=> 'yes',
599 'builder_post_comments' => 'yes',
600 'builder_post_content' => 'yes',
601 'builder_post_date_meta' => 'yes',
602 'builder_post_excerpt' => 'yes',
603 'builder_post_featured_image'=> 'yes',
604 'builder_post_reading_time' => 'yes',
605 'builder_post_social_share' => 'yes',
606 'builder_post_tag' => 'yes',
607 'builder_post_title' => 'yes',
608 'builder_post_view_count' => 'yes',
609 'save_version' => rand(1, 1000)
610 );
611 if (empty($data)) {
612 update_option('ultp_options', $init_data);
613 $GLOBALS['ultp_settings'] = $init_data;
614 } else {
615 foreach ($init_data as $key => $single) {
616 if (!isset($data[$key])) {
617 $data[$key] = $single;
618 }
619 }
620 update_option('ultp_options', $data);
621 $GLOBALS['ultp_settings'] = $data;
622 }
623 }
624
625
626 /**
627 * Get Excerpt Text
628 *
629 * @since v.1.0.0
630 * @param | Post ID (STRING) | Limit (NUMBER)
631 * @return STRING
632 */
633 public function excerpt( $post_id, $limit = 55 ) {
634 $content = preg_replace('/(\[postx_template[\s\w="]*)]/m', '', get_the_content( $post_id )); // Remove postx_template shortcode form Content
635 return apply_filters( 'the_excerpt', wp_trim_words($content, $limit) );
636 }
637
638 /**
639 * Builder Attributes
640 *
641 * @since v.1.0.0
642 * @param STRING type
643 * @return STRING
644 */
645 public function get_builder_attr($type) {
646 $builder_data = '';
647 if ($type == 'archiveBuilder') {
648 if (is_archive()) {
649 if (is_date()) {
650 if (is_year()) {
651 $builder_data = 'date###'.get_the_date('Y');
652 } else if (is_month() ) {
653 $builder_data = 'date###'.get_the_date('Y-n');
654 } else if (is_day() ) {
655 $builder_data = 'date###'.get_the_date('Y-n-j');
656 }
657 } else if (is_author()) {
658 $builder_data = 'author###'.get_the_author_meta('ID');
659 } else {
660 $obj = get_queried_object();
661 if (isset($obj->taxonomy)) {
662 $builder_data = 'taxonomy###'.$obj->taxonomy.'###'.$obj->slug;
663 }
664 }
665 } else if (is_search()) {
666 $builder_data = 'search###'.get_search_query(true);
667 }
668 }
669 return $builder_data ? 'data-builder="'.$builder_data.'"' : '';
670 }
671
672
673 public function is_builder($builder = '') {
674 $id = '';
675 $page_id = ultimate_post()->conditions('return');
676 if ($page_id && ultimate_post()->get_setting('ultp_builder')) {
677 $id = $page_id;
678 }
679 return $id;
680 }
681
682
683 /**
684 * Get Post Number Depending On Device
685 *
686 * @since v.2.5.4
687 * @param MULTIPLE | Attribute of Posts
688 * @return STRING
689 */
690 public function get_post_number($preDef, $prev, $current) {
691
692 $current = is_object($current)?json_decode(json_encode($current), true):$current;
693 if (['lg'=>$preDef,'sm'=>$preDef,'xs'=>$preDef] == $current) {
694 if ($preDef != $prev) {
695 return $prev;
696 }
697 }
698 if ($this->isDevice() == 'mobile') {
699 return isset($current['xs']) && $current['xs'] ? $current['xs'] : $current['lg'];
700 } else if ($this->isDevice() == 'tablet') {
701 return isset($current['sm']) && $current['sm'] ? $current['sm'] : $current['lg'];
702 } else {
703 return $current['lg'];
704 }
705 }
706
707
708 /**
709 * Get Post Number Depending On Device
710 *
711 * @since v.2.5.4
712 * @param NULL
713 * @return STRING | Device Type
714 */
715 public function isDevice(){
716 $useragent = isset($_SERVER['HTTP_USER_AGENT']) ? sanitize_key($_SERVER['HTTP_USER_AGENT']) : '';
717 if ($useragent) {
718 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))) {
719 return 'mobile';
720 } else if (preg_match('/(tablet|ipad|playbook)|(android(?!.*(mobi|opera mini)))/i', strtolower($useragent))) {
721 return 'tablet';
722 } else {
723 return 'desktop';
724 }
725 }
726 return 'desktop';
727 }
728
729
730 /**
731 * Get Raw Value from Objects
732 *
733 * @since v.2.5.3
734 * @param NULL
735 * @return STRING | Device Type
736 */
737 public function get_value($attr) {
738 $data = [];
739 if (is_array($attr)) {
740 foreach ($attr as $val) {
741 $data[] = $val->value;
742 }
743 }
744 return $data;
745 }
746
747 /**
748 * QueryArgs for Filter
749 *
750 * @since v.2.8.9
751 * @param ARRAY | Attribute of the Query
752 * @return ARRAY
753 */
754 public function getFilterQueryArgs( $attr ) {
755 $tax_value = (strlen($attr['queryTaxValue']) > 2) ? $attr['queryTaxValue'] : [];
756 $tax_value = is_array($tax_value) ? $tax_value : json_decode($tax_value);
757
758 $tax_value = (isset($tax_value[0]) && is_object($tax_value[0])) ? $this->get_value($tax_value) : $tax_value;
759
760 if (is_array($tax_value) && count($tax_value) > 0) {
761 $relation = isset($attr['queryRelation']) ? $attr['queryRelation'] : 'OR';
762 $var = array('relation'=>$relation);
763 foreach ($tax_value as $val) {
764 $tax_name = $attr['queryTax'];
765 // For Custom Terms
766 if ($attr['queryTax'] == 'multiTaxonomy') {
767 $temp = explode('###', $val);
768 if (isset($temp[1])) {
769 $val = $temp[1];
770 $tax_name = $temp[0];
771 }
772 }
773 $var[] = array('taxonomy'=> $tax_name, 'field' => 'slug', 'terms' => $val );
774 }
775
776 }
777 return isset($var) ? $var : [];
778 }
779
780 /**
781 * Query Builder
782 *
783 * @since v.1.0.0
784 * @param ARRAY | Attribute of the Query
785 * @return ARRAY
786 */
787 public function get_query($attr) {
788 $builder = isset($attr['builder']) ? $attr['builder'] : '';
789 $post_type = isset($attr['queryType']) ? $attr['queryType'] : 'post';
790 if ( $post_type == 'archiveBuilder' && ($builder || $this->is_builder($builder)) ) {
791 $archive_query = array();
792 if ($builder) {
793 $str = explode('###', $builder);
794 if (isset($str[0])) {
795 if ($str[0] == 'taxonomy') {
796 if (isset($str[1]) && isset($str[2])) {
797 $archive_query['tax_query'] = array(
798 array(
799 'taxonomy' => $str[1],
800 'field' => 'slug',
801 'terms' => $str[2]
802 )
803 );
804 }
805 } else if ($str[0] == 'author') {
806 if (isset($str[1])) {
807 $archive_query['author'] = $str[1];
808 }
809 } else if ($str[0] == 'search') {
810 if (isset($str[1])) {
811 $archive_query['s'] = $str[1];
812 }
813 } else if ($str[0] == 'date') {
814 if (isset($str[1])) {
815 $all_date = explode('-', $str[1]);
816 if (!empty($all_date)) {
817 $arg = array();
818 if (isset($all_date[0])) { $arg['year'] = $all_date[0]; }
819 if (isset($all_date[1])) { $arg['month'] = $all_date[1]; }
820 if (isset($all_date[2])) { $arg['day'] = $all_date[2]; }
821 $archive_query['date_query'][] = $arg;
822 }
823 }
824 }
825 }
826 } else {
827 global $wp_query;
828 $archive_query = $wp_query->query_vars;
829 }
830 $archive_query['posts_per_page'] = isset($attr['queryNumber']) ? $attr['queryNumber'] : 1;
831 $archive_query['paged'] = isset($attr['paged']) ? $attr['paged'] : 1;
832 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
833 $offset = $this->get_offset($attr['queryOffset'], $archive_query);
834 $archive_query = array_merge($archive_query, $offset);
835 }
836
837 // Include Remove from Version 2.5.4
838 if (isset($attr['queryInclude']) && $attr['queryInclude']) {
839 $_include = explode(',', $attr['queryInclude']);
840 if (is_array($_include) && count($_include)) {
841 $archive_query['post__in'] = isset($archive_query['post__in']) ? array_merge($archive_query['post__in'], $_include) : $_include;
842 $archive_query['ignore_sticky_posts'] = 1;
843 $archive_query['orderby'] = 'post__in';
844 }
845 }
846
847 if (isset($attr['queryExclude']) && $attr['queryExclude']) {
848 $_exclude = (substr($attr['queryExclude'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryExclude'])) : explode(',', $attr['queryExclude']);
849 if (is_array($_exclude) && count($_exclude)) {
850 $archive_query['post__not_in'] = isset($archive_query['post__not_in']) ? array_merge($archive_query['post__not_in'], $_exclude) : $_exclude;
851 }
852 }
853
854
855 if(isset($attr['querySticky']) && $attr['querySticky']) {
856 if (filter_var($attr['querySticky'], FILTER_VALIDATE_BOOLEAN)) {
857 $sticky = get_option( 'sticky_posts', [] );
858 $archive_query['post__not_in'] = isset($archive_query['post__not_in']) ? array_merge($archive_query['post__not_in'], $sticky) : $sticky;
859 }
860 }
861
862 $archive_query['post_status'] = 'publish';
863 if (is_user_logged_in()) {
864 if( current_user_can('editor') || current_user_can('administrator') ) {
865 $archive_query['post_status'] = array('publish', 'private');
866 }
867 }
868
869 if(!isset($archive_query['orderby'])) {
870 $archive_query['orderby'] = isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date';
871 }
872
873 // Quick Query Support for Builder
874 if (isset($attr['queryQuick'])) {
875 if ($attr['queryQuick'] != '') {
876 $archive_query = ultimate_post()->get_quick_query($attr, $archive_query);
877 }
878 }
879
880 if (!isset($attr['ajaxCall'])) {
881 if(isset($attr['filterShow']) && $attr['filterShow']) {
882 if(isset($attr['filterType']) && isset($attr['filterValue'])) {
883 $filterValue = strlen($attr['filterValue']) > 2 ? $attr['filterValue'] : [];
884 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
885 if (count($filterValue) > 0 && $attr['filterType']) {
886 $final = array('relation' => 'OR');
887 foreach ($filterValue as $key => $val) {
888 $final[] = array(
889 'taxonomy' => $attr['filterType'],
890 'field' => 'slug',
891 'terms' => $val,
892 );
893 }
894 $archive_query['tax_query'] = $final;
895 }
896 }
897 }
898 }
899
900 return apply_filters('ultp_archive_query', $archive_query);
901 }
902
903 $query_args = array(
904 'posts_per_page' => isset($attr['queryNumber']) ? $attr['queryNumber'] : 3,
905 'post_type' => $post_type == 'archiveBuilder' ? 'post' : $post_type,
906 'orderby' => isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date',
907 'order' => isset($attr['queryOrder']) ? $attr['queryOrder'] : 'desc',
908 'paged' => isset($attr['paged']) ? $attr['paged'] : 1,
909 'post_status' => 'publish'
910 );
911
912 // For Private Post 'private'
913 if (is_user_logged_in()) {
914 if( current_user_can('editor') || current_user_can('administrator') ) {
915 $query_args['post_status'] = array('publish', 'private');
916 }
917 }
918
919 if ($attr['queryType'] == 'posts') {
920 if (isset($attr['queryPosts']) && $attr['queryPosts']) {
921 unset($query_args['post_type']);
922 $data = json_decode(isset($attr['queryPosts'])?$attr['queryPosts']:'[]');
923 $final = $this->get_value($data);
924 if (count($final) > 0) {
925 $query_args['post__in'] = $final;
926 $query_args['posts_per_page'] = -1;
927 }
928 $query_args['ignore_sticky_posts'] = 1;
929 return $query_args;
930 }
931 } else if ($attr['queryType'] == 'customPosts') {
932 if (isset($attr['queryCustomPosts']) && $attr['queryCustomPosts']) {
933 $query_args['post_type'] = $this->get_post_type();
934 $data = json_decode(isset($attr['queryCustomPosts'])?$attr['queryCustomPosts']:'[]');
935 $final = $this->get_value($data);
936 if (count($final) > 0) {
937 $query_args['post__in'] = $final;
938 $query_args['posts_per_page'] = -1;
939 }
940 $query_args['ignore_sticky_posts'] = 1;
941 return $query_args;
942 }
943 }
944
945 if (isset($attr['queryExcludeAuthor']) && $attr['queryExcludeAuthor']) {
946 $data = json_decode(isset($attr['queryExcludeAuthor'])?$attr['queryExcludeAuthor']:'[]');
947 $final = $this->get_value($data);
948 if (count($final) > 0) {
949 $query_args['author__not_in'] = $final;
950 }
951 }
952
953
954 if (isset($attr['queryOrderBy']) && isset($attr['metaKey'])) {
955 if ($attr['queryOrderBy'] == 'meta_value_num') {
956 $query_args['meta_key'] = $attr['metaKey'];
957 }
958 }
959
960 // Include Remove from Version 2.5.4
961 if (isset($attr['queryInclude']) && $attr['queryInclude']) {
962 $_include = explode(',', $attr['queryInclude']);
963 if (is_array($_include) && count($_include)) {
964 $query_args['post__in'] = isset($query_args['post__in']) ? array_merge($query_args['post__in'], $_include) : $_include;
965 $query_args['ignore_sticky_posts'] = 1;
966 $query_args['orderby'] = 'post__in';
967 }
968 }
969
970
971 if (isset($attr['queryTax'])) {
972 if (isset($attr['queryTaxValue'])) {
973 $var = $this->getFilterQueryArgs($attr);
974 if (isset($var) && count($var) > 1) {
975 $query_args['tax_query'] = $var;
976 }
977 }
978 }
979
980 if (isset($attr['queryExcludeTerm']) && $attr['queryExcludeTerm']) {
981 $temp = json_decode($attr['queryExcludeTerm']);
982 $_term = [];
983 foreach ($temp as $val) {
984 $temp = explode('###', $val->value);
985 if (isset($temp[1])) {
986 if (array_key_exists($temp[0], $_term)) {
987 $_term[$temp[0]][] = $temp[1];
988 } else {
989 $_term[$temp[0]] = array($temp[1]);
990 }
991 }
992 }
993 if (count($_term) > 0) {
994 $final = array('relation' => 'AND');
995 foreach ($_term as $key => $val) {
996 $final[] = array(
997 'taxonomy' => $key,
998 'field' => 'slug',
999 'terms' => $val,
1000 'operator' => 'NOT IN',
1001 );
1002 }
1003
1004 if (array_key_exists('tax_query', $query_args)) {
1005 $query_args['tax_query'] = array(
1006 'relation' => 'AND',
1007 $query_args['tax_query']
1008 );
1009 $query_args['tax_query'][] = $final;
1010 } else {
1011 $query_args['tax_query'] = $final;
1012 }
1013 }
1014 }
1015
1016 if (isset($attr['queryExclude']) && $attr['queryExclude']) {
1017 $_exclude = (substr($attr['queryExclude'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryExclude'])) : explode(',', $attr['queryExclude']);
1018 if (is_array($_exclude) && count($_exclude)) {
1019 $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $_exclude) : $_exclude;
1020 }
1021 }
1022
1023 if (isset($attr['queryUnique']) && $attr['queryUnique']) {
1024 global $unique_ID;
1025 if (isset($unique_ID[$attr['queryUnique']])) {
1026 $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']];
1027 }
1028 }
1029
1030 if (isset($attr['queryQuick'])) {
1031 if ($attr['queryQuick'] != '' && $post_type != 'archiveBuilder') {
1032 $query_args = ultimate_post()->get_quick_query($attr, $query_args);
1033 }
1034 }
1035
1036 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
1037 $offset = $this->get_offset($attr['queryOffset'], $query_args);
1038 $query_args = array_merge($query_args, $offset);
1039 }
1040
1041 if (isset($attr['queryAuthor']) && $attr['queryAuthor'] ) {
1042 $_include = (substr($attr['queryAuthor'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryAuthor'])) : explode(',', $attr['queryAuthor']);
1043 if (is_array($_include) && count($_include)) {
1044 $query_args['author__in'] = $_include;
1045 }
1046 }
1047
1048 if(isset($attr['querySticky']) && $attr['querySticky']) {
1049 if (filter_var($attr['querySticky'], FILTER_VALIDATE_BOOLEAN)) {
1050 $sticky = get_option( 'sticky_posts', [] );
1051 $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $sticky) : $sticky;
1052 }
1053 }
1054
1055 if (!isset($attr['ajaxCall'])) {
1056 if(isset($attr['filterShow']) && $attr['filterShow']) {
1057 if(isset($attr['checkFilter']) && isset($attr['queryTax']) && isset($attr['queryTaxValue']) ) {
1058 $var = $this->getFilterQueryArgs($attr);
1059 if (isset($var) && count($var) > 1) {
1060 $query_args['tax_query'] = $var;
1061 }
1062 }
1063 else if(isset($attr['filterType']) && isset($attr['filterValue'])) {
1064 $filterValue = strlen($attr['filterValue']) > 2 ? $attr['filterValue'] : [];
1065 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
1066 if (is_array($filterValue) && count($filterValue) > 0 && $attr['filterType']) {
1067 $final = array('relation' => 'OR');
1068 foreach ($filterValue as $key => $val) {
1069 $final[] = array(
1070 'taxonomy' => $attr['filterType'],
1071 'field' => 'slug',
1072 'terms' => $val,
1073 // 'operator' => '=',
1074 );
1075 }
1076 $query_args['tax_query'] = $final;
1077 }
1078 }
1079 }
1080 }
1081
1082 $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
1083
1084 return apply_filters('ultp_frontend_query', $query_args);
1085 }
1086
1087 /**
1088 * Get Page Offset
1089 *
1090 * @since v.1.0.0
1091 * @param | Offset Number(NUMBER) | Query Arg(ARRAY)
1092 * @return ARRAY
1093 */
1094 function get_offset($queryOffset, $query_args) {
1095 $query = array();
1096 if ($query_args['paged'] > 1) {
1097 $offset_post = wp_get_recent_posts($query_args, OBJECT);
1098 if (count($offset_post) > 0 ) {
1099 $offset = array();
1100 for($x = count($offset_post); $x > count($offset_post) - $queryOffset; $x--) {
1101 $offset[] = $offset_post[$x-1]->ID;
1102 }
1103 $query['post__not_in'] = $offset;
1104 }
1105 } else {
1106 $query['offset'] = isset($queryOffset) ? $queryOffset : 0;
1107 }
1108 return $query;
1109 }
1110
1111
1112 /**
1113 * Get Page Number
1114 *
1115 * @since v.1.0.0
1116 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1117 * @return ARRAY
1118 */
1119 public function get_page_number($attr, $post_number) {
1120 if ($post_number > 0) {
1121 if (isset($attr['queryOffset']) && $attr['queryOffset']) {
1122 $post_number = $post_number - (int)$attr['queryOffset'];
1123 }
1124 $post_per_page = isset($attr['queryNumber']) ? ($attr['queryNumber'] ? $attr['queryNumber'] : 1) : 3;
1125 $pages = ceil($post_number/$post_per_page);
1126 return $pages ? $pages : 1;
1127 }else{
1128 return 1;
1129 }
1130 }
1131
1132
1133 /**
1134 * Get Image Size
1135 *
1136 * @since v.1.0.0
1137 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1138 * @return ARRAY
1139 */
1140 public function get_image_size() {
1141 $sizes = get_intermediate_image_sizes();
1142 $filter = array('full' => 'Full');
1143 foreach ($sizes as $value) {
1144 $title = ucwords(str_replace(array('_', '-', 'ultp'), array(' ', ' ', 'PostX'), $value));
1145 switch ($value) {
1146 case 'thumbnail':
1147 $title = $title.' [150x150]';
1148 break;
1149 case 'medium':
1150 $title = $title.' [300x300]';
1151 break;
1152 case 'large':
1153 $title = $title.' [1024x1024]';
1154 break;
1155 case 'ultp_layout_landscape_large':
1156 $title = $title.' [1200x800]';
1157 break;
1158 case 'ultp_layout_landscape':
1159 $title = $title.' [870x570]';
1160 break;
1161 case 'ultp_layout_portrait':
1162 $title = $title.' [600x900]';
1163 break;
1164 case 'ultp_layout_square':
1165 $title = $title.' [600x600]';
1166 break;
1167 default:
1168 break;
1169 }
1170 $filter[$value] = $title;
1171 }
1172 return $filter;
1173 }
1174
1175
1176 /**
1177 * Get All PostType Registered
1178 *
1179 * @since v.1.0.0
1180 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1181 * @return ARRAY
1182 */
1183 public function get_post_type() {
1184 $filter = apply_filters('ultp_public_post_type', true);
1185 $post_type = get_post_types( ($filter ? ['public' => true] : ''), 'names' );
1186 return array_diff($post_type, array( 'attachment' ));
1187 }
1188
1189 /**
1190 * Get Pagination Url
1191 *
1192 * @since v.2.8.9
1193 * @param | pageNo (NUMBER) | baseUrl (STRING)
1194 * @return STRING
1195 */
1196 public function generatePaginationUrl($pageNo , $baseUrl) {
1197 if($baseUrl) {
1198 $url = $baseUrl.($pageNo == 1? '' : "page/".$pageNo);
1199 }
1200 else {
1201 $url = get_pagenum_link($pageNo);
1202 }
1203 return $url;
1204 }
1205 /**
1206 * Get Pagination HTML
1207 *
1208 * @since v.1.0.0
1209 * @param | pages (NUMBER) | Pagination Nav (STRING) | Pagination Text |
1210 * @return STRING
1211 */
1212 public function pagination($pages = '', $paginationNav = '', $paginationText = '', $paginationAjax = true, $baseUrl = '') {
1213 $html = '';
1214 $showitems = 3;
1215 $paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
1216 $paged = $paged ? $paged : 1;
1217 if ($pages == '') {
1218 global $wp_query;
1219 $pages = $wp_query->max_num_pages;
1220 if (!$pages) {
1221 $pages = 1;
1222 }
1223 }
1224
1225 $data = ($paged>=3?[($paged-1),$paged,$paged+1]:[1,2,3]);
1226
1227 $paginationText = explode('|', $paginationText);
1228
1229 $prev_text = isset($paginationText[0]) ? $paginationText[0] : __("Previous", "ultimate-post");
1230 $next_text = isset($paginationText[1]) ? $paginationText[1] : __("Next", "ultimate-post");
1231
1232 if (1 != $pages) {
1233 $html .= '<ul class="ultp-pagination">';
1234 $display_none = 'style="display:none"';
1235 if ($pages > 4) {
1236 $html .= '<li class="ultp-prev-page-numbers" '.($paged==1?$display_none:"").'><a href="'.$this->generatePaginationUrl($paged-1, $baseUrl).'">'.ultimate_post()->svg_icon('leftAngle2').' '.($paginationNav == 'textArrow' ? $prev_text : "").'</a></li>';
1237 }
1238 if ($pages > 4) {
1239 $html .= '<li class="ultp-first-pages" '.($paged<2?$display_none:"").' data-current="1"><a href="'.$this->generatePaginationUrl(1, $baseUrl).'">1</a></li>';
1240 }
1241 if ($pages > 4) {
1242 $html .= '<li class="ultp-first-dot" '.($paged<2? $display_none : "").'><a href="#">...</a></li>';
1243 }
1244 foreach ($data as $i) {
1245 if ($pages >= $i) {
1246 $html .= ($paged == $i) ? '<li class="ultp-center-item pagination-active" data-current="'.$i.'"><a href="'.$this->generatePaginationUrl($i, $baseUrl).'">'.$i.'</a></li>':'<li class="ultp-center-item" data-current="'.$i.'" '.( ( $pages > 4 && $paged==2 && $i==1 && !$paginationAjax ) ? $display_none : "").'><a href="'.$this->generatePaginationUrl($i, $baseUrl).'">'.$i.'</a></li>';
1247 }
1248 }
1249 if ($pages > 4) {
1250 $html .= '<li class="ultp-last-dot" '.($pages<=$paged+1?$display_none:"").'><a href="#">...</a></li>';
1251 }
1252 if ($pages > 4) {
1253 $html .= '<li class="ultp-last-pages" '.($pages<=$paged+1?$display_none:"").' data-current="'.$pages.'"><a href="'.$this->generatePaginationUrl($pages, $baseUrl).'">'.$pages.'</a></li>';
1254 }
1255 if ($paged != $pages) {
1256 $html .= '<li class="ultp-next-page-numbers"><a href="'.$this->generatePaginationUrl($paged + 1, $baseUrl).'">'.($paginationNav == 'textArrow' ? $next_text : "").ultimate_post()->svg_icon('rightAngle2').'</a></li>';
1257 }
1258 $html .= '</ul>';
1259 }
1260 return $html;
1261 }
1262
1263 /**
1264 * Svg Icon Source
1265 *
1266 * @since v.1.0.0
1267 * @param STRING | String Name
1268 * @return STRING
1269 */
1270 public function svg_icon($ultp_icons = '') {
1271 $ultp_icon_lists = array(
1272 'eye' => file_get_contents(ULTP_PATH.'assets/img/setting/eye.svg'),
1273 'user' => file_get_contents(ULTP_PATH.'assets/img/setting/user.svg'),
1274 'calendar' => file_get_contents(ULTP_PATH.'assets/img/setting/calendar.svg'),
1275 'comment' => file_get_contents(ULTP_PATH.'assets/img/setting/comment.svg'),
1276 'book' => file_get_contents(ULTP_PATH.'assets/img/setting/book.svg'),
1277 'tag' => file_get_contents(ULTP_PATH.'assets/img/setting/tag.svg'),
1278 'clock' => file_get_contents(ULTP_PATH.'assets/img/setting/clock.svg'),
1279 'leftAngle' => file_get_contents(ULTP_PATH.'assets/img/setting/leftAngle.svg'),
1280 'rightAngle' => file_get_contents(ULTP_PATH.'assets/img/setting/rightAngle.svg'),
1281 'leftAngle2' => file_get_contents(ULTP_PATH.'assets/img/setting/leftAngle2.svg'),
1282 'rightAngle2' => file_get_contents(ULTP_PATH.'assets/img/setting/rightAngle2.svg'),
1283 'leftArrowLg' => file_get_contents(ULTP_PATH.'assets/img/setting/leftArrowLg.svg'),
1284 'rightArrowLg' => file_get_contents(ULTP_PATH.'assets/img/setting/rightArrowLg.svg'),
1285 'refresh' => file_get_contents(ULTP_PATH.'assets/img/setting/refresh.svg'),
1286 'upArrow' => file_get_contents(ULTP_PATH.'assets/img/setting/upArrow.svg'),
1287 'downArrow' => file_get_contents(ULTP_PATH.'assets/img/setting/downArrow.svg'),
1288 'arrowUp2' => file_get_contents(ULTP_PATH.'assets/img/setting/arrowUp2.svg'),
1289 'longArrowUp2' => file_get_contents(ULTP_PATH.'assets/img/setting/longArrowUp2.svg'),
1290 'caretArrow' => file_get_contents(ULTP_PATH.'assets/img/setting/caretArrow.svg'),
1291 'left' => file_get_contents(ULTP_PATH.'assets/img/setting/left.svg'),
1292 'center' => file_get_contents(ULTP_PATH.'assets/img/setting/center.svg'),
1293 'right' => file_get_contents(ULTP_PATH.'assets/img/setting/right.svg'),
1294 'justify' => file_get_contents(ULTP_PATH.'assets/img/setting/justify.svg'),
1295 'desktop' => file_get_contents(ULTP_PATH.'assets/img/setting/desktop.svg'),
1296 'laptop' => file_get_contents(ULTP_PATH.'assets/img/setting/laptop.svg'),
1297 'tablet' => file_get_contents(ULTP_PATH.'assets/img/setting/tablet.svg'),
1298 'mobile' => file_get_contents(ULTP_PATH.'assets/img/setting/mobile.svg'),
1299 'dimension' => file_get_contents(ULTP_PATH.'assets/img/setting/dimension.svg'),
1300 'setting' => file_get_contents(ULTP_PATH.'assets/img/setting/setting.svg'),
1301 'plus' => file_get_contents(ULTP_PATH.'assets/img/setting/plus.svg'),
1302 // Builder
1303 'commentCount1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount1.svg'),
1304 'commentCount2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount2.svg'),
1305 'commentCount3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount3.svg'),
1306 'commentCount4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount4.svg'),
1307 'commentCount5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount5.svg'),
1308 'commentCount6' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/comments_meta/commentCount6.svg'),
1309 'date1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/date_meta/date1.svg'),
1310 'date2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/date_meta/date2.svg'),
1311 'date3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/date_meta/date3.svg'),
1312 'date4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/date_meta/date4.svg'),
1313 'date5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/date_meta/date5.svg'),
1314 'author1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/author_meta/author1.svg'),
1315 'author2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/author_meta/author2.svg'),
1316 'author3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/author_meta/author3.svg'),
1317 'author4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/author_meta/author4.svg'),
1318 'author5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/author_meta/author5.svg'),
1319 'readingTime1' => file_get_contents(ULTP_PATH.
1320 '/assets/img/blocks/builder/reading_time/readingTime1.svg'),
1321 'readingTime2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/reading_time/readingTime2.svg'),
1322 'readingTime3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/reading_time/readingTime3.svg'),
1323 'readingTime4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/reading_time/readingTime4.svg'),
1324 'readingTime5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/reading_time/readingTime5.svg'),
1325 'viewCount1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount1.svg'),
1326 'viewCount2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount2.svg'),
1327 'viewCount3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount3.svg'),
1328 'viewCount4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount4.svg'),
1329 'viewCount5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount5.svg'),
1330 'viewCount6' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/viewCount/viewCount6.svg'),
1331 'cat1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat1.svg'),
1332 'cat2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat2.svg'),
1333 'cat3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat3.svg'),
1334 'cat4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat4.svg'),
1335 'cat5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat5.svg'),
1336 'cat6' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat6.svg'),
1337 'cat7' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/category/cat7.svg'),
1338 'tag1' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag1.svg'),
1339 'tag2' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag2.svg'),
1340 'tag3' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag3.svg'),
1341 'tag4' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag4.svg'),
1342 'tag5' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag5.svg'),
1343 'tag6' => file_get_contents(ULTP_PATH.'assets/img/blocks/builder/tag/tag6.svg'),
1344 'rightArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/rightArrowLg.svg'),
1345 'share' => file_get_contents(ULTP_PATH.'assets/img/svg/share.svg'),
1346 'facebook' => file_get_contents(ULTP_PATH.'assets/img/svg/facebookIcon.svg'),
1347 'linkedin' => file_get_contents(ULTP_PATH.'assets/img/svg/linkedinIcon.svg'),
1348 'mail' => file_get_contents(ULTP_PATH.'assets/img/svg/mailIcon.svg'),
1349 'messenger' => file_get_contents(ULTP_PATH.'assets/img/svg/messengerIcon.svg'),
1350 'reddit' => file_get_contents(ULTP_PATH.'assets/img/svg/redditIcon.svg'),
1351 'twitter' => file_get_contents(ULTP_PATH.'assets/img/svg/twitterIcon.svg'),
1352 'whatsapp' => file_get_contents(ULTP_PATH.'assets/img/svg/whatsappIcon.svg'),
1353 'pinterest' => file_get_contents(ULTP_PATH.'assets/img/svg/pinIcon.svg'),
1354 'skype' => file_get_contents(ULTP_PATH.'assets/img/svg/skype.svg'),
1355 'videoplay' => file_get_contents(ULTP_PATH.'assets/img/svg/videoplay.svg')
1356 );
1357 if ($ultp_icons) {
1358 return $ultp_icon_lists[ $ultp_icons ];
1359 }
1360 }
1361
1362
1363 /**
1364 * Get Excerpt Word
1365 *
1366 * @since v.1.0.0
1367 * @param NUMBER | Character Length
1368 * @return STRING
1369 */
1370 public function excerpt_word($charlength = 200) {
1371 $html = '';
1372 $charlength++;
1373 $excerpt = get_the_excerpt();
1374 if (mb_strlen( $excerpt ) > $charlength ) {
1375 $subex = mb_substr( $excerpt, 0, $charlength );
1376 $exwords = explode( ' ', $subex );
1377 $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
1378 if ($excut < 0 ) {
1379 $html = mb_substr( $subex, 0, $excut );
1380 } else {
1381 $html = $subex;
1382 }
1383 $html .= '...';
1384 } else {
1385 $html = $excerpt;
1386 }
1387 return $html;
1388 }
1389
1390
1391 /**
1392 * Get Taxonomy Lists
1393 *
1394 * @since v.1.0.0
1395 * @param STRING | Taxonomy Slug
1396 * @return ARRAY
1397 */
1398 public function taxonomy( $prams = 'category' ) {
1399 $data = array();
1400 $terms = get_terms( $prams, array(
1401 'hide_empty' => false,
1402 ));
1403 if (!is_wp_error($terms)) {
1404 foreach ($terms as $val) {
1405 $data[urldecode_deep($val->slug)] = $val->name;
1406 }
1407 }
1408 return $data;
1409 }
1410
1411
1412 /**
1413 * Get Taxonomy Lists
1414 *
1415 * @since v.2.9.0
1416 * @param STRING | Taxonomy Slug
1417 * @return ARRAY
1418 */
1419 public function builder_preview( $tax_slug, $number ) {
1420 $data = array();
1421 $term_data = get_terms( $tax_slug, array( 'hide_empty' => true, 'number' => $number, 'parent' => 0 ) );
1422 if (!empty($term_data)) {
1423 foreach ($term_data as $terms) {
1424 $data[] = $this->get_tax_data($terms);
1425 }
1426 }
1427 return $data;
1428 }
1429
1430 /**
1431 * Get Taxonomy Data Lists
1432 *
1433 * @since v.1.0.0
1434 * @param OBJECT | Taxonomy Object
1435 * @return ARRAY
1436 */
1437 public function get_tax_data($terms) {
1438 $temp = array();
1439 $thumbnail_id = get_term_meta( $terms->term_id, 'ultp_category_image', true );
1440 $image_src = array();
1441 if ($thumbnail_id) {
1442 $image_sizes = ultimate_post()->get_image_size();
1443 foreach ($image_sizes as $key => $value) {
1444 $image_src[$key] = wp_get_attachment_image_src($thumbnail_id, $key, false)[0];
1445 }
1446 }
1447 $temp['url'] = get_term_link($terms);
1448 $temp['thumbnail_id'] = $thumbnail_id;
1449 $temp['name'] = $terms->name;
1450 $temp['desc'] = $terms->description;
1451 $temp['count'] = $terms->count;
1452 $temp['image'] = $image_src;
1453 $color = get_term_meta($terms->term_id, 'ultp_category_color', true);
1454 $temp['color'] = $color ? $color : '#037fff';
1455 return $temp;
1456 }
1457
1458 public function get_category_data($catSlug, $number = 40, $type = '', $tax_slug = 'category', $archiveBuilder = '') {
1459 $data = array();
1460 if ($type == 'child') {
1461 if($archiveBuilder) {
1462 $data = $this->builder_preview( $tax_slug, $number );
1463 }
1464 else {
1465 if(is_category()) {
1466 $catSlug = array(get_queried_object()->slug);
1467 }
1468 $image = '';
1469 if (!empty($catSlug)) {
1470 foreach ($catSlug as $cat) {
1471 $parent_term = get_term_by('slug', $cat, $tax_slug);
1472 if (!empty($parent_term)) {
1473 $term_data = get_terms($tax_slug, array(
1474 'hide_empty' => true,
1475 'number' => $number,
1476 'parent' => $parent_term->term_id
1477 ));
1478 if (!empty($term_data)) {
1479 foreach ($term_data as $terms) {
1480 $data[] = $this->get_tax_data($terms);
1481 }
1482 }
1483 }
1484 }
1485 }
1486 }
1487 } else if ($type == 'parent') {
1488 $term_data = is_category() ? array(get_term(get_queried_object()->parent, 'category')) : get_terms( $tax_slug, array( 'hide_empty' => true, 'number' => $number, 'parent' => 0 ) );
1489 if($archiveBuilder && !empty($term_data)) {
1490 $term_data = array($term_data[0]);
1491 }
1492 if (!empty($term_data)) {
1493 foreach ($term_data as $terms) {
1494 if (!empty($terms->term_id)) {
1495 $data[] = $this->get_tax_data($terms);
1496 }
1497 }
1498 }
1499 } else if ($type == 'custom') {
1500 foreach ($catSlug as $cat) {
1501 $terms = get_term_by('slug', $cat, $tax_slug);
1502 if (!empty($terms)) {
1503 $data[] = $this->get_tax_data($terms);
1504 }
1505 }
1506 } else if ($type == 'immediate_child') {
1507 if($archiveBuilder) {
1508 $data = $this->builder_preview( $tax_slug, $number );
1509 } else {
1510 $id_ = get_queried_object();
1511 if (isset($id_->term_id)) {
1512 $term_data = get_terms( $tax_slug, array( 'hide_empty' => true, 'number' => 100, 'parent' => $id_->term_id) );
1513 if (!empty($term_data)) {
1514 foreach ($term_data as $terms) {
1515 $data[] = $this->get_tax_data($terms);
1516 }
1517 }
1518 }
1519 }
1520 } else if ($type == 'allchild') {
1521 if($archiveBuilder) {
1522 $data = $this->builder_preview( $tax_slug, $number );
1523 } else {
1524 $id_ = get_queried_object();
1525 if (isset($id_->term_taxonomy_id)) {
1526 $termchildren = get_term_children( $id_->term_taxonomy_id, $tax_slug );
1527 foreach ($termchildren as $key => $value) {
1528 $terms = get_term_by('id', $value, $tax_slug);
1529 $data[] = $this->get_tax_data($terms);
1530 }
1531 }
1532 }
1533 } else if ($type == 'current_level') {
1534 if($archiveBuilder) {
1535 $data = $this->builder_preview( $tax_slug, $number );
1536 } else {
1537 $id_ = get_queried_object();
1538 if (isset($id_->parent)) {
1539 $term_data = get_terms( $tax_slug, array( 'hide_empty' => true, 'number' => $number, 'parent' => $id_->parent ) );
1540 if (!empty($term_data)) {
1541 foreach ($term_data as $terms) {
1542 if ($terms->term_id != $id_->term_id) {
1543 $data[] = $this->get_tax_data($terms);
1544 }
1545 }
1546 }
1547 }
1548 }
1549 } else {
1550 $term_data = get_terms($tax_slug, array('hide_empty' => true, 'number' => $number));
1551 if (!empty($term_data)) {
1552 foreach ($term_data as $terms) {
1553 $data[] = $this->get_tax_data($terms);
1554 }
1555 }
1556 }
1557 return $data;
1558 }
1559
1560
1561 /**
1562 * Get Next Previous HTML
1563 *
1564 * @since v.1.0.0
1565 * @param OBJECT | Taxonomy Object
1566 * @return STRING
1567 */
1568 public function next_prev() {
1569 $html = '';
1570 $html .= '<ul>';
1571 $html .= '<li>';
1572 $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
1573 $html .= ultimate_post()->svg_icon('leftAngle2').'<span class="screen-reader-text">'.esc_html__("Previous", "ultimate-post").'</span>';
1574 $html .= '</a>';
1575 $html .= '</li>';
1576 $html .= '<li>';
1577 $html .= '<a class="ultp-next-action">';
1578 $html .= ultimate_post()->svg_icon('rightAngle2').'<span class="screen-reader-text">'.esc_html__("Next", "ultimate-post").'</span>';
1579 $html .= '</a>';
1580 $html .= '</li>';
1581 $html .= '</ul>';
1582 return $html;
1583 }
1584
1585
1586 /**
1587 * Get Loading HTML
1588 *
1589 * @since v.1.0.0
1590 * @param NULL
1591 * @return STRING
1592 */
1593 public function loading() {
1594 $html = '';
1595 $style = ultimate_post()->get_setting('preloader_style');
1596 if ($style == 'style2') {
1597 $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
1598 } else {
1599 $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>';
1600 }
1601 return '<div class="ultp-loading">'.$html.'</div>';
1602 }
1603
1604
1605 /**
1606 * Get Filter HTML
1607 *
1608 * @since v.1.0.0
1609 * @param | Filter Text (STRING) | Filter Type (STRING) | Filter Value (ARRAY) | Filter Cat (ARRAY) | Filter Tag (ARRAY) |
1610 * @return STRING
1611 */
1612 public function filter($filterText = '', $filterType = '', $filterValue = '[]', $filterMobileText = '...', $filterMobile = true) {
1613 $html = '';
1614 $html .= '<ul '.($filterMobile ? 'class="ultp-flex-menu"' : '').' data-name="'.($filterMobileText ? $filterMobileText : '&nbsp;').'">';
1615 $cat = $this->taxonomy($filterType);
1616 if ($filterText) {
1617 $html .= '<li class="filter-item"><a class="filter-active" data-taxonomy="" href="#">'.$filterText.'</a></li>';
1618 }
1619
1620 if ($filterValue) {
1621 $filterValue = strlen($filterValue) > 2 ? $filterValue : [];
1622 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
1623 if (is_array($filterValue) && count($filterValue)) {
1624 foreach ($filterValue as $val) {
1625 $val = isset($val->value) ? $val->value : $val;
1626 $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($cat[$val]) ? $cat[$val] : $val).'</a></li>';
1627 }
1628 }
1629 }
1630 $html .= '</ul>';
1631 return $html;
1632 }
1633
1634
1635 /**
1636 * Check License Status
1637 *
1638 * @since v.2.4.2
1639 * @return BOOLEAN | Is pro license active or not
1640 */
1641 public function is_lc_active() {
1642 if (function_exists('ultimate_post_pro')) {
1643 return get_option('edd_ultp_license_status') == 'valid' ? true : false;
1644 }
1645 if (get_transient( 'ulpt_theme_enable' ) == 'integration') {
1646 return true;
1647 }
1648 return false;
1649 }
1650
1651
1652 /**
1653 * Get SEO Meta
1654 *
1655 * @since v.2.4.3
1656 * @param NUMBER | Post ID
1657 * @return STRING | SEO Meta Description or Excerpt
1658 */
1659 public function get_excerpt($post_id = 0, $showSeoMeta = 0, $showFullExcerpt = 0, $excerptLimit = 55) {
1660 $html = '';
1661 if ($showSeoMeta) {
1662 $str = '';
1663 if (function_exists('ultimate_post_pro') ) {
1664 if (ultimate_post()->get_setting('ultp_yoast') == 'true') {
1665 $str = method_exists( ultimate_post_pro(), 'get_yoast_meta' ) ? ultimate_post_pro()->get_yoast_meta($post_id) : '';
1666 } else if (ultimate_post()->get_setting('ultp_rankmath') == 'true') {
1667 $str = method_exists( ultimate_post_pro(), 'get_rankmath_meta' ) ? ultimate_post_pro()->get_rankmath_meta($post_id) : '';
1668 } else if (ultimate_post()->get_setting('ultp_aioseo') == 'true') {
1669 $str = method_exists( ultimate_post_pro(), 'get_aioseo_meta' ) ? ultimate_post_pro()->get_aioseo_meta($post_id) : '';
1670 } else if (ultimate_post()->get_setting('ultp_seopress') == 'true') {
1671 $str = method_exists( ultimate_post_pro(), 'get_seopress_meta' ) ? ultimate_post_pro()->get_seopress_meta($post_id) : '';
1672 } else if (ultimate_post()->get_setting('ultp_squirrly') == 'true') {
1673 $str = method_exists( ultimate_post_pro(), 'get_squirrly_meta' ) ? ultimate_post_pro()->get_squirrly_meta($post_id) : '';
1674 }
1675 }
1676 $html = $str ? $str : ultimate_post()->excerpt($post_id, $excerptLimit);
1677 } else {
1678 if ($showFullExcerpt == 0 ) {
1679 $html = ultimate_post()->excerpt($post_id, $excerptLimit);
1680 } else {
1681 $html = get_the_excerpt();
1682 }
1683 }
1684 return $html;
1685 }
1686
1687 /**
1688 * Set Inline CSS
1689 *
1690 * @since v.2.5.8
1691 * @param STRING | CSS
1692 * @return STRING | CSS with Style
1693 */
1694 public function set_inline($css) {
1695 return '<style type="text/css">'.wp_strip_all_tags($css).'</style>';
1696 }
1697
1698 /**
1699 * Array Sanitize Function
1700 *
1701 * @since v.2.6.0
1702 * @param ARRAY
1703 * @return ARRAY | Array of Sanitize
1704 */
1705 public function recursive_sanitize_text_field($array) {
1706 foreach ($array as $key => &$value) {
1707 if (is_array($value)) {
1708 $value = $this->recursive_sanitize_text_field($value);
1709 } else {
1710 $value = sanitize_text_field($value);
1711 }
1712 }
1713 return $array;
1714 }
1715
1716
1717 public function get_embeded_video($url, $autoPlay, $loop, $mute, $playback, $preload, $poster, $inline, $size) {
1718 $vidAutoPlay = $vidloop = $vidloop = $vidmute = $vidplayback = $vidPoster = $vidInline = "";
1719
1720 if($autoPlay){
1721 $vidAutoPlay = "autoplay";
1722 }
1723 if($poster){
1724 $vidPoster = 'poster="'.$poster["url"].'"';
1725 }
1726 if($loop){
1727 $vidloop = "loop";
1728 }
1729 if($mute){
1730 $vidmute = "muted";
1731 }
1732 if($playback){
1733 $vidplayback = "controls";
1734 }
1735 if($inline){
1736 $vidInline = "playsinline";
1737 }
1738 if (!empty($url)) {
1739 $embeded = wp_oembed_get($url, $size);
1740 if ($embeded == false) {
1741 $format = '';
1742 $url = strtolower($url);
1743 if (strpos($url, '.mp4')) {
1744 $format = 'mp4';
1745 } elseif (strpos($url, '.ogg')) {
1746 $format = 'ogg';
1747 } elseif (strpos($url, '.webm')) {
1748 $format = 'WebM';
1749 }
1750 $embeded = '<video
1751 '.$vidloop.'
1752 '.$vidmute.'
1753 '.$vidplayback.'
1754 preload="'.$preload.'"
1755 '.$vidAutoPlay.'
1756 '.$vidPoster.'
1757 '.$vidInline.'
1758 ><source src="' . $url . '" type="video/' . $format . '">' . __('Your browser does not support the video tag.', 'ultimate-post') . '</video>';
1759 return '<div class="ultp-video-wrapper">'.$embeded.'</div>';
1760 }
1761 return '<div class="ultp-video-wrapper ultp-embaded-video">'.$embeded.'</div>';
1762 } else {
1763 return false;
1764 }
1765 }
1766
1767 /**
1768 * Get Public taxonomy Lists
1769 *
1770 * @since v.2.7.0
1771 * @param NULL
1772 * @return ARRAY | Taxonomy Lists as array
1773 */
1774 public function get_taxonomy_list() {
1775 $taxonomy = get_taxonomies(array('public' => true));
1776 return empty($taxonomy) ? [] : array_keys($taxonomy);
1777 }
1778
1779 /**
1780 * Content Print
1781 *
1782 * @since v.2.7.0
1783 * @param NUMBER | Post ID
1784 * @return STRING | Content of the Post
1785 */
1786 public function content($post_id) {
1787 $content_post = get_post($post_id);
1788 $content = $content_post->post_content;
1789 $content = apply_filters('the_content', $content);
1790 $content = str_replace(']]>', ']]&gt;', $content);
1791 echo $content;
1792 }
1793
1794
1795 /**
1796 * String Part finder inside array
1797 *
1798 * @since v.2.7.0
1799 * @return ARRAY | String Part
1800 */
1801 public function in_string_part($part, $data, $isValue = false) {
1802 $return = false;
1803 foreach ($data as $val) {
1804 if (strpos($val, $part) !== false) {
1805 $return = $isValue ? $val : true;
1806 break;
1807 }
1808 }
1809 return $return;
1810 }
1811
1812 /**
1813 * All Addons Data
1814 *
1815 * @since v.2.7.0
1816 * @return ARRAY | String Part
1817 */
1818 public static function all_addons() {
1819 $all_addons = array(
1820 'ultp_category' => array(
1821 'name' => __( 'Category', 'ultimate-post' ),
1822 'desc' => __( 'Choose your desired color and Image for categories or any taxonomy.', 'ultimate-post' ),
1823 'img' => ULTP_URL.'/assets/img/addons/category-style.svg',
1824 'is_pro' => true,
1825 'docs' => 'https://docs.wpxpo.com/docs/postx/',
1826 'live' => 'https://www.wpxpo.com/postx/addons/category/',
1827 'position' => 15
1828 ),
1829 'ultp_progressbar' => array(
1830 'name' => __( 'Progressbar', 'ultimate-post' ),
1831 'desc' => __( 'Let the users see a graphical indicator to know the reading progress of a blog post.', 'ultimate-post' ),
1832 'img' => ULTP_URL.'/assets/img/addons/progressbar.svg',
1833 'is_pro' => true,
1834 'docs' => 'https://docs.wpxpo.com/docs/postx/add-on/progress-bar/',
1835 'live' => 'https://www.wpxpo.com/postx/progress-bar/',
1836 'position' => 30
1837 ),
1838 'ultp_yoast' => array(
1839 'name' => __( 'Yoast Meta', 'ultimate-post' ),
1840 'desc' => __( 'Show Yoast meta description in the excerpt.', 'ultimate-post' ),
1841 'img' => ULTP_URL.'/assets/img/addons/yoast.svg',
1842 'is_pro' => true,
1843 'docs' => 'https://docs.wpxpo.com/docs/postx/add-on/seo-meta/',
1844 'live' => 'https://www.wpxpo.com/postx/addons/yoast/',
1845 'required' => array(
1846 'name' => 'Yoast',
1847 'slug' => 'wordpress-seo/wp-seo.php'
1848 ),
1849 'position' => 55
1850 ),
1851 'ultp_aioseo' => array(
1852 'name' => __( 'All in One SEO Meta', 'ultimate-post' ),
1853 'desc' => __( 'Show All in One SEO meta description in the excerpt.', 'ultimate-post' ),
1854 'img' => ULTP_URL.'/assets/img/addons/aioseo.svg',
1855 'is_pro' => true,
1856 'docs' => 'https://docs.wpxpo.com/docs/postx/add-on/seo-meta/',
1857 'live' => 'https://www.wpxpo.com/postx/addons/all-in-one-seo-meta/',
1858 'required' => array(
1859 'name' => 'All in One SEO',
1860 'slug' => 'all-in-one-seo-pack/all_in_one_seo_pack.php'
1861 ),
1862 'position' => 35
1863 ),
1864 'ultp_rankmath' => array(
1865 'name' => __( 'RankMath Meta', 'ultimate-post' ),
1866 'desc' => __( 'Show RankMath meta description in the excerpt.', 'ultimate-post' ),
1867 'img' => ULTP_URL.'/assets/img/addons/rankmath.svg',
1868 'is_pro' => true,
1869 'docs' => 'https://docs.wpxpo.com/docs/postx/add-on/seo-meta/',
1870 'live' => 'https://www.wpxpo.com/postx/addons/rankmath/',
1871 'required' => array(
1872 'name' => 'RankMath',
1873 'slug' => 'seo-by-rank-math/rank-math.php'
1874 ),
1875 'position' => 40
1876 ),
1877 'ultp_seopress' => array(
1878 'name' => __( 'SEOPress Meta', 'ultimate-post' ),
1879 'desc' => __( 'Show SEOPress meta description in the excerpt.', 'ultimate-post' ),
1880 'img' => ULTP_URL.'/assets/img/addons/seopress.svg',
1881 'is_pro' => true,
1882 'docs' => 'https://docs.wpxpo.com/docs/postx/add-on/seo-meta/',
1883 'live' => 'https://www.wpxpo.com/postx/addons/seopress/',
1884 'required' => array(
1885 'name' => 'SEOPress',
1886 'slug' => 'wp-seopress/seopress.php'
1887 ),
1888 'position' => 45
1889 ),
1890 'ultp_squirrly' => array(
1891 'name' => __( 'Squirrly Meta', 'ultimate-post' ),
1892 'desc' => __( 'Show Squirrly meta description in the excerpt.', 'ultimate-post' ),
1893 'img' => ULTP_URL.'/assets/img/addons/squirrly.svg',
1894 'is_pro' => true,
1895 'docs' => 'https://docs.wpxpo.com/docs/postx/add-on/seo-meta/',
1896 'live' => 'https://www.wpxpo.com/postx/addons/squirrly/',
1897 'required' => array(
1898 'name' => 'Squirrly',
1899 'slug' => 'squirrly-seo/squirrly.php'
1900 ),
1901 'position' => 50
1902 ),
1903 );
1904 return apply_filters('ultp_addons_config', $all_addons);
1905 }
1906
1907 /**
1908 * All Block Data
1909 *
1910 * @since v.2.7.0
1911 * @return ARRAY | String Part
1912 */
1913 public function get_blocks_settings() {
1914 $arr = array(
1915 'grid' => array(
1916 'label' => __('Post Grid Blocks', 'ultimate-post'),
1917 'attr' => array(
1918 'post_grid_1' => array(
1919 'label' => __('Post Grid #1', 'ultimate-post'),
1920 'default' => true,
1921 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6829',
1922 'docs' => 'https://docs.wpxpo.com/docs/postx/',
1923 'icon' => ULTP_URL.'assets/img/blocks/post-grid-1.svg'
1924 ),
1925 'post_grid_2' => array(
1926 'label' => __('Post Grid #2', 'ultimate-post'),
1927 'default' => true,
1928 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6830',
1929 'docs' => 'https://docs.wpxpo.com/docs/postx/',
1930 'icon' => ULTP_URL.'assets/img/blocks/post-grid-2.svg'
1931 ),
1932 'post_grid_3' => array(
1933 'label' => __('Post Grid #3', 'ultimate-post'),
1934 'default' => true,
1935 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6831',
1936 'docs' => 'https://docs.wpxpo.com/docs/postx/',
1937 'icon' => ULTP_URL.'assets/img/blocks/post-grid-3.svg'
1938 ),
1939 'post_grid_4' => array(
1940 'label' => __('Post Grid #4', 'ultimate-post'),
1941 'default' => true,
1942 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6832',
1943 'docs' => 'https://docs.wpxpo.com/docs/postx/',
1944 'icon' => ULTP_URL.'assets/img/blocks/post-grid-4.svg'
1945 ),
1946 'post_grid_5' => array(
1947 'label' => __('Post Grid #5', 'ultimate-post'),
1948 'default' => true,
1949 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6833',
1950 'docs' => 'https://docs.wpxpo.com/docs/postx/',
1951 'icon' => ULTP_URL.'assets/img/blocks/post-grid-5.svg'
1952 ),
1953 'post_grid_6' => array(
1954 'label' => __('Post Grid #6', 'ultimate-post'),
1955 'default' => true,
1956 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6834',
1957 'docs' => 'https://docs.wpxpo.com/docs/postx/',
1958 'icon' => ULTP_URL.'assets/img/blocks/post-grid-6.svg'
1959 ),
1960 'post_grid_7' => array(
1961 'label' => __('Post Grid #7', 'ultimate-post'),
1962 'default' => true,
1963 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6835',
1964 'docs' => 'https://docs.wpxpo.com/docs/postx/',
1965 'icon' => ULTP_URL.'assets/img/blocks/post-grid-7.svg'
1966 )
1967 )
1968 ),
1969 'list' => array(
1970 'label' => __('Post List Blocks', 'ultimate-post'),
1971 'attr' => array(
1972 'post_list_1' => array(
1973 'label' => __('Post List #1', 'ultimate-post'),
1974 'default' => true,
1975 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6836',
1976 'docs' => 'https://docs.wpxpo.com/docs/postx/',
1977 'icon' => ULTP_URL.'assets/img/blocks/post-list-1.svg'
1978 ),
1979 'post_list_2' => array(
1980 'label' => __('Post List #2', 'ultimate-post'),
1981 'default' => true,
1982 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6837',
1983 'docs' => 'https://docs.wpxpo.com/docs/postx/',
1984 'icon' => ULTP_URL.'assets/img/blocks/post-list-2.svg'
1985 ),
1986 'post_list_3' => array(
1987 'label' => __('Post List #3', 'ultimate-post'),
1988 'default' => true,
1989 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6838',
1990 'docs' => 'https://docs.wpxpo.com/docs/postx/',
1991 'icon' => ULTP_URL.'assets/img/blocks/post-list-3.svg'
1992 ),
1993 'post_list_4' => array(
1994 'label' => __('Post List #4', 'ultimate-post'),
1995 'default' => true,
1996 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6839',
1997 'docs' => 'https://docs.wpxpo.com/docs/postx/',
1998 'icon' => ULTP_URL.'assets/img/blocks/post-list-4.svg'
1999 ),
2000
2001 )
2002 ),
2003 'slider' => array(
2004 'label' => __('Post Slider', 'ultimate-post'),
2005 'attr' => array(
2006 'post_slider_1' => array(
2007 'label' => __('Post Slider #1', 'ultimate-post'),
2008 'default' => true,
2009 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6840',
2010 'docs' => 'https://docs.wpxpo.com/docs/postx/',
2011 'icon' => ULTP_URL.'/assets/img/blocks/post-slider-1.svg'
2012 ),
2013 'post_slider_2' => array(
2014 'label' => __('Post Slider #2', 'ultimate-post'),
2015 'default' => true,
2016 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid7487',
2017 'docs' => 'https://docs.wpxpo.com/docs/postx/all-blocks/post-slider-2/',
2018 'icon' => ULTP_URL.'/assets/img/blocks/post-slider-2.svg'
2019 ),
2020 )
2021 ),
2022 'other' => array(
2023 'label' => __('Others Post Blocks', 'ultimate-post'),
2024 'attr' => array(
2025 'post_module_1' => array(
2026 'label' => __('Post Module #1', 'ultimate-post'),
2027 'default' => true,
2028 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6825',
2029 'docs' => 'https://docs.wpxpo.com/docs/postx/',
2030 'icon' => ULTP_URL.'/assets/img/blocks/post-module-1.svg'
2031 ),
2032 'post_module_2' => array(
2033 'label' => __('Post Module #2', 'ultimate-post'),
2034 'default' => true,
2035 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6827',
2036 'docs' => 'https://docs.wpxpo.com/docs/postx/',
2037 'icon' => ULTP_URL.'/assets/img/blocks/post-module-2.svg'
2038 ),
2039 'heading' => array(
2040 'label' => __('Heading', 'ultimate-post'),
2041 'default' => true,
2042 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6842',
2043 'docs' => 'https://docs.wpxpo.com/docs/postx/',
2044 'icon' => ULTP_URL.'/assets/img/blocks/heading.svg'
2045 ),
2046 'image' => array(
2047 'label' => __('Image', 'ultimate-post'),
2048 'default' => true,
2049 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6843',
2050 'docs' => 'https://docs.wpxpo.com/docs/postx/all-blocks/image-blocks/',
2051 'icon' => ULTP_URL.'/assets/img/blocks/image.svg'
2052 ),
2053 'taxonomy' => array(
2054 'label' => __('Taxonomy', 'ultimate-post'),
2055 'default' => true,
2056 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6841',
2057 'docs' => 'https://docs.wpxpo.com/docs/postx/all-blocks/taxonomy-style-1/',
2058 'icon' => ULTP_URL.'/assets/img/blocks/taxonomy.svg'
2059 ),
2060 'wrapper' => array(
2061 'label' => __('Wrapper', 'ultimate-post'),
2062 'default' => true,
2063 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6844',
2064 'docs' => 'https://docs.wpxpo.com/docs/postx/add-on/wrapper-blocks/',
2065 'icon' => ULTP_URL.'/assets/img/blocks/wrapper.svg'
2066 ),
2067 'news_ticker' => array(
2068 'label' => __('News Ticker', 'ultimate-post'),
2069 'default' => true,
2070 'live' => 'https://www.wpxpo.com/postx/blocks/#demoid6845',
2071 'docs' => 'https://docs.wpxpo.com/docs/postx/all-blocks/news-ticker-block/',
2072 'icon' => ULTP_URL.'/assets/img/blocks/news-ticker.svg'
2073 ),
2074 )
2075 ),
2076 'builder' => array(
2077 'label' => __('Site Builder Blocks', 'ultimate-post'),
2078 'attr' => array(
2079 'builder_post_title' => array(
2080 'label' => __('Post Title', 'ultimate-post'),
2081 'default' => true,
2082 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2083 'icon' => ULTP_URL.'/assets/img/blocks/builder/post_title.svg'
2084 ),
2085 'builder_advance_post_meta' => array(
2086 'label' => __('Advance Post Meta', 'ultimate-post'),
2087 'default' => true,
2088 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2089 'icon' => ULTP_URL.'/assets/img/blocks/builder/post_meta.svg'
2090 ),
2091 'builder_archive_title' => array(
2092 'label' => __('Archive Title', 'ultimate-post'),
2093 'default' => true,
2094 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2095 'icon' => ULTP_URL.'/assets/img/blocks/archive-title.svg'
2096 ),
2097 'builder_author_box' => array(
2098 'label' => __('Post Author Box', 'ultimate-post'),
2099 'default' => true,
2100 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2101 'icon' => ULTP_URL.'/assets/img/blocks/builder/author_box.svg'
2102 ),
2103 'builder_post_next_previous' => array(
2104 'label' => __('Post Next Previous', 'ultimate-post'),
2105 'default' => true,
2106 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2107 'icon' => ULTP_URL.'/assets/img/blocks/builder/next_previous.svg'
2108 ),
2109 'builder_post_author_meta' => array(
2110 'label' => __('Post Author Meta', 'ultimate-post'),
2111 'default' => true,
2112 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2113 'icon' => ULTP_URL.'/assets/img/blocks/builder/author.svg'
2114 ),
2115 'builder_post_breadcrumb' => array(
2116 'label' => __('Post Breadcrumb', 'ultimate-post'),
2117 'default' => true,
2118 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2119 'icon' => ULTP_URL.'/assets/img/blocks/builder/breadcrumb.svg'
2120 ),
2121 'builder_post_category' => array(
2122 'label' => __('Post Category', 'ultimate-post'),
2123 'default' => true,
2124 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2125 'icon' => ULTP_URL.'/assets/img/blocks/builder/category.svg'
2126 ),
2127 'builder_post_comment_count' => array(
2128 'label' => __('Post Comment Count', 'ultimate-post'),
2129 'default' => true,
2130 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2131 'icon' => ULTP_URL.'/assets/img/blocks/builder/comment_count.svg'
2132 ),
2133 'builder_post_comments' => array(
2134 'label' => __('Post Comments', 'ultimate-post'),
2135 'default' => true,
2136 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2137 'icon' => ULTP_URL.'/assets/img/blocks/builder/comments.svg'
2138 ),
2139 'builder_post_content' => array(
2140 'label' => __('Post Content', 'ultimate-post'),
2141 'default' => true,
2142 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2143 'icon' => ULTP_URL.'/assets/img/blocks/builder/content.svg'
2144 ),
2145 'builder_post_date_meta' => array(
2146 'label' => __('Post Date Meta', 'ultimate-post'),
2147 'default' => true,
2148 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2149 'icon' => ULTP_URL.'/assets/img/blocks/builder/post_date.svg'
2150 ),
2151 'builder_post_excerpt' => array(
2152 'label' => __('Post Excerpt', 'ultimate-post'),
2153 'default' => true,
2154 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2155 'icon' => ULTP_URL.'/assets/img/blocks/builder/excerpt.svg'
2156 ),
2157 'builder_post_featured_image' => array(
2158 'label' => __('Post Featured Image/Video', 'ultimate-post'),
2159 'default' => true,
2160 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2161 'icon' => ULTP_URL.'/assets/img/blocks/builder/featured_img.svg'
2162 ),
2163 'builder_post_reading_time' => array(
2164 'label' => __('Post Reading Time', 'ultimate-post'),
2165 'default' => true,
2166 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2167 'icon' => ULTP_URL.'/assets/img/blocks/builder/reading_time.svg'
2168 ),
2169 'builder_post_social_share' => array(
2170 'label' => __('Post Social Share', 'ultimate-post'),
2171 'default' => true,
2172 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2173 'icon' => ULTP_URL.'/assets/img/blocks/builder/share.svg'
2174 ),
2175 'builder_post_tag' => array(
2176 'label' => __('Post Tag', 'ultimate-post'),
2177 'default' => true,
2178 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2179 'icon' => ULTP_URL.'/assets/img/blocks/builder/post_tag.svg'
2180 ),
2181 'builder_post_view_count' => array(
2182 'label' => __('Post View Count', 'ultimate-post'),
2183 'default' => true,
2184 'docs' => 'https://docs.wpxpo.com/docs/postx/dynamic-site-builder/',
2185 'icon' => ULTP_URL.'/assets/img/blocks/builder/view_count.svg'
2186 ),
2187 )
2188 )
2189 );
2190
2191 return $arr;
2192 }
2193 /**
2194 * Builder Conditions
2195 *
2196 * @since v.2.7.0
2197 * @param STRING | Type of Return
2198 * @return MIXED || ID or Path
2199 */
2200 public function conditions( $type = 'return' ) {
2201 $page_id = '';
2202
2203 $conditions = get_option('ultp_builder_conditions', array());
2204 if (isset($conditions['archive'])) {
2205 if (!empty($conditions['archive'])) {
2206 $is_search = is_search();
2207 $is_archive = is_archive();
2208 $taxonomy = (is_category() || is_tag() || is_tax()) ? get_queried_object() : (object)[];
2209
2210 if (is_archive()) {
2211 foreach ($conditions['archive'] as $key => $val) {
2212 if (in_array('include/archive', $val)) {
2213 if ('publish' == get_post_status($key)) {
2214 $page_id = $key;
2215 }
2216 }
2217 if (in_array('exclude/archive', $val)) {
2218 if ('publish' == get_post_status($key)) {
2219 $page_id = '';
2220 }
2221 }
2222 }
2223 if (is_category()) {
2224 foreach ($conditions['archive'] as $key => $val) {
2225 if (in_array('include/archive/category', $val)) {
2226 if ('publish' == get_post_status($key)) {
2227 $page_id = $key;
2228 }
2229 }
2230 if (in_array('exclude/archive/category', $val)) {
2231 if ('publish' == get_post_status($key)) {
2232 $page_id = '';
2233 }
2234 }
2235 if (in_array('include/archive/category/'.$taxonomy->term_id, $val)) {
2236 if ('publish' == get_post_status($key)) {
2237 $page_id = $key;
2238 }
2239 }
2240 if (in_array('exclude/archive/category/'.$taxonomy->term_id, $val)) {
2241 if ('publish' == get_post_status($key)) {
2242 $page_id = '';
2243 }
2244 }
2245 if ($this->in_string_part('any_child_of', $val)) {
2246 if (in_array('include/archive/any_child_of_category', $val)) {
2247 if ('publish' == get_post_status($key)) {
2248 $page_id = $key;
2249 }
2250 }
2251 if (in_array('exclude/archive/any_child_of_category', $val)) {
2252 if ('publish' == get_post_status($key)) {
2253 $page_id = '';
2254 }
2255 }
2256 foreach ($val as $v) {
2257 if (strpos($v, '/archive/any_child_of_category/') !== false) {
2258 if ($v) {
2259 $data = explode("/", $v);
2260 if (isset($data[3]) && $data[3]) {
2261 if (term_is_ancestor_of($data[3], $taxonomy->term_id, 'category')) {
2262 if ('publish' == get_post_status($key)) {
2263 $page_id = $data[0] == 'exclude' ? '' : $key;
2264 }
2265 }
2266 }
2267 }
2268 }
2269 }
2270 } else {
2271 if ($this->in_string_part('child_of', $val)) {
2272 if (in_array('include/archive/child_of_category', $val)) {
2273 if ('publish' == get_post_status($key)) {
2274 $page_id = $key;
2275 }
2276 }
2277 if (in_array('exclude/archive/child_of_category', $val)) {
2278 if ('publish' == get_post_status($key)) {
2279 $page_id = '';
2280 }
2281 }
2282 if (in_array('include/archive/child_of_category/'.$taxonomy->parent, $val)) {
2283 if ('publish' == get_post_status($key)) {
2284 $page_id = $key;
2285 }
2286 }
2287 if (in_array('exclude/archive/child_of_category/'.$taxonomy->parent, $val)) {
2288 if ('publish' == get_post_status($key)) {
2289 $page_id = '';
2290 }
2291 }
2292 }
2293 }
2294 }
2295 } else if (is_tag()) {
2296 foreach ($conditions['archive'] as $key => $val) {
2297 if (in_array('include/archive/post_tag', $val)) {
2298 if ('publish' == get_post_status($key)) {
2299 $page_id = $key;
2300 }
2301 }
2302 if (in_array('exclude/archive/post_tag', $val)) {
2303 if ('publish' == get_post_status($key)) {
2304 $page_id = '';
2305 }
2306 }
2307 if (in_array('include/archive/post_tag/'.$taxonomy->term_id, $val)) {
2308 if ('publish' == get_post_status($key)) {
2309 $page_id = $key;
2310 }
2311 }
2312 if (in_array('exclude/archive/post_tag/'.$taxonomy->term_id, $val)) {
2313 if ('publish' == get_post_status($key)) {
2314 $page_id = '';
2315 }
2316 }
2317 }
2318 } else if (is_tax()) {
2319 foreach ($conditions['archive'] as $key => $val) {
2320 if (in_array('include/archive/'.$taxonomy->taxonomy, $val)) {
2321 if ('publish' == get_post_status($key)) {
2322 $page_id = $key;
2323 }
2324 }
2325 if (in_array('exclude/archive/'.$taxonomy->taxonomy, $val)) {
2326 if ('publish' == get_post_status($key)) {
2327 $page_id = '';
2328 }
2329 }
2330 if (in_array('include/archive/'.$taxonomy->taxonomy.'/'.$taxonomy->term_id, $val)) {
2331 if ('publish' == get_post_status($key)) {
2332 $page_id = $key;
2333 }
2334 }
2335 if (in_array('exclude/archive/'.$taxonomy->taxonomy.'/'.$taxonomy->term_id, $val)) {
2336 if ('publish' == get_post_status($key)) {
2337 $page_id = '';
2338 }
2339 }
2340 if ($this->in_string_part('any_child_of', $val)) {
2341 if (in_array('include/archive/any_child_of_'.$taxonomy->taxonomy, $val)) {
2342 if ('publish' == get_post_status($key)) {
2343 $page_id = $key;
2344 }
2345 }
2346 if (in_array('exclude/archive/any_child_of_'.$taxonomy->taxonomy, $val)) {
2347 if ('publish' == get_post_status($key)) {
2348 $page_id = '';
2349 }
2350 }
2351 foreach ($val as $v) {
2352 if (strpos($v, '/archive/any_child_of_'.$taxonomy->taxonomy.'/') !== false) {
2353 if ($v) {
2354 $data = explode("/", $v);
2355 if (isset($data[3]) && $data[3]) {
2356 if (term_is_ancestor_of($data[3], $taxonomy->term_id, $taxonomy->taxonomy)) {
2357 if ('publish' == get_post_status($key)) {
2358 $page_id = $data[0] == 'exclude' ? '' : $key;
2359 }
2360 }
2361 }
2362 }
2363 }
2364 }
2365 } else {
2366 if ($this->in_string_part('child_of', $val)) {
2367 if (in_array('include/archive/child_of_'.$taxonomy->taxonomy, $val)) {
2368 if ('publish' == get_post_status($key)) {
2369 $page_id = $key;
2370 }
2371 }
2372 if (in_array('exclude/archive/child_of_'.$taxonomy->taxonomy, $val)) {
2373 if ('publish' == get_post_status($key)) {
2374 $page_id = '';
2375 }
2376 }
2377 if (in_array('include/archive/child_of_'.$taxonomy->taxonomy.'/'.$taxonomy->parent, $val)) {
2378 if ('publish' == get_post_status($key)) {
2379 $page_id = $key;
2380 }
2381 }
2382 if (in_array('exclude/archive/child_of_'.$taxonomy->taxonomy.'/'.$taxonomy->parent, $val)) {
2383 if ('publish' == get_post_status($key)) {
2384 $page_id = '';
2385 }
2386 }
2387 }
2388 }
2389 }
2390 } else if (is_date()) {
2391 foreach ($conditions['archive'] as $key => $val) {
2392 if (in_array('include/archive/date', $val)) {
2393 if ('publish' == get_post_status($key)) {
2394 $page_id = $key;
2395 }
2396 }
2397 if (in_array('exclude/archive/date', $val)) {
2398 if ('publish' == get_post_status($key)) {
2399 $page_id = '';
2400 }
2401 }
2402 }
2403 } else if (is_author()) {
2404 foreach ($conditions['archive'] as $key => $val) {
2405 if (in_array('include/archive/author', $val)) {
2406 if ('publish' == get_post_status($key)) {
2407 $page_id = $key;
2408 }
2409 }
2410 if (in_array('exclude/archive/author', $val)) {
2411 if ('publish' == get_post_status($key)) {
2412 $page_id = '';
2413 }
2414 }
2415 $author_id = get_the_author_meta('ID');
2416 if (in_array('include/archive/author/'.$author_id, $val)) {
2417 if ('publish' == get_post_status($key)) {
2418 $page_id = $key;
2419 }
2420 }
2421 if (in_array('exclude/archive/author/'.$author_id, $val)) {
2422 if ('publish' == get_post_status($key)) {
2423 $page_id = '';
2424 }
2425 }
2426 }
2427 }
2428 } else if (is_search()) {
2429 foreach ($conditions['archive'] as $key => $val) {
2430 if (in_array('include/archive/search', $val)) {
2431 if ('publish' == get_post_status($key)) {
2432 $page_id = $key;
2433 }
2434 }
2435 if (in_array('exclude/archive/search', $val)) {
2436 if ('publish' == get_post_status($key)) {
2437 $page_id = '';
2438 }
2439 }
2440 }
2441 }
2442 }
2443 }
2444 // Singular
2445 if (isset($conditions['singular'])) {
2446 if (!empty($conditions['singular']) && ( is_singular() || is_front_page() || is_home() ) ) {
2447 $obj = get_queried_object();
2448 $tax_list = $this->get_taxonomy_list();
2449 foreach ($conditions['singular'] as $key => $val) {
2450 if (get_post_status($key)) {
2451 // Front Page
2452 if ((is_front_page() && is_home())
2453 || (is_home() && !is_object($obj))
2454 || (is_singular() && is_front_page() && is_object($obj))) {
2455 if (in_array('include/singular/front_page', $val)) {
2456 if ('publish' == get_post_status($key)) {
2457 $page_id = $key;
2458 }
2459 }
2460 if (in_array('exclude/singular/front_page', $val)) {
2461 if ('publish' == get_post_status($key)) {
2462 $page_id = '';
2463 }
2464 }
2465 }
2466 // Author check
2467 if (in_array('singular/post_by_author', $val)) {
2468 if (in_array('include/singular/post_by_author', $val)) {
2469 if ('publish' == get_post_status($key)) {
2470 $page_id = $key;
2471 }
2472 }
2473 if (in_array('exclude/singular/post_by_author', $val)) {
2474 if ('publish' == get_post_status($key)) {
2475 $page_id = '';
2476 }
2477 }
2478 if (in_array('include/singular/post_by_author/'.$obj->post_author, $val)) {
2479 if ('publish' == get_post_status($key)) {
2480 $page_id = $key;
2481 }
2482 }
2483 if (in_array('exclude/singular/post_by_author/'.$obj->post_author, $val)) {
2484 if ('publish' == get_post_status($key)) {
2485 $page_id = '';
2486 }
2487 }
2488 }
2489 // All Taxonomy
2490 if($this->in_string_part('/singular/in_', $val)) {
2491 foreach ($tax_list as $tax) {
2492 if ($this->in_string_part('singular/in_'.$tax.'_children', $val)) {
2493 // In Taxonomy Children
2494 if (in_array('include/singular/in_'.$tax.'_children', $val)) {
2495 if ('publish' == get_post_status($key)) {
2496 $page_id = $key;
2497 }
2498 }
2499 if (in_array('exclude/singular/in_'.$tax.'_children', $val)) {
2500 if ('publish' == get_post_status($key)) {
2501 $page_id = '';
2502 }
2503 }
2504 if (is_object($obj)) {
2505 foreach ($val as $v) {
2506 if (strpos($v, '/singular/in_'.$tax.'_children/') !== false) {
2507 if ($v) {
2508 $data = explode("/", $v);
2509 if (isset($data[3]) && $data[3]) {
2510 if (is_object_in_term($obj->ID , $tax, $data[3] )) {
2511 if ('publish' == get_post_status($key)) {
2512 $page_id = $data[0] == 'exclude' ? '' : $key;
2513 }
2514 }
2515 }
2516 }
2517 }
2518 }
2519 }
2520 } else {
2521 // IN Taxonomy
2522 if (in_array('include/singular/in_'.$tax, $val)) {
2523 if ('publish' == get_post_status($key)) {
2524 $page_id = $key;
2525 }
2526 }
2527 if (in_array('exclude/singular/in_'.$tax, $val)) {
2528 if ('publish' == get_post_status($key)) {
2529 $page_id = '';
2530 }
2531 }
2532 if (is_object($obj)) {
2533 foreach ($val as $v) {
2534 if (strpos($v, '/singular/in_'.$tax.'/') !== false) {
2535 if ($v) {
2536 $data = explode("/", $v);
2537 if (isset($data[3]) && $data[3]) {
2538 if (is_object_in_term($obj->ID , $tax, $data[3] )) {
2539 if ('publish' == get_post_status($key)) {
2540 $page_id = $data[0] == 'exclude' ? '' : $key;
2541 }
2542 }
2543 }
2544 }
2545 }
2546 }
2547 }
2548 }
2549 }
2550 }
2551 if (is_object($obj)) {
2552 // All Post Type
2553 if (in_array('include/singular/'.$obj->post_type, $val)) {
2554 if ('publish' == get_post_status($key)) {
2555 $page_id = $key;
2556 }
2557 }
2558 if (in_array('exclude/singular/'.$obj->post_type, $val)) {
2559 if ('publish' == get_post_status($key)) {
2560 $page_id = '';
2561 }
2562 }
2563 if ($this->in_string_part('include/singular/'.$obj->post_type.'/'.$obj->ID, $val)) {
2564 if ('publish' == get_post_status($key)) {
2565 $page_id = $key;
2566 }
2567 }
2568 if ($this->in_string_part('exclude/singular/'.$obj->post_type.'/'.$obj->ID, $val)) {
2569 if ('publish' == get_post_status($key)) {
2570 $page_id = '';
2571 }
2572 }
2573 }
2574 }
2575 }
2576 }
2577 }
2578
2579 if ($type == 'return') {
2580 return $page_id;
2581 }
2582 if ($type == 'includes') {
2583 return $page_id ? ULTP_PATH.'addons/builder/Archive_Template.php' : '';
2584 }
2585 }
2586
2587
2588 /**
2589 * Get Add Default Condition Data
2590 *
2591 * @since v.2.7.0
2592 * @return ARRAY | Default Data
2593 */
2594 public function builder_data() {
2595 $archive_data = [
2596 [
2597 'label' => 'All Archive',
2598 'value' => '',
2599 ],
2600 [
2601 'label' => 'Author Archive',
2602 'value' => 'author',
2603 'search' => 'author###'
2604 ],
2605 [
2606 'label' => 'Date Archive',
2607 'value' => 'date',
2608 ],
2609 [
2610 'label' => 'Search Results',
2611 'value' => 'search',
2612 ],
2613 ];
2614 $single_data = [
2615 [
2616 'label' => 'Front Page',
2617 'value' => 'front_page',
2618 ]
2619 ];
2620
2621 $post_type = get_post_types( ['public' => true], 'objects' );
2622 foreach ($post_type as $key => $type) {
2623 // Post Type
2624 $single_temp = [
2625 'label' => $type->label,
2626 'value' => $type->name,
2627 'search' => 'type###'.$type->name
2628 ];
2629 $archive_temp = [];
2630
2631 // Taxonomy
2632 $taxonomy = get_object_taxonomies( $type->name, 'objects' );
2633 if (!empty($taxonomy)) {
2634 $single_tax = $archive_tax = [];
2635 $single_tax[] = $single_temp;
2636
2637 $archive_temp = [
2638 'label' => $type->label . ' Archive',
2639 'value' => $type->name . '_archive',
2640 ];
2641 // $archive_tax[] = $archive_temp;
2642 foreach ($taxonomy as $key => $val) {
2643 if ($val->public) {
2644 $single_tax[] = [
2645 'label' => 'In ' . $val->label,
2646 'value' => 'in_' . $val->name,
2647 'search' => 'term###'.$val->name
2648 ];
2649 $archive_tax[] = [
2650 'label' => $val->label,
2651 'value' => $val->name,
2652 'search' => 'term###'.$val->name
2653 ];
2654
2655 if ($val->hierarchical) {
2656 // Hierarchical
2657 $single_tax[] = [
2658 'label' => 'In Child ' . $val->label,
2659 'value' => 'in_' . $val->name . '_children',
2660 'search' => 'term###'.$val->name
2661 ];
2662 $archive_tax[] = [
2663 'label' => 'Direct Child ' . $val->label . ' Of',
2664 'value' => 'child_of_' . $val->name,
2665 'search' => 'term###'.$val->name
2666 ];
2667 $archive_tax[] = [
2668 'label' => 'Any Child ' . $val->label . ' Of',
2669 'value' => 'any_child_of_' . $val->name,
2670 'search' => 'term###'.$val->name
2671 ];
2672 }
2673 }
2674 }
2675 // Author
2676 $single_tax[] = [
2677 'label' => 'Posts By Author',
2678 'value' => 'post_by_author',
2679 'search' => 'author###'
2680 ];
2681 $single_temp['attr'] = $single_tax;
2682 $archive_temp['attr'] = $archive_tax;
2683 }
2684 $single_data[] = $single_temp;
2685 if (!empty($archive_temp)) {
2686 $archive_data[] = $archive_temp;
2687 }
2688 }
2689
2690 return ['singular' => $single_data, 'archive' => $archive_data];
2691 }
2692
2693 /**
2694 * Get Date Default Format
2695 *
2696 * @since v.2.7.2
2697 * @return ARRAY | Default Data
2698 */
2699 public function get_format($format) {
2700 if ($format == 'default_date') {
2701 return $this->get_setting('date_format');
2702 } else if ($format == 'default_date_time') {
2703 return $this->get_setting('date_format').' '.$this->get_setting('time_format');
2704 } else {
2705 return $format;
2706 }
2707 }
2708
2709 public function pro_popup_html() { ?>
2710 <div class="ultp-popup-container popup-center">
2711 <div class="ultp-unlock-popup ultp-unlock-modal">
2712 <img src="<?php echo esc_url(ULTP_URL . '/assets/img/admin/dashboard/unlock-super-icon.svg'); ?>" alt="lock icon">
2713 <h4 class="ultp-md-heading ultp-mt25 ultp-mb25"><?php esc_html_e('Unlock 11+ Addons', 'ultimate-post'); ?></h4>
2714 <div class="ultp-popup-desc">
2715 <?php esc_html_e('We’re sorry, all PostX addons are not available on the free version. Please upgrade to a PRO plan to unlock all the addons of your choice.', 'ultimate-post'); ?>
2716 </div>
2717 <a href="<?php echo esc_url(ultimate_post()->get_premium_link('', 'menu_addons_popup')); ?>" class="ultp-popup-planbtn ultp-btn ultp-btn-warning ultp-mt25"><?php esc_html_e('Upgrade Plan', 'ultimate-post'); ?></a>
2718 <button class="ultp-popup-close"></button>
2719 </div>
2720 </div>
2721 <?php }
2722
2723 /**
2724 * Common Frontend and Backend CSS and JS Scripts
2725 *
2726 * @since v.1.0.0
2727 * @return NULL
2728 */
2729 public function register_scripts_common() {
2730 wp_enqueue_style('ultp-style', ULTP_URL.'assets/css/style.min.css', array(), ULTP_VER );
2731 wp_enqueue_script('ultp-script', ULTP_URL.'assets/js/ultp.min.js', array('jquery'), ULTP_VER, true);
2732 wp_localize_script('ultp-script', 'ultp_data_frontend', array(
2733 'url' => ULTP_URL,
2734 'ajax' => admin_url('admin-ajax.php'),
2735 'security' => wp_create_nonce('ultp-nonce')
2736 ));
2737 }
2738
2739 /**
2740 * Get Page Post Id ( Kadence elemwnt )
2741 *
2742 * @since v.2.8.9
2743 * @return NULL
2744 */
2745 public function get_page_post_id($page_post_id, $blockId) {
2746 global $wpdb;
2747 $post_meta = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "postmeta WHERE meta_value LIKE %s", '%.ultp-block-'.$blockId.'%'));
2748 if($post_meta && isset($post_meta->post_id) && $post_meta->post_id != $page_post_id) {
2749 return $post_meta->post_id;
2750 }
2751 return $page_post_id;
2752 }
2753
2754 /**
2755 * Get Notice Data
2756 *
2757 * @since v.2.9.0
2758 * @return NULL
2759 */
2760 public function get_notice_data($type = 'banner') {
2761 if ($type == 'banner') {
2762 return array(
2763 array(
2764 'start' => '16-04-2023',
2765 'end' => '28-04-2023',
2766 'type' => 'content',
2767 'content' => "<p>EID Is Here! </p> <p>Let's Celebrate Together</p> <p class=".'ultp-enjoy-offer'.">Enjoy Up To 50% OFF on PostX Pro!</p> <a href=".ultimate_post()->get_premium_link('','dashboard_db_banner')." target=".'_blank'." class=".'ultp-get-now'.">GET IT NOW</a> <a href=".esc_url( add_query_arg( 'disable_postx_notice_v12', 'yes' ) )." class=".'ultp-dismiss'.">Dismiss</a>",
2768 'force' => true
2769 ),
2770 array(
2771 'start' => '12-2-2023', // Date format "d-m-Y" [08-02-2019]
2772 'end' => '18-2-2023',
2773 'type' => 'banner',
2774 'content' => ULTP_URL.'assets/img/banner.jpg',
2775 'force' => true
2776 ),
2777 // array(
2778 // 'start' => '17-4-2023', // Date format "d-m-Y" [08-02-2019]
2779 // 'end' => '27-4-2023',
2780 // 'type' => 'banner',
2781 // 'content' => ULTP_URL.'assets/img/eid-banner.jpg',
2782 // 'force' => true
2783 // )
2784 );
2785 } else {
2786 return array(
2787 // 'start' => '12-2-2023', // Date format "d-m-Y" [08-02-2019]
2788 // 'end' => '22-3-2023',
2789 // 'content' => 'Upgrade 30% off Sale!!!'
2790 );
2791 }
2792 }
2793 /**
2794 * Get no Result found html
2795 *
2796 * @since v.2.9.0
2797 * @param STRING | No result found text
2798 * @return STRING | Taxonomy Lists as array
2799 */
2800 public function get_no_result_found_html($text) {
2801 return $text ? '<div class="ultp-not-found-message" role="alert">'.$text.'</div>' : '';
2802 }
2803
2804 }
2805