示例#1
0
function Q_filters_reducisaurus($params)
{
    $parts = $params['parts'];
    $dest = $params['dest'];
    $processed = array();
    foreach ($parts as $src => $content) {
        $dest_parts = explode('/', $dest);
        $src_parts = explode('/', $src);
        $j = 0;
        foreach ($dest_parts as $i => $p) {
            if (!isset($src_parts[$i]) or $src_parts[$i] !== $dest_parts[$i]) {
                break;
            }
            $j = $i + 1;
        }
        $dc = count($dest_parts);
        $sc = count($src_parts);
        $relative = str_repeat("../", $dc - $j - 1) . implode('/', array_slice($src_parts, $j, $sc - $j - 1));
        if ($relative) {
            $relative .= '/';
        }
        $processed[$src] = preg_replace("/url\\((\\'){0,1}/", 'url($1' . $relative, $content);
    }
    $service_url = "http://reducisaurus.appspot.com/css";
    $options = array('file' => implode("\n\n", $processed));
    $result = Q_Utils::post($service_url, $options);
    if ($error = substr($result, 0, 5) === 'Error') {
        throw new Q_Exception("Reducisaurus:\n" . $result);
    }
    return $result;
}
function Q_filters_googleClosureCompiler($params)
{
    $content = implode("\n\n", $params['parts']);
    $compilation_level = isset($params['compilation_level']) ? $params['compilation_level'] : 'SIMPLE_OPTIMIZATIONS';
    $service_url = "http://closure-compiler.appspot.com/compile";
    $options = array('js_code' => $content, 'compilation_level' => $compilation_level, 'output_format' => 'text', 'output_info' => 'compiled_code');
    $result = Q_Utils::post($service_url, $options);
    if ($error = substr($result, 0, 5) === 'Error') {
        throw new Q_Exception("Google Closure Compiler:\n" . $result);
    }
    if (!trim($result)) {
        $options['output_info'] = 'errors';
        throw new Q_Exception("Google Closure Compiler:\n" . Q_Utils::post($service_url, $options));
    }
    return $result;
}