function ctools_css_filter_css_data
Run disassembled $css through the filter.
Parameters
$css: CSS code disassembled by ctools_dss_disassemble().
$allowed_properties: A list of properties that are allowed by the filter. If empty ctools_css_filter_default_allowed_properties() will provide the list.
$allowed_values: A list of values that are allowed by the filter. If empty ctools_css_filter_default_allowed_values() will provide the list.
Return value
An array of disassembled, filtered CSS.
2 calls to ctools_css_filter_css_data()
- CtoolsCssTestCase::testCssFilterURLHandling in tests/
css.test - Test that in case that url is used, the colons survives filtering.
- ctools_css_filter in includes/
css.inc - Filter a chunk of CSS text.
File
-
includes/
css.inc, line 386
Code
function ctools_css_filter_css_data($css, $allowed_properties = array(), $allowed_values = array(), $allowed_values_regex = '', $disallowed_values_regex = '') {
// Retrieve the default list of allowed properties if none is provided.
$allowed_properties = !empty($allowed_properties) ? $allowed_properties : ctools_css_filter_default_allowed_properties();
// Retrieve the default list of allowed values if none is provided.
$allowed_values = !empty($allowed_values) ? $allowed_values : ctools_css_filter_default_allowed_values();
// Define allowed values regex if none is provided.
$allowed_values_regex = !empty($allowed_values_regex) ? $allowed_values_regex : '/(#[0-9a-f]+|rgb\\(\\d+%?,\\d*%?,?\\d*%?\\)?|\\d{0,2}\\.?\\d{0,2}(cm|em|ex|in|mm|pc|pt|px|%|,|\\))?)/';
// Define disallowed url() value contents, if none is provided.
$disallowed_values_regex = !empty($disallowed_values_regex) ? $disallowed_values_regex : '/(url|expression)/';
foreach ($css as $selector_str => $declaration) {
foreach ($declaration as $property => $value) {
if (!in_array($property, $allowed_properties)) {
// $filtered['properties'][$selector_str][$property] = $value;.
unset($css[$selector_str][$property]);
continue;
}
$value = str_replace('!important', '', $value);
if (preg_match($disallowed_values_regex, $value) || !(in_array($value, $allowed_values) || preg_match($allowed_values_regex, $value))) {
// $filtered['values'][$selector_str][$property] = $value;.
unset($css[$selector_str][$property]);
continue;
}
}
}
return $css;
}