$data = file_get_contents($in); if ($data === false) { err("Could not read to file {$in}"); exit(1); } } //Parse input $parser = new css_parser(); $css_doc = $parser->parse($data); if (has('u')) { //css_cleaner if (!has('p')) { err('Please, indicate the project source path. Multiple paths can be concatenated using ' . PATH_SEPARATOR); exit(1); } $cleaner = new css_cleaner(); $cleaner->verbose = true; $cleaner->project_files = explode(PATH_SEPARATOR, $opts['p']); $cleaner->method = get('m', 'safe') == 'safe' ? css_cleaner::METHOD_SAFE : css_cleaner::METHOD_BEST_CLEAN; if (has('e')) { $cleaner->extensions = get('e'); } if (has('r')) { $cleaner->report_path = get('r'); } $cleaner->clean($css_doc); } //Optimize $optimizer = new css_optimizer(); $optimizer->compress = get('c', true); $optimizer->optimize = get('o', true);
function do_optimization() { $settings = array(); $cleaner = new css_cleaner(); foreach (array('method', 'compress') as $prop) { $settings[$prop] = isset($_POST[$prop]) ? $_POST[$prop] : (isset($cleaner->{$prop}) ? $cleaner->{$prop} : false); $cleaner->{$prop} = $settings[$prop]; } $result = array(); $result['settings'] = $settings; if (!empty($_POST['source'])) { $cleaner->verbose = true; $cleaner->project_files[] = dirname(__FILE__); $result['source'] = $_POST['source']; $parser = new css_parser(); //Clean CSS ob_start(); $start = microtime(true); $result['css'] = $cleaner->clean($parser->parse($result['source']))->render($settings['compress']); $result['execution_time'] = microtime(true) - $start; $result['output'] = ob_get_clean(); } return $result; }