load-styles.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. require( ABSPATH . 'wp-admin/includes/noop.php' );
  14. require( ABSPATH . WPINC . '/script-loader.php' );
  15. require( ABSPATH . WPINC . '/version.php' );
  16. $load = $_GET['load'];
  17. if ( is_array( $load ) ) {
  18. $load = implode( '', $load );
  19. }
  20. $load = preg_replace( '/[^a-z0-9,_-]+/i', '', $load );
  21. $load = array_unique( explode( ',', $load ) );
  22. if ( empty($load) )
  23. exit;
  24. $rtl = ( isset($_GET['dir']) && 'rtl' == $_GET['dir'] );
  25. $expires_offset = 31536000; // 1 year
  26. $out = '';
  27. $wp_styles = new WP_Styles();
  28. wp_default_styles($wp_styles);
  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_styles->registered) )
  39. continue;
  40. $style = $wp_styles->registered[$handle];
  41. if ( empty( $style->src ) ) {
  42. continue;
  43. }
  44. $path = ABSPATH . $style->src;
  45. if ( $rtl && ! empty( $style->extra['rtl'] ) ) {
  46. // All default styles have fully independent RTL files.
  47. $path = str_replace( '.min.css', '-rtl.min.css', $path );
  48. }
  49. $content = get_file( $path ) . "\n";
  50. if ( strpos( $style->src, '/' . WPINC . '/css/' ) === 0 ) {
  51. $content = str_replace( '../images/', '../' . WPINC . '/images/', $content );
  52. $content = str_replace( '../js/tinymce/', '../' . WPINC . '/js/tinymce/', $content );
  53. $content = str_replace( '../fonts/', '../' . WPINC . '/fonts/', $content );
  54. $out .= $content;
  55. } else {
  56. $out .= str_replace( '../images/', 'images/', $content );
  57. }
  58. }
  59. header("Etag: $wp_version");
  60. header('Content-Type: text/css; charset=UTF-8');
  61. header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT');
  62. header("Cache-Control: public, max-age=$expires_offset");
  63. echo $out;
  64. exit;