/**
  * Take a collection of CSS or JS files and create and return the filename of an aggregation file which
  * contains all of their individual contents.
  *
  * @param array $files An array of files to aggregate.
  * @param string $type The type of files we are aggregating ("css" or "js").
  * @return array An array containing a single element, which is the path to the aggregation file.
  */
 protected function aggregateFiles($files, $type)
 {
     // Construct an array of filenames, and get the maximum last modifiction time of all the files.
     $filenames = array();
     $lastModTime = 0;
     foreach ($files as $filename) {
         $filenames[] = str_replace(".", "", pathinfo($filename, PATHINFO_FILENAME));
         $lastModTime = max($lastModTime, filemtime(PATH_ROOT . "/" . $filename));
     }
     // Construct a filename for the aggregation file based on the individual filenames.
     $file = PATH_ROOT . "/cache/{$type}/" . implode(",", $filenames) . ".{$type}";
     // If this file doesn't exist, or if it is out of date, generate and write it.
     if (!file_exists($file) or filemtime($file) < $lastModTime) {
         $contents = "";
         // Get the contents of each of the files, fixing up image URL paths for CSS files.
         foreach ($files as $f) {
             $content = file_get_contents(PATH_ROOT . "/" . $f);
             if ($type == "css") {
                 $content = preg_replace("/url\\(('?)/i", "url(\$1" . getResource(pathinfo($f, PATHINFO_DIRNAME) . "/"), $content);
             }
             $contents .= $content . " ";
         }
         // Minify and write the contents.
         file_force_contents($file, $type == "css" ? minifyCSS($contents) : minifyJS($contents));
     }
     return array($file);
 }
 /**
  * Take a collection of CSS or JS files and create and return the filename of an aggregation file which
  * contains all of their individual contents.
  *
  * @param array $files An array of files to aggregate.
  * @param string $type The type of files we are aggregating ("css" or "js").
  * @return array An array containing a single element, which is the path to the aggregation file.
  */
 protected function aggregateFiles($files, $type)
 {
     // Construct an array of filenames, and get the maximum last modifiction time of all the files.
     $filenames = array();
     $lastModTime = 0;
     foreach ($files as $filename) {
         $filenames[] = str_replace(".", "", pathinfo($filename, PATHINFO_FILENAME));
         //$lastModTime = max($lastModTime, filemtime(PATH_ROOT."/".$filename));
     }
     $_name = implode("_", $filenames);
     $_name = substr($_name, 0, 5) . '_' . md5($_name);
     // Construct a filename for the aggregation file based on the individual filenames.
     $file = PATH_ROOT . "/cache/{$type}/" . $_name . ".{$type}";
     $filesae = "saekv://cache/{$type}/" . $_name . ".{$type}";
     // If this file doesn't exist, or if it is out of date, generate and write it. or filemtime($file) < $lastModTime
     //if (!file_exists($file)) {
     //先通过memcache判断是否生成了文件,节约在kvdb中读取的时间
     $key = md5($filesae);
     $_filenames = array();
     //load filename cache
     $narr = ET::$cache->filenames;
     if ($narr !== false && isset($narr["static_cache"])) {
         $_filenames = $narr["static_cache"];
     }
     //while $narr is empty create an new array
     if (empty($narr)) {
         $narr = array();
     }
     if (empty($_filenames) || $_filenames[$key] == false) {
         if (!file_exists($filesae)) {
             $contents = "";
             // Get the contents of each of the files, fixing up image URL paths for CSS files.
             foreach ($files as $f) {
                 $content = @file_get_contents(strpos($f, 'saekv://') === false ? PATH_ROOT . "/" . $f : $f);
                 if (!$content) {
                     continue;
                 }
                 if ($type == "css") {
                     $content = preg_replace("/url\\(('?)/i", "url(\$1" . getResource(pathinfo($f, PATHINFO_DIRNAME) . "/"), $content);
                 }
                 $contents .= $content . " ";
             }
             // Minify and write the contents.
             file_force_contents($filesae, $type == "css" ? minifyCSS($contents) : minifyJS($contents));
         }
         //memcache
         $_filenames[$key] = $key;
         //记录生成时间,以便自动更新浏览器缓存
         $_filenames['lasttime'][$key] = time();
         $narr["static_cache"] = $_filenames;
         //ET::$cache->store(ET::$cache->fname_key , $narr);
         ET::$cache->filenames = $narr;
         ET::$cache->fnamechanged = true;
         //ET::$cache->store('file_cache_'.$key, $key);
     }
     //}
     //获取生成时间
     $lastModTime = $_filenames['lasttime'][$key];
     if ($lastModTime) {
         $file .= '?t=' . $lastModTime;
     }
     //var_dump($file);
     //var_dump($_filenames);
     return array($file);
 }
Exemple #3
0
$SCSSFileTime = filemtime($SCSS);
$CSSFileTime = filemtime($CSS);
// Update CSS when needed.
if (!file_exists($CSS) or $SCSSFileTime > $CSSFileTime) {
    // Activate library.
    require_once $root . '/site/plugins/scssphp/scss.inc.php';
    $parser = new scssc();
    // Setting compression provided by library.
    $parser->setFormatter('scss_formatter_compressed');
    // Setting relative @import paths.
    $importPath = $root . '/assets/scss';
    $parser->addImportPath($importPath);
    // Place SCSS file in buffer.
    $buffer = file_get_contents($SCSS);
    // Compile content in buffer.
    $buffer = $parser->compile($buffer);
    // Minify the CSS even further.
    require_once $root . '/site/plugins/scssphp/minify.php';
    $buffer = minifyCSS($buffer);
    // Update CSS file.
    file_put_contents($CSS, $buffer);
}
?>
<link rel="stylesheet" property="stylesheet" href="<?php 
echo url($CSSKirbyPath);
?>
?version=<?php 
echo $CSSFileTime;
?>
">
<body style="font-family: monospace;">
<?php 
include_once "minifier.php";
/* FILES ARRAYs
 * Keys as input, Values as output */
$js = array("js/application.js" => "js/application.min.js", "js/main.js" => "js/main.min.js");
$css = array("css/application.css" => "css/application.min.css", "css/main.css" => "css/main.min.css");
minifyJS($js);
minifyCSS($css);
?>
</body>
Exemple #5
0
$check_edit = check_file_edit($file_check_edit, $file_check_type, $arraySourceFilePath);
// $check_edit = 1;

//
// Neu nhu trong list file co file nao bi sua thi thuc hien
if($check_edit != 0 || !is_file($url_min) || filesize($url_min) < 10 || time() - filemtime($url_min) > 900){

	//
	// Minifier Default
	$dataAll = minifyCssDefault($arraySourceFilePath);
	write_content_utf8($url_min, $dataAll);

	//
	// Minifier with service
	//*/
	$arrOption = array(
		'keep_line_breaks' => '', // Keep line breaks
		'remove_comment' => '1', // Remove all special comments, i.e. /*! comment /
		'remove_comment_except_first_comment' => '' // Remove all special comments but the first one
		);

	minifyCSS($arraySourceFilePath, $url_min, $arrOption);
	//*/

}

//
// Huy bien
unset($arrSourceFile, $arraySourceFilePath);

    $string = preg_replace('/ +/', ' ', $string);
    $string = preg_replace('/ ?([,:;{}]) ?/', '$1', $string);
    /* Kill Trailing Semicolon, Contributed by Oliver */
    $string = preg_replace('/;}/', '}', $string);
    /* Return Minified CSS */
    return $string;
}
$error_css_mini = false;
// simple securité
if (file_exists(@$prefix . 'layout/css/styles.css') && file_exists(@$prefix . 'layout/css/styles_mini.css') && is_writable(@$prefix . 'layout/css/styles_mini.css')) {
    $date_css = filemtime($prefix . 'layout/css/styles.css');
    // sélectionner le fichier et chopper son timestamp
    $date_css_mini = filemtime($prefix . 'layout/css/styles_mini.css');
    // ensuite comparer la date et le timestamp, voir si regeneration nécessaire
    if ($date_css > $date_css_mini) {
        // regen and minify
        $filename = $prefix . 'layout/css/styles.css';
        $handle = fopen($filename, "r");
        $content = fread($handle, filesize($filename));
        $result = minifyCSS($content);
        $fp = fopen($prefix . 'layout/css/styles_mini.css', 'w');
        fwrite($fp, $result);
        //define("_CSS_FILENAME",'styles_mini_'.$date_css.'.css');
        define("_CSS_FILENAME", 'styles_mini.css');
    } else {
        //define("_CSS_FILENAME",'styles_mini_'.$date_css.'.css');
        define("_CSS_FILENAME", 'styles_mini.css');
    }
} else {
    define("_CSS_FILENAME", 'styles_20120909.css');
}