summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/js/clientscripts.php
blob: 2bc206da5a8fc29e24b3e379a201ba0435d580a5 (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
<?php
/**
 * This file compresses the javascript files using GZip 
 *
 * Todo:
 *  - Add local file cache for the GZip:ed version.
 */

if(isset($_GET['nocache']))
	$expiresOffset = -10000; //no cache
else
	$expiresOffset = 3600 * 24 * 10;		// 10 days util client cache expires

// Get data to load
$library = array( 'base', 'dom', 'effects', 'controls', 'logger',
	'ajax', 'rico', 'validator', 'datepicker');

$param = isset($_GET['js']) ? $_GET['js'] : '';

//check for proper matching parameters, otherwise exit;
if(preg_match('/(\w)+(,\w+)*/', $param)) $js = explode(',', $param); else exit();
foreach($js as $lib) if(!in_array($lib, $library)) exit(); 

// Only gzip the contents if clients and server support it
if (isset($_SERVER['HTTP_ACCEPT_ENCODING']))
	$encodings = explode(',', strtolower($_SERVER['HTTP_ACCEPT_ENCODING']));
else
	$encodings = array();

// Check for gzip header or northon internet securities
if ((in_array('gzip', $encodings) || isset($_SERVER['---------------'])) 
		&& function_exists('ob_gzhandler') && !ini_get('zlib.output_compression'))
	ob_start("ob_gzhandler");

// Output rest of headers
header('Content-type: text/javascript; charset: UTF-8');
// header("Cache-Control: must-revalidate");
header('Vary: Accept-Encoding'); // Handle proxies
header('Expires: ' . @gmdate('D, d M Y H:i:s', @time() + $expiresOffset) . ' GMT');

foreach($js as $lib)
{
	$file = realpath($lib.'.js');
	if(is_file($file))
		echo file_get_contents($file);
	else //log missings files to console logger
	{
		echo 'setTimeout(function(){ if(Logger) Logger.error("Missing file", "'.$lib.'.js"); }, 1000);';
		error_log("Unable to find asset file {$lib}.js");
	}
}

?>