first commit
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php exit;
|
||||
/**
|
||||
* Autoptimize's magic 404 handler.
|
||||
*
|
||||
* Configure your webserver to have requests for files that are no longer in
|
||||
* /wp-content/cache/autoptimize/ to redirect to this file. AO's .htaccess file
|
||||
* will have a "Errordocument:" directive to automatically do this.
|
||||
*
|
||||
* This file has simple logic to redirect to the "fallback" files that are
|
||||
* created automatically by AO to avoid visitors seeing broken pages or
|
||||
* Googlebot getting utterly confused.
|
||||
*
|
||||
* Error logging is off by default (don't want to flood your php errorlog, but
|
||||
* can be enabled by this code snippet:
|
||||
*
|
||||
* add_filter( 'autoptimize_filter_cache_fallback_log_errors', '__return_true' );
|
||||
*
|
||||
* Warning: the fallback files might not apply to all pages, so this is a just
|
||||
* a temporary solution, you really should clear any page cache to avoid requests
|
||||
* to files that don't exist in AO's cache.
|
||||
*/
|
||||
|
||||
$original_request = strtok( $_SERVER['REQUEST_URI'], '?' );
|
||||
|
||||
if ( strpos( $original_request, 'uucss/uucss-' ) !== false ) {
|
||||
$original_request = preg_replace( '/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request );
|
||||
}
|
||||
|
||||
$fallback_target = preg_replace( '/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request );
|
||||
$ao_cache_dir = '<!--ao-cache-dir-->';
|
||||
$js_or_css = pathinfo( $original_request, PATHINFO_EXTENSION );
|
||||
$fallback_path = $ao_cache_dir . $js_or_css . '/autoptimize_fallback.' . $js_or_css;
|
||||
|
||||
if ( $original_request !== $fallback_target && file_exists( $fallback_path ) ) {
|
||||
// error_log( 'Autoptimize file ' . $original_request . ' not found, using fallback instead.' );
|
||||
header( 'HTTP/1.1 301 Moved Permanently' );
|
||||
header( 'Location: ' . $fallback_target );
|
||||
} else {
|
||||
// error_log( 'Autoptimize file ' . $original_request . ' not found, sending 410 gone response.' );
|
||||
header( 'HTTP/1.1 410 Gone' );
|
||||
}
|
||||
|
||||
exit();
|
||||
87
wp-content/plugins/autoptimize/config/default.php
Normal file
87
wp-content/plugins/autoptimize/config/default.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php exit;
|
||||
|
||||
//Check everything exists before using it
|
||||
if(!isset($_SERVER['HTTP_ACCEPT_ENCODING']))
|
||||
$_SERVER['HTTP_ACCEPT_ENCODING'] = '';
|
||||
if(!isset($_SERVER['HTTP_USER_AGENT']))
|
||||
$_SERVER['HTTP_USER_AGENT'] = '';
|
||||
|
||||
// Determine supported compression method
|
||||
$gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
|
||||
$deflate = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate');
|
||||
|
||||
// Determine used compression method
|
||||
$encoding = $gzip ? 'gzip' : ($deflate ? 'deflate' : 'none');
|
||||
|
||||
// Check for buggy versions of Internet Explorer
|
||||
if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Opera') &&
|
||||
preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches))
|
||||
{
|
||||
$version = floatval($matches[1]);
|
||||
|
||||
if ($version < 6)
|
||||
$encoding = 'none';
|
||||
|
||||
if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1'))
|
||||
$encoding = 'none';
|
||||
}
|
||||
|
||||
//Some servers compress the output of PHP - Don't break in those cases
|
||||
if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1)
|
||||
$encoding = 'none';
|
||||
|
||||
$iscompressed = file_exists(__FILE__.'.'.$encoding);
|
||||
if($encoding != 'none' && $iscompressed == false)
|
||||
{
|
||||
$flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE);
|
||||
$code = file_get_contents(__FILE__.'.none');
|
||||
$contents = gzencode($code,9,$flag);
|
||||
}else{
|
||||
//Get data
|
||||
$contents = file_get_contents(__FILE__.'.'.$encoding);
|
||||
}
|
||||
|
||||
// first check if we have to send 304
|
||||
// inspired by http://www.jonasjohn.de/snippets/php/caching.htm
|
||||
|
||||
$eTag=md5($contents);
|
||||
$modTime=filemtime(__FILE__.'.none');
|
||||
|
||||
date_default_timezone_set("UTC");
|
||||
$eTagMatch = (isset($_SERVER['HTTP_IF_NONE_MATCH']) && strpos($_SERVER['HTTP_IF_NONE_MATCH'],$eTag));
|
||||
$modTimeMatch = (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === $modTime);
|
||||
|
||||
if (($modTimeMatch)||($eTagMatch)) {
|
||||
header('HTTP/1.1 304 Not Modified');
|
||||
header('Connection: close');
|
||||
} else {
|
||||
// send all sorts of headers
|
||||
$expireTime=60*60*24*355; // 1y max according to RFC
|
||||
if ($encoding != 'none') {
|
||||
header('Content-Encoding: '.$encoding);
|
||||
}
|
||||
header('Vary: Accept-Encoding');
|
||||
header('Content-Length: '.strlen($contents));
|
||||
header('Content-type: %%CONTENT%%; charset=utf-8');
|
||||
header('Cache-Control: max-age='.$expireTime.', public, must-revalidate');
|
||||
header('Cache-Control: max-age='.$expireTime.', public, immutable');
|
||||
header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT');
|
||||
header('ETag: ' . $eTag);
|
||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT');
|
||||
|
||||
// send output
|
||||
echo $contents;
|
||||
|
||||
//And write to filesystem cache if not done yet
|
||||
if($encoding != 'none' && $iscompressed == false)
|
||||
{
|
||||
//Write the content we sent
|
||||
file_put_contents(__FILE__.'.'.$encoding,$contents);
|
||||
|
||||
//And write the new content
|
||||
$flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP);
|
||||
$ext = ($encoding == 'gzip' ? 'deflate' : 'gzip');
|
||||
$contents = gzencode($code,9,$flag);
|
||||
file_put_contents(__FILE__.'.'.$ext,$contents);
|
||||
}
|
||||
}
|
||||
1
wp-content/plugins/autoptimize/config/index.html
Normal file
1
wp-content/plugins/autoptimize/config/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>
|
||||
Reference in New Issue
Block a user