Subversion Repositories ALCASAR

Rev

Rev 2770 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log

Rev 2770 Rev 3037
1
<?php
1
<?php
2
/**
2
/**
3
 * compress js files and send them to the browser on the fly
3
 * compress js files and send them to the browser on the fly
4
 *
4
 *
5
 * PHP version 5
5
 * PHP version 5
6
 *
6
 *
7
 * @category  PHP
7
 * @category  PHP
8
 * @package   PSI_JS
8
 * @package   PSI_JS
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
10
 * @copyright 2009 phpSysInfo
10
 * @copyright 2009 phpSysInfo
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
12
 * @version   SVN: $Id: js.php 661 2012-08-27 11:26:39Z namiltd $
12
 * @version   SVN: $Id: js.php 661 2012-08-27 11:26:39Z namiltd $
13
 * @link      http://phpsysinfo.sourceforge.net
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
14
 */
15
/**
15
/**
16
 * application root path
16
 * application root path
17
 *
17
 *
18
 * @var string
18
 * @var string
19
 */
19
 */
20
define('PSI_APP_ROOT', dirname(__FILE__));
20
define('PSI_APP_ROOT', dirname(__FILE__));
21
 
21
 
22
require_once PSI_APP_ROOT.'/includes/autoloader.inc.php';
22
require_once PSI_APP_ROOT.'/includes/autoloader.inc.php';
23
 
23
 
24
require_once PSI_APP_ROOT.'/read_config.php';
24
require_once PSI_APP_ROOT.'/read_config.php';
25
 
25
 
26
$file = isset($_GET['name']) ? basename(htmlspecialchars($_GET['name'])) : null;
26
$file = isset($_GET['name']) ? basename(htmlspecialchars($_GET['name'])) : null;
27
$plugin = isset($_GET['plugin']) ? basename(htmlspecialchars($_GET['plugin'])) : null;
27
$plugin = isset($_GET['plugin']) ? basename(htmlspecialchars($_GET['plugin'])) : null;
28
$script = null;
28
$script = null;
29
 
29
 
30
if ($file != null && $plugin == null) {
30
if ($file != null && $plugin == null) {
31
    if (strtolower(substr($file, 0, 6)) == 'jquery') {
31
    if (strtolower(substr($file, 0, 6)) == 'jquery') {
32
        $script = PSI_APP_ROOT.'/js/jQuery/'.$file;
32
        $script = PSI_APP_ROOT.'/js/jQuery/'.$file;
33
    } elseif (strtolower(substr($file, 0, 10)) == 'phpsysinfo') {
33
    } elseif (strtolower(substr($file, 0, 10)) == 'phpsysinfo') {
34
        $script = PSI_APP_ROOT.'/js/phpSysInfo/'.$file;
34
        $script = PSI_APP_ROOT.'/js/phpSysInfo/'.$file;
35
    } else {
35
    } else {
36
        $script = PSI_APP_ROOT.'/js/vendor/'.$file;
36
        $script = PSI_APP_ROOT.'/js/vendor/'.$file;
37
    }
37
    }
38
} elseif ($file == null && $plugin != null) {
38
} elseif ($file == null && $plugin != null) {
39
    $script = PSI_APP_ROOT.'/plugins/'.strtolower($plugin).'/js/'.strtolower($plugin);
39
    $script = PSI_APP_ROOT.'/plugins/'.strtolower($plugin).'/js/'.strtolower($plugin);
40
} elseif ($file != null && $plugin != null) {
40
} elseif ($file != null && $plugin != null) {
41
    $script = PSI_APP_ROOT.'/plugins/'.strtolower($plugin).'/js/'.strtolower($file);
41
    $script = PSI_APP_ROOT.'/plugins/'.strtolower($plugin).'/js/'.strtolower($file);
42
}
42
}
43
 
43
 
44
if ($script != null) {
44
if ($script != null) {
45
    $scriptjs = $script.'.js';
45
    $scriptjs = $script.'.js';
46
    $scriptmin = $script.'.min.js';
46
    $scriptmin = $script.'.min.js';
47
    $compression = false;
47
    $compression = false;
48
 
48
 
49
    header("content-type: application/x-javascript");
49
    header('content-type: application/x-javascript');
50
 
50
 
51
    if ((!defined("PSI_DEBUG") || (PSI_DEBUG !== true)) && defined("PSI_JS_COMPRESSION")) {
51
    if ((!defined("PSI_DEBUG") || (PSI_DEBUG !== true)) && defined("PSI_JS_COMPRESSION")) {
52
        $compression = strtolower(PSI_JS_COMPRESSION);
52
        $compression = strtolower(PSI_JS_COMPRESSION);
53
    }
53
    }
54
    switch ($compression) {
54
    switch ($compression) {
55
        case "normal":
55
    case "normal":
56
            if (file_exists($scriptmin) && is_readable($scriptmin)) {
56
        if (file_exists($scriptmin) && is_readable($scriptmin)) {
57
                $filecontent = file_get_contents($scriptmin);
57
            echo file_get_contents($scriptmin);
58
                echo $filecontent;
-
 
59
            } elseif (file_exists($scriptjs) && is_readable($scriptjs)) {
58
        } elseif (file_exists($scriptjs) && is_readable($scriptjs)) {
60
                $filecontent = file_get_contents($scriptjs);
-
 
61
                $packer = new JavaScriptPacker($filecontent);
59
            $packer = new JavaScriptPacker(file_get_contents($scriptjs));
62
                echo $packer->pack();
60
            echo $packer->pack();
63
            }
61
        }
64
            break;
62
        break;
65
        case "none":
63
    case "none":
66
            if (file_exists($scriptjs) && is_readable($scriptjs)) {
64
        if (file_exists($scriptjs) && is_readable($scriptjs)) {
67
                $filecontent = file_get_contents($scriptjs);
-
 
68
                $packer = new JavaScriptPacker($filecontent, 0);
65
           $packer = new JavaScriptPacker(file_get_contents($scriptjs), 0);
69
                echo $packer->pack();
66
            echo $packer->pack();
70
            } elseif (file_exists($scriptmin) && is_readable($scriptmin)) {
67
        } elseif (file_exists($scriptmin) && is_readable($scriptmin)) {
71
                $filecontent = file_get_contents($scriptmin);
68
           echo file_get_contents($scriptmin);
72
                echo $filecontent;
-
 
73
            }
69
        }
74
            break;
70
        break;
75
        default:
71
    default:
76
            if (file_exists($scriptjs) && is_readable($scriptjs)) {
72
        if (file_exists($scriptjs) && is_readable($scriptjs)) {
77
                $filecontent = file_get_contents($scriptjs);
73
            echo file_get_contents($scriptjs);
78
            } elseif (file_exists($scriptmin) && is_readable($scriptmin)) {
74
        } elseif (file_exists($scriptmin) && is_readable($scriptmin)) {
79
                $filecontent = file_get_contents($scriptmin);
75
            echo file_get_contents($scriptmin);
80
            } else break;
-
 
81
 
-
 
82
            echo $filecontent;
-
 
83
            break;
76
        }
84
    }
77
    }
85
}
78
}
86
 
79