PageRenderTime 14ms CodeModel.GetById 7ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/kharm/public/concat_files.php

http://kharm-xml.googlecode.com/
PHP | 57 lines | 43 code | 10 blank | 4 comment | 14 complexity | 7e366042c97e0476c16dba209d6ac795 MD5 | raw file
 1<?php
 2
 3define('BASE_PATH', realpath(dirname(__FILE__)) . '/');
 4
 5$type = $_GET['type'];
 6
 7if ($type == 'js') {
 8	$elements = array(
 9					"js/global_vars.js",
10					"js/global_functions.js",
11					"js/google_map.js",
12					"js/google_chart.js",
13					"js/ajax.js",
14					"js/forms.js",
15					"js/centers.js");
16	$type = 'javascript';
17} else if ($type="css") {
18	$elements = array("css/global.css");
19	$type = 'css';
20}
21
22$contents = '';
23foreach ($elements as $element) {
24	$path = realpath(BASE_PATH . '/' . $element);
25	$contents .= "\n\n" . file_get_contents($path);
26}
27
28// Send Content-Type
29header ("Content-Type: text/" . $type . "; charset=utf-8");
30
31$contents = str_replace( array("\n", "\r", "\t", "  "), array('', '', '', ''), $contents );
32
33// Encoding
34$gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
35$deflate = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate');
36// Determine used compression method
37$encoding = $gzip ? 'gzip' : ($deflate ? 'deflate' : 'none');
38// Check for buggy versions of Internet Explorer
39if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Opera') && 
40	preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) {
41	
42	$version = floatval($matches[1]);
43	if ($version < 6)
44		$encoding = 'none';
45	if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) 
46		$encoding = 'none';
47}
48
49if (isset($encoding) && $encoding != 'none') {
50	$contents = gzencode($contents, 9, $gzip ? FORCE_GZIP : FORCE_DEFLATE);
51	header ("Content-Encoding: " . $encoding);
52	header ('Content-Length: ' . strlen($contents));
53} else {
54	header ('Content-Length: ' . strlen($contents));
55}
56
57echo $contents;