| 2 | | define( "BLOGDEFINITION", true ); |
|---|
| 3 | | require_once( "../wp-config.php" ); |
|---|
| | 2 | define( 'BLOGDEFINITION', true ); // this prevents most of WP from being loaded |
|---|
| | 3 | require_once( dirname( dirname( __FILE__) ) . '/wp-config.php' ); // absolute includes are faster |
|---|
| | 4 | |
|---|
| | 5 | if ( |
|---|
| | 6 | $current_blog->archived == '1' || |
|---|
| | 7 | $current_blog->spam == '1' || |
|---|
| | 8 | $current_blog->deleted == '1' |
|---|
| | 9 | ) { |
|---|
| | 10 | header("HTTP/1.1 404 Not Found"); |
|---|
| | 11 | graceful_fail('404 — File not found.'); |
|---|
| | 12 | } |
|---|
| 71 | | if( is_file( $file ) ) { |
|---|
| 72 | | $etag = md5( $file . filemtime( $file ) ); |
|---|
| 73 | | $lastModified = date( "D, j M Y H:i:s ", filemtime( $file ) ) . "GMT"; |
|---|
| 74 | | #$headers = apache_request_headers(); |
|---|
| 75 | | // get mime type |
|---|
| 76 | | $mime = wp_check_filetype( $_SERVER[ 'REQUEST_URI' ] ); |
|---|
| 77 | | if( $mime[ 'type' ] != false ) { |
|---|
| 78 | | $mimetype = $mime[ 'type' ]; |
|---|
| 79 | | } else { |
|---|
| 80 | | $ext = substr( $_SERVER[ 'REQUEST_URI' ], strrpos( $_SERVER[ 'REQUEST_URI' ], '.' ) + 1 ); |
|---|
| 81 | | $mimetype = "image/$ext"; |
|---|
| 82 | | } |
|---|
| | 80 | // These should never, ever be served |
|---|
| | 81 | $never = array( 'js', 'exe', 'swf', 'class', 'tar', 'zip', 'rar' ); |
|---|
| | 82 | if ( in_array( preg_replace( '|.*\.(.*)$|', '$1', $file ), $never ) ) { |
|---|
| | 83 | header("HTTP/1.1 404 Not Found"); |
|---|
| | 84 | graceful_fail('404 — File not found.'); |
|---|
| | 85 | } |
|---|
| 84 | | // from http://blog.rd2inc.com/archives/2005/03/24/making-dynamic-php-pages-cacheable/ |
|---|
| 85 | | if( $_SERVER[ 'HTTP_IF_NONE_MATCH' ] == '"' . $etag . '"' || $lastModified == $_SERVER['HTTP_IF_MODIFIED_SINCE']) { |
|---|
| 86 | | // They already have an up to date copy so tell them |
|---|
| 87 | | header('HTTP/1.1 304 Not Modified'); |
|---|
| 88 | | header('Cache-Control: private'); |
|---|
| 89 | | header('Content-Type: $mimetype'); |
|---|
| 90 | | header('ETag: "'.$etag.'"'); |
|---|
| 91 | | } else { |
|---|
| 92 | | header("Content-type: $mimetype" ); |
|---|
| 93 | | header( "Last-Modified: " . $lastModified ); |
|---|
| 94 | | header( 'Accept-Ranges: bytes' ); |
|---|
| 95 | | header( "Content-Length: " . filesize( $file ) ); |
|---|
| 96 | | header( 'ETag: "' . $etag . '"' ); |
|---|
| 97 | | readfile( $file ); |
|---|
| 98 | | } |
|---|
| | 87 | $mime = wp_check_filetype( $_SERVER[ 'REQUEST_URI' ] ); |
|---|
| | 88 | if( $mime[ 'type' ] != false ) { |
|---|
| | 89 | $mimetype = $mime[ 'type' ]; |
|---|
| | 94 | header( 'Content-type: ' . $mimetype ); // always send this |
|---|
| | 95 | |
|---|
| | 96 | $timestamp = filemtime( $file ); |
|---|
| | 97 | |
|---|
| | 98 | $last_modified = gmdate('D, d M Y H:i:s', $timestamp); |
|---|
| | 99 | $etag = '"' . md5($last_modified) . '"'; |
|---|
| | 100 | @header( "Last-Modified: $last_modified GMT" ); |
|---|
| | 101 | @header( 'ETag: ' . $etag ); |
|---|
| | 102 | |
|---|
| | 103 | $expire = gmdate('D, d M Y H:i:s', time() + 100000000); |
|---|
| | 104 | @header( "Expires: $expire GMT" ); |
|---|
| | 105 | |
|---|
| | 106 | // Support for Conditional GET |
|---|
| | 107 | if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) $client_etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']); |
|---|
| | 108 | else $client_etag = false; |
|---|
| | 109 | |
|---|
| | 110 | $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE']); |
|---|
| | 111 | // If string is empty, return 0. If not, attempt to parse into a timestamp |
|---|
| | 112 | $client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0; |
|---|
| | 113 | |
|---|
| | 114 | // Make a timestamp for our most recent modification... |
|---|
| | 115 | $modified_timestamp = strtotime($last_modified); |
|---|
| | 116 | |
|---|
| | 117 | if ( ($client_last_modified && $client_etag) ? |
|---|
| | 118 | (($client_modified_timestamp >= $modified_timestamp) && ($client_etag == $etag)) : |
|---|
| | 119 | (($client_modified_timestamp >= $modified_timestamp) || ($client_etag == $etag)) ) { |
|---|
| | 120 | header('HTTP/1.1 304 Not Modified'); |
|---|
| | 121 | exit; |
|---|
| | 122 | } |
|---|
| | 123 | |
|---|
| | 124 | // If we made it this far, just serve the file |
|---|
| | 125 | |
|---|
| | 126 | readfile( $file ); |
|---|
| | 127 | |
|---|