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 |
|
|
|
49 |
header("content-type: application/x-javascript");
|
|
|
50 |
|
|
|
51 |
if ((!defined("PSI_DEBUG") || (PSI_DEBUG !== true)) && defined("PSI_JS_COMPRESSION")) {
|
|
|
52 |
$compression = strtolower(PSI_JS_COMPRESSION);
|
|
|
53 |
}
|
|
|
54 |
switch ($compression) {
|
|
|
55 |
case "normal":
|
|
|
56 |
if (file_exists($scriptmin) && is_readable($scriptmin)) {
|
|
|
57 |
$filecontent = file_get_contents($scriptmin);
|
|
|
58 |
echo $filecontent;
|
|
|
59 |
} elseif (file_exists($scriptjs) && is_readable($scriptjs)) {
|
|
|
60 |
$filecontent = file_get_contents($scriptjs);
|
|
|
61 |
$packer = new JavaScriptPacker($filecontent);
|
|
|
62 |
echo $packer->pack();
|
|
|
63 |
}
|
|
|
64 |
break;
|
|
|
65 |
case "none":
|
|
|
66 |
if (file_exists($scriptjs) && is_readable($scriptjs)) {
|
|
|
67 |
$filecontent = file_get_contents($scriptjs);
|
|
|
68 |
$packer = new JavaScriptPacker($filecontent, 0);
|
|
|
69 |
echo $packer->pack();
|
|
|
70 |
} elseif (file_exists($scriptmin) && is_readable($scriptmin)) {
|
|
|
71 |
$filecontent = file_get_contents($scriptmin);
|
|
|
72 |
echo $filecontent;
|
|
|
73 |
}
|
|
|
74 |
break;
|
|
|
75 |
default:
|
|
|
76 |
if (file_exists($scriptjs) && is_readable($scriptjs)) {
|
|
|
77 |
$filecontent = file_get_contents($scriptjs);
|
|
|
78 |
} elseif (file_exists($scriptmin) && is_readable($scriptmin)) {
|
|
|
79 |
$filecontent = file_get_contents($scriptmin);
|
|
|
80 |
} else break;
|
|
|
81 |
|
|
|
82 |
echo $filecontent;
|
|
|
83 |
break;
|
|
|
84 |
}
|
|
|
85 |
}
|