Example #1
0
<?php

/* 输出合并后的js和css文件 */
require '../settings.php';
$uri = $_SERVER["REQUEST_URI"];
$uri = preg_replace('/^\\' . WEB_PATH . 'i', '', $uri);
$pos = strpos($uri, '?');
if ($pos !== FALSE) {
    $uri = substr($uri, 0, $pos);
}
$temp_array = array();
if (preg_match('/^.+\\.(js|css)/i', $uri, $temp_array)) {
    $static_type = $temp_array[1];
    /* scripts || styles */
    $file_path = $temp_array[0];
    $static_contents = get_static_content($file_path);
    if ('js' == $static_type) {
        @header('Content-Type: application/x-javascript');
    } else {
        @header('Content-Type: text/css');
    }
    echo $static_contents;
}
Example #2
0
function compress_css($file_path)
{
    $file_path = '/' . ltrim($file_path, '\\/\\');
    $static_contents = get_static_content($file_path, true);
    $output_file = OUTPUT_DIR . ltrim($file_path, '\\/\\');
    $file_full_path = rtrim(ROOT_PATH, '\\/\\') . $file_path;
    $temp_file = $file_full_path . '____';
    write_file($temp_file, $static_contents);
    $static_contents = null;
    $compiler_command = 'java -jar ' . INCLUDE_PATH . 'cmd/yuicompressor-2.4.6.jar ' . $temp_file . ' -v --type css -o ' . $output_file;
    exec($compiler_command, $return, $code);
    unlink($temp_file);
    if (1 == $code) {
        return false;
    }
    return true;
}