示例#1
0
<?php

list($script, $basePath, $type, $compressor, $inFile, $outFile) = $argv;
require $basePath . '/app/Mage.php';
Mage::app('admin')->setUseSessionInUrl(false);
if (file_exists($inFile) === false) {
    Mage::helper('ewminify/system')->log(Mage::helper('ewminify')->__('File does not exists: %s', $inFile));
    exit;
}
$contents = file_get_contents($inFile);
Extendware_EWMinify_Model_Minify::setDisableExternalMinifier(true);
$minifiedContents = null;
if ($type == 'js') {
    $minifiedContents = Extendware_EWMinify_Model_Minify::js($contents, array(), $compressor);
} elseif ($type == 'css') {
    $minifiedContents = Extendware_EWMinify_Model_Minify::css($contents, array(), $compressor);
}
if ($minifiedContents !== null) {
    if (file_put_contents($outFile, $minifiedContents, LOCK_EX) !== false) {
        echo 'OK';
    } else {
        @unlink($outFile);
    }
}
示例#2
0
 private function minifyCss($fileName, array $files = array(), $cssCompressor = 'none')
 {
     $this->canSaveCache = false;
     $fileContents = null;
     $rawFile = $this->getMinifyCacheDirectory() . DS . 'css' . DS . $fileName . '.source';
     if (file_exists($rawFile) === false) {
         foreach ($files as $file) {
             $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
             if (in_array($ext, array('css'))) {
                 $fileContents .= @Extendware_EWMinify_Model_Minify::cssRewriteUri(self::getFileContents($file), $this->getArea(), dirname($file)) . "\n";
             }
         }
         @file_put_contents($rawFile, $fileContents);
     }
     if (!$fileContents) {
         $fileContents = file_get_contents($rawFile);
     }
     if (Mage::helper('ewminify')->lock() === false) {
         $fileName = basename($fileName, '.css') . '-raw.css';
         return array($fileName, $fileContents);
     }
     $fileContents = Extendware_EWMinify_Model_Minify::css($fileContents, array(), $cssCompressor);
     Mage::helper('ewminify')->unlock();
     return array($fileName, $fileContents);
 }