<?php
// PHP-CSS-Compiler
// setup:
function ob_filter_terse($t)
{
// this filter minifies the CSS
$t = str_replace(array("\t","\r", "\n"), array(' ', '', ' '), $t);
while(strpos(' ', $t) !== FALSE)
$t = str_replace(' ', ' ', $t);
return $t;
}
function ob_filter_verbose($t)
{
// this function leaves CSS as it is and adds a little debug info
$t = "/* CSS Compiled ".strftime("%Y-%m-%d %H:%M:%S")." */\n" . $t;
return $t;
}
// configuration:
// its important that we use soft-namespaces in this process
// since all the variables in the main section are exposed to all the included files
$comp_verbose = (isset($_REQUEST['v']) && $_REQUEST['v']=='true' ? TRUE : FALSE);
$comp_includes = array();
if(isset($_REQUEST['i']))
{
$comp_includes = explode(',', $_REQUEST['i']);
}
// compilation:
header("Content-Type: text/css");
ob_start(($comp_verbose ? 'ob_filter_verbose' : 'ob_filter_terse')); // set which filter function to use
if($comp_verbose)
{
foreach($comp_includes as $f)
echo "/* Source: $f */\n";
echo "\n\n";
}
foreach($comp_includes as $f)
{
include($f);
}
ob_end_flush(); //calls the filter function
?>