Projekt

Obecné

Profil

Stáhnout (2.87 KB) Statistiky
| Větev: | Tag: | Revize:
1
<?php
2
/* SVN FILE: $Id: css.php 4409 2007-02-02 13:20:59Z phpnut $ */
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://www.cakephp.org/>
11
 * Copyright 2005-2007, Cake Software Foundation, Inc.
12
 *								1785 E. Sahara Avenue, Suite 490-204
13
 *								Las Vegas, Nevada 89104
14
 *
15
 * Licensed under The MIT License
16
 * Redistributions of files must retain the above copyright notice.
17
 *
18
 * @filesource
19
 * @copyright		Copyright 2005-2007, Cake Software Foundation, Inc.
20
 * @link				http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
21
 * @package			cake
22
 * @subpackage		cake.app.webroot
23
 * @since			CakePHP(tm) v 0.2.9
24
 * @version			$Revision: 4409 $
25
 * @modifiedby		$LastChangedBy: phpnut $
26
 * @lastmodified	$Date: 2007-02-02 07:20:59 -0600 (Fri, 02 Feb 2007) $
27
 * @license			http://www.opensource.org/licenses/mit-license.php The MIT License
28
 */
29
/**
30
 * Enter description here...
31
 */
32
	require(CONFIGS . 'paths.php');
33
	require(CAKE . 'basics.php');
34
	require(LIBS . 'folder.php');
35
	require(LIBS . 'file.php');
36
	require(LIBS . 'legacy.php');
37
/**
38
 * Enter description here...
39
 *
40
 * @param unknown_type $path
41
 * @param unknown_type $name
42
 * @return unknown
43
 */
44
	function make_clean_css($path, $name) {
45
		 require(VENDORS . 'csspp' . DS . 'csspp.php');
46
		 $data  =file_get_contents($path);
47
		 $csspp =new csspp();
48
		 $output=$csspp->compress($data);
49
		 $ratio =100 - (round(strlen($output) / strlen($data), 3) * 100);
50
		 $output=" /* file: $name, ratio: $ratio% */ " . $output;
51
		 return $output;
52
	}
53
/**
54
 * Enter description here...
55
 *
56
 * @param unknown_type $path
57
 * @param unknown_type $content
58
 * @return unknown
59
 */
60
	function write_css_cache($path, $content) {
61
		 if (!is_dir(dirname($path))) {
62
			  mkdir(dirname($path));
63
		 }
64
		 $cache=new File($path);
65
		 return $cache->write($content);
66
	}
67

    
68
	if (preg_match('|\.\.|', $url) || !preg_match('|^ccss/(.+)$|i', $url, $regs)) {
69
		 die('Wrong file name.');
70
	}
71

    
72
	$filename = 'css/' . $regs[1];
73
	$filepath = CSS . $regs[1];
74
	$cachepath = CACHE . 'css' . DS . str_replace(array('/','\\'), '-', $regs[1]);
75

    
76
	if (!file_exists($filepath)) {
77
		 die('Wrong file name.');
78
	}
79

    
80
	if (file_exists($cachepath)) {
81
		 $templateModified=filemtime($filepath);
82
		 $cacheModified   =filemtime($cachepath);
83

    
84
		 if ($templateModified > $cacheModified) {
85
			  $output=make_clean_css($filepath, $filename);
86
			  write_css_cache($cachepath, $output);
87
		 } else {
88
			  $output = file_get_contents($cachepath);
89
		 }
90
	} else {
91
		 $output=make_clean_css($filepath, $filename);
92
		 write_css_cache($cachepath, $output);
93
	}
94
	header("Date: " . date("D, j M Y G:i:s ", $templateModified) . 'GMT');
95
	header("Content-Type: text/css");
96
	header("Expires: " . gmdate("D, j M Y H:i:s", time() + DAY) . " GMT");
97
	header("Cache-Control: cache"); // HTTP/1.1
98
	header("Pragma: cache");        // HTTP/1.0
99
	print $output;
100
?>
(10-10/25)