improvements to custom content dir support, props nacin, see #11742

git-svn-id: http://svn.automattic.com/wordpress/trunk@12936 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
wpmuguru 2010-02-03 18:19:56 +00:00
parent a62e167391
commit d1069acd38
4 changed files with 58 additions and 51 deletions

View File

@ -4,7 +4,7 @@ RewriteBase BASE/
#uploaded files #uploaded files
RewriteRule ^(.*/)?files/$ index.php [L] RewriteRule ^(.*/)?files/$ index.php [L]
RewriteCond %{REQUEST_URI} !.*wp-content/plugins.* RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
RewriteRule ^(.*/)?files/(.*) wp-includes/blogs.php?file=$2 [L] RewriteRule ^(.*/)?files/(.*) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin # add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} ^.*/wp-admin$ RewriteCond %{REQUEST_URI} ^.*/wp-admin$

View File

@ -1,14 +0,0 @@
<?php
/**
* Load mulitsite uploaded media
*
* @since 3.0.0
*
* @package WordPress
* @subpackage Multisite
*/
define( 'SHORTINIT', true );
require_once( dirname( dirname( __FILE__) ) . '/wp-load.php' ); // absolute includes are faster
require_once( WP_CONTENT_DIR . '/blogs.php' );
exit();

View File

@ -54,6 +54,20 @@ function ms_default_constants( $context ) {
if ( !defined('COOKIE_DOMAIN') ) if ( !defined('COOKIE_DOMAIN') )
define('COOKIE_DOMAIN', '.' . $current_site->cookie_domain); define('COOKIE_DOMAIN', '.' . $current_site->cookie_domain);
break; break;
case 'ms-files' :
/**
* Optional support for X-Sendfile header
* @since 3.0.0
*/
if ( !defined( 'WPMU_SENDFILE' ) )
define( 'WPMU_SENDFILE', false );
/**
* Optional support for X-Accel-Redirect header
* @since 3.0.0
*/
if ( !defined( 'WPMU_ACCEL_REDIRECT' ) )
define( 'WPMU_ACCEL_REDIRECT', false );
break;
} }
} }
?> ?>

77
wp-content/blogs.php → wp-includes/ms-files.php Executable file → Normal file
View File

@ -1,12 +1,22 @@
<?php <?php
if ( !defined( 'SHORTINIT' ) ) { /**
define( 'SHORTINIT', true ); // this prevents most of WP from being loaded * Load mulitsite uploaded media
require_once( dirname( dirname( __FILE__) ) . '/wp-load.php' ); // absolute includes are faster *
} * @since 3.0.0
*
* @package WordPress
* @subpackage Multisite
*/
define( 'SHORTINIT', true );
require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
ms_default_constants( 'ms-files' );
error_reporting(0);
if ( $current_blog->archived == '1' || $current_blog->spam == '1' || $current_blog->deleted == '1' ) { if ( $current_blog->archived == '1' || $current_blog->spam == '1' || $current_blog->deleted == '1' ) {
status_header( 404 ); status_header( 404 );
die('404 &#8212; File not found.'); die( '404 &#8212; File not found.' );
} }
if ( !function_exists('wp_check_filetype') ) : if ( !function_exists('wp_check_filetype') ) :
@ -53,7 +63,7 @@ function wp_check_filetype($filename, $mimes = null) {
$type = false; $type = false;
$ext = false; $ext = false;
foreach ( (array)$mimes as $ext_preg => $mime_match ) { foreach ( (array) $mimes as $ext_preg => $mime_match ) {
$ext_preg = '!\.(' . $ext_preg . ')$!i'; $ext_preg = '!\.(' . $ext_preg . ')$!i';
if ( preg_match($ext_preg, $filename, $ext_matches) ) { if ( preg_match($ext_preg, $filename, $ext_matches) ) {
$type = $mime_match; $type = $mime_match;
@ -69,62 +79,59 @@ endif;
$file = BLOGUPLOADDIR . str_replace( '..', '', $_GET[ 'file' ] ); $file = BLOGUPLOADDIR . str_replace( '..', '', $_GET[ 'file' ] );
if ( !is_file( $file ) ) { if ( !is_file( $file ) ) {
status_header( 404 ); status_header( 404 );
die('404 &#8212; File not found.'); die( '404 &#8212; File not found.' );
} }
$mime = wp_check_filetype( $_SERVER[ 'REQUEST_URI' ] ); $mime = wp_check_filetype( $_SERVER[ 'REQUEST_URI' ] );
if( $mime[ 'type' ] === false && function_exists( 'mime_content_type' ) ) if( false === $mime[ 'type' ] && function_exists( 'mime_content_type' ) )
$mime[ 'type' ] = mime_content_type( $file ); $mime[ 'type' ] = mime_content_type( $file );
if( $mime[ 'type' ] != false ) { if( $mime[ 'type' ] )
$mimetype = $mime[ 'type' ]; $mimetype = $mime[ 'type' ];
} else { else
$ext = substr( $_SERVER[ 'REQUEST_URI' ], strrpos( $_SERVER[ 'REQUEST_URI' ], '.' ) + 1 ); $mimetype = 'image/' . substr( $_SERVER[ 'REQUEST_URI' ], strrpos( $_SERVER[ 'REQUEST_URI' ], '.' ) + 1 );
$mimetype = "image/$ext";
} header( 'Content-type: ' . $mimetype ); // always send this
@header( 'Content-type: ' . $mimetype ); // always send this
if ( false === strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) ) if ( false === strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) )
@header( 'Content-Length: ' . filesize( $file ) ); header( 'Content-Length: ' . filesize( $file ) );
// Optional support for X-Sendfile and X-Accel-Redirect // Optional support for X-Sendfile and X-Accel-Redirect
if ( defined('WPMU_ACCEL_REDIRECT') && WPMU_ACCEL_REDIRECT ) { if ( WPMU_ACCEL_REDIRECT ) {
@header( 'X-Accel-Redirect: ' . str_replace( WP_CONTENT_DIR, '', $file ) ); header( 'X-Accel-Redirect: ' . str_replace( WP_CONTENT_DIR, '', $file ) );
exit; exit;
} elseif ( defined('WPMU_SENDFILE') && WPMU_SENDFILE ) { } elseif ( WPMU_SENDFILE ) {
@header( 'X-Sendfile: ' . $file ); header( 'X-Sendfile: ' . $file );
exit; exit;
} }
$last_modified = gmdate('D, d M Y H:i:s', filemtime( $file )); $last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) );
$etag = '"' . md5($last_modified) . '"'; $etag = '"' . md5( $last_modified ) . '"';
@header( "Last-Modified: $last_modified GMT" ); header( "Last-Modified: $last_modified GMT" );
@header( 'ETag: ' . $etag ); header( 'ETag: ' . $etag );
@header( 'Expires: ' . gmdate('D, d M Y H:i:s', time() + 100000000) . ' GMT' ); header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' );
// Support for Conditional GET // Support for Conditional GET
if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) $client_etag = isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ? stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) : false;
$client_etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
else
$client_etag = false;
if( !isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) if( ! isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) )
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = false; $_SERVER['HTTP_IF_MODIFIED_SINCE'] = false;
$client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE']);
$client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
// If string is empty, return 0. If not, attempt to parse into a timestamp // If string is empty, return 0. If not, attempt to parse into a timestamp
$client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0; $client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0;
// Make a timestamp for our most recent modification... // Make a timestamp for our most recent modification...
$modified_timestamp = strtotime($last_modified); $modified_timestamp = strtotime($last_modified);
if ( ($client_last_modified && $client_etag) ? if ( ( $client_last_modified && $client_etag )
(($client_modified_timestamp >= $modified_timestamp) && ($client_etag == $etag)) : ? ( ( $client_modified_timestamp >= $modified_timestamp) && ( $client_etag == $etag ) )
(($client_modified_timestamp >= $modified_timestamp) || ($client_etag == $etag)) ) { : ( ( $client_modified_timestamp >= $modified_timestamp) || ( $client_etag == $etag ) )
) {
status_header( 304 ); status_header( 304 );
exit; exit;
} }
// If we made it this far, just serve the file // If we made it this far, just serve the file
readfile( $file ); readfile( $file );
?> ?>