summaryrefslogtreecommitdiff
path: root/itjs.php
blob: 148b8ff42904bb54ad78ef0601213f0419acf57d (plain)
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
/*
**	Copyright (C) 1995-2007 by the ITools Authors.
**	This file is part of ITools - the Internet Tools Library
**
**	ITools is free software; you can redistribute it and/or modify
**	it under the terms of the GNU General Public License as published by
**	the Free Software Foundation; either version 3 of the License, or
**	(at your option) any later version.
**
**	ITools is distributed in the hope that it will be useful,
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**	GNU General Public License for more details.
**
**	You should have received a copy of the GNU General Public License
**	along with this program.  If not, see <http://www.gnu.org/licenses/>.
**
**	itjs.php - Delivers /itjs/ files through AliasMatch in httpd.conf
*/

require "itools/itools.lib";

if (EDC('slowjs'))
	 sleep(20);

if ($_SERVER['HTTP_IF_NONE_MATCH'] && it::is_live() && !$_REQUEST['retry']) {
	header("HTTP/1.0 304 Not Modified"); # client should always keep the component that fits the page it has
	exit;
}

$files = itjs::filenames(it::match('/itjs/([a-z0-9_,.-]*)', $_SERVER['PHP_SELF']));
$data = itjs::filecontents($files);
$file = end($files);

if (it::match('\.gif$', $file))
{
	header("Content-Type: image/gif");
}
else if (it::match('\.css', $_SERVER['PHP_SELF']))
{
	header("Content-Type: text/css");
	$data .= "\n#it_boot_dom { display:none }\n";	# Append magic style for it_boot
	if (!it::match('^devel', $GLOBALS['ULTRASERVERTYPE']))
		$data = it::replace(array('[ \t]*([{};])[ \t]*' => '$1', '/\*.*?\*/' => ""), $data);
	if (it::match('W3C_CSS_Validator', $_SERVER['HTTP_USER_AGENT']) || EDC('w3c'))
		$data = it::replace(array('@-.*' => "", 'background[^;}]*(gradient|rgba)[^;}]*;?' => "", '(filter:\s*(progid|none)|text-overflow:|zoom:|-webkit-|display:-moz-|-moz-|-o-|cursor:|border-radius:|behavior:|\w+:expression)[^;}]*;?' => "", 'pointer-events:[^;}]*' => "", 'html\.ie6.*' => "", '([^/])\*(\w)' => '$1$2'), $data);
}
else if (it::match('\.htc$', $file))
{
	header("Content-Type: text/x-component");
}
else if (!it::match('\.html$', $file))
{
	$charset = ini_get('default_charset') ?: 'iso-8859-1';
	header("Content-Type: application/x-javascript; charset=$charset");
}

@header("Etag: alwaysvalid");

if (!preg_match('/Opera/', $_SERVER['HTTP_USER_AGENT']) && it::is_live() && !$_REQUEST['retry'])
{
	header("Cache-Control: max-age=604800, private"); # proxies should not cache since contents of same url can differ between browsers
	header("Expires: " . gmdate("D, d M Y H:i:s", time()+604800). " GMT");
}

$data = itjs::strip($data);

if ($_REQUEST['boot'])
{
	$data .= "window.it_boot_init();\n";
	if (!$_REQUEST['script'])
		$data = sprintf("/*sln:%d*/\n%s/*eln:%d*/", grapheme_strlen($data), strtr($data, array('%' => "%25", '.' => "%2e", 'e' => "%65", 'i' => "%69")), grapheme_strlen($data));	# Protect from Firewalls/Proxies altering Javascript source code
}

echo it_untaint($data);

?>