예제 #1
0
function cssUrl()
{
    $srcs = func_get_args();
    if (ENV_MINIFY_CSS) {
        foreach ($srcs as $key => $value) {
            if (strpos($value, '.min.') !== false) {
                continue;
            }
            $minifiedBasename = str_replace('.css', '.min.css', $value);
            $minifiedFilename = ENV_DIR_CSS . '/' . $minifiedBasename;
            $developmentFilename = ENV_DIR_CSS . '/' . $value;
            if (!file_exists($minifiedFilename) && file_exists($developmentFilename)) {
                file_put_contents($minifiedFilename, minifyCss(file_get_contents($developmentFilename)));
                $srcs[$key] = $minifiedBasename;
            } else {
                if (file_exists($minifiedFilename)) {
                    $srcs[$key] = $minifiedBasename;
                }
            }
        }
    }
    $urls = makeUrl($srcs, ENV_DIR_CSS);
    if (count($urls) == 1) {
        return $urls[0];
    } else {
        return $urls;
    }
}
예제 #2
0
/**
 * Combine files
 *
 * @param array $files
 * @param string $prefix
 * @param string $ext
 * @return string
 */
function combineFiles(array $files, $prefix, $ext)
{
    $baseDir = getBaseDir($prefix) . '/';
    $cacheDir = getCacheDir();
    $filesKey = md5(serialize($files)) . '.' . $ext;
    $noCache = empty($_GET['nocache']) ? false : true;
    if (!$noCache && file_exists($cacheDir . $filesKey) && filemtime($cacheDir . $filesKey) + getRefreshTime() > time()) {
        $allData = file_get_contents($cacheDir . $filesKey);
    } else {
        $allData = '';
        foreach ($files as $file) {
            if (!file_exists($baseDir . $file)) {
                continue;
            }
            $data = file_get_contents($baseDir . $file);
            if ($ext == 'css') {
                $data = translateUrlInCss($data, $file, $prefix);
            }
            if ($allData) {
                $allData .= "\n\n";
            }
            $allData .= $data;
        }
        if ($ext == 'css') {
            $allData = minifyCss($allData);
        } else {
            $allData = minifyJs($allData);
        }
        if (!$noCache) {
            file_put_contents($cacheDir . $filesKey, $allData);
        }
    }
    echo $allData;
}