-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.css.php
More file actions
79 lines (71 loc) · 1.69 KB
/
Copy pathclass.css.php
File metadata and controls
79 lines (71 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace Module\CSS;
/**
* Concatinates and compresses CSS.
*
* ### Usage
*
* <code>
* require_once('class.css.php');
*
* $c = new \Module\CSS\Compress();
* $files = explode("&", $_GET['css']);
*
* foreach ($files as $file) {
* $c->add(DIRBASE . "/css/" . $file . ".css");
* }
*
* $c->show();
* </code>
*
* ### Changelog
* ## Version 1.2
* * Added namespacing
*
* ## Version 1.1
* * Added the usage and date sections to documentation
*
* @date June 16, 2014
* @author Jaime A. Rodriguez <hi.i.am.jaime@gmail.com>
* @version 1.1
* @license http://opensource.org/licenses/MIT
* @internal
*/
class Compress {
/**
* An array of CSS files
*
* @private
* @var array
*/
private $files = array();
/**
* Adds a file to the CSS array for compression and concatenation
* @param string $file The name of the CSS file
*/
public function add($file) {
array_push($this->files, $file);
}
/**
* Outputs the compressed CSS to the browser
* @return void nothing
*/
public function show() {
$buffer = "";
// Load the files
foreach ($this->files as $file) {
$buffer .= file_get_contents($file);
}
// Compress the files
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer); // comments
$buffer = str_replace(': ', ':', $buffer); // space after colon
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer); // whitespace
// Enable zip compression
ob_start("ob_gzhandler");
header('Cache-Control: public');
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 86400) . ' GMT'); // 1 day
header("Content-type: text/css");
// Output to browser
echo($buffer);
}
}