Bez popisu

load-styles.php 2.4KB

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