author | ymh <ymh.work@gmail.com> |
Wed, 21 Sep 2022 18:19:35 +0200 | |
changeset 18 | be944660c56a |
parent 16 | a86126ab1dd4 |
child 19 | 3d72ae0968f4 |
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' ) ) { |
16 | 12 |
define( 'ABSPATH', dirname( __DIR__ ) . '/' ); |
7
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' ); |
18 | 16 |
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); |
0 | 17 |
|
16 | 18 |
require ABSPATH . 'wp-admin/includes/noop.php'; |
18 | 19 |
require ABSPATH . WPINC . '/theme.php'; |
20 |
require ABSPATH . WPINC . '/class-wp-theme-json-resolver.php'; |
|
16 | 21 |
require ABSPATH . WPINC . '/script-loader.php'; |
22 |
require ABSPATH . WPINC . '/version.php'; |
|
23 |
||
24 |
$protocol = $_SERVER['SERVER_PROTOCOL']; |
|
25 |
if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ), true ) ) { |
|
26 |
$protocol = 'HTTP/1.0'; |
|
27 |
} |
|
0 | 28 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
$load = $_GET['load']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
if ( is_array( $load ) ) { |
16 | 31 |
ksort( $load ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
$load = implode( '', $load ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
} |
16 | 34 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
$load = preg_replace( '/[^a-z0-9,_-]+/i', '', $load ); |
0 | 36 |
$load = array_unique( explode( ',', $load ) ); |
37 |
||
9 | 38 |
if ( empty( $load ) ) { |
16 | 39 |
header( "$protocol 400 Bad Request" ); |
0 | 40 |
exit; |
9 | 41 |
} |
0 | 42 |
|
16 | 43 |
$rtl = ( isset( $_GET['dir'] ) && 'rtl' === $_GET['dir'] ); |
44 |
$expires_offset = 31536000; // 1 year. |
|
9 | 45 |
$out = ''; |
0 | 46 |
|
47 |
$wp_styles = new WP_Styles(); |
|
9 | 48 |
wp_default_styles( $wp_styles ); |
0 | 49 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
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
|
51 |
header( "$protocol 304 Not Modified" ); |
16 | 52 |
exit; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
} |
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 |
foreach ( $load as $handle ) { |
9 | 56 |
if ( ! array_key_exists( $handle, $wp_styles->registered ) ) { |
0 | 57 |
continue; |
9 | 58 |
} |
0 | 59 |
|
9 | 60 |
$style = $wp_styles->registered[ $handle ]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
if ( empty( $style->src ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
|
0 | 66 |
$path = ABSPATH . $style->src; |
67 |
||
5 | 68 |
if ( $rtl && ! empty( $style->extra['rtl'] ) ) { |
69 |
// All default styles have fully independent RTL files. |
|
70 |
$path = str_replace( '.min.css', '-rtl.min.css', $path ); |
|
0 | 71 |
} |
72 |
||
5 | 73 |
$content = get_file( $path ) . "\n"; |
74 |
||
75 |
if ( strpos( $style->src, '/' . WPINC . '/css/' ) === 0 ) { |
|
76 |
$content = str_replace( '../images/', '../' . WPINC . '/images/', $content ); |
|
77 |
$content = str_replace( '../js/tinymce/', '../' . WPINC . '/js/tinymce/', $content ); |
|
78 |
$content = str_replace( '../fonts/', '../' . WPINC . '/fonts/', $content ); |
|
9 | 79 |
$out .= $content; |
0 | 80 |
} else { |
81 |
$out .= str_replace( '../images/', 'images/', $content ); |
|
82 |
} |
|
83 |
} |
|
84 |
||
9 | 85 |
header( "Etag: $wp_version" ); |
86 |
header( 'Content-Type: text/css; charset=UTF-8' ); |
|
87 |
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' ); |
|
88 |
header( "Cache-Control: public, max-age=$expires_offset" ); |
|
0 | 89 |
|
90 |
echo $out; |
|
91 |
exit; |