PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.17.14
Shortcodes and extra features for Phlox theme v2.17.14
2.17.21 2.17.20 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.6 1.0.9 1.1.0 1.3.0 1.3.1 1.3.10 1.3.14 1.3.2 1.3.3 1.3.6 1.4.0 1.4.1 1.4.2 1.5.0 1.5.2 1.6.0 1.6.2 1.6.4 1.7.0 1.7.2 2.10.0 2.10.1 2.10.3 2.10.5 2.10.7 2.10.8 2.10.9 2.11.0 2.11.1 2.11.2 2.12.0 2.14.0 2.15.0 2.15.2 2.15.4 2.15.5 2.15.6 2.15.7 2.15.8 2.15.9 2.16.0 2.16.1 2.16.2 2.16.3 2.16.4 2.17.0 2.17.1 2.17.12 2.17.13 2.17.14 2.17.15 2.17.16 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.8 2.17.9 2.4.12 2.4.13 2.4.14 2.4.16 2.4.18 2.4.19 2.4.9 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.17 2.5.19 2.5.2 2.5.20 2.5.3 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.10 2.6.12 2.6.13 2.6.14 2.6.15 2.6.16 2.6.17 2.6.19 2.6.2 2.6.20 2.6.4 2.6.5 2.6.7 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.9 2.9.0 2.9.12 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.19 2.9.2 2.9.20 2.9.21 2.9.22 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8
auxin-elements / includes / general-functions.php
auxin-elements / includes Last commit date
classes 6 months ago compatibility 11 months ago elementor 6 months ago elements 6 months ago define.php 6 months ago general-functions.php 11 months ago general-hooks.php 1 year ago general-shortcodes.php 2 years ago index.php 3 years ago
general-functions.php
2593 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-2025 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 esc_attr( $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' ), esc_html( $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 wp_kses_post( $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(wp_strip_all_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( $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( $index, $column_media_width, $pattern = 'default' ) {
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 = wp_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', wp_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', wp_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>'. wp_kses_post( $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 wp_delete_file( $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 * Get All Pages Id and Title
1859 * Used for Customizer Options for 404 ,Maintance and Coming soon Section
1860 * @return array
1861 */
1862 function auxin_get_all_pages() {
1863
1864 $pages = array();
1865 $args = array(
1866 'post_type' => 'page',
1867 'post_status' => 'publish',
1868 'posts_per_page' => -1
1869 );
1870
1871 $pages['default'] = __( 'Theme Default', 'auxin-elements' ) ; // Default Page For 404, Maintance , And Coming Soon
1872
1873 $pages_array = get_posts( $args );
1874
1875 foreach ( $pages_array as $page ) {
1876 $pages[ $page->ID ] = $page->post_title ;
1877 }
1878
1879 return $pages;
1880 }
1881
1882 /**
1883 * Get the size of numeric controls
1884 *
1885 * @param string|array $value The controller value
1886 * @return int The size
1887 */
1888 function auxin_get_control_size( $value ){
1889 return isset( $value['size'] ) ? $value['size'] : $value;
1890 }
1891
1892 /**
1893 * Change search uery based on options
1894 *
1895 * @param object $query A WP_Query object
1896 * @return object $query
1897 */
1898 function auxin_custom_search_results( $query ) {
1899
1900 if ( ! is_admin() && $query->is_main_query() ) {
1901 if ($query->is_search) {
1902
1903 $all_post_types = get_post_types( array( 'public' => true, 'exclude_from_search' => false ) );
1904
1905 $excluded_post_types = (array) auxin_get_option( 'auxin_search_exclude_post_types', array() );
1906
1907 $post_types = array_diff( $all_post_types , $excluded_post_types );
1908
1909 $posts_in = auxin_get_option( 'auxin_search_pinned_contents', '' );
1910
1911 $query->set( 'post_type', $post_types );
1912
1913 $query->set( 'post__in' , $posts_in );
1914
1915 if ( auxin_get_option( 'auxin_search_exclude_no_media' ) ) {
1916 $query->set( 'meta_query', array(array('key' => '_thumbnail_id')) );
1917 }
1918
1919 }
1920 }
1921 return $query;
1922
1923 }
1924
1925 add_filter( 'pre_get_posts', 'auxin_custom_search_results' );
1926
1927 /**
1928 * Page Cover Markup
1929 */
1930
1931 function auxin_cover() {
1932 global $post;
1933
1934 ob_start();
1935 if ( auxin_is_true( auxin_get_post_meta( $post, 'display_page_header_cover', false ) ) ) {
1936 $cover_image = auxin_get_post_meta( $post, 'page_header_cover_image', '' );
1937 $image = auxin_get_the_responsive_attachment( $cover_image,
1938 array(
1939 'quality' => 100,
1940 'preloadable' => false,
1941 'preload_preview' => false,
1942 'size' => 'full',
1943 'crop' => true,
1944 'add_hw' => true,
1945 'attr' => array( 'data-object-fit' => 'cover', 'class' => 'auxin-page-cover-image' )
1946 )
1947 );
1948 $cover_title = auxin_get_post_meta( $post, 'page_header_cover_title', '' );
1949 $discover_text = auxin_get_post_meta( $post, 'page_header_discover_text', '' );
1950 ?>
1951 <div class="aux-page-cover-wrapper">
1952 <?php echo wp_kses_post( $image ) ;?>
1953 <?php
1954 if ( ! empty ( $cover_title ) ) { ?>
1955 <div class="aux-page-cover-content">
1956 <?php echo wp_kses_post( $cover_title );?>
1957 </div>
1958 <?php }
1959 ?>
1960 <div class="aux-page-cover-footer">
1961 <div class="aux-page-cover-footer-text">
1962 <a href="#" title="<?php echo esc_attr( $discover_text ); ?>"><?php echo wp_kses_post( $discover_text ) ?></a>
1963 </div>
1964 </div>
1965 </div>
1966 <?php }
1967
1968 echo ob_get_clean();
1969
1970 }
1971
1972 add_action( 'auxin_after_body_open', 'auxin_cover' );
1973
1974 /**
1975 * Strpos search in array
1976 * @return boolean
1977 */
1978 function auxin_strposa( $haystack, $needle, $offset = 0 ) {
1979 if( ! is_array( $needle ) ) {
1980 $needle = array($needle);
1981 }
1982 foreach($needle as $query) {
1983 if( strpos( $haystack, $query, $offset ) !== false ) {
1984 return true; // stop on first true result
1985 }
1986 }
1987 return false;
1988 }
1989
1990 /**
1991 * Return preloadable options
1992 * @return arraqy
1993 */
1994 function auxin_get_preloadable_previews(){
1995 return apply_filters( 'auxin_get_preloadable_previews', array(
1996 'no' => __('Blank', 'auxin-elements' ),
1997 'yes' => __('Blurred placeholder image', 'auxin-elements' ),
1998 'progress-box' => __('In-progress box animation', 'auxin-elements' ),
1999 'simple-spinner' => __('Loading spinner (blue)', 'auxin-elements' ),
2000 'simple-spinner-light' => __('Loading spinner (light)', 'auxin-elements' ),
2001 'simple-spinner-dark' => __('Loading spinner (dark)', 'auxin-elements' )
2002 ) );
2003 }
2004
2005 /**
2006 * Check purchase activation status
2007 *
2008 * @return void
2009 */
2010 function auxin_is_activated(){
2011 // A temporary code to update the old license value
2012 if( ! get_site_option( THEME_ID . '_license_update', false ) ){
2013 $getLicense = get_option( THEME_ID . '_license' );
2014 $getLicense = empty( $getLicense ) ? get_option( AUXELS_PURCHASE_KEY ) : $getLicense;
2015 update_site_option( AUXELS_PURCHASE_KEY, $getLicense );
2016 update_site_option( THEME_ID . '_license_update', true );
2017 }
2018
2019 $getLicense = get_site_option( THEME_ID . '_license' );
2020 $getLicense = empty( $getLicense ) ? get_site_option( AUXELS_PURCHASE_KEY ) : $getLicense;
2021 $isPro = defined('THEME_PRO' ) && THEME_PRO;
2022 if( $isPro && ( isset( $getLicense['token'] ) && ! empty( $getLicense['token'] ) ) ){
2023 // Check token validation every 24 hours
2024 $key = sanitize_key( 'auxin_check_token_validation_status' );
2025 if ( false === $token_status = auxin_get_transient( $key ) ) {
2026 $token_validation = Auxin_License_Activation::get_instance()->maybe_invalid_token();
2027 $token_status = isset( $token_validation['allowed'] ) ? $token_validation['allowed']: 0;
2028 // Add transient
2029 auxin_set_transient( $key, $token_status , 2 * DAY_IN_SECONDS );
2030 }
2031 return $token_status;
2032 }
2033 return false;
2034 }
2035
2036 /**
2037 * Get recent comments query
2038 *
2039 * @param array $args
2040 * @return array
2041 */
2042 function auxin_get_comments( $args = array() ){
2043 // The Query
2044 $comments_query = new WP_Comment_Query;
2045 $comments = $comments_query->query( $args );
2046 return $comments;
2047 }
2048
2049 /**
2050 * Return elementor header template
2051 *
2052 * @return void
2053 */
2054 function auxin_get_header_template(){
2055 global $post;
2056
2057 $template_ID = auxin_get_option( 'site_elementor_header_template', '' );
2058 $template_ID = ( ! empty( auxin_get_post_meta( $post, 'page_elementor_header_template' ) ) && auxin_get_post_meta($post , 'page_header_use_legacy' ) !== 'default' ) ?
2059 auxin_get_post_meta( $post, 'page_elementor_header_template' ) : $template_ID ;
2060 // get translated template if wpml enabled
2061 $template_ID = ( function_exists( 'icl_object_id' ) && defined( 'ICL_LANGUAGE_CODE' ) ) ? icl_object_id( $template_ID, 'elementor_library', true, ICL_LANGUAGE_CODE ) : $template_ID;
2062
2063 $attrs = [
2064 'class' => ['aux-elementor-header'],
2065 'id' => 'site-elementor-header',
2066 'itemscope' => 'itemscope',
2067 'itemtype' => 'https://schema.org/WPHeader',
2068 ];
2069
2070 if ( 'default' === $overlay_header = auxin_get_post_meta( $post, 'page_overlay_header', 'default' ) ) {
2071 $overlay_header = auxin_get_option('site_overlay_header');
2072 }
2073
2074 if ( 'default' === $attributes['data-sticky-height'] = auxin_get_post_meta( $post, 'page_header_container_scaled_height', 'default' ) ) {
2075 $attrs['data-sticky-height'] = auxin_get_option( 'site_header_container_scaled_height','60' );
2076 }
2077
2078 if ( auxin_is_true ( $overlay_header ) ) {
2079 array_push( $attrs['class'], 'aux-overlay-header' );
2080 }
2081
2082 if( isset( $template_ID ) && $template_ID !== ' ' && get_post_status( $template_ID ) ){
2083 ?>
2084 <header <?php echo auxin_make_html_attributes( $attrs ) ;?> >
2085 <div class="aux-wrapper">
2086 <div class="aux-header aux-header-elements-wrapper">
2087 <?php echo Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $template_ID ); ?>
2088 </div><!-- end of header-elements -->
2089 </div><!-- end of wrapper -->
2090 </header><!-- end header -->
2091 <?php
2092 }
2093 }
2094
2095 /**
2096 * Return elementor footer template
2097 *
2098 * @return void
2099 */
2100 function auxin_get_footer_template(){
2101 global $post;
2102
2103 $template_ID = auxin_get_option( 'site_elementor_footer_template', '' );
2104 $template_ID = ( ! empty( auxin_get_post_meta( $post, 'page_elementor_footer_template' ) ) && auxin_get_post_meta($post , 'page_footer_use_legacy' ) !== 'default' ) ?
2105 auxin_get_post_meta( $post, 'page_elementor_footer_template' ) : $template_ID ;
2106 // get translated template if wpml enabled
2107 $template_ID = ( function_exists( 'icl_object_id' ) && defined( 'ICL_LANGUAGE_CODE' ) ) ? icl_object_id( $template_ID, 'elementor_library', true, ICL_LANGUAGE_CODE ) : $template_ID;
2108
2109 $attrs = [
2110 'class' => ['aux-elementor-footer'],
2111 'itemscope' => 'itemscope',
2112 'itemtype' => 'https://schema.org/WPFooter',
2113 'role' => 'contentinfo'
2114 ];
2115
2116 if( isset( $template_ID ) && $template_ID !== ' ' && get_post_status( $template_ID ) ){
2117
2118 ?>
2119 <footer <?php echo auxin_make_html_attributes( $attrs ) ;?> >
2120 <div class="aux-wrapper">
2121 <?php echo Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $template_ID ); ?>
2122 </div><!-- end of wrapper -->
2123 </footer><!-- end footer -->
2124 <?php
2125 }
2126 }
2127
2128 /**
2129 * generate unique token for audit API
2130 *
2131 * @return void
2132 */
2133 function auxin_get_site_key(){
2134 $option_name = THEME_ID . '_' . 'audit_token';
2135 $site_key = get_option( $option_name );
2136
2137 if ( ! $site_key ) {
2138 $site_key = md5( uniqid( wp_generate_password() ) );
2139 update_option( $option_name, $site_key );
2140 }
2141
2142 return $site_key;
2143 }
2144
2145 /**
2146 * Whether a plugin is active or not
2147 *
2148 * @param string $plugin_basename plugin directory name and mail file address
2149 * @return bool True if plugin is active and FALSE otherwise
2150 */
2151 if( ! function_exists( 'auxin_is_plugin_active' ) ){
2152 function auxin_is_plugin_active( $plugin_basename ){
2153 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
2154 return is_plugin_active( $plugin_basename );
2155 }
2156 }
2157
2158 /**
2159 * Get public post type list
2160 *
2161 * @param array $args
2162 * @return array
2163 */
2164 function auxin_get_public_post_types( $args = array() ) {
2165 $post_type_args = [
2166 // Default is the value $public.
2167 'show_in_nav_menus' => true,
2168 ];
2169
2170 // Keep for backwards compatibility
2171 if ( ! empty( $args['post_type'] ) ) {
2172 $post_type_args['name'] = $args['post_type'];
2173 unset( $args['post_type'] );
2174 }
2175
2176 $post_type_args = wp_parse_args( $post_type_args, $args );
2177
2178 $_post_types = get_post_types( $post_type_args, 'objects' );
2179
2180 $post_types = [];
2181
2182 foreach ( $_post_types as $post_type => $object ) {
2183 $post_types[ $post_type ] = $object->label;
2184 }
2185
2186 return apply_filters( 'auxin/core_elements/get_public_post_types', $post_types );
2187 }
2188
2189
2190 /**
2191 * Print elementor template type on target location
2192 *
2193 * @param string $location
2194 * @return void
2195 */
2196 function auxin_theme_do_location( $location ) {
2197 $is_active = auxin_is_true( auxin_get_option( 'site_' . $location . '_override_template', false ) );
2198 $site_temp = auxin_get_option( 'site_' . $location . '_template', ' ' );
2199 $template = $site_temp !== ' ' ? get_page_by_path( $site_temp, OBJECT, 'elementor_library' ) : NULL;
2200 if( $is_active && ( isset( $template->ID ) && $template->ID !== NULL && get_post_status( $template->ID ) ) ){
2201 $document = new Auxin\Plugin\CoreElements\Elementor\Modules\ThemeBuilder\Classes\Locations_Manager();
2202 $document->do_location( $template->ID, $location );
2203 return true;
2204 }
2205
2206 return false;
2207 }
2208
2209 /**
2210 * get current page title
2211 *
2212 * @param boolean $include_context
2213 * @return string
2214 */
2215 function auxin_get_page_title( $include_context = true ) {
2216 $title = '';
2217
2218 if ( is_singular() ) {
2219 /* translators: %s: Search term. */
2220 $title = get_the_title();
2221
2222 if ( $include_context ) {
2223 $post_type_obj = get_post_type_object( get_post_type() );
2224 $title = sprintf( '%s: %s', $post_type_obj->labels->singular_name, $title );
2225 }
2226 } elseif ( is_search() ) {
2227 /* translators: %s: Search term. */
2228 $title = sprintf( __( 'Search Results for: %s', 'auxin-elements' ), get_search_query() );
2229
2230 if ( get_query_var( 'paged' ) ) {
2231 /* translators: %s is the page number. */
2232 $title .= sprintf( __( '&nbsp;&ndash; Page %s', 'auxin-elements' ), get_query_var( 'paged' ) );
2233 }
2234 } elseif ( is_category() ) {
2235 $title = single_cat_title( '', false );
2236
2237 if ( $include_context ) {
2238 /* translators: Category archive title. 1: Category name */
2239 $title = sprintf( __( 'Category: %s', 'auxin-elements' ), $title );
2240 }
2241 } elseif ( is_tag() ) {
2242 $title = single_tag_title( '', false );
2243 if ( $include_context ) {
2244 /* translators: Tag archive title. 1: Tag name */
2245 $title = sprintf( __( 'Tag: %s', 'auxin-elements' ), $title );
2246 }
2247 } elseif ( is_author() ) {
2248 $title = '<span class="vcard">' . get_the_author() . '</span>';
2249
2250 if ( $include_context ) {
2251 /* translators: Author archive title. 1: Author name */
2252 $title = sprintf( __( 'Author: %s', 'auxin-elements' ), $title );
2253 }
2254 } elseif ( is_year() ) {
2255 $title = get_the_date( _x( 'Y', 'yearly archives date format', 'auxin-elements' ) );
2256
2257 if ( $include_context ) {
2258 /* translators: Yearly archive title. 1: Year */
2259 $title = sprintf( __( 'Year: %s', 'auxin-elements' ), $title );
2260 }
2261 } elseif ( is_month() ) {
2262 $title = get_the_date( _x( 'F Y', 'monthly archives date format', 'auxin-elements' ) );
2263
2264 if ( $include_context ) {
2265 /* translators: Monthly archive title. 1: Month name and year */
2266 $title = sprintf( __( 'Month: %s', 'auxin-elements' ), $title );
2267 }
2268 } elseif ( is_day() ) {
2269 $title = get_the_date( _x( 'F j, Y', 'daily archives date format', 'auxin-elements' ) );
2270
2271 if ( $include_context ) {
2272 /* translators: Daily archive title. 1: Date */
2273 $title = sprintf( __( 'Day: %s', 'auxin-elements' ), $title );
2274 }
2275 } elseif ( is_tax( 'post_format' ) ) {
2276 if ( is_tax( 'post_format', 'post-format-aside' ) ) {
2277 $title = _x( 'Asides', 'post format archive title', 'auxin-elements' );
2278 } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
2279 $title = _x( 'Galleries', 'post format archive title', 'auxin-elements' );
2280 } elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
2281 $title = _x( 'Images', 'post format archive title', 'auxin-elements' );
2282 } elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
2283 $title = _x( 'Videos', 'post format archive title', 'auxin-elements' );
2284 } elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
2285 $title = _x( 'Quotes', 'post format archive title', 'auxin-elements' );
2286 } elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
2287 $title = _x( 'Links', 'post format archive title', 'auxin-elements' );
2288 } elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
2289 $title = _x( 'Statuses', 'post format archive title', 'auxin-elements' );
2290 } elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
2291 $title = _x( 'Audio', 'post format archive title', 'auxin-elements' );
2292 } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
2293 $title = _x( 'Chats', 'post format archive title', 'auxin-elements' );
2294 }
2295 } elseif ( is_post_type_archive() ) {
2296 $title = post_type_archive_title( '', false );
2297
2298 if ( $include_context ) {
2299 /* translators: Post type archive title. 1: Post type name */
2300 $title = sprintf( __( 'Archives: %s', 'auxin-elements' ), $title );
2301 }
2302 } elseif ( is_tax() ) {
2303 $title = single_term_title( '', false );
2304
2305 if ( $include_context ) {
2306 $tax = get_taxonomy( get_queried_object()->taxonomy );
2307 /* translators: Taxonomy term archive title. 1: Taxonomy singular name, 2: Current taxonomy term */
2308 $title = sprintf( __( '%1$s: %2$s', 'auxin-elements' ), $tax->labels->singular_name, $title );
2309 }
2310 } elseif ( is_404() ) {
2311 $title = __( 'Page Not Found', 'auxin-elements' );
2312 } // End if().
2313
2314 $title = apply_filters( 'auxin/core_elements/get_the_archive_title', $title );
2315
2316 return $title;
2317 }
2318
2319 /**
2320 * Get archive url
2321 *
2322 * @return string
2323 */
2324 function auxin_get_the_archive_url() {
2325 $url = '';
2326 if ( is_category() || is_tag() || is_tax() ) {
2327 $url = get_term_link( get_queried_object() );
2328 } elseif ( is_author() ) {
2329 $url = get_author_posts_url( get_queried_object_id() );
2330 } elseif ( is_year() ) {
2331 $url = get_year_link( get_query_var( 'year' ) );
2332 } elseif ( is_month() ) {
2333 $url = get_month_link( get_query_var( 'year' ), get_query_var( 'monthnum' ) );
2334 } elseif ( is_day() ) {
2335 $url = get_day_link( get_query_var( 'year' ), get_query_var( 'monthnum' ), get_query_var( 'day' ) );
2336 } elseif ( is_post_type_archive() ) {
2337 $url = get_post_type_archive_link( get_post_type() );
2338 }
2339
2340 return $url;
2341 }
2342
2343 /**
2344 * Set global author data
2345 *
2346 * @return void
2347 */
2348 function auxin_set_global_authordata() {
2349 global $authordata;
2350 if ( ! isset( $authordata->ID ) ) {
2351 $post = get_post();
2352 $authordata = get_userdata( $post->post_author );
2353 }
2354 }
2355
2356 /**
2357 * Used to overcome core bug when taxonomy is in more then one post type
2358 *
2359 * @param array $args
2360 * @param string $output
2361 * @param string $operator
2362 *
2363 * @return array
2364 */
2365 function auxin_get_taxonomies( $args = [], $output = 'names', $operator = 'and' ) {
2366 global $wp_taxonomies;
2367
2368 $field = ( 'names' === $output ) ? 'name' : false;
2369
2370 // Handle 'object_type' separately.
2371 if ( isset( $args['object_type'] ) ) {
2372 $object_type = (array) $args['object_type'];
2373 unset( $args['object_type'] );
2374 }
2375
2376 $taxonomies = wp_filter_object_list( $wp_taxonomies, $args, $operator );
2377
2378 if ( isset( $object_type ) ) {
2379 foreach ( $taxonomies as $tax => $tax_data ) {
2380 if ( ! array_intersect( $object_type, $tax_data->object_type ) ) {
2381 unset( $taxonomies[ $tax ] );
2382 }
2383 }
2384 }
2385
2386 if ( $field ) {
2387 $taxonomies = wp_list_pluck( $taxonomies, $field );
2388 }
2389
2390 return $taxonomies;
2391 }
2392
2393
2394 /**
2395 * Full Screen Search Results
2396 *
2397 */
2398 function auxin_search_page_results($post_type = 'post',$args = array()) {
2399 switch ($post_type) {
2400 case 'product':
2401
2402 if ( class_exists('AUXSHP') ) {
2403 $image_aspect_ratio = auxin_get_option( 'product_index_thumb_ratio', '1.33' );
2404 $args['image_aspect_ratio'] = $image_aspect_ratio == 'custom' ? (float) auxin_get_option( 'product_index_thumb_ratio_custom', '1' ) : $image_aspect_ratio;
2405 } else {
2406 $sizes = wc_get_image_size( 'woocommerce_thumbnail' );
2407 $args['image_aspect_ratio'] = $sizes['width']/$sizes['height'];
2408 }
2409
2410 echo auxin_widget_the_recent_products_callback($args);
2411 break;
2412
2413 case 'portfolio':
2414 $additional_args = array(
2415 'display_like' => 0,
2416 'display_title' => 0,
2417 'show_info' => 0,
2418 'paginate' => false
2419 );
2420 $args = wp_parse_args( $additional_args, $args );
2421 echo auxin_widget_recent_portfolios_grid_callback($args);
2422 break;
2423
2424 case 'news':
2425 $additional_args = array(
2426 'big_grid_style' => 'pattern-6',
2427 );
2428 $args = wp_parse_args( $additional_args, $args );
2429 echo auxin_widget_recent_news_big_grid_callback( $args );
2430 break;
2431
2432 default:
2433 echo auxin_widget_recent_posts_callback($args);
2434 break;
2435 }
2436
2437 }
2438
2439 /**
2440 * Used to create an image size if not exist
2441 *
2442 * @param int $attachment_id
2443 * @param string $size
2444 *
2445 * @return void
2446 */
2447
2448 function auxin_maybe_create_image_size( $attachment_id, $size = '' ) {
2449
2450 if ( empty( $attachment_id ) || ! is_numeric( $attachment_id ) ) {
2451 return;
2452 }
2453
2454 if ( 'full' === $size ) {
2455 return;
2456 }
2457
2458 // check if image size exist or not
2459 if ( ! image_get_intermediate_size( $attachment_id, $size )) {
2460
2461 if ( ! function_exists( 'wp_update_image_subsizes' ) ) {
2462 require_once( ABSPATH . "wp-admin" . '/includes/image.php' );
2463 }
2464
2465 // if WP version is less than 5.3.0
2466 if( ! function_exists( 'wp_get_missing_image_subsizes' ) ){
2467 return;
2468 }
2469
2470 // only create the image size we need
2471 if ( ! isset( wp_get_missing_image_subsizes( $attachment_id )[ $size ] ) ) {
2472 return;
2473 }
2474
2475 add_filter( 'wp_get_missing_image_subsizes', function( $missing_sizes ) use ( $size ) {
2476 return array( $size => $missing_sizes[ $size ] );
2477 });
2478
2479 wp_update_image_subsizes( $attachment_id );
2480 }
2481 }
2482
2483 /**
2484 * Get List of available pages with id and title
2485 *
2486 * @return array
2487 */
2488 function auxin_list_pages() {
2489 $all_pages = get_pages();
2490 $list = array( '' => __( 'Select Page', 'auxin-elements' ) );
2491 foreach( $all_pages as $page ) {
2492 $list[ $page->ID ] = $page->post_title ;
2493 }
2494
2495 return $list;
2496 }
2497
2498 /**
2499 * Get List of available image sizes
2500 *
2501 * @return array
2502 */
2503 function auxin_get_available_image_sizes() {
2504
2505 $image_sizes = get_intermediate_image_sizes();
2506 $auto_size = array( 'auto' => 'auto' );
2507 $image_sizes = array_merge( $image_sizes, $auto_size );
2508
2509 return array_combine( $image_sizes, $image_sizes);
2510
2511 }
2512
2513 /**
2514 * Retrives the value of a key in array if key exists
2515 *
2516 * @param array $array
2517 * @param string $key
2518 * @param string $default
2519 * @return void
2520 */
2521 function auxin_get_array_value( $array, $key, $default = '' ){
2522 return isset( $array[ $key ] ) ? $array[ $key ] : $default;
2523 }
2524
2525 /**
2526 * Insert a value or key/value pair after a specific key in an array. If key doesn't exist, value is appended
2527 * to the end of the array.
2528 *
2529 * @param array $array - old array
2530 * @param string $key
2531 * @param array $new - array that will insert in old array
2532 *
2533 * @return array
2534 */
2535 function auxin_array_insert_after( array $array, $key, array $new ) {
2536 $keys = array_keys( $array );
2537 $index = array_search( $key, $keys );
2538 $pos = false === $index ? count( $array ) : $index + 1;
2539
2540 return array_merge( array_slice( $array, 0, $pos ), $new, array_slice( $array, $pos ) );
2541 }
2542
2543 /**
2544 * Sanitize array values as text fields
2545 *
2546 * @param array|string|int $input
2547 * @return array
2548 */
2549 function auxin_sanitize_input( $input ) {
2550 if ( is_array( $input ) ) {
2551 array_walk_recursive( $input, function( &$value, $key ) {
2552 if ( !is_array( $value ) && !empty( $value ) && $value != ' ' ) {
2553 $value = sanitize_text_field( $value );
2554 }
2555 });
2556 } else {
2557 if ( is_numeric( $input ) ) {
2558 $input = absint( $input );
2559 } else {
2560 $input = sanitize_text_field( $input );
2561 }
2562 }
2563
2564 return $input;
2565 }
2566
2567 /**
2568 * Escape array and return json encoded data
2569 *
2570 * @param array $json_array
2571 * @return string
2572 */
2573 function auxin_escape_json( $json_array ) {
2574 array_walk_recursive( $json_array, function( &$value, $key ) {
2575 if ( !is_array( $value ) ) {
2576 $value = esc_attr( $value );
2577 }
2578 });
2579
2580 return wp_json_encode( $json_array );
2581 }
2582
2583 /**
2584 * Check if a string is in json format or not
2585 *
2586 * $param string $json
2587 * @return bool
2588 */
2589 function auxin_is_json( $json ) {
2590 json_decode( $json );
2591 return json_last_error() === JSON_ERROR_NONE;
2592 }
2593