text changes to registration mail content
[namibia] / public / min / lib / Minify / CSS.php
1 <?php
2 /**
3  * Class Minify_CSS  
4  * @package Minify
5  */
6
7 /**
8  * Minify CSS
9  *
10  * This class uses Minify_CSS_Compressor and Minify_CSS_UriRewriter to 
11  * minify CSS and rewrite relative URIs.
12  * 
13  * @package Minify
14  * @author Stephen Clay <steve@mrclay.org>
15  * @author http://code.google.com/u/1stvamp/ (Issue 64 patch)
16  */
17 class Minify_CSS {
18     
19     /**
20      * Minify a CSS string
21      * 
22      * @param string $css
23      * 
24      * @param array $options available options:
25      * 
26      * 'preserveComments': (default true) multi-line comments that begin
27      * with "/*!" will be preserved with newlines before and after to
28      * enhance readability.
29      *
30      * 'removeCharsets': (default true) remove all @charset at-rules
31      * 
32      * 'prependRelativePath': (default null) if given, this string will be
33      * prepended to all relative URIs in import/url declarations
34      * 
35      * 'currentDir': (default null) if given, this is assumed to be the
36      * directory of the current CSS file. Using this, minify will rewrite
37      * all relative URIs in import/url declarations to correctly point to
38      * the desired files. For this to work, the files *must* exist and be
39      * visible by the PHP process.
40      *
41      * 'symlinks': (default = array()) If the CSS file is stored in 
42      * a symlink-ed directory, provide an array of link paths to
43      * target paths, where the link paths are within the document root. Because 
44      * paths need to be normalized for this to work, use "//" to substitute 
45      * the doc root in the link paths (the array keys). E.g.:
46      * <code>
47      * array('//symlink' => '/real/target/path') // unix
48      * array('//static' => 'D:\\staticStorage')  // Windows
49      * </code>
50      *
51      * 'docRoot': (default = $_SERVER['DOCUMENT_ROOT'])
52      * see Minify_CSS_UriRewriter::rewrite
53      * 
54      * @return string
55      */
56     public static function minify($css, $options = array()) 
57     {
58         $options = array_merge(array(
59             'compress' => true,
60             'removeCharsets' => true,
61             'preserveComments' => true,
62             'currentDir' => null,
63             'docRoot' => $_SERVER['DOCUMENT_ROOT'],
64             'prependRelativePath' => null,
65             'symlinks' => array(),
66         ), $options);
67         
68         if ($options['removeCharsets']) {
69             $css = preg_replace('/@charset[^;]+;\\s*/', '', $css);
70         }
71         if ($options['compress']) {
72             if (! $options['preserveComments']) {
73                 $css = Minify_CSS_Compressor::process($css, $options);
74             } else {
75                 $css = Minify_CommentPreserver::process(
76                     $css
77                     ,array('Minify_CSS_Compressor', 'process')
78                     ,array($options)
79                 );
80             }
81         }
82         if (! $options['currentDir'] && ! $options['prependRelativePath']) {
83             return $css;
84         }
85         if ($options['currentDir']) {
86             return Minify_CSS_UriRewriter::rewrite(
87                 $css
88                 ,$options['currentDir']
89                 ,$options['docRoot']
90                 ,$options['symlinks']
91             );  
92         } else {
93             return Minify_CSS_UriRewriter::prepend(
94                 $css
95                 ,$options['prependRelativePath']
96             );
97         }
98     }
99 }