Linux multi-monitor fullscreen support
[ryzomcore.git] / web / public_php / webtt / app / webroot / css.php
blobaae68cba8241e8057dcd1975869dacb16f7271a1
1 <?php
2 /**
3 * CSS helping functions
5 * PHP versions 4 and 5
7 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
8 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
10 * Licensed under The MIT License
11 * Redistributions of files must retain the above copyright notice.
13 * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
14 * @link http://cakephp.org CakePHP(tm) Project
15 * @package cake
16 * @subpackage cake.app.webroot
17 * @since CakePHP(tm) v 0.2.9
18 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
20 if (!defined('CAKE_CORE_INCLUDE_PATH')) {
21 header('HTTP/1.1 404 Not Found');
22 exit('File Not Found');
25 /**
26 * Ensure required classes are available.
28 if (!class_exists('File')) {
29 uses('file');
32 /**
33 * Make clean CSS
35 * @param unknown_type $path
36 * @param unknown_type $name
37 * @return unknown
39 function make_clean_css($path, $name) {
40 App::import('Vendor', 'csspp' . DS . 'csspp');
41 $data = file_get_contents($path);
42 $csspp = new csspp();
43 $output = $csspp->compress($data);
44 $ratio = 100 - (round(strlen($output) / strlen($data), 3) * 100);
45 $output = " /* file: $name, ratio: $ratio% */ " . $output;
46 return $output;
48 /**
49 * Write CSS cache
51 * @param unknown_type $path
52 * @param unknown_type $content
53 * @return unknown
55 function write_css_cache($path, $content) {
56 if (!is_dir(dirname($path))) {
57 mkdir(dirname($path));
59 $cache = new File($path);
60 return $cache->write($content);
63 if (preg_match('|\.\.|', $url) || !preg_match('|^ccss/(.+)$|i', $url, $regs)) {
64 die('Wrong file name.');
67 $filename = 'css/' . $regs[1];
68 $filepath = CSS . $regs[1];
69 $cachepath = CACHE . 'css' . DS . str_replace(array('/','\\'), '-', $regs[1]);
71 if (!file_exists($filepath)) {
72 die('Wrong file name.');
75 if (file_exists($cachepath)) {
76 $templateModified = filemtime($filepath);
77 $cacheModified = filemtime($cachepath);
79 if ($templateModified > $cacheModified) {
80 $output = make_clean_css($filepath, $filename);
81 write_css_cache($cachepath, $output);
82 } else {
83 $output = file_get_contents($cachepath);
85 } else {
86 $output = make_clean_css($filepath, $filename);
87 write_css_cache($cachepath, $output);
88 $templateModified = time();
91 header("Date: " . date("D, j M Y G:i:s ", $templateModified) . 'GMT');
92 header("Content-Type: text/css");
93 header("Expires: " . gmdate("D, d M Y H:i:s", time() + DAY) . " GMT");
94 header("Cache-Control: max-age=86400, must-revalidate"); // HTTP/1.1
95 header("Pragma: cache"); // HTTP/1.0
96 print $output;