$v ) { if ( ! array_key_exists( $k, $a2 ) ) { continue; } if ( is_array( $v ) && is_array( $a2[ $k ] ) ) { $a1[ $k ] = sp_array_overlay( $v, $a2[ $k ] ); } else { $a1[ $k ] = $a2[ $k ]; } } return $a1; } /** * SportsPress Date Format - Allows to change date format for everything SportsPress * * @access public * @return string */ function sp_date_format() { return apply_filters( 'sportspress_date_format', get_option( 'date_format' ) ); } /** * SportsPress Time Format - Allows to change time format for everything SportsPress * * @access public * @return string */ function sp_time_format() { return apply_filters( 'sportspress_time_format', get_option( 'time_format' ) ); } if ( ! function_exists( 'sp_rgb_from_hex' ) ) { /** * Hex darker/lighter/contrast functions for colours * * @access public * @param mixed $color * @return string */ function sp_rgb_from_hex( $color ) { $color = str_replace( '#', '', $color ); // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); $rgb['R'] = hexdec( $color{0}.$color{1} ); $rgb['G'] = hexdec( $color{2}.$color{3} ); $rgb['B'] = hexdec( $color{4}.$color{5} ); return $rgb; } } if ( ! function_exists( 'sp_hex_darker' ) ) { /** * Hex darker/lighter/contrast functions for colours * * @access public * @param mixed $color * @param int $factor (default: 30) * @return string */ function sp_hex_darker( $color, $factor = 30 ) { $base = sp_rgb_from_hex( $color ); $color = '#'; foreach ($base as $k => $v) : $amount = $v / 100; $amount = round($amount * $factor); $new_decimal = $v - $amount; $new_hex_component = dechex($new_decimal); if(strlen($new_hex_component) < 2) : $new_hex_component = "0".$new_hex_component; endif; $color .= $new_hex_component; endforeach; return $color; } } if ( ! function_exists( 'sp_hex_lighter' ) ) { /** * Hex darker/lighter/contrast functions for colours * * @access public * @param mixed $color * @param int $factor (default: 30) * @return string */ function sp_hex_lighter( $color, $factor = 30 ) { $base = sp_rgb_from_hex( $color ); $color = '#'; foreach ($base as $k => $v) : $amount = 255 - $v; $amount = $amount / 100; $amount = round($amount * $factor); $new_decimal = $v + $amount; $new_hex_component = dechex($new_decimal); if(strlen($new_hex_component) < 2) : $new_hex_component = "0".$new_hex_component; endif; $color .= $new_hex_component; endforeach; return $color; } } if ( ! function_exists( 'sp_light_or_dark' ) ) { /** * Detect if we should use a light or dark colour on a background colour * * @access public * @param mixed $color * @param string $dark (default: '#000000') * @param string $light (default: '#FFFFFF') * @return string */ function sp_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { //return ( hexdec( $color ) > 0xffffff / 2 ) ? $dark : $light; $hex = str_replace( '#', '', $color ); $c_r = hexdec( substr( $hex, 0, 2 ) ); $c_g = hexdec( substr( $hex, 2, 2 ) ); $c_b = hexdec( substr( $hex, 4, 2 ) ); $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; return $brightness > 155 ? $dark : $light; } } if ( ! function_exists( 'sp_format_hex' ) ) { /** * Format string as hex * * @access public * @param string $hex * @return string */ function sp_format_hex( $hex ) { $hex = trim( str_replace( '#', '', $hex ) ); if ( strlen( $hex ) == 3 ) { $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; } if ( $hex ) return '#' . $hex; } }