~ubuntu-branches/ubuntu/trusty/moodle/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/minify/lib/Minify/CSS.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2013-07-19 08:52:46 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130719085246-yebwditc2exoap2r
Tags: 2.5.1-1
* New upstream version: 2.5.1.
  - Fixes security issues:
    CVE-2013-2242 CVE-2013-2243 CVE-2013-2244 CVE-2013-2245
    CVE-2013-2246
* Depend on apache2 instead of obsolete apache2-mpm-prefork.
* Use packaged libphp-phpmailer (closes: #429339), adodb,
  HTMLPurifier, PclZip.
* Update debconf translations, thanks Salvatore Merone, Pietro Tollot,
  Joe Hansen, Yuri Kozlov, Holger Wansing, Américo Monteiro,
  Adriano Rafael Gomes, victory, Michał Kułach.
  (closes: #716972, #716986, #717080, #717108, #717278)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
     * 'prependRelativePath': (default null) if given, this string will be
31
 
     * prepended to all relative URIs in import/url declarations
32
 
     * 
33
 
     * 'currentDir': (default null) if given, this is assumed to be the
34
 
     * directory of the current CSS file. Using this, minify will rewrite
35
 
     * all relative URIs in import/url declarations to correctly point to
36
 
     * the desired files. For this to work, the files *must* exist and be
37
 
     * visible by the PHP process.
38
 
     *
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>
48
 
     * 
49
 
     * @return string
50
 
     */
51
 
    public static function minify($css, $options = array()) 
52
 
    {
53
 
        require_once 'Minify/CSS/Compressor.php';
54
 
        if (isset($options['preserveComments']) 
55
 
            && !$options['preserveComments']) {
56
 
            $css = Minify_CSS_Compressor::process($css, $options);
57
 
        } else {
58
 
            require_once 'Minify/CommentPreserver.php';
59
 
            $css = Minify_CommentPreserver::process(
60
 
                $css
61
 
                ,array('Minify_CSS_Compressor', 'process')
62
 
                ,array($options)
63
 
            );
64
 
        }
65
 
        if (! isset($options['currentDir']) && ! isset($options['prependRelativePath'])) {
66
 
            return $css;
67
 
        }
68
 
        require_once 'Minify/CSS/UriRewriter.php';
69
 
        if (isset($options['currentDir'])) {
70
 
            return Minify_CSS_UriRewriter::rewrite(
71
 
                $css
72
 
                ,$options['currentDir']
73
 
                ,isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT']
74
 
                ,isset($options['symlinks']) ? $options['symlinks'] : array()
75
 
            );  
76
 
        } else {
77
 
            return Minify_CSS_UriRewriter::prepend(
78
 
                $css
79
 
                ,$options['prependRelativePath']
80
 
            );
81
 
        }
82
 
    }
83
 
}
 
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
            'removeCharsets' => true,
 
60
            'preserveComments' => true,
 
61
            'currentDir' => null,
 
62
            'docRoot' => $_SERVER['DOCUMENT_ROOT'],
 
63
            'prependRelativePath' => null,
 
64
            'symlinks' => array(),
 
65
        ), $options);
 
66
        
 
67
        if ($options['removeCharsets']) {
 
68
            $css = preg_replace('/@charset[^;]+;\\s*/', '', $css);
 
69
        }
 
70
        require_once 'Minify/CSS/Compressor.php';
 
71
        if (! $options['preserveComments']) {
 
72
            $css = Minify_CSS_Compressor::process($css, $options);
 
73
        } else {
 
74
            require_once 'Minify/CommentPreserver.php';
 
75
            $css = Minify_CommentPreserver::process(
 
76
                $css
 
77
                ,array('Minify_CSS_Compressor', 'process')
 
78
                ,array($options)
 
79
            );
 
80
        }
 
81
        if (! $options['currentDir'] && ! $options['prependRelativePath']) {
 
82
            return $css;
 
83
        }
 
84
        require_once 'Minify/CSS/UriRewriter.php';
 
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
}