get_scripts.js.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Concatenates several js files to reduce the number of
  5. * http requests sent to the server
  6. *
  7. * @package PhpMyAdmin
  8. */
  9. chdir('..');
  10. // Close session early as we won't write anything there
  11. session_write_close();
  12. // Send correct type
  13. header('Content-Type: text/javascript; charset=UTF-8');
  14. // Enable browser cache for 1 hour
  15. header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 3600) . ' GMT');
  16. if (! empty($_GET['scripts']) && is_array($_GET['scripts'])) {
  17. foreach ($_GET['scripts'] as $script) {
  18. // Sanitise filename
  19. $script_name = 'js';
  20. $path = explode("/", $script);
  21. foreach ($path as $index => $filename) {
  22. // Allow alphanumeric, "." and "-" chars only, no files starting
  23. // with .
  24. if (preg_match("@^[\w][\w\.-]+$@", $filename)) {
  25. $script_name .= DIRECTORY_SEPARATOR . $filename;
  26. }
  27. }
  28. // Output file contents
  29. if (preg_match("@\.js$@", $script_name) && is_readable($script_name)) {
  30. readfile($script_name);
  31. echo ";\n\n";
  32. }
  33. }
  34. }
  35. if (isset($_GET['call_done'])) {
  36. echo "AJAX.scriptHandler.done();";
  37. }
  38. ?>