load-scripts.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Disable error reporting
  4. *
  5. * Set this to error_reporting( -1 ) for debugging.
  6. */
  7. error_reporting(0);
  8. /** Set ABSPATH for execution */
  9. if ( ! defined( 'ABSPATH' ) ) {
  10. define( 'ABSPATH', dirname( dirname( __FILE__ ) ) . '/' );
  11. }
  12. define( 'WPINC', 'wp-includes' );
  13. $load = $_GET['load'];
  14. if ( is_array( $load ) )
  15. $load = implode( '', $load );
  16. $load = preg_replace( '/[^a-z0-9,_-]+/i', '', $load );
  17. $load = array_unique( explode( ',', $load ) );
  18. if ( empty($load) )
  19. exit;
  20. require( ABSPATH . 'wp-admin/includes/noop.php' );
  21. require( ABSPATH . WPINC . '/script-loader.php' );
  22. require( ABSPATH . WPINC . '/version.php' );
  23. $compress = ( isset($_GET['c']) && $_GET['c'] );
  24. $force_gzip = ( $compress && 'gzip' == $_GET['c'] );
  25. $expires_offset = 31536000; // 1 year
  26. $out = '';
  27. $wp_scripts = new WP_Scripts();
  28. wp_default_scripts($wp_scripts);
  29. if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $wp_version ) {
  30. $protocol = $_SERVER['SERVER_PROTOCOL'];
  31. if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) {
  32. $protocol = 'HTTP/1.0';
  33. }
  34. header( "$protocol 304 Not Modified" );
  35. exit();
  36. }
  37. foreach ( $load as $handle ) {
  38. if ( !array_key_exists($handle, $wp_scripts->registered) )
  39. continue;
  40. $path = ABSPATH . $wp_scripts->registered[$handle]->src;
  41. $out .= get_file($path) . "\n";
  42. }
  43. header("Etag: $wp_version");
  44. header('Content-Type: application/javascript; charset=UTF-8');
  45. header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT');
  46. header("Cache-Control: public, max-age=$expires_offset");
  47. if ( $compress && ! ini_get('zlib.output_compression') && 'ob_gzhandler' != ini_get('output_handler') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) {
  48. header('Vary: Accept-Encoding'); // Handle proxies
  49. if ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) {
  50. header('Content-Encoding: deflate');
  51. $out = gzdeflate( $out, 3 );
  52. } elseif ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') ) {
  53. header('Content-Encoding: gzip');
  54. $out = gzencode( $out, 3 );
  55. }
  56. }
  57. echo $out;
  58. exit;