Exemple #1
0
function output_file($file_item, $current_path, $type)
{
    global $ignore_files, $template_exts, $total_reduce_size;
    if ($current_path !== '') {
        foreach ((array) $file_item['file'] as $file_name => $file_info) {
            if (false === strpos($current_path, 'views') && $file_name[0] === '_' || $file_name[0] == '.') {
                continue;
            }
            if (in_array($file_name, $ignore_files)) {
                continue;
            }
            $file_path = $current_path . '/' . $file_name;
            $result = true;
            $file_skiped = false;
            $ext = get_ext($file_name);
            if ('all' != $type && $ext != $type) {
                continue;
            }
            if ($ext == 'css') {
                if (strpos($file_name, 'min.') === 0) {
                    $result = compress_css($file_path);
                } else {
                    $file_skiped = true;
                }
            } elseif ($ext == 'js') {
                if (strpos($file_name, 'min.') === 0) {
                    $result = compress_js($file_path);
                } else {
                    $file_skiped = true;
                }
            } elseif ($ext == 'png') {
                compress_png($file_path);
            } elseif (in_array($ext, $template_exts)) {
                compress_template($file_path);
            } else {
                copy(ROOT_PATH . $file_path, OUTPUT_DIR . $file_path);
            }
            $file_size = 0;
            if ($file_skiped === false) {
                if (file_exists(OUTPUT_DIR . $file_path)) {
                    $file_size = filesize(OUTPUT_DIR . $file_path);
                    $total_reduce_size += $file_info['infor']['file_size'] - $file_size;
                    if ($file_size <= 0) {
                        $file_size = 'b style="color:#ff0000">' . $file_size . '</b>';
                    } else {
                        $file_size = human_file_size($file_size);
                    }
                } else {
                    $result = false;
                }
            }
            if (false === $result) {
                echo '<p style="color:#ff0000;font-weight:bold">' . $file_path . ' Error</p>';
            } else {
                if ($file_skiped === false) {
                    echo $file_path . ' <b style="color:#1EBC16">OK</b> <span style="color:#888">(' . human_file_size($file_info['infor']['file_size']) . ' → ' . $file_size . ')</span><br />';
                } else {
                    echo '<span style="color:#aaa">' . $file_path . ' <b>Skiped</b></span><br />';
                }
            }
        }
    }
    foreach ((array) $file_item['dir'] as $dir_name => $dir) {
        if ($dir_name[0] === '_' || $dir_name[0] == '.') {
            continue;
        }
        if (in_array($dir_name, $ignore_files)) {
            continue;
        }
        $dir_path = $current_path . '/' . $dir_name;
        echo '<h2>' . $dir_path . '</h2>';
        make_dir($dir_path, OUTPUT_DIR);
        output_file($dir, $dir_path, $type);
    }
}
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();
$is_html = (bool) preg_match('/^.+\\.js\\.html(\\?.*)?$/i', $uri, $temp_array);
if (preg_match('/^.+\\.(js|css)/i', $uri, $temp_array)) {
    $static_type = $temp_array[1];
    /* scripts || styles */
    $file_path = $temp_array[0];
    $file_path = preg_replace('/\\.min/', '', $file_path);
    $static_contents = get_static_content($file_path);
    $compressed_result = compress_js($file_path, true, !$is_html);
    $compressed_contents = $compressed_result['output'];
    $origin_size = strlen($static_contents);
    $compressed_size = strlen($compressed_contents);
    $origin_size_label = human_file_size($origin_size);
    $compressed_size_label = human_file_size($compressed_size);
    $compress_saving = 100 - (int) ($compressed_size / $origin_size * 10000) / 100;
}
if (!$is_html) {
    @header('Content-Type: application/x-javascript');
    die($compressed_contents);
}
?>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><?php 
echo $file_path;