示例#1
0
function wsc_mod_rewrite()
{
    global $cache_enabled, $super_cache_enabled, $cache_compression, $cache_compression_changed, $valid_nonce, $cache_path;
    if ($super_cache_enabled == false && $cache_enabled == true) {
        ?>
<h3><?php 
        _e('Super Cache Compression', 'wp-super-cache');
        ?>
</h3>
		<p><?php 
        _e('Compression is enabled by default when in <em>HALF ON</em> mode.', 'wp-super-cache');
        ?>
</p>
		<?php 
        return;
    } elseif ($super_cache_enabled == false) {
        return;
    }
    if (false == defined('WPSC_DISABLE_COMPRESSION')) {
        ?>
	<a name='rewrite'></a>
	<fieldset class="options"> 
	<h3><?php 
        _e('Super Cache Compression', 'wp-super-cache');
        ?>
</h3>
	<form name="wp_manager" action="#rewrite" method="post">
	<label><input type="radio" name="cache_compression" value="1" <?php 
        if ($cache_compression) {
            echo "checked=checked";
        }
        ?>
> <?php 
        _e('Enabled', 'wp-super-cache');
        ?>
</label>
	<label><input type="radio" name="cache_compression" value="0" <?php 
        if (!$cache_compression) {
            echo "checked=checked";
        }
        ?>
> <?php 
        _e('Disabled', 'wp-super-cache');
        ?>
</label>
	<p><?php 
        _e('Compression is disabled by default because some hosts have problems with compressed files. Switching this on and off clears the cache.', 'wp-super-cache');
        ?>
</p>
	<?php 
        if (isset($cache_compression_changed) && isset($_POST['cache_compression']) && !$cache_compression) {
            ?>
<p><strong><?php 
            _e('Super Cache compression is now disabled.', 'wp-super-cache');
            ?>
</strong></p> <?php 
        } elseif (isset($cache_compression_changed) && isset($_POST['cache_compression']) && $cache_compression) {
            ?>
<p><strong><?php 
            _e('Super Cache compression is now enabled.', 'wps-uper-cache');
            ?>
</strong></p><?php 
        }
        echo '<div class="submit"><input ' . SUBMITDISABLED . 'type="submit" value="' . __('Update Compression', 'wp-super-cache') . ' &raquo;" /></div>';
        wp_nonce_field('wp-cache');
        echo "</form>\n";
        ?>
</fieldset>
	<?php 
    }
    ?>

	<a name="modrewrite"></a><fieldset class="options"> 
	<h3><?php 
    _e('Mod Rewrite Rules', 'wp-super-cache');
    ?>
</h3><?php 
    if (isset($_SERVER["PHP_DOCUMENT_ROOT"])) {
        $document_root = $_SERVER["PHP_DOCUMENT_ROOT"];
        $apache_root = $_SERVER["PHP_DOCUMENT_ROOT"];
    } else {
        $document_root = $_SERVER["DOCUMENT_ROOT"];
        $apache_root = '%{DOCUMENT_ROOT}';
    }
    $home_path = get_home_path();
    $home_root = parse_url(get_bloginfo('url'));
    $home_root = isset($home_root['path']) ? trailingslashit($home_root['path']) : '/';
    $inst_root = str_replace('//', '/', '/' . trailingslashit(str_replace($document_root, '', str_replace('\\', '/', WP_CONTENT_DIR))));
    $wprules = implode("\n", extract_from_markers($home_path . '.htaccess', 'WordPress'));
    $wprules = str_replace("RewriteEngine On\n", '', $wprules);
    $wprules = str_replace("RewriteBase {$home_root}\n", '', $wprules);
    $scrules = implode("\n", extract_from_markers($home_path . '.htaccess', 'WPSuperCache'));
    if (substr(get_option('permalink_structure'), -1) == '/') {
        $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*[^/]\$";
        $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*//.*\$";
    }
    $condition_rules[] = "RewriteCond %{REQUEST_METHOD} !POST";
    $condition_rules[] = "RewriteCond %{QUERY_STRING} !.*=.*";
    $condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*\$";
    $condition_rules[] = "RewriteCond %{HTTP_USER_AGENT} !^.*(Android|2.0\\ MMP|240x320|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|hiptop|IEMobile|iPhone|iPod|KYOCERA/WX310K|LG/U990|MIDP-2.0|MMEF20|MOT-V|NetFront|Newt|Nintendo\\ Wii|Nitro|Nokia|Opera\\ Mini|Palm|Playstation\\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|Small|SonyEricsson|Symbian\\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|Windows\\ CE|WinWAP).*";
    $condition_rules = apply_filters('supercacherewriteconditions', $condition_rules);
    $rules = "<IfModule mod_rewrite.c>\n";
    $rules .= "RewriteEngine On\n";
    $rules .= "RewriteBase {$home_root}\n";
    // props Chris Messina
    $charset = get_option('blog_charset') == '' ? 'UTF-8' : get_option('blog_charset');
    $rules .= "AddDefaultCharset {$charset}\n";
    $rules .= "CONDITION_RULES";
    $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
    $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&#8217;s backwards compatible with older versions if you&#8217;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') . ' &raquo;" /></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 
}
示例#2
0
function wsc_mod_rewrite()
{
    global $super_cache_enabled, $cache_compression, $cache_compression_changed, $valid_nonce, $cache_path;
    if ($super_cache_enabled == false) {
        return;
    }
    ?>
	<br /><fieldset class="options"> 
	<h3>Super Cache Compression</h3>
	<form name="wp_manager" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
" method="post">
	<label><input type="radio" name="cache_compression" value="1" <?php 
    if ($cache_compression) {
        echo "checked=checked";
    }
    ?>
> Enabled</label>
	<label><input type="radio" name="cache_compression" value="0" <?php 
    if (!$cache_compression) {
        echo "checked=checked";
    }
    ?>
> Disabled</label>
	<p>Compression is disabled by default because some hosts have problems with compressed files. Switching this on and off clears the cache.</p>
	<?php 
    if (isset($cache_compression_changed) && isset($_POST['cache_compression']) && !$cache_compression) {
        ?>
<p><strong>Super Cache compression is now disabled.</strong></p> <?php 
    } elseif (isset($cache_compression_changed) && isset($_POST['cache_compression']) && $cache_compression) {
        ?>
<p><strong>Super Cache compression is now enabled.</strong></p><?php 
    }
    echo '<div><input ' . SUBMITDISABLED . 'type="submit" value="Update Compression &raquo;" /></div>';
    wp_nonce_field('wp-cache');
    echo "</form>\n";
    ?>
</fieldset><br />

	<a name="modrewrite"></a><fieldset class="options"> 
	<h3>Mod Rewrite Rules</h3><?php 
    $home_path = get_home_path();
    $home_root = parse_url(get_bloginfo('url'));
    $home_root = trailingslashit($home_root['path']);
    $inst_root = parse_url(get_bloginfo('wpurl'));
    $inst_root = trailingslashit($inst_root['path']);
    $wprules = implode("\n", extract_from_markers($home_path . '.htaccess', 'WordPress'));
    $wprules = str_replace("RewriteEngine On\n", '', $wprules);
    $wprules = str_replace("RewriteBase {$home_root}\n", '', $wprules);
    $scrules = implode("\n", extract_from_markers($home_path . '.htaccess', 'WPSuperCache'));
    if (substr(get_option('permalink_structure'), -1) == '/') {
        $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*[^/]\$";
        $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*//.*\$";
    }
    $condition_rules[] = "RewriteCond %{REQUEST_METHOD} !=POST";
    $condition_rules[] = "RewriteCond %{QUERY_STRING} !.*=.*";
    $condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*\$";
    $condition_rules = apply_filters('supercacherewriteconditions', $condition_rules);
    $rules = "<IfModule mod_rewrite.c>\n";
    $rules .= "RewriteEngine On\n";
    $rules .= "RewriteBase {$home_root}\n";
    // props Chris Messina
    $charset = get_option('blog_charset') == '' ? 'UTF-8' : get_option('blog_charset');
    $rules .= "AddDefaultCharset {$charset}\n";
    $rules .= "CONDITION_RULES";
    $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
    $rules .= "RewriteCond %{DOCUMENT_ROOT}{$inst_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}\$1/index.html.gz -f\n";
    $rules .= "RewriteRule ^(.*) {$inst_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}\$1/index.html.gz [L]\n\n";
    $rules .= "CONDITION_RULES";
    $rules .= "RewriteCond %{DOCUMENT_ROOT}{$inst_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}\$1/index.html -f\n";
    $rules .= "RewriteRule ^(.*) {$inst_root}wp-content/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</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.</p>";
    } elseif (!$wprules || $wprules == '') {
        echo "<h4 style='color: #a00'>Mod Rewrite rules cannot be updated!</h4>";
        echo "<p>You must have <strong>BEGIN</strong> and <strong>END</strong> markers in {$home_path}.htaccess for the auto update to work. They look like this and surround the main WordPress mod_rewrite rules:\n\t\t<blockquote><code><em># BEGIN WordPress</em><br /> RewriteCond %{REQUEST_FILENAME} !-f<br /> RewriteCond %{REQUEST_FILENAME} !-d<br /> RewriteRule . /index.php [L]<br /> <em># END WordPress</em></code></blockquote>\n\t\tRefresh this page when you have updated your .htaccess file.";
        echo "</fieldset></div>";
        return;
    } elseif (strpos($wprules, 'wordpressuser')) {
        // Need to clear out old mod_rewrite rules
        echo "<p><strong>Thank you for upgrading.</strong> 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: <blockquote><code>RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*\$</code></blockquote> so it looks like this: <blockquote><code>RewriteCond %{HTTP:Cookie} !^.*wordpress.*\$</code></blockquote> 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.</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: 2px; background: #ff0'><h4>Trailing slash check required.</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.<br />";
        echo "To fix, you must edit your .htaccess file and add these two rules to the two groups of Super Cache rules:</p>";
        echo "<blockquote><code>RewriteCond %{REQUEST_URI} !^.*[^/]\$<br />RewriteCond %{REQUEST_URI} !^.*//.*\$<br /></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.</p></div>";
        $dohtaccess = false;
    } elseif (strpos($scrules, 'supercache') || strpos($wprules, 'supercache')) {
        // only write the rules once
        $dohtaccess = false;
    }
    if ($dohtaccess && !$_POST['updatehtaccess']) {
        if (!is_writeable_ACLSafe($home_path . ".htaccess")) {
            echo "<div style='padding: 2px; background: #ff0'><h4>Cannot update .htaccess</h4><p>The file <code>{$home_path}.htaccess</code> cannot be modified by the web server. Please correct this using the chmod command or your ftp client.</p><p>Refresh this page when the file permissions have been modified.</p><p>Alternatively, you can edit your <code>{$home_path}.htaccess</code> file manually and add the following code (before any WordPress rules):</p>";
            echo "<p><pre># BEGIN WPSuperCache\n" . wp_specialchars($rules) . "# END WPSuperCache</pre></p></div>";
        } else {
            echo "<div style='padding: 2px; background: #ff0'><p>To serve static html files your server must have the correct mod_rewrite rules added to a file called <code>{$home_path}.htaccess</code><br /> This can be done automatically by clicking the <em>'Update mod_rewrite rules &raquo;'</em> button or you can edit the file yourself and add the following rules. Make sure they appear before any existing WordPress rules.";
            echo "<pre># BEGIN WPSuperCache\n" . wp_specialchars($rules) . "# END WPSuperCache</pre></p>";
            echo '<form name="updatehtaccess" action="' . $_SERVER["REQUEST_URI"] . '#modrewrite" method="post">';
            echo '<input type="hidden" name="updatehtaccess" value="1" />';
            echo '<div><input type="submit" ' . SUBMITDISABLED . 'id="updatehtaccess" value="Update mod_rewrite rules &raquo;" /></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: 2px; background: #ff0'>";
        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!</h4>";
            echo "<p><strong>{$home_path}.htaccess has been updated with the necessary mod_rewrite rules. Please verify they are correct. They should look like this:</strong></p>\n";
        } else {
            echo "<h4>Mod Rewrite rules must be updated!</h4>";
            echo "<p><strong> Your {$home_path}.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:</strong></p>\n";
        }
        echo "<p><pre>" . wp_specialchars($rules) . "</pre></p>\n</div>";
    } else {
        ?>
		<p>WP Super Cache mod rewrite rules were detected in your <?php 
        echo $home_path;
        ?>
.htaccess file. Click the following link to see the lines added to that file. If you have upgraded the plugin make sure these rules match. <a href="javascript:toggleLayer('rewriterules');" title="See your mod_rewrite rules">View mod_rewrite rules</a>
		<div id='rewriterules' style='display: none;'>
		<?php 
        echo "<p><pre># BEGIN WPSuperCache\n" . wp_specialchars($rules) . "# END WPSuperCache</pre></p>\n";
        ?>
		</div>
		<?php 
    }
    // http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/
    if (!is_file($cache_path . '.htaccess')) {
        $gziprules = "<IfModule mod_mime.c>\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 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";
        $gziprules = insert_with_markers($cache_path . '.htaccess', 'supercache', explode("\n", $gziprules));
        echo "<h4>Gzip encoding rules in {$cache_path}.htaccess created.</h4>";
    }
    ?>
</fieldset><?php 
}
示例#3
0
function wpsc_update_htaccess()
{
    extract(wpsc_get_htaccess_info());
    wpsc_remove_marker($home_path . '.htaccess', 'WordPress');
    // remove original WP rules so SuperCache rules go on top
    if (insert_with_markers($home_path . '.htaccess', 'WPSuperCache', explode("\n", $rules)) && insert_with_markers($home_path . '.htaccess', 'WordPress', explode("\n", $wprules))) {
        return true;
    } else {
        return false;
    }
}