author | ymh <ymh.work@gmail.com> |
Tue, 15 Oct 2019 15:48:13 +0200 | |
changeset 13 | d255fe9cd479 |
parent 9 | 177826044cd9 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
||
3 |
/** |
|
4 |
* Disable error reporting |
|
5 |
* |
|
5 | 6 |
* Set this to error_reporting( -1 ) for debugging |
0 | 7 |
*/ |
9 | 8 |
error_reporting( 0 ); |
0 | 9 |
|
10 |
/** Set ABSPATH for execution */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
11 |
if ( ! defined( 'ABSPATH' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
define( 'ABSPATH', dirname( dirname( __FILE__ ) ) . '/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
|
0 | 15 |
define( 'WPINC', 'wp-includes' ); |
16 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
require( ABSPATH . 'wp-admin/includes/noop.php' ); |
5 | 18 |
require( ABSPATH . WPINC . '/script-loader.php' ); |
19 |
require( ABSPATH . WPINC . '/version.php' ); |
|
0 | 20 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
$load = $_GET['load']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
if ( is_array( $load ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
$load = implode( '', $load ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
$load = preg_replace( '/[^a-z0-9,_-]+/i', '', $load ); |
0 | 26 |
$load = array_unique( explode( ',', $load ) ); |
27 |
||
9 | 28 |
if ( empty( $load ) ) { |
0 | 29 |
exit; |
9 | 30 |
} |
0 | 31 |
|
9 | 32 |
$rtl = ( isset( $_GET['dir'] ) && 'rtl' == $_GET['dir'] ); |
0 | 33 |
$expires_offset = 31536000; // 1 year |
9 | 34 |
$out = ''; |
0 | 35 |
|
36 |
$wp_styles = new WP_Styles(); |
|
9 | 37 |
wp_default_styles( $wp_styles ); |
0 | 38 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $wp_version ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
$protocol = $_SERVER['SERVER_PROTOCOL']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
$protocol = 'HTTP/1.0'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
header( "$protocol 304 Not Modified" ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
exit(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
foreach ( $load as $handle ) { |
9 | 49 |
if ( ! array_key_exists( $handle, $wp_styles->registered ) ) { |
0 | 50 |
continue; |
9 | 51 |
} |
0 | 52 |
|
9 | 53 |
$style = $wp_styles->registered[ $handle ]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
if ( empty( $style->src ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
|
0 | 59 |
$path = ABSPATH . $style->src; |
60 |
||
5 | 61 |
if ( $rtl && ! empty( $style->extra['rtl'] ) ) { |
62 |
// All default styles have fully independent RTL files. |
|
63 |
$path = str_replace( '.min.css', '-rtl.min.css', $path ); |
|
0 | 64 |
} |
65 |
||
5 | 66 |
$content = get_file( $path ) . "\n"; |
67 |
||
68 |
if ( strpos( $style->src, '/' . WPINC . '/css/' ) === 0 ) { |
|
69 |
$content = str_replace( '../images/', '../' . WPINC . '/images/', $content ); |
|
70 |
$content = str_replace( '../js/tinymce/', '../' . WPINC . '/js/tinymce/', $content ); |
|
71 |
$content = str_replace( '../fonts/', '../' . WPINC . '/fonts/', $content ); |
|
9 | 72 |
$out .= $content; |
0 | 73 |
} else { |
74 |
$out .= str_replace( '../images/', 'images/', $content ); |
|
75 |
} |
|
76 |
} |
|
77 |
||
9 | 78 |
header( "Etag: $wp_version" ); |
79 |
header( 'Content-Type: text/css; charset=UTF-8' ); |
|
80 |
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' ); |
|
81 |
header( "Cache-Control: public, max-age=$expires_offset" ); |
|
0 | 82 |
|
83 |
echo $out; |
|
84 |
exit; |