Setup selector and details arrays for compression methods
Parameters
(string) css: Trimed stylesheet:
File
-
advagg_css_compress/
css-compressor-3.x/ src/ lib/ Setup.inc, line 75
Class
- CSSCompression_Setup
- CSS Compressor [VERSION] [DATE] Corey Hart @ http://www.codenothing.com
Code
public function setup($css) {
// Seperate the element from the elements details
$css = explode("\n", preg_replace($this->rsetup['patterns'], $this->rsetup['replacements'], $css));
$newline = $this->options['readability'] > CSSCompression::READ_NONE ? "\n" : '';
$setup = array(
'selectors' => array(),
'details' => array(),
'unknown' => array(),
'introliner' => '',
'namespace' => '',
'import' => '',
'charset' => '',
);
while (count($css)) {
$row = trim(array_shift($css));
if ($row == '') {
continue;
}
else {
if ($row[0] == '@' && $css[0] == '{' && trim($css[1]) != '' && $css[2] == '}') {
// Stash selector
array_push($setup['selectors'], $row);
// Stash details (after the opening brace)
array_push($setup['details'], $this->details(trim($css[1])));
// drop the details from the stack
$css = array_slice($css, 3);
}
else {
if (preg_match($this->rliner, $row, $match)) {
$setup[$match[1]] .= $this->liner($row) . $newline;
}
else {
if ($row[0] == '@' && $css[0] == '{') {
// Stash atrule as selector
array_push($setup['selectors'], $this->token . $row);
// Stash details (after the opening brace)
array_push($setup['details'], $this->nested($css, preg_match($this->rmedia, $row)) . $newline);
}
else {
if ($row[0] == '@' && substr($row, -1) == ';') {
$setup['introliner'] .= $row . $newline;
}
else {
if (count($css) >= 3 && $css[0] == '{' && $css[2] == '}') {
// Stash selector
array_push($setup['selectors'], $row);
// Stash details (after the opening brace)
array_push($setup['details'], $this->details(trim($css[1])));
// drop the details from the stack
$css = array_slice($css, 3);
}
else {
// Still add to unknown stack, for notification
array_push($setup['unknown'], $row);
// Stash unknown artifacts as selectors with a token
array_push($setup['selectors'], $this->token . $row);
// Give it an empty rule set
array_push($setup['details'], '');
}
}
}
}
}
}
}
return $setup;
}