Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wpforms-.../includes/function...
File: colors.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Helper functions to work with colors.
[2] Fix | Delete
*
[3] Fix | Delete
* @since 1.8.0
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Detect if we should use a light or dark color based on the color given.
[8] Fix | Delete
*
[9] Fix | Delete
* @link https://docs.woocommerce.com/wc-apidocs/source-function-wc_light_or_dark.html#608-627
[10] Fix | Delete
*
[11] Fix | Delete
* @since 1.2.5
[12] Fix | Delete
*
[13] Fix | Delete
* @param mixed $color Color value.
[14] Fix | Delete
* @param string $dark Dark color value (default: '#000000').
[15] Fix | Delete
* @param string $light Light color value (default: '#FFFFFF').
[16] Fix | Delete
*
[17] Fix | Delete
* @return string
[18] Fix | Delete
*/
[19] Fix | Delete
function wpforms_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
[20] Fix | Delete
[21] Fix | Delete
$hex = str_replace( '#', '', $color );
[22] Fix | Delete
[23] Fix | Delete
$c_r = hexdec( substr( $hex, 0, 2 ) );
[24] Fix | Delete
$c_g = hexdec( substr( $hex, 2, 2 ) );
[25] Fix | Delete
$c_b = hexdec( substr( $hex, 4, 2 ) );
[26] Fix | Delete
[27] Fix | Delete
$brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
[28] Fix | Delete
[29] Fix | Delete
return $brightness > 155 ? $dark : $light;
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Convert hex color value to RGB.
[34] Fix | Delete
*
[35] Fix | Delete
* @since 1.7.9
[36] Fix | Delete
* @since 1.8.5 New param and return type were added.
[37] Fix | Delete
*
[38] Fix | Delete
* @param string $hex Color value in hex format.
[39] Fix | Delete
* @param bool $as_string Whether to return the RGB value as a string or array.
[40] Fix | Delete
*
[41] Fix | Delete
* @return string|array Color value in RGB format.
[42] Fix | Delete
*/
[43] Fix | Delete
function wpforms_hex_to_rgb( $hex, $as_string = true ) {
[44] Fix | Delete
[45] Fix | Delete
$hex = ltrim( $hex, '#' );
[46] Fix | Delete
[47] Fix | Delete
// Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF".
[48] Fix | Delete
$rgb_parts = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $hex );
[49] Fix | Delete
[50] Fix | Delete
$rgb = [];
[51] Fix | Delete
$rgb['R'] = hexdec( $rgb_parts[0] . $rgb_parts[1] );
[52] Fix | Delete
$rgb['G'] = hexdec( $rgb_parts[2] . $rgb_parts[3] );
[53] Fix | Delete
$rgb['B'] = hexdec( $rgb_parts[4] . $rgb_parts[5] );
[54] Fix | Delete
[55] Fix | Delete
// Return the RGB value as a string.
[56] Fix | Delete
if ( $as_string ) {
[57] Fix | Delete
return sprintf(
[58] Fix | Delete
'%1$d, %2$d, %3$d',
[59] Fix | Delete
$rgb['R'],
[60] Fix | Delete
$rgb['G'],
[61] Fix | Delete
$rgb['B']
[62] Fix | Delete
);
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
return $rgb; // This is an array.
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Get a lighter color hex value.
[70] Fix | Delete
*
[71] Fix | Delete
* @since 1.8.5
[72] Fix | Delete
*
[73] Fix | Delete
* @param string $color Color hex value.
[74] Fix | Delete
* @param int $factor Factor to lighten the color.
[75] Fix | Delete
*
[76] Fix | Delete
* @return string Lighter color hex value.
[77] Fix | Delete
*/
[78] Fix | Delete
function wpforms_hex_lighter( $color, $factor = 30 ) {
[79] Fix | Delete
[80] Fix | Delete
$base = wpforms_hex_to_rgb( $color, false );
[81] Fix | Delete
[82] Fix | Delete
// Leave if we can't get the RGB values.
[83] Fix | Delete
if ( empty( $base ) || count( $base ) !== 3 ) {
[84] Fix | Delete
return '';
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
$hex = '#';
[88] Fix | Delete
[89] Fix | Delete
foreach ( $base as $channel ) {
[90] Fix | Delete
$amount = 255 - $channel;
[91] Fix | Delete
$amount = $amount / 100;
[92] Fix | Delete
$amount = round( floatval( $amount * $factor ) );
[93] Fix | Delete
$new_decimal = $channel + $amount;
[94] Fix | Delete
[95] Fix | Delete
$new_hex_component = dechex( $new_decimal );
[96] Fix | Delete
[97] Fix | Delete
if ( strlen( $new_hex_component ) < 2 ) {
[98] Fix | Delete
$new_hex_component = '0' . $new_hex_component;
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
$hex .= $new_hex_component;
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
return $hex;
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
/**
[108] Fix | Delete
* Get a darker color hex value.
[109] Fix | Delete
*
[110] Fix | Delete
* @since 1.8.5
[111] Fix | Delete
*
[112] Fix | Delete
* @param string $color Color hex value.
[113] Fix | Delete
* @param int $factor Factor to darken the color.
[114] Fix | Delete
*
[115] Fix | Delete
* @return string Darker color hex value.
[116] Fix | Delete
*/
[117] Fix | Delete
function wpforms_hex_darker( $color, $factor = 30 ) {
[118] Fix | Delete
[119] Fix | Delete
$base = wpforms_hex_to_rgb( $color, false );
[120] Fix | Delete
[121] Fix | Delete
// Leave if we can't get the RGB values.
[122] Fix | Delete
if ( empty( $base ) || count( $base ) !== 3 ) {
[123] Fix | Delete
return '';
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
$hex = '#';
[127] Fix | Delete
[128] Fix | Delete
foreach ( $base as $channel ) {
[129] Fix | Delete
$amount = $channel / 100;
[130] Fix | Delete
$amount = round( floatval( $amount * $factor ) );
[131] Fix | Delete
$new_decimal = $channel - $amount;
[132] Fix | Delete
[133] Fix | Delete
$new_hex_component = dechex( $new_decimal );
[134] Fix | Delete
[135] Fix | Delete
if ( strlen( $new_hex_component ) < 2 ) {
[136] Fix | Delete
$new_hex_component = '0' . $new_hex_component;
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
$hex .= $new_hex_component;
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
return $hex;
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
/**
[146] Fix | Delete
* Generate a contrasting color based on the given color.
[147] Fix | Delete
*
[148] Fix | Delete
* This function calculates a contrasting color to ensure readability based on the provided color.
[149] Fix | Delete
*
[150] Fix | Delete
* @since 1.8.5
[151] Fix | Delete
*
[152] Fix | Delete
* @param string $color The original color value. Color hex value.
[153] Fix | Delete
* @param int $light_factor The factor to lighten the color.
[154] Fix | Delete
* @param int $dark_factor The factor to darken the color.
[155] Fix | Delete
*
[156] Fix | Delete
* @return string The contrasting color value.
[157] Fix | Delete
*/
[158] Fix | Delete
function wpforms_generate_contrasting_color( $color, $light_factor = 30, $dark_factor = 30 ) {
[159] Fix | Delete
[160] Fix | Delete
$is_dark = wpforms_light_or_dark( $color, 'light', 'dark' ) === 'dark';
[161] Fix | Delete
[162] Fix | Delete
return $is_dark ? wpforms_hex_lighter( $color, $light_factor ) : wpforms_hex_darker( $color, $dark_factor );
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function