PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.5.6
Post Grid Gutenberg Blocks – PostX v2.5.6
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
← All changes | classes/Functions.php +976 -119 2.1.22.5.6 View file →
@@ -1,15 +1,294 @@
1 1 <?php
2 +/**
3 + * Common Functions.
4 + *
5 + * @package ULTP\Functions
6 + * @since v.1.0.0
7 + */
2 8 namespace ULTP;
3 9
4 10 defined('ABSPATH') || exit;
5 11
12 +/**
13 + * Functions class.
14 + */
15 +
6 16 class Functions{
7 17
8 - public function __construct(){
9 - $GLOBALS['ultp_settings'] = get_option('ultp_options');
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 + }
10 27 }
11 28
29 + /**
30 + * ID for the Builder Post or Normal Post
31 + *
32 + * @since v.2.3.1
33 + * @return NUMBER | is Builder or not
34 + */
35 + public function get_ID() {
36 + $id = $this->is_builder();
37 + return $id ? $id : (function_exists('is_shop') ? (is_shop() ? wc_get_page_id('shop') : get_the_ID()) : get_the_ID() );
38 + }
39 +
40 + /**
41 + * Checking Statement of Archive Builder
42 + *
43 + * @since v.2.3.1
44 + * @return BOOLEAN | is Builder or not
45 + */
46 + public function is_archive_builder() {
47 + return get_post_type( get_the_ID() ) == 'ultp_builder' ? true : false;
48 + }
49 +
50 +
51 + /**
52 + * Set Link with the Parameters
53 + *
54 + * @since v.1.1.0
55 + * @return STRING | URL with Arg
56 + */
57 + public function get_premium_link( $url = 'https://www.wpxpo.com/postx/pricing/' ) {
58 + $affiliate_id = apply_filters( 'ultp_affiliate_id', FALSE );
59 + $arg = array( 'utm_source' => 'go_premium' );
60 + if ( ! empty( $affiliate_id ) ) {
61 + $arg[ 'ref' ] = esc_attr( $affiliate_id );
62 + }
63 + return add_query_arg( $arg, $url );
64 + }
65 +
66 +
67 + /**
68 + * Get Width and Height of the Image
69 + *
70 + * @since v.1.1.0
71 + * @return STRING | Image Size
72 + */
73 + public function get_size($name = ''){
74 + global $_wp_additional_image_sizes;
75 + $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];
76 +
77 + return ' width="'.$image_size['width'].'" height="'.$image_size['height'].'" ';
78 + }
79 +
80 +
81 + /**
82 + * Image Placeholder
83 + *
84 + * @since v.1.1.0
85 + * @return STRING | Image Placeholder
86 + */
87 + public function img_placeholder($type = 'small') {
88 + switch ($type) {
89 + case 'small':
90 + return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG4AAABLAQMAAACr9CA9AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABZJREFUOI1jYMADmEe5o9xR7iiXQi4A4BsA388WUyMAAAAASUVORK5CYII=';
91 + break;
92 +
93 + case 'wide':
94 + return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAKCAYAAADVTVykAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAB9JREFUeNpi/P//P8NAAiaGAQajDhh1wKgDRh0AEGAAQTcDEcKDrpMAAAAASUVORK5CYII=';
95 + break;
96 +
97 + case 'square':
98 + return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAApJREFUCJljYAAAAAIAAfRxZKYAAAAASUVORK5CYII=';
99 + break;
100 +
101 + case 'slider':
102 + return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKYAAABkCAMAAAA7drv6AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF////AAAAVcLTfgAAAAF0Uk5TAEDm2GYAAAAqSURBVHja7MEBDQAAAMKg909tDjegAAAAAAAAAAAAAAAAAAAAAH5NgAEAQTwAAWZtItYAAAAASUVORK5CYII=';
103 + break;
104 +
105 + default:
106 + return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYYAAADcAQMAAABOLJSDAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAACJJREFUaIHtwTEBAAAAwqD1T20ND6AAAAAAAAAAAAAA4N8AKvgAAUFIrrEAAAAASUVORK5CYII=';
107 + break;
108 + }
109 + }
110 +
111 +
112 + /**
113 + * Quick Query
114 + *
115 + * @since v.1.1.0
116 + * @return ARRAY | Query Arg
117 + */
118 + public function get_quick_query($prams, $args) {
119 + switch ($prams['queryQuick']) {
120 + case 'related_posts':
121 + global $post;
122 + if (isset($post->ID)) {
123 + $args['post__not_in'] = array($post->ID);
124 + }
125 + break;
126 + case 'related_tag':
127 + global $post;
128 + if (isset($post->ID)) {
129 + $args['tax_query'] = array(
130 + array(
131 + 'taxonomy' => 'post_tag',
132 + 'terms' => $this->get_terms_id($post->ID, 'post_tag'),
133 + 'field' => 'term_id',
134 + )
135 + );
136 + $args['post__not_in'] = array($post->ID);
137 + }
138 + break;
139 + case 'related_category':
140 + global $post;
141 + if (isset($post->ID)) {
142 + $args['tax_query'] = array(
143 + array(
144 + 'taxonomy' => 'category',
145 + 'terms' => $this->get_terms_id($post->ID, 'category'),
146 + 'field' => 'term_id',
147 + )
148 + );
149 + $args['post__not_in'] = array($post->ID);
150 + }
151 + break;
152 + case 'related_cat_tag':
153 + global $post;
154 + if (isset($post->ID)) {
155 + $args['tax_query'] = array(
156 + array(
157 + 'taxonomy' => 'post_tag',
158 + 'terms' => $this->get_terms_id($post->ID, 'post_tag'),
159 + 'field' => 'term_id',
160 + ),
161 + array(
162 + 'taxonomy' => 'category',
163 + 'terms' => $this->get_terms_id($post->ID, 'category'),
164 + 'field' => 'term_id',
165 + )
166 + );
167 + $args['post__not_in'] = array($post->ID);
168 + }
169 + break;
170 + case 'sticky_posts':
171 + $sticky = get_option('sticky_posts');
172 + if (is_array($sticky)) {
173 + rsort($sticky);
174 + $sticky = array_slice($sticky, 0, $args['posts_per_page']);
175 + }
176 + $args['ignore_sticky_posts'] = 1;
177 + $args['post__in'] = $sticky;
178 + break;
179 + case 'latest_post_published':
180 + $args['orderby'] = 'date';
181 + $args['order'] = 'DESC';
182 + $args['ignore_sticky_posts'] = 1;
183 + break;
184 + case 'latest_post_modified':
185 + $args['orderby'] = 'modified';
186 + $args['order'] = 'DESC';
187 + $args['ignore_sticky_posts'] = 1;
188 + break;
189 + case 'oldest_post_published':
190 + $args['orderby'] = 'date';
191 + $args['order'] = 'ASC';
192 + break;
193 + case 'oldest_post_modified':
194 + $args['orderby'] = 'modified';
195 + $args['order'] = 'ASC';
196 + break;
197 + case 'alphabet_asc':
198 + $args['orderby'] = 'title';
199 + $args['order'] = 'ASC';
200 + break;
201 + case 'alphabet_desc':
202 + $args['orderby'] = 'title';
203 + $args['order'] = 'DESC';
204 + break;
205 + case 'random_post':
206 + $args['orderby'] = 'rand';
207 + $args['order'] = 'ASC';
208 + break;
209 + case 'random_post_7_days':
210 + $args['orderby'] = 'rand';
211 + $args['order'] = 'ASC';
212 + $args['date_query'] = array( array( 'after' => '1 week ago') );
213 + break;
214 + case 'random_post_30_days':
215 + $args['orderby'] = 'rand';
216 + $args['order'] = 'ASC';
217 + $args['date_query'] = array( array( 'after' => '1 month ago') );
218 + break;
219 + case 'most_comment':
220 + $args['orderby'] = 'comment_count';
221 + $args['order'] = 'DESC';
222 + break;
223 + case 'most_comment_1_day':
224 + $args['orderby'] = 'comment_count';
225 + $args['order'] = 'DESC';
226 + $args['date_query'] = array( array( 'after' => '1 day ago') );
227 + break;
228 + case 'most_comment_7_days':
229 + $args['orderby'] = 'comment_count';
230 + $args['order'] = 'DESC';
231 + $args['date_query'] = array( array( 'after' => '1 week ago') );
232 + break;
233 + case 'most_comment_30_days':
234 + $args['orderby'] = 'comment_count';
235 + $args['order'] = 'DESC';
236 + $args['date_query'] = array( array( 'after' => '1 month ago') );
237 + break;
238 + case 'popular_post_1_day_view':
239 + $args['meta_key'] = '__post_views_count';
240 + $args['orderby'] = 'meta_value meta_value_num';
241 + $args['order'] = 'DESC';
242 + $args['date_query'] = array( array( 'after' => '1 day ago') );
243 + break;
244 + case 'popular_post_7_days_view':
245 + $args['meta_key'] = '__post_views_count';
246 + $args['orderby'] = 'meta_value meta_value_num';
247 + $args['order'] = 'DESC';
248 + $args['date_query'] = array( array( 'after' => '1 week ago') );
249 + break;
250 + case 'popular_post_30_days_view':
251 + $args['meta_key'] = '__post_views_count';
252 + $args['orderby'] = 'meta_value meta_value_num';
253 + $args['order'] = 'DESC';
254 + $args['date_query'] = array( array( 'after' => '1 month ago') );
255 + break;
256 + case 'popular_post_all_times_view':
257 + $args['meta_key'] = '__post_views_count';
258 + $args['orderby'] = 'meta_value meta_value_num';
259 + $args['order'] = 'DESC';
260 + break;
261 + default:
262 + # code...
263 + break;
264 + }
265 + return $args;
266 + }
267 +
268 + /**
269 + * Get All Term ID as Array
270 + *
271 + * @since v.2.4.12
272 + * @return ARRAY | Query Arg
273 + */
274 + public function get_terms_id($id, $type) {
275 + $data = array();
276 + $arr = get_the_terms($id, $type);
277 + if (is_array($arr)) {
278 + foreach ($arr as $key => $val) {
279 + $data[] = $val->term_id;
280 + }
281 + }
282 + return $data;
283 + }
284 +
285 + /**
286 + * Get All Reusable ID
287 + *
288 + * @since v.1.1.0
289 + * @return ARRAY | Query Arg
290 + */
12 291 public function reusable_id($post_id){
13 292 $reusable_id = array();
14 293 if($post_id){
15 294 $post = get_post($post_id);
@@ -24,9 +303,16 @@
24 303 }
25 304 return $reusable_id;
26 305 }
27 306
28 - public function set_css_style($post_id){
307 +
308 + /**
309 + * Set CSS Style
310 + *
311 + * @since v.1.1.0
312 + * @return ARRAY | Query Arg
313 + */
314 + public function set_css_style($post_id, $shortcode = false){
29 315 if( $post_id ){
30 316 $upload_dir_url = wp_get_upload_dir();
31 317 $upload_css_dir_url = trailingslashit( $upload_dir_url['basedir'] );
32 318 $css_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
@@ -50,20 +336,32 @@
50 336 }
51 337 }
52 338 }
53 339
54 - if ( file_exists( $css_dir_path ) ) {
55 - $css_url = $css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
56 - wp_enqueue_style( "ultp-post-{$post_id}", $css_url, array(), ULTP_VER, 'all' );
57 - } else {
58 - $css = get_post_meta($post_id, '_ultp_css', true);
59 - if( $css ) {
60 - wp_enqueue_style("ultp-post-{$post_id}", $css, false, ULTP_VER);
61 - }
62 - }
340 + if (isset($_GET['et_fb']) || (isset($_GET['action']) && $_GET['action'] =='elementor') || $shortcode) {
341 + return '<style type="text/css">'.get_post_meta($post_id, '_ultp_css', true).'</style>';
342 + } else {
343 + if ( file_exists( $css_dir_path ) ) {
344 + $css_url = $css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
345 + wp_enqueue_style( "ultp-post-{$post_id}", $css_url, array(), ULTP_VER, 'all' );
346 + } else {
347 + $css = get_post_meta($post_id, '_ultp_css', true);
348 + if( $css ) {
349 + wp_enqueue_style("ultp-post-{$post_id}", $css, false, ULTP_VER);
350 + }
351 + }
352 + }
63 353 }
64 354 }
65 355
356 +
357 + /**
358 + * Get Global Plugin Settings
359 + *
360 + * @since v.1.0.0
361 + * @param STRING | Key of the Option
362 + * @return ARRAY | STRING
363 + */
66 364 public function get_setting($key = ''){
67 365 $data = $GLOBALS['ultp_settings'];
68 366 if ($key != '') {
69 367 return isset($data[$key]) ? $data[$key] : '';
@@ -71,8 +369,16 @@
71 369 return $data;
72 370 }
73 371 }
74 372
373 +
374 + /**
375 + * Set Option Settings
376 + *
377 + * @since v.1.0.0
378 + * @param STRING | Key of the Option (STRING), Value (STRING)
379 + * @return NULL
380 + */
75 381 public function set_setting($key = '', $val = '') {
76 382 if($key != ''){
77 383 $data = $GLOBALS['ultp_settings'];
78 384 $data[$key] = $val;
@@ -80,58 +386,82 @@
80 386 $GLOBALS['ultp_settings'] = $data;
81 387 }
82 388 }
83 389
84 - public function get_image_html($url = '', $size = 'full', $class = '', $alt = ''){
390 +
391 + /**
392 + * Get Image HTML
393 + *
394 + * @since v.1.0.0
395 + * @param | URL (STRING) | size (STRING) | class (STRING) | alt (STRING)
396 + * @return STRING
397 + */
398 + public function get_image_html($url = '', $size = 'full', $class = '', $alt = '', $lazy = ''){
85 399 $alt = $alt ? ' alt="'.$alt.'" ' : '';
86 - if( function_exists('ultimate_post_pro') ){
87 - $addon_enable = ultimate_post()->get_setting();
88 - if(isset($addon_enable['addons_imageloading']) && $addon_enable['addons_imageloading'] == 'true'){
89 - $class = $class ? ' class="ultp-lazy '.$class.'" ' : ' class="ultp-lazy" ';
90 - return '<img loading="lazy" loading="lazy" '.$class.$alt.' '.ultimate_post_pro()->get_size($size).' src="'.ultimate_post_pro()->img_placeholder($size).'" data-src="'.$url.'"/>';
91 - }else{
92 - $class = $class ? ' class="'.$class.'" ' : '';
93 - return '<img loading="lazy" '.$class.$alt.' src="'.$url.'" />';
94 - }
95 - } else {
96 - $class = $class ? ' class="'.$class.'" ' : '';
97 - return '<img loading="lazy" '.$class.$alt.' src="'.$url.'" />';
98 - }
400 + $lazy_data = $lazy ? ' loading="lazy"' : '';
401 + $class = $class ? ' class="'.$class.'" ' : '';
402 + return '<img '.$lazy_data.$class.$alt.' src="'.$url.'" />';
99 403 }
100 404
101 - public function get_image($attach_id, $size = 'full', $class = '', $alt = ''){
405 +
406 + /**
407 + * Get Image HTML
408 + *
409 + * @since v.1.0.0
410 + * @param | Attach ID (STRING) | size (STRING) | class (STRING) | alt (STRING)
411 + * @return STRING
412 + */
413 + public function get_image($attach_id, $size = 'full', $class = '', $alt = '', $srcset = '', $lazy = ''){
102 414 $alt = $alt ? ' alt="'.$alt.'" ' : '';
103 - if( function_exists('ultimate_post_pro') ){
104 - $addon_enable = ultimate_post()->get_setting();
105 - if(isset($addon_enable['addons_imageloading']) && $addon_enable['addons_imageloading'] == 'true'){
106 - $class = $class ? ' class="ultp-lazy '.$class.'" ' : ' class="ultp-lazy" ';
107 - return '<img loading="lazy" '.$class.$alt.' '.ultimate_post_pro()->get_size($size).' src="'.ultimate_post_pro()->img_placeholder($size).'" data-src="'.wp_get_attachment_image_url( $attach_id, $size ).'"/>';
108 - }else{
109 - $class = $class ? ' class="'.$class.'" ' : '';
110 - return '<img loading="lazy" '.$class.$alt.' src="'.wp_get_attachment_image_url( $attach_id, $size ).'" />';
111 - }
112 - } else {
113 - $class = $class ? ' class="'.$class.'" ' : '';
114 - return '<img loading="lazy" '.$class.$alt.' src="'.wp_get_attachment_image_url( $attach_id, $size ).'" />';
115 - }
415 + $class = $class ? ' class="'.$class.'" ' : '';
416 + $size = ( ultimate_post()->get_setting('disable_image_size') == 'yes' && strpos($size, 'ultp_layout_') !== false ) ? 'full' : $size;
417 + $lazy_data = $lazy ? ' loading="lazy"' : '';
418 + $srcset_data = $srcset ? ' srcset="'.esc_attr(wp_get_attachment_image_srcset($attach_id)).'"' : '';
419 + return '<img '.$srcset_data.$lazy_data.$class.$alt.' src="'.wp_get_attachment_image_url( $attach_id, $size ).'" />';
116 420 }
117 421
118 - // Init data
422 +
423 + /**
424 + * Setup Initial Data Set
425 + *
426 + * @since v.1.0.0
427 + * @return NULL
428 + */
119 429 public function init_set_data(){
120 430 $data = get_option( 'ultp_options', array() );
121 431 $init_data = array(
122 432 'css_save_as' => 'wp_head',
123 433 'preloader_style' => 'style1',
124 - 'preloader_color' => '#1740f5',
434 + 'preloader_color' => '#037fff',
125 435 'container_width' => '1140',
126 - 'editor_container' => 'full_width',
127 436 'hide_import_btn' => '',
437 + 'disable_image_size'=> '',
128 438 'ultp_templates' => 'true',
129 - 'ultp_elementor' => 'true'
439 + 'ultp_elementor' => 'true',
440 + 'ultp_table_of_content'=> 'true',
441 + 'post_grid_1' => 'yes',
442 + 'post_grid_2' => 'yes',
443 + 'post_grid_3' => 'yes',
444 + 'post_grid_4' => 'yes',
445 + 'post_grid_5' => 'yes',
446 + 'post_grid_6' => 'yes',
447 + 'post_grid_7' => 'yes',
448 + 'post_list_1' => 'yes',
449 + 'post_list_2' => 'yes',
450 + 'post_list_3' => 'yes',
451 + 'post_list_4' => 'yes',
452 + 'post_module_1' => 'yes',
453 + 'post_module_2' => 'yes',
454 + 'post_slider_1' => 'yes',
455 + 'heading' => 'yes',
456 + 'image' => 'yes',
457 + 'taxonomy' => 'yes',
458 + 'wrapper' => 'yes',
459 + 'news_ticker' => 'yes'
130 460 );
131 461 if (empty($data)) {
132 462 update_option('ultp_options', $init_data);
133 - $GLOBALS['wopb_settings'] = $init_data;
463 + $GLOBALS['ultp_settings'] = $init_data;
134 464 } else {
135 465 foreach ($init_data as $key => $single) {
136 466 if (!isset($data[$key])) {
137 467 $data[$key] = $single;
@@ -137,19 +467,212 @@
137 467 $data[$key] = $single;
138 468 }
139 469 }
140 470 update_option('ultp_options', $data);
141 - $GLOBALS['wopb_settings'] = $data;
471 + $GLOBALS['ultp_settings'] = $data;
142 472 }
143 473 }
144 474
145 - // Excerpt
475 +
476 + /**
477 + * Get Excerpt Text
478 + *
479 + * @since v.1.0.0
480 + * @param | Post ID (STRING) | Limit (NUMBER)
481 + * @return STRING
482 + */
146 483 public function excerpt( $post_id, $limit = 55 ) {
147 484 return apply_filters( 'the_excerpt', wp_trim_words( get_the_content( $post_id ) , $limit ) );
148 485 }
149 486
150 - // Query Builder
487 + public function get_builder_attr() {
488 + $builder_data = '';
489 + if (is_archive()) {
490 + if (is_date()) {
491 + if ( is_year() ) {
492 + $builder_data = 'date###'.get_the_date('Y');
493 + } else if ( is_month() ) {
494 + $builder_data = 'date###'.get_the_date('Y-n');
495 + } else if ( is_day() ) {
496 + $builder_data = 'date###'.get_the_date('Y-n-j');
497 + }
498 + } else if (is_author()) {
499 + $builder_data = 'author###'.get_the_author_meta('ID');
500 + } else {
501 + $obj = get_queried_object();
502 + if (isset($obj->taxonomy)) {
503 + $builder_data = 'taxonomy###'.$obj->taxonomy.'###'.$obj->slug;
504 + }
505 + }
506 + } else if (is_search()) {
507 + $builder_data = 'search###'.get_search_query(true);
508 + }
509 + return $builder_data ? 'data-builder="'.$builder_data.'"' : '';
510 + }
511 +
512 +
513 + public function is_builder($builder = '') {
514 + $id = '';
515 + if (function_exists('ultimate_post_pro')) {
516 + if ($builder) {
517 + return true;
518 + }
519 + $page_id = ultimate_post_pro()->conditions('return');
520 + if ($page_id && ultimate_post()->get_setting('ultp_builder')) {
521 + $id = $page_id;
522 + }
523 + }
524 + return $id;
525 + }
526 +
527 +
528 + /**
529 + * Get Post Number Depending On Device
530 + *
531 + * @since v.2.5.4
532 + * @param MULTIPLE | Attribute of Posts
533 + * @return STRING
534 + */
535 + public function get_post_number($preDef, $prev, $current) {
536 +
537 + $current = is_object($current)?json_decode(json_encode($current), true):$current;
538 + if (['lg'=>$preDef,'sm'=>$preDef,'xs'=>$preDef] == $current) {
539 + if ($preDef != $prev) {
540 + return $prev;
541 + }
542 + }
543 + if ($this->isDevice() == 'mobile') {
544 + return $current['xs'];
545 + } else if ($this->isDevice() == 'tablet') {
546 + return $current['sm'];
547 + } else {
548 + return $current['lg'];
549 + }
550 + }
551 +
552 +
553 + /**
554 + * Get Post Number Depending On Device
555 + *
556 + * @since v.2.5.4
557 + * @param NULL
558 + * @return STRING | Device Type
559 + */
560 + public function isDevice(){
561 + $useragent = $_SERVER['HTTP_USER_AGENT'];
562 + 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))) {
563 + return 'mobile';
564 + } else if (preg_match('/(tablet|ipad|playbook)|(android(?!.*(mobi|opera mini)))/i', strtolower($useragent))) {
565 + return 'tablet';
566 + } else {
567 + return 'desktop';
568 + }
569 + }
570 +
571 +
572 + /**
573 + * Get Raw Value from Objects
574 + *
575 + * @since v.2.5.3
576 + * @param NULL
577 + * @return STRING | Device Type
578 + */
579 + public function get_value($attr) {
580 + $data = [];
581 + if (is_array($attr)) {
582 + foreach ($attr as $val) {
583 + $data[] = $val->value;
584 + }
585 + }
586 + return $data;
587 + }
588 +
589 +
590 + /**
591 + * Query Builder
592 + *
593 + * @since v.1.0.0
594 + * @param ARRAY | Attribute of the Query
595 + * @return ARRAY
596 + */
151 597 public function get_query($attr) {
598 + $builder = isset($attr['builder']) ? $attr['builder'] : '';
599 + if ($this->is_builder($builder)) {
600 + $archive_query = array();
601 + if ($builder) {
602 + $str = explode('###', $builder);
603 + if (isset($str[0])) {
604 + if ($str[0] == 'taxonomy') {
605 + if (isset($str[1]) && isset($str[2])) {
606 + $archive_query['tax_query'] = array(
607 + array(
608 + 'taxonomy' => $str[1],
609 + 'field' => 'slug',
610 + 'terms' => $str[2]
611 + )
612 + );
613 + }
614 + } else if ($str[0] == 'author') {
615 + if (isset($str[1])) {
616 + $archive_query['author'] = $str[1];
617 + }
618 + } else if ($str[0] == 'search') {
619 + if (isset($str[1])) {
620 + $archive_query['s'] = $str[1];
621 + }
622 + } else if ($str[0] == 'date') {
623 + if (isset($str[1])) {
624 + $all_date = explode('-', $str[1]);
625 + if (!empty($all_date)) {
626 + $arg = array();
627 + if (isset($all_date[0])) { $arg['year'] = $all_date[0]; }
628 + if (isset($all_date[1])) { $arg['month'] = $all_date[1]; }
629 + if (isset($all_date[2])) { $arg['day'] = $all_date[2]; }
630 + $archive_query['date_query'][] = $arg;
631 + }
632 + }
633 + }
634 + }
635 + } else {
636 + global $wp_query;
637 + $archive_query = $wp_query->query_vars;
638 + }
639 + $archive_query['posts_per_page'] = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
640 + $archive_query['paged'] = isset($attr['paged']) ? $attr['paged'] : 1;
641 + if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
642 + $offset = $this->get_offset($attr['queryOffset'], $archive_query);
643 + $archive_query = array_merge($archive_query, $offset);
644 + }
645 +
646 + // Include Remove from Version 2.5.4
647 + if (isset($attr['queryInclude']) && $attr['queryInclude']) {
648 + $_include = explode(',', $attr['queryInclude']);
649 + if (is_array($_include) && count($_include)) {
650 + $archive_query['post__in'] = isset($archive_query['post__in']) ? array_merge($archive_query['post__in'], $_include) : $_include;
651 + $archive_query['ignore_sticky_posts'] = 1;
652 + $archive_query['orderby'] = 'post__in';
653 + }
654 + }
655 +
656 + if (isset($attr['queryExclude']) && $attr['queryExclude']) {
657 + $_exclude = (substr($attr['queryExclude'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryExclude'])) : explode(',', $attr['queryExclude']);
658 + if (is_array($_exclude) && count($_exclude)) {
659 + $archive_query['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $_exclude) : $_exclude;
660 + }
661 + }
662 +
663 +
664 + if(isset($attr['querySticky']) && $attr['querySticky']) {
665 + if (filter_var($attr['querySticky'], FILTER_VALIDATE_BOOLEAN)) {
666 + $sticky = get_option( 'sticky_posts', [] );
667 + $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $sticky) : $sticky;
668 + }
669 + }
670 +
671 + $archive_query['post_status'] = 'publish';
672 + return apply_filters('ultp_archive_query', $archive_query);
673 + }
674 +
152 675 $query_args = array(
153 676 'posts_per_page' => isset($attr['queryNumber']) ? $attr['queryNumber'] : 3,
154 677 'post_type' => isset($attr['queryType']) ? $attr['queryType'] : 'post',
155 678 'orderby' => isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date',
@@ -157,8 +680,44 @@
157 680 'paged' => isset($attr['paged']) ? $attr['paged'] : 1,
158 681 'post_status' => 'publish'
159 682 );
160 683
684 +
685 + if ($attr['queryType'] == 'posts') {
686 + if (isset($attr['queryPosts']) && $attr['queryPosts']) {
687 + unset($query_args['post_type']);
688 + $data = json_decode(isset($attr['queryPosts'])?$attr['queryPosts']:'[]');
689 + $final = $this->get_value($data);
690 + if (count($final) > 0) {
691 + $query_args['post__in'] = $final;
692 + $query_args['posts_per_page'] = -1;
693 + }
694 + $query_args['ignore_sticky_posts'] = 1;
695 + return $query_args;
696 + }
697 + } else if ($attr['queryType'] == 'customPosts') {
698 + if (isset($attr['queryCustomPosts']) && $attr['queryCustomPosts']) {
699 + $query_args['post_type'] = $this->get_post_type();
700 + $data = json_decode(isset($attr['queryCustomPosts'])?$attr['queryCustomPosts']:'[]');
701 + $final = $this->get_value($data);
702 + if (count($final) > 0) {
703 + $query_args['post__in'] = $final;
704 + $query_args['posts_per_page'] = -1;
705 + }
706 + $query_args['ignore_sticky_posts'] = 1;
707 + return $query_args;
708 + }
709 + }
710 +
711 + if(isset($attr['queryExcludeAuthor']) && $attr['queryExcludeAuthor']){
712 + $data = json_decode(isset($attr['queryExcludeAuthor'])?$attr['queryExcludeAuthor']:'[]');
713 + $final = $this->get_value($data);
714 + if (count($final) > 0) {
715 + $query_args['author__not_in'] = $final;
716 + }
717 + }
718 +
719 +
161 720 if(isset($attr['queryOrderBy']) && isset($attr['metaKey'])){
162 721 if($attr['queryOrderBy'] == 'meta_value_num') {
163 722 $query_args['meta_key'] = $attr['metaKey'];
164 723 }
@@ -163,24 +722,41 @@
163 722 $query_args['meta_key'] = $attr['metaKey'];
164 723 }
165 724 }
166 725
167 - if(isset($attr['queryInclude']) && $attr['queryInclude']){
168 - $query_args['post__in'] = explode(',', $attr['queryInclude']);
169 - $query_args['ignore_sticky_posts'] = 1;
170 - $query_args['orderby'] = 'post__in';
726 + // Include Remove from Version 2.5.4
727 + if (isset($attr['queryInclude']) && $attr['queryInclude']) {
728 + $_include = explode(',', $attr['queryInclude']);
729 + if (is_array($_include) && count($_include)) {
730 + $query_args['post__in'] = isset($query_args['post__in']) ? array_merge($query_args['post__in'], $_include) : $_include;
731 + $query_args['ignore_sticky_posts'] = 1;
732 + $query_args['orderby'] = 'post__in';
733 + }
171 734 }
172 735
173 - if(isset($attr['queryExclude']) && $attr['queryExclude']){
174 - $query_args['post__not_in'] = explode(',', $attr['queryExclude']);
175 - }
176 736
177 737 if(isset($attr['queryTax'])){
178 - if(isset($attr['queryCat'])){
179 - if($attr['queryTax'] == 'category' && !empty($attr['queryCat'])){
180 - $var = array('relation'=>'OR');
181 - foreach (json_decode($attr['queryCat']) as $val) {
182 - $var[] = array('taxonomy'=>'category', 'field' => 'slug', 'terms' => $val );
738 + if(isset($attr['queryTaxValue'])){
739 + $tax_value = (strlen($attr['queryTaxValue']) > 2) ? $attr['queryTaxValue'] : [];
740 + $tax_value = is_array($tax_value) ? $tax_value : json_decode($tax_value);
741 +
742 + $tax_value = (isset($tax_value[0]) && is_object($tax_value[0])) ? $this->get_value($tax_value) : $tax_value;
743 +
744 + if(count($tax_value) > 0){
745 + $relation = isset($attr['queryRelation']) ? $attr['queryRelation'] : 'OR';
746 + $var = array('relation'=>$relation);
747 + foreach ($tax_value as $val) {
748 + $tax_name = $attr['queryTax'];
749 + // For Custom Terms
750 + if ($attr['queryTax'] == 'multiTaxonomy') {
751 + $temp = explode('###', $val);
752 + if (isset($temp[1])) {
753 + $val = $temp[1];
754 + $tax_name = $temp[0];
755 + }
756 + }
757 +
758 + $var[] = array('taxonomy'=> $tax_name, 'field' => 'slug', 'terms' => $val );
183 759 }
184 760 if(count($var) > 1){
185 761 $query_args['tax_query'] = $var;
186 762 }
@@ -185,51 +761,122 @@
185 761 $query_args['tax_query'] = $var;
186 762 }
187 763 }
188 764 }
189 - if(isset($attr['queryTag'])){
190 - if($attr['queryTax'] == 'post_tag' && !empty($attr['queryTag'])){
191 - $var = array('relation'=>'OR');
192 - foreach (json_decode($attr['queryTag']) as $val) {
193 - $var[] = array('taxonomy'=>'post_tag', 'field' => 'slug', 'terms' => $val );
765 + }
766 +
767 +
768 + if (isset($attr['queryExcludeTerm']) && $attr['queryExcludeTerm']) {
769 + $temp = json_decode($attr['queryExcludeTerm']);
770 + $_term = [];
771 + foreach ($temp as $val) {
772 + $temp = explode('###', $val->value);
773 + if (isset($temp[1])) {
774 + if (array_key_exists($temp[0], $_term)) {
775 + $_term[$temp[0]][] = $temp[1];
776 + } else {
777 + $_term[$temp[0]] = array($temp[1]);
194 778 }
195 - $query_args['tax_query'] = $var;
196 779 }
197 780 }
781 + if (count($_term) > 0) {
782 + $final = array('relation' => 'AND');
783 + foreach ($_term as $key => $val) {
784 + $final[] = array(
785 + 'taxonomy' => $key,
786 + 'field' => 'slug',
787 + 'terms' => $val,
788 + 'operator' => 'NOT IN',
789 + );
790 + }
791 +
792 + if (array_key_exists('tax_query', $query_args)) {
793 + $query_args['tax_query'] = array(
794 + 'relation' => 'AND',
795 + $query_args['tax_query']
796 + );
797 + $query_args['tax_query'][] = $final;
798 + } else {
799 + $query_args['tax_query'] = $final;
800 + }
801 + }
198 802 }
199 803
200 - if(isset($attr['queryQuick'])){
201 - if($attr['queryQuick'] != ''){
202 - if(function_exists('ultimate_post_pro')){
203 - $query_args = ultimate_post_pro()->get_quick_query($attr, $query_args);
204 - }
804 + if (isset($attr['queryExclude']) && $attr['queryExclude']) {
805 + $_exclude = (substr($attr['queryExclude'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryExclude'])) : explode(',', $attr['queryExclude']);
806 + if (is_array($_exclude) && count($_exclude)) {
807 + $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $_exclude) : $_exclude;
205 808 }
206 809 }
207 810
208 - if(isset($attr['queryOffset']) && $attr['queryOffset'] ){
209 - if($query_args['paged'] > 1){
210 - $offset_post = wp_get_recent_posts($query_args, OBJECT);
211 - if( count($offset_post) > 0 ){
212 - $offset = array();
213 - for($x = count($offset_post); $x > count($offset_post) - $attr['queryOffset']; $x--){
214 - $offset[] = $offset_post[$x-1]->ID;
215 - }
216 - $query_args['post__not_in'] = $offset;
217 - }
218 - }else{
219 - $query_args['offset'] = isset($attr['queryOffset']) ? $attr['queryOffset'] : 0;
811 + if (isset($attr['queryUnique']) && $attr['queryUnique']) {
812 + global $unique_ID;
813 + if (isset($unique_ID[$attr['queryUnique']])) {
814 + $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']];
220 815 }
221 816 }
222 817
818 + if (isset($attr['queryQuick'])) {
819 + if ($attr['queryQuick'] != '') {
820 + $query_args = ultimate_post()->get_quick_query($attr, $query_args);
821 + }
822 + }
823 +
824 + if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
825 + $offset = $this->get_offset($attr['queryOffset'], $query_args);
826 + $query_args = array_merge($query_args, $offset);
827 + }
828 +
829 + if (isset($attr['queryAuthor']) && $attr['queryAuthor'] ) {
830 + $_include = (substr($attr['queryAuthor'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryAuthor'])) : explode(',', $attr['queryAuthor']);
831 + if (is_array($_include) && count($_include)) {
832 + $query_args['author__in'] = $_include;
833 + }
834 + }
835 +
836 + if(isset($attr['querySticky']) && $attr['querySticky']) {
837 + if (filter_var($attr['querySticky'], FILTER_VALIDATE_BOOLEAN)) {
838 + $sticky = get_option( 'sticky_posts', [] );
839 + $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $sticky) : $sticky;
840 + }
841 + }
842 +
223 843 $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
224 844
225 - return $query_args;
845 + return apply_filters('ultp_frontend_query', $query_args);
226 846 }
227 847
848 + function get_offset($queryOffset, $query_args) {
849 + $query = array();
850 + if ($query_args['paged'] > 1) {
851 + $offset_post = wp_get_recent_posts($query_args, OBJECT);
852 + if ( count($offset_post) > 0 ) {
853 + $offset = array();
854 + for($x = count($offset_post); $x > count($offset_post) - $queryOffset; $x--){
855 + $offset[] = $offset_post[$x-1]->ID;
856 + }
857 + $query['post__not_in'] = $offset;
858 + }
859 + } else {
860 + $query['offset'] = isset($queryOffset) ? $queryOffset : 0;
861 + }
862 + return $query;
863 + }
228 864
865 +
866 + /**
867 + * Get Page Number
868 + *
869 + * @since v.1.0.0
870 + * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
871 + * @return ARRAY
872 + */
229 873 public function get_page_number($attr, $post_number) {
230 - if($post_number > 0){
231 - $post_per_page = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
874 + if ($post_number > 0) {
875 + if (isset($attr['queryOffset']) && $attr['queryOffset']) {
876 + $post_number = $post_number - (int)$attr['queryOffset'];
877 + }
878 + $post_per_page = isset($attr['queryNumber']) ? ($attr['queryNumber'] ? $attr['queryNumber'] : 1) : 3;
232 879 $pages = ceil($post_number/$post_per_page);
233 880 return $pages ? $pages : 1;
234 881 }else{
235 882 return 1;
@@ -235,29 +882,77 @@
235 882 return 1;
236 883 }
237 884 }
238 885
886 +
887 + /**
888 + * Get Image Size
889 + *
890 + * @since v.1.0.0
891 + * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
892 + * @return ARRAY
893 + */
239 894 public function get_image_size() {
240 895 $sizes = get_intermediate_image_sizes();
241 896 $filter = array('full' => 'Full');
242 897 foreach ($sizes as $value) {
243 - $filter[$value] = ucwords(str_replace(array('_', '-'), array(' ', ' '), $value));
898 + $title = ucwords(str_replace(array('_', '-'), array(' ', ' '), $value));
899 + switch ($value) {
900 + case 'thumbnail':
901 + $title = $title.' [150x150]';
902 + break;
903 + case 'medium':
904 + $title = $title.' [300x300]';
905 + break;
906 + case 'large':
907 + $title = $title.' [1024x1024]';
908 + break;
909 + case 'ultp_layout_landscape_large':
910 + $title = $title.' [1200x800]';
911 + break;
912 + case 'ultp_layout_landscape':
913 + $title = $title.' [870x570]';
914 + break;
915 + case 'ultp_layout_portrait':
916 + $title = $title.' [600x900]';
917 + break;
918 + case 'ultp_layout_square':
919 + $title = $title.' [600x600]';
920 + break;
921 + default:
922 + break;
923 + }
924 + $filter[$value] = $title;
244 925 }
245 926 return $filter;
246 927 }
247 928
248 929
930 + /**
931 + * Get All PostType Registered
932 + *
933 + * @since v.1.0.0
934 + * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
935 + * @return ARRAY
936 + */
249 937 public function get_post_type() {
250 - $post_type = get_post_types( '', 'names' );
251 - return array_diff($post_type, array( 'attachment', 'revision', 'nav_menu_item', 'custom_css', 'customize_changeset', 'oembed_cache', 'user_request', 'wp_block' ));
938 + $post_type = get_post_types( ['public' => true], 'names' );
939 + return array_diff($post_type, array( 'attachment' ));
252 940 }
253 941
254 942
255 - // Pagination
256 - public function pagination($pages = '', $paginationNav, $range = 1) {
943 + /**
944 + * Get Pagination HTML
945 + *
946 + * @since v.1.0.0
947 + * @param | pages (NUMBER) | Pagination Nav (STRING) | Pagination Text |
948 + * @return STRING
949 + */
950 + public function pagination($pages = '', $paginationNav = '', $paginationText = '') {
257 951 $html = '';
258 952 $showitems = 3;
259 - $paged = get_query_var('paged') ? get_query_var('paged') : 1;
953 + $paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
954 + $paged = $paged ? $paged : 1;
260 955 if($pages == '') {
261 956 global $wp_query;
262 957 $pages = $wp_query->max_num_pages;
263 958 if(!$pages) {
@@ -265,14 +960,18 @@
265 960 }
266 961 }
267 962 $data = ($paged>=3?[($paged-1),$paged,$paged+1]:[1,2,3]);
268 963
964 + $paginationText = explode('|', $paginationText);
965 +
966 + $prev_text = isset($paginationText[0]) ? $paginationText[0] : __("Previous", "ultimate-post");
967 + $next_text = isset($paginationText[1]) ? $paginationText[1] : __("Next", "ultimate-post");
269 968
270 969 if(1 != $pages) {
271 970 $html .= '<ul class="ultp-pagination">';
272 971 $display_none = 'style="display:none"';
273 972 if($pages > 4) {
274 - $html .= '<li class="ultp-prev-page-numbers" '.($paged==1?$display_none:"").'><a href="'.get_pagenum_link($paged-1).'">'.ultimate_post()->svg_icon('leftAngle2').' '.($paginationNav == 'textArrow'?__("Previous", "ultimate-post"):"").'</a></li>';
973 + $html .= '<li class="ultp-prev-page-numbers" '.($paged==1?$display_none:"").'><a href="'.get_pagenum_link($paged-1).'">'.ultimate_post()->svg_icon('leftAngle2').' '.($paginationNav == 'textArrow' ? $prev_text : "").'</a></li>';
275 974 }
276 975 if($pages > 4){
277 976 $html .= '<li class="ultp-first-pages" '.($paged<2?$display_none:"").' data-current="1"><a href="'.get_pagenum_link(1).'">1</a></li>';
278 977 }
@@ -290,9 +989,9 @@
290 989 if($pages > 4){
291 990 $html .= '<li class="ultp-last-pages" '.($pages<=$paged+1?$display_none:"").' data-current="'.$pages.'"><a href="'.get_pagenum_link($pages).'">'.$pages.'</a></li>';
292 991 }
293 992 if ($paged != $pages) {
294 - $html .= '<li class="ultp-next-page-numbers"><a href="'.get_pagenum_link($paged + 1).'">'.($paginationNav == 'textArrow' ? __("Next", "ultimate-post") : "").ultimate_post()->svg_icon('rightAngle2').'</a></li>';
993 + $html .= '<li class="ultp-next-page-numbers"><a href="'.get_pagenum_link($paged + 1).'">'.($paginationNav == 'textArrow' ? $next_text : "").ultimate_post()->svg_icon('rightAngle2').'</a></li>';
295 994 }
296 995 $html .= '</ul>';
297 996 }
298 997 return $html;
@@ -297,8 +996,16 @@
297 996 }
298 997 return $html;
299 998 }
300 999
1000 +
1001 + /**
1002 + * Get Excerpt Word
1003 + *
1004 + * @since v.1.0.0
1005 + * @param NUMBER | Character Length
1006 + * @return STRING
1007 + */
301 1008 public function excerpt_word($charlength = 200) {
302 1009 $html = '';
303 1010 $charlength++;
304 1011 $excerpt = get_the_excerpt();
@@ -318,16 +1025,23 @@
318 1025 return $html;
319 1026 }
320 1027
321 1028
1029 + /**
1030 + * Get Taxonomy Lists
1031 + *
1032 + * @since v.1.0.0
1033 + * @param STRING | Taxonomy Slug
1034 + * @return ARRAY
1035 + */
322 1036 public function taxonomy( $prams = 'category' ) {
323 1037 $data = array();
324 1038 $terms = get_terms( $prams, array(
325 - 'hide_empty' => true,
1039 + 'hide_empty' => false,
326 1040 ));
327 - if( !empty($terms) ){
1041 + if( !is_wp_error($terms) ){
328 1042 foreach ($terms as $val) {
329 - $data[$val->slug] = $val->name;
1043 + $data[urldecode_deep($val->slug)] = $val->name;
330 1044 }
331 1045 }
332 1046 return $data;
333 1047 }
@@ -332,8 +1046,85 @@
332 1046 return $data;
333 1047 }
334 1048
335 1049
1050 + /**
1051 + * Get Taxonomy Data Lists
1052 + *
1053 + * @since v.1.0.0
1054 + * @param OBJECT | Taxonomy Object
1055 + * @return ARRAY
1056 + */
1057 + public function get_tax_data($terms) {
1058 + $temp = array();
1059 + $image = '';
1060 + $thumbnail_id = get_term_meta( $terms->term_id, 'ultp_category_image', true );
1061 + if( $thumbnail_id ){
1062 + $image = wp_get_attachment_url( $thumbnail_id );
1063 + }
1064 + $temp['url'] = get_term_link($terms);
1065 + $temp['name'] = $terms->name;
1066 + $temp['desc'] = $terms->description;
1067 + $temp['count'] = $terms->count;
1068 + $temp['image'] = $image;
1069 + $color = get_term_meta($terms->term_id, 'ultp_category_color', true);
1070 + $temp['color'] = $color ? $color : '#037fff';
1071 + return $temp;
1072 + }
1073 +
1074 + public function get_category_data($catSlug, $number = 40, $type = '', $tax_slug = 'category') {
1075 + $data = array();
1076 + if($type == 'child'){
1077 + $image = '';
1078 + if (!empty($catSlug)) {
1079 + foreach ($catSlug as $cat) {
1080 + $parent_term = get_term_by('slug', $cat, $tax_slug);
1081 + if (!empty($parent_term)) {
1082 + $term_data = get_terms($tax_slug, array(
1083 + 'hide_empty' => true,
1084 + 'parent' => $parent_term->term_id
1085 + ));
1086 + if (!empty($term_data)) {
1087 + foreach ($term_data as $terms) {
1088 + $data[] = $this->get_tax_data($terms);
1089 + }
1090 + }
1091 + }
1092 + }
1093 + }
1094 + } else if ($type == 'parent') {
1095 + $term_data = get_terms( $tax_slug, array( 'hide_empty' => true, 'number' => $number, 'parent' => 0 ) );
1096 + if (!empty($term_data)) {
1097 + foreach ($term_data as $terms) {
1098 + $data[] = $this->get_tax_data($terms);
1099 + }
1100 + }
1101 + } else if ($type == 'custom') {
1102 + foreach ($catSlug as $cat) {
1103 + $terms = get_term_by('slug', $cat, $tax_slug);
1104 + if (!empty($terms)) {
1105 + $data[] = $this->get_tax_data($terms);
1106 + }
1107 + }
1108 + } else {
1109 + $term_data = get_terms($tax_slug, array('hide_empty' => true, 'number' => $number));
1110 + if (!empty($term_data)) {
1111 + foreach ($term_data as $terms) {
1112 + $data[] = $this->get_tax_data($terms);
1113 + }
1114 + }
1115 + }
1116 + return $data;
1117 + }
1118 +
1119 +
1120 + /**
1121 + * Get Next Previous HTML
1122 + *
1123 + * @since v.1.0.0
1124 + * @param OBJECT | Taxonomy Object
1125 + * @return STRING
1126 + */
336 1127 public function next_prev() {
337 1128 $html = '';
338 1129 $html .= '<ul>';
339 1130 $html .= '<li>';
@@ -349,15 +1140,19 @@
349 1140 $html .= '</ul>';
350 1141 return $html;
351 1142 }
352 1143
1144 +
1145 + /**
1146 + * Get Loading HTML
1147 + *
1148 + * @since v.1.0.0
1149 + * @param NULL
1150 + * @return STRING
1151 + */
353 1152 public function loading(){
354 1153 $html = '';
355 - $style = 'style1';
356 - $option_data = ultimate_post()->get_setting();
357 - if( isset($option_data['preloader_style']) ){
358 - $style = $option_data['preloader_style'];
359 - }
1154 + $style = ultimate_post()->get_setting('preloader_style');
360 1155 if( $style == 'style2' ){
361 1156 $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
362 1157 } else {
363 1158 $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>';
@@ -364,34 +1159,61 @@
364 1159 }
365 1160 return '<div class="ultp-loading">'.$html.'</div>';
366 1161 }
367 1162
368 - public function filter($filterText = '', $filterType = '', $filterCat = '[]', $filterTag = '[]'){
1163 +
1164 + /**
1165 + * Get Filter HTML
1166 + *
1167 + * @since v.1.0.0
1168 + * @param | Filter Text (STRING) | Filter Type (STRING) | Filter Value (ARRAY) | Filter Cat (ARRAY) | Filter Tag (ARRAY) |
1169 + * @return STRING
1170 + */
1171 + public function filter($filterText = '', $filterType = '', $filterValue = '[]', $filterMobileText = '...', $filterMobile = true){
369 1172 $html = '';
370 - $html .= '<ul class="ultp-flex-menu">';
371 - if ($filterType == 'category') {
372 - $cat = $this->taxonomy('category');
373 - if($filterText){
374 - $html .= '<li class="filter-item"><a data-taxonomy="" href="#">'.$filterText.'</a></li>';
375 - }
376 - foreach (json_decode($filterCat) as $val) {
1173 + $html .= '<ul '.($filterMobile ? 'class="ultp-flex-menu"' : '').' data-name="'.($filterMobileText ? $filterMobileText : '&nbsp;').'">';
1174 + $cat = $this->taxonomy($filterType);
1175 + if($filterText){
1176 + $html .= '<li class="filter-item"><a class="filter-active" data-taxonomy="" href="#">'.$filterText.'</a></li>';
1177 + }
1178 +
1179 + if ($filterValue) {
1180 + $filterValue = strlen($filterValue) > 2 ? $filterValue : [];
1181 + $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
1182 + foreach ($filterValue as $val) {
377 1183 $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($cat[$val]) ? $cat[$val] : $val).'</a></li>';
378 1184 }
379 - } else {
380 - $tag = $this->taxonomy('post_tag');
381 - if($filterText){
382 - $html .= '<li class="filter-item"><a data-taxonomy="" href="#">'.$filterText.'</a></li>';
383 - }
384 - foreach (json_decode($filterTag) as $val) {
385 - $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($tag[$val]) ? $tag[$val] : $val).'</a></li>';
386 - }
387 1185 }
388 1186 $html .= '</ul>';
389 1187 return $html;
390 1188 }
391 1189
1190 +
1191 + /**
1192 + * Check License Status
1193 + *
1194 + * @since v.2.4.2
1195 + * @return BOOLEAN | Is pro license active or not
1196 + */
1197 + public function is_lc_active() {
1198 + if (function_exists('ultimate_post_pro')) {
1199 + return get_option('edd_ultp_license_status') == 'valid' ? true : false;
1200 + }
1201 + if (get_transient( 'ulpt_theme_enable' ) == 'integration') {
1202 + return true;
1203 + }
1204 + return false;
1205 + }
1206 +
1207 +
1208 + /**
1209 + * Get SVG Icon
1210 + *
1211 + * @since v.1.0.0
1212 + * @param STRING | Icon Key
1213 + * @return STRING | Icon SVG
1214 + */
392 1215 public function svg_icon($icons = ''){
393 -
394 1216 $icon_lists = array(
395 1217 'eye' => file_get_contents(ULTP_PATH.'assets/img/svg/eye.svg'),
396 1218 'user' => file_get_contents(ULTP_PATH.'assets/img/svg/user.svg'),
397 1219 'calendar' => file_get_contents(ULTP_PATH.'assets/img/svg/calendar.svg'),
@@ -409,7 +1231,42 @@
409 1231 );
410 1232 if($icons){
411 1233 return $icon_lists[ $icons ];
412 1234 }
1235 + }
1236 +
1237 + /**
1238 + * Get SEO Meta
1239 + *
1240 + * @since v.2.4.3
1241 + * @param NUMBER | Post ID
1242 + * @return STRING | SEO Meta Description or Excerpt
1243 + */
1244 + public function get_excerpt($post_id = 0, $showSeoMeta = 0, $showFullExcerpt = 0, $excerptLimit = 55) {
1245 + $html = '';
1246 + if ($showSeoMeta) {
1247 + $str = '';
1248 + if( function_exists('ultimate_post_pro') ) {
1249 + if (ultimate_post()->get_setting('ultp_yoast') == 'true') {
1250 + $str = method_exists( ultimate_post_pro(), 'get_yoast_meta' ) ? ultimate_post_pro()->get_yoast_meta($post_id) : '';
1251 + } else if (ultimate_post()->get_setting('ultp_rankmath') == 'true') {
1252 + $str = method_exists( ultimate_post_pro(), 'get_rankmath_meta' ) ? ultimate_post_pro()->get_rankmath_meta($post_id) : '';
1253 + } else if (ultimate_post()->get_setting('ultp_aioseo') == 'true') {
1254 + $str = method_exists( ultimate_post_pro(), 'get_aioseo_meta' ) ? ultimate_post_pro()->get_aioseo_meta($post_id) : '';
1255 + } else if (ultimate_post()->get_setting('ultp_seopress') == 'true') {
1256 + $str = method_exists( ultimate_post_pro(), 'get_seopress_meta' ) ? ultimate_post_pro()->get_seopress_meta($post_id) : '';
1257 + } else if (ultimate_post()->get_setting('ultp_squirrly') == 'true') {
1258 + $str = method_exists( ultimate_post_pro(), 'get_squirrly_meta' ) ? ultimate_post_pro()->get_squirrly_meta($post_id) : '';
1259 + }
1260 + }
1261 + $html = $str ? $str : ultimate_post()->excerpt($post_id, $excerptLimit);
1262 + } else {
1263 + if ( $showFullExcerpt == 0 ) {
1264 + $html = ultimate_post()->excerpt($post_id, $excerptLimit);
1265 + } else {
1266 + $html = get_the_excerpt();
1267 + }
1268 + }
1269 + return $html;
413 1270 }
414 1271
415 1272 }