function ctools_css_disassemble
Disassemble the css string.
Strip the css of irrelevant characters, invalid/malformed selectors and declarations, and otherwise prepare it for processing.
Parameters
string $css: A string containing the css to be disassembled.
Return value
array An array of disassembled, slightly cleaned-up/formatted css statements.
2 calls to ctools_css_disassemble()
- 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 284
Code
function ctools_css_disassemble($css) {
$disassembled_css = array();
// Remove comments.
$css = preg_replace("/\\/\\*(.*)?\\*\\//Usi", "", $css);
// Split out each statement. Match either a right curly brace or a semi-colon
// that precedes a left curly brace with no right curly brace separating them.
$statements = preg_split('/}|;(?=[^}]*{)/', $css);
// If we have any statements, parse them.
if (!empty($statements)) {
// Iterate through all of the statements.
foreach ($statements as $statement) {
// Get the selector(s) and declaration.
if (empty($statement) || !strpos($statement, '{')) {
continue;
}
list($selector_str, $declaration) = explode('{', $statement);
// If the selector exists, then disassemble it, check it, and regenerate
// the selector string.
$selector_str = empty($selector_str) ? FALSE : _ctools_css_disassemble_selector($selector_str);
if (empty($selector_str)) {
// No valid selectors. Bomb out and start the next item.
continue;
}
// Disassemble the declaration, check it and tuck it into an array.
if (!isset($disassembled_css[$selector_str])) {
$disassembled_css[$selector_str] = array();
}
$disassembled_css[$selector_str] += _ctools_css_disassemble_declaration($declaration);
}
}
return $disassembled_css;
}