File: js.php

package info (click to toggle)
phpsysinfo 3.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,900 kB
  • sloc: javascript: 22,511; php: 20,651; xml: 18,293; sh: 196; python: 58; makefile: 12
file content (78 lines) | stat: -rw-r--r-- 2,756 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
 * compress js files and send them to the browser on the fly
 *
 * PHP version 5
 *
 * @category  PHP
 * @package   PSI_JS
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
 * @copyright 2009 phpSysInfo
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
 * @version   SVN: $Id: js.php 661 2012-08-27 11:26:39Z namiltd $
 * @link      http://phpsysinfo.sourceforge.net
 */
/**
 * application root path
 *
 * @var string
 */
define('PSI_APP_ROOT', dirname(__FILE__));

require_once PSI_APP_ROOT.'/includes/autoloader.inc.php';

require_once PSI_APP_ROOT.'/read_config.php';

$file = isset($_GET['name']) ? basename(htmlspecialchars($_GET['name'])) : null;
$plugin = isset($_GET['plugin']) ? basename(htmlspecialchars($_GET['plugin'])) : null;
$script = null;

if ($file != null && $plugin == null) {
    if (strtolower(substr($file, 0, 6)) == 'jquery') {
        $script = PSI_APP_ROOT.'/js/jQuery/'.$file;
    } elseif (strtolower(substr($file, 0, 10)) == 'phpsysinfo') {
        $script = PSI_APP_ROOT.'/js/phpSysInfo/'.$file;
    } else {
        $script = PSI_APP_ROOT.'/js/vendor/'.$file;
    }
} elseif ($file == null && $plugin != null) {
    $script = PSI_APP_ROOT.'/plugins/'.strtolower($plugin).'/js/'.strtolower($plugin);
} elseif ($file != null && $plugin != null) {
    $script = PSI_APP_ROOT.'/plugins/'.strtolower($plugin).'/js/'.strtolower($file);
}

if ($script != null) {
    $scriptjs = $script.'.js';
    $scriptmin = $script.'.min.js';
    $compression = false;

    header('content-type: application/x-javascript');

    if ((!defined("PSI_DEBUG") || (PSI_DEBUG !== true)) && defined("PSI_JS_COMPRESSION")) {
        $compression = strtolower(PSI_JS_COMPRESSION);
    }
    switch ($compression) {
    case "normal":
        if (file_exists($scriptmin) && is_readable($scriptmin)) {
            echo file_get_contents($scriptmin);
        } elseif (file_exists($scriptjs) && is_readable($scriptjs)) {
            $packer = new JavaScriptPacker(file_get_contents($scriptjs));
            echo $packer->pack();
        }
        break;
    case "none":
        if (file_exists($scriptjs) && is_readable($scriptjs)) {
           $packer = new JavaScriptPacker(file_get_contents($scriptjs), 0);
            echo $packer->pack();
        } elseif (file_exists($scriptmin) && is_readable($scriptmin)) {
           echo file_get_contents($scriptmin);
        }
        break;
    default:
        if (file_exists($scriptjs) && is_readable($scriptjs)) {
            echo file_get_contents($scriptjs);
        } elseif (file_exists($scriptmin) && is_readable($scriptmin)) {
            echo file_get_contents($scriptmin);
        }
    }
}