Edit File by line
/home/barbar84/www/wp-conte.../themes/Divi/includes/function...
File: sanitization.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Sanitize float number
[2] Fix | Delete
* @param mixed
[3] Fix | Delete
* @return float
[4] Fix | Delete
*/
[5] Fix | Delete
function et_sanitize_float_number( $number ) {
[6] Fix | Delete
return floatval( $number );
[7] Fix | Delete
}
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* Sanitize integer number
[11] Fix | Delete
* @param mixed
[12] Fix | Delete
* @return int
[13] Fix | Delete
*/
[14] Fix | Delete
function et_sanitize_int_number( $number ) {
[15] Fix | Delete
return intval( $number );
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Sanitize font style
[20] Fix | Delete
* @param string
[21] Fix | Delete
* @param string
[22] Fix | Delete
*/
[23] Fix | Delete
function et_sanitize_font_style( $styles ) {
[24] Fix | Delete
// List of allowable style
[25] Fix | Delete
$allowed_styles = array_keys( et_divi_font_style_choices() );
[26] Fix | Delete
[27] Fix | Delete
// Explodes styles into array
[28] Fix | Delete
$styles_array = explode( '|', $styles );
[29] Fix | Delete
[30] Fix | Delete
// Get valid styles
[31] Fix | Delete
$valid_styles = array_intersect( $allowed_styles, $styles_array );
[32] Fix | Delete
[33] Fix | Delete
// Return sanitized styles
[34] Fix | Delete
return implode( "|", $valid_styles );
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* Sanitize choosen option based on options' key
[39] Fix | Delete
* @param string
[40] Fix | Delete
* @param array
[41] Fix | Delete
* @return string|bool
[42] Fix | Delete
*/
[43] Fix | Delete
function et_sanitize_key_based_option( $choosen, $options, $default = false ) {
[44] Fix | Delete
// Validate choosen option based on available options
[45] Fix | Delete
if ( ! isset( $options[ $choosen ] ) ) {
[46] Fix | Delete
return $default;
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
return $choosen;
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Sanitize font choice
[54] Fix | Delete
* @param string
[55] Fix | Delete
* @return string|bool
[56] Fix | Delete
*/
[57] Fix | Delete
function et_sanitize_font_choices( $choosen ) {
[58] Fix | Delete
$google_fonts = et_builder_get_fonts();
[59] Fix | Delete
$user_fonts = et_builder_get_custom_fonts();
[60] Fix | Delete
[61] Fix | Delete
// combine google fonts with custom user fonts
[62] Fix | Delete
$all_fonts = array_merge( $user_fonts, $google_fonts );
[63] Fix | Delete
[64] Fix | Delete
return et_sanitize_key_based_option( $choosen, $all_fonts );
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Sanitize color scheme
[69] Fix | Delete
* @param string
[70] Fix | Delete
* @return string|bool
[71] Fix | Delete
*/
[72] Fix | Delete
function et_sanitize_color_scheme( $choosen ) {
[73] Fix | Delete
return et_sanitize_key_based_option( $choosen, et_divi_color_scheme_choices() );
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Sanitize header style
[78] Fix | Delete
* @param string
[79] Fix | Delete
* @return string|bool
[80] Fix | Delete
*/
[81] Fix | Delete
function et_sanitize_header_style( $choosen ) {
[82] Fix | Delete
return et_sanitize_key_based_option( $choosen, et_divi_header_style_choices() );
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Sanitize dropdown animation
[87] Fix | Delete
* @param string
[88] Fix | Delete
* @return string|bool
[89] Fix | Delete
*/
[90] Fix | Delete
function et_sanitize_dropdown_animation( $choosen ) {
[91] Fix | Delete
return et_sanitize_key_based_option( $choosen, et_divi_dropdown_animation_choices() );
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
/**
[95] Fix | Delete
* Sanitize footer column
[96] Fix | Delete
* @param string
[97] Fix | Delete
* @return string|bool
[98] Fix | Delete
*/
[99] Fix | Delete
function et_sanitize_footer_column( $choosen ) {
[100] Fix | Delete
return et_sanitize_key_based_option( $choosen, et_divi_footer_column_choices() );
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* Sanitize yes no choices
[105] Fix | Delete
* @param string
[106] Fix | Delete
* @return string|bool
[107] Fix | Delete
*/
[108] Fix | Delete
function et_sanitize_yes_no( $choosen ) {
[109] Fix | Delete
return et_sanitize_key_based_option( $choosen, et_divi_yes_no_choices() );
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Sanitize left or right choices
[114] Fix | Delete
* @param string
[115] Fix | Delete
* @return string|bool
[116] Fix | Delete
*/
[117] Fix | Delete
function et_sanitize_left_right( $choosen ) {
[118] Fix | Delete
return et_sanitize_key_based_option( $choosen, et_divi_left_right_choices() );
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
/**
[122] Fix | Delete
* Sanitize image animation choices
[123] Fix | Delete
* @param string
[124] Fix | Delete
* @return string|bool
[125] Fix | Delete
*/
[126] Fix | Delete
function et_sanitize_image_animation( $choosen ) {
[127] Fix | Delete
return et_sanitize_key_based_option( $choosen, et_divi_image_animation_choices() );
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
/**
[131] Fix | Delete
* Sanitize divider style choices
[132] Fix | Delete
* @param string
[133] Fix | Delete
* @return string|bool
[134] Fix | Delete
*/
[135] Fix | Delete
function et_sanitize_divider_style( $choosen ) {
[136] Fix | Delete
return et_sanitize_key_based_option( $choosen, et_divi_divider_style_choices() );
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Sanitize divider position choices
[141] Fix | Delete
* @param string
[142] Fix | Delete
* @return string|bool
[143] Fix | Delete
*/
[144] Fix | Delete
function et_sanitize_divider_position( $choosen ) {
[145] Fix | Delete
return et_sanitize_key_based_option( $choosen, et_divi_divider_position_choices() );
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
/**
[149] Fix | Delete
* Sanitize RGBA color
[150] Fix | Delete
* @param string
[151] Fix | Delete
* @return string|bool
[152] Fix | Delete
*/
[153] Fix | Delete
function et_sanitize_alpha_color( $color ) {
[154] Fix | Delete
// Trim unneeded whitespace
[155] Fix | Delete
$color = str_replace( ' ', '', $color );
[156] Fix | Delete
[157] Fix | Delete
// If this is hex color, validate and return it
[158] Fix | Delete
if ( 1 === preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) {
[159] Fix | Delete
return $color;
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
// If this is rgb, validate and return it
[163] Fix | Delete
elseif ( 'rgb(' === substr( $color, 0, 4 ) ) {
[164] Fix | Delete
sscanf( $color, 'rgb(%d,%d,%d)', $red, $green, $blue );
[165] Fix | Delete
[166] Fix | Delete
if ( ( $red >= 0 && $red <= 255 ) &&
[167] Fix | Delete
( $green >= 0 && $green <= 255 ) &&
[168] Fix | Delete
( $blue >= 0 && $blue <= 255 )
[169] Fix | Delete
) {
[170] Fix | Delete
return "rgb({$red},{$green},{$blue})";
[171] Fix | Delete
}
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
// If this is rgba, validate and return it
[175] Fix | Delete
elseif ( 'rgba(' === substr( $color, 0, 5 ) ) {
[176] Fix | Delete
sscanf( $color, 'rgba(%d,%d,%d,%f)', $red, $green, $blue, $alpha );
[177] Fix | Delete
[178] Fix | Delete
if ( ( $red >= 0 && $red <= 255 ) &&
[179] Fix | Delete
( $green >= 0 && $green <= 255 ) &&
[180] Fix | Delete
( $blue >= 0 && $blue <= 255 ) &&
[181] Fix | Delete
$alpha >= 0 && $alpha <= 1
[182] Fix | Delete
) {
[183] Fix | Delete
return "rgba({$red},{$green},{$blue},{$alpha})";
[184] Fix | Delete
}
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
return false;
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
/**
[191] Fix | Delete
* Sanitize font icon
[192] Fix | Delete
* @param string
[193] Fix | Delete
* @param string
[194] Fix | Delete
* @return string
[195] Fix | Delete
*/
[196] Fix | Delete
function et_sanitize_font_icon( $font_icon, $symbols_function = 'default' ) {
[197] Fix | Delete
// Convert symbols into strings
[198] Fix | Delete
$font_icon = trim( $font_icon );
[199] Fix | Delete
// @phpcs:ignore Generic.PHP.ForbiddenFunctions.Found
[200] Fix | Delete
$icon_symbols = is_callable( $symbols_function ) ? call_user_func( $symbols_function ) : et_pb_get_font_icon_symbols();
[201] Fix | Delete
$icon_symbols = array_map( 'et_sanitize_font_icon_convert_icon_to_string', $icon_symbols );
[202] Fix | Delete
[203] Fix | Delete
// the exact font icon value is saved
[204] Fix | Delete
if ( 1 !== preg_match( "/^%%/", $font_icon ) ) {
[205] Fix | Delete
return in_array( $font_icon, $icon_symbols ) ? $font_icon : '';
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
// the font icon value is saved in the following format: %%index_number%%
[209] Fix | Delete
// strip the %'s to get to end result: index_number
[210] Fix | Delete
$icon_index = (int) str_replace( '%', '', $font_icon );
[211] Fix | Delete
return isset( $icon_symbols[ $icon_index ] ) ? $icon_symbols[ $icon_index ] : '';
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
/**
[215] Fix | Delete
* Convert font hex-code font icons into strings so it can be compared
[216] Fix | Delete
* @param string
[217] Fix | Delete
* @return string
[218] Fix | Delete
*/
[219] Fix | Delete
function et_sanitize_font_icon_convert_icon_to_string( $icon ) {
[220] Fix | Delete
// Replace &amp; with &. Otherwise, it'll incorrectly decoded
[221] Fix | Delete
$icon = str_replace( '&amp;', '&', $icon );
[222] Fix | Delete
[223] Fix | Delete
// Decode
[224] Fix | Delete
return html_entity_decode( $icon );
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
/**
[228] Fix | Delete
* Array of allowed html tags on short block
[229] Fix | Delete
* @return array
[230] Fix | Delete
*/
[231] Fix | Delete
function et_allowed_html_tags_short_block() {
[232] Fix | Delete
$allowed_tags = array(
[233] Fix | Delete
'div' => array(
[234] Fix | Delete
'class' => array(),
[235] Fix | Delete
'id' => array(),
[236] Fix | Delete
),
[237] Fix | Delete
'span' => array(
[238] Fix | Delete
'class' => array(),
[239] Fix | Delete
'id' => array(),
[240] Fix | Delete
),
[241] Fix | Delete
'ol' => array(
[242] Fix | Delete
'class' => array(),
[243] Fix | Delete
'id' => array(),
[244] Fix | Delete
),
[245] Fix | Delete
'ul' => array(
[246] Fix | Delete
'class' => array(),
[247] Fix | Delete
'id' => array(),
[248] Fix | Delete
),
[249] Fix | Delete
'li' => array(
[250] Fix | Delete
'class' => array(),
[251] Fix | Delete
'id' => array(),
[252] Fix | Delete
),
[253] Fix | Delete
'p' => array(
[254] Fix | Delete
'class' => array(),
[255] Fix | Delete
'id' => array(),
[256] Fix | Delete
),
[257] Fix | Delete
'a' => array(
[258] Fix | Delete
'href' => array(),
[259] Fix | Delete
'class' => array(),
[260] Fix | Delete
'id' => array(),
[261] Fix | Delete
'rel' => array(),
[262] Fix | Delete
'title' => array(),
[263] Fix | Delete
'target' => array(),
[264] Fix | Delete
),
[265] Fix | Delete
'br' => array(),
[266] Fix | Delete
'em' => array(),
[267] Fix | Delete
'strong' => array(),
[268] Fix | Delete
);
[269] Fix | Delete
[270] Fix | Delete
return apply_filters( 'et_allowed_html_tags_short_block', $allowed_tags );
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
/**
[274] Fix | Delete
* Sanitize short block html input
[275] Fix | Delete
* @return string
[276] Fix | Delete
*/
[277] Fix | Delete
function et_sanitize_html_input_text( $string ) {
[278] Fix | Delete
return wp_kses( $string, et_allowed_html_tags_short_block() );
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
/**
[282] Fix | Delete
* Sanitize background repeat value
[283] Fix | Delete
* @return string
[284] Fix | Delete
*/
[285] Fix | Delete
function et_sanitize_background_repeat( $choosen ) {
[286] Fix | Delete
return et_sanitize_key_based_option(
[287] Fix | Delete
$choosen,
[288] Fix | Delete
et_divi_background_repeat_choices(),
[289] Fix | Delete
apply_filters( 'et_divi_background_repeat_default', 'repeat' )
[290] Fix | Delete
);
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
/**
[294] Fix | Delete
* Sanitize background attachment value
[295] Fix | Delete
* @return string
[296] Fix | Delete
*/
[297] Fix | Delete
function et_sanitize_background_attachment( $choosen ) {
[298] Fix | Delete
return et_sanitize_key_based_option(
[299] Fix | Delete
$choosen,
[300] Fix | Delete
et_divi_background_attachment_choices(),
[301] Fix | Delete
apply_filters( 'et_sanitize_background_attachment_default', 'scroll' )
[302] Fix | Delete
);
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function