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