PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / mrclay / minify / lib / Minify / CSS.php

CSS.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/mrclay/minify/lib/Minify/CSS.php

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