]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/load-styles.php
WordPress 4.5
[autoinstalls/wordpress.git] / wp-admin / load-styles.php
1 <?php
2
3 /**
4  * Disable error reporting
5  *
6  * Set this to error_reporting( -1 ) for debugging
7  */
8 error_reporting(0);
9
10 /** Set ABSPATH for execution */
11 define( 'ABSPATH', dirname(dirname(__FILE__)) . '/' );
12 define( 'WPINC', 'wp-includes' );
13
14 require( ABSPATH . 'wp-admin/includes/noop.php' );
15 require( ABSPATH . WPINC . '/script-loader.php' );
16 require( ABSPATH . WPINC . '/version.php' );
17
18 $load = $_GET['load'];
19 if ( is_array( $load ) ) {
20         $load = implode( '', $load );
21 }
22 $load = preg_replace( '/[^a-z0-9,_-]+/i', '', $load );
23 $load = array_unique( explode( ',', $load ) );
24
25 if ( empty($load) )
26         exit;
27
28 $compress = ( isset($_GET['c']) && $_GET['c'] );
29 $force_gzip = ( $compress && 'gzip' == $_GET['c'] );
30 $rtl = ( isset($_GET['dir']) && 'rtl' == $_GET['dir'] );
31 $expires_offset = 31536000; // 1 year
32 $out = '';
33
34 $wp_styles = new WP_Styles();
35 wp_default_styles($wp_styles);
36
37 if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $wp_version ) {
38         $protocol = $_SERVER['SERVER_PROTOCOL'];
39         if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) {
40                 $protocol = 'HTTP/1.0';
41         }
42         header( "$protocol 304 Not Modified" );
43         exit();
44 }
45
46 foreach ( $load as $handle ) {
47         if ( !array_key_exists($handle, $wp_styles->registered) )
48                 continue;
49
50         $style = $wp_styles->registered[$handle];
51
52         if ( empty( $style->src ) ) {
53                 continue;
54         }
55
56         $path = ABSPATH . $style->src;
57
58         if ( $rtl && ! empty( $style->extra['rtl'] ) ) {
59                 // All default styles have fully independent RTL files.
60                 $path = str_replace( '.min.css', '-rtl.min.css', $path );
61         }
62
63         $content = get_file( $path ) . "\n";
64
65         if ( strpos( $style->src, '/' . WPINC . '/css/' ) === 0 ) {
66                 $content = str_replace( '../images/', '../' . WPINC . '/images/', $content );
67                 $content = str_replace( '../js/tinymce/', '../' . WPINC . '/js/tinymce/', $content );
68                 $content = str_replace( '../fonts/', '../' . WPINC . '/fonts/', $content );
69                 $out .= $content;
70         } else {
71                 $out .= str_replace( '../images/', 'images/', $content );
72         }
73 }
74
75 header("Etag: $wp_version");
76 header('Content-Type: text/css; charset=UTF-8');
77 header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT');
78 header("Cache-Control: public, max-age=$expires_offset");
79
80 if ( $compress && ! ini_get('zlib.output_compression') && 'ob_gzhandler' != ini_get('output_handler') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) {
81         header('Vary: Accept-Encoding'); // Handle proxies
82         if ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) {
83                 header('Content-Encoding: deflate');
84                 $out = gzdeflate( $out, 3 );
85         } elseif ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') ) {
86                 header('Content-Encoding: gzip');
87                 $out = gzencode( $out, 3 );
88         }
89 }
90
91 echo $out;
92 exit;