/** * 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', ''); } } } } } }
/** * job_board_rewrite function. * * @access public * @return void */ public function job_board_rewrite() { if (!function_exists('get_home_path')) { require_once ABSPATH . 'wp-admin/includes/file.php'; } $root_path = get_home_path(); $file_existing_permission = ''; /* Getting Rules */ $rules = 'yes' === get_option('job_board_anti_hotlinking') ? $this->job_board_rewrite_rules() : ''; /* Rules Force Files to be Downloaded */ $forcedownload_rule = "AddType application/octet-stream .pdf .txt\n"; /* Changing File to Writable Mode */ if (file_exists($root_path . '.htaccess') && !is_writable($root_path . '.htaccess')) { $file_existing_permission = substr(decoct(fileperms($root_path . '.htaccess')), -4); chmod($root_path . '.htaccess', 0777); } /* Appending .htaccess */ if (file_exists($root_path . '.htaccess') && is_writable($root_path . '.htaccess')) { $rules = explode("\n", $rules); $forcedownload_rule = explode("\n", $forcedownload_rule); // Anti-Hotlinking Rules Writing in .htaccess file if (!function_exists('insert_with_markers')) { require_once ABSPATH . 'wp-admin/includes/misc.php'; } insert_with_markers($root_path . '.htaccess', 'Hotlinking', $rules); // Force Download Rules Writing in .htaccess file insert_with_markers($root_path . '.htaccess', 'Force Download', $forcedownload_rule); /* Revert File Permission */ if (!empty($file_existing_permission)) { chmod($root_path . '.htaccess', $file_existing_permission); } } }
function custom_admin_url() { if (isset($_POST['custom_wpadmin_slug'])) { // sanitize input $wpadmin_slug = trim(sanitize_key(wp_strip_all_tags($_POST['custom_wpadmin_slug']))); $home_path = get_home_path(); // check if permalinks are turned off, if so force push rules to .htaccess if (isset($_POST['selection']) && $_POST['selection'] == '' && $wpadmin_slug != '') { // check if .htaccess is writable if (!file_exists($home_path . '.htaccess') && is_writable($home_path) || is_writable($home_path . '.htaccess')) { // taken from wp-includes/rewrite.php $home_root = parse_url(home_url()); if (isset($home_root['path'])) { $home_root = trailingslashit($home_root['path']); } else { $home_root = '/'; } // create rules $rules = "<IfModule mod_rewrite.c>\n"; $rules .= "RewriteEngine On\n"; $rules .= "RewriteRule ^{$wpadmin_slug}/?\$ " . $home_root . "wp-login.php [QSA,L]\n"; $rules .= "</IfModule>"; // write to .htaccess insert_with_markers($home_path . '.htaccess', 'WPAdminURL', explode("\n", $rules)); } } else { if (isset($_POST['selection']) || isset($_POST['selection']) && $_POST['selection'] == '' && $wpadmin_slug == '') { // remove rules if permalinks were enabled $markerdata = explode("\n", implode('', file($home_path . '.htaccess'))); $found = false; $newdata = ''; foreach ($markerdata as $line) { if ($line == '# BEGIN WPAdminURL') { $found = true; } if (!$found) { $newdata .= "{$line}\n"; } if ($line == '# END WPAdminURL') { $found = false; } } // write back $f = @fopen($home_path . '.htaccess', 'w'); fwrite($f, $newdata); } } // save to db update_option('custom_wpadmin_slug', $wpadmin_slug); // write rewrite rules right away if ($wpadmin_slug != '') { add_rewrite_rule($wpadmin_slug . '/?$', 'wp-login.php', 'top'); } else { flush_rewrite_rules(); } } add_settings_field('custom_wpadmin_slug', 'WP-Admin slug', array($this, 'options_page'), 'permalink', 'optional', array('label_for' => 'custom_wpadmin_slug')); register_setting('permalink', 'custom_wpadmin_slug', 'strval'); }
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)); } }
function insert_with_markers($file_path, $marker_text, $insertion) { if (!function_exists('insert_with_markers')) { if (file_exists(ABSPATH . '/wp-admin/includes/misc.php')) { include_once ABSPATH . '/wp-admin/includes/misc.php'; } else { return; } } if ($insertion || file_exists($file_path)) { insert_with_markers($file_path, $marker_text, explode("\n", $insertion)); } }
function handle_rhc_uninstall() { $WP_Roles = new WP_Roles(); foreach (array('calendarize_author', 'edit_' . RHC_CAPABILITY_TYPE, 'read_' . RHC_CAPABILITY_TYPE, 'delete_' . RHC_CAPABILITY_TYPE, 'delete_' . RHC_CAPABILITY_TYPE . 's', 'edit_' . RHC_CAPABILITY_TYPE . 's', 'edit_others_' . RHC_CAPABILITY_TYPE . 's', 'edit_published_' . RHC_CAPABILITY_TYPE . 's', 'delete_published_' . RHC_CAPABILITY_TYPE . 's', 'delete_private_' . RHC_CAPABILITY_TYPE . 's', 'delete_others_' . RHC_CAPABILITY_TYPE . 's', 'publish_' . RHC_CAPABILITY_TYPE . 's', 'read_private_' . RHC_CAPABILITY_TYPE . 's', 'manage_' . RHC_VENUE, 'manage_' . RHC_CALENDAR, 'manage_' . RHC_ORGANIZER) as $cap) { $WP_Roles->remove_cap(RHC_ADMIN_ROLE, $cap); } //----- delete_site_transient('update_plugins'); delete_option('rhc_dismiss_help_notice'); $filename = get_home_path() . '.htaccess'; if (file_exists($filename)) { insert_with_markers($filename, 'RHC', array()); } }
function groundup_compression($rewrites) { global $wp_rewrite; $mod_rewrite_enabled = function_exists('got_mod_rewrite') ? got_mod_rewrite() : false; $home_path = function_exists('get_home_path') ? get_home_path() : ABSPATH; $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 ($mod_rewrite_enabled) { $gzip = "<IfModule mod_headers.c>\n\t# Make sure proxies don't deliver the wrong content\n\tHeader append Vary User-Agent env=!dont-vary\n\t</IfModule>\n\t<IfModule mod_deflate.c>\n\t# Insert filters\n\tAddOutputFilterByType DEFLATE text/plain\n\tAddOutputFilterByType DEFLATE text/html\n\tAddOutputFilterByType DEFLATE text/xml\n\tAddOutputFilterByType DEFLATE text/css\n\tAddOutputFilterByType DEFLATE text/javascript\n\tAddOutputFilterByType DEFLATE application/xml\n\tAddOutputFilterByType DEFLATE application/xhtmlxml\n\tAddOutputFilterByType DEFLATE application/rssxml\n\tAddOutputFilterByType DEFLATE application/javascript\n\tAddOutputFilterByType DEFLATE application/x-javascript\n\tAddOutputFilterByType DEFLATE application/json\n\tAddOutputFilterByType DEFLATE application/x-json\n\tAddOutputFilterByType DEFLATE application/x-httpd-php\n\tAddOutputFilterByType DEFLATE application/x-httpd-fastphp\n\tAddOutputFilterByType DEFLATE image/svgxml\n\t# Drop problematic browsers\n\tBrowserMatch ^Mozilla/4 gzip-only-text/html\n\tBrowserMatch ^Mozilla/4\\.0[678] no-gzip\n\t# IE5.x and IE6 get no gzip, but 7 should\n\tBrowserMatch \\bMSIE\\s[789] !no-gzip !gzip-only-text/html\n\t# IE 6.0 after SP2 has no gzip bugs\n\tBrowserMatch \\bMSIE.SV !no-gzip\n\t# Opera occasionally pretends to be IE with Mozilla/4.0\n\tBrowserMatch \\bOpera !no-gzip\n\t</IfModule>"; $gzip = explode("\n", $gzip); return insert_with_markers($htaccess_file, 'gzip', $gzip); } } return $rewrites; }
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; }
function insert_with_markers($file_path, $marker_text, $insertion) { if (!function_exists('insert_with_markers')) { if (file_exists(ABSPATH . '/wp-admin/includes/misc.php')) { include_once ABSPATH . '/wp-admin/includes/misc.php'; } else { return; } } if ($insertion || file_exists($file_path)) { if (!$insertion) { // if no insertion and no existing entry, don't mess $htcontent = file_get_contents($file_path); if (false === strpos($htcontent, $marker_text)) { return; } } insert_with_markers($file_path, $marker_text, explode("\n", $insertion)); } }
/** * Remove security rules from .htaccess * @return void */ protected function _remove_htaccess_security() { if (!insert_with_markers($this->_htaccess_path, 'wtwp_security', array())) { return new WP_Error('generic', sprintf(__('Failed to update %s', 'welcome-to-wordpress'), $this->_htaccess_path)); } return true; }
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') . ' »" /></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’s backwards compatible with older versions if you’re brave enough to use them.', 'wp-super-cache'), '<blockquote><code>RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$</code></blockquote>', '<blockquote><code>RewriteCond %{HTTP:Cookie} !^.*wordpress.*$</code></blockquote>') . "</p>"; echo "</fieldset></div>"; return; } elseif ($scrules != '' && strpos($scrules, '%{REQUEST_URI} !^.*[^/]$') === false && substr(get_option('permalink_structure'), -1) == '/') { // permalink structure has a trailing slash, need slash check in rules. echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><h4>" . __('Trailing slash check required.', 'wp-super-cache') . "</h4><p>" . __('It looks like your blog has URLs that end with a "/". Unfortunately since you installed this plugin a duplicate content bug has been found where URLs not ending in a "/" end serve the same content as those with the "/" and do not redirect to the proper URL. To fix, you must edit your .htaccess file and add these two rules to the two groups of Super Cache rules:', 'wp-super-cache') . "</p>"; echo "<blockquote><code>RewriteCond %{REQUEST_URI} !^.*[^/]{$RewriteCond} %{REQUEST_URI} !^.*//.*\$</code></blockquote>"; echo "<p>" . __('You can see where the rules go and examine the complete rules by clicking the "View mod_rewrite rules" link below.', 'wp-super-cache') . "</p></div>"; $dohtaccess = false; } elseif (strpos($scrules, 'supercache') || strpos($wprules, 'supercache')) { // only write the rules once $dohtaccess = false; } // cache/.htaccess rules $gziprules = "<IfModule mod_mime.c>\n <FilesMatch \"\\.html\\.gz\$\">\n ForceType text/html\n FileETag None\n </FilesMatch>\n AddEncoding gzip .gz\n AddType text/html .gz\n</IfModule>\n"; $gziprules .= "<IfModule mod_deflate.c>\n SetEnvIfNoCase Request_URI \\.gz\$ no-gzip\n</IfModule>\n"; $gziprules .= "<IfModule mod_headers.c>\n Header set Vary \"Accept-Encoding, Cookie\"\n Header set Cache-Control 'max-age=300, must-revalidate'\n</IfModule>\n"; $gziprules .= "<IfModule mod_expires.c>\n ExpiresActive On\n ExpiresByType text/html A300\n</IfModule>\n"; if ($dohtaccess && !$_POST['updatehtaccess']) { if (!is_writeable_ACLSafe($home_path . ".htaccess")) { echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><h4>" . __('Cannot update .htaccess', 'wp-super-cache') . "</h4><p>" . sprintf(__('The file <code>%s.htaccess</code> cannot be modified by the web server. Please correct this using the chmod command or your ftp client.', 'wp-super-cache'), $home_path) . "</p><p>" . __('Refresh this page when the file permissions have been modified.') . "</p><p>" . sprintf(__('Alternatively, you can edit your <code>%s.htaccess</code> file manually and add the following code (before any WordPress rules):', 'wp-super-cache'), $home_path) . "</p>"; echo "<p><pre># BEGIN WPSuperCache\n" . wp_specialchars($rules) . "# END WPSuperCache</pre></p></div>"; } else { echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><p>" . sprintf(__('To serve static html files your server must have the correct mod_rewrite rules added to a file called <code>%s.htaccess</code>', 'wp-super-cache'), $home_path) . " "; if (!function_exists('is_site_admin')) { _e("You must edit the file yourself add the following rules.", 'wp-super-cache'); } else { _e("You can edit the file yourself add the following rules.", 'wp-super-cache'); } echo __(" Make sure they appear before any existing WordPress rules. ", 'wp-super-cache') . "</p>"; echo "<pre># BEGIN WPSuperCache\n" . wp_specialchars($rules) . "# END WPSuperCache</pre></p>"; echo "<p>" . sprintf(__('Rules must be added to %s too:', 'wp-super-cache'), WP_CONTENT_DIR . "/cache/.htaccess") . "</p>"; echo "<pre># BEGIN supercache\n" . wp_specialchars($gziprules) . "# END supercache</pre></p>"; if (!function_exists('is_site_admin')) { echo '<form name="updatehtaccess" action="#modrewrite" method="post">'; echo '<input type="hidden" name="updatehtaccess" value="1" />'; echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'id="updatehtaccess" value="' . __('Update Mod_Rewrite Rules', 'wp-super-cache') . ' »" /></div>'; wp_nonce_field('wp-cache'); echo "</form></div>\n"; } } } elseif ($dohtaccess && $valid_nonce && $_POST['updatehtaccess']) { wpsc_remove_marker($home_path . '.htaccess', 'WordPress'); // remove original WP rules so SuperCache rules go on top echo "<div style='padding:0 8px;color:#4f8a10;background-color:#dff2bf;border:1px solid #4f8a10;'>"; if (insert_with_markers($home_path . '.htaccess', 'WPSuperCache', explode("\n", $rules)) && insert_with_markers($home_path . '.htaccess', 'WordPress', explode("\n", $wprules))) { echo "<h4>" . __('Mod Rewrite rules updated!', 'wp-super-cache') . "</h4>"; echo "<p><strong>" . sprintf(__('%s.htaccess has been updated with the necessary mod_rewrite rules. Please verify they are correct. They should look like this:', 'wp-super-cache'), $home_path) . "</strong></p>\n"; } else { echo "<h4>" . __('Mod Rewrite rules must be updated!', 'wp-super-cache') . "</h4>"; echo "<p><strong>" . sprintf(__('Your %s.htaccess is not writable by the webserver and must be updated with the necessary mod_rewrite rules. The new rules go above the regular WordPress rules as shown in the code below:', 'wp-super-cache'), $home_path) . "</strong></p>\n"; } echo "<p><pre>" . wp_specialchars($rules) . "</pre></p>\n</div>"; } else { ?> <p><?php printf(__('WP Super Cache mod rewrite rules were detected in your %s.htaccess file.<br /> Click the following link to see the lines added to that file. If you have upgraded the plugin make sure these rules match.', 'wp-super-cache'), $home_path); ?> <br /><br /> <a href="javascript:toggleLayer('rewriterules');" class="button"><?php _e('View Mod_Rewrite Rules', 'wp-super-cache'); ?> </a> <div id='rewriterules' style='display: none;'> <?php echo "<p><pre># BEGIN WPSuperCache\n" . wp_specialchars($rules) . "# END WPSuperCache</pre></p>\n"; echo "<p>" . sprintf(__('Rules must be added to %s too:', 'wp-super-cache'), WP_CONTENT_DIR . "/cache/.htaccess") . "</p>"; echo "<pre># BEGIN supercache\n" . wp_specialchars($gziprules) . "# END supercache</pre></p>"; ?> </div> <?php } // http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/ if (!is_file($cache_path . '.htaccess')) { $gziprules = insert_with_markers($cache_path . '.htaccess', 'supercache', explode("\n", $gziprules)); echo "<h4>" . sprintf(__('Gzip encoding rules in %s.htaccess created.', 'wp-super-cache'), $cache_path) . "</h4>"; } ?> </fieldset><?php }
function save_file_cache() { if (iis7_supports_permalinks()) { return; } global $rhc_plugin; if ('1' == $rhc_plugin->get_option('file_cache', '', true)) { $content = $this->get_htaccess(); $rules_arr = explode("\n", $content); } else { $rules_arr = array(); } $filename = get_home_path() . '.htaccess'; if (file_exists($filename) && is_writeable($filename)) { $str = file_get_contents($filename); if (false === strpos($str, 'BEGIN RHC')) { $prepend = "# BEGIN RHC\n"; $prepend .= "# END RHC\n"; $str = $prepend . $str; file_put_contents($filename, $str); } } insert_with_markers($filename, 'RHC', $rules_arr); }
function update_htaccess($hard = false) { if (defined('DOING_CRON') && DOING_CRON) { return; } if ('hidden' === get_option('mainwp_child_pluginDir') && ($hard || 'yes' !== get_option('mainwp_child_htaccess_set'))) { include_once ABSPATH . '/wp-admin/includes/misc.php'; $snPluginDir = basename($this->plugin_dir); $rules = null; if ('1' !== get_option('heatMapsIndividualOverrideSetting') && '0' !== get_option('heatMapEnabled') || '1' === get_option('heatMapsIndividualOverrideSetting') && '1' !== get_option('heatMapsIndividualDisable') || get_option('mainwp_kwl_enable_statistic')) { //Heatmap enabled //Make the plugin invisible, except heatmap $rules = $this->mod_rewrite_rules(array('wp-content/plugins/' . $snPluginDir . '/([^js\\/]*)$' => 'wp-content/plugins/THIS_PLUGIN_DOES_NOT_EXIST')); } else { //Make the plugin invisible $rules = $this->mod_rewrite_rules(array('wp-content/plugins/' . $snPluginDir . '/(.*)$' => 'wp-content/plugins/THIS_PLUGIN_DOES_NOT_EXIST')); } $home_path = ABSPATH; $htaccess_file = $home_path . '.htaccess'; if (function_exists('save_mod_rewrite_rules')) { $rules = explode("\n", $rules); // $ch = @fopen($htaccess_file,'w'); // if (@flock($ch, LOCK_EX)) // { insert_with_markers($htaccess_file, 'MainWP', $rules); // } // @flock($ch, LOCK_UN); // @fclose($ch); if (get_option('mainwp_child_onetime_htaccess') === false) { MainWP_Helper::update_option('mainwp_child_onetime_htaccess', true); } } MainWP_Helper::update_option('mainwp_child_htaccess_set', 'yes', 'yes'); } else { if ($hard) { include_once ABSPATH . '/wp-admin/includes/misc.php'; $home_path = ABSPATH; $htaccess_file = $home_path . '.htaccess'; if (function_exists('save_mod_rewrite_rules')) { $rules = explode("\n", ''); // $ch = @fopen($htaccess_file,'w'); // if (@flock($ch, LOCK_EX)) // { insert_with_markers($htaccess_file, 'MainWP', $rules); // } // @flock($ch, LOCK_UN); // @fclose($ch); if (get_option('mainwp_child_onetime_htaccess') === false) { MainWP_Helper::update_option('mainwp_child_onetime_htaccess', true); } } } } }
function wp_cache_disable_plugin() { global $wp_cache_config_file, $wp_rewrite; if (file_exists(ABSPATH . 'wp-config.php')) { $global_config_file = ABSPATH . 'wp-config.php'; } else { $global_config_file = dirname(ABSPATH) . '/wp-config.php'; } $line = 'define(\'WP_CACHE\', true);'; if (strpos(file_get_contents($global_config_file), $line) && (!is_writeable_ACLSafe($global_config_file) || !wp_cache_replace_line('define *\\( *\'WP_CACHE\'', '//' . $line, $global_config_file))) { wp_die("Could not remove WP_CACHE define from {$global_config_file}. Please edit that file and remove the line containing the text 'WP_CACHE'. Then refresh this page."); } uninstall_supercache(WP_CONTENT_DIR . '/cache'); $file_not_deleted = false; if (@file_exists(WP_CONTENT_DIR . "/advanced-cache.php")) { if (false == @unlink(WP_CONTENT_DIR . "/advanced-cache.php")) { $file_not_deleted[] = 'advanced-cache.php'; } } if (@file_exists(WP_CONTENT_DIR . "/wp-cache-config.php")) { if (false == unlink(WP_CONTENT_DIR . "/wp-cache-config.php")) { $file_not_deleted[] = 'wp-cache-config.php'; } } if ($file_not_deleted) { $msg = "<p>One or more files could not be deleted. These files and directories must be made writeable:</p>\n <ol><li>" . WP_CONTENT_DIR . "</li>\n"; $code = "<ul>\n"; foreach ((array) $file_not_deleted as $filename) { $msg .= "<li>" . WP_CONTENT_DIR . "/{$filename}</li>"; $code .= "<li><code>chmod 666 " . WP_CONTENT_DIR . "/{$filename}</code></li>\n"; } $code .= "</ul>\n"; $msg .= "</ol>\n<p>First try fixing the directory permissions with this command and refresh this page:<br /><br /><code>chmod 777 " . WP_CONTENT_DIR . "</code><br /><br />If you still see this error, you have to fix the permissions on the files themselves and refresh this page again:</p> {$code}\n<p>Don't forgot to fix things later:<br /><code>chmod 755 " . WP_CONTENT_DIR . "</code></p><p>If you don't know what <strong>chmod</strong> is use <a href='http://www.google.ie/search?hl=en&q=ftp+chmod+777'>this Google search</a> to find out all about it.</p><p>Please refresh this page when the permissions have been modified.</p>"; wp_die($msg); } extract(wpsc_get_htaccess_info()); if ($scrules != '' && insert_with_markers($home_path . '.htaccess', 'WPSuperCache', array())) { $wp_rewrite->flush_rules(); } elseif ($scrules != '') { wp_mail(get_option('admin_email'), __('Supercache Uninstall Problems', 'wp-super-cache'), sprintf(__("Dear User,\n\nWP Super Cache was removed from your blog but the mod_rewrite rules\nin your .htaccess were not.\n\nPlease edit the following file and remove the code\nbetween 'BEGIN WPSuperCache' and 'END WPSuperCache'. Please backup the file first!\n\n%s\n\nRegards,\nWP Super Cache Plugin\nhttp://wordpress.org/extend/plugins/wp-super-cache/", 'wp-super-cache'), ABSPATH . '/.htaccess')); } }
/** * Get the path to the backups directory * * Will try to create it if it doesn't exist * and will fallback to default if a custom dir * isn't writable. */ function hmbkp_path() { global $is_apache; $path = untrailingslashit(get_option('hmbkp_path')); // Allow the backups path to be defined if (defined('HMBKP_PATH') && HMBKP_PATH) { $path = untrailingslashit(HMBKP_PATH); } // If the dir doesn't exist or isn't writable then use the default path instead instead if ((!$path || is_dir($path) && !is_writable($path) || !is_dir($path) && !is_writable(dirname($path))) && $path !== hmbkp_path_default()) { $path = hmbkp_path_default(); } // Create the backups directory if it doesn't exist if (!is_dir($path) && is_writable(dirname($path))) { wp_mkdir_p($path); } // If the path has changed then cache it if (get_option('hmbkp_path') !== $path) { update_option('hmbkp_path', $path); } // Protect against directory browsing by including a index.html file $index = $path . '/index.html'; if (!file_exists($index) && is_writable($path)) { file_put_contents($index, ''); } $htaccess = $path . '/.htaccess'; // Protect the directory with a .htaccess file on Apache servers if ($is_apache && function_exists('insert_with_markers') && !file_exists($htaccess) && is_writable($path)) { $contents[] = '# ' . sprintf(__('This %s file ensures that other people cannot download your backup files.', 'hmbkp'), '.htaccess'); $contents[] = ''; $contents[] = '<IfModule mod_rewrite.c>'; $contents[] = 'RewriteEngine On'; $contents[] = 'RewriteCond %{QUERY_STRING} !key=' . HMBKP_SECURE_KEY; $contents[] = 'RewriteRule (.*) - [F]'; $contents[] = '</IfModule>'; $contents[] = ''; insert_with_markers($htaccess, 'BackUpWordPress', $contents); } return HM_Backup::conform_dir($path); }
/** * Prepare the envato backup directory and .htaccess * * @access private * @since 1.4 * * @return void */ function _prepare_envato_backup() { $path = EWPT_BACKUP_DIR; /* Create the backups directory if it doesn't exist */ if (is_writable(dirname($path)) && !is_dir($path)) { mkdir($path, 0755); } /* Secure the directory with a .htaccess file */ $htaccess = $path . '.htaccess'; $contents[] = '# ' . __('This .htaccess file ensures that other people cannot download your backup files.', 'envato'); $contents[] = ''; $contents[] = '<IfModule mod_rewrite.c>'; $contents[] = 'RewriteEngine On'; $contents[] = 'RewriteCond %{QUERY_STRING} !key=' . md5(EWPT_SECURE_KEY); $contents[] = 'RewriteRule (.*) - [F]'; $contents[] = '</IfModule>'; $contents[] = ''; if (!file_exists($htaccess) && is_writable($path) && (require_once ABSPATH . '/wp-admin/includes/misc.php')) { insert_with_markers($htaccess, 'EnvatoBackup', $contents); } }
/** * 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); }
function ewww_image_optimizer_webp_rewrite() { // verify that the user is properly authorized if (!wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-settings')) { wp_die(__('Cheatin’ eh?', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } if ($ewww_rules = ewww_image_optimizer_webp_rewrite_verify()) { if (insert_with_markers(get_home_path() . '.htaccess', 'EWWWIO', $ewww_rules) && !ewww_image_optimizer_webp_rewrite_verify()) { _e('Insertion successful', EWWW_IMAGE_OPTIMIZER_DOMAIN); } else { _e('Insertion failed', EWWW_IMAGE_OPTIMIZER_DOMAIN); } } die; }
/** * Updates the htaccess file with the current rules if it is writable. * * Always writes to the file if it exists and is writable to ensure that we * blank out old rules. * * @since 1.5.0 * * @global WP_Rewrite $wp_rewrite */ function save_mod_rewrite_rules() { if (is_multisite()) { return; } global $wp_rewrite; $home_path = get_home_path(); $htaccess_file = $home_path . '.htaccess'; /* * If the file doesn't already exist check for write access to the directory * and whether we have some rules. Else check for write access to the file. */ if (!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks() || is_writable($htaccess_file)) { if (got_mod_rewrite()) { $rules = explode("\n", $wp_rewrite->mod_rewrite_rules()); return insert_with_markers($htaccess_file, 'WordPress', $rules); } } return false; }
/** * @param string $reset */ public function protect_path($reset = 'no') { global $is_apache; // Protect against directory browsing by including an index.html file $index = $this->path . '/index.html'; if ('reset' === $reset && file_exists($index)) { @unlink($index); } if (!file_exists($index) && wp_is_writable($this->path)) { file_put_contents($index, ''); } $htaccess = $this->path . '/.htaccess'; if ('reset' === $reset && file_exists($htaccess)) { @unlink($htaccess); } // Protect the directory with a .htaccess file on Apache servers if ($is_apache && function_exists('insert_with_markers') && !file_exists($htaccess) && wp_is_writable($this->path)) { $contents[] = '# ' . sprintf(__('This %s file ensures that other people cannot download your backup files.', 'hmbkp'), '.htaccess'); $contents[] = ''; $contents[] = '<IfModule mod_rewrite.c>'; $contents[] = 'RewriteEngine On'; $contents[] = 'RewriteCond %{QUERY_STRING} !key=' . HMBKP_SECURE_KEY; $contents[] = 'RewriteRule (.*) - [F]'; $contents[] = '</IfModule>'; $contents[] = ''; insert_with_markers($htaccess, 'BackUpWordPress', $contents); } }
/** * Test whether the attachment upload directory is protected. * * We create a dummy file in the directory, and then test to see * whether we can fetch a copy of the file with a remote request. * * @since 1.6.0 * * @return True if protected, false if not. */ public function check_is_protected($force_check = true) { global $is_apache; // Fall back on cached value if it exists if (!$force_check) { $is_protected = bp_get_option('bp_docs_attachment_protection'); if ('' === $is_protected) { return (bool) $is_protected; } } $uploads = wp_upload_dir(); $test_dir = $uploads['basedir'] . DIRECTORY_SEPARATOR . 'bp-attachments' . DIRECTORY_SEPARATOR . '0'; $test_file_dir = $test_dir . DIRECTORY_SEPARATOR . 'test.html'; $test_text = 'This is a test of the Protected Attachment feature of BuddyPress Docs. Please do not remove.'; if (!file_exists($test_file_dir)) { if (!file_exists($test_dir)) { wp_mkdir_p($test_dir); } // Create an .htaccess, if we can if ($is_apache) { // Fake the doc ID $this->doc_id = 0; $rules = array('RewriteEngine On', 'RewriteBase /', 'RewriteRule (.+) ?bp-attachment=$1 [R=302,NC]'); if (!empty($rules)) { if (!file_exists('insert_with_markers')) { require_once ABSPATH . 'wp-admin/includes/misc.php'; } insert_with_markers($test_dir . DIRECTORY_SEPARATOR . '.htaccess', 'BuddyPress Docs', $rules); } } // Make a dummy file file_put_contents($test_dir . DIRECTORY_SEPARATOR . 'test.html', $test_text); } $test_url = $uploads['baseurl'] . '/bp-attachments/0/test.html'; $r = wp_remote_get($test_url); // If the response body includes our test text, we have a problem $is_protected = true; if (!is_wp_error($r) && $r['body'] === $test_text) { $is_protected = false; } // Cache $cache = $is_protected ? '1' : '0'; bp_update_option('bp_docs_attachment_protection', $cache); return $is_protected; }
function remove_restriction($file_path) { $rest_line = $this->get_restriction_line($file_path); if ($rest_line == -1) { return; } $htaccess_file = $this->get_htaccess(); $rules = $this->get_restrictions(); unset($rules[$rest_line]); $rules = array_values($rules); insert_with_markers($htaccess_file, 'e4d', $rules); }
/** * Write to an Apache configuration file * * @return void */ private function writeConf($file, $marker, $content) { require_once ABSPATH . 'wp-admin/includes/misc.php'; if (is_array($file)) { $file = $this->path($file); } insert_with_markers($file, $marker, $content); }
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 »" /></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 »'</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 »" /></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 }
/** * Creates an .htaccess file in the given path which will disable access to all files on Apache Web Servers. * * @since 2.0.0 * * @param $path */ public static function maybe_create_htaccess_file($path) { $htaccess_file = $path . '.htaccess'; if (file_exists($htaccess_file)) { return; } $txt = '# Disable access to files via Apache web servers. deny from all'; $rules = explode("\n", $txt); if (!function_exists('insert_with_markers')) { require_once ABSPATH . 'wp-admin/includes/misc.php'; } insert_with_markers($htaccess_file, 'Gravity Forms', $rules); }
/** * Remove directives from .htaccess file to enable Shibboleth Lazy Sessions. */ function shibboleth_remove_htaccess() { if (got_mod_rewrite()) { $htaccess = get_home_path() . '.htaccess'; insert_with_markers($htaccess, 'Shibboleth', array()); } }
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; } }
function save_mod_rewrite_rules() { global $is_apache, $wp_rewrite; $home_path = get_home_path(); if (!$wp_rewrite->using_mod_rewrite_permalinks()) { return; } if (!(!file_exists($home_path . '.htaccess') && is_writable($home_path) || is_writable($home_path . '.htaccess'))) { return; } if (!$is_apache) { return; } $rules = explode("\n", $wp_rewrite->mod_rewrite_rules()); insert_with_markers($home_path . '.htaccess', 'WordPress', $rules); }
public static function add_htaccess_file() { $upload_root = GFFormsModel::get_upload_root(); if (!is_dir($upload_root)) { return; } $htaccess_file = $upload_root . '/.htaccess'; if (file_exists($htaccess_file)) { unlink($htaccess_file); } $txt = '# Disable parsing of PHP for some server configurations. This file may be removed or modified on certain server configurations by using by the gform_upload_root_htaccess_rules filter. Please consult your system administrator before removing this file. <Files *> SetHandler none SetHandler default-handler Options -ExecCGI RemoveHandler .cgi .php .php3 .php4 .php5 .phtml .pl .py .pyc .pyo </Files> <IfModule mod_php5.c> php_flag engine off </IfModule>'; $rules = explode("\n", $txt); $rules = apply_filters('gform_upload_root_htaccess_rules', $rules); if (!empty($rules)) { if (!function_exists('insert_with_markers')) { require_once ABSPATH . 'wp-admin/includes/misc.php'; } insert_with_markers($htaccess_file, 'Gravity Forms', $rules); } }