1: <?php
2: /* SVN FILE: $Id$ */
3: /**
4: * Short description for file.
5: *
6: * Long description for file
7: *
8: * PHP versions 4 and 5
9: *
10: * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
11: * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
12: *
13: * Licensed under The MIT License
14: * Redistributions of files must retain the above copyright notice.
15: *
16: * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
17: * @link http://cakephp.org CakePHP(tm) Project
18: * @package cake
19: * @subpackage cake.app.webroot
20: * @since CakePHP(tm) v 0.2.9
21: * @version $Revision$
22: * @modifiedby $LastChangedBy$
23: * @lastmodified $Date$
24: * @license http://www.opensource.org/licenses/mit-license.php The MIT License
25: */
26: if (!defined('CAKE_CORE_INCLUDE_PATH')) {
27: header('HTTP/1.1 404 Not Found');
28: exit('File Not Found');
29: }
30: /**
31: * Enter description here...
32: */
33: if (!class_exists('File')) {
34: uses('file');
35: }
36: /**
37: * Enter description here...
38: *
39: * @param unknown_type $path
40: * @param unknown_type $name
41: * @return unknown
42: */
43: function make_clean_css($path, $name) {
44: App::import('Vendor', 'csspp' . DS . 'csspp');
45: $data = file_get_contents($path);
46: $csspp = new csspp();
47: $output = $csspp->compress($data);
48: $ratio = 100 - (round(strlen($output) / strlen($data), 3) * 100);
49: $output = " /* file: $name, ratio: $ratio% */ " . $output;
50: return $output;
51: }
52: /**
53: * Enter description here...
54: *
55: * @param unknown_type $path
56: * @param unknown_type $content
57: * @return unknown
58: */
59: function write_css_cache($path, $content) {
60: if (!is_dir(dirname($path))) {
61: mkdir(dirname($path));
62: }
63: $cache = new File($path);
64: return $cache->write($content);
65: }
66:
67: if (preg_match('|\.\.|', $url) || !preg_match('|^ccss/(.+)$|i', $url, $regs)) {
68: exit('Wrong file name.');
69: }
70:
71: $filename = 'css/' . $regs[1];
72: $filepath = CSS . $regs[1];
73: $cachepath = CACHE . 'css' . DS . str_replace(array('/','\\'), '-', $regs[1]);
74:
75: if (!file_exists($filepath)) {
76: exit('Wrong file name.');
77: }
78:
79: if (file_exists($cachepath)) {
80: $templateModified = filemtime($filepath);
81: $cacheModified = filemtime($cachepath);
82:
83: if ($templateModified > $cacheModified) {
84: $output = make_clean_css($filepath, $filename);
85: write_css_cache($cachepath, $output);
86: } else {
87: $output = file_get_contents($cachepath);
88: }
89: } else {
90: $output = make_clean_css($filepath, $filename);
91: write_css_cache($cachepath, $output);
92: $templateModified = time();
93: }
94:
95: header("Date: " . date("D, j M Y G:i:s ", $templateModified) . 'GMT');
96: header("Content-Type: text/css");
97: header("Expires: " . gmdate("D, j M Y H:i:s", time() + DAY) . " GMT");
98: header("Cache-Control: max-age=86400, must-revalidate"); // HTTP/1.1
99: header("Pragma: cache"); // HTTP/1.0
100: print $output;
101: ?>