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 <[email protected]> |
10
|
|
|
* @copyright 2009 phpSysInfo |
11
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
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('APP_ROOT', dirname(__FILE__)); |
21
|
|
|
|
22
|
|
|
require_once APP_ROOT.'/includes/autoloader.inc.php'; |
23
|
|
|
|
24
|
|
|
require_once 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 = APP_ROOT.'/js/jQuery/'.$file; |
33
|
|
|
} elseif (strtolower(substr($file, 0, 10)) == 'phpsysinfo') { |
34
|
|
|
$script = APP_ROOT.'/js/phpSysInfo/'.$file; |
35
|
|
|
} else { |
36
|
|
|
$script = APP_ROOT.'/js/vendor/'.$file; |
37
|
|
|
} |
38
|
|
|
} elseif ($file == null && $plugin != null) { |
39
|
|
|
$script = APP_ROOT.'/plugins/'.strtolower($plugin).'/js/'.strtolower($plugin); |
40
|
|
|
} elseif ($file != null && $plugin != null) { |
41
|
|
|
$script = 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
|
|
View Code Duplication |
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
|
|
View Code Duplication |
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
|
|
|
} |
86
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.