2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2010-05-29 15:20:28 +00:00
|
|
|
* CSS Functions
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:38:58 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package app.webroot
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 0.2.9
|
2009-11-06 06:51:51 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
|
|
|
|
header('HTTP/1.1 404 Not Found');
|
|
|
|
exit('File Not Found');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-05-29 15:10:48 +00:00
|
|
|
* Ensure required files are included
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-06-11 15:46:31 +00:00
|
|
|
if (!class_exists('File')) {
|
2009-07-23 20:53:37 +00:00
|
|
|
require LIBS . 'file.php';
|
2008-06-11 15:46:31 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-05-29 15:10:48 +00:00
|
|
|
* Make clean CSS
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @param unknown_type $path
|
|
|
|
* @param unknown_type $name
|
|
|
|
* @return unknown
|
|
|
|
*/
|
|
|
|
function make_clean_css($path, $name) {
|
2008-10-09 03:43:42 +00:00
|
|
|
App::import('Vendor', 'csspp' . DS . 'csspp');
|
2008-05-30 11:40:08 +00:00
|
|
|
$data = file_get_contents($path);
|
|
|
|
$csspp = new csspp();
|
|
|
|
$output = $csspp->compress($data);
|
|
|
|
$ratio = 100 - (round(strlen($output) / strlen($data), 3) * 100);
|
|
|
|
$output = " /* file: $name, ratio: $ratio% */ " . $output;
|
|
|
|
return $output;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-05-29 15:10:48 +00:00
|
|
|
* Write CSS cache
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @param unknown_type $path
|
|
|
|
* @param unknown_type $content
|
|
|
|
* @return unknown
|
|
|
|
*/
|
|
|
|
function write_css_cache($path, $content) {
|
|
|
|
if (!is_dir(dirname($path))) {
|
|
|
|
mkdir(dirname($path));
|
|
|
|
}
|
|
|
|
$cache = new File($path);
|
|
|
|
return $cache->write($content);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preg_match('|\.\.|', $url) || !preg_match('|^ccss/(.+)$|i', $url, $regs)) {
|
2009-11-19 22:05:59 +00:00
|
|
|
exit('Wrong file name.');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$filename = 'css/' . $regs[1];
|
|
|
|
$filepath = CSS . $regs[1];
|
|
|
|
$cachepath = CACHE . 'css' . DS . str_replace(array('/','\\'), '-', $regs[1]);
|
|
|
|
|
|
|
|
if (!file_exists($filepath)) {
|
2009-11-19 22:05:59 +00:00
|
|
|
exit('Wrong file name.');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (file_exists($cachepath)) {
|
|
|
|
$templateModified = filemtime($filepath);
|
|
|
|
$cacheModified = filemtime($cachepath);
|
|
|
|
|
|
|
|
if ($templateModified > $cacheModified) {
|
|
|
|
$output = make_clean_css($filepath, $filename);
|
|
|
|
write_css_cache($cachepath, $output);
|
|
|
|
} else {
|
|
|
|
$output = file_get_contents($cachepath);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$output = make_clean_css($filepath, $filename);
|
|
|
|
write_css_cache($cachepath, $output);
|
|
|
|
$templateModified = time();
|
|
|
|
}
|
|
|
|
|
|
|
|
header("Date: " . date("D, j M Y G:i:s ", $templateModified) . 'GMT');
|
|
|
|
header("Content-Type: text/css");
|
|
|
|
header("Expires: " . gmdate("D, j M Y H:i:s", time() + DAY) . " GMT");
|
2008-11-21 04:29:22 +00:00
|
|
|
header("Cache-Control: max-age=86400, must-revalidate"); // HTTP/1.1
|
2008-05-30 11:40:08 +00:00
|
|
|
header("Pragma: cache"); // HTTP/1.0
|
|
|
|
print $output;
|