classes
8 years ago
elements
8 years ago
define.php
8 years ago
general-functions.php
8 years ago
general-hooks.php
8 years ago
general-shortcodes.php
9 years ago
index.php
8 years ago
general-functions.php
1533 lines
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * |
| 5 | * @package Auxin |
| 6 | * @license LICENSE.txt |
| 7 | * @author |
| 8 | * @link http://averta.net/phlox/ |
| 9 | * @copyright (c) 2010-2017 |
| 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 | |
| 62 | return wp_get_attachment_image( auxin_get_option('site_secondary_logo_image'), 'full', false, array( |
| 63 | 'class' => 'aux-logo-image aux-logo-dark', |
| 64 | 'itemprop' => 'logo', |
| 65 | 'alt' => esc_attr( get_bloginfo( 'name', 'display' ) ) |
| 66 | ) ); |
| 67 | |
| 68 | } |
| 69 | |
| 70 | //// is absolute url /////////////////////////////////////////////////////////////////// |
| 71 | |
| 72 | /** |
| 73 | * Whether it's absolute url or not |
| 74 | * |
| 75 | * @param string $url The URL |
| 76 | * @return bool TRUE if the URL is absolute |
| 77 | */ |
| 78 | |
| 79 | if( ! function_exists( "auxin_is_absolute_url" ) ){ |
| 80 | |
| 81 | function auxin_is_absolute_url( $url ){ |
| 82 | return preg_match( "~^(?:f|ht)tps?://~i", $url ); |
| 83 | } |
| 84 | |
| 85 | } |
| 86 | |
| 87 | |
| 88 | //// create absolute url if the url is relative //////////////////////////////////////// |
| 89 | |
| 90 | /** |
| 91 | * Print absolute URL for media file even if the URL is relative |
| 92 | * |
| 93 | * @param string $url The link to media file |
| 94 | * @return void |
| 95 | */ |
| 96 | function auxin_the_absolute_image_url( $url ){ |
| 97 | echo auxin_get_the_absolute_image_url( $url ); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Get absolute URL for media file event if the URL is relative |
| 102 | * |
| 103 | * @param string $url The link to media file |
| 104 | * @return string The absolute URL to media file |
| 105 | */ |
| 106 | if( ! function_exists( 'auxin_get_the_absolute_image_url' ) ){ |
| 107 | |
| 108 | function auxin_get_the_absolute_image_url( $url ){ |
| 109 | if( ! isset( $url ) || empty( $url ) ) return ''; |
| 110 | |
| 111 | if( auxin_is_absolute_url( $url ) || auxin_contains_upload_dir( $url ) ) return $url; |
| 112 | |
| 113 | $uploads = wp_get_upload_dir(); |
| 114 | return trailingslashit( $uploads['baseurl'] ) . $url; |
| 115 | } |
| 116 | |
| 117 | } |
| 118 | |
| 119 | //// get all registerd siderbar ids /////////////////////////////////////////////////// |
| 120 | |
| 121 | if( ! function_exists( 'auxin_get_all_sidebar_ids' ) ){ |
| 122 | |
| 123 | function auxin_get_all_sidebar_ids(){ |
| 124 | $sidebars = get_theme_mod( 'auxin_sidebars'); |
| 125 | $output = array(); |
| 126 | |
| 127 | if( isset( $auxin_sidebars ) && ! empty( $auxin_sidebars ) ){ |
| 128 | foreach( $sidebars as $key => $value ) { |
| 129 | $output[] = THEME_ID .'-'. strtolower( str_replace(' ', '-', $value) ); |
| 130 | } |
| 131 | } |
| 132 | return $output; |
| 133 | } |
| 134 | |
| 135 | } |
| 136 | |
| 137 | //// remove all auto generated p tags from shortcode content ////////////////////////// |
| 138 | |
| 139 | if( ! function_exists( "auxin_do_cleanup_shortcode" ) ){ |
| 140 | |
| 141 | function auxin_do_cleanup_shortcode( $content ) { |
| 142 | |
| 143 | /* Parse nested shortcodes and add formatting. */ |
| 144 | $content = trim( wpautop( do_shortcode( $content ) ) ); |
| 145 | |
| 146 | /* Remove any instances of '<p>' '</p>'. */ |
| 147 | $content = auxin_cleanup_content( $content ); |
| 148 | |
| 149 | return $content; |
| 150 | } |
| 151 | |
| 152 | } |
| 153 | |
| 154 | |
| 155 | //// remove all p tags from string //////////////////////////////////////////////////// |
| 156 | |
| 157 | if( ! function_exists( 'auxin_cleanup_content' ) ){ |
| 158 | |
| 159 | function auxin_cleanup_content( $content ) { |
| 160 | /* Remove any instances of '<p>' '</p>'. */ |
| 161 | return str_replace( array('<p>','</p>'), array('','') , $content ); |
| 162 | } |
| 163 | |
| 164 | } |
| 165 | |
| 166 | /*-----------------------------------------------------------------------------------*/ |
| 167 | /* A function that makes excluding featured image, post formats and post ids simpler |
| 168 | /*-----------------------------------------------------------------------------------*/ |
| 169 | |
| 170 | if( ! function_exists( 'auxin_parse_query_args' ) ){ |
| 171 | |
| 172 | |
| 173 | /** |
| 174 | * A function that makes excluding featured image, post formats and post ids simpler |
| 175 | * |
| 176 | * @param array $args The list of options and query params |
| 177 | * @return array The parsed args as array |
| 178 | */ |
| 179 | function auxin_parse_query_args( $args ){ |
| 180 | |
| 181 | $defaults = array( |
| 182 | 'post_type' => 'post', |
| 183 | 'post_status' => 'publish', |
| 184 | 'posts_per_page' => -1, |
| 185 | 'ignore_sticky_posts' => 1, |
| 186 | |
| 187 | 'posts__in' => '', // display only these post IDs. array or string comma separated |
| 188 | 'posts__not_in' => '', // exclude these post IDs from result. array or string comma separated |
| 189 | |
| 190 | 'include_posts__in' => '', // include these post IDs in result too. array or string comma separated |
| 191 | 'exclude_without_media' => 0, // exclude the posts without featured image |
| 192 | 'exclude_post_formats_in' => '', // exclude the post with these post formats |
| 193 | ); |
| 194 | |
| 195 | // parse and merge the passed args |
| 196 | $parsed_args = wp_parse_args( $args, $defaults ); |
| 197 | |
| 198 | |
| 199 | // Exclude post formats ---------------------------------------------------- |
| 200 | |
| 201 | // exclude post formats if specified |
| 202 | if( ! empty( $parsed_args['exclude_post_formats_in'] ) ){ |
| 203 | |
| 204 | // generate post-format terms (i.e post-format-aside) |
| 205 | $post_format_terms = array(); |
| 206 | foreach ( $parsed_args['exclude_post_formats_in'] as $_post_format ) { |
| 207 | $post_format_terms[] = 'post-format-' . $_post_format; |
| 208 | } |
| 209 | |
| 210 | // exclude the redundant taxonomies (post-format) |
| 211 | $parsed_args['tax_query'] = array( |
| 212 | array( |
| 213 | 'taxonomy' => 'post_format', |
| 214 | 'field' => 'slug', |
| 215 | 'terms' => $post_format_terms, |
| 216 | 'operator' => 'NOT IN' |
| 217 | ) |
| 218 | ); |
| 219 | |
| 220 | } |
| 221 | |
| 222 | // Exclude posts without featured image ------------------------------------ |
| 223 | |
| 224 | // whether to exclude posts without featured-image or not |
| 225 | if( $parsed_args['exclude_without_media'] ){ |
| 226 | $parsed_args['meta_query'] = array( |
| 227 | array( |
| 228 | 'key' => '_thumbnail_id', |
| 229 | 'value' => '', |
| 230 | 'compare' => '!=' |
| 231 | ) |
| 232 | ); |
| 233 | } |
| 234 | |
| 235 | |
| 236 | // Include, Exclude & Replace Post IDs ------------------------------------- |
| 237 | |
| 238 | // get the list of custom post ids to display |
| 239 | $only_posts = $parsed_args['posts__in'] ? wp_parse_id_list( $parsed_args['posts__in'] ) : array(); |
| 240 | |
| 241 | // get the list of custom post ids to include |
| 242 | $include_posts = $parsed_args['include_posts__in'] ? wp_parse_id_list( $parsed_args['include_posts__in'] ) : array(); |
| 243 | |
| 244 | // get the list of custom post ids to exclude |
| 245 | $exclude_posts = $parsed_args['posts__not_in'] ? wp_parse_id_list( $parsed_args['posts__not_in'] ) : array(); |
| 246 | |
| 247 | |
| 248 | // if both of post__in and post__not_in options are defined, we have to array_diff the arrays, |
| 249 | // because we cannot use post__in & post__not_in at the time in WordPress |
| 250 | |
| 251 | if( $only_posts ){ |
| 252 | |
| 253 | if( $exclude_posts ){ |
| 254 | // remove the excluded post ids from post__in list |
| 255 | if( $only_posts = array_filter( array_diff( $only_posts, $exclude_posts ) ) ){ |
| 256 | $parsed_args['post__in'] = $only_posts; |
| 257 | } |
| 258 | } else { |
| 259 | $parsed_args['post__in'] = $only_posts; |
| 260 | } |
| 261 | $parsed_args['posts__not_in'] = ''; |
| 262 | |
| 263 | // if include_posts__in was specified |
| 264 | } elseif( $include_posts ){ |
| 265 | |
| 266 | $extra_query_args = $parsed_args; |
| 267 | |
| 268 | // query the posts other than the ones we intend to include |
| 269 | $include_and_exclude_posts = array_unique( array_filter( array_merge( $include_posts, $exclude_posts ) ) ); |
| 270 | // remove the excluded post ids from include_posts__in list |
| 271 | $the_posts_to_include = array_diff( $include_posts, $exclude_posts ); |
| 272 | |
| 273 | $extra_query_args['fields'] = 'ids'; // just get IDs, for better performance |
| 274 | $extra_query_args['post__in'] = ''; // forget post__in in this pre query |
| 275 | $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 |
| 276 | |
| 277 | // get the post ids other than our include and exclude list |
| 278 | $other_post_ids = get_posts( $extra_query_args ); |
| 279 | |
| 280 | // prepend the included post ids |
| 281 | $merged_post_ids = array_merge( $the_posts_to_include, $other_post_ids ); |
| 282 | |
| 283 | // change the main query base on previous result |
| 284 | $parsed_args = array( |
| 285 | 'post__in' => $merged_post_ids, |
| 286 | 'orderby' => 'post__in', // query base on the order of defined post ids |
| 287 | 'posts_per_page' => $parsed_args['posts_per_page'], |
| 288 | 'ignore_sticky_posts' => 1 |
| 289 | ); |
| 290 | |
| 291 | // if just "post__not_in" option is specified |
| 292 | } elseif( $exclude_posts ) { |
| 293 | $parsed_args['post__not_in'] = $exclude_posts; |
| 294 | } |
| 295 | |
| 296 | // Remove extra query args ------------------------------------------------- |
| 297 | |
| 298 | unset( $parsed_args['include_posts__in'] ); |
| 299 | unset( $parsed_args['exclude_without_media'] ); |
| 300 | unset( $parsed_args['exclude_post_formats_in'] ); |
| 301 | |
| 302 | return $parsed_args; |
| 303 | } |
| 304 | |
| 305 | } |
| 306 | |
| 307 | |
| 308 | |
| 309 | /*-----------------------------------------------------------------------------------*/ |
| 310 | /* Extract only raw text - remove all special charecters, html tags, js and css codes |
| 311 | /*-----------------------------------------------------------------------------------*/ |
| 312 | |
| 313 | function auxin_extract_text( $content = null ) { |
| 314 | // decode encoded html tags |
| 315 | $content = htmlspecialchars_decode($content); |
| 316 | // remove script tag and inline js content |
| 317 | $content = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $content); |
| 318 | // remove style tag and inline css content |
| 319 | $content = preg_replace('#<style(.*?)>(.*?)</style>#is' , '', $content); |
| 320 | // remove iframe content |
| 321 | $content = preg_replace('#<if'.'rame(.*?)>(.*?)</iframe>#is', '', $content); |
| 322 | // remove extra white spaces |
| 323 | $content = preg_replace('/[\s]+/', ' ', $content ); |
| 324 | // strip html tags and escape special charecters |
| 325 | $content = esc_attr(strip_tags($content)); |
| 326 | // remove double space |
| 327 | $content = preg_replace('/\s{3,}/',' ', $content ); |
| 328 | return $content; |
| 329 | } |
| 330 | |
| 331 | /*-----------------------------------------------------------------------------------*/ |
| 332 | /* Big Grid layout patterns |
| 333 | /*-----------------------------------------------------------------------------------*/ |
| 334 | |
| 335 | function auxin_get_grid_pattern( $pattern, $index, $column_media_width ) { |
| 336 | |
| 337 | switch ( $pattern ) { |
| 338 | case 'pattern-1': |
| 339 | return auxin_big_grid_pattern_1( $index, $column_media_width ); |
| 340 | break; |
| 341 | case 'pattern-2'; |
| 342 | return auxin_big_grid_pattern_2( $index, $column_media_width ); |
| 343 | break; |
| 344 | case 'pattern-3'; |
| 345 | return auxin_big_grid_pattern_3( $index, $column_media_width ); |
| 346 | break; |
| 347 | case 'pattern-4'; |
| 348 | return auxin_big_grid_pattern_4( $index, $column_media_width ); |
| 349 | break; |
| 350 | case 'pattern-5'; |
| 351 | return auxin_big_grid_pattern_5( $index, $column_media_width ); |
| 352 | break; |
| 353 | case 'pattern-6'; |
| 354 | return auxin_big_grid_pattern_6( $index, $column_media_width ); |
| 355 | break; |
| 356 | case 'pattern-7'; |
| 357 | return auxin_big_grid_pattern_7( $index, $column_media_width ); |
| 358 | break; |
| 359 | default: |
| 360 | return auxin_get_big_grid_pattern( 'default', $index, $column_media_width ); |
| 361 | break; |
| 362 | } |
| 363 | |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Defines the size of post tile based on pattern and given index |
| 368 | * @param string $pattern |
| 369 | * @param int $index |
| 370 | * @return Array classname, image size |
| 371 | */ |
| 372 | function auxin_get_big_grid_pattern( $pattern = 'default', $index, $column_media_width ) { |
| 373 | |
| 374 | $div_index = $index % 12; |
| 375 | $return_value = array(); |
| 376 | |
| 377 | switch ( $div_index ) { |
| 378 | |
| 379 | // large squares |
| 380 | case 0: |
| 381 | case 7: |
| 382 | $return_value = array( |
| 383 | 'classname' => 'aux-big-grid-6-6 aux-t-big-grid-4-2 aux-m-big-grid-4-2', |
| 384 | 'size' => array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 385 | 'image_sizes' => array( |
| 386 | array( 'min' => '' , 'max' => '992px', 'width' => '100vw' ), |
| 387 | array( 'min' => '' , 'max' => '', 'width' => 2 * $column_media_width . 'px' ) |
| 388 | ), |
| 389 | 'srcset_sizes' => array( |
| 390 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 391 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ), |
| 392 | array( 'width' => 8 * $column_media_width, 'height' => 8 * $column_media_width ) |
| 393 | ) |
| 394 | ); |
| 395 | break; |
| 396 | |
| 397 | // full width |
| 398 | case 5: |
| 399 | case 11: |
| 400 | $return_value = array( |
| 401 | 'classname' => 'aux-big-grid-12-6', |
| 402 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width * 0.5 ), |
| 403 | 'image_sizes' => array( |
| 404 | |
| 405 | ), |
| 406 | 'srcset_sizes' => array( |
| 407 | array( 'width' => $column_media_width, 'height' => $column_media_width * 0.5), |
| 408 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width * 0.5), |
| 409 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width * 0.5 ) |
| 410 | ) |
| 411 | ); |
| 412 | break; |
| 413 | |
| 414 | // small squares |
| 415 | default: |
| 416 | $return_value = array( |
| 417 | 'classname' => 'aux-big-grid-3-3 aux-t-big-grid-2-2 aux-m-big-grid--4-2', |
| 418 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 419 | 'image_sizes' => array( |
| 420 | array( 'min' => '', 'max' => '767px', 'width' => '100vw' ), |
| 421 | array( 'min' => '' , 'max' => '992px', 'width' => '50vw' ), |
| 422 | array( 'min' => '' , 'max' => '', 'width' => $column_media_width . 'px' ) |
| 423 | ), |
| 424 | 'srcset_sizes' => array( |
| 425 | array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 426 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 427 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ) |
| 428 | ) |
| 429 | ); |
| 430 | |
| 431 | } |
| 432 | |
| 433 | return $return_value; |
| 434 | } |
| 435 | |
| 436 | |
| 437 | function auxin_big_grid_pattern_1( $index, $column_media_width ) { |
| 438 | |
| 439 | $return_value = array(); |
| 440 | |
| 441 | $return_value = array( |
| 442 | 'classname' => 'aux-big-grid-4-4 aux-t-big-grid-6-6 aux-m-big-grid-12-6', |
| 443 | 'size' => array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 444 | 'image_sizes' => array( |
| 445 | array( 'min' => '' , 'max' => '992px', 'width' => '100vw' ), |
| 446 | array( 'min' => '' , 'max' => ' |
| 447 | ', 'width' => 2 * $column_media_width . 'px' ) |
| 448 | ), |
| 449 | 'srcset_sizes' => array( |
| 450 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 451 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ), |
| 452 | array( 'width' => 8 * $column_media_width, 'height' => 8 * $column_media_width ) |
| 453 | ) |
| 454 | ); |
| 455 | |
| 456 | return $return_value; |
| 457 | |
| 458 | } |
| 459 | |
| 460 | |
| 461 | function auxin_big_grid_pattern_2( $index, $column_media_width ) { |
| 462 | |
| 463 | $div_index = $index % 5; |
| 464 | $return_value = array(); |
| 465 | |
| 466 | switch ( $div_index ) { |
| 467 | |
| 468 | // large squares |
| 469 | case 1: |
| 470 | $return_value = array( |
| 471 | 'classname' => 'aux-big-grid-6-6 aux-t-big-grid-12-6 aux-m-big-grid-12-6', |
| 472 | 'size' => array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 473 | 'image_sizes' => array( |
| 474 | array( 'min' => '' , 'max' => '992px', 'width' => '100vw' ), |
| 475 | array( 'min' => '' , 'max' => '', 'width' => 2 * $column_media_width . 'px' ) |
| 476 | ), |
| 477 | 'srcset_sizes' => array( |
| 478 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 479 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ), |
| 480 | array( 'width' => 8 * $column_media_width, 'height' => 8 * $column_media_width ) |
| 481 | ) |
| 482 | ); |
| 483 | break; |
| 484 | |
| 485 | // small squares |
| 486 | default: |
| 487 | $return_value = array( |
| 488 | 'classname' => 'aux-big-grid-3-3 aux-t-big-grid-6-6 aux-m-big-grid-12-6', |
| 489 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 490 | 'image_sizes' => array( |
| 491 | array( 'min' => '', 'max' => '767px', 'width' => '100vw' ), |
| 492 | array( 'min' => '' , 'max' => '992px', 'width' => '50vw' ), |
| 493 | array( 'min' => '' , 'max' => '', 'width' => $column_media_width . 'px' ) |
| 494 | ), |
| 495 | 'srcset_sizes' => array( |
| 496 | array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 497 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 498 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ) |
| 499 | ) |
| 500 | ); |
| 501 | |
| 502 | } |
| 503 | |
| 504 | return $return_value; |
| 505 | |
| 506 | } |
| 507 | |
| 508 | |
| 509 | function auxin_big_grid_pattern_3( $index, $column_media_width ) { |
| 510 | |
| 511 | $div_index = $index % 3; |
| 512 | $return_value = array(); |
| 513 | |
| 514 | switch ( $div_index ) { |
| 515 | |
| 516 | case 0: |
| 517 | $return_value = array( |
| 518 | 'classname' => 'aux-big-grid-6-6 aux-t-big-grid-12-6 aux-m-big-grid-12-6', |
| 519 | 'size' => array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 520 | 'image_sizes' => array( |
| 521 | array( 'min' => '' , 'max' => '992px', 'width' => '100vw' ), |
| 522 | array( 'min' => '' , 'max' => '', 'width' => 2 * $column_media_width . 'px' ) |
| 523 | ), |
| 524 | 'srcset_sizes' => array( |
| 525 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 526 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ), |
| 527 | array( 'width' => 8 * $column_media_width, 'height' => 8 * $column_media_width ) |
| 528 | ) |
| 529 | ); |
| 530 | break; |
| 531 | |
| 532 | default: |
| 533 | $return_value = array( |
| 534 | 'classname' => 'aux-big-grid-6-3 aux-t-big-grid-12-6 aux-m-big-grid-12-6', |
| 535 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 536 | 'image_sizes' => array( |
| 537 | array( 'min' => '', 'max' => '767px', 'width' => '100vw' ), |
| 538 | array( 'min' => '' , 'max' => '992px', 'width' => '50vw' ), |
| 539 | array( 'min' => '' , 'max' => '', 'width' => $column_media_width . 'px' ) |
| 540 | ), |
| 541 | 'srcset_sizes' => array( |
| 542 | array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 543 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 544 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ) |
| 545 | ) |
| 546 | ); |
| 547 | |
| 548 | } |
| 549 | |
| 550 | return $return_value; |
| 551 | |
| 552 | } |
| 553 | |
| 554 | |
| 555 | function auxin_big_grid_pattern_4( $index, $column_media_width ) { |
| 556 | |
| 557 | $div_index = $index % 4; |
| 558 | $return_value = array(); |
| 559 | |
| 560 | switch ( $div_index ) { |
| 561 | |
| 562 | // large squares |
| 563 | case 0: |
| 564 | $return_value = array( |
| 565 | 'classname' => 'aux-big-grid-6-6 aux-t-big-grid-12-6 aux-m-big-grid-12-6', |
| 566 | 'size' => array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 567 | 'image_sizes' => array( |
| 568 | array( 'min' => '' , 'max' => '992px', 'width' => '100vw' ), |
| 569 | array( 'min' => '' , 'max' => '', 'width' => 2 * $column_media_width . 'px' ) |
| 570 | ), |
| 571 | 'srcset_sizes' => array( |
| 572 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 573 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ), |
| 574 | array( 'width' => 8 * $column_media_width, 'height' => 8 * $column_media_width ) |
| 575 | ) |
| 576 | ); |
| 577 | break; |
| 578 | |
| 579 | case 1: |
| 580 | $return_value = array( |
| 581 | 'classname' => 'aux-big-grid-6-3 aux-t-big-grid-12-6 aux-m-big-grid-12-6', |
| 582 | 'size' => array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ), |
| 583 | 'image_sizes' => array( |
| 584 | array( 'min' => '' , 'max' => '992px', 'width' => '100vw' ), |
| 585 | array( 'min' => '' , 'max' => '', 'width' => 2 * $column_media_width . 'px' ) |
| 586 | ), |
| 587 | 'srcset_sizes' => array( |
| 588 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 589 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ), |
| 590 | array( 'width' => 8 * $column_media_width, 'height' => 8 * $column_media_width ) |
| 591 | ) |
| 592 | ); |
| 593 | break; |
| 594 | |
| 595 | // small squares |
| 596 | default: |
| 597 | $return_value = array( |
| 598 | 'classname' => 'aux-big-grid-3-3 aux-t-big-grid-6-6 aux-m-big-grid-12-6', |
| 599 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 600 | 'image_sizes' => array( |
| 601 | array( 'min' => '', 'max' => '767px', 'width' => '100vw' ), |
| 602 | array( 'min' => '' , 'max' => '992px', 'width' => '50vw' ), |
| 603 | array( 'min' => '' , 'max' => '', 'width' => $column_media_width . 'px' ) |
| 604 | ), |
| 605 | 'srcset_sizes' => array( |
| 606 | array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 607 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 608 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ) |
| 609 | ) |
| 610 | ); |
| 611 | |
| 612 | } |
| 613 | |
| 614 | return $return_value; |
| 615 | } |
| 616 | |
| 617 | |
| 618 | function auxin_big_grid_pattern_5( $index, $column_media_width ) { |
| 619 | $div_index = $index % 6; |
| 620 | $return_value = array(); |
| 621 | |
| 622 | switch ( $div_index ) { |
| 623 | |
| 624 | // large squares |
| 625 | case 0: |
| 626 | case 1: |
| 627 | $return_value = array( |
| 628 | 'classname' => 'aux-big-grid-6-6 aux-t-big-grid-12-6 aux-m-big-grid-12-6', |
| 629 | 'size' => array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 630 | 'image_sizes' => array( |
| 631 | array( 'min' => '' , 'max' => '992px', 'width' => '100vw' ), |
| 632 | array( 'min' => '' , 'max' => '', 'width' => 2 * $column_media_width . 'px' ) |
| 633 | ), |
| 634 | 'srcset_sizes' => array( |
| 635 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 636 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ), |
| 637 | array( 'width' => 8 * $column_media_width, 'height' => 8 * $column_media_width ) |
| 638 | ) |
| 639 | ); |
| 640 | break; |
| 641 | |
| 642 | // small squares |
| 643 | default: |
| 644 | $return_value = array( |
| 645 | 'classname' => 'aux-big-grid-3-3 aux-t-big-grid-6-6 aux-m-big-grid-12-6', |
| 646 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 647 | 'image_sizes' => array( |
| 648 | array( 'min' => '', 'max' => '767px', 'width' => '100vw' ), |
| 649 | array( 'min' => '' , 'max' => '992px', 'width' => '50vw' ), |
| 650 | array( 'min' => '' , 'max' => '', 'width' => $column_media_width . 'px' ) |
| 651 | ), |
| 652 | 'srcset_sizes' => array( |
| 653 | array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 654 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 655 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ) |
| 656 | ) |
| 657 | ); |
| 658 | |
| 659 | } |
| 660 | |
| 661 | return $return_value; |
| 662 | |
| 663 | } |
| 664 | |
| 665 | |
| 666 | function auxin_big_grid_pattern_6( $index, $column_media_width ) { |
| 667 | $return_value = array(); |
| 668 | |
| 669 | $return_value = array( |
| 670 | 'classname' => 'aux-big-grid-lg-4-4 aux-t-big-grid-lg-6-6 aux-m-big-grid-lg-12-6', |
| 671 | 'size' => array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 672 | 'image_sizes' => array( |
| 673 | array( 'min' => '' , 'max' => '992px', 'width' => '100vw' ), |
| 674 | array( 'min' => '' , 'max' => ' |
| 675 | ', 'width' => 2 * $column_media_width . 'px' ) |
| 676 | ), |
| 677 | 'srcset_sizes' => array( |
| 678 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 679 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ), |
| 680 | array( 'width' => 8 * $column_media_width, 'height' => 8 * $column_media_width ) |
| 681 | ) |
| 682 | ); |
| 683 | |
| 684 | return $return_value; |
| 685 | |
| 686 | } |
| 687 | |
| 688 | |
| 689 | function auxin_big_grid_pattern_7( $index, $column_media_width ) { |
| 690 | $return_value = array(); |
| 691 | |
| 692 | $return_value = array( |
| 693 | 'classname' => 'aux-big-grid-sg-4-4 aux-t-big-grid-sg-6-6 aux-m-big-grid-sg-12-6', |
| 694 | 'size' => array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 695 | 'image_sizes' => array( |
| 696 | array( 'min' => '' , 'max' => '992px', 'width' => '100vw' ), |
| 697 | array( 'min' => '' , 'max' => ' |
| 698 | ', 'width' => 2 * $column_media_width . 'px' ) |
| 699 | ), |
| 700 | 'srcset_sizes' => array( |
| 701 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 702 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ), |
| 703 | array( 'width' => 8 * $column_media_width, 'height' => 8 * $column_media_width ) |
| 704 | ) |
| 705 | ); |
| 706 | |
| 707 | return $return_value; |
| 708 | |
| 709 | } |
| 710 | |
| 711 | |
| 712 | /*-----------------------------------------------------------------------------------*/ |
| 713 | /* Tiles layout patterns |
| 714 | /*-----------------------------------------------------------------------------------*/ |
| 715 | |
| 716 | |
| 717 | /** |
| 718 | * Defines the size of post tile based on pattern and given index |
| 719 | * @param string $pattern |
| 720 | * @param int $index |
| 721 | * @return Array classname, image size |
| 722 | */ |
| 723 | function auxin_get_tile_pattern( $pattern = 'default', $index, $column_media_width ) { |
| 724 | |
| 725 | $div_index = $index % 12; |
| 726 | $return_value = array(); |
| 727 | |
| 728 | switch ( $div_index ) { |
| 729 | |
| 730 | // large squares |
| 731 | case 0: |
| 732 | case 7: |
| 733 | $return_value = array( |
| 734 | 'classname' => 'aux-tile-2-2 aux-t-tile-4-2 aux-m-tile-4-2', |
| 735 | 'size' => array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 736 | 'image_sizes' => array( |
| 737 | array( 'min' => '' , 'max' => '992px', 'width' => '100vw' ), |
| 738 | array( 'min' => '' , 'max' => '', 'width' => 2 * $column_media_width . 'px' ) |
| 739 | ), |
| 740 | 'srcset_sizes' => array( |
| 741 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 742 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ), |
| 743 | array( 'width' => 8 * $column_media_width, 'height' => 8 * $column_media_width ) |
| 744 | ) |
| 745 | ); |
| 746 | break; |
| 747 | |
| 748 | // full width |
| 749 | case 5: |
| 750 | case 11: |
| 751 | $return_value = array( |
| 752 | 'classname' => 'aux-tile-4-2', |
| 753 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width * 0.5 ), |
| 754 | 'image_sizes' => array( |
| 755 | |
| 756 | ), |
| 757 | 'srcset_sizes' => array( |
| 758 | array( 'width' => $column_media_width, 'height' => $column_media_width * 0.5), |
| 759 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width * 0.5), |
| 760 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width * 0.5 ) |
| 761 | ) |
| 762 | ); |
| 763 | break; |
| 764 | |
| 765 | // small squares |
| 766 | default: |
| 767 | $return_value = array( |
| 768 | 'classname' => 'aux-tile-1-1 aux-t-tile-2-2 aux-m-tile-4-2', |
| 769 | 'size' => array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 770 | 'image_sizes' => array( |
| 771 | array( 'min' => '', 'max' => '767px', 'width' => '100vw' ), |
| 772 | array( 'min' => '' , 'max' => '992px', 'width' => '50vw' ), |
| 773 | array( 'min' => '' , 'max' => '', 'width' => $column_media_width . 'px' ) |
| 774 | ), |
| 775 | 'srcset_sizes' => array( |
| 776 | array( 'width' => $column_media_width, 'height' => $column_media_width ), |
| 777 | array( 'width' => 2 * $column_media_width, 'height' => 2 * $column_media_width ), |
| 778 | array( 'width' => 4 * $column_media_width, 'height' => 4 * $column_media_width ) |
| 779 | ) |
| 780 | ); |
| 781 | |
| 782 | } |
| 783 | |
| 784 | return $return_value; |
| 785 | } |
| 786 | |
| 787 | |
| 788 | /*-----------------------------------------------------------------------------------*/ |
| 789 | /* Retrieves the provider from an embed code link |
| 790 | /*-----------------------------------------------------------------------------------*/ |
| 791 | |
| 792 | |
| 793 | function auxin_extract_embed_provider_name( $src ){ |
| 794 | require_once( ABSPATH . WPINC . '/class-oembed.php' ); |
| 795 | $oembed = _wp_oembed_get_object(); |
| 796 | if( ! $provider = $oembed->get_provider( $src ) ){ |
| 797 | return ''; |
| 798 | } |
| 799 | |
| 800 | $provider_info = parse_url( $provider ); |
| 801 | if( $provider_info['host'] ){ |
| 802 | $host_parts = explode( '.', $provider_info['host'] ); |
| 803 | $host_parts_num = count( $host_parts ); |
| 804 | if( $host_parts_num > 1 ){ |
| 805 | return $host_parts[ $host_parts_num -2 ]; |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | return ''; |
| 810 | } |
| 811 | |
| 812 | |
| 813 | |
| 814 | //// Store content in file //////////////////////////////////////////////////////// |
| 815 | |
| 816 | /** |
| 817 | * Creates and stores content in a file (#admin) |
| 818 | * |
| 819 | * @param string $content The content for writing in the file |
| 820 | * @param string $file_location The address that we plan to create the file in. |
| 821 | * |
| 822 | * @return boolean Returns true if the file is created and updated successfully, false on failure |
| 823 | */ |
| 824 | function auxin_put_contents( $content, $file_location = '', $chmode = 0644 ){ |
| 825 | |
| 826 | if( empty( $file_location ) ){ |
| 827 | return false; |
| 828 | } |
| 829 | |
| 830 | /** |
| 831 | * Initialize the WP_Filesystem |
| 832 | */ |
| 833 | global $wp_filesystem; |
| 834 | if ( empty( $wp_filesystem ) ) { |
| 835 | require_once ( ABSPATH.'/wp-admin/includes/file.php' ); |
| 836 | WP_Filesystem(); |
| 837 | } |
| 838 | |
| 839 | // Write the content, if possible |
| 840 | if ( wp_mkdir_p( dirname( $file_location ) ) && ! $wp_filesystem->put_contents( $file_location, $content, $chmode ) ) { |
| 841 | // If writing the content in the file was not successful |
| 842 | return false; |
| 843 | } else { |
| 844 | return true; |
| 845 | } |
| 846 | |
| 847 | } |
| 848 | |
| 849 | |
| 850 | //// Stores content in custom js file ///////////////////////////////////////////// |
| 851 | |
| 852 | |
| 853 | /** |
| 854 | * Stores JavaScript content in custom js file (#admin) |
| 855 | * |
| 856 | * @return boolean Returns true if the file is created and updated successfully, false on failure |
| 857 | */ |
| 858 | function auxin_save_custom_js(){ |
| 859 | |
| 860 | $js_string = get_theme_mod( 'custom_js_string' ); |
| 861 | |
| 862 | ob_start(); |
| 863 | ?> |
| 864 | /* |
| 865 | =============================================================== |
| 866 | #CUSTOM JavaScript |
| 867 | - Please do not edit this file. This file is generated from admin area. |
| 868 | - Every changes here will be overwritten by theme |
| 869 | ===============================================================*/ |
| 870 | <?php |
| 871 | |
| 872 | $js_string = ob_get_clean() . $js_string; |
| 873 | |
| 874 | |
| 875 | if ( auxin_put_contents_dir( $js_string, 'custom.js' ) ) { |
| 876 | set_theme_mod( 'custom_js_ver', rand(10, 99)/10 ); // disable inline css output |
| 877 | set_theme_mod( 'use_inline_custom_js' , false ); // disable inline css output |
| 878 | |
| 879 | return true; |
| 880 | } else { |
| 881 | // if the directory is not writable, try inline css fallback |
| 882 | set_theme_mod( 'use_inline_custom_js' , true ); // save css rules as option to print as inline css |
| 883 | |
| 884 | return false; |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | |
| 889 | /** |
| 890 | * Removes an specific content from custom js file (#admin) |
| 891 | * |
| 892 | * @param string $ref_name The reference name for referring a content in $js_array array |
| 893 | * |
| 894 | * @return boolean Returns true if the content was removed successfully, false on failure |
| 895 | */ |
| 896 | function auxin_remove_custom_js( $ref_name = '' ){ |
| 897 | |
| 898 | // retrieve the js array list |
| 899 | $js_array = get_theme_mod( 'custom_js_array', array() ); |
| 900 | |
| 901 | if( isset( $js_array[ $ref_name ] ) ){ |
| 902 | unset( $js_array[ $ref_name ] ); |
| 903 | |
| 904 | set_theme_mod( 'custom_js_array' , $js_array ); |
| 905 | // update the file content too |
| 906 | auxin_add_custom_js(); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | |
| 911 | /** |
| 912 | * Retrieves the list of custom scripts generated with themes options |
| 913 | * |
| 914 | * @param string $exclude_ref_names The reference names that are expected to be excluded from result |
| 915 | * |
| 916 | * @return boolean The list of custom scripts generated with themes options |
| 917 | */ |
| 918 | function auxin_get_custom_js_array( $exclude_ref_names = array() ){ |
| 919 | // retrieve the css array list |
| 920 | $js_array = get_theme_mod( 'custom_js_array', array() ); |
| 921 | |
| 922 | return array_diff_key( $js_array, array_flip( (array) $exclude_ref_names ) ); |
| 923 | } |
| 924 | |
| 925 | |
| 926 | |
| 927 | //// Stores content in custom css file ///////////////////////////////////////////// |
| 928 | |
| 929 | |
| 930 | /** |
| 931 | * Stores css content in custom css file (#admin) |
| 932 | * |
| 933 | * @return boolean Returns true if the file is created and updated successfully, false on failure |
| 934 | */ |
| 935 | function auxin_save_custom_css(){ |
| 936 | |
| 937 | $css_string = get_theme_mod( 'custom_css_string' ); |
| 938 | |
| 939 | ob_start(); |
| 940 | ?> |
| 941 | /* |
| 942 | =============================================================== |
| 943 | #CUSTOM CSS |
| 944 | - Please do not edit this file. This file is generated from admin area. |
| 945 | - Every changes here will be overwritten by theme |
| 946 | ===============================================================*/ |
| 947 | <?php |
| 948 | |
| 949 | $css_string = ob_get_clean() . $css_string; |
| 950 | |
| 951 | if ( auxin_put_contents_dir( $css_string, 'custom.css' ) ) { |
| 952 | |
| 953 | set_theme_mod( 'custom_css_ver', rand(10, 99)/10 ); |
| 954 | set_theme_mod( 'use_inline_custom_css' , false ); // disable inline css output |
| 955 | |
| 956 | return true; |
| 957 | // if the directory is not writable, try inline css fallback |
| 958 | } else { |
| 959 | set_theme_mod( 'use_inline_custom_css' , true ); // save css rules as option to print as inline css |
| 960 | return false; |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | |
| 965 | /** |
| 966 | * Removes an specific content from custom css file (#admin) |
| 967 | * |
| 968 | * @param string $ref_name The reference name for referring a content in $css_array array |
| 969 | * |
| 970 | * @return boolean Returns true if the content was removed successfully, false on failure |
| 971 | */ |
| 972 | function auxin_remove_custom_css( $ref_name = '' ){ |
| 973 | |
| 974 | // retrieve the css array list |
| 975 | $css_array = get_theme_mod( 'custom_css_array', array() ); |
| 976 | |
| 977 | if( isset( $css_array[ $ref_name ] ) ){ |
| 978 | unset( $css_array[ $ref_name ] ); |
| 979 | |
| 980 | set_theme_mod( 'custom_css_array', $css_array ); |
| 981 | // update the file content too |
| 982 | auxin_add_custom_css(); |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | |
| 987 | /** |
| 988 | * Retrieves the list of custom styles generated with themes options |
| 989 | * |
| 990 | * @param string $exclude_ref_names The reference names that are expected to be excluded from result |
| 991 | * |
| 992 | * @return boolean The list of custom styles generated with themes options |
| 993 | */ |
| 994 | function auxin_get_custom_css_array( $exclude_ref_names = array() ){ |
| 995 | // retrieve the css array list |
| 996 | $css_array = get_theme_mod( 'custom_css_array', array() ); |
| 997 | |
| 998 | return array_diff_key( $css_array, array_flip( (array) $exclude_ref_names ) ); |
| 999 | } |
| 1000 | |
| 1001 | |
| 1002 | /** |
| 1003 | * Retrieves the custom styles generated with themes options |
| 1004 | * |
| 1005 | * @param string $exclude_ref_names The css reference names that are expected to be excluded from result |
| 1006 | * |
| 1007 | * @return boolean The custom styles generated with themes options |
| 1008 | */ |
| 1009 | function auxin_get_custom_css_string( $exclude_ref_names = array() ){ |
| 1010 | // retrieve the css array list |
| 1011 | $css_array = auxin_get_custom_css_array( (array) $exclude_ref_names ); |
| 1012 | $css_string = ''; |
| 1013 | |
| 1014 | $sep_comment = apply_filters( 'auxin_custom_css_sep_comment', "/* %s \n=========================*/\n" ); |
| 1015 | |
| 1016 | // Convert the contents in array to string |
| 1017 | if( is_array( $css_array ) ){ |
| 1018 | foreach ( $css_array as $node_ref => $node_content ) { |
| 1019 | if( ! is_numeric( $node_ref) ){ |
| 1020 | $css_string .= sprintf( $sep_comment, str_replace( '_', '-', $node_ref ) ); |
| 1021 | } |
| 1022 | $css_string .= "$node_content\n"; |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | // Remove <style> if user used them in the style content |
| 1027 | return str_replace( array( "<style>", "</style>" ), array('', ''), $css_string ); |
| 1028 | } |
| 1029 | |
| 1030 | |
| 1031 | /** |
| 1032 | * Extract numbers from string |
| 1033 | * |
| 1034 | * @param string $str The string that contains numbers |
| 1035 | * @param int $default The number which should be returned if no number found in the string |
| 1036 | * @return int The extracted numbers |
| 1037 | */ |
| 1038 | function auxin_get_numerics( $str, $default = null ) { |
| 1039 | if( empty( $str ) ){ |
| 1040 | return is_numeric( $default ) ? $default: ''; |
| 1041 | } |
| 1042 | preg_match('/\d+/', $str, $matches); |
| 1043 | return $matches[0]; |
| 1044 | } |
| 1045 | |
| 1046 | |
| 1047 | /** |
| 1048 | * Prints JS variable |
| 1049 | * |
| 1050 | * @param string $object_name The object or variable name |
| 1051 | * @param array $object_value The object value |
| 1052 | */ |
| 1053 | function auxin_print_script_object( $object_name, $object_value = array() ){ |
| 1054 | |
| 1055 | if( empty( $object_name ) ){ |
| 1056 | _doing_it_wrong( __FUNCTION__, 'The object name cannot be empty' ); |
| 1057 | return; |
| 1058 | } |
| 1059 | // remove unespected chars |
| 1060 | $object_name = trim( $object_name, '.' ); |
| 1061 | |
| 1062 | if( false !== strpos( $object_name, '.') ){ |
| 1063 | $script = sprintf( 'auxinNS("%1$s"); %1$s=%2$s;', esc_js( $object_name ), wp_json_encode( $object_value ) ); |
| 1064 | } else { |
| 1065 | $script = sprintf( 'var %1$s=%2$s;', esc_js( $object_name ), wp_json_encode( $object_value ) ); |
| 1066 | } |
| 1067 | |
| 1068 | echo $script ? '<script>'. $script .'</script>' : ''; |
| 1069 | } |
| 1070 | |
| 1071 | /*-----------------------------------------------------------------------------------*/ |
| 1072 | /* Returns post type menu name |
| 1073 | /*-----------------------------------------------------------------------------------*/ |
| 1074 | |
| 1075 | if( ! function_exists( 'auxin_get_post_type_name' ) ){ |
| 1076 | |
| 1077 | // returns post type menu name |
| 1078 | function auxin_get_post_type_name( $post_type = '' ){ |
| 1079 | $post_type = empty( $post_type ) ? get_post_type() : $post_type; |
| 1080 | $post_type_obj = get_post_type_object( $post_type ); |
| 1081 | |
| 1082 | return apply_filters( 'auxin_get_post_type_name', $post_type_obj->labels->menu_name, $post_type ); |
| 1083 | } |
| 1084 | |
| 1085 | } |
| 1086 | |
| 1087 | /** |
| 1088 | * Generates and retrieves a random token |
| 1089 | * |
| 1090 | * @param integer $length The token length |
| 1091 | * @return strinf The random token |
| 1092 | */ |
| 1093 | function auxin_random_token( $length = 32 ){ |
| 1094 | $length = ! is_numeric( $length ) ? 4 : $length; |
| 1095 | $length = $length < 1 ? 32 : $length; |
| 1096 | |
| 1097 | if ( function_exists('random_bytes') ) { |
| 1098 | return bin2hex(random_bytes( $length )); |
| 1099 | } |
| 1100 | if (function_exists('mcrypt_create_iv')) { |
| 1101 | return bin2hex(mcrypt_create_iv( $length, MCRYPT_DEV_URANDOM )); |
| 1102 | } |
| 1103 | if ( function_exists('openssl_random_pseudo_bytes') ) { |
| 1104 | return bin2hex(openssl_random_pseudo_bytes( $length )); |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | |
| 1109 | /*-----------------------------------------------------------------------------------*/ |
| 1110 | /* A function to generate header and footer for all widgets |
| 1111 | /*-----------------------------------------------------------------------------------*/ |
| 1112 | |
| 1113 | function auxin_get_widget_scafold( $atts, $default_atts, $shortcode_content = '' ){ |
| 1114 | |
| 1115 | $result = array( |
| 1116 | 'parsed_atts' => '', |
| 1117 | 'widget_info' => '', |
| 1118 | 'widget_header' => '', |
| 1119 | 'widget_title' => '', |
| 1120 | 'widget_footer' => '', |
| 1121 | 'ajax_data' => '' |
| 1122 | ); |
| 1123 | |
| 1124 | // ---- |
| 1125 | if( ! isset( $default_atts['extra_classes'] ) ){ |
| 1126 | $default_atts['extra_classes'] = ''; |
| 1127 | } |
| 1128 | if( ! isset( $default_atts['custom_el_id'] ) ){ |
| 1129 | $default_atts['custom_el_id'] = ''; |
| 1130 | } |
| 1131 | if( ! isset( $default_atts['content'] ) ){ |
| 1132 | $default_atts['content'] = ''; |
| 1133 | } |
| 1134 | if( empty( $default_atts['universal_id'] ) ){ |
| 1135 | $default_atts['universal_id'] = 'au'.auxin_random_token(4); |
| 1136 | } |
| 1137 | if( ! isset( $default_atts['skip_wrappers'] ) ){ |
| 1138 | $default_atts['skip_wrappers'] = false; |
| 1139 | } |
| 1140 | if( ! isset( $default_atts['loadmore_type'] ) ){ |
| 1141 | $default_atts['loadmore_type'] = ''; |
| 1142 | } |
| 1143 | if( ! isset( $default_atts['base'] ) ){ |
| 1144 | $default_atts['base'] = ''; |
| 1145 | } |
| 1146 | // prevent nested query while placing a recent posts widget in the same post |
| 1147 | if( isset( $atts['exclude'] ) ){ |
| 1148 | global $post; |
| 1149 | $atts['exclude'] .= ',' . $post->ID; |
| 1150 | } |
| 1151 | |
| 1152 | // Widget general info |
| 1153 | $before_widget = $after_widget = ''; |
| 1154 | $before_title = $after_title = ''; |
| 1155 | |
| 1156 | // If widget info is passed, extract them in above variables |
| 1157 | if( isset( $atts['widget_info'] ) ){ |
| 1158 | $result['widget_info'] = $atts['widget_info']; |
| 1159 | extract( $atts['widget_info'] ); |
| 1160 | } |
| 1161 | // CSS class names for section ------------- |
| 1162 | |
| 1163 | // The default CSS classes for widget container |
| 1164 | // Note that 'widget-container' should be in all element |
| 1165 | $_css_classes = array( 'widget-container' ); |
| 1166 | |
| 1167 | // Parse shortcode attributes |
| 1168 | $parsed_atts = shortcode_atts( $default_atts, $atts, __FUNCTION__ ); |
| 1169 | |
| 1170 | if( empty( $parsed_atts['content'] ) ){ |
| 1171 | $parsed_atts['content'] = $shortcode_content; |
| 1172 | } |
| 1173 | if( empty( $parsed_atts['loadmore_per_page'] ) ){ |
| 1174 | $parsed_atts['loadmore_per_page'] = ! empty( $parsed_atts['num'] ) ? $parsed_atts['num'] : 12; |
| 1175 | } |
| 1176 | |
| 1177 | $result['parsed_atts'] = $parsed_atts; |
| 1178 | |
| 1179 | // make the result params filterable prior to generating markup variables |
| 1180 | $result = apply_filters( 'auxin_pre_widget_scafold_params', $result, $atts, $default_atts, $shortcode_content ); |
| 1181 | |
| 1182 | if( $result['parsed_atts']['skip_wrappers'] ){ |
| 1183 | return $result; |
| 1184 | } |
| 1185 | |
| 1186 | if( ! empty( $result['parsed_atts']['loadmore_type'] ) ){ |
| 1187 | |
| 1188 | if( empty( $result['parsed_atts']["base"] ) ){ |
| 1189 | _doing_it_wrong( __FUNCTION__, 'For using ajax load more feature, "base" parameter in element default attributes is required.' ); |
| 1190 | } |
| 1191 | |
| 1192 | // Enqueue wp-mediaelement |
| 1193 | wp_enqueue_style ( 'wp-mediaelement' ); |
| 1194 | wp_enqueue_script( 'wp-mediaelement' ); |
| 1195 | |
| 1196 | $ajax_args = $result['parsed_atts']; |
| 1197 | |
| 1198 | // remove redundant ajax args |
| 1199 | unset( $ajax_args['base'] ); |
| 1200 | unset( $ajax_args['base_class'] ); |
| 1201 | unset( $ajax_args['use_wp_query'] ); |
| 1202 | |
| 1203 | // force the element not to render wrappers for ajax handler |
| 1204 | $ajax_args['skip_wrappers'] = true; |
| 1205 | |
| 1206 | $result['ajax_data'] = array( |
| 1207 | 'nonce' => wp_create_nonce('auxin_front_load_more'), |
| 1208 | 'args' => $ajax_args, |
| 1209 | 'handler' => $result['parsed_atts']["base"], |
| 1210 | 'per_page'=> $parsed_atts['loadmore_per_page'] |
| 1211 | ); |
| 1212 | |
| 1213 | $_css_classes[] = 'aux-ajax-type-' . $result['parsed_atts']['loadmore_type']; |
| 1214 | } |
| 1215 | |
| 1216 | // Defining extra class names -------------- |
| 1217 | |
| 1218 | // Add extra class names to class list here - widget-{element_name} |
| 1219 | $_css_classes[] = $result['parsed_atts']['base_class']; |
| 1220 | |
| 1221 | $_css_classes[] = 'aux-parent-' . $result['parsed_atts']['universal_id']; |
| 1222 | |
| 1223 | |
| 1224 | $_widget_classes = auxin_merge_css_classes( $_css_classes, $result['parsed_atts']['extra_classes'] ); |
| 1225 | $_widget_classes = esc_attr( trim( join( ' ', array_unique( $_widget_classes ) ) ) ); |
| 1226 | |
| 1227 | // Generate the opening tags for widget or shortcode element |
| 1228 | if( $before_widget ){ |
| 1229 | |
| 1230 | $result['widget_header'] .= str_replace( |
| 1231 | array( 'class="', '<div'), |
| 1232 | array( 'class="'.$_widget_classes.' ', '<section' ), |
| 1233 | $before_widget |
| 1234 | ); |
| 1235 | } elseif ( !empty($result['parsed_atts']['custom_el_id']) ){ |
| 1236 | $result['widget_header'] .= sprintf('<section id="%s" class="%s">', $result['parsed_atts']['custom_el_id'], $_widget_classes ); |
| 1237 | } else { |
| 1238 | $result['widget_header'] .= sprintf('<section class="%s">', $_widget_classes ); |
| 1239 | } |
| 1240 | |
| 1241 | // Generate the title for widget or shortcode element |
| 1242 | if( ! empty( $result['parsed_atts']['title'] ) ){ |
| 1243 | if( $before_title ){ |
| 1244 | $result['widget_title'] .= $before_title . $result['parsed_atts']['title'] . $after_title; |
| 1245 | } elseif( ! empty( $result['parsed_atts']['title'] ) ){ |
| 1246 | $result['widget_title'] .= '<h3 class="widget-title">'. $result['parsed_atts']['title'] .'</h3>'; |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | // Generate the close tags for widget or shortcode element |
| 1251 | if( $after_widget ){ |
| 1252 | // fix for the difference in end tag in siteorigin page builder |
| 1253 | $result['widget_footer'] .= str_replace( '</div', '</section', $after_widget ); |
| 1254 | } else { |
| 1255 | $result['widget_footer'] .= '</section><!-- widget-container -->'; |
| 1256 | } |
| 1257 | |
| 1258 | // Enable filtering the result variable |
| 1259 | $result = apply_filters( 'auxin_widget_scafold_params', $result, $atts, $default_atts, $shortcode_content ); |
| 1260 | |
| 1261 | // Prints the javascript variable if load more is enabled |
| 1262 | // We can modify the ajax args using "auxin_widget_scafold_params" filter |
| 1263 | if( ! empty( $result['parsed_atts']['loadmore_type'] ) ){ |
| 1264 | // echo js dependencies |
| 1265 | auxin_print_script_object( "auxin.content.loadmore." . $result['parsed_atts']['universal_id'], $result['ajax_data'] ); |
| 1266 | } |
| 1267 | |
| 1268 | return $result; |
| 1269 | } |
| 1270 | |
| 1271 | |
| 1272 | /*----------------------------------------------------------------------------*/ |
| 1273 | /* Retrieves remote data |
| 1274 | /*----------------------------------------------------------------------------*/ |
| 1275 | |
| 1276 | /** |
| 1277 | * Retrieves a URL using the HTTP POST method |
| 1278 | * |
| 1279 | * @return mixed|boolean The body content |
| 1280 | */ |
| 1281 | function auxin_remote_post( $url, $args ) { |
| 1282 | $request = wp_remote_post( $url, $args ); |
| 1283 | |
| 1284 | if ( ! is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ) { |
| 1285 | return $request['body']; |
| 1286 | } |
| 1287 | return false; |
| 1288 | } |
| 1289 | |
| 1290 | /** |
| 1291 | * Retrieves a URL using the HTTP GET method |
| 1292 | * |
| 1293 | * @return mixed|boolean The body content |
| 1294 | */ |
| 1295 | function auxin_remote_get( $url, $args ) { |
| 1296 | $request = wp_remote_get( $url, $args ); |
| 1297 | |
| 1298 | if ( ! is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ) { |
| 1299 | return $request['body']; |
| 1300 | } |
| 1301 | return false; |
| 1302 | } |
| 1303 | |
| 1304 | /*----------------------------------------------------------------------------*/ |
| 1305 | /* Removes a class method from a specified filter hook. |
| 1306 | /*----------------------------------------------------------------------------*/ |
| 1307 | |
| 1308 | if( ! function_exists( 'auxin_remove_filter_from_class' ) ){ |
| 1309 | |
| 1310 | /** |
| 1311 | * Removes a class method from a specified filter hook. |
| 1312 | * |
| 1313 | * @param string $hook_name The filter hook to which the function to be removed is hooked |
| 1314 | * @param string $class_name The name of class which its method should be removed. |
| 1315 | * @param string $method_name The name of the method which should be removed. |
| 1316 | * @param integer $priority Optional. The priority of the function. Default 10. |
| 1317 | * @return bool Whether the function existed before it was removed. |
| 1318 | */ |
| 1319 | function auxin_remove_filter_from_class( $hook_name = '', $class_name ='', $method_name = '', $priority = 10 ) { |
| 1320 | global $wp_filter; |
| 1321 | |
| 1322 | // Take only filters on right hook name and priority |
| 1323 | if ( !isset($wp_filter[$hook_name][$priority]) || !is_array($wp_filter[$hook_name][$priority]) ) |
| 1324 | return false; |
| 1325 | |
| 1326 | // Loop on filters registered |
| 1327 | foreach( (array) $wp_filter[$hook_name][$priority] as $unique_id => $filter_array ) { |
| 1328 | // Test if filter is an array ! (always for class/method) |
| 1329 | if ( isset($filter_array['function']) && is_array($filter_array['function']) ) { |
| 1330 | // Test if object is a class, class and method is equal to param ! |
| 1331 | 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 ) { |
| 1332 | unset($wp_filter[$hook_name][$priority][$unique_id]); |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | } |
| 1337 | |
| 1338 | return false; |
| 1339 | } |
| 1340 | |
| 1341 | } |
| 1342 | |
| 1343 | |
| 1344 | if( ! function_exists( 'auxin_remove_action_from_class' ) ){ |
| 1345 | |
| 1346 | /** |
| 1347 | * Removes a class method from a specified filter hook. |
| 1348 | * |
| 1349 | * @param string $hook_name The filter hook to which the function to be removed is hooked |
| 1350 | * @param string $class_name The name of class which its method should be removed. |
| 1351 | * @param string $method_name The name of the method which should be removed. |
| 1352 | * @param integer $priority Optional. The priority of the function. Default 10. |
| 1353 | * @return bool Whether the function existed before it was removed. |
| 1354 | */ |
| 1355 | function auxin_remove_action_from_class( $hook_name = '', $class_name ='', $method_name = '', $priority = 10 ) { |
| 1356 | global $wp_action; |
| 1357 | |
| 1358 | // Take only filters on right hook name and priority |
| 1359 | if ( !isset($wp_action[$hook_name][$priority]) || !is_array($wp_action[$hook_name][$priority]) ) |
| 1360 | return false; |
| 1361 | |
| 1362 | // Loop on filters registered |
| 1363 | foreach( (array) $wp_action[$hook_name][$priority] as $unique_id => $filter_array ) { |
| 1364 | // Test if filter is an array ! (always for class/method) |
| 1365 | if ( isset($filter_array['function']) && is_array($filter_array['function']) ) { |
| 1366 | // Test if object is a class, class and method is equal to param ! |
| 1367 | 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 ) { |
| 1368 | unset($wp_action[$hook_name][$priority][$unique_id]); |
| 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | } |
| 1373 | |
| 1374 | return false; |
| 1375 | } |
| 1376 | |
| 1377 | } |
| 1378 | |
| 1379 | |
| 1380 | |
| 1381 | /*-----------------------------------------------------------------------------------*/ |
| 1382 | /* Auxin Load More |
| 1383 | /*-----------------------------------------------------------------------------------*/ |
| 1384 | |
| 1385 | /** |
| 1386 | * A callback for Auxin Load More functionality |
| 1387 | * |
| 1388 | * @return string |
| 1389 | */ |
| 1390 | function auxin_get_load_more_controller( $type ) { |
| 1391 | // Return null when loadmore type is empty |
| 1392 | if ( empty( $type ) ) return; |
| 1393 | // Check load more type |
| 1394 | if ( $type == "next-prev" ) { |
| 1395 | return ' |
| 1396 | <div class="aux-ajax-controller"> |
| 1397 | <nav class="aux-next-prev-posts nav-skin-minimal"> |
| 1398 | <section class="aux-load-next-prev hidden np-prev-section"> |
| 1399 | <div class="np-arrow"> |
| 1400 | <div class="aux-arrow-nav aux-hover-slide aux-round aux-outline aux-medium"> |
| 1401 | <span class="aux-overlay"></span> |
| 1402 | <span class="aux-svg-arrow aux-medium-left"></span> |
| 1403 | <span class="aux-hover-arrow aux-svg-arrow aux-medium-left aux-white"></span> |
| 1404 | </div> |
| 1405 | </div> |
| 1406 | <p class="np-nav-text">'.__('Previous', 'auxin-elements').'</p> |
| 1407 | <h4 class="np-title">'.__('page', 'auxin-elements').'</h4> |
| 1408 | </section> |
| 1409 | <section class="aux-load-next-prev np-next-section"> |
| 1410 | <div class="np-arrow"> |
| 1411 | <div class="aux-arrow-nav aux-hover-slide aux-round aux-outline aux-medium"> |
| 1412 | <span class="aux-overlay"></span> |
| 1413 | <span class="aux-svg-arrow aux-medium-right"></span> |
| 1414 | <span class="aux-hover-arrow aux-svg-arrow aux-medium-right aux-white"></span> |
| 1415 | </div> |
| 1416 | </div> |
| 1417 | <p class="np-nav-text">'.__('Next', 'auxin-elements').'</p> |
| 1418 | <h4 class="np-title">'.__('Page', 'auxin-elements').'</h4> |
| 1419 | </section> |
| 1420 | |
| 1421 | </nav> |
| 1422 | </div>'; |
| 1423 | |
| 1424 | } elseif ( $type == "scroll" || $type == "next" ) { |
| 1425 | |
| 1426 | return ' |
| 1427 | <div class="aux-ajax-controller"> |
| 1428 | <nav class="aux-load-more center"> |
| 1429 | <svg class="aux-circle" width="100%" height="100%" viewBox="0 0 102 102"> |
| 1430 | <circle class="aux-progress" r="50" cx="51" cy="51" fill="none" transform="rotate(-90 51 51)"></circle> |
| 1431 | </svg> |
| 1432 | <div class="aux-label-text">'.__('LOAD MORE', 'auxin-elements').'</div> |
| 1433 | <span class="aux-loading-label">'.__('LOADING', 'auxin-elements').'</span> |
| 1434 | </nav> |
| 1435 | </div>'; |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | |
| 1440 | /*-----------------------------------------------------------------------------------*/ |
| 1441 | /* A function to get the custom style of Google maps |
| 1442 | /*-----------------------------------------------------------------------------------*/ |
| 1443 | |
| 1444 | if ( ! function_exists( 'auxin_get_gmap_style' ) ) { |
| 1445 | |
| 1446 | function auxin_get_gmap_style () { |
| 1447 | |
| 1448 | $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"}]}]'; |
| 1449 | |
| 1450 | return apply_filters( 'auxin_gmap_style', $styler ); |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | |
| 1455 | function auxin_get_header_button( $button_id_num = 1 ){ |
| 1456 | |
| 1457 | if( empty( $button_id_num ) || ! is_numeric( $button_id_num ) ){ |
| 1458 | _doing_it_wrong( __FUNCTION__, "A numeric buttom id is required." ); |
| 1459 | } |
| 1460 | if( ! auxin_get_option( "site_header_show_btn" . $button_id_num ) ){ |
| 1461 | return ''; |
| 1462 | } |
| 1463 | |
| 1464 | return auxin_widget_button_callback( |
| 1465 | array( |
| 1466 | 'label' => auxin_get_option( 'site_header_btn'. $button_id_num .'_label' ), |
| 1467 | 'size' => auxin_get_option( 'site_header_btn'. $button_id_num .'_size', 'large' ), |
| 1468 | 'border' => auxin_get_option( 'site_header_btn'. $button_id_num .'_shape' ), |
| 1469 | 'style' => auxin_get_option( 'site_header_btn'. $button_id_num .'_style' ), |
| 1470 | 'dark' => auxin_get_option( 'site_header_btn'. $button_id_num .'_darken', 0 ), |
| 1471 | 'icon' => auxin_get_option( 'site_header_btn'. $button_id_num .'_icon' ), |
| 1472 | 'icon_align' => auxin_get_option( 'site_header_btn'. $button_id_num .'_icon_align' ), |
| 1473 | 'color_name' => auxin_get_option( 'site_header_btn'. $button_id_num .'_color_name' ), |
| 1474 | 'link' => auxin_get_option( 'site_header_btn'. $button_id_num .'_link', "#" ), |
| 1475 | 'target' => auxin_get_option( 'site_header_btn'. $button_id_num .'_target' ), |
| 1476 | 'uppercase' => '0', |
| 1477 | 'extra_classes' => 'aux-ac-btn'. $button_id_num |
| 1478 | ) |
| 1479 | ); |
| 1480 | } |
| 1481 | |
| 1482 | |
| 1483 | /** |
| 1484 | * Removes all generate images from uploads directory |
| 1485 | * |
| 1486 | * @return void |
| 1487 | */ |
| 1488 | function auxin_remove_all_generate_images( $remove = true ){ |
| 1489 | if( is_multisite() ){ |
| 1490 | return; |
| 1491 | } |
| 1492 | $upload_dir = wp_get_upload_dir(); |
| 1493 | |
| 1494 | $all_images = auxin_find_all_files( $upload_dir['basedir'] ); |
| 1495 | $generated_images = array(); |
| 1496 | |
| 1497 | foreach( $all_images as $key => $file ) { |
| 1498 | if( 1 == preg_match("#-(\d+)x(\d+).(png|jpg|bmp|gif)$#", $file) ) { |
| 1499 | $generated_images[] = $file; |
| 1500 | if( $remove ){ |
| 1501 | unlink( $file ); |
| 1502 | } |
| 1503 | } |
| 1504 | } |
| 1505 | echo count( $all_images ) . " / " . count( $generated_images ); |
| 1506 | } |
| 1507 | |
| 1508 | /** |
| 1509 | * Find all files within a directory |
| 1510 | * |
| 1511 | * @param string $dir The directory which we intend to serach in |
| 1512 | * @return array List of files |
| 1513 | */ |
| 1514 | function auxin_find_all_files( $dir, $recursive = true ){ |
| 1515 | $root = scandir( $dir ); |
| 1516 | $result = array(); |
| 1517 | |
| 1518 | foreach( $root as $file ){ |
| 1519 | if( $file === '.' || $file === '..') { |
| 1520 | continue; |
| 1521 | } |
| 1522 | if( is_file( "$dir/$file" ) ){ |
| 1523 | $result[] = "$dir/$file"; |
| 1524 | continue; |
| 1525 | } elseif( $recursive && is_dir( "$dir/$file" ) ){ |
| 1526 | $sub_dir_files = auxin_find_all_files( "$dir/$file" ); |
| 1527 | $result = array_merge( $result, $sub_dir_files ); |
| 1528 | } |
| 1529 | } |
| 1530 | return $result; |
| 1531 | } |
| 1532 | |
| 1533 |