root/tags/1_0-rc1/wp-content/blogs.php

Revision 550, 1.7 kB (checked in by donncha, 3 years ago)

WP Merge and new features

Line 
1 <?php
2 define( "BLOGDEFINITION", true );
3 require_once( "../wp-config.php" );
4
5 // Referrer protection
6 if( $_SERVER["HTTP_REFERER"] ) {
7     if( strpos( $_SERVER["HTTP_REFERER"], $current_blog->domain ) == false ) {
8         // do something against hot linking sites!
9     }
10 }
11 $file = $_GET[ 'file' ];
12 $file = ABSPATH . "wp-content/blogs.dir/" . $blog_id . '/files/' . $file;
13
14 if( is_file( $file ) ) {
15     $etag = md5( $file . filemtime( $file ) );
16     $lastModified = date( "D, j M Y H:i:s ", filemtime( $file ) ) . "GMT";
17     #$headers = apache_request_headers();
18     // get mime type
19     $ext = substr( $_SERVER[ 'REQUEST_URI' ], strrpos( $_SERVER[ 'REQUEST_URI' ], '.' ) + 1 );
20     $ext_list = array( "jpg" => "image/jpeg", "mp3" => "audio/mpeg", "mov" => "video/quicktime" );
21     if( $ext_list[ $ext ] ) {
22         $mimetype = $ext_list[ $ext ];
23     } else {
24         $mimetype = "image/$ext";
25     }
26
27     // from http://blog.rd2inc.com/archives/2005/03/24/making-dynamic-php-pages-cacheable/
28     if( $_SERVER[ 'HTTP_IF_NONE_MATCH' ] == '"' . $etag . '"' || $lastModified == $_SERVER['HTTP_IF_MODIFIED_SINCE']) {
29         // They already have an up to date copy so tell them
30         header('HTTP/1.1 304 Not Modified');
31         header('Cache-Control: private');
32         header('Content-Type: $mimetype');
33         header('ETag: "'.$etag.'"');
34     } else {
35         header("Content-type: $mimetype" );
36         header( "Last-Modified: " . $lastModified );
37         header( 'Accept-Ranges: bytes' );
38         header( "Content-Length: " . filesize( $file ) );
39         header( 'ETag: "' . $etag . '"' );
40         readfile( $file );
41     }
42 } else {
43     // 404
44     header("HTTP/1.1 404 Not Found");
45     print "<html><head><title>Error 404! File Not Found!</title></head>";
46     print "<body>";
47     print "<h1>File Not Found!</h1>";
48     print "</body></html>";
49 }
50 ?>
51
Note: See TracBrowser for help on using the browser.