You are here

function csstidy_optimise::discard_invalid_selectors in Advanced CSS/JS Aggregation 6

Same name and namespace in other branches
  1. 7 advagg_css_compress/csstidy/class.csstidy_optimise.inc \csstidy_optimise::discard_invalid_selectors()

Removes invalid selectors and their corresponding rule-sets as defined by 4.1.7 in REC-CSS2. This is a very rudimentary check and should be replaced by a full-blown parsing algorithm or regular expression @version 1.4

1 call to csstidy_optimise::discard_invalid_selectors()
csstidy_optimise::postparse in advagg_css_compress/csstidy/class.csstidy_optimise.inc
Optimises $css after parsing @access public @version 1.0

File

advagg_css_compress/csstidy/class.csstidy_optimise.inc, line 498

Class

csstidy_optimise
CSS Optimising Class

Code

function discard_invalid_selectors(&$array) {
  $invalid = array(
    '+' => true,
    '~' => true,
    ',' => true,
    '>' => true,
  );
  foreach ($array as $selector => $decls) {
    $ok = true;
    $selectors = array_map('trim', explode(',', $selector));
    foreach ($selectors as $s) {
      $simple_selectors = preg_split('/\\s*[+>~\\s]\\s*/', $s);
      foreach ($simple_selectors as $ss) {
        if ($ss === '') {
          $ok = false;
        }

        // could also check $ss for internal structure,
        // but that probably would be too slow
      }
    }
    if (!$ok) {
      unset($array[$selector]);
    }
  }
}