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