function my_log($dir, $message) { $time = date('Y-m-d H:i:s', time()); $message = $time . ' ' . $message . PHP_EOL; file_force_contents($dir, $message); }
/** * 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); }