Example #1
1
 /**
  * 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);
 }
Example #3
0
<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>
Example #4
0
//
// 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 = minifyJsDefault($arraySourceFilePath);
	write_content_utf8($url_min, $dataAll);

	//
	// Minifier with service
	//*/
	$arrOption = array(
		'beautify' => '', // Beautify output/specify output options - Làm đẹp code
		'mangle' => '1', // Mangle names/pass mangler options - Đổi(chặt) tên biến để min
		'reserved' => '', // Giữ lại 1 số tên biến từ mangle '$,require,exports'
		'compress' => '1', // Enable compressor/pass compressor options. - Nén
		'comments' => '', // Giữ lại comment có thể dùng 'all' hoặc pregmath '/foo|bar/'
		'packer' => '1', // Co the dung them JS Packer dang compress js eval - Dang nay sieu nen nhung client phai giai nen
		);

	minifyJS($dataAll, $url_min, $arrOption);
	//*/

}

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