summaryrefslogtreecommitdiffstats
path: root/wp-content/blogs.php
blob: 63f3f0ca3242669d368f4a397991700c6f43a175 (plain)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
define( "BLOGDEFINITION", true );
require_once( "../wp-config.php" );

if ( !function_exists('wp_check_filetype') ) :
function wp_check_filetype($filename, $mimes = null) {
	// Accepted MIME types are set here as PCRE unless provided.

	$mimes = is_array($mimes) ? $mimes : array (
		'jpg|jpeg|jpe' => 'image/jpeg',
		'gif' => 'image/gif',
		'png' => 'image/png',
		'bmp' => 'image/bmp',
		'tif|tiff' => 'image/tiff',
		'ico' => 'image/x-icon',
		'asf|asx|wax|wmv|wmx' => 'video/asf',
		'avi' => 'video/avi',
		'mov|qt' => 'video/quicktime',
		'mpeg|mpg|mpe' => 'video/mpeg',
		'txt|c|cc|h' => 'text/plain',
		'rtx' => 'text/richtext',
		'css' => 'text/css',
		'htm|html' => 'text/html',
		'mp3|mp4' => 'audio/mpeg',
		'ra|ram' => 'audio/x-realaudio',
		'wav' => 'audio/wav',
		'ogg' => 'audio/ogg',
		'mid|midi' => 'audio/midi',
		'wma' => 'audio/wma',
		'rtf' => 'application/rtf',
		'js' => 'application/javascript',
		'pdf' => 'application/pdf',
		'doc' => 'application/msword',
		'pot|pps|ppt' => 'application/vnd.ms-powerpoint',
		'wri' => 'application/vnd.ms-write',
		'xla|xls|xlt|xlw' => 'application/vnd.ms-excel',
		'mdb' => 'application/vnd.ms-access',
		'mpp' => 'application/vnd.ms-project',
		'swf' => 'application/x-shockwave-flash',
		'class' => 'application/java',
		'tar' => 'application/x-tar',
		'zip' => 'application/zip',
		'gz|gzip' => 'application/x-gzip',
		'exe' => 'application/x-msdownload'
	);

	$type = false;
	$ext = false;

	foreach ($mimes as $ext_preg => $mime_match) {
		$ext_preg = '!\.(' . $ext_preg . ')$!i';
		if ( preg_match($ext_preg, $filename, $ext_matches) ) {
			$type = $mime_match;
			$ext = $ext_matches[1];
			break;
		}
	}

	return compact('ext', 'type');
}
endif;

// Referrer protection

if( $_SERVER["HTTP_REFERER"] ) {
	if( strpos( $_SERVER["HTTP_REFERER"], $current_blog->domain ) == false ) {
		// do something against hot linking sites!

	}
}
$file = $_GET[ 'file' ];
$file = ABSPATH . "wp-content/blogs.dir/" . $blog_id . '/files/' . $file;

if( is_file( $file ) ) {
	$etag = md5( $file . filemtime( $file ) );
	$lastModified = date( "D, j M Y H:i:s ", filemtime( $file ) ) . "GMT";
	#$headers = apache_request_headers();

	// get mime type

	$mime = wp_check_filetype( $_SERVER[ 'REQUEST_URI' ] );
	if( $mime[ 'type' ] != false ) {
		$mimetype = $mime[ 'type' ];
	} else {
		$ext = substr( $_SERVER[ 'REQUEST_URI' ], strrpos( $_SERVER[ 'REQUEST_URI' ], '.' ) + 1 );
		$mimetype = "image/$ext";
	}

	// from http://blog.rd2inc.com/archives/2005/03/24/making-dynamic-php-pages-cacheable/

	if( $_SERVER[ 'HTTP_IF_NONE_MATCH' ] == '"' . $etag . '"' || $lastModified == $_SERVER['HTTP_IF_MODIFIED_SINCE']) {
		// They already have an up to date copy so tell them 

		header('HTTP/1.1 304 Not Modified'); 
		header('Cache-Control: private'); 
		header('Content-Type: $mimetype'); 
		header('ETag: "'.$etag.'"'); 
	} else {
		header("Content-type: $mimetype" );
		header( "Last-Modified: " . $lastModified );
		header( 'Accept-Ranges: bytes' );
		header( "Content-Length: " . filesize( $file ) );
		header( 'ETag: "' . $etag . '"' );
		readfile( $file );
	}
} else {
	// 404

	header("HTTP/1.1 404 Not Found");
	print "<html><head><title>Error 404! File Not Found!</title></head>";
	print "<body>";
	print "<h1>File Not Found!</h1>";
	print "</body></html>";
}
?>