//.........这里部分代码省略.........
$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}\$1/index.html.gz -f\n";
$rules .= "RewriteRule ^(.*) {$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}\$1/index.html.gz [L]\n\n";
$rules .= "CONDITION_RULES";
$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}\$1/index.html -f\n";
$rules .= "RewriteRule ^(.*) {$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}\$1/index.html [L]\n";
$rules .= "</IfModule>\n";
$rules = apply_filters('supercacherewriterules', $rules);
$rules = str_replace("CONDITION_RULES", implode("\n", $condition_rules) . "\n", $rules);
$dohtaccess = true;
if (function_exists('is_site_admin')) {
echo "<h4 style='color: #a00'>" . __('WordPress MU Detected', 'wp-super-cache') . "</h4><p>" . __("Unfortunately the rewrite rules cannot be updated automatically when running WordPress MU. Please open your .htaccess and add the following mod_rewrite rules above any other rules in that file.", 'wp-super-cache') . "</p>";
} elseif (!$wprules || $wprules == '') {
echo "<h4 style='color: #a00'>" . __('Mod Rewrite rules cannot be updated!', 'wp-super-cache') . "</h4>";
echo "<p>" . sprintf(__("You must have <strong>BEGIN</strong> and <strong>END</strong> markers in %s.htaccess for the auto update to work. They look like this and surround the main WordPress mod_rewrite rules:", 'wp-super-cache'), $home_path);
echo "<blockquote><pre><em># BEGIN WordPress</em>\n RewriteCond %{REQUEST_FILENAME} !-f\n RewriteCond %{REQUEST_FILENAME} !-d\n RewriteRule . /index.php [L]\n <em># END WordPress</em></pre></blockquote>";
_e('Refresh this page when you have updated your .htaccess file.', 'wp-super-cache');
echo "</fieldset></div>";
return;
} elseif (strpos($wprules, 'wordpressuser')) {
// Need to clear out old mod_rewrite rules
echo "<p><strong>" . __('Thank you for upgrading.', 'wp-super-cache') . "</strong> " . sprintf(__('The mod_rewrite rules changed since you last installed this plugin. Unfortunately you must remove the old supercache rules before the new ones are updated. Refresh this page when you have edited your .htaccess file. If you wish to manually upgrade, change the following line: %1$s so it looks like this: %2$s The only changes are "HTTP_COOKIE" becomes "HTTP:Cookie" and "wordpressuser" becomes "wordpress". This is a WordPress 2.5 change but it’s backwards compatible with older versions if you’re brave enough to use them.', 'wp-super-cache'), '<blockquote><code>RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$</code></blockquote>', '<blockquote><code>RewriteCond %{HTTP:Cookie} !^.*wordpress.*$</code></blockquote>') . "</p>";
echo "</fieldset></div>";
return;
} elseif ($scrules != '' && strpos($scrules, '%{REQUEST_URI} !^.*[^/]$') === false && substr(get_option('permalink_structure'), -1) == '/') {
// permalink structure has a trailing slash, need slash check in rules.
echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><h4>" . __('Trailing slash check required.', 'wp-super-cache') . "</h4><p>" . __('It looks like your blog has URLs that end with a "/". Unfortunately since you installed this plugin a duplicate content bug has been found where URLs not ending in a "/" end serve the same content as those with the "/" and do not redirect to the proper URL. To fix, you must edit your .htaccess file and add these two rules to the two groups of Super Cache rules:', 'wp-super-cache') . "</p>";
echo "<blockquote><code>RewriteCond %{REQUEST_URI} !^.*[^/]{$RewriteCond} %{REQUEST_URI} !^.*//.*\$</code></blockquote>";
echo "<p>" . __('You can see where the rules go and examine the complete rules by clicking the "View mod_rewrite rules" link below.', 'wp-super-cache') . "</p></div>";
$dohtaccess = false;
} elseif (strpos($scrules, 'supercache') || strpos($wprules, 'supercache')) {
// only write the rules once
$dohtaccess = false;
}
// cache/.htaccess rules
$gziprules = "<IfModule mod_mime.c>\n <FilesMatch \"\\.html\\.gz\$\">\n ForceType text/html\n FileETag None\n </FilesMatch>\n AddEncoding gzip .gz\n AddType text/html .gz\n</IfModule>\n";
$gziprules .= "<IfModule mod_deflate.c>\n SetEnvIfNoCase Request_URI \\.gz\$ no-gzip\n</IfModule>\n";
$gziprules .= "<IfModule mod_headers.c>\n Header set Vary \"Accept-Encoding, Cookie\"\n Header set Cache-Control 'max-age=300, must-revalidate'\n</IfModule>\n";
$gziprules .= "<IfModule mod_expires.c>\n ExpiresActive On\n ExpiresByType text/html A300\n</IfModule>\n";
if ($dohtaccess && !$_POST['updatehtaccess']) {
if (!is_writeable_ACLSafe($home_path . ".htaccess")) {
echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><h4>" . __('Cannot update .htaccess', 'wp-super-cache') . "</h4><p>" . sprintf(__('The file <code>%s.htaccess</code> cannot be modified by the web server. Please correct this using the chmod command or your ftp client.', 'wp-super-cache'), $home_path) . "</p><p>" . __('Refresh this page when the file permissions have been modified.') . "</p><p>" . sprintf(__('Alternatively, you can edit your <code>%s.htaccess</code> file manually and add the following code (before any WordPress rules):', 'wp-super-cache'), $home_path) . "</p>";
echo "<p><pre># BEGIN WPSuperCache\n" . wp_specialchars($rules) . "# END WPSuperCache</pre></p></div>";
} else {
echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><p>" . sprintf(__('To serve static html files your server must have the correct mod_rewrite rules added to a file called <code>%s.htaccess</code>', 'wp-super-cache'), $home_path) . " ";
if (!function_exists('is_site_admin')) {
_e("You must edit the file yourself add the following rules.", 'wp-super-cache');
} else {
_e("You can edit the file yourself add the following rules.", 'wp-super-cache');
}
echo __(" Make sure they appear before any existing WordPress rules. ", 'wp-super-cache') . "</p>";
echo "<pre># BEGIN WPSuperCache\n" . wp_specialchars($rules) . "# END WPSuperCache</pre></p>";
echo "<p>" . sprintf(__('Rules must be added to %s too:', 'wp-super-cache'), WP_CONTENT_DIR . "/cache/.htaccess") . "</p>";
echo "<pre># BEGIN supercache\n" . wp_specialchars($gziprules) . "# END supercache</pre></p>";
if (!function_exists('is_site_admin')) {
echo '<form name="updatehtaccess" action="#modrewrite" method="post">';
echo '<input type="hidden" name="updatehtaccess" value="1" />';
echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'id="updatehtaccess" value="' . __('Update Mod_Rewrite Rules', 'wp-super-cache') . ' »" /></div>';
wp_nonce_field('wp-cache');
echo "</form></div>\n";
}
}
} elseif ($dohtaccess && $valid_nonce && $_POST['updatehtaccess']) {
wpsc_remove_marker($home_path . '.htaccess', 'WordPress');
// remove original WP rules so SuperCache rules go on top
echo "<div style='padding:0 8px;color:#4f8a10;background-color:#dff2bf;border:1px solid #4f8a10;'>";
if (insert_with_markers($home_path . '.htaccess', 'WPSuperCache', explode("\n", $rules)) && insert_with_markers($home_path . '.htaccess', 'WordPress', explode("\n", $wprules))) {
echo "<h4>" . __('Mod Rewrite rules updated!', 'wp-super-cache') . "</h4>";
echo "<p><strong>" . sprintf(__('%s.htaccess has been updated with the necessary mod_rewrite rules. Please verify they are correct. They should look like this:', 'wp-super-cache'), $home_path) . "</strong></p>\n";
} else {
echo "<h4>" . __('Mod Rewrite rules must be updated!', 'wp-super-cache') . "</h4>";
echo "<p><strong>" . sprintf(__('Your %s.htaccess is not writable by the webserver and must be updated with the necessary mod_rewrite rules. The new rules go above the regular WordPress rules as shown in the code below:', 'wp-super-cache'), $home_path) . "</strong></p>\n";
}
echo "<p><pre>" . wp_specialchars($rules) . "</pre></p>\n</div>";
} else {
?>
<p><?php
printf(__('WP Super Cache mod rewrite rules were detected in your %s.htaccess file.<br /> Click the following link to see the lines added to that file. If you have upgraded the plugin make sure these rules match.', 'wp-super-cache'), $home_path);
?>
<br /><br />
<a href="javascript:toggleLayer('rewriterules');" class="button"><?php
_e('View Mod_Rewrite Rules', 'wp-super-cache');
?>
</a>
<div id='rewriterules' style='display: none;'>
<?php
echo "<p><pre># BEGIN WPSuperCache\n" . wp_specialchars($rules) . "# END WPSuperCache</pre></p>\n";
echo "<p>" . sprintf(__('Rules must be added to %s too:', 'wp-super-cache'), WP_CONTENT_DIR . "/cache/.htaccess") . "</p>";
echo "<pre># BEGIN supercache\n" . wp_specialchars($gziprules) . "# END supercache</pre></p>";
?>
</div>
<?php
}
// http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/
if (!is_file($cache_path . '.htaccess')) {
$gziprules = insert_with_markers($cache_path . '.htaccess', 'supercache', explode("\n", $gziprules));
echo "<h4>" . sprintf(__('Gzip encoding rules in %s.htaccess created.', 'wp-super-cache'), $cache_path) . "</h4>";
}
?>
</fieldset><?php
}
function wp_cache_disable_plugin()
{
global $wp_cache_config_file, $wp_rewrite;
if (file_exists(ABSPATH . 'wp-config.php')) {
$global_config_file = ABSPATH . 'wp-config.php';
} else {
$global_config_file = dirname(ABSPATH) . '/wp-config.php';
}
$line = 'define(\'WP_CACHE\', true);';
if (strpos(file_get_contents($global_config_file), $line) && (!is_writeable_ACLSafe($global_config_file) || !wp_cache_replace_line('define *\\( *\'WP_CACHE\'', '//' . $line, $global_config_file))) {
wp_die("Could not remove WP_CACHE define from {$global_config_file}. Please edit that file and remove the line containing the text 'WP_CACHE'. Then refresh this page.");
}
uninstall_supercache(WP_CONTENT_DIR . '/cache');
$file_not_deleted = false;
if (@file_exists(WP_CONTENT_DIR . "/advanced-cache.php")) {
if (false == @unlink(WP_CONTENT_DIR . "/advanced-cache.php")) {
$file_not_deleted[] = 'advanced-cache.php';
}
}
if (@file_exists(WP_CONTENT_DIR . "/wp-cache-config.php")) {
if (false == unlink(WP_CONTENT_DIR . "/wp-cache-config.php")) {
$file_not_deleted[] = 'wp-cache-config.php';
}
}
if ($file_not_deleted) {
$msg = "<p>One or more files could not be deleted. These files and directories must be made writeable:</p>\n <ol><li>" . WP_CONTENT_DIR . "</li>\n";
$code = "<ul>\n";
foreach ((array) $file_not_deleted as $filename) {
$msg .= "<li>" . WP_CONTENT_DIR . "/{$filename}</li>";
$code .= "<li><code>chmod 666 " . WP_CONTENT_DIR . "/{$filename}</code></li>\n";
}
$code .= "</ul>\n";
$msg .= "</ol>\n<p>First try fixing the directory permissions with this command and refresh this page:<br /><br /><code>chmod 777 " . WP_CONTENT_DIR . "</code><br /><br />If you still see this error, you have to fix the permissions on the files themselves and refresh this page again:</p> {$code}\n<p>Don't forgot to fix things later:<br /><code>chmod 755 " . WP_CONTENT_DIR . "</code></p><p>If you don't know what <strong>chmod</strong> is use <a href='http://www.google.ie/search?hl=en&q=ftp+chmod+777'>this Google search</a> to find out all about it.</p><p>Please refresh this page when the permissions have been modified.</p>";
wp_die($msg);
}
extract(wpsc_get_htaccess_info());
if ($scrules != '' && insert_with_markers($home_path . '.htaccess', 'WPSuperCache', array())) {
$wp_rewrite->flush_rules();
} elseif ($scrules != '') {
wp_mail(get_option('admin_email'), __('Supercache Uninstall Problems', 'wp-super-cache'), sprintf(__("Dear User,\n\nWP Super Cache was removed from your blog but the mod_rewrite rules\nin your .htaccess were not.\n\nPlease edit the following file and remove the code\nbetween 'BEGIN WPSuperCache' and 'END WPSuperCache'. Please backup the file first!\n\n%s\n\nRegards,\nWP Super Cache Plugin\nhttp://wordpress.org/extend/plugins/wp-super-cache/", 'wp-super-cache'), ABSPATH . '/.htaccess'));
}
}
/**
* Get the path to the backups directory
*
* Will try to create it if it doesn't exist
* and will fallback to default if a custom dir
* isn't writable.
*/
function hmbkp_path()
{
global $is_apache;
$path = untrailingslashit(get_option('hmbkp_path'));
// Allow the backups path to be defined
if (defined('HMBKP_PATH') && HMBKP_PATH) {
$path = untrailingslashit(HMBKP_PATH);
}
// If the dir doesn't exist or isn't writable then use the default path instead instead
if ((!$path || is_dir($path) && !is_writable($path) || !is_dir($path) && !is_writable(dirname($path))) && $path !== hmbkp_path_default()) {
$path = hmbkp_path_default();
}
// Create the backups directory if it doesn't exist
if (!is_dir($path) && is_writable(dirname($path))) {
wp_mkdir_p($path);
}
// If the path has changed then cache it
if (get_option('hmbkp_path') !== $path) {
update_option('hmbkp_path', $path);
}
// Protect against directory browsing by including a index.html file
$index = $path . '/index.html';
if (!file_exists($index) && is_writable($path)) {
file_put_contents($index, '');
}
$htaccess = $path . '/.htaccess';
// Protect the directory with a .htaccess file on Apache servers
if ($is_apache && function_exists('insert_with_markers') && !file_exists($htaccess) && is_writable($path)) {
$contents[] = '# ' . sprintf(__('This %s file ensures that other people cannot download your backup files.', 'hmbkp'), '.htaccess');
$contents[] = '';
$contents[] = '<IfModule mod_rewrite.c>';
$contents[] = 'RewriteEngine On';
$contents[] = 'RewriteCond %{QUERY_STRING} !key=' . HMBKP_SECURE_KEY;
$contents[] = 'RewriteRule (.*) - [F]';
$contents[] = '</IfModule>';
$contents[] = '';
insert_with_markers($htaccess, 'BackUpWordPress', $contents);
}
return HM_Backup::conform_dir($path);
}
请发表评论