css.php
Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 require(CONFIGS . 'paths.php');
00033 require(CAKE . 'basics.php');
00034 require(LIBS . 'folder.php');
00035 require(LIBS . 'file.php');
00036 require(LIBS . 'legacy.php');
00037
00038
00039
00040
00041
00042
00043
00044 function make_clean_css($path, $name) {
00045 require(VENDORS . 'csspp' . DS . 'csspp.php');
00046 $data =file_get_contents($path);
00047 $csspp =new csspp();
00048 $output=$csspp->compress($data);
00049 $ratio =100 - (round(strlen($output) / strlen($data), 3) * 100);
00050 $output=" /* file: $name, ratio: $ratio% */ " . $output;
00051 return $output;
00052 }
00053
00054
00055
00056
00057
00058
00059
00060 function write_css_cache($path, $content) {
00061 if (!is_dir(dirname($path))) {
00062 mkdir(dirname($path));
00063 }
00064 $cache=new File($path);
00065 return $cache->write($content);
00066 }
00067
00068 if (preg_match('|\.\.|', $url) || !preg_match('|^ccss/(.+)$|i', $url, $regs)) {
00069 die('Wrong file name.');
00070 }
00071
00072 $filename = 'css/' . $regs[1];
00073 $filepath = CSS . $regs[1];
00074 $cachepath = CACHE . 'css' . DS . str_replace(array('/','\\'), '-', $regs[1]);
00075
00076 if (!file_exists($filepath)) {
00077 die('Wrong file name.');
00078 }
00079
00080 if (file_exists($cachepath)) {
00081 $templateModified=filemtime($filepath);
00082 $cacheModified =filemtime($cachepath);
00083
00084 if ($templateModified > $cacheModified) {
00085 $output=make_clean_css($filepath, $filename);
00086 write_css_cache($cachepath, $output);
00087 } else {
00088 $output = file_get_contents($cachepath);
00089 }
00090 } else {
00091 $output=make_clean_css($filepath, $filename);
00092 write_css_cache($cachepath, $output);
00093 }
00094 header("Date: " . date("D, j M Y G:i:s ", $templateModified) . 'GMT');
00095 header("Content-Type: text/css");
00096 header("Expires: " . gmdate("D, j M Y H:i:s", time() + DAY) . " GMT");
00097 header("Cache-Control: cache");
00098 header("Pragma: cache");
00099 print $output;
00100 ?>