BMLT Root Server
js_stripper.php
Go to the documentation of this file.
1 <?php
2 /***********************************************************************/
3 /** \file js_stripper.php
4 
5  \brief This file reads in a JavaScript file, and optimizes it by stripping
6  out comments and whitespace. It will also try to GZ compress the output
7  using the standard OB functions. It can make a HUGE difference in size.
8 
9  The way it works is that you call it from the <link/> element (don't
10  specify a "type" attribute), and give it a GET parameter of filename,
11  which will equal the file path to the JavaScript file.
12 
13  For security purposes, the file must always be a ".js" file, and you can't
14  go out of the directory in which this file is located.
15 
16  This file is part of the Basic Meeting List Toolbox (BMLT).
17 
18  Find out more at: https://bmlt.app
19 
20  BMLT is free software: you can redistribute it and/or modify
21  it under the terms of the MIT License.
22 
23  BMLT is distributed in the hope that it will be useful,
24  but WITHOUT ANY WARRANTY; without even the implied warranty of
25  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  MIT License for more details.
27 
28  You should have received a copy of the MIT License along with this code.
29  If not, see <https://opensource.org/licenses/MIT>.
30 */
31  $pathname = $_GET['filename'];
32 if (!preg_match("|/|", $pathname)) {
33  if (preg_match("|.*?\.js$|", $pathname)) {
34  $pathname = dirname(__FILE__)."/$pathname";
35  $opt = file_get_contents($pathname);
36  $opt = preg_replace("|[\n\r]+|s", "\n", $opt);
37  $opt = preg_replace("|\/\*.*?\*\/|s", "", $opt);
38  $opt = preg_replace('#\/\/.*?\n#', "", $opt);
39  $opt = preg_replace("|\t+|s", " ", $opt);
40  $opt = preg_replace("| +|s", " ", $opt);
41  $opt = preg_replace("|\n+|s", "\n", $opt);
42  header("Content-type: text/javascript");
43  if (zlib_get_coding_type() === false) {
44  ob_start("ob_gzhandler");
45  } else {
46  ob_start();
47  }
48 
49  echo $opt;
50  ob_end_flush();
51  } else {
52  echo "FILE MUST BE A .CSS FILE!";
53  }
54 } else {
55  echo "YOU CANNOT LEAVE THE DIRECTORY!";
56 }
$pathname
Definition: js_stripper.php:32
$_GET['switcher']