/**
 * Add HTML5 Boilerplate's .htaccess via WordPress
 */
function uncode_add_h5bp_htaccess()
{
    $options = get_option(ot_options_id());
    $theme_opt = $options['_uncode_htaccess'];
    $saved_opt = get_option("_uncode_htaccess_performace");
    if ($theme_opt === 'on' && $saved_opt !== 'on' || $theme_opt === 'off' && $saved_opt === 'on') {
        global $wp_rewrite;
        $home_path = function_exists('get_home_path') ? get_home_path() : ABSPATH;
        $htaccess_file = $home_path . '.htaccess';
        $mod_rewrite_enabled = function_exists('got_mod_rewrite') ? got_mod_rewrite() : false;
        if (!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks() || is_writable($htaccess_file)) {
            if ($mod_rewrite_enabled) {
                $h5bp_rules = extract_from_markers($htaccess_file, 'HTML5 Boilerplate');
                if ($h5bp_rules === array()) {
                    $filename = dirname(__FILE__) . '/h5bp-htaccess';
                    update_option("_uncode_htaccess_performace", $theme_opt);
                    return insert_with_markers($htaccess_file, 'HTML5 Boilerplate', extract_from_markers($filename, 'HTML5 Boilerplate'));
                } else {
                    if ($theme_opt === 'off') {
                        update_option("_uncode_htaccess_performace", $theme_opt);
                        return insert_with_markers($htaccess_file, 'HTML5 Boilerplate', '');
                    }
                }
            }
        }
    }
}
 protected function write()
 {
     $server_config_rules = extract_from_markers(self::$wp_htaccess_file, self::MARKER);
     if (empty($server_config_rules)) {
         $server_config_rules = implode('', file(self::$roots_htaccess_file));
         $server_config_rules = str_replace(array_keys(self::$rules_filters), array_values(self::$rules_filters), $server_config_rules);
         $server_config_rules = apply_filters('roots/h5bp-htaccess-rules', $server_config_rules);
         insert_with_markers(self::$wp_htaccess_file, self::MARKER, explode(PHP_EOL, $server_config_rules));
     }
 }
 /**
  * Adds extra goodness whenever WP writes to .htaccess
  * 
  * @global object $wp_rewrite
  * @param string $content
  * @return boolean
  */
 function htaccess_add_rules($content)
 {
     global $wp_rewrite;
     $home_path = function_exists('get_home_path') ? get_home_path() : ABSPATH;
     $htaccess_file = $home_path . '.htaccess';
     $mod_rewrite_enabled = function_exists('got_mod_rewrite') ? got_mod_rewrite() : false;
     $firewall_rules = extract_from_markers($htaccess_file, 'Tabula Rasa');
     if ($firewall_rules === array()) {
         $filename = dirname(__FILE__) . '/TR-htaccess';
         return $this->prepend_with_markers($htaccess_file, 'Tabula Rasa', extract_from_markers($filename, 'Tabula Rasa'));
     }
     return $content;
 }
 function roots_add_h5bp_htaccess($content)
 {
     global $wp_rewrite;
     $home_path = get_home_path();
     $htaccess_file = $home_path . '.htaccess';
     if (!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks() || is_writable($htaccess_file)) {
         if (got_mod_rewrite()) {
             $h5bp_rules = extract_from_markers($htaccess_file, 'HTML5 Boilerplate');
             if ($h5bp_rules === array()) {
                 $filename = __DIR__ . '/h5bp-htaccess';
                 return insert_with_markers($htaccess_file, 'HTML5 Boilerplate', extract_from_markers($filename, 'HTML5 Boilerplate'));
             }
         }
     }
     return $content;
 }
/**
 * Add HTML5 Boilerplate's .htaccess via WordPress
 */
function roots_add_h5bp_htaccess($content)
{
    global $wp_rewrite;
    $home_path = function_exists('get_home_path') ? get_home_path() : ABSPATH;
    $htaccess_file = $home_path . '.htaccess';
    $mod_rewrite_enabled = function_exists('got_mod_rewrite') ? got_mod_rewrite() : false;
    if (!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks() || is_writable($htaccess_file)) {
        if ($mod_rewrite_enabled) {
            $h5bp_rules = extract_from_markers($htaccess_file, 'HTML5 Boilerplate');
            if ($h5bp_rules === array()) {
                $filename = dirname(__FILE__) . '/h5bp-htaccess';
                return insert_with_markers($htaccess_file, 'HTML5 Boilerplate', extract_from_markers($filename, 'HTML5 Boilerplate'));
            }
        }
    }
    return $content;
}
Exemple #6
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 
}
Exemple #7
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 
}
Exemple #8
0
function wpsc_get_htaccess_info()
{
    global $wp_cache_mobile_enabled, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers;
    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}';
    }
    $content_dir_root = $document_root;
    if (strpos($document_root, '/kunden/') === 0) {
        // http://wordpress.org/support/topic/plugin-wp-super-cache-how-to-get-mod_rewrite-working-on-1and1-shared-hosting?replies=1
        // On 1and1, PHP's directory structure starts with '/homepages'. The
        // Apache directory structure has an extra '/kunden' before it.
        // Also 1and1 does not support the %{DOCUMENT_ROOT} variable in
        // .htaccess files.
        // This prevents the $inst_root from being calculated correctly and
        // means that the $apache_root is wrong.
        //
        // e.g. This is an example of how Apache and PHP see the directory
        // structure on	1and1:
        // Apache: /kunden/homepages/xx/dxxxxxxxx/htdocs/site1/index.html
        // PHP:           /homepages/xx/dxxxxxxxx/htdocs/site1/index.html
        // Here we fix up the paths to make mode_rewrite work on 1and1 shared hosting.
        $content_dir_root = substr($content_dir_root, 7);
        $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']) : '/';
    $home_root_lc = str_replace('//', '/', strtolower($home_root));
    $inst_root = str_replace('//', '/', '/' . trailingslashit(str_replace($content_dir_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_logged_in|wp-postpass_).*\$";
    $condition_rules[] = "RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\\\"]+ [NC]";
    $condition_rules[] = "RewriteCond %{HTTP:Profile} !^[a-z0-9\\\"]+ [NC]";
    if ($wp_cache_mobile_enabled) {
        $condition_rules[] = "RewriteCond %{HTTP_USER_AGENT} !^.*(" . addcslashes(implode('|', $wp_cache_mobile_browsers), ' ') . ").* [NC]";
        $condition_rules[] = "RewriteCond %{HTTP_user_agent} !^(" . addcslashes(implode('|', $wp_cache_mobile_prefixes), ' ') . ").* [NC]";
    }
    $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
    $rules .= "#If you serve pages from behind a proxy you may want to change 'RewriteCond %{HTTPS} on' to something more sensible\n";
    $rules .= "CONDITION_RULES";
    $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
    $rules .= "RewriteCond %{HTTPS} on\n";
    $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root_lc}\$1/index-https.html.gz -f\n";
    $rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root_lc}\$1/index-https.html.gz\" [L]\n\n";
    $rules .= "CONDITION_RULES";
    $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
    $rules .= "RewriteCond %{HTTPS} !on\n";
    $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root_lc}\$1/index.html.gz -f\n";
    $rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root_lc}\$1/index.html.gz\" [L]\n\n";
    $rules .= "CONDITION_RULES";
    $rules .= "RewriteCond %{HTTPS} on\n";
    $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root_lc}\$1/index-https.html -f\n";
    $rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root_lc}\$1/index-https.html\" [L]\n\n";
    $rules .= "CONDITION_RULES";
    $rules .= "RewriteCond %{HTTPS} !on\n";
    $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root_lc}\$1/index.html -f\n";
    $rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root_lc}\$1/index.html\" [L]\n";
    $rules .= "</IfModule>\n";
    $rules = apply_filters('supercacherewriterules', $rules);
    $rules = str_replace("CONDITION_RULES", implode("\n", $condition_rules) . "\n", $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=3, must-revalidate'\n</IfModule>\n";
    $gziprules .= "<IfModule mod_expires.c>\n  ExpiresActive On\n  ExpiresByType text/html A3\n</IfModule>\n";
    return array("document_root" => $document_root, "apache_root" => $apache_root, "home_path" => $home_path, "home_root" => $home_root, "home_root_lc" => $home_root_lc, "inst_root" => $inst_root, "wprules" => $wprules, "scrules" => $scrules, "condition_rules" => $condition_rules, "rules" => $rules, "gziprules" => $gziprules);
}
 /**
  * Upgrade
  * Check options, perform any necessary data conversions
  */
 public static function upgrade()
 {
     // Get the current version
     $version = get_option('p3-profiler_version');
     // Upgrading from < 1.1.0
     if (empty($version) || version_compare($version, '1.1.0') < 0) {
         update_option('p3-profiler_disable_opcode_cache', true);
         update_option('p3-profiler_use_current_ip', true);
         update_option('p3-profiler_ip_address', '');
         update_option('p3-profiler_version', '1.1.0');
     }
     // Upgrading from < 1.1.2
     if (empty($version) || version_compare($version, '1.1.2') < 0) {
         update_option('p3-profiler_cache_buster', true);
         update_option('p3-profiler_version', '1.1.2');
     }
     // Upgrading from < 1.2.0
     if (empty($version) || version_compare($version, '1.2.0') < 0) {
         // Set profiling option
         update_option('p3-profiler_profiling_enabled', false);
         update_option('p3-profiler_version', '1.2.0');
         update_option('p3-profiler_debug', false);
         update_option('p3-profiler_debug_log', array());
         // Remove any .htaccess modifications
         $file = ABSPATH . '/.htaccess';
         if (file_exists($file) && array() !== extract_from_markers($file, 'p3-profiler')) {
             insert_with_markers($file, 'p3-profiler', array('# removed during 1.2.0 upgrade'));
         }
         // Remove .profiling_enabled if it's still present
         if (file_exists(P3_PATH . '/.profiling_enabled')) {
             @unlink(P3_PATH . '/.profiling_enabled');
         }
     }
     // Upgrading from < 1.3.0
     if (empty($version) || version_compare($version, '1.3.0') < 0) {
         update_option('p3-profiler_version', '1.3.0');
         // Move to a serialized single option
         $opts = array('profiling_enabled' => get_option('p3-profiler_profiling_enabled'), 'disable_opcode_cache' => get_option('p3-profiler_disable_opcode_cache'), 'use_current_ip' => get_option('p3-profiler_use_current_ip'), 'ip_address' => get_option('p3-profiler_ip_address'), 'cache_buster' => get_option('p3-profiler_cache_buster'), 'debug' => get_option('p3-profiler_debug'));
         update_option('p3-profiler_options', $opts);
         // Delete the extra options
         delete_option('p3-profiler_disable_opcode_cache');
         delete_option('p3-profiler_use_current_ip');
         delete_option('p3-profiler_ip_address');
         delete_option('p3-profiler_cache_buster');
         delete_option('p3-profiler_debug');
         delete_option('p3-profiler_profiling_enabled');
     }
     // Upgrading from < 1.5.0
     if (empty($version) || version_compare($version, '1.5.0') < 0) {
         update_option('p3-profiler_version', '1.5.0');
     }
     // Ensure the profiles folder is there
     $uploads_dir = wp_upload_dir();
     $folder = $uploads_dir['basedir'] . DIRECTORY_SEPARATOR . 'profiles';
     self::make_profiles_folder($folder);
 }
Exemple #10
0
function wpsc_get_htaccess_info()
{
    global $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers;
    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_logged_in|wp-postpass_).*\$";
    $condition_rules[] = "RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\\\"]+ [NC]";
    $condition_rules[] = "RewriteCond %{HTTP:Profile} !^[a-z0-9\\\"]+ [NC]";
    $condition_rules[] = "RewriteCond %{HTTP_USER_AGENT} !^.*(" . addcslashes(implode('|', $wp_cache_mobile_browsers), ' ') . ").*";
    $condition_rules[] = "RewriteCond %{HTTP_user_agent} !^(" . addcslashes(implode('|', $wp_cache_mobile_prefixes), ' ') . ").*";
    $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);
    $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";
    return array("document_root" => $document_root, "apache_root" => $apache_root, "home_path" => $home_path, "home_root" => $home_root, "inst_root" => $inst_root, "wprules" => $wprules, "scrules" => $scrules, "condition_rules" => $condition_rules, "rules" => $rules, "gziprules" => $gziprules);
}
 function get_restrictions()
 {
     $htaccess_file = $this->get_htaccess();
     return extract_from_markers($htaccess_file, 'e4d');
 }
 /**
  * Remove overzealous 'DOC' entry which is causing false-positive bad 
  * bot blocking.
  */
 function bad_bots_201603()
 {
     global $aiosp, $aioseop_options;
     // Remove 'DOC' from bad bots list to avoid false positives
     if (isset($aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_blocklist'])) {
         $list = $aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_blocklist'];
         $list = str_replace(array("DOC\r\n", "DOC\n"), '', $list);
         $aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_blocklist'] = $list;
         update_option('aioseop_options', $aioseop_options);
         $aiosp->update_class_option($aioseop_options);
         if (isset($aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_htaccess_rules']) && 'on' === $aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_htaccess_rules']) {
             if (!class_exists('All_in_One_SEO_Pack_Bad_Robots')) {
                 require_once AIOSEOP_PLUGIN_DIR . 'admin/aioseop_module_class.php';
                 require_once AIOSEOP_PLUGIN_DIR . 'modules/aioseop_bad_robots.php';
             }
             $aiosp_reset_htaccess = new All_in_One_SEO_Pack_Bad_Robots();
             $aiosp_reset_htaccess->generate_htaccess_blocklist();
         }
         if (!isset($aioseop_options['modules']['aiosp_bad_robots_options']['aiosp_bad_robots_htaccess_rules']) && extract_from_markers(get_home_path() . '.htaccess', 'Bad Bot Blocker')) {
             insert_with_markers(get_home_path() . '.htaccess', 'Bad Bot Blocker', '');
         }
     }
 }
Exemple #13
0
 public static function regenerate_htaccess_file()
 {
     if (!function_exists('save_mod_rewrite_rules')) {
         if (!function_exists('mysql2date')) {
             require ABSPATH . '/wp-includes/functions.php';
         }
         if (!function_exists('get_home_path')) {
             require ABSPATH . '/wp-admin/includes/file.php';
         }
         require ABSPATH . '/wp-admin/includes/misc.php';
     }
     global $is_nginx, $wp_rewrite;
     $home_path = get_home_path();
     $htaccess_file = $home_path . '.htaccess';
     if (file_exists($htaccess_file)) {
         unlink($htaccess_file);
     }
     $home_path = get_home_path();
     $iis7_permalinks = iis7_supports_permalinks();
     $prefix = $blog_prefix = '';
     if (!got_url_rewrite()) {
         $prefix = '/index.php';
     }
     if (is_multisite() && !is_subdomain_install() && is_main_site()) {
         $blog_prefix = '/blog';
     }
     $permalink_structure = get_option('permalink_structure');
     $category_base = get_option('category_base');
     $tag_base = get_option('tag_base');
     $update_required = false;
     if ($iis7_permalinks) {
         if (!file_exists($home_path . 'web.config') && win_is_writable($home_path) || win_is_writable($home_path . 'web.config')) {
             $writable = true;
         } else {
             $writable = false;
         }
     } elseif ($is_nginx) {
         $writable = false;
     } else {
         if (!file_exists($home_path . '.htaccess') && is_writable($home_path) || is_writable($home_path . '.htaccess')) {
             $writable = true;
         } else {
             $writable = false;
             $existing_rules = array_filter(extract_from_markers($home_path . '.htaccess', 'WordPress'));
             $new_rules = array_filter(explode("\n", $wp_rewrite->mod_rewrite_rules()));
             $update_required = $new_rules !== $existing_rules;
         }
     }
     if ($wp_rewrite->using_index_permalinks()) {
         $usingpi = true;
     } else {
         $usingpi = false;
     }
     flush_rewrite_rules();
     save_mod_rewrite_rules();
 }
Exemple #14
0
 /**
  * Creates or opens the robots.txt in blog root and inserts the sitemap location
  * 
  * @since 3.0b8
  * @access private
  * @author Arne Brachhold
  * @return true on success
  */
 function WriteRobotsFile()
 {
     $file = $this->GetRobotsFilePath();
     $marker = 'XML-SITEMAP-PLUGIN';
     $current = extract_from_markers($file, $marker);
     if (is_array($current)) {
         $current = $current[0];
     }
     $smUrl = $this->GetXmlUrl();
     if ($this->IsGzipEnabled()) {
         $smUrl = $this->GetZipUrl();
     }
     $new = "Sitemap: " . $smUrl;
     if ($current != $new) {
         if ($this->IsFileWritable($file)) {
             return insert_with_markers($file, $marker, array($new));
         } else {
             return false;
         }
     }
     return true;
 }
$tag_base = get_option('tag_base');
$update_required = false;
if ($iis7_permalinks) {
    if (!file_exists($home_path . 'web.config') && win_is_writable($home_path) || win_is_writable($home_path . 'web.config')) {
        $writable = true;
    } else {
        $writable = false;
    }
} elseif ($is_nginx) {
    $writable = false;
} else {
    if (!file_exists($home_path . '.htaccess') && is_writable($home_path) || is_writable($home_path . '.htaccess')) {
        $writable = true;
    } else {
        $writable = false;
        $existing_rules = array_filter(extract_from_markers($home_path . '.htaccess', 'WordPress'));
        $new_rules = array_filter(explode("\n", $wp_rewrite->mod_rewrite_rules()));
        $update_required = $new_rules !== $existing_rules;
    }
}
if ($wp_rewrite->using_index_permalinks()) {
    $usingpi = true;
} else {
    $usingpi = false;
}
flush_rewrite_rules();
require ABSPATH . 'wp-admin/admin-header.php';
if (!empty($_GET['settings-updated'])) {
    ?>
<div id="message" class="updated notice is-dismissible"><p><?php 
    if (!is_multisite()) {
Exemple #16
0
function ewww_image_optimizer_webp_rewrite_verify()
{
    $current_rules = extract_from_markers(get_home_path() . '.htaccess', 'EWWWIO');
    $ewww_rules = array("<IfModule mod_rewrite.c>", "RewriteEngine On", "RewriteCond %{HTTP_ACCEPT} image/webp", "RewriteCond %{REQUEST_FILENAME} (.*)\\.(jpe?g|png)\$", "RewriteCond %{REQUEST_FILENAME}.webp -f", "RewriteRule (.+)\\.(jpe?g|png)\$ %{REQUEST_FILENAME}.webp [T=image/webp,E=accept:1]", "</IfModule>", "<IfModule mod_headers.c>", "Header append Vary Accept env=REDIRECT_accept", "</IfModule>", "AddType image/webp .webp");
    if (array_diff($ewww_rules, $current_rules)) {
        ewwwio_memory(__FUNCTION__);
        return $ewww_rules;
    } else {
        ewwwio_memory(__FUNCTION__);
        return;
    }
}
    public function show_browser_caching_field()
    {
        global $is_iis7, $is_apache;
        if ($is_iis7) {
            if (file_exists($this->_web_config_path) && is_readable($this->_web_config_path)) {
                $caching = false !== strpos(file_get_contents($this->_web_config_path), '<urlCompression');
            } else {
                $caching = false;
            }
        } elseif ($is_apache) {
            $caching = array() != extract_from_markers($this->_htaccess_path, 'wtwp_cache');
        } else {
            $caching = false;
        }
        ?>

			<fieldset>

				<legend class="screen-reader-text browser-title">

					<?php 
        _e('Browser caching rules', 'welcome-to-wordpress');
        ?>

				</legend>

			</fieldset>

			<label for="wtwp_use_caching_rules" class="browser-label">

				<input type="checkbox" id="wtwp_use_caching_rules" name="wtwp_use_caching_rules" <?php 
        disabled(!$is_iis7 && !$is_apache);
        ?>
 <?php 
        checked($caching);
        ?>
 />

				<?php 
        if ($is_iis7) {
            ?>

					<?php 
            _e('Enable browser caching web.config rules', 'welcome-to-wordpress');
            ?>

				<?php 
        } elseif ($is_apache) {
            ?>

					<?php 
            _e('Enable browser caching .htaccess rules', 'welcome-to-wordpress');
            ?>

				<?php 
        } else {
            ?>

					<?php 
            _e('Browser caching rules are not available on this platform', 'welcome-to-wordpress');
            ?>

				<?php 
        }
        ?>

			</label>

			<p class="description browser-description"><?php 
        _e('Caching WordPress rules are only available on IIS7 and apache', 'welcome-to-wordpress');
        ?>
</p>

		<?php 
    }