0xffffff / 2 ) ? $dark : $light; } } /** * Color conversion from HEX to RGB or RGBA. */ if ( ! function_exists( 'ast_hex2rgba' ) ) { /** * Color conversion from HEX to RGB or RGBA. * * @since 1.0 * @param string $hex Color code in HEX format. * @param string $alpha Color code alpha value for RGBA conversion. * @return string Return RGB or RGBA color code. */ function ast_hex2rgba( $hex, $alpha = '' ) { $hex = str_replace( '#', '', $hex ); if ( strlen( $hex ) == 3 ) { $r = hexdec( substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) ); $g = hexdec( substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) ); $b = hexdec( substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ) ); } else { $r = hexdec( substr( $hex, 0, 2 ) ); $g = hexdec( substr( $hex, 2, 2 ) ); $b = hexdec( substr( $hex, 4, 2 ) ); } $rgb = $r . ',' . $g . ',' . $b; if ( '' === $alpha ) { return 'rgb(' . $rgb . ')'; } else { $alpha = floatval( $alpha ); return 'rgba(' . $rgb . ',' . $alpha . ')'; } } } /** * Retrieve theme or meta options subkey value. */ if ( ! function_exists( 'ast_get_option_subkey' ) ) { /** * Retrieve theme or meta options subkey value. * * @since 1.0 * @param string $result_key Return sub key. * @param string $subkeys Subkey value. * @param string $default Return default value if not found. * @return mixed Depending on the output type of the field used. */ function ast_get_option_subkey( $result_key, $subkeys = '', $default = '' ) { if ( isset( $result_key ) && '' != $result_key ) { $count = count( $subkeys ); if ( 1 == $count ) { $value = ( isset( $result_key[ $subkeys[1] ] ) && '' !== $result_key[ $subkeys[1] ] ) ? $result_key[ $subkeys[1] ] : $default; } elseif ( 2 == $count ) { if ( isset( $result_key[ $subkeys[1] ] ) ) { $value = ( isset( $result_key[ $subkeys[1] ][ $subkeys[2] ] ) && '' !== $result_key[ $subkeys[1] ][ $subkeys[2] ] ) ? $result_key[ $subkeys[1] ][ $subkeys[2] ] : $default; } } elseif ( 3 == $count ) { if ( isset( $result_key[ $subkeys[1] ] ) ) { if ( isset( $result_key[ $subkeys[1] ][ $subkeys[2] ] ) ) { $value = ( isset( $result_key[ $subkeys[1] ][ $subkeys[2] ][ $subkeys[3] ] ) && '' !== $result_key[ $subkeys[1] ][ $subkeys[2] ][ $subkeys[3] ] ) ? $result_key[ $subkeys[1] ][ $subkeys[2] ][ $subkeys[3] ] : $default; } } } } else { $value = ( isset( $result_key ) && '' !== $result_key ) ? $result_key : $default; } return $value; } } /** * Generate CSS */ if ( ! function_exists( 'ast_css' ) ) { /** * Generate CSS * * @param mixed $value CSS value. * @param string $css_property CSS property. * @param string $selector CSS selector. * @param string $unit CSS property unit. * @return void Echo generated CSS. */ function ast_css( $value = '', $css_property = '', $selector = '', $unit = '' ) { if ( $selector ) { if ( $css_property && $value ) { if ( '' != $unit ) { $value .= $unit; } $css = $selector; $css .= '{'; $css .= ' ' . $css_property . ': ' . $value . ';'; $css .= '}'; echo $css; } } } } /** * Set background color / image etc */ if ( ! function_exists( 'ast_css_background' ) ) { /** * Set background color / image etc * * @param string $selector CSS selector. * @param string $bg_color Background color in HEX. * @param string $bg_img Background image URL. * @param string $bg_pos Background image position. * @param string $bg_rep Background image repeat. * @param int $bg_size Background image size. * @param string $bg_atch Background image attachment. * @return void Echo the generated CSS. */ function ast_css_background( $selector = '', $bg_color = '', $bg_img = '', $bg_pos = '', $bg_rep = '', $bg_size = '', $bg_atch = '' ) { /** * Selector */ if ( $selector ) { $css = ''; // Has bg color? if ( $bg_color ) { // set [parent] HEX color. $css .= $selector; $css .= '{'; $css .= ' background-color: ' . $bg_color . ';'; $css .= '}'; } // Has bg image? if ( $bg_img ) { $css .= $selector; $css .= '{'; $css .= ' background-image: url(' . $bg_img . ');'; // background repeat. if ( $bg_rep ) { $css .= ' background-repeat:' . $bg_rep . ';'; } // background size. if ( $bg_size ) { $css .= ' background-size:' . $bg_size . ';'; } // background attachment. if ( $bg_atch ) { $css .= ' background-attachment:' . $bg_atch . ';'; } $css .= '}'; } echo $css; }// End if(). } }// End if(). /** * CSS Font Font */ if ( ! function_exists( 'ast_css_font' ) ) { /** * CSS Font Font * * @since 1.0 * @param string $selector CSS selector. * @param number $font_size Font size. * @param string $font_weight Font weight. * @param string $font_family Font family. * @return void Echo the generated CSS. */ function ast_css_font( $selector = '', $font_size = '', $font_weight = '', $font_family = '' ) { $output = ''; $theme_options = Ast_Theme_Options::get_options(); $body_font_size = ( $theme_options['font-size-body'] ) ? $theme_options['font-size-body'] : ''; if ( $selector ) { /** * Selector */ $output .= $selector; $output .= ' { '; /** * Font Size */ if ( $font_size ) { // font size in 'px'. // font size in 'rem'. $output .= 'font-size: ' . esc_attr( round( $font_size ) ) . 'px;'; if ( $body_font_size ) { $output .= 'font-size: ' . ( esc_attr( $font_size ) / esc_attr( $body_font_size ) ) . 'rem;'; } } /** * Font Weight */ if ( $font_weight && 'inherit' != $font_weight ) { $output .= 'font-weight: ' . esc_attr( $font_weight ) . ';'; } /** * Font Family */ if ( $font_family && 'inherit' != $font_family ) { $output .= 'font-family: ' . esc_attr( $font_family ) . ';'; } $output .= ' } '; }// End if(). echo $output; } }// End if(). /** * Get CSS value */ if ( ! function_exists( 'ast_get_css_value' ) ) { /** * Get CSS value * * Syntax: * * ast_get_css_value( VALUE, UNIT ); * * E.g. * * ast_get_css_value( VALUE, 'url' ); * ast_get_css_value( VALUE, 'px' ); * ast_get_css_value( VALUE, 'em' ); * * @param string $value CSS value. * @param string $unit CSS unit. * @param string $default_font CSS default font. * @return mixed CSS value depends on $unit */ function ast_get_css_value( $value = '', $unit = 'px', $default_font = '' ) { if ( '' == $value ) { return $value; } $css_val = ''; switch ( $unit ) { case 'dimension' : if ( is_numeric( $value ) ) { $css_val = esc_attr( $value ) . 'px'; } else { $css_val = esc_attr( $value ); } break; case 'font' : if ( 'inherit' != $value ) { $css_val = esc_attr( $value ); } elseif ( '' != $default_font ) { $css_val = esc_attr( $default_font ); } break; case 'px': case '%' : $css_val = esc_attr( $value ) . $unit; break; case 'url' : $css_val = $unit . '(' . esc_attr( $value ) . ')'; break; case 'rem': if ( is_numeric( $value ) || strpos( $value, 'px' ) ) { $value = intval( $value ); $theme_options = Ast_Theme_Options::get_options(); $body_font_size = ( $theme_options['font-size-body'] ) ? $theme_options['font-size-body'] : ''; if ( $body_font_size ) { $css_val = esc_attr( $value ) . 'px;font-size:' . ( esc_attr( $value ) / esc_attr( $body_font_size ) ) . $unit; } } else { $css_val = esc_attr( $value ); } break; default: if ( '' != $value ) { $css_val = esc_attr( $value ) . $unit; } }// End switch(). return $css_val; } }// End if(). /** * Parse CSS */ if ( ! function_exists( 'ast_parse_css' ) ) { /** * Parse CSS * * @param array $css_output Array of CSS. * @param string $min_media Min Media breakpoint. * @param string $max_media Max Media breakpoint. * @return string Generated CSS. */ function ast_parse_css( $css_output = array(), $min_media = '', $max_media = '' ) { $parse_css = ''; if ( is_array( $css_output ) && count( $css_output ) > 0 ) { foreach ( $css_output as $selector => $properties ) { if ( ! count( $properties ) ) { continue; } $temp_parse_css = $selector . '{'; $properties_added = 0; foreach ( $properties as $property => $value ) { if ( '' === $value ) { continue; } $properties_added++; $temp_parse_css .= $property . ':' . $value . ';'; } $temp_parse_css .= '}'; if ( $properties_added > 0 ) { $parse_css .= $temp_parse_css; } } if ( '' != $parse_css && ( '' !== $min_media || '' !== $max_media ) ) { $media_css = '@media '; $min_media_css = ''; $max_media_css = ''; $media_separator = ''; if ( '' !== $min_media ) { $min_media_css = '(min-width:' . $min_media . 'px)'; } if ( '' !== $max_media ) { $max_media_css = '(max-width:' . $max_media . 'px)'; } if ( '' !== $min_media && '' !== $max_media ) { $media_separator = ' and '; } $media_css .= $min_media_css . $media_separator . $max_media_css . '{' . $parse_css . '}'; return $media_css; } }// End if(). return $parse_css; } }// End if(). /** * Return Theme options. */ if ( ! function_exists( 'ast_get_option' ) ) { /** * Return Theme options. * * @param string $option Option key. * @param string $subkeys Option subkey. * @param string $default Option default value. * @return string Return option value. */ function ast_get_option( $option, $subkeys = '', $default = '' ) { $theme_options = Ast_Theme_Options::get_options(); if ( ! empty( $subkeys ) && is_array( $subkeys ) && isset( $theme_options[ $option ] ) ) { $value = ast_get_option_subkey( $theme_options[ $option ], $subkeys, $default ); } else { $value = ( isset( $theme_options[ $option ] ) && '' !== $theme_options[ $option ] ) ? $theme_options[ $option ] : $default; } return $value; } } /** * Return Theme options from postmeta. */ if ( ! function_exists( 'ast_get_option_meta' ) ) { /** * Return Theme options from postmeta. * * @param string $option_id Option ID. * @param string $subkeys Option subkey value. * @param string $default Option default value. * @param boolean $only_meta Get only meta value. * @param string $extension Is value from extension. * @param string $post_id Get value from specific post by post ID. * @return string Return option value. */ function ast_get_option_meta( $option_id, $subkeys = '', $default = '', $only_meta = false, $extension = '', $post_id = '' ) { $post_id = ( '' != $post_id ) ? $post_id : ast_get_post_id(); $value = ast_get_option( $option_id, $subkeys, $default ); // Get value from option 'post-meta'. if ( is_singular() || ( is_home() && ! is_front_page() ) ) { $value = get_post_meta( $post_id, $option_id, true ); if ( empty( $value ) || 'default' == $value ) { if ( true == $only_meta ) { return false; } $value = ast_get_option( $option_id, $subkeys, $default ); } } return $value; } }// End if(). /** * Output markup required for the language switcher for WPML. */ if ( ! function_exists( 'ast_language_switcher' ) ) { /** * Output markup required for the language switcher for WPML. * * @since 1.0 * @return HTML */ function ast_language_switcher() { if ( ! function_exists( 'icl_get_languages' ) ) { return; } $languages = icl_get_languages( 'skip_missing=0&orderby=code' ); echo '