Subversion Repositories ALCASAR

Rev

Rev 2770 | Details | Compare with Previous | Last modification | View Log

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