PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.4.2
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.4.2
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 / CSSmin.php

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

89 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class Minify_CSSmin
4 * @package Minify
5 */
6
7 use tubalmartin\CssMin\Minifier as CSSmin;
8
9 /**
10 * Wrapper for CSSmin
11 *
12 * This class uses CSSmin and Minify_CSS_UriRewriter to minify CSS and rewrite relative URIs.
13 *
14 * @package Minify
15 * @author Stephen Clay <[email protected]>
16 */
17 class Minify_CSSmin
18 {
19
20 /**
21 * Minify a CSS string
22 *
23 * @param string $css
24 *
25 * @param array $options available options:
26 *
27 * 'removeCharsets': (default true) remove all @charset at-rules
28 *
29 * 'prependRelativePath': (default null) if given, this string will be
30 * prepended to all relative URIs in import/url declarations
31 *
32 * 'currentDir': (default null) if given, this is assumed to be the
33 * directory of the current CSS file. Using this, minify will rewrite
34 * all relative URIs in import/url declarations to correctly point to
35 * the desired files. For this to work, the files *must* exist and be
36 * visible by the PHP process.
37 *
38 * 'symlinks': (default = array()) If the CSS file is stored in
39 * a symlink-ed directory, provide an array of link paths to
40 * target paths, where the link paths are within the document root. Because
41 * paths need to be normalized for this to work, use "//" to substitute
42 * the doc root in the link paths (the array keys). E.g.:
43 * <code>
44 * array('//symlink' => '/real/target/path') // unix
45 * array('//static' => 'D:\\staticStorage') // Windows
46 * </code>
47 *
48 * 'docRoot': (default = $_SERVER['DOCUMENT_ROOT'])
49 * see Minify_CSS_UriRewriter::rewrite
50 *
51 * @return string
52 */
53 public static function minify($css, $options = array())
54 {
55 $options = array_merge(array(
56 'compress' => true,
57 'removeCharsets' => true,
58 'currentDir' => null,
59 'docRoot' => $_SERVER['DOCUMENT_ROOT'],
60 'prependRelativePath' => null,
61 'symlinks' => array(),
62 ), $options);
63
64 if ($options['removeCharsets']) {
65 $css = preg_replace('/@charset[^;]+;\\s*/', '', $css);
66 }
67 if ($options['compress']) {
68 $obj = new CSSmin();
69 $css = $obj->run($css);
70 }
71 if (! $options['currentDir'] && ! $options['prependRelativePath']) {
72 return $css;
73 }
74 if ($options['currentDir']) {
75 return Minify_CSS_UriRewriter::rewrite(
76 $css,
77 $options['currentDir'],
78 $options['docRoot'],
79 $options['symlinks']
80 );
81 }
82
83 return Minify_CSS_UriRewriter::prepend(
84 $css,
85 $options['prependRelativePath']
86 );
87 }
88 }
89