classes
6 years ago
elementor
6 years ago
elements
6 years ago
define.php
6 years ago
general-functions.php
6 years ago
general-hooks.php
6 years ago
general-shortcodes.php
9 years ago
index.php
7 years ago
general-functions.php
2492 lines
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * |
| 5 | * @package Auxin |
| 6 | * @license LICENSE.txt |
| 7 | * @author averta |
| 8 | * @link http://phlox.pro/ |
| 9 | * @copyright (c) 2010-2020 averta |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * Whether a plugin is active or not |
| 14 | * |
| 15 | * @param string $plugin_basename plugin directory name and mail file address |
| 16 | * @return bool True if plugin is active and FALSE otherwise |
| 17 | */ |
| 18 | if( ! function_exists( 'auxin_is_plugin_active' ) ){ |
| 19 | function auxin_is_plugin_active( $plugin_basename ){ |
| 20 | include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 21 | return is_plugin_active( $plugin_basename ); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | |
| 26 | /** |
| 27 | * Retrieves the markup for footer logo element |
| 28 | * |
| 29 | * @param array $args The properties fort this element |
| 30 | * |
| 31 | * @return string The markup for logo element |
| 32 | */ |
| 33 | function auxin_get_footer_logo_block( $args = array() ){ |
| 34 | |
| 35 | $defaults = array( |
| 36 | 'css_class' => '', |
| 37 | 'middle' => true |
| 38 | ); |
| 39 | |
| 40 | $args = wp_parse_args( $args, $defaults ); |
| 41 | |
| 42 | ob_start(); |
| 43 | ?> |
| 44 | <div class="aux-logo <?php echo $args['css_class']; ?>"> |
| 45 | <a class="aux-logo-anchor <?php echo ($args['middle'] ? 'aux-middle' : ''); ?>" href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"> |
| 46 | <?php echo _auxin_get_footer_logo_image(); ?> |
| 47 | </a> |
| 48 | </div><!-- end logo aux-fold --> |
| 49 | |
| 50 | <?php |
| 51 | return ob_get_clean(); |
| 52 | } |
| 53 | |
| 54 | |
| 55 | /** |
| 56 | * Retrieves the footer logo image tag |
| 57 | * |
| 58 | * @return string The markup for logo image |
| 59 | */ |
| 60 | function _auxin_get_footer_logo_image(){ |
| 61 | global $post; |
| 62 | |
| 63 | if( ! $img_id = auxin_get_post_meta( $post, 'page_secondary_logo_image' ) ){ |
| 64 | $img_id = auxin_get_option( 'site_secondary_logo_image'); |
| 65 | } |
| 66 | |
| 67 | return wp_get_attachment_image( $img_id, 'full', false, array( |
| 68 | 'class' => 'aux-logo-image aux-logo-dark', |
| 69 | 'itemprop' => 'logo', |
| 70 | 'alt' => esc_attr( get_bloginfo( 'name', 'display' ) ) |
| 71 | ) ); |
| 72 | |
| 73 | } |
| 74 | |
| 75 | //// is absolute url /////////////////////////////////////////////////////////////////// |
| 76 | |
| 77 | /** |
| 78 | * Whether it's absolute url or not |
| 79 | * |
| 80 | * @param string $url The URL |
| 81 | * @return bool TRUE if the URL is absolute |
| 82 | */ |
| 83 | |
| 84 | if( ! function_exists( "auxin_is_absolute_url" ) ){ |
| 85 | |
| 86 | function auxin_is_absolute_url( $url ){ |
| 87 | return preg_match( "~^(?:f|ht)tps?://~i", $url ); |
| 88 | } |
| 89 | |
| 90 | } |
| 91 | |
| 92 | |
| 93 | //// create absolute url if the url is relative //////////////////////////////////////// |
| 94 | |
| 95 | /** |
| 96 | * Print absolute URL for media file even if the URL is relative |
| 97 | * |
| 98 | * @param string $url The link to media file |
| 99 | * @return void |
| 100 | */ |
| 101 | function auxin_the_absolute_image_url( $url ){ |
| 102 | echo auxin_get_the_absolute_image_url( $url ); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Get absolute URL for media file event if the URL is relative |
| 107 | * |
| 108 | * @param string $url The link to media file |
| 109 | * @return string The absolute URL to media file |
| 110 | */ |
| 111 | if( ! function_exists( 'auxin_get_the_absolute_image_url' ) ){ |
| 112 | |
| 113 | function auxin_get_the_absolute_image_url( $url ){ |
| 114 | if( ! isset( $url ) || empty( $url ) ) return ''; |
| 115 | |
| 116 | if( auxin_is_absolute_url( $url ) || auxin_contains_upload_dir( $url ) ) return $url; |
| 117 | |
| 118 | $uploads = wp_get_upload_dir(); |
| 119 | return trailingslashit( $uploads['baseurl'] ) . $url; |
| 120 | } |
| 121 | |
| 122 | } |
| 123 | |
| 124 | //// get all registerd siderbar ids /////////////////////////////////////////////////// |
| 125 | |
| 126 | if( ! function_exists( 'auxin_get_all_sidebar_ids' ) ){ |
| 127 | |
| 128 | function auxin_get_all_sidebar_ids(){ |
| 129 | $sidebars = get_theme_mod( 'auxin_sidebars'); |
| 130 | $output = array(); |
| 131 | |
| 132 | if( isset( $auxin_sidebars ) && ! empty( $auxin_sidebars ) ){ |
| 133 | foreach( $sidebars as $key => $value ) { |
| 134 | $output[] = THEME_ID .'-'. strtolower( str_replace(' ', '-', $value) ); |
| 135 | } |
| 136 | } |
| 137 | return $output; |
| 138 | } |
| 139 | |
| 140 | } |
| 141 | |
| 142 | //// remove all auto generated p tags from shortcode content ////////////////////////// |
| 143 | |
| 144 | if( ! function_exists( "auxin_do_cleanup_shortcode" ) ){ |
| 145 | |
| 146 | function auxin_do_cleanup_shortcode( $content ) { |
| 147 | |
| 148 | /* Parse nested shortcodes and add formatting. */ |
| 149 | $content = trim( wpautop( do_shortcode( $content ) ) ); |
| 150 | |
| 151 | /* Remove any instances of '<p>' '</p>'. */ |
| 152 | $content = auxin_cleanup_content( $content ); |
| 153 | |
| 154 | return $content; |
| 155 | } |
| 156 | |
| 157 | } |
| 158 | |
| 159 | |
| 160 | //// remove all p tags from string //////////////////////////////////////////////////// |
| 161 | |
| 162 | if( ! function_exists( 'auxin_cleanup_content' ) ){ |
| 163 | |
| 164 | function auxin_cleanup_content( $content ) { |
| 165 | /* Remove any instances of '<p>' '</p>'. */ |
| 166 | return str_replace( array('<p>','</p>'), array('','') , $content ); |
| 167 | } |
| 168 | |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Generates and may print a notice for missing required plugins in elementor |
| 173 | * |
| 174 | * @param array $args |
| 175 | * @return string May return the notice markup |
| 176 | */ |
| 177 | function auxin_elementor_plugin_missing_notice( $args ){ |
| 178 | // default params |
| 179 | $defaults = array( |
| 180 | 'plugin_name' => '', |
| 181 | 'echo' => true |
| 182 | ); |
| 183 | $args = wp_parse_args( $args, $defaults ); |
| 184 | |
| 185 | ob_start(); |
| 186 | ?> |
| 187 | <div class="elementor-alert elementor-alert-danger" role="alert"> |
| 188 | <span class="elementor-alert-title"> |
| 189 | <?php echo sprintf( esc_html__( '"%s" Plugin is Not Activated!', 'auxin-elements' ), $args['plugin_name'] ); ?> |
| 190 | </span> |
| 191 | <span class="elementor-alert-description"> |
| 192 | <?php esc_html_e( 'In order to use this element, you need to install and activate this plugin.', 'auxin-elements' ); ?> |
| 193 | </span> |
| 194 | </div> |
| 195 | <?php |
| 196 | $notice = ob_get_clean(); |
| 197 | |
| 198 | if( $args['echo'] ){ |
| 199 | echo $notice; |
| 200 | } else { |
| 201 | return $notice; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | /*-----------------------------------------------------------------------------------*/ |
| 206 | /* A function that makes excluding featured image, post formats and post ids simpler |
| 207 | /*-----------------------------------------------------------------------------------*/ |
| 208 | |
| 209 | if( ! function_exists( 'auxin_parse_query_args' ) ){ |
| 210 | |
| 211 | |
| 212 | /** |
| 213 | * A function that makes excluding featured image, post formats and post ids simpler |
| 214 | * |
| 215 | * @param array $args The list of options and query params |
| 216 | * @return array The parsed args as array |
| 217 | */ |
| 218 | function auxin_parse_query_args( $args ){ |
| 219 | |
| 220 | $defaults = array( |
| 221 | 'post_type' => 'post', |
| 222 | 'post_status' => 'publish', |
| 223 | 'posts_per_page' => -1, |
| 224 | 'ignore_sticky_posts' => 1, |
| 225 | 'tax_query' => array(), |
| 226 | |
| 227 | 'posts__in' => '', // display only these post IDs. array or string comma separated |
| 228 | 'posts__not_in' => '', // exclude these post IDs from result. array or string comma separated |
| 229 | |
| 230 | 'include_posts__in' => '', // include these post IDs in result too. array or string comma separated |
| 231 | 'exclude_without_media' => 0, // exclude the posts without featured image |
| 232 | 'exclude_post_formats_in' => '', // exclude the post with these post formats |
| 233 | 'include_post_formats_in' => '', // include the post with these post formats |
| 234 | ); |
| 235 | |
| 236 | // parse and merge the passed args |
| 237 | $parsed_args = wp_parse_args( $args, $defaults ); |
| 238 | |
| 239 | |
| 240 | // Exclude post formats ---------------------------------------------------- |
| 241 | |
| 242 | // exclude post formats if specified |
| 243 | if( ! empty( $parsed_args['exclude_post_formats_in'] ) ){ |
| 244 | |
| 245 | // generate post-format terms (i.e post-format-aside) |
| 246 | $post_format_terms = array(); |
| 247 | foreach ( $parsed_args['exclude_post_formats_in'] as $_post_format ) { |
| 248 | $post_format_terms[] = 'post-format-' . $_post_format; |
| 249 | } |
| 250 | |
| 251 | // exclude the redundant taxonomies (post-format) |
| 252 | $parsed_args['tax_query'][] = array( |
| 253 | 'taxonomy' => 'post_format', |
| 254 | 'field' => 'slug', |
| 255 | 'terms' => $post_format_terms, |
| 256 | 'operator' => 'NOT IN' |
| 257 | ); |
| 258 | |
| 259 | } else if( ! empty( $parsed_args['include_post_formats_in'] ) ) { |
| 260 | // generate post-format terms (i.e post-format-aside) |
| 261 | $post_format_terms = array(); |
| 262 | foreach ( $parsed_args['include_post_formats_in'] as $_post_format ) { |
| 263 | $post_format_terms[] = 'post-format-' . $_post_format; |
| 264 | } |
| 265 | |
| 266 | // exclude the redundant taxonomies (post-format) |
| 267 | $parsed_args['tax_query'][] = array( |
| 268 | 'taxonomy' => 'post_format', |
| 269 | 'field' => 'slug', |
| 270 | 'terms' => $post_format_terms, |
| 271 | 'operator' => 'IN' |
| 272 | ); |
| 273 | } |
| 274 | |
| 275 | // Exclude posts without featured image ------------------------------------ |
| 276 | |
| 277 | // whether to exclude posts without featured-image or not |
| 278 | if( $parsed_args['exclude_without_media'] ){ |
| 279 | $parsed_args['meta_query'] = array( |
| 280 | array( |
| 281 | 'key' => '_thumbnail_id', |
| 282 | 'value' => '', |
| 283 | 'compare' => '!=' |
| 284 | ) |
| 285 | ); |
| 286 | } |
| 287 | |
| 288 | |
| 289 | // Include, Exclude & Replace Post IDs ------------------------------------- |
| 290 | |
| 291 | // get the list of custom post ids to display |
| 292 | $only_posts = $parsed_args['posts__in'] ? wp_parse_id_list( $parsed_args['posts__in'] ) : array(); |
| 293 | |
| 294 | // get the list of custom post ids to include |
| 295 | $include_posts = $parsed_args['include_posts__in'] ? wp_parse_id_list( $parsed_args['include_posts__in'] ) : array(); |
| 296 | |
| 297 | // get the list of custom post ids to exclude |
| 298 | $exclude_posts = $parsed_args['posts__not_in'] ? wp_parse_id_list( $parsed_args['posts__not_in'] ) : array(); |
| 299 | |
| 300 | |
| 301 | // if both of post__in and post__not_in options are defined, we have to array_diff the arrays, |
| 302 | // because we cannot use post__in & post__not_in at the time in WordPress |
| 303 | |
| 304 | if( $only_posts ){ |
| 305 | |
| 306 | if( $exclude_posts ){ |
| 307 | // remove the excluded post ids from post__in list |
| 308 | if( $only_posts = array_filter( array_diff( $only_posts, $exclude_posts ) ) ){ |
| 309 | $parsed_args['post__in'] = $only_posts; |
| 310 | } |
| 311 | } else { |
| 312 | $parsed_args['post__in'] = $only_posts; |
| 313 | } |
| 314 | $parsed_args['posts__not_in'] = ''; |
| 315 | |
| 316 | // if include_posts__in was specified |
| 317 | } elseif( $include_posts ){ |
| 318 | |
| 319 | $extra_query_args = $parsed_args; |
| 320 | |
| 321 | // query the posts other than the ones we intend to include |
| 322 | $include_and_exclude_posts = array_unique( array_filter( array_merge( $include_posts, $exclude_posts ) ) ); |
| 323 | // remove the excluded post ids from include_posts__in list |
| 324 | $the_posts_to_include = array_diff( $include_posts, $exclude_posts ); |
| 325 | |
| 326 | $extra_query_args['fields'] = 'ids'; // just get IDs, for better performance |
| 327 | $extra_query_args['post__in'] = ''; // forget post__in in this pre query |
| 328 | $extra_query_args['post__not_in'] = $include_and_exclude_posts; // dont select our include adn exclude posts in this query, we will prepend them later |
| 329 | |
| 330 | // get the post ids other than our include and exclude list |
| 331 | $other_post_ids = get_posts( $extra_query_args ); |
| 332 | |
| 333 | // prepend the included post ids |
| 334 | $merged_post_ids = array_merge( $the_posts_to_include, $other_post_ids ); |
| 335 | |
| 336 | // change the main query base on previous result |
| 337 | $parsed_args = array( |
| 338 | 'post__in' => $merged_post_ids, |
| 339 | 'orderby' => 'post__in', // query base on the order of defined post ids |
| 340 | 'posts_per_page' => $parsed_args['posts_per_page'], |
| 341 | 'ignore_sticky_posts' => 1 |
| 342 | ); |
| 343 | |
| 344 | // if just "post__not_in" option is specified |
| 345 | } elseif( $exclude_posts ) { |
| 346 | $parsed_args['post__not_in'] = $exclude_posts; |
| 347 | } |
| 348 | |
| 349 | // Remove extra query args ------------------------------------------------- |
| 350 | |
| 351 | unset( $parsed_args['include_posts__in'] ); |
| 352 | unset( $parsed_args['exclude_without_media'] ); |
| 353 | unset( $parsed_args['exclude_post_formats_in'] ); |
| 354 | unset( $parsed_args['include_post_formats_in'] ); |
| 355 | |
| 356 | return $parsed_args; |
| 357 | } |
| 358 | |
| 359 | } |
| 360 | |
| 361 | |
| 362 | |
| 363 | /*-----------------------------------------------------------------------------------*/ |
| 364 | /* Extract only raw text - remove all special charecters, html tags, js and css codes |
| 365 | /*-----------------------------------------------------------------------------------*/ |
| 366 | |
| 367 | function auxin_extract_text( $content = null ) { |
| 368 | // decode encoded html tags |
| 369 | $content = htmlspecialchars_decode($content); |
| 370 | // remove script tag and inline js content |
| 371 | $content = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $content); |
| 372 | // remove style tag and inline css content |
| 373 | $content = preg_replace('#<style(.*?)>(.*?)</style>#is' , '', $content); |
| 374 | // remove iframe content |
| 375 | $content = preg_replace('#<if'.'rame(.*?)>(.*?)</iframe>#is', '', $content); |
| 376 | // remove extra white spaces |
| 377 | $content = preg_replace('/[\s]+/', ' ', $content ); |
| 378 | // strip html tags and escape special charecters |
| 379 | $content = esc_attr(strip_tags($content)); |
| 380 | // remove double space |
| 381 | $content = preg_replace('/\s{3,}/',' ', $content ); |
| 382 | return $content; |
| 383 | } |
| 384 | |
| 385 | /*-----------------------------------------------------------------------------------*/ |
| 386 | /* Big Grid layout patterns |
| 387 | /*-----------------------------------------------------------------------------------*/ |
| 388 | |
| 389 | function auxin_get_grid_pattern( $pattern, $index, $column_media_width ) { |
| 390 | switch ( $pattern ) { |
| 391 | case 'pattern-1': |
| 392 | return auxin_big_grid_pattern_1( $index, $column_media_width ); |
| 393 | break; |
| 394 | case 'pattern-2'; |
| 395 | return auxin_big_grid_pattern_2( $index, $column_media_width ); |
| 396 | break; |
| 397 | case 'pattern-3'; |
| 398 | return auxin_big_grid_pattern_3( $index, $column_media_width ); |
| 399 | break; |
| 400 | case 'pattern-4'; |
| 401 | return auxin_big_grid_pattern_4( $index, $column_media_width ); |
| 402 | break; |
| 403 | case 'pattern-5'; |
| 404 | return auxin_big_grid_pattern_5( $index, $column_media_width ); |
| 405 | break; |
| 406 | case 'pattern-6'; |
| 407 | return auxin_big_grid_pattern_6( $index, $column_media_width ); |
| 408 | break; |
| 409 | case 'pattern-7'; |
| 410 | return auxin_big_grid_pattern_7( $index, $column_media_width ); |
| 411 | break; |
| 412 | default: |
| 413 | return auxin_get_big_grid_pattern( 'default', $index, $column_media_width ); |
| 414 | break; |
| 415 | } |
| 416 | |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * Defines the size of post tile based on pattern and given index |
| 421 | * @param string $pattern |
| 422 | * @param int $index |
| 423 | * @return Array classname, image size |
| 424 | */ |
| 425 | function auxin_get_big_grid_pattern( $pattern = 'default', $index, $column_media_width ) { |
| 426 | |
| 427 | $div_index = $index % 12; |
| 428 | $return_value = array(); |
| 429 | |
| 430 | $column_media_width = auxin_get_content_column_width( 4, 0, $column_media_width ); |
| 431 | |
| 432 | switch ( $div_index ) { |
| 433 | |
| 434 | // large squares |
| 435 | case 0: |
| 436 | case 7: |
| 437 | $return_value = array( |
| 438 | 'classname' => 'aux-big-grid-6-6 aux-t-big-grid-12-8 aux-m-big-grid-12-8', |
| 439 | 'size' => array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ) |
| 440 | ); |
| 441 | break; |
| 442 | |
| 443 | // full width |
| 444 | case 5: |
| 445 | case 11: |
| 446 | $return_value = array( |
| 447 | 'classname' => 'aux-big-grid-12-6', |
| 448 | 'size' => array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width * 0.5 ) |
| 449 | ); |
| 450 | break; |
| 451 | |
| 452 | // small squares |
| 453 | default: |
| 454 | $return_value = array( |
| 455 | 'classname' => 'aux-big-grid-3-3 aux-t-big-grid-6-5 aux-m-big-grid-12-8', |
| 456 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ) |
| 457 | ); |
| 458 | |
| 459 | } |
| 460 | |
| 461 | return $return_value; |
| 462 | } |
| 463 | |
| 464 | |
| 465 | function auxin_big_grid_pattern_1( $index, $column_media_width ) { |
| 466 | |
| 467 | $return_value = array(); |
| 468 | |
| 469 | $column_media_width = auxin_get_content_column_width( 3, 0, $column_media_width ); |
| 470 | |
| 471 | return array( |
| 472 | 'classname' => 'aux-big-grid-4-4 aux-t-big-grid-6-6 aux-m-big-grid-12-6', |
| 473 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ) |
| 474 | ); |
| 475 | |
| 476 | return $return_value; |
| 477 | |
| 478 | } |
| 479 | |
| 480 | |
| 481 | function auxin_big_grid_pattern_2( $index, $column_media_width ) { |
| 482 | |
| 483 | $column_media_width = auxin_get_content_column_width( 4, 0, $column_media_width ); |
| 484 | |
| 485 | $div_index = $index % 5; |
| 486 | $return_value = array(); |
| 487 | |
| 488 | switch ( $div_index ) { |
| 489 | |
| 490 | // large squares |
| 491 | case 1: |
| 492 | $return_value = array( |
| 493 | 'classname' => 'aux-big-grid-6-6 aux-t-big-grid-12-6 aux-m-big-grid-12-6', |
| 494 | 'size' => array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ) |
| 495 | ); |
| 496 | break; |
| 497 | |
| 498 | // small squares |
| 499 | default: |
| 500 | $return_value = array( |
| 501 | 'classname' => 'aux-big-grid-3-3 aux-t-big-grid-6-6 aux-m-big-grid-12-6', |
| 502 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ) |
| 503 | ); |
| 504 | |
| 505 | } |
| 506 | |
| 507 | return $return_value; |
| 508 | |
| 509 | } |
| 510 | |
| 511 | |
| 512 | function auxin_big_grid_pattern_3( $index, $column_media_width ) { |
| 513 | |
| 514 | $column_media_width = auxin_get_content_column_width( 2, 0, $column_media_width ); |
| 515 | |
| 516 | $div_index = $index % 3; |
| 517 | $return_value = array(); |
| 518 | |
| 519 | switch ( $div_index ) { |
| 520 | |
| 521 | case 0: |
| 522 | $return_value = array( |
| 523 | 'classname' => 'aux-big-grid-6-6 aux-t-big-grid-12-6 aux-m-big-grid-12-6', |
| 524 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ) |
| 525 | ); |
| 526 | break; |
| 527 | |
| 528 | default: |
| 529 | $return_value = array( |
| 530 | 'classname' => 'aux-big-grid-6-3 aux-t-big-grid-12-6 aux-m-big-grid-12-6', |
| 531 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width * 0.5 ) |
| 532 | ); |
| 533 | |
| 534 | } |
| 535 | |
| 536 | return $return_value; |
| 537 | |
| 538 | } |
| 539 | |
| 540 | |
| 541 | function auxin_big_grid_pattern_4( $index, $column_media_width ) { |
| 542 | |
| 543 | $column_media_width = auxin_get_content_column_width( 2, 0, $column_media_width ); |
| 544 | |
| 545 | $div_index = $index % 4; |
| 546 | $return_value = array(); |
| 547 | |
| 548 | switch ( $div_index ) { |
| 549 | |
| 550 | // large squares |
| 551 | case 0: |
| 552 | $return_value = array( |
| 553 | 'classname' => 'aux-big-grid-6-6 aux-t-big-grid-12-6 aux-m-big-grid-12-6', |
| 554 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ) |
| 555 | ); |
| 556 | break; |
| 557 | |
| 558 | case 1: |
| 559 | $return_value = array( |
| 560 | 'classname' => 'aux-big-grid-6-3 aux-t-big-grid-12-6 aux-m-big-grid-12-6', |
| 561 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width * 0.5 ) |
| 562 | ); |
| 563 | break; |
| 564 | |
| 565 | // small squares |
| 566 | default: |
| 567 | $return_value = array( |
| 568 | 'classname' => 'aux-big-grid-3-3 aux-t-big-grid-6-6 aux-m-big-grid-12-6', |
| 569 | 'size' => array( 'width' => $column_media_width * 0.5 , 'height' => $column_media_width * 0.5 ) |
| 570 | ); |
| 571 | |
| 572 | } |
| 573 | |
| 574 | return $return_value; |
| 575 | } |
| 576 | |
| 577 | |
| 578 | function auxin_big_grid_pattern_5( $index, $column_media_width ) { |
| 579 | |
| 580 | $column_media_width = auxin_get_content_column_width( 2, 0, $column_media_width ); |
| 581 | |
| 582 | $div_index = $index % 6; |
| 583 | $return_value = array(); |
| 584 | |
| 585 | switch ( $div_index ) { |
| 586 | |
| 587 | // large squares |
| 588 | case 0: |
| 589 | case 1: |
| 590 | $return_value = array( |
| 591 | 'classname' => 'aux-big-grid-6-6 aux-t-big-grid-12-6 aux-m-big-grid-12-6', |
| 592 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ) |
| 593 | ); |
| 594 | break; |
| 595 | |
| 596 | // small squares |
| 597 | default: |
| 598 | $return_value = array( |
| 599 | 'classname' => 'aux-big-grid-3-3 aux-t-big-grid-6-6 aux-m-big-grid-12-6', |
| 600 | 'size' => array( 'width' => $column_media_width * 0.5, 'height' => $column_media_width * 0.5 ) |
| 601 | ); |
| 602 | |
| 603 | } |
| 604 | |
| 605 | return $return_value; |
| 606 | |
| 607 | } |
| 608 | |
| 609 | |
| 610 | function auxin_big_grid_pattern_6( $index, $column_media_width ) { |
| 611 | |
| 612 | $column_media_width = auxin_get_content_column_width( 3, 15, $column_media_width ); |
| 613 | $return_value = array(); |
| 614 | |
| 615 | $return_value = array( |
| 616 | 'classname' => 'aux-big-grid-lg-4-4 aux-t-big-grid-lg-6-6 aux-m-big-grid-lg-12-6', |
| 617 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ) |
| 618 | ); |
| 619 | |
| 620 | return $return_value; |
| 621 | |
| 622 | } |
| 623 | |
| 624 | |
| 625 | function auxin_big_grid_pattern_7( $index, $column_media_width ) { |
| 626 | $column_media_width = auxin_get_content_column_width( 3, 1, $column_media_width ); |
| 627 | $return_value = array(); |
| 628 | |
| 629 | $return_value = array( |
| 630 | 'classname' => 'aux-big-grid-sg-4-4 aux-t-big-grid-sg-6-6 aux-m-big-grid-sg-12-6', |
| 631 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ) |
| 632 | ); |
| 633 | |
| 634 | return $return_value; |
| 635 | |
| 636 | } |
| 637 | |
| 638 | |
| 639 | /*-----------------------------------------------------------------------------------*/ |
| 640 | /* Tiles layout patterns |
| 641 | /*-----------------------------------------------------------------------------------*/ |
| 642 | |
| 643 | |
| 644 | /** |
| 645 | * Defines the size of post tile based on pattern and given index |
| 646 | * @param string $pattern |
| 647 | * @param int $index |
| 648 | * @return Array classname, image size |
| 649 | */ |
| 650 | function auxin_get_tile_pattern( $pattern, $index, $column_media_width ) { |
| 651 | |
| 652 | switch ( $pattern ) { |
| 653 | |
| 654 | case 'pattern-1': |
| 655 | $pattern = auxin_tile_pattern_1( $index, $column_media_width ); |
| 656 | break; |
| 657 | case 'pattern-2': |
| 658 | $pattern = auxin_tile_pattern_2( $index, $column_media_width ); |
| 659 | break; |
| 660 | case 'pattern-3': |
| 661 | $pattern = auxin_tile_pattern_3( $index, $column_media_width ); |
| 662 | break; |
| 663 | case 'pattern-4': |
| 664 | $pattern = auxin_tile_pattern_4( $index, $column_media_width ); |
| 665 | break; |
| 666 | case 'pattern-5': |
| 667 | $pattern = auxin_tile_pattern_5( $index, $column_media_width ); |
| 668 | break; |
| 669 | case 'pattern-6': |
| 670 | $pattern = auxin_tile_pattern_6( $index, $column_media_width ); |
| 671 | break; |
| 672 | case 'pattern-7': |
| 673 | $pattern = auxin_tile_pattern_7( $index, $column_media_width ); |
| 674 | break; |
| 675 | case 'pattern-8': |
| 676 | $pattern = auxin_tile_pattern_8( $index, $column_media_width ); |
| 677 | break; |
| 678 | default: |
| 679 | $pattern = auxin_tile_pattern_default( $index, $column_media_width ); |
| 680 | break; |
| 681 | } |
| 682 | |
| 683 | if( empty( $pattern['image_sizes'] ) ){ |
| 684 | $pattern['image_sizes'] = 'auto'; |
| 685 | } |
| 686 | if( empty( $pattern['srcset_sizes'] ) ){ |
| 687 | $pattern['srcset_sizes'] = 'auto'; |
| 688 | } |
| 689 | |
| 690 | return $pattern; |
| 691 | } |
| 692 | |
| 693 | function auxin_tile_pattern_default( $index, $column_media_width ) { |
| 694 | |
| 695 | $column_media_width = auxin_get_content_column_width( 4, 0, $column_media_width ); |
| 696 | $custom_aspect_ratio = 0.5; |
| 697 | |
| 698 | $div_index = $index % 12; |
| 699 | $return_value = array(); |
| 700 | |
| 701 | switch ( $div_index ) { |
| 702 | |
| 703 | // large squares |
| 704 | case 0: |
| 705 | case 7: |
| 706 | $return_value = array( |
| 707 | 'classname' => 'aux-tile-6-6 aux-t-tile-12-12 aux-m-tile-12-12', |
| 708 | 'size' => array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 709 | ); |
| 710 | break; |
| 711 | |
| 712 | // full width |
| 713 | case 5: |
| 714 | case 11: |
| 715 | $return_value = array( |
| 716 | 'classname' => 'aux-tile-12-6', |
| 717 | 'size' => array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width * $custom_aspect_ratio ), |
| 718 | ); |
| 719 | break; |
| 720 | |
| 721 | // small squares |
| 722 | default: |
| 723 | $return_value = array( |
| 724 | 'classname' => 'aux-tile-3-3 aux-t-tile-6-6 aux-m-tile-6-6', |
| 725 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 726 | ); |
| 727 | |
| 728 | } |
| 729 | |
| 730 | return $return_value; |
| 731 | |
| 732 | } |
| 733 | |
| 734 | function auxin_tile_pattern_1( $index, $column_media_width ) { |
| 735 | |
| 736 | $column_media_width = auxin_get_content_column_width( 3, 0, $column_media_width ); |
| 737 | |
| 738 | return array( |
| 739 | 'classname' => 'aux-tile-4-4 aux-t-tile-6-6 aux-m-tile-12-12', |
| 740 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ) |
| 741 | ); |
| 742 | } |
| 743 | |
| 744 | function auxin_tile_pattern_2( $index, $column_media_width ) { |
| 745 | |
| 746 | $column_media_width = auxin_get_content_column_width( 4, 0, $column_media_width ); |
| 747 | |
| 748 | $div_index = $index % 5; |
| 749 | $return_value = array(); |
| 750 | |
| 751 | switch ( $div_index ) { |
| 752 | |
| 753 | // large squares |
| 754 | case 1: |
| 755 | $return_value = array( |
| 756 | 'classname' => 'aux-tile-6-6 aux-t-tile-6-6 aux-m-tile-12-12', |
| 757 | 'size' => array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ) |
| 758 | ); |
| 759 | break; |
| 760 | |
| 761 | // small squares |
| 762 | default: |
| 763 | $return_value = array( |
| 764 | 'classname' => 'aux-tile-3-3 aux-t-tile-6-6 aux-m-tile-6-6', |
| 765 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ) |
| 766 | ); |
| 767 | |
| 768 | } |
| 769 | |
| 770 | return $return_value; |
| 771 | |
| 772 | } |
| 773 | |
| 774 | function auxin_tile_pattern_3( $index, $column_media_width ) { |
| 775 | |
| 776 | $column_media_width = auxin_get_content_column_width( 2, 0, $column_media_width ); |
| 777 | |
| 778 | $div_index = $index % 3; |
| 779 | $return_value = array(); |
| 780 | |
| 781 | switch ( $div_index ) { |
| 782 | |
| 783 | case 0: |
| 784 | $return_value = array( |
| 785 | 'classname' => 'aux-tile-6-6 aux-t-tile-6-6 aux-m-tile-12-12', |
| 786 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ) |
| 787 | ); |
| 788 | break; |
| 789 | |
| 790 | default: |
| 791 | $return_value = array( |
| 792 | 'classname' => 'aux-tile-6-3 aux-t-tile-12-6 aux-m-tile-12-6', |
| 793 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width * 0.5 ) |
| 794 | ); |
| 795 | |
| 796 | } |
| 797 | |
| 798 | return $return_value; |
| 799 | |
| 800 | } |
| 801 | |
| 802 | |
| 803 | function auxin_tile_pattern_4( $index, $column_media_width ) { |
| 804 | |
| 805 | $column_media_width = auxin_get_content_column_width( 2, 0, $column_media_width ); |
| 806 | |
| 807 | $div_index = $index % 4; |
| 808 | $return_value = array(); |
| 809 | |
| 810 | switch ( $div_index ) { |
| 811 | |
| 812 | // large squares |
| 813 | case 0: |
| 814 | $return_value = array( |
| 815 | 'classname' => 'aux-tile-6-6 aux-t-tile-6-6 aux-m-tile-12-12', |
| 816 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 817 | ); |
| 818 | break; |
| 819 | |
| 820 | case 1: |
| 821 | $return_value = array( |
| 822 | 'classname' => 'aux-tile-6-3 aux-t-tile-12-6 aux-m-tile-12-6', |
| 823 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width * 0.5), |
| 824 | ); |
| 825 | break; |
| 826 | |
| 827 | // small squares |
| 828 | default: |
| 829 | $return_value = array( |
| 830 | 'classname' => 'aux-tile-3-3 aux-t-tile-6-6 aux-m-tile-6-6', |
| 831 | 'size' => array( 'width' => $column_media_width * 0.5, 'height' => $column_media_width * 0.5 ), |
| 832 | ); |
| 833 | |
| 834 | } |
| 835 | |
| 836 | return $return_value; |
| 837 | } |
| 838 | |
| 839 | |
| 840 | function auxin_tile_pattern_5( $index, $column_media_width ) { |
| 841 | |
| 842 | $column_media_width = auxin_get_content_column_width( 2, 0, $column_media_width ); |
| 843 | |
| 844 | $div_index = $index % 6; |
| 845 | $return_value = array(); |
| 846 | |
| 847 | switch ( $div_index ) { |
| 848 | |
| 849 | // large squares |
| 850 | case 0: |
| 851 | case 1: |
| 852 | $return_value = array( |
| 853 | 'classname' => 'aux-tile-6-6 aux-t-tile-6-6 aux-m-tile-12-12', |
| 854 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 855 | ); |
| 856 | break; |
| 857 | |
| 858 | // small squares |
| 859 | default: |
| 860 | $return_value = array( |
| 861 | 'classname' => 'aux-tile-3-3 aux-t-tile-6-6 aux-m-tile-6-6', |
| 862 | 'size' => array( 'width' => $column_media_width * 0.5, 'height' => $column_media_width * 0.5 ), |
| 863 | ); |
| 864 | |
| 865 | } |
| 866 | |
| 867 | return $return_value; |
| 868 | |
| 869 | } |
| 870 | |
| 871 | |
| 872 | function auxin_tile_pattern_6( $index, $column_media_width ) { |
| 873 | |
| 874 | $column_media_width = auxin_get_content_column_width( 3, 15, $column_media_width ); |
| 875 | |
| 876 | $return_value = array( |
| 877 | 'classname' => 'aux-tile-lg-4-4 aux-t-tile-lg-6-6 aux-m-tile-lg-12-12', |
| 878 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 879 | ); |
| 880 | |
| 881 | return $return_value; |
| 882 | |
| 883 | } |
| 884 | |
| 885 | |
| 886 | function auxin_tile_pattern_7( $index, $column_media_width ) { |
| 887 | |
| 888 | $column_media_width = auxin_get_content_column_width( 3, 1, $column_media_width ); |
| 889 | |
| 890 | $return_value = array( |
| 891 | 'classname' => 'aux-tile-sg-4-4 aux-t-tile-sg-6-6 aux-m-tile-sg-12-12', |
| 892 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 893 | ); |
| 894 | |
| 895 | return $return_value; |
| 896 | |
| 897 | } |
| 898 | function auxin_tile_pattern_8( $index, $column_media_width ) { |
| 899 | |
| 900 | $column_media_width = auxin_get_content_column_width( 2, 0, $column_media_width ); |
| 901 | |
| 902 | $return_value = array( |
| 903 | 'classname' => 'aux-tile-6-6 aux-t-tile-6-6 aux-m-tile-12-12', |
| 904 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 905 | ); |
| 906 | |
| 907 | return $return_value; |
| 908 | |
| 909 | } |
| 910 | /*-----------------------------------------------------------------------------------*/ |
| 911 | /* Retrieves the provider from an embed code link |
| 912 | /*-----------------------------------------------------------------------------------*/ |
| 913 | |
| 914 | |
| 915 | function auxin_extract_embed_provider_name( $src ){ |
| 916 | // TODO - Else condition will be removed on WP 5.6 |
| 917 | if( file_exists( ABSPATH . WPINC . '/class-wp-oembed.php' ) ){ |
| 918 | require_once( ABSPATH . WPINC . '/class-wp-oembed.php' ); |
| 919 | } else { |
| 920 | require_once( ABSPATH . WPINC . '/class-oembed.php' ); |
| 921 | } |
| 922 | $oembed = _wp_oembed_get_object(); |
| 923 | if( ! $provider = $oembed->get_provider( $src ) ){ |
| 924 | return ''; |
| 925 | } |
| 926 | |
| 927 | $provider_info = parse_url( $provider ); |
| 928 | if( $provider_info['host'] ){ |
| 929 | $host_parts = explode( '.', $provider_info['host'] ); |
| 930 | $host_parts_num = count( $host_parts ); |
| 931 | if( $host_parts_num > 1 ){ |
| 932 | return $host_parts[ $host_parts_num -2 ]; |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | return ''; |
| 937 | } |
| 938 | |
| 939 | |
| 940 | |
| 941 | //// Store content in file //////////////////////////////////////////////////////// |
| 942 | |
| 943 | /** |
| 944 | * Creates and stores content in a file (#admin) |
| 945 | * |
| 946 | * @param string $content The content for writing in the file |
| 947 | * @param string $file_location The address that we plan to create the file in. |
| 948 | * |
| 949 | * @return boolean Returns true if the file is created and updated successfully, false on failure |
| 950 | */ |
| 951 | function auxin_put_contents( $content, $file_location = '', $chmode = 0644 ){ |
| 952 | |
| 953 | if( empty( $file_location ) ){ |
| 954 | return false; |
| 955 | } |
| 956 | |
| 957 | /** |
| 958 | * Initialize the WP_Filesystem |
| 959 | */ |
| 960 | global $wp_filesystem; |
| 961 | if ( empty( $wp_filesystem ) ) { |
| 962 | require_once ( ABSPATH.'/wp-admin/includes/file.php' ); |
| 963 | WP_Filesystem(); |
| 964 | } |
| 965 | |
| 966 | // Write the content, if possible |
| 967 | if ( wp_mkdir_p( dirname( $file_location ) ) && ! $wp_filesystem->put_contents( $file_location, $content, $chmode ) ) { |
| 968 | // If writing the content in the file was not successful |
| 969 | return false; |
| 970 | } else { |
| 971 | return true; |
| 972 | } |
| 973 | |
| 974 | } |
| 975 | |
| 976 | |
| 977 | //// Stores content in custom js file ///////////////////////////////////////////// |
| 978 | |
| 979 | |
| 980 | /** |
| 981 | * Stores JavaScript content in custom js file (#admin) |
| 982 | * |
| 983 | * @return boolean Returns true if the file is created and updated successfully, false on failure |
| 984 | */ |
| 985 | function auxin_save_custom_js(){ |
| 986 | |
| 987 | $js_string = get_theme_mod( 'custom_js_string' ); |
| 988 | |
| 989 | ob_start(); |
| 990 | ?> |
| 991 | /* |
| 992 | =============================================================== |
| 993 | #CUSTOM JavaScript |
| 994 | - Please do not edit this file. This file is generated from admin area. |
| 995 | - Every changes here will be overwritten by theme |
| 996 | ===============================================================*/ |
| 997 | <?php |
| 998 | |
| 999 | $js_string = ob_get_clean() . $js_string; |
| 1000 | |
| 1001 | |
| 1002 | if ( auxin_put_contents_dir( $js_string, 'custom.js' ) ) { |
| 1003 | set_theme_mod( 'custom_js_ver', rand(10, 99)/10 ); // disable inline css output |
| 1004 | set_theme_mod( 'use_inline_custom_js' , false ); // disable inline css output |
| 1005 | |
| 1006 | return true; |
| 1007 | } else { |
| 1008 | // if the directory is not writable, try inline css fallback |
| 1009 | set_theme_mod( 'use_inline_custom_js' , true ); // save css rules as option to print as inline css |
| 1010 | |
| 1011 | return false; |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | |
| 1016 | /** |
| 1017 | * Removes an specific content from custom js file (#admin) |
| 1018 | * |
| 1019 | * @param string $ref_name The reference name for referring a content in $js_array array |
| 1020 | * |
| 1021 | * @return boolean Returns true if the content was removed successfully, false on failure |
| 1022 | */ |
| 1023 | function auxin_remove_custom_js( $ref_name = '' ){ |
| 1024 | |
| 1025 | // retrieve the js array list |
| 1026 | $js_array = get_theme_mod( 'custom_js_array', array() ); |
| 1027 | |
| 1028 | if( isset( $js_array[ $ref_name ] ) ){ |
| 1029 | unset( $js_array[ $ref_name ] ); |
| 1030 | |
| 1031 | set_theme_mod( 'custom_js_array' , $js_array ); |
| 1032 | // update the file content too |
| 1033 | auxin_add_custom_js(); |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | |
| 1038 | /** |
| 1039 | * Retrieves the list of custom scripts generated with themes options |
| 1040 | * |
| 1041 | * @param string $exclude_ref_names The reference names that are expected to be excluded from result |
| 1042 | * |
| 1043 | * @return boolean The list of custom scripts generated with themes options |
| 1044 | */ |
| 1045 | function auxin_get_custom_js_array( $exclude_ref_names = array() ){ |
| 1046 | // retrieve the css array list |
| 1047 | $js_array = get_theme_mod( 'custom_js_array', array() ); |
| 1048 | |
| 1049 | return array_diff_key( $js_array, array_flip( (array) $exclude_ref_names ) ); |
| 1050 | } |
| 1051 | |
| 1052 | |
| 1053 | |
| 1054 | //// Stores content in custom css file ///////////////////////////////////////////// |
| 1055 | |
| 1056 | |
| 1057 | /** |
| 1058 | * Stores css content in custom css file (#admin) |
| 1059 | * |
| 1060 | * @return boolean Returns true if the file is created and updated successfully, false on failure |
| 1061 | */ |
| 1062 | function auxin_save_custom_css(){ |
| 1063 | |
| 1064 | $css_string = get_theme_mod( 'custom_css_string' ); |
| 1065 | |
| 1066 | ob_start(); |
| 1067 | ?> |
| 1068 | /* |
| 1069 | =============================================================== |
| 1070 | #CUSTOM CSS |
| 1071 | - Please do not edit this file. This file is generated from admin area. |
| 1072 | - Every changes here will be overwritten by theme |
| 1073 | ===============================================================*/ |
| 1074 | <?php |
| 1075 | |
| 1076 | $css_string = ob_get_clean() . $css_string; |
| 1077 | |
| 1078 | if ( auxin_put_contents_dir( $css_string, 'custom.css' ) ) { |
| 1079 | |
| 1080 | set_theme_mod( 'custom_css_ver', rand(10, 99)/10 ); |
| 1081 | set_theme_mod( 'use_inline_custom_css' , false ); // disable inline css output |
| 1082 | |
| 1083 | return true; |
| 1084 | // if the directory is not writable, try inline css fallback |
| 1085 | } else { |
| 1086 | set_theme_mod( 'use_inline_custom_css' , true ); // save css rules as option to print as inline css |
| 1087 | return false; |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | |
| 1092 | /** |
| 1093 | * Removes an specific content from custom css file (#admin) |
| 1094 | * |
| 1095 | * @param string $ref_name The reference name for referring a content in $css_array array |
| 1096 | * |
| 1097 | * @return boolean Returns true if the content was removed successfully, false on failure |
| 1098 | */ |
| 1099 | function auxin_remove_custom_css( $ref_name = '' ){ |
| 1100 | |
| 1101 | // retrieve the css array list |
| 1102 | $css_array = get_theme_mod( 'custom_css_array', array() ); |
| 1103 | |
| 1104 | if( isset( $css_array[ $ref_name ] ) ){ |
| 1105 | unset( $css_array[ $ref_name ] ); |
| 1106 | |
| 1107 | set_theme_mod( 'custom_css_array', $css_array ); |
| 1108 | // update the file content too |
| 1109 | auxin_add_custom_css(); |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | |
| 1114 | /** |
| 1115 | * Retrieves the list of custom styles generated with themes options |
| 1116 | * |
| 1117 | * @param string $exclude_ref_names The reference names that are expected to be excluded from result |
| 1118 | * |
| 1119 | * @return boolean The list of custom styles generated with themes options |
| 1120 | */ |
| 1121 | function auxin_get_custom_css_array( $exclude_ref_names = array() ){ |
| 1122 | // retrieve the css array list |
| 1123 | $css_array = get_theme_mod( 'custom_css_array', array() ); |
| 1124 | |
| 1125 | return array_diff_key( $css_array, array_flip( (array) $exclude_ref_names ) ); |
| 1126 | } |
| 1127 | |
| 1128 | |
| 1129 | /** |
| 1130 | * Retrieves the custom styles generated with themes options |
| 1131 | * |
| 1132 | * @param string $exclude_ref_names The css reference names that are expected to be excluded from result |
| 1133 | * |
| 1134 | * @return boolean The custom styles generated with themes options |
| 1135 | */ |
| 1136 | function auxin_get_custom_css_string( $exclude_ref_names = array() ){ |
| 1137 | // retrieve the css array list |
| 1138 | $css_array = auxin_get_custom_css_array( (array) $exclude_ref_names ); |
| 1139 | $css_string = ''; |
| 1140 | |
| 1141 | $sep_comment = apply_filters( 'auxin_custom_css_sep_comment', "/* %s \n=========================*/\n" ); |
| 1142 | |
| 1143 | // Convert the contents in array to string |
| 1144 | if( is_array( $css_array ) ){ |
| 1145 | foreach ( $css_array as $node_ref => $node_content ) { |
| 1146 | if( ! is_numeric( $node_ref) ){ |
| 1147 | $css_string .= sprintf( $sep_comment, str_replace( '_', '-', $node_ref ) ); |
| 1148 | } |
| 1149 | $css_string .= "$node_content\n"; |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | // Remove <style> if user used them in the style content |
| 1154 | return str_replace( array( "<style>", "</style>" ), array('', ''), $css_string ); |
| 1155 | } |
| 1156 | |
| 1157 | |
| 1158 | /** |
| 1159 | * Extract numbers from string |
| 1160 | * |
| 1161 | * @param string $str The string that contains numbers |
| 1162 | * @param int $default The number which should be returned if no number found in the string |
| 1163 | * @return int The extracted numbers |
| 1164 | */ |
| 1165 | function auxin_get_numerics( $str, $default = null ) { |
| 1166 | if( empty( $str ) ){ |
| 1167 | return is_numeric( $default ) ? $default: ''; |
| 1168 | } |
| 1169 | preg_match('/\d+/', $str, $matches); |
| 1170 | return $matches[0]; |
| 1171 | } |
| 1172 | |
| 1173 | |
| 1174 | /** |
| 1175 | * Prints JS variable |
| 1176 | * |
| 1177 | * @param string $object_name The object or variable name |
| 1178 | * @param array $object_value The object value |
| 1179 | */ |
| 1180 | function auxin_print_script_object( $object_name, $object_value = array() ){ |
| 1181 | |
| 1182 | if( empty( $object_name ) ){ |
| 1183 | _doing_it_wrong( __FUNCTION__, 'The object name cannot be empty' ); |
| 1184 | return; |
| 1185 | } |
| 1186 | // remove unespected chars |
| 1187 | $object_name = trim( $object_name, '.' ); |
| 1188 | |
| 1189 | if( false !== strpos( $object_name, '.') ){ |
| 1190 | $script = sprintf( 'auxinNS("%1$s"); %1$s=%2$s;', esc_js( $object_name ), wp_json_encode( $object_value ) ); |
| 1191 | } else { |
| 1192 | $script = sprintf( 'var %1$s=%2$s;', esc_js( $object_name ), wp_json_encode( $object_value ) ); |
| 1193 | } |
| 1194 | |
| 1195 | echo $script ? '<script>'. $script .'</script>' : ''; |
| 1196 | } |
| 1197 | |
| 1198 | /*-----------------------------------------------------------------------------------*/ |
| 1199 | /* Returns post type menu name |
| 1200 | /*-----------------------------------------------------------------------------------*/ |
| 1201 | |
| 1202 | if( ! function_exists( 'auxin_get_post_type_name' ) ){ |
| 1203 | |
| 1204 | // returns post type menu name |
| 1205 | function auxin_get_post_type_name( $post_type = '' ){ |
| 1206 | $post_type = empty( $post_type ) ? get_post_type() : $post_type; |
| 1207 | $post_type_obj = get_post_type_object( $post_type ); |
| 1208 | |
| 1209 | return apply_filters( 'auxin_get_post_type_name', $post_type_obj->labels->menu_name, $post_type ); |
| 1210 | } |
| 1211 | |
| 1212 | } |
| 1213 | |
| 1214 | /** |
| 1215 | * Generates and retrieves a random token |
| 1216 | * |
| 1217 | * @param integer $length The token length |
| 1218 | * @return strinf The random token |
| 1219 | */ |
| 1220 | function auxin_random_token( $length = 32 ){ |
| 1221 | $length = ! is_numeric( $length ) ? 4 : $length; |
| 1222 | $length = $length < 1 ? 32 : $length; |
| 1223 | |
| 1224 | if ( function_exists('random_bytes') ) { |
| 1225 | return bin2hex(random_bytes( $length )); |
| 1226 | } |
| 1227 | if (function_exists('mcrypt_create_iv')) { |
| 1228 | return bin2hex(mcrypt_create_iv( $length, MCRYPT_DEV_URANDOM )); |
| 1229 | } |
| 1230 | if ( function_exists('openssl_random_pseudo_bytes') ) { |
| 1231 | return bin2hex(openssl_random_pseudo_bytes( $length )); |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | |
| 1236 | /*-----------------------------------------------------------------------------------*/ |
| 1237 | /* A function to generate header and footer for all widgets |
| 1238 | /*-----------------------------------------------------------------------------------*/ |
| 1239 | |
| 1240 | function auxin_get_widget_scafold( $atts, $default_atts, $shortcode_content = '' ){ |
| 1241 | |
| 1242 | $result = array( |
| 1243 | 'parsed_atts' => '', |
| 1244 | 'widget_info' => '', |
| 1245 | 'widget_header' => '', |
| 1246 | 'widget_title' => '', |
| 1247 | 'widget_footer' => '', |
| 1248 | 'ajax_data' => '' |
| 1249 | ); |
| 1250 | |
| 1251 | // ---- |
| 1252 | if( ! isset( $default_atts['extra_classes'] ) ){ |
| 1253 | $default_atts['extra_classes'] = ''; |
| 1254 | } |
| 1255 | if( ! isset( $default_atts['custom_el_id'] ) ){ |
| 1256 | $default_atts['custom_el_id'] = ''; |
| 1257 | } |
| 1258 | if( ! isset( $default_atts['content'] ) ){ |
| 1259 | $default_atts['content'] = ''; |
| 1260 | } |
| 1261 | if( empty( $default_atts['universal_id'] ) ){ |
| 1262 | $default_atts['universal_id'] = 'au'.auxin_random_token(4); |
| 1263 | } |
| 1264 | if( ! isset( $default_atts['skip_wrappers'] ) ){ |
| 1265 | $default_atts['skip_wrappers'] = false; |
| 1266 | } |
| 1267 | if( ! isset( $default_atts['loadmore_type'] ) ){ |
| 1268 | $default_atts['loadmore_type'] = ''; |
| 1269 | } |
| 1270 | if( ! isset( $default_atts['base'] ) ){ |
| 1271 | $default_atts['base'] = ''; |
| 1272 | } |
| 1273 | if( ! isset( $default_atts['content_width'] ) ){ |
| 1274 | if( ! did_action( 'wp' ) && function_exists( 'auxin_set_content_width' ) ){ |
| 1275 | $default_atts['content_width'] = auxin_set_content_width(); |
| 1276 | } else { |
| 1277 | global $aux_content_width; |
| 1278 | $default_atts['content_width'] = $aux_content_width; |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | // animation options |
| 1283 | if( ! isset( $default_atts['inview_transition'] ) ){ |
| 1284 | $default_atts['inview_transition'] = 'none'; |
| 1285 | } |
| 1286 | if( ! isset( $default_atts['inview_duration'] ) ){ |
| 1287 | $default_atts['inview_duration'] = ''; |
| 1288 | } |
| 1289 | if( ! isset( $default_atts['inview_delay'] ) ){ |
| 1290 | $default_atts['inview_delay'] = ''; |
| 1291 | } |
| 1292 | if( ! isset( $default_atts['inview_repeat'] ) ){ |
| 1293 | $default_atts['inview_repeat'] = 'no'; |
| 1294 | } |
| 1295 | if( ! isset( $default_atts['inview_offset'] ) ){ |
| 1296 | $default_atts['inview_offset'] = ''; |
| 1297 | } |
| 1298 | |
| 1299 | // What called the widget fallback function |
| 1300 | if( ! isset( $default_atts['called_from'] ) ){ |
| 1301 | $default_atts['called_from'] = ''; |
| 1302 | } |
| 1303 | |
| 1304 | // prevent nested query while placing a recent posts widget in the same post |
| 1305 | if( isset( $atts['exclude'] ) && ! empty( $atts['exclude'] ) ){ |
| 1306 | global $post; |
| 1307 | if( ! empty( $post->ID ) ){ |
| 1308 | $atts['exclude'] .= ',' . $post->ID; |
| 1309 | } |
| 1310 | } |
| 1311 | |
| 1312 | // Widget general info |
| 1313 | $before_widget = $after_widget = ''; |
| 1314 | $before_title = $after_title = ''; |
| 1315 | |
| 1316 | // If widget info is passed, extract them in above variables |
| 1317 | if( isset( $atts['widget_info'] ) ){ |
| 1318 | $result['widget_info'] = $atts['widget_info']; |
| 1319 | extract( $atts['widget_info'] ); |
| 1320 | } |
| 1321 | // CSS class names for section ------------- |
| 1322 | |
| 1323 | // The default CSS classes for widget container |
| 1324 | // Note that 'widget-container' should be in all element |
| 1325 | $_css_classes = array( 'widget-container' ); |
| 1326 | |
| 1327 | // Parse shortcode attributes |
| 1328 | $parsed_atts = shortcode_atts( $default_atts, $atts, __FUNCTION__ ); |
| 1329 | |
| 1330 | if( empty( $parsed_atts['content'] ) ){ |
| 1331 | $parsed_atts['content'] = $shortcode_content; |
| 1332 | } |
| 1333 | if( empty( $parsed_atts['loadmore_per_page'] ) ){ |
| 1334 | $parsed_atts['loadmore_per_page'] = ! empty( $parsed_atts['num'] ) ? $parsed_atts['num'] : 12; |
| 1335 | } |
| 1336 | |
| 1337 | $result['parsed_atts'] = $parsed_atts; |
| 1338 | |
| 1339 | // make the result params filterable prior to generating markup variables |
| 1340 | $result = apply_filters( 'auxin_pre_widget_scafold_params', $result, $atts, $default_atts, $shortcode_content ); |
| 1341 | |
| 1342 | if( $result['parsed_atts']['skip_wrappers'] ){ |
| 1343 | return $result; |
| 1344 | } |
| 1345 | |
| 1346 | if( ! empty( $result['parsed_atts']['loadmore_type'] ) ){ |
| 1347 | |
| 1348 | if( empty( $result['parsed_atts']["base"] ) ){ |
| 1349 | _doing_it_wrong( __FUNCTION__, 'For using ajax load more feature, "base" parameter in element default attributes is required.' ); |
| 1350 | } |
| 1351 | |
| 1352 | // Enqueue wp-mediaelement |
| 1353 | wp_enqueue_style ( 'wp-mediaelement' ); |
| 1354 | wp_enqueue_script( 'wp-mediaelement' ); |
| 1355 | |
| 1356 | $ajax_args = $result['parsed_atts']; |
| 1357 | |
| 1358 | if( isset( $ajax_args['use_wp_query'] ) && $ajax_args['use_wp_query'] ){ |
| 1359 | $queried_object = get_queried_object(); |
| 1360 | if( $queried_object instanceof WP_Term ){ |
| 1361 | $ajax_args['cat'] = $queried_object->term_id; |
| 1362 | $ajax_args['taxonomy_name'] = $queried_object->taxonomy; |
| 1363 | } |
| 1364 | } |
| 1365 | |
| 1366 | // remove redundant ajax args |
| 1367 | unset( $ajax_args['base'] ); |
| 1368 | unset( $ajax_args['base_class'] ); |
| 1369 | unset( $ajax_args['use_wp_query'] ); |
| 1370 | |
| 1371 | // force the element not to render wrappers for ajax handler |
| 1372 | $ajax_args['skip_wrappers'] = true; |
| 1373 | |
| 1374 | $result['ajax_data'] = array( |
| 1375 | 'nonce' => wp_create_nonce('auxin_front_load_more'), |
| 1376 | 'args' => $ajax_args, |
| 1377 | 'handler' => $result['parsed_atts']["base"], |
| 1378 | 'per_page'=> $parsed_atts['loadmore_per_page'] |
| 1379 | ); |
| 1380 | |
| 1381 | $_css_classes[] = 'aux-ajax-type-' . $result['parsed_atts']['loadmore_type']; |
| 1382 | if ( 'infinite-scroll' === $result['parsed_atts']['loadmore_type'] ) { |
| 1383 | $_css_classes[] = 'aux-ajax-type-scroll'; |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | // Defining extra class names -------------- |
| 1388 | |
| 1389 | // Add extra class names to class list here - widget-{element_name} |
| 1390 | $_css_classes[] = $result['parsed_atts']['base_class']; |
| 1391 | |
| 1392 | $_css_classes[] = 'aux-parent-' . $result['parsed_atts']['universal_id']; |
| 1393 | |
| 1394 | $_widget_attrs = ''; |
| 1395 | $_widget_styles = ''; |
| 1396 | |
| 1397 | if( ! empty( $result['parsed_atts']['inview_transition'] ) && 'none' !== $result['parsed_atts']['inview_transition'] ){ |
| 1398 | $_css_classes[] = 'aux-appear-watch'; |
| 1399 | $_css_classes[] = esc_attr( $result['parsed_atts']['inview_transition'] ); |
| 1400 | |
| 1401 | if( ! empty( $result['parsed_atts']['inview_duration'] ) && 600 != $result['parsed_atts']['inview_duration'] ){ |
| 1402 | $_widget_styles .= 'animation-duration:' . esc_attr( rtrim( $result['parsed_atts']['inview_duration'], 'ms') ) . 'ms;'; |
| 1403 | $_widget_styles .= 'transition-duration:' . esc_attr( rtrim( $result['parsed_atts']['inview_duration'], 'ms') ) . 'ms;'; |
| 1404 | } |
| 1405 | if( ! empty( $result['parsed_atts']['inview_delay'] ) ){ |
| 1406 | $_widget_styles .= 'animation-delay:' . esc_attr( rtrim( $result['parsed_atts']['inview_delay'], 'ms') ) . 'ms;'; |
| 1407 | $_widget_styles .= 'transition-delay:' . esc_attr( rtrim( $result['parsed_atts']['inview_delay'], 'ms') ) . 'ms;'; |
| 1408 | } |
| 1409 | if( ! empty( $result['parsed_atts']['inview_repeat'] ) && 'no' !== $result['parsed_atts']['inview_repeat'] ){ |
| 1410 | $_css_classes[] = 'aux-appear-repeat'; |
| 1411 | } |
| 1412 | if( ! empty( $result['parsed_atts']['inview_offset'] ) ){ |
| 1413 | $offset = $result['parsed_atts']['inview_offset']; |
| 1414 | if( false === strpos( $offset, '%' ) ){ |
| 1415 | $offset = trim( $offset, 'px' ) . 'px'; |
| 1416 | } |
| 1417 | $_widget_attrs .= 'data-offset="' . esc_attr( $offset ) . '" '; |
| 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | $_widget_classes = auxin_merge_css_classes( $_css_classes, $result['parsed_atts']['extra_classes'] ); |
| 1422 | $_widget_classes = esc_attr( trim( join( ' ', array_unique( $_widget_classes ) ) ) ); |
| 1423 | |
| 1424 | // Generate the opening tags for widget or shortcode element |
| 1425 | if( $before_widget ){ |
| 1426 | |
| 1427 | $result['widget_header'] .= str_replace( |
| 1428 | array( 'class="', '>','<div'), |
| 1429 | array( 'class="'.$_widget_classes.' ', ' style="'. $_widget_styles .'" '. $_widget_attrs .' >', '<section' ), |
| 1430 | $before_widget |
| 1431 | ); |
| 1432 | } elseif ( !empty($result['parsed_atts']['custom_el_id']) ){ |
| 1433 | $result['widget_header'] .= sprintf('<section id="%s" class="%s" style="%s" %s>', $result['parsed_atts']['custom_el_id'], $_widget_classes, $_widget_styles, $_widget_attrs ); |
| 1434 | } else { |
| 1435 | $result['widget_header'] .= sprintf('<section class="%s" style="%s" %s>', $_widget_classes, $_widget_styles, $_widget_attrs ); |
| 1436 | } |
| 1437 | |
| 1438 | // Generate the title for widget or shortcode element |
| 1439 | if( ! empty( $result['parsed_atts']['title'] ) ){ |
| 1440 | if( $before_title ){ |
| 1441 | $result['widget_title'] .= $before_title . $result['parsed_atts']['title'] . $after_title; |
| 1442 | } elseif( ! empty( $result['parsed_atts']['title'] ) ){ |
| 1443 | $result['widget_title'] .= '<h3 class="widget-title">'. $result['parsed_atts']['title'] .'</h3>'; |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | // Generate the close tags for widget or shortcode element |
| 1448 | if( $after_widget ){ |
| 1449 | // fix for the difference in end tag in siteorigin page builder |
| 1450 | $result['widget_footer'] .= str_replace( '</div', '</section', $after_widget ); |
| 1451 | } else { |
| 1452 | $result['widget_footer'] .= '</section><!-- widget-container -->'; |
| 1453 | } |
| 1454 | |
| 1455 | // Enable filtering the result variable |
| 1456 | $result = apply_filters( 'auxin_widget_scafold_params', $result, $atts, $default_atts, $shortcode_content ); |
| 1457 | |
| 1458 | // Prints the javascript variable if load more is enabled |
| 1459 | // We can modify the ajax args using "auxin_widget_scafold_params" filter |
| 1460 | if( ! empty( $result['parsed_atts']['loadmore_type'] ) ){ |
| 1461 | // echo js dependencies |
| 1462 | auxin_print_script_object( "auxin.content.loadmore." . $result['parsed_atts']['universal_id'], $result['ajax_data'] ); |
| 1463 | } |
| 1464 | |
| 1465 | return $result; |
| 1466 | } |
| 1467 | |
| 1468 | |
| 1469 | /*----------------------------------------------------------------------------*/ |
| 1470 | /* Retrieves remote data |
| 1471 | /*----------------------------------------------------------------------------*/ |
| 1472 | |
| 1473 | /** |
| 1474 | * Retrieves a URL using the HTTP POST method |
| 1475 | * |
| 1476 | * @return mixed|boolean The body content |
| 1477 | */ |
| 1478 | function auxin_remote_post( $url, $args = array() ) { |
| 1479 | $response = wp_remote_post( $url, $args ); |
| 1480 | |
| 1481 | if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) { |
| 1482 | return wp_remote_retrieve_body( $response ); |
| 1483 | } else { |
| 1484 | error_log( "Something went wrong while connecting ($url): " . $response->get_error_message() ); |
| 1485 | } |
| 1486 | |
| 1487 | return false; |
| 1488 | } |
| 1489 | |
| 1490 | /** |
| 1491 | * Retrieves a URL using the HTTP GET method |
| 1492 | * |
| 1493 | * @return mixed|boolean The body content |
| 1494 | */ |
| 1495 | function auxin_remote_get( $url, $args ) { |
| 1496 | $response = wp_remote_get( $url, $args ); |
| 1497 | |
| 1498 | if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) { |
| 1499 | return wp_remote_retrieve_body( $response ); |
| 1500 | } else { |
| 1501 | error_log( "Something went wrong while connecting ($url): " . $response->get_error_message() ); |
| 1502 | } |
| 1503 | |
| 1504 | return false; |
| 1505 | } |
| 1506 | |
| 1507 | /*----------------------------------------------------------------------------*/ |
| 1508 | /* Removes a class method from a specified filter hook. |
| 1509 | /*----------------------------------------------------------------------------*/ |
| 1510 | |
| 1511 | if( ! function_exists( 'auxin_remove_filter_from_class' ) ){ |
| 1512 | |
| 1513 | /** |
| 1514 | * Removes a class method from a specified filter hook. |
| 1515 | * |
| 1516 | * @param string $hook_name The filter hook to which the function to be removed is hooked |
| 1517 | * @param string $class_name The name of class which its method should be removed. |
| 1518 | * @param string $method_name The name of the method which should be removed. |
| 1519 | * @param integer $priority Optional. The priority of the function. Default 10. |
| 1520 | * @return bool Whether the function existed before it was removed. |
| 1521 | */ |
| 1522 | function auxin_remove_filter_from_class( $hook_name = '', $class_name ='', $method_name = '', $priority = 10 ) { |
| 1523 | global $wp_filter; |
| 1524 | |
| 1525 | // Take only filters on right hook name and priority |
| 1526 | if ( !isset($wp_filter[$hook_name][$priority]) || !is_array($wp_filter[$hook_name][$priority]) ) |
| 1527 | return false; |
| 1528 | |
| 1529 | // Loop on filters registered |
| 1530 | foreach( (array) $wp_filter[$hook_name][$priority] as $unique_id => $filter_array ) { |
| 1531 | // Test if filter is an array ! (always for class/method) |
| 1532 | if ( isset($filter_array['function']) && is_array($filter_array['function']) ) { |
| 1533 | // Test if object is a class, class and method is equal to param ! |
| 1534 | if ( is_object($filter_array['function'][0]) && get_class($filter_array['function'][0]) && get_class($filter_array['function'][0]) == $class_name && $filter_array['function'][1] == $method_name ) { |
| 1535 | unset($wp_filter[$hook_name][$priority][$unique_id]); |
| 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | } |
| 1540 | |
| 1541 | return false; |
| 1542 | } |
| 1543 | |
| 1544 | } |
| 1545 | |
| 1546 | |
| 1547 | if( ! function_exists( 'auxin_remove_action_from_class' ) ){ |
| 1548 | |
| 1549 | /** |
| 1550 | * Removes a class method from a specified filter hook. |
| 1551 | * |
| 1552 | * @param string $hook_name The filter hook to which the function to be removed is hooked |
| 1553 | * @param string $class_name The name of class which its method should be removed. |
| 1554 | * @param string $method_name The name of the method which should be removed. |
| 1555 | * @param integer $priority Optional. The priority of the function. Default 10. |
| 1556 | * @return bool Whether the function existed before it was removed. |
| 1557 | */ |
| 1558 | function auxin_remove_action_from_class( $hook_name = '', $class_name ='', $method_name = '', $priority = 10 ) { |
| 1559 | global $wp_action; |
| 1560 | |
| 1561 | // Take only filters on right hook name and priority |
| 1562 | if ( !isset($wp_action[$hook_name][$priority]) || !is_array($wp_action[$hook_name][$priority]) ) |
| 1563 | return false; |
| 1564 | |
| 1565 | // Loop on filters registered |
| 1566 | foreach( (array) $wp_action[$hook_name][$priority] as $unique_id => $filter_array ) { |
| 1567 | // Test if filter is an array ! (always for class/method) |
| 1568 | if ( isset($filter_array['function']) && is_array($filter_array['function']) ) { |
| 1569 | // Test if object is a class, class and method is equal to param ! |
| 1570 | if ( is_object($filter_array['function'][0]) && get_class($filter_array['function'][0]) && get_class($filter_array['function'][0]) == $class_name && $filter_array['function'][1] == $method_name ) { |
| 1571 | unset($wp_action[$hook_name][$priority][$unique_id]); |
| 1572 | } |
| 1573 | } |
| 1574 | |
| 1575 | } |
| 1576 | |
| 1577 | return false; |
| 1578 | } |
| 1579 | |
| 1580 | } |
| 1581 | |
| 1582 | |
| 1583 | |
| 1584 | /*-----------------------------------------------------------------------------------*/ |
| 1585 | /* Auxin Load More |
| 1586 | /*-----------------------------------------------------------------------------------*/ |
| 1587 | |
| 1588 | /** |
| 1589 | * A callback for Auxin Load More functionality |
| 1590 | * |
| 1591 | * @return string |
| 1592 | */ |
| 1593 | function auxin_get_load_more_controller( $type, $label = 'text' ) { |
| 1594 | // Return null when loadmore type is empty |
| 1595 | if ( empty( $type ) ) return; |
| 1596 | // Check load more type |
| 1597 | if ( $type == "next-prev" ) { |
| 1598 | return ' |
| 1599 | <div class="aux-ajax-controller"> |
| 1600 | <nav class="aux-next-prev-posts nav-skin-minimal"> |
| 1601 | <section class="aux-load-next-prev hidden np-prev-section"> |
| 1602 | <div class="np-arrow"> |
| 1603 | <div class="aux-arrow-nav aux-hover-slide aux-round aux-outline aux-medium"> |
| 1604 | <span class="aux-overlay"></span> |
| 1605 | <span class="aux-svg-arrow aux-medium-left"></span> |
| 1606 | <span class="aux-hover-arrow aux-svg-arrow aux-medium-left aux-white"></span> |
| 1607 | </div> |
| 1608 | </div> |
| 1609 | <p class="np-nav-text">'.__('Previous', 'auxin-elements').'</p> |
| 1610 | <h4 class="np-title">'.__('page', 'auxin-elements').'</h4> |
| 1611 | </section> |
| 1612 | <section class="aux-load-next-prev np-next-section"> |
| 1613 | <div class="np-arrow"> |
| 1614 | <div class="aux-arrow-nav aux-hover-slide aux-round aux-outline aux-medium"> |
| 1615 | <span class="aux-overlay"></span> |
| 1616 | <span class="aux-svg-arrow aux-medium-right"></span> |
| 1617 | <span class="aux-hover-arrow aux-svg-arrow aux-medium-right aux-white"></span> |
| 1618 | </div> |
| 1619 | </div> |
| 1620 | <p class="np-nav-text">'.__('Next', 'auxin-elements').'</p> |
| 1621 | <h4 class="np-title">'.__('Page', 'auxin-elements').'</h4> |
| 1622 | </section> |
| 1623 | |
| 1624 | </nav> |
| 1625 | </div>'; |
| 1626 | |
| 1627 | } elseif ( $type == "scroll" || $type == "infinite-scroll" || $type == "next" ) { |
| 1628 | |
| 1629 | switch ( $label ) { |
| 1630 | case 'text': |
| 1631 | $label = __('LOAD MORE', 'auxin-elements'); |
| 1632 | break; |
| 1633 | |
| 1634 | case 'arrow': |
| 1635 | $label = '<span class="aux-svg-arrow aux-h-large-down"></span>'; |
| 1636 | break; |
| 1637 | |
| 1638 | case 'text-arrow': |
| 1639 | $label = '<span class="aux-svg-arrow aux-small-down"></span>' . __('MORE', 'auxin-elements'); |
| 1640 | break; |
| 1641 | } |
| 1642 | |
| 1643 | return ' |
| 1644 | <div class="aux-ajax-controller"> |
| 1645 | <nav class="aux-load-more center"> |
| 1646 | <svg class="aux-circle" width="100%" height="100%" viewBox="0 0 102 102"> |
| 1647 | <circle class="aux-progress-bg" r="50" cx="51" cy="51" fill="none" transform="rotate(-90 51 51)"></circle> |
| 1648 | <circle class="aux-progress" r="50" cx="51" cy="51" fill="none" transform="rotate(-90 51 51)"></circle> |
| 1649 | </svg> |
| 1650 | <div class="aux-label-text">'.apply_filters( 'auxin_loadmore_label', $label ).'</div> |
| 1651 | <span class="aux-loading-label">'.__('LOADING', 'auxin-elements').'</span> |
| 1652 | </nav> |
| 1653 | </div>'; |
| 1654 | |
| 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | |
| 1659 | /*-----------------------------------------------------------------------------------*/ |
| 1660 | /* A function to get the custom style of Google maps |
| 1661 | /*-----------------------------------------------------------------------------------*/ |
| 1662 | |
| 1663 | if ( ! function_exists( 'auxin_get_gmap_style' ) ) { |
| 1664 | |
| 1665 | function auxin_get_gmap_style () { |
| 1666 | |
| 1667 | $styler = '[{"featureType":"landscape.man_made","elementType":"geometry.fill","stylers":[{"color":"#e9e5dc"}]},{"featureType":"landscape.natural","elementType":"geometry.fill","stylers":[{"visibility":"on"},{"color":"#b8cb93"}]},{"featureType":"poi","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"poi.business","elementType":"all","stylers":[{"visibility":"simplified"}]},{"featureType":"poi.medical","elementType":"all","stylers":[{"visibility":"on"}]},{"featureType":"poi.park","elementType":"all","stylers":[{"visibility":"on"}]},{"featureType":"poi.park","elementType":"geometry.fill","stylers":[{"color":"#ccdca1"}]},{"featureType":"poi.sports_complex","elementType":"all","stylers":[{"visibility":"on"}]},{"featureType":"road","elementType":"geometry.fill","stylers":[{"hue":"#ff0000"},{"saturation":-100},{"lightness":99}]},{"featureType":"road","elementType":"geometry.stroke","stylers":[{"color":"#808080"},{"lightness":54},{"visibility":"off"}]},{"featureType":"road","elementType":"labels.text.fill","stylers":[{"color":"#767676"}]},{"featureType":"road","elementType":"labels.text.stroke","stylers":[{"color":"#ffffff"}]},{"featureType":"water","elementType":"all","stylers":[{"saturation":43},{"lightness":-11},{"color":"#89cada"}]}]'; |
| 1668 | |
| 1669 | return apply_filters( 'auxin_gmap_style', $styler ); |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | /** |
| 1674 | * Retrieves markup for a header button |
| 1675 | * |
| 1676 | * @param $button_id_num The ID of the header button (1 or 2) |
| 1677 | * @return string |
| 1678 | */ |
| 1679 | function auxin_get_header_button( $button_id_num = 1 ){ |
| 1680 | |
| 1681 | if( empty( $button_id_num ) || ! is_numeric( $button_id_num ) ){ |
| 1682 | _doing_it_wrong( __FUNCTION__, "A numeric button id is required." ); |
| 1683 | } |
| 1684 | if( ! auxin_get_option( "site_header_show_btn" . $button_id_num ) ){ |
| 1685 | return ''; |
| 1686 | } |
| 1687 | |
| 1688 | $btn_args = apply_filters( 'auxin_header_button_args', array( |
| 1689 | 'label' => auxin_get_option( 'site_header_btn'. $button_id_num .'_label' ), |
| 1690 | 'size' => auxin_get_option( 'site_header_btn'. $button_id_num .'_size', 'large' ), |
| 1691 | 'border' => auxin_get_option( 'site_header_btn'. $button_id_num .'_shape' ), |
| 1692 | 'style' => auxin_get_option( 'site_header_btn'. $button_id_num .'_style' ), |
| 1693 | 'dark' => auxin_get_option( 'site_header_btn'. $button_id_num .'_darken', 0 ), |
| 1694 | 'icon' => auxin_get_option( 'site_header_btn'. $button_id_num .'_icon' ), |
| 1695 | 'icon_align' => auxin_get_option( 'site_header_btn'. $button_id_num .'_icon_align' ), |
| 1696 | 'color_name' => auxin_get_option( 'site_header_btn'. $button_id_num .'_color_name' ), |
| 1697 | 'link' => auxin_get_option( 'site_header_btn'. $button_id_num .'_link', "#" ), |
| 1698 | 'target' => auxin_get_option( 'site_header_btn'. $button_id_num .'_target' ), |
| 1699 | 'btn_attrs' => sprintf( 'data-colorname-default{%s};data-colorname-sticky{%s}', |
| 1700 | auxin_get_option( 'site_header_btn'. $button_id_num .'_color_name' ), |
| 1701 | auxin_get_option( 'site_header_btn'. $button_id_num .'_color_name_on_sticky' ) |
| 1702 | ), |
| 1703 | 'uppercase' => '0', |
| 1704 | 'extra_classes' => 'aux-ac-btn'. $button_id_num |
| 1705 | ), $button_id_num ); |
| 1706 | |
| 1707 | if( empty( $btn_args ) ){ |
| 1708 | return ''; |
| 1709 | } |
| 1710 | |
| 1711 | return auxin_widget_button_callback( $btn_args ); |
| 1712 | } |
| 1713 | |
| 1714 | |
| 1715 | /** |
| 1716 | * Returns the second custom logo, linked to home. |
| 1717 | * |
| 1718 | * @param integer $blog_id The site id on multisite |
| 1719 | * @return string Markup for second custom logo. |
| 1720 | */ |
| 1721 | function auxin_get_custom_logo2( $blog_id = 0, $args = array() ) { |
| 1722 | |
| 1723 | $defaults = array( |
| 1724 | 'anchor_extra_classes' => 'aux-middle aux-logo-sticky', |
| 1725 | 'image_extra_classes' => 'aux-logo-light' |
| 1726 | ); |
| 1727 | |
| 1728 | $args = wp_parse_args( $args, $defaults ); |
| 1729 | |
| 1730 | $html = ''; |
| 1731 | $switched_blog = false; |
| 1732 | |
| 1733 | if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) { |
| 1734 | switch_to_blog( $blog_id ); |
| 1735 | $switched_blog = true; |
| 1736 | } |
| 1737 | |
| 1738 | // make the secondary logo image modifiable |
| 1739 | $custom_logo_id = apply_filters( 'auxin_secondary_logo_id', auxin_get_option('custom_logo2'), $args, $blog_id ); |
| 1740 | |
| 1741 | // We have a logo. Logo is go. |
| 1742 | if ( $custom_logo_id ) { |
| 1743 | $custom_logo_attr = array( |
| 1744 | 'class' => 'custom-logo aux-logo-image aux-logo-image2 '. $args['image_extra_classes'], |
| 1745 | 'itemprop' => 'logo', |
| 1746 | ); |
| 1747 | |
| 1748 | /* |
| 1749 | * If the logo alt attribute is empty, get the site title and explicitly |
| 1750 | * pass it to the attributes used by wp_get_attachment_image(). |
| 1751 | */ |
| 1752 | $image_alt = get_post_meta( $custom_logo_id, '_wp_attachment_image_alt', true ); |
| 1753 | if ( empty( $image_alt ) ) { |
| 1754 | $custom_logo_attr['alt'] = get_bloginfo( 'name', 'display' ); |
| 1755 | } |
| 1756 | |
| 1757 | /* |
| 1758 | * If the alt attribute is not empty, there's no need to explicitly pass |
| 1759 | * it because wp_get_attachment_image() already adds the alt attribute. |
| 1760 | */ |
| 1761 | $html = sprintf( '<a href="%1$s" class="custom-logo-link aux-logo-anchor aux-logo-anchor2 aux-has-logo %2$s" rel="home" itemprop="url">%3$s</a>', |
| 1762 | esc_url( home_url( '/' ) ), |
| 1763 | esc_attr( $args['anchor_extra_classes'] ), |
| 1764 | wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr ) |
| 1765 | ); |
| 1766 | } |
| 1767 | |
| 1768 | if ( $switched_blog ) { |
| 1769 | restore_current_blog(); |
| 1770 | } |
| 1771 | |
| 1772 | /** |
| 1773 | * Filters the custom logo output. |
| 1774 | * |
| 1775 | * @param string $html Custom logo HTML output. |
| 1776 | * @param int $blog_id ID of the blog to get the custom logo for. |
| 1777 | */ |
| 1778 | return apply_filters( 'auxin_get_custom_logo2', $html, $blog_id ); |
| 1779 | } |
| 1780 | |
| 1781 | |
| 1782 | /** |
| 1783 | * Determines whether the site has the second custom logo. |
| 1784 | * |
| 1785 | * @param integer $blog_id The site id on multisite |
| 1786 | * @return bool Whether the site has the custom logo or not. |
| 1787 | */ |
| 1788 | function auxin_has_custom_logo2( $blog_id = 0 ) { |
| 1789 | $switched_blog = false; |
| 1790 | |
| 1791 | if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) { |
| 1792 | switch_to_blog( $blog_id ); |
| 1793 | $switched_blog = true; |
| 1794 | } |
| 1795 | |
| 1796 | $custom_logo_id = get_theme_mod( 'custom_logo2' ); |
| 1797 | |
| 1798 | if ( $switched_blog ) { |
| 1799 | restore_current_blog(); |
| 1800 | } |
| 1801 | |
| 1802 | return (bool) $custom_logo_id; |
| 1803 | } |
| 1804 | |
| 1805 | |
| 1806 | /** |
| 1807 | * Removes all generate images from uploads directory |
| 1808 | * |
| 1809 | * @return void |
| 1810 | */ |
| 1811 | function auxin_remove_all_generate_images( $remove = true ){ |
| 1812 | if( is_multisite() ){ |
| 1813 | return; |
| 1814 | } |
| 1815 | $upload_dir = wp_get_upload_dir(); |
| 1816 | |
| 1817 | $all_images = auxin_find_all_files( $upload_dir['basedir'] ); |
| 1818 | $generated_images = array(); |
| 1819 | |
| 1820 | foreach( $all_images as $key => $file ) { |
| 1821 | if( 1 == preg_match("#-(\d+)x(\d+).(png|jpg|bmp|gif)$#", $file) ) { |
| 1822 | $generated_images[] = $file; |
| 1823 | if( $remove ){ |
| 1824 | unlink( $file ); |
| 1825 | } |
| 1826 | } |
| 1827 | } |
| 1828 | echo count( $all_images ) . " / " . count( $generated_images ); |
| 1829 | } |
| 1830 | |
| 1831 | /** |
| 1832 | * Find all files within a directory |
| 1833 | * |
| 1834 | * @param string $dir The directory which we intend to serach in |
| 1835 | * @return array List of files |
| 1836 | */ |
| 1837 | function auxin_find_all_files( $dir, $recursive = true ){ |
| 1838 | $root = scandir( $dir ); |
| 1839 | $result = array(); |
| 1840 | |
| 1841 | foreach( $root as $file ){ |
| 1842 | if( $file === '.' || $file === '..') { |
| 1843 | continue; |
| 1844 | } |
| 1845 | if( is_file( "$dir/$file" ) ){ |
| 1846 | $result[] = "$dir/$file"; |
| 1847 | continue; |
| 1848 | } elseif( $recursive && is_dir( "$dir/$file" ) ){ |
| 1849 | $sub_dir_files = auxin_find_all_files( "$dir/$file" ); |
| 1850 | $result = array_merge( $result, $sub_dir_files ); |
| 1851 | } |
| 1852 | } |
| 1853 | return $result; |
| 1854 | } |
| 1855 | |
| 1856 | |
| 1857 | /** |
| 1858 | * Flatten an array |
| 1859 | * Used for flatten grouped data in SiteOrigin widgets |
| 1860 | * @param array $keys Keys that we need to extract and merge with main array |
| 1861 | * @param array $array The array that we need to flatten |
| 1862 | * @return array |
| 1863 | */ |
| 1864 | function auxin_flatten_array( $keys = array(), $arr = array() ) { |
| 1865 | foreach ( $keys as $key ) { |
| 1866 | if ( isset( $arr[$key] ) ) { |
| 1867 | $temp = $arr[$key]; |
| 1868 | unset($arr[$key]); |
| 1869 | $arr = array_merge( $arr, $temp ); |
| 1870 | } |
| 1871 | } |
| 1872 | return $arr; |
| 1873 | } |
| 1874 | |
| 1875 | |
| 1876 | /** |
| 1877 | * Get All Pages Id and Title |
| 1878 | * Used for Customizer Options for 404 ,Maintance and Coming soon Section |
| 1879 | * @return array |
| 1880 | */ |
| 1881 | function auxin_get_all_pages() { |
| 1882 | |
| 1883 | $pages = array(); |
| 1884 | $args = array( |
| 1885 | 'post_type' => 'page', |
| 1886 | 'post_status' => 'publish', |
| 1887 | ); |
| 1888 | |
| 1889 | $pages['default'] = __( 'Theme Default', 'auxin-elements' ) ; // Default Page For 404, Maintance , And Coming Soon |
| 1890 | |
| 1891 | $pages_array = get_posts( $args ); |
| 1892 | |
| 1893 | foreach ( $pages_array as $page ) { |
| 1894 | $pages[ $page->ID ] = $page->post_title ; |
| 1895 | } |
| 1896 | |
| 1897 | return $pages; |
| 1898 | } |
| 1899 | |
| 1900 | /** |
| 1901 | * Get the size of numeric controls |
| 1902 | * |
| 1903 | * @param string|array $value The controller value |
| 1904 | * @return int The size |
| 1905 | */ |
| 1906 | function auxin_get_control_size( $value ){ |
| 1907 | return isset( $value['size'] ) ? $value['size'] : $value; |
| 1908 | } |
| 1909 | |
| 1910 | /** |
| 1911 | * Change search uery based on options |
| 1912 | * |
| 1913 | * @param object $query A WP_Query object |
| 1914 | * @return object $query |
| 1915 | */ |
| 1916 | function auxin_custom_search_results( $query ) { |
| 1917 | |
| 1918 | if ( ! is_admin() && $query->is_main_query() ) { |
| 1919 | if ($query->is_search) { |
| 1920 | |
| 1921 | $all_post_types = get_post_types( array( 'public' => true, 'exclude_from_search' => false ) ); |
| 1922 | |
| 1923 | $excluded_post_types = (array) auxin_get_option( 'auxin_search_exclude_post_types', array() ); |
| 1924 | |
| 1925 | $post_types = array_diff( $all_post_types , $excluded_post_types ); |
| 1926 | |
| 1927 | $posts_in = auxin_get_option( 'auxin_search_pinned_contents', '' ); |
| 1928 | |
| 1929 | if ( auxin_get_option( 'auxin_search_exclude_no_media' ) ) { |
| 1930 | $query->set( 'meta_query', array(array('key' => '_thumbnail_id')) ); |
| 1931 | } |
| 1932 | |
| 1933 | } |
| 1934 | } |
| 1935 | return $query; |
| 1936 | |
| 1937 | } |
| 1938 | |
| 1939 | add_filter( 'pre_get_posts', 'auxin_custom_search_results' ); |
| 1940 | |
| 1941 | /** |
| 1942 | * Page Cover Markup |
| 1943 | */ |
| 1944 | |
| 1945 | function auxin_cover() { |
| 1946 | global $post; |
| 1947 | |
| 1948 | ob_start(); |
| 1949 | if ( auxin_is_true( auxin_get_post_meta( $post, 'display_page_header_cover', false ) ) ) { |
| 1950 | $cover_image = auxin_get_post_meta( $post, 'page_header_cover_image', '' ); |
| 1951 | $image = auxin_get_the_responsive_attachment( $cover_image, |
| 1952 | array( |
| 1953 | 'quality' => 100, |
| 1954 | 'preloadable' => false, |
| 1955 | 'preload_preview' => false, |
| 1956 | 'size' => 'full', |
| 1957 | 'crop' => true, |
| 1958 | 'add_hw' => true, |
| 1959 | 'attr' => array( 'data-object-fit' => 'cover', 'class' => 'auxin-page-cover-image' ) |
| 1960 | ) |
| 1961 | ); |
| 1962 | $cover_title = auxin_get_post_meta( $post, 'page_header_cover_title', '' ); |
| 1963 | $discover_text = auxin_get_post_meta( $post, 'page_header_discover_text', '' ); |
| 1964 | ?> |
| 1965 | <div class="aux-page-cover-wrapper"> |
| 1966 | <?php echo $image ;?> |
| 1967 | <?php |
| 1968 | if ( ! empty ( $cover_title ) ) { ?> |
| 1969 | <div class="aux-page-cover-content"> |
| 1970 | <?php _e( $cover_title, 'auxin-elements' );?> |
| 1971 | </div> |
| 1972 | <?php } |
| 1973 | ?> |
| 1974 | <div class="aux-page-cover-footer"> |
| 1975 | <div class="aux-page-cover-footer-text"> |
| 1976 | <a href="#" title="<?php echo $discover_text ?>"><?php echo $discover_text ?></a> |
| 1977 | </div> |
| 1978 | </div> |
| 1979 | </div> |
| 1980 | <?php } |
| 1981 | |
| 1982 | echo ob_get_clean(); |
| 1983 | |
| 1984 | } |
| 1985 | |
| 1986 | add_action( 'auxin_after_body_open', 'auxin_cover' ); |
| 1987 | |
| 1988 | /** |
| 1989 | * Strpos search in array |
| 1990 | * @return boolean |
| 1991 | */ |
| 1992 | function auxin_strposa( $haystack, $needle, $offset = 0 ) { |
| 1993 | if( ! is_array( $needle ) ) { |
| 1994 | $needle = array($needle); |
| 1995 | } |
| 1996 | foreach($needle as $query) { |
| 1997 | if( strpos( $haystack, $query, $offset ) !== false ) { |
| 1998 | return true; // stop on first true result |
| 1999 | } |
| 2000 | } |
| 2001 | return false; |
| 2002 | } |
| 2003 | |
| 2004 | /** |
| 2005 | * Return preloadable options |
| 2006 | * @return arraqy |
| 2007 | */ |
| 2008 | function auxin_get_preloadable_previews(){ |
| 2009 | return apply_filters( 'auxin_get_preloadable_previews', array( |
| 2010 | 'no' => __('Blank', 'auxin-elements' ), |
| 2011 | 'yes' => __('Blurred placeholder image', 'auxin-elements' ), |
| 2012 | 'progress-box' => __('In-progress box animation', 'auxin-elements' ), |
| 2013 | 'simple-spinner' => __('Loading spinner (blue)', 'auxin-elements' ), |
| 2014 | 'simple-spinner-light' => __('Loading spinner (light)', 'auxin-elements' ), |
| 2015 | 'simple-spinner-dark' => __('Loading spinner (dark)', 'auxin-elements' ) |
| 2016 | ) ); |
| 2017 | } |
| 2018 | |
| 2019 | /** |
| 2020 | * Check purchase activation status |
| 2021 | * |
| 2022 | * @return void |
| 2023 | */ |
| 2024 | function auxin_is_activated(){ |
| 2025 | // A temporary code to update the old license value |
| 2026 | if( ! get_site_option( THEME_ID . '_license_update', false ) ){ |
| 2027 | $getLicense = get_option( THEME_ID . '_license' ); |
| 2028 | $getLicense = empty( $getLicense ) ? get_option( AUXELS_PURCHASE_KEY ) : $getLicense; |
| 2029 | update_site_option( AUXELS_PURCHASE_KEY, $getLicense ); |
| 2030 | update_site_option( THEME_ID . '_license_update', true ); |
| 2031 | } |
| 2032 | |
| 2033 | $getLicense = get_site_option( THEME_ID . '_license' ); |
| 2034 | $getLicense = empty( $getLicense ) ? get_site_option( AUXELS_PURCHASE_KEY ) : $getLicense; |
| 2035 | $isPro = defined('THEME_PRO' ) && THEME_PRO; |
| 2036 | if( $isPro && ( isset( $getLicense['token'] ) && ! empty( $getLicense['token'] ) ) ){ |
| 2037 | // Check token validation every 24 hours |
| 2038 | $key = sanitize_key( 'auxin_check_token_validation_status' ); |
| 2039 | if ( false === $token_status = auxin_get_transient( $key ) ) { |
| 2040 | $token_validation = Auxin_License_Activation::get_instance()->maybe_invalid_token(); |
| 2041 | $token_status = isset( $token_validation['allowed'] ) ? $token_validation['allowed']: 0; |
| 2042 | // Add transient |
| 2043 | auxin_set_transient( $key, $token_status , 2 * DAY_IN_SECONDS ); |
| 2044 | } |
| 2045 | return $token_status; |
| 2046 | } |
| 2047 | return false; |
| 2048 | } |
| 2049 | |
| 2050 | /** |
| 2051 | * Get recent comments query |
| 2052 | * |
| 2053 | * @param array $args |
| 2054 | * @return array |
| 2055 | */ |
| 2056 | function auxin_get_comments( $args = array() ){ |
| 2057 | // The Query |
| 2058 | $comments_query = new WP_Comment_Query; |
| 2059 | $comments = $comments_query->query( $args ); |
| 2060 | return $comments; |
| 2061 | } |
| 2062 | |
| 2063 | /** |
| 2064 | * Return elementor header template |
| 2065 | * |
| 2066 | * @return void |
| 2067 | */ |
| 2068 | function auxin_get_header_template(){ |
| 2069 | global $post; |
| 2070 | |
| 2071 | $template_ID = auxin_get_option( 'site_elementor_header_template', '' ); |
| 2072 | $template_ID = ( ! empty( auxin_get_post_meta( $post, 'page_elementor_header_template' ) ) && auxin_get_post_meta($post , 'page_header_use_legacy' ) !== 'default' ) ? |
| 2073 | auxin_get_post_meta( $post, 'page_elementor_header_template' ) : $template_ID ; |
| 2074 | |
| 2075 | $attrs = [ |
| 2076 | 'class' => ['aux-elementor-header'], |
| 2077 | 'id' => 'site-elementor-header', |
| 2078 | 'itemscope' => 'itemscope', |
| 2079 | 'itemtype' => 'https://schema.org/WPHeader', |
| 2080 | ]; |
| 2081 | |
| 2082 | if ( 'default' === $overlay_header = auxin_get_post_meta( $post, 'page_overlay_header', 'default' ) ) { |
| 2083 | $overlay_header = auxin_get_option('site_overlay_header'); |
| 2084 | } |
| 2085 | |
| 2086 | if ( 'default' === $attributes['data-sticky-height'] = auxin_get_post_meta( $post, 'page_header_container_scaled_height', 'default' ) ) { |
| 2087 | $attrs['data-sticky-height'] = auxin_get_option( 'site_header_container_scaled_height','60' ); |
| 2088 | } |
| 2089 | |
| 2090 | if ( auxin_is_true ( $overlay_header ) ) { |
| 2091 | array_push( $attrs['class'], 'aux-overlay-header' ); |
| 2092 | } |
| 2093 | |
| 2094 | if( isset( $template_ID ) && $template_ID !== ' ' && get_post_status( $template_ID ) ){ |
| 2095 | ?> |
| 2096 | <header <?php echo auxin_make_html_attributes( $attrs ) ;?> > |
| 2097 | <div class="aux-wrapper"> |
| 2098 | <div class="aux-header aux-header-elements-wrapper"> |
| 2099 | <?php echo Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $template_ID ); ?> |
| 2100 | </div><!-- end of header-elements --> |
| 2101 | </div><!-- end of wrapper --> |
| 2102 | </header><!-- end header --> |
| 2103 | <?php |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | /** |
| 2108 | * Return elementor footer template |
| 2109 | * |
| 2110 | * @return void |
| 2111 | */ |
| 2112 | function auxin_get_footer_template(){ |
| 2113 | global $post; |
| 2114 | |
| 2115 | $template_ID = auxin_get_option( 'site_elementor_footer_template', '' ); |
| 2116 | $template_ID = ( ! empty( auxin_get_post_meta( $post, 'page_elementor_footer_template' ) ) && auxin_get_post_meta($post , 'page_footer_use_legacy' ) !== 'default' ) ? |
| 2117 | auxin_get_post_meta( $post, 'page_elementor_footer_template' ) : $template_ID ; |
| 2118 | |
| 2119 | $attrs = [ |
| 2120 | 'class' => ['aux-elementor-footer'], |
| 2121 | 'itemscope' => 'itemscope', |
| 2122 | 'itemtype' => 'https://schema.org/WPFooter', |
| 2123 | 'role' => 'contentinfo' |
| 2124 | ]; |
| 2125 | |
| 2126 | if( isset( $template_ID ) && $template_ID !== ' ' && get_post_status( $template_ID ) ){ |
| 2127 | |
| 2128 | ?> |
| 2129 | <footer <?php echo auxin_make_html_attributes( $attrs ) ;?> > |
| 2130 | <div class="aux-wrapper"> |
| 2131 | <?php echo Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $template_ID ); ?> |
| 2132 | </div><!-- end of wrapper --> |
| 2133 | </footer><!-- end footer --> |
| 2134 | <?php |
| 2135 | } |
| 2136 | } |
| 2137 | |
| 2138 | /** |
| 2139 | * generate unique token for audit API |
| 2140 | * |
| 2141 | * @return void |
| 2142 | */ |
| 2143 | function auxin_get_site_key(){ |
| 2144 | $option_name = THEME_ID . '_' . 'audit_token'; |
| 2145 | $site_key = get_option( $option_name ); |
| 2146 | |
| 2147 | if ( ! $site_key ) { |
| 2148 | $site_key = md5( uniqid( wp_generate_password() ) ); |
| 2149 | update_option( $option_name, $site_key ); |
| 2150 | } |
| 2151 | |
| 2152 | return $site_key; |
| 2153 | } |
| 2154 | |
| 2155 | /** |
| 2156 | * Whether a plugin is active or not |
| 2157 | * |
| 2158 | * @param string $plugin_basename plugin directory name and mail file address |
| 2159 | * @return bool True if plugin is active and FALSE otherwise |
| 2160 | */ |
| 2161 | if( ! function_exists( 'auxin_is_plugin_active' ) ){ |
| 2162 | function auxin_is_plugin_active( $plugin_basename ){ |
| 2163 | include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 2164 | return is_plugin_active( $plugin_basename ); |
| 2165 | } |
| 2166 | } |
| 2167 | |
| 2168 | /** |
| 2169 | * Get public post type list |
| 2170 | * |
| 2171 | * @param array $args |
| 2172 | * @return array |
| 2173 | */ |
| 2174 | function auxin_get_public_post_types( $args = array() ) { |
| 2175 | $post_type_args = [ |
| 2176 | // Default is the value $public. |
| 2177 | 'show_in_nav_menus' => true, |
| 2178 | ]; |
| 2179 | |
| 2180 | // Keep for backwards compatibility |
| 2181 | if ( ! empty( $args['post_type'] ) ) { |
| 2182 | $post_type_args['name'] = $args['post_type']; |
| 2183 | unset( $args['post_type'] ); |
| 2184 | } |
| 2185 | |
| 2186 | $post_type_args = wp_parse_args( $post_type_args, $args ); |
| 2187 | |
| 2188 | $_post_types = get_post_types( $post_type_args, 'objects' ); |
| 2189 | |
| 2190 | $post_types = []; |
| 2191 | |
| 2192 | foreach ( $_post_types as $post_type => $object ) { |
| 2193 | $post_types[ $post_type ] = $object->label; |
| 2194 | } |
| 2195 | |
| 2196 | return apply_filters( 'auxin/core_elements/get_public_post_types', $post_types ); |
| 2197 | } |
| 2198 | |
| 2199 | |
| 2200 | /** |
| 2201 | * Print elementor template type on target location |
| 2202 | * |
| 2203 | * @param string $location |
| 2204 | * @return void |
| 2205 | */ |
| 2206 | function auxin_theme_do_location( $location ) { |
| 2207 | $is_active = auxin_is_true( auxin_get_option( 'site_' . $location . '_override_template', false ) ); |
| 2208 | $site_temp = auxin_get_option( 'site_' . $location . '_template', ' ' ); |
| 2209 | $template = $site_temp !== ' ' ? get_page_by_path( $site_temp, OBJECT, 'elementor_library' ) : NULL; |
| 2210 | if( $is_active && ( isset( $template->ID ) && $template->ID !== NULL && get_post_status( $template->ID ) ) ){ |
| 2211 | $document = new Auxin\Plugin\CoreElements\Elementor\Modules\ThemeBuilder\Classes\Locations_Manager(); |
| 2212 | $document->do_location( $template->ID, $location ); |
| 2213 | return true; |
| 2214 | } |
| 2215 | |
| 2216 | return false; |
| 2217 | } |
| 2218 | |
| 2219 | /** |
| 2220 | * get current page title |
| 2221 | * |
| 2222 | * @param boolean $include_context |
| 2223 | * @return string |
| 2224 | */ |
| 2225 | function auxin_get_page_title( $include_context = true ) { |
| 2226 | $title = ''; |
| 2227 | |
| 2228 | if ( is_singular() ) { |
| 2229 | /* translators: %s: Search term. */ |
| 2230 | $title = get_the_title(); |
| 2231 | |
| 2232 | if ( $include_context ) { |
| 2233 | $post_type_obj = get_post_type_object( get_post_type() ); |
| 2234 | $title = sprintf( '%s: %s', $post_type_obj->labels->singular_name, $title ); |
| 2235 | } |
| 2236 | } elseif ( is_search() ) { |
| 2237 | /* translators: %s: Search term. */ |
| 2238 | $title = sprintf( __( 'Search Results for: %s', 'auxin-elements' ), get_search_query() ); |
| 2239 | |
| 2240 | if ( get_query_var( 'paged' ) ) { |
| 2241 | /* translators: %s is the page number. */ |
| 2242 | $title .= sprintf( __( ' – Page %s', 'auxin-elements' ), get_query_var( 'paged' ) ); |
| 2243 | } |
| 2244 | } elseif ( is_category() ) { |
| 2245 | $title = single_cat_title( '', false ); |
| 2246 | |
| 2247 | if ( $include_context ) { |
| 2248 | /* translators: Category archive title. 1: Category name */ |
| 2249 | $title = sprintf( __( 'Category: %s', 'auxin-elements' ), $title ); |
| 2250 | } |
| 2251 | } elseif ( is_tag() ) { |
| 2252 | $title = single_tag_title( '', false ); |
| 2253 | if ( $include_context ) { |
| 2254 | /* translators: Tag archive title. 1: Tag name */ |
| 2255 | $title = sprintf( __( 'Tag: %s', 'auxin-elements' ), $title ); |
| 2256 | } |
| 2257 | } elseif ( is_author() ) { |
| 2258 | $title = '<span class="vcard">' . get_the_author() . '</span>'; |
| 2259 | |
| 2260 | if ( $include_context ) { |
| 2261 | /* translators: Author archive title. 1: Author name */ |
| 2262 | $title = sprintf( __( 'Author: %s', 'auxin-elements' ), $title ); |
| 2263 | } |
| 2264 | } elseif ( is_year() ) { |
| 2265 | $title = get_the_date( _x( 'Y', 'yearly archives date format', 'auxin-elements' ) ); |
| 2266 | |
| 2267 | if ( $include_context ) { |
| 2268 | /* translators: Yearly archive title. 1: Year */ |
| 2269 | $title = sprintf( __( 'Year: %s', 'auxin-elements' ), $title ); |
| 2270 | } |
| 2271 | } elseif ( is_month() ) { |
| 2272 | $title = get_the_date( _x( 'F Y', 'monthly archives date format', 'auxin-elements' ) ); |
| 2273 | |
| 2274 | if ( $include_context ) { |
| 2275 | /* translators: Monthly archive title. 1: Month name and year */ |
| 2276 | $title = sprintf( __( 'Month: %s', 'auxin-elements' ), $title ); |
| 2277 | } |
| 2278 | } elseif ( is_day() ) { |
| 2279 | $title = get_the_date( _x( 'F j, Y', 'daily archives date format', 'auxin-elements' ) ); |
| 2280 | |
| 2281 | if ( $include_context ) { |
| 2282 | /* translators: Daily archive title. 1: Date */ |
| 2283 | $title = sprintf( __( 'Day: %s', 'auxin-elements' ), $title ); |
| 2284 | } |
| 2285 | } elseif ( is_tax( 'post_format' ) ) { |
| 2286 | if ( is_tax( 'post_format', 'post-format-aside' ) ) { |
| 2287 | $title = _x( 'Asides', 'post format archive title', 'auxin-elements' ); |
| 2288 | } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) { |
| 2289 | $title = _x( 'Galleries', 'post format archive title', 'auxin-elements' ); |
| 2290 | } elseif ( is_tax( 'post_format', 'post-format-image' ) ) { |
| 2291 | $title = _x( 'Images', 'post format archive title', 'auxin-elements' ); |
| 2292 | } elseif ( is_tax( 'post_format', 'post-format-video' ) ) { |
| 2293 | $title = _x( 'Videos', 'post format archive title', 'auxin-elements' ); |
| 2294 | } elseif ( is_tax( 'post_format', 'post-format-quote' ) ) { |
| 2295 | $title = _x( 'Quotes', 'post format archive title', 'auxin-elements' ); |
| 2296 | } elseif ( is_tax( 'post_format', 'post-format-link' ) ) { |
| 2297 | $title = _x( 'Links', 'post format archive title', 'auxin-elements' ); |
| 2298 | } elseif ( is_tax( 'post_format', 'post-format-status' ) ) { |
| 2299 | $title = _x( 'Statuses', 'post format archive title', 'auxin-elements' ); |
| 2300 | } elseif ( is_tax( 'post_format', 'post-format-audio' ) ) { |
| 2301 | $title = _x( 'Audio', 'post format archive title', 'auxin-elements' ); |
| 2302 | } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) { |
| 2303 | $title = _x( 'Chats', 'post format archive title', 'auxin-elements' ); |
| 2304 | } |
| 2305 | } elseif ( is_post_type_archive() ) { |
| 2306 | $title = post_type_archive_title( '', false ); |
| 2307 | |
| 2308 | if ( $include_context ) { |
| 2309 | /* translators: Post type archive title. 1: Post type name */ |
| 2310 | $title = sprintf( __( 'Archives: %s', 'auxin-elements' ), $title ); |
| 2311 | } |
| 2312 | } elseif ( is_tax() ) { |
| 2313 | $title = single_term_title( '', false ); |
| 2314 | |
| 2315 | if ( $include_context ) { |
| 2316 | $tax = get_taxonomy( get_queried_object()->taxonomy ); |
| 2317 | /* translators: Taxonomy term archive title. 1: Taxonomy singular name, 2: Current taxonomy term */ |
| 2318 | $title = sprintf( __( '%1$s: %2$s', 'auxin-elements' ), $tax->labels->singular_name, $title ); |
| 2319 | } |
| 2320 | } elseif ( is_404() ) { |
| 2321 | $title = __( 'Page Not Found', 'auxin-elements' ); |
| 2322 | } // End if(). |
| 2323 | |
| 2324 | $title = apply_filters( 'auxin/core_elements/get_the_archive_title', $title ); |
| 2325 | |
| 2326 | return $title; |
| 2327 | } |
| 2328 | |
| 2329 | /** |
| 2330 | * Get archive url |
| 2331 | * |
| 2332 | * @return string |
| 2333 | */ |
| 2334 | function auxin_get_the_archive_url() { |
| 2335 | $url = ''; |
| 2336 | if ( is_category() || is_tag() || is_tax() ) { |
| 2337 | $url = get_term_link( get_queried_object() ); |
| 2338 | } elseif ( is_author() ) { |
| 2339 | $url = get_author_posts_url( get_queried_object_id() ); |
| 2340 | } elseif ( is_year() ) { |
| 2341 | $url = get_year_link( get_query_var( 'year' ) ); |
| 2342 | } elseif ( is_month() ) { |
| 2343 | $url = get_month_link( get_query_var( 'year' ), get_query_var( 'monthnum' ) ); |
| 2344 | } elseif ( is_day() ) { |
| 2345 | $url = get_day_link( get_query_var( 'year' ), get_query_var( 'monthnum' ), get_query_var( 'day' ) ); |
| 2346 | } elseif ( is_post_type_archive() ) { |
| 2347 | $url = get_post_type_archive_link( get_post_type() ); |
| 2348 | } |
| 2349 | |
| 2350 | return $url; |
| 2351 | } |
| 2352 | |
| 2353 | /** |
| 2354 | * Set global author data |
| 2355 | * |
| 2356 | * @return void |
| 2357 | */ |
| 2358 | function auxin_set_global_authordata() { |
| 2359 | global $authordata; |
| 2360 | if ( ! isset( $authordata->ID ) ) { |
| 2361 | $post = get_post(); |
| 2362 | $authordata = get_userdata( $post->post_author ); // WPCS: override ok. |
| 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | /** |
| 2367 | * Used to overcome core bug when taxonomy is in more then one post type |
| 2368 | * |
| 2369 | * @param array $args |
| 2370 | * @param string $output |
| 2371 | * @param string $operator |
| 2372 | * |
| 2373 | * @return array |
| 2374 | */ |
| 2375 | function auxin_get_taxonomies( $args = [], $output = 'names', $operator = 'and' ) { |
| 2376 | global $wp_taxonomies; |
| 2377 | |
| 2378 | $field = ( 'names' === $output ) ? 'name' : false; |
| 2379 | |
| 2380 | // Handle 'object_type' separately. |
| 2381 | if ( isset( $args['object_type'] ) ) { |
| 2382 | $object_type = (array) $args['object_type']; |
| 2383 | unset( $args['object_type'] ); |
| 2384 | } |
| 2385 | |
| 2386 | $taxonomies = wp_filter_object_list( $wp_taxonomies, $args, $operator ); |
| 2387 | |
| 2388 | if ( isset( $object_type ) ) { |
| 2389 | foreach ( $taxonomies as $tax => $tax_data ) { |
| 2390 | if ( ! array_intersect( $object_type, $tax_data->object_type ) ) { |
| 2391 | unset( $taxonomies[ $tax ] ); |
| 2392 | } |
| 2393 | } |
| 2394 | } |
| 2395 | |
| 2396 | if ( $field ) { |
| 2397 | $taxonomies = wp_list_pluck( $taxonomies, $field ); |
| 2398 | } |
| 2399 | |
| 2400 | return $taxonomies; |
| 2401 | } |
| 2402 | |
| 2403 | |
| 2404 | /** |
| 2405 | * Full Screen Search Results |
| 2406 | * |
| 2407 | */ |
| 2408 | function auxin_search_page_results($post_type = 'post',$args = array()) { |
| 2409 | switch ($post_type) { |
| 2410 | case 'product': |
| 2411 | echo auxin_widget_the_recent_products_callback($args); |
| 2412 | break; |
| 2413 | |
| 2414 | case 'portfolio': |
| 2415 | $additional_args = array( |
| 2416 | 'display_like' => 0, |
| 2417 | 'display_title' => 0, |
| 2418 | 'show_info' => 0, |
| 2419 | 'paginate' => false |
| 2420 | ); |
| 2421 | $args = wp_parse_args( $additional_args, $args ); |
| 2422 | echo auxin_widget_recent_portfolios_grid_callback($args); |
| 2423 | break; |
| 2424 | |
| 2425 | case 'news': |
| 2426 | $additional_args = array( |
| 2427 | 'big_grid_style' => 'pattern-6', |
| 2428 | ); |
| 2429 | $args = wp_parse_args( $additional_args, $args ); |
| 2430 | echo auxin_widget_recent_news_big_grid_callback( $args ); |
| 2431 | break; |
| 2432 | |
| 2433 | default: |
| 2434 | echo auxin_widget_recent_posts_callback($args); |
| 2435 | break; |
| 2436 | } |
| 2437 | |
| 2438 | } |
| 2439 | |
| 2440 | /** |
| 2441 | * Used to create an image size if not exist |
| 2442 | * |
| 2443 | * @param int $attachment_id |
| 2444 | * @param string $size |
| 2445 | * |
| 2446 | * @return void |
| 2447 | */ |
| 2448 | |
| 2449 | function auxin_maybe_create_image_size( $attachment_id, $size = '' ) { |
| 2450 | |
| 2451 | if ( empty( $attachment_id) || ! is_numeric( $attachment_id ) ) { |
| 2452 | return; |
| 2453 | } |
| 2454 | // check if image size exist or not |
| 2455 | if ( ! image_get_intermediate_size( $attachment_id, $size )) { |
| 2456 | |
| 2457 | if ( ! function_exists( 'wp_update_image_subsizes' ) ) { |
| 2458 | require_once( ABSPATH . "wp-admin" . '/includes/image.php' ); |
| 2459 | } |
| 2460 | |
| 2461 | // if WP version is less than 5.3.0 |
| 2462 | if( ! function_exists( 'wp_get_missing_image_subsizes' ) ){ |
| 2463 | return; |
| 2464 | } |
| 2465 | |
| 2466 | // only create the image size we need |
| 2467 | if ( ! isset( wp_get_missing_image_subsizes( $attachment_id )[ $size ] ) ) { |
| 2468 | return; |
| 2469 | } |
| 2470 | |
| 2471 | add_filter( 'wp_get_missing_image_subsizes', function( $missing_sizes ) use ( $size ) { |
| 2472 | return array( $size => $missing_sizes[ $size ] ); |
| 2473 | }); |
| 2474 | |
| 2475 | wp_update_image_subsizes( $attachment_id ); |
| 2476 | } |
| 2477 | } |
| 2478 | |
| 2479 | /** |
| 2480 | * Get List of available pages with id and title |
| 2481 | * |
| 2482 | * @return array |
| 2483 | */ |
| 2484 | function auxin_list_pages() { |
| 2485 | $all_pages = get_pages(); |
| 2486 | $list = array( '' => __( 'Select Page', 'auxin-elements' ) ); |
| 2487 | foreach( $all_pages as $page ) { |
| 2488 | $list[ $page->ID ] = $page->post_title ; |
| 2489 | } |
| 2490 | |
| 2491 | return $list; |
| 2492 | } |