Ejemplo n.º 1
0
function wsc_mod_rewrite()
{
    global $cache_enabled, $super_cache_enabled, $valid_nonce, $cache_path, $wp_cache_mod_rewrite, $wpmu_version;
    if (!$wp_cache_mod_rewrite) {
        return false;
    }
    if (isset($wpmu_version) || function_exists('is_multisite') && is_multisite()) {
        if (false == wpsupercache_site_admin()) {
            return false;
        }
        if (function_exists("is_main_site") && false == is_main_site() || function_exists('is_main_blog') && false == is_main_blog()) {
            global $current_site;
            $protocol = 'on' == strtolower($_SERVER['HTTPS']) ? 'https://' : 'http://';
            if (isset($wpmu_version)) {
                $link_to_admin = admin_url("wpmu-admin.php?page=wpsupercache");
            } else {
                $link_to_admin = admin_url("ms-admin.php?page=wpsupercache");
            }
            echo '<div id="message" class="updated fade"><p>' . sprintf(__('Notice: WP Super Cache mod_rewrite rule checks disabled unless running on <a href="%s">the main site</a> of this network.', 'wp-super-cache'), $link_to_admin) . '</p></div>';
            return false;
        }
    }
    if (function_exists("is_main_site") && false == is_main_site() || function_exists('is_main_blog') && false == is_main_blog()) {
        return true;
    }
    ?>
	<a name="modrewrite"></a><fieldset class="options"> 
	<h3><?php 
    _e('Mod Rewrite Rules', 'wp-super-cache');
    ?>
</h3><?php 
    extract(wpsc_get_htaccess_info());
    $dohtaccess = true;
    global $wpmu_version;
    if (isset($wpmu_version)) {
        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>";
        $dohtaccess = false;
    } 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;
    }
    if ($dohtaccess && !$_POST['updatehtaccess']) {
        if ($scrules == '') {
            wpsc_update_htaccess_form(0);
            // don't hide the update htaccess form
        } else {
            wpsc_update_htaccess_form();
        }
    } elseif ($valid_nonce && $_POST['updatehtaccess']) {
        echo "<div style='padding:0 8px;color:#4f8a10;background-color:#dff2bf;border:1px solid #4f8a10;'>";
        if (wpsc_update_htaccess()) {
            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>" . esc_html($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);
        ?>
</p>
		<?php 
        if ($rules != $scrules) {
            ?>
<p style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><?php 
            _e('A difference between the rules in your .htaccess file and the plugin rewrite rules has been found. This could be simple whitespace differences but you should compare the rules in the file with those below as soon as possible. Click the &#8217;Update Mod_Rewrite Rules&#8217; button to update the rules.', 'wp-super-cache');
            ?>
</p><?php 
        }
        ?>
<a href="javascript:toggleLayer('rewriterules');" class="button"><?php 
        _e('View Mod_Rewrite Rules', 'wp-super-cache');
        ?>
</a><?php 
        wpsc_update_htaccess_form();
        echo "<div id='rewriterules' style='display: none;'>";
        if ($rules != $scrules) {
            echo '<div style="background: #fff; border: 1px solid #333; margin: 2px;">' . wp_text_diff($scrules, $rules, array('title' => 'Rewrite Rules', 'title_left' => 'Current Rules', 'title_right' => 'New Rules')) . "</div>";
        }
        echo "<p><pre># BEGIN WPSuperCache\n" . esc_html($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" . esc_html($gziprules) . "# END supercache</pre></p>";
        echo '</div>';
    }
    // 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 
}
Ejemplo n.º 2
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 
    extract(wpsc_get_htaccess_info());
    $dohtaccess = true;
    global $wpmu_version;
    if (isset($wpmu_version)) {
        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;
    }
    if ($dohtaccess && !$_POST['updatehtaccess']) {
        if ($scrules == '') {
            wpsc_update_htaccess_form(0);
            // don't hide the update htaccess form
        } else {
            wpsc_update_htaccess_form();
        }
    } elseif ($valid_nonce && $_POST['updatehtaccess']) {
        echo "<div style='padding:0 8px;color:#4f8a10;background-color:#dff2bf;border:1px solid #4f8a10;'>";
        if (wpsc_update_htaccess()) {
            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);
        ?>
</p>
		<?php 
        if ($rules != $scrules) {
            ?>
<p style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><?php 
            _e('A difference between the rules in your .htaccess file and the plugin rewrite rules has been found. This could be simple whitespace differences but you should compare the rules in the file with those below as soon as possible. Click the &#8217;Update Mod_Rewrite Rules&#8217; button to update the rules.', 'wp-super-cache');
            ?>
</p><?php 
        }
        ?>
		<a href="javascript:toggleLayer('rewriterules');" class="button"><?php 
        _e('View Mod_Rewrite Rules', 'wp-super-cache');
        ?>
</a>
		<?php 
        wpsc_update_htaccess_form();
        ?>
		<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 
}