Ticket #28722: 28722.diff
File 28722.diff, 4.7 KB (added by , 10 years ago) |
---|
-
src/wp-admin/load-scripts.php
123 123 124 124 if ( empty($load) ) 125 125 exit; 126 126 127 127 require(ABSPATH . WPINC . '/script-loader.php'); 128 128 require(ABSPATH . WPINC . '/version.php'); 129 129 130 130 $compress = ( isset($_GET['c']) && $_GET['c'] ); 131 131 $force_gzip = ( $compress && 'gzip' == $_GET['c'] ); 132 132 $expires_offset = 31536000; // 1 year 133 133 $out = ''; 134 134 135 135 $wp_scripts = new WP_Scripts(); 136 136 wp_default_scripts($wp_scripts); 137 137 138 foreach( $load as $handle ) { 139 if ( !array_key_exists($handle, $wp_scripts->registered) ) 138 $etag = "wp:{$wp_version},"; 139 140 foreach ( $load as $i => $handle ) { 141 if ( !array_key_exists($handle, $wp_scripts->registered) ) { 142 unset( $load[ $i ] ); 140 143 continue; 144 } 145 $etag .= $handle . ':' . $wp_scripts->registered[$handle]->ver . ','; 146 } 147 $etag = md5( $etag ); 148 149 if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $etag ) { 150 header('HTTP/1.1 304 Not Modified'); 151 exit(); 152 } 141 153 154 foreach ( $load as $handle ) { 142 155 $path = ABSPATH . $wp_scripts->registered[$handle]->src; 143 156 $out .= get_file($path) . "\n"; 144 157 } 145 158 159 header("Etag: $etag"); 146 160 header('Content-Type: application/x-javascript; charset=UTF-8'); 147 161 header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT'); 148 162 header("Cache-Control: public, max-age=$expires_offset"); 149 163 150 164 if ( $compress && ! ini_get('zlib.output_compression') && 'ob_gzhandler' != ini_get('output_handler') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) { 151 165 header('Vary: Accept-Encoding'); // Handle proxies 152 166 if ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) { 153 167 header('Content-Encoding: deflate'); 154 168 $out = gzdeflate( $out, 3 ); 155 169 } elseif ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') ) { 156 170 header('Content-Encoding: gzip'); 157 171 $out = gzencode( $out, 3 ); 158 172 } 159 173 } 160 174 -
src/wp-admin/load-styles.php
98 98 $load = preg_replace( '/[^a-z0-9,_-]+/i', '', $_GET['load'] ); 99 99 $load = array_unique( explode( ',', $load ) ); 100 100 101 101 if ( empty($load) ) 102 102 exit; 103 103 104 104 $compress = ( isset($_GET['c']) && $_GET['c'] ); 105 105 $force_gzip = ( $compress && 'gzip' == $_GET['c'] ); 106 106 $rtl = ( isset($_GET['dir']) && 'rtl' == $_GET['dir'] ); 107 107 $expires_offset = 31536000; // 1 year 108 108 $out = ''; 109 109 110 110 $wp_styles = new WP_Styles(); 111 111 wp_default_styles($wp_styles); 112 112 113 foreach( $load as $handle ) { 114 if ( !array_key_exists($handle, $wp_styles->registered) ) 113 $etag = "wp:{$wp_version},"; 114 115 foreach ( $load as $i => $handle ) { 116 if ( !array_key_exists($handle, $wp_styles->registered) ) { 117 unset( $load[ $i ] ); 115 118 continue; 119 } 120 $etag .= $handle . ':' . $wp_styles->registered[$handle]->ver . ','; 121 } 122 $etag = md5( $etag ); 123 124 if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $etag ) { 125 header('HTTP/1.1 304 Not Modified'); 126 exit(); 127 } 116 128 129 foreach ( $load as $handle ) { 117 130 $style = $wp_styles->registered[$handle]; 118 131 $path = ABSPATH . $style->src; 119 132 120 133 if ( $rtl && ! empty( $style->extra['rtl'] ) ) { 121 134 // All default styles have fully independent RTL files. 122 135 $path = str_replace( '.min.css', '-rtl.min.css', $path ); 123 136 } 124 137 125 138 $content = get_file( $path ) . "\n"; 126 139 127 140 if ( strpos( $style->src, '/' . WPINC . '/css/' ) === 0 ) { 128 141 $content = str_replace( '../images/', '../' . WPINC . '/images/', $content ); 129 142 $content = str_replace( '../js/tinymce/', '../' . WPINC . '/js/tinymce/', $content ); 130 143 $content = str_replace( '../fonts/', '../' . WPINC . '/fonts/', $content ); 131 144 $out .= $content; 132 145 } else { 133 146 $out .= str_replace( '../images/', 'images/', $content ); 134 147 } 135 148 } 136 149 150 header("Etag: $etag"); 137 151 header('Content-Type: text/css; charset=UTF-8'); 138 152 header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT'); 139 153 header("Cache-Control: public, max-age=$expires_offset"); 140 154 141 155 if ( $compress && ! ini_get('zlib.output_compression') && 'ob_gzhandler' != ini_get('output_handler') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) { 142 156 header('Vary: Accept-Encoding'); // Handle proxies 143 157 if ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) { 144 158 header('Content-Encoding: deflate'); 145 159 $out = gzdeflate( $out, 3 ); 146 160 } elseif ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') ) { 147 161 header('Content-Encoding: gzip'); 148 162 $out = gzencode( $out, 3 ); 149 163 } 150 164 } 151 165