get_scripts.js.php 1.2 KB

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