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