load-styles.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. $protocol = $_SERVER['SERVER_PROTOCOL'];
  17. if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) {
  18. $protocol = 'HTTP/1.0';
  19. }
  20. $load = $_GET['load'];
  21. if ( is_array( $load ) ) {
  22. ksort( $load );
  23. $load = implode( '', $load );
  24. }
  25. $load = preg_replace( '/[^a-z0-9,_-]+/i', '', $load );
  26. $load = array_unique( explode( ',', $load ) );
  27. if ( empty( $load ) ) {
  28. header( "$protocol 400 Bad Request" );
  29. exit;
  30. }
  31. $rtl = ( isset( $_GET['dir'] ) && 'rtl' == $_GET['dir'] );
  32. $expires_offset = 31536000; // 1 year
  33. $out = '';
  34. $wp_styles = new WP_Styles();
  35. wp_default_styles( $wp_styles );
  36. if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $wp_version ) {
  37. header( "$protocol 304 Not Modified" );
  38. exit();
  39. }
  40. foreach ( $load as $handle ) {
  41. if ( ! array_key_exists( $handle, $wp_styles->registered ) ) {
  42. continue;
  43. }
  44. $style = $wp_styles->registered[ $handle ];
  45. if ( empty( $style->src ) ) {
  46. continue;
  47. }
  48. $path = ABSPATH . $style->src;
  49. if ( $rtl && ! empty( $style->extra['rtl'] ) ) {
  50. // All default styles have fully independent RTL files.
  51. $path = str_replace( '.min.css', '-rtl.min.css', $path );
  52. }
  53. $content = get_file( $path ) . "\n";
  54. if ( strpos( $style->src, '/' . WPINC . '/css/' ) === 0 ) {
  55. $content = str_replace( '../images/', '../' . WPINC . '/images/', $content );
  56. $content = str_replace( '../js/tinymce/', '../' . WPINC . '/js/tinymce/', $content );
  57. $content = str_replace( '../fonts/', '../' . WPINC . '/fonts/', $content );
  58. $out .= $content;
  59. } else {
  60. $out .= str_replace( '../images/', 'images/', $content );
  61. }
  62. }
  63. header( "Etag: $wp_version" );
  64. header( 'Content-Type: text/css; charset=UTF-8' );
  65. header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' );
  66. header( "Cache-Control: public, max-age=$expires_offset" );
  67. echo $out;
  68. exit;