forked from staylor/minify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.php
86 lines (70 loc) · 2.45 KB
/
make.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* dynamic md5 string or sluf indicating which batch of assets is requested
*
*/
$hash = ( !empty( $_GET[ 'hash' ] ) ? $_GET[ 'hash' ] : false );
/**
* must be css or js
*
*/
$type = ( !empty( $_GET[ 'type' ] ) && in_array( $_GET[ 'type' ], array( 'css', 'js' ) ) ? $_GET[ 'type' ] : false );
$incr = ( !empty( $_GET[ 'incr' ] ) ? $_GET[ 'incr' ] : false );
if( empty( $type ) || empty( $incr ) || empty( $hash ) )
die( 'Not all parameters are included' );
define( 'SHORTINIT', true );
/**
* load bare-bones WP so we get Cache / Options / Transients
*
*/
$load_path = $_SERVER[ 'DOCUMENT_ROOT' ] . '/wordpress/wp-load.php';
if ( !is_file( $load_path ) )
$load_path = $_SERVER[ 'DOCUMENT_ROOT' ] . '/wp-load.php';
if ( !is_file( $load_path ) )
die( 'WHERE IS WORDPRESS? Please edit: ' . __FILE__ );
require_once( $load_path );
/**
* SHORTINIT does NOT load plugins, so load our base plugin file
* Also doesn't load large chunks of WordPress, so load in a few files we need
* @TODO: Only load the below files if we need to (though it's pretty lightweight)
*/
if( !defined( 'sanitize_option' ) )
require_once( ABSPATH . WPINC . '/formatting.php' );
if( !defined( 'wp_remote_get' ) ) {
require_once( ABSPATH . WPINC . '/class-http.php' );
require_once( ABSPATH . WPINC . '/http.php' );
}
if( !defined( 'get_bloginfo' ) ) {
require_once( ABSPATH . WPINC . '/general-template.php' );
require_once( ABSPATH . WPINC . '/link-template.php' );
}
require_once( dirname( __FILE__ ) . '/minify.php' );
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $minify->cache_ttl ) . ' GMT', true );
header( 'Cache-Control: max-age=' . $minify->cache_ttl . ', public', true );
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $minify->cache_ttl ) . ' GMT', true );
header( 'Pragma: public', true );
/**
* Serve JS or CSS file
*
*/
switch ( $type ) {
case 'js':
header( 'Content-type: application/x-javascript; charset=UTF-8', true );
break;
case 'css':
header( 'Content-type: text/css; charset=UTF-8', true );
break;
}
$src = get_site_transient( 'minify:' . $type . '-output:' . $hash . ':' . $incr );
if ( empty( $src ) ) {
$files = get_site_option( 'minify:' . $type . ':' . $hash . ':' . $incr );
if ( !empty( $files ) ) {
$minify->combine( $hash, $files, $type, true );
} else {
http_response_code( 500 );
error_log( 'Minified files of type ' . $type . ' with hash = ' . $hash . ' not found...' );
}
} else {
exit( $src );
}
exit();