Subversion Repositories ALCASAR

Rev

Rev 3037 | 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
 
3287 rexy 26
$file = isset($_GET['name']) ? basename(htmlspecialchars(trim($_GET['name']))) : null;
27
$plugin = isset($_GET['plugin']) ? basename(htmlspecialchars(trim($_GET['plugin']))) : null;
2770 rexy 28
$script = null;
29
 
30
if ($file != null && $plugin == null) {
3287 rexy 31
    if (strtolower(substr($file, 0, 10)) == 'phpsysinfo') {
32
        $script = PSI_APP_ROOT.'/js/'.$file;
33
    } elseif (strtolower($file) == 'jquery') {
34
        $script = PSI_APP_ROOT.'/js/common/jquery';
35
    } elseif (strtolower(substr($file, 0, 7)) == 'jquery.') {
36
        $script = PSI_APP_ROOT.'/js/dynamic/'.$file;
2770 rexy 37
    } else {
3287 rexy 38
        $script = PSI_APP_ROOT.'/js/bootstrap/'.$file;
2770 rexy 39
    }
40
} elseif ($file == null && $plugin != null) {
41
    $script = PSI_APP_ROOT.'/plugins/'.strtolower($plugin).'/js/'.strtolower($plugin);
42
} elseif ($file != null && $plugin != null) {
43
    $script = PSI_APP_ROOT.'/plugins/'.strtolower($plugin).'/js/'.strtolower($file);
44
}
45
 
46
if ($script != null) {
47
    $scriptjs = $script.'.js';
48
    $scriptmin = $script.'.min.js';
49
    $compression = false;
50
 
3037 rexy 51
    header('content-type: application/x-javascript');
2770 rexy 52
 
53
    if ((!defined("PSI_DEBUG") || (PSI_DEBUG !== true)) && defined("PSI_JS_COMPRESSION")) {
54
        $compression = strtolower(PSI_JS_COMPRESSION);
55
    }
56
    switch ($compression) {
3037 rexy 57
    case "normal":
58
        if (file_exists($scriptmin) && is_readable($scriptmin)) {
59
            echo file_get_contents($scriptmin);
60
        } elseif (file_exists($scriptjs) && is_readable($scriptjs)) {
61
            $packer = new JavaScriptPacker(file_get_contents($scriptjs));
62
            echo $packer->pack();
63
        }
64
        break;
65
    case "none":
66
        if (file_exists($scriptjs) && is_readable($scriptjs)) {
67
           $packer = new JavaScriptPacker(file_get_contents($scriptjs), 0);
68
            echo $packer->pack();
69
        } elseif (file_exists($scriptmin) && is_readable($scriptmin)) {
70
           echo file_get_contents($scriptmin);
71
        }
72
        break;
73
    default:
74
        if (file_exists($scriptjs) && is_readable($scriptjs)) {
75
            echo file_get_contents($scriptjs);
76
        } elseif (file_exists($scriptmin) && is_readable($scriptmin)) {
77
            echo file_get_contents($scriptmin);
78
        }
2770 rexy 79
    }
80
}