= $last_modified)) { header('HTTP/1.0 304 Not Modified'); exit; } print("/* Generated by CSS Mixin v3 http://habilis.net/cssmixin/ */\n"); if ($debug) print("/*\n PHP Style Script: {$_SERVER['PHP_SELF']}\n CSS Class File: $cssfile\n*/\n"); } // load CSS $f = file_get_contents($cssfile); // Strip all the comments $f = preg_replace('/\/\*.*\*\//sU', '', $f); // Tokenize into selectors, and declariations. // It's not a parser, it's a pharser (hackish, kludgy parser). preg_match_all('/([>_a-z0-9-:\.\*][>_a-z0-9-:\.\* ]+[>_a-z0-9-:\.\*])|({[^}]+})/si', $f, $out, PREG_SET_ORDER); //print_r($out); // Construct descriptor by appending selectors $selector_list = array(); foreach ($out as $o) { $firstc = $o[0][0]; if ($firstc != '{') { $selector_list[] = $o[1]; } else if ($firstc == '{') { $descriptor = trim(trim($o[2], ' '), "\n\r"); foreach ($selector_list as $s) { preg_match('/\.([_a-z0-9-]+)/si', $s, $matches); $class = $matches[1]; if (array_key_exists($class, $cssrules)) $cssrules[$class][] = array($s, $descriptor); else $cssrules[$class] = array(array($s, $descriptor)); } $selector_list = array(); } } //print_r($cssrules); } // cssmixin creates new style descriptors for $newspec based on the $mixinclasses list. function cssmixin($newspec, $mixinclasses) { global $cssrules; global $debug; $clist = explode(' ', $mixinclasses); foreach ($clist as $c) { if ($debug) { print("/* Spec: $newspec Class: $c */\n\n"); } if (array_key_exists($c, $cssrules)) { foreach ($cssrules[$c] as $rule) { $selector = $rule[0]; $description = $rule[1]; $selector = str_replace(".$c", $newspec, $selector); print("$selector $description\n\n"); } } } } ?>