Commit 89a67c8a authored by lucha's avatar lucha

[auto] plugin: wp-super-cache 1.5.9

parent a2d20a6f
<?php
# WP SUPER CACHE 1.2
// WP SUPER CACHE 1.2
function wpcache_broken_message() {
global $wp_cache_config_file;
if ( isset( $wp_cache_config_file ) == false )
if ( isset( $wp_cache_config_file ) == false ) {
return '';
}
$doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
$doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
$xmlrpc_request = defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST;
$rest_request = defined( 'REST_REQUEST' ) && REST_REQUEST;
$robots_request = strpos( $_SERVER[ 'REQUEST_URI' ], 'robots.txt' ) != false;
$rest_request = defined( 'REST_REQUEST' ) && REST_REQUEST;
$robots_request = strpos( $_SERVER['REQUEST_URI'], 'robots.txt' ) != false;
$skip_output = ( $doing_ajax || $xmlrpc_request || $rest_request || $robots_request);
if ( false == strpos( $_SERVER[ 'REQUEST_URI' ], 'wp-admin' ) && !$skip_output ) {
echo "<!-- WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory. -->";
$skip_output = ( $doing_ajax || $xmlrpc_request || $rest_request || $robots_request );
if ( false == strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) && ! $skip_output ) {
echo '<!-- WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory. -->';
}
}
if ( false == defined( 'WPCACHEHOME' ) ) {
define( 'ADVANCEDCACHEPROBLEM', 1 );
} elseif ( !include_once( WPCACHEHOME . 'wp-cache-phase1.php' ) ) {
if ( !@is_file( WPCACHEHOME . 'wp-cache-phase1.php' ) ) {
} elseif ( ! include_once WPCACHEHOME . 'wp-cache-phase1.php' ) {
if ( ! @is_file( WPCACHEHOME . 'wp-cache-phase1.php' ) ) {
define( 'ADVANCEDCACHEPROBLEM', 1 );
}
}
if ( defined( 'ADVANCEDCACHEPROBLEM' ) )
if ( defined( 'ADVANCEDCACHEPROBLEM' ) ) {
register_shutdown_function( 'wpcache_broken_message' );
?>
}
# Copyright (C) 2013
# Copyright (C) 2013
# This file is distributed under the same license as the package.
msgid ""
msgstr ""
......
# Copyright (C) 2012
# Copyright (C) 2012
# This file is distributed under the same license as the package.
msgid ""
msgstr ""
......
......@@ -3,38 +3,47 @@
/* Taken from OSSDL CDN off-linker, a plugin by W-Mark Kubacki (http://mark.ossdl.de/) and used with permission */
/* Set up some defaults */
if ( get_option( 'ossdl_off_cdn_url' ) == false )
if ( get_option( 'ossdl_off_cdn_url' ) === false ) {
add_option( 'ossdl_off_cdn_url', get_option( 'siteurl' ) );
if ( get_option( 'ossdl_off_blog_url' ) == false )
}
if ( get_option( 'ossdl_off_blog_url' ) === false ) {
add_option( 'ossdl_off_blog_url', apply_filters( 'ossdl_off_blog_url', untrailingslashit( get_option( 'siteurl' ) ) ) );
}
$ossdl_off_blog_url = get_option( 'ossdl_off_blog_url' );
$ossdl_off_cdn_url = trim( get_option('ossdl_off_cdn_url') );
if ( get_option( 'ossdl_off_include_dirs' ) == false )
add_option('ossdl_off_include_dirs', 'wp-content,wp-includes');
$ossdl_off_include_dirs = trim(get_option('ossdl_off_include_dirs'));
if ( get_option( 'ossdl_off_exclude' ) == false )
add_option('ossdl_off_exclude', '.php');
$ossdl_off_exclude = trim(get_option('ossdl_off_exclude'));
$arr_of_excludes = array_map('trim', explode(',', $ossdl_off_exclude));
if ( !is_array( $arr_of_excludes ) )
$ossdl_off_cdn_url = trim( get_option( 'ossdl_off_cdn_url' ) );
if ( get_option( 'ossdl_off_include_dirs' ) === false ) {
add_option( 'ossdl_off_include_dirs', 'wp-content,wp-includes' );
}
$ossdl_off_include_dirs = trim( get_option( 'ossdl_off_include_dirs' ) );
if ( get_option( 'ossdl_off_exclude' ) === false ) {
add_option( 'ossdl_off_exclude', '.php' );
}
$ossdl_off_exclude = trim( get_option( 'ossdl_off_exclude' ) );
$arr_of_excludes = array_map( 'trim', explode( ',', $ossdl_off_exclude ) );
if ( ! is_array( $arr_of_excludes ) ) {
$arr_of_excludes = array();
}
if ( get_option( 'ossdl_cname' ) == false )
add_option('ossdl_cname', '');
$ossdl_cname = trim(get_option('ossdl_cname'));
$ossdl_https = intval(get_option('ossdl_https'));
$arr_of_cnames = array_map('trim', explode(',', $ossdl_cname));
if ($arr_of_cnames[0] == '') $arr_of_cnames = array();
if ( get_option( 'ossdl_cname' ) == false ) {
add_option( 'ossdl_cname', '' );
}
$ossdl_cname = trim( get_option( 'ossdl_cname' ) );
$ossdl_https = intval( get_option( 'ossdl_https' ) );
$arr_of_cnames = array_map( 'trim', explode( ',', $ossdl_cname ) );
if ( $arr_of_cnames[0] == '' ) {
$arr_of_cnames = array();
}
/**
* Determines whether to exclude a match.
*
* @param String $match URI to examine
* @param Array $excludes array of "badwords"
* @return Boolean true if to exclude given match from rewriting
* @param string $match URI to examine.
* @param array $excludes Array of "badwords".
*
* @return boolean true if to exclude given match from rewriting.
*/
function scossdl_off_exclude_match($match, $excludes) {
foreach( $excludes as $badword ) {
function scossdl_off_exclude_match( $match, $excludes ) {
foreach ( $excludes as $badword ) {
if ( ! empty( $badword ) && stripos( $match, $badword ) !== false ) {
return true;
}
......@@ -42,14 +51,19 @@ function scossdl_off_exclude_match($match, $excludes) {
return false;
}
/**
/**
* Compute string modulo, based on SHA1 hash
*
* @param string $str
* @param int $mod
*
* @return int
*/
function scossdl_string_mod($s, $mod) {
function scossdl_string_mod( $str, $mod ) {
/* The full SHA1 is too large for PHP integer types. This should be
* enough for our purpose */
$n = hexdec(substr(sha1($s), 0, 5));
return $n % $mod;
$num = hexdec( substr( sha1( $str ), 0, 5 ) );
return $num % $mod;
}
/**
......@@ -57,29 +71,32 @@ function scossdl_string_mod($s, $mod) {
*
* Called by #scossdl_off_filter.
*/
function scossdl_off_rewriter($match) {
function scossdl_off_rewriter( $match ) {
global $ossdl_off_blog_url, $ossdl_off_cdn_url, $arr_of_excludes, $arr_of_cnames, $ossdl_https;
if ( $ossdl_off_cdn_url == '' )
if ( $ossdl_off_cdn_url == '' ) {
return $match[0];
}
if ( $ossdl_https && substr( $match[0], 0, 5 ) == 'https' )
if ( $ossdl_https && 0 === strncmp( $match[0], 'https', 5 ) ) {
return $match[0];
}
if ( false == in_array( $ossdl_off_cdn_url, $arr_of_cnames ) )
if ( false === in_array( $ossdl_off_cdn_url, $arr_of_cnames ) ) {
$arr_of_cnames[] = $ossdl_off_cdn_url;
}
if ( scossdl_off_exclude_match( $match[0], $arr_of_excludes ) ) {
return $match[0];
} else {
$include_dirs = scossdl_off_additional_directories();
if ( preg_match( '/' . $include_dirs . '/', $match[0] ) ) {
$offset = scossdl_string_mod($match[1], count($arr_of_cnames));
return str_replace($ossdl_off_blog_url, $arr_of_cnames[$offset], $match[0]);
} else {
return $match[0];
}
}
$include_dirs = scossdl_off_additional_directories();
if ( preg_match( '/' . $include_dirs . '/', $match[0] ) ) {
$offset = scossdl_string_mod( $match[1], count( $arr_of_cnames ) );
return str_replace( $ossdl_off_blog_url, $arr_of_cnames[ $offset ], $match[0] );
}
return $match[0];
}
/**
......@@ -88,27 +105,29 @@ function scossdl_off_rewriter($match) {
* @return String with the pattern with {@literal |} as prefix, or empty
*/
function scossdl_off_additional_directories() {
global $ossdl_off_include_dirs;
$input = explode(',', $ossdl_off_include_dirs);
if ($ossdl_off_include_dirs == '' || count($input) < 1) {
return 'wp\-content|wp\-includes';
} else {
return implode('|', array_map('quotemeta', array_map('trim', $input)));
}
global $ossdl_off_include_dirs;
$arr_dirs = explode( ',', $ossdl_off_include_dirs );
if ( $ossdl_off_include_dirs == '' || count( $arr_dirs ) < 1 ) {
return 'wp\-content|wp\-includes';
}
return implode( '|', array_map( 'preg_quote', array_map( 'trim', $arr_dirs ) ) );
}
/**
* Output filter which runs the actual plugin logic.
*/
function scossdl_off_filter($content) {
function scossdl_off_filter( $content ) {
global $ossdl_off_blog_url, $ossdl_off_cdn_url;
if ($ossdl_off_blog_url == $ossdl_off_cdn_url) { // no rewrite needed
if ( $ossdl_off_blog_url == $ossdl_off_cdn_url ) { // no rewrite needed
return $content;
} else {
$dirs = scossdl_off_additional_directories();
$regex = '#(?<=[(\"\'])'.quotemeta($ossdl_off_blog_url).'/(?:((?:'.$dirs.')[^\"\')]+)|([^/\"\']+\.[^/\"\')]+))(?=[\"\')])#';
return preg_replace_callback($regex, 'scossdl_off_rewriter', $content);
}
$dirs = scossdl_off_additional_directories();
$regex = '#(?<=[(\"\'])' . preg_quote( $ossdl_off_blog_url ) . '/(?:((?:' . $dirs . ')[^\"\')]+)|([^/\"\']+\.[^/\"\')]+))(?=[\"\')])#';
return preg_replace_callback( $regex, 'scossdl_off_rewriter', $content );
}
/**
......@@ -116,40 +135,39 @@ function scossdl_off_filter($content) {
*/
function do_scossdl_off_ob_start() {
global $ossdl_off_blog_url, $ossdl_off_cdn_url;
if ($ossdl_off_blog_url != $ossdl_off_cdn_url) {
if ( $ossdl_off_blog_url != $ossdl_off_cdn_url ) {
add_filter( 'wp_cache_ob_callback_filter', 'scossdl_off_filter' );
}
}
if ( false == isset( $ossdlcdn ) )
if ( false == isset( $ossdlcdn ) ) {
$ossdlcdn = 1; // have to default to on for existing users.
if ( $ossdlcdn == 1 )
add_action('init', 'do_scossdl_off_ob_start');
}
if ( $ossdlcdn == 1 ) {
add_action( 'init', 'do_scossdl_off_ob_start' );
}
function scossdl_off_update() {
global $ossdlcdn, $wp_cache_config_file;
$valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
if ( $valid_nonce && isset($_POST['action']) && ( $_POST['action'] == 'update_ossdl_off' )){
update_option( 'ossdl_off_cdn_url', untrailingslashit( $_POST[ 'ossdl_off_cdn_url' ] ) );
update_option( 'ossdl_off_blog_url', untrailingslashit( $_POST[ 'ossdl_off_blog_url' ] ) );
update_option('ossdl_off_include_dirs', $_POST['ossdl_off_include_dirs'] == '' ? 'wp-content,wp-includes' : $_POST['ossdl_off_include_dirs']);
update_option('ossdl_off_exclude', $_POST['ossdl_off_exclude']);
update_option('ossdl_cname', $_POST['ossdl_cname']);
if ( !isset( $_POST[ 'ossdl_https' ] ) )
$_POST[ 'ossdl_https' ] = 0;
update_option('ossdl_https', (int)$_POST['ossdl_https']);
if ( isset( $_POST[ 'ossdlcdn' ] ) ) {
$ossdlcdn = 1;
} else {
$ossdlcdn = 0;
}
wp_cache_replace_line('^ *\$ossdlcdn', "\$ossdlcdn = $ossdlcdn;", $wp_cache_config_file);
if ( isset( $_POST['action'], $_POST['_wpnonce'] )
&& 'update_ossdl_off' === $_POST['action']
&& wp_verify_nonce( $_POST['_wpnonce'], 'wp-cache' )
) {
update_option( 'ossdl_off_cdn_url', untrailingslashit( $_POST['ossdl_off_cdn_url'] ) );
update_option( 'ossdl_off_blog_url', untrailingslashit( $_POST['ossdl_off_blog_url'] ) );
update_option( 'ossdl_off_include_dirs', $_POST['ossdl_off_include_dirs'] == '' ? 'wp-content,wp-includes' : $_POST['ossdl_off_include_dirs'] );
update_option( 'ossdl_off_exclude', $_POST['ossdl_off_exclude'] );
update_option( 'ossdl_cname', $_POST['ossdl_cname'] );
$ossdl_https = empty( $_POST['ossdl_https'] ) ? 0 : 1;
$ossdlcdn = empty( $_POST['ossdlcdn'] ) ? 0 : 1;
update_option( 'ossdl_https', $ossdl_https );
wp_cache_setting( 'ossdlcdn', $ossdlcdn );
}
}
function scossdl_off_options() {
global $ossdlcdn, $wp_cache_config_file, $ossdl_off_blog_url;
global $ossdlcdn, $ossdl_off_blog_url;
scossdl_off_update();
......@@ -158,9 +176,9 @@ function scossdl_off_options() {
$example_cnames .= ',' . str_replace( 'http://cdn.', 'http://cdn2.', $example_cdn_uri );
$example_cnames .= ',' . str_replace( 'http://cdn.', 'http://cdn3.', $example_cdn_uri );
$example_cdn_uri = get_option('ossdl_off_cdn_url') == get_option( 'siteurl' ) ? $example_cdn_uri : get_option('ossdl_off_cdn_url');
$example_cdn_uri = get_option( 'ossdl_off_cdn_url' ) == get_option( 'siteurl' ) ? $example_cdn_uri : get_option( 'ossdl_off_cdn_url' );
$example_cdn_uri .= '/wp-includes/js/jquery/jquery-migrate.js';
$example_cdn_uri = esc_url( $example_cdn_uri );
$example_cdn_uri = esc_url( $example_cdn_uri );
?>
<p><?php _e( 'Your website probably uses lots of static files. Image, Javascript and CSS files are usually static files that could just as easily be served from another site or CDN. Therefore, this plugin replaces any links in the <code>wp-content</code> and <code>wp-includes</code> directories (except for PHP files) on your site with the URL you provide below. That way you can either copy all the static content to a dedicated host or mirror the files to a CDN by <a href="https://knowledgelayer.softlayer.com/faq/how-does-origin-pull-work" target="_blank">origin pull</a>.', 'wp-super-cache' ); ?></p>
<p><?php printf( __( '<strong style="color: red">WARNING:</strong> Test some static urls e.g., %s to ensure your CDN service is fully working before saving changes.', 'wp-super-cache' ), '<code>' . esc_html( $example_cdn_uri ) . '</code>' ); ?></p>
......@@ -171,11 +189,11 @@ function scossdl_off_options() {
<p><?php _e( 'You can define different CDN URLs for each site on a multsite network.', 'wp-super-cache' ); ?></p>
<p><form method="post" action="">
<?php wp_nonce_field('wp-cache'); ?>
<?php wp_nonce_field( 'wp-cache' ); ?>
<table class="form-table"><tbody>
<tr valign="top">
<td style='text-align: right'>
<input id='ossdlcdn' type="checkbox" name="ossdlcdn" value="1" <?php if ( $ossdlcdn ) echo "checked=1"; ?> />
<input id='ossdlcdn' type="checkbox" name="ossdlcdn" value="1" <?php if ( $ossdlcdn ) { echo "checked=1"; } ?> />
</td>
<th scope="row"><label for="ossdlcdn"><?php _e( 'Enable CDN Support', 'wp-super-cache' ); ?></label></th>
</tr>
......@@ -219,9 +237,8 @@ function scossdl_off_options() {
</tr>
</tbody></table>
<input type="hidden" name="action" value="update_ossdl_off" />
<p class="submit"><input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'wp-super-cache' ) ?>" /></p>
<p class="submit"><input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'wp-super-cache' ); ?>" /></p>
</form></p>
<p><?php _e( 'CDN functionality provided by <a href="http://wordpress.org/plugins/ossdl-cdn-off-linker/">OSSDL CDN Off Linker</a> by <a href="http://mark.ossdl.de/">Mark Kubacki</a>', 'wp-super-cache' ); ?></p>
<p><?php _e( 'CDN functionality provided by <a href="https://wordpress.org/plugins/ossdl-cdn-off-linker/">OSSDL CDN Off Linker</a> by <a href="http://mark.ossdl.de/">Mark Kubacki</a>', 'wp-super-cache' ); ?></p>
<?php
}
?>
......@@ -7,21 +7,21 @@ function awaitingmoderation_action( $buffer ) {
function awaitingmoderation_actions() {
global $cache_awaitingmoderation;
if( $cache_awaitingmoderation == '1' ) {
if ( '1' === $cache_awaitingmoderation ) {
add_filter( 'wpsupercache_buffer', 'awaitingmoderation_action' );
}
}
add_cacheaction( 'add_cacheaction', 'awaitingmoderation_actions' );
//Your comment is awaiting moderation.
// Your comment is awaiting moderation.
function wp_supercache_awaitingmoderation_admin() {
global $cache_awaitingmoderation, $wp_cache_config_file, $valid_nonce;
$cache_awaitingmoderation = $cache_awaitingmoderation == '' ? '0' : $cache_awaitingmoderation;
$cache_awaitingmoderation = '' === $cache_awaitingmoderation ? '0' : $cache_awaitingmoderation;
if(isset($_POST['cache_awaitingmoderation']) && $valid_nonce) {
$cache_awaitingmoderation = (int)$_POST['cache_awaitingmoderation'];
wp_cache_replace_line('^ *\$cache_awaitingmoderation', "\$cache_awaitingmoderation = '$cache_awaitingmoderation';", $wp_cache_config_file);
if ( isset( $_POST['cache_awaitingmoderation'] ) && $valid_nonce ) {
$cache_awaitingmoderation = (int) $_POST['cache_awaitingmoderation'];
wp_cache_replace_line( '^ *\$cache_awaitingmoderation', "\$cache_awaitingmoderation = '$cache_awaitingmoderation';", $wp_cache_config_file );
$changed = true;
} else {
$changed = false;
......@@ -31,19 +31,20 @@ function wp_supercache_awaitingmoderation_admin() {
<fieldset id="<?php echo $id; ?>" class="options">
<h4><?php _e( 'Awaiting Moderation', 'wp-super-cache' ); ?></h4>
<form name="wp_manager" action="" method="post">
<label><input type="radio" name="cache_awaitingmoderation" value="1" <?php if( $cache_awaitingmoderation ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
<label><input type="radio" name="cache_awaitingmoderation" value="0" <?php if( !$cache_awaitingmoderation ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
<label><input type="radio" name="cache_awaitingmoderation" value="1" <?php if ( $cache_awaitingmoderation ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
<label><input type="radio" name="cache_awaitingmoderation" value="0" <?php if ( ! $cache_awaitingmoderation ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
<p><?php _e( 'Enables or disables plugin to Remove the text "Your comment is awaiting moderation." when someone leaves a moderated comment.', 'wp-super-cache' ); ?></p>
<?php
if ($changed) {
if ( $cache_awaitingmoderation )
$status = __( "enabled", 'wp-super-cache' );
else
$status = __( "disabled", 'wp-super-cache' );
echo "<p><strong>" . sprintf( __( "Awaiting Moderation is now %s", 'wp-super-cache' ), $status ) . "</strong></p>";
if ( $changed ) {
if ( $cache_awaitingmoderation ) {
$status = __( 'enabled', 'wp-super-cache' );
} else {
$status = __( 'disabled', 'wp-super-cache' );
}
echo '<p><strong>' . sprintf( __( 'Awaiting Moderation is now %s', 'wp-super-cache' ), $status ) . '</strong></p>';
}
echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
wp_nonce_field('wp-cache');
echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
wp_nonce_field( 'wp-cache' );
?>
</form>
</fieldset>
......@@ -53,13 +54,12 @@ function wp_supercache_awaitingmoderation_admin() {
add_cacheaction( 'cache_admin_page', 'wp_supercache_awaitingmoderation_admin' );
function wpsc_awaiting_moderation_list( $list ) {
$list[ 'awaitingmoderation' ] = array(
'key' => 'awaitingmoderation',
'url' => '',
$list['awaitingmoderation'] = array(
'key' => 'awaitingmoderation',
'url' => '',
'title' => __( 'Awaiting Moderation', 'wp-super-cache' ),
'desc' => __( 'Enables or disables plugin to Remove the text "Your comment is awaiting moderation." when someone leaves a moderated comment.', 'wp-super-cache' ),
'desc' => __( 'Enables or disables plugin to Remove the text "Your comment is awaiting moderation." when someone leaves a moderated comment.', 'wp-super-cache' ),
);
return $list;
}
add_cacheaction( 'wpsc_filter_list', 'wpsc_awaiting_moderation_list' );
?>
......@@ -3,8 +3,9 @@
function wp_supercache_badbehaviour( $file ) {
global $cache_badbehaviour;
if( $cache_badbehaviour != 1 )
if ( 1 !== $cache_badbehaviour ) {
return $file;
}
wp_supercache_badbehaviour_include();
return $file;
}
......@@ -12,18 +13,20 @@ add_cacheaction( 'wp_cache_served_cache_file', 'wp_supercache_badbehaviour' );
function wp_supercache_badbehaviour_include() {
$bbfile = get_bb_file_loc();
if( !$bbfile )
require_once( $bbfile );
if ( ! $bbfile ) {
require_once $bbfile;
}
}
function get_bb_file_loc() {
global $cache_badbehaviour_file;
if( $cache_badbehaviour_file )
if ( $cache_badbehaviour_file ) {
return $cache_badbehaviour_file;
}
if( file_exists( WP_CONTENT_DIR . '/plugins/bad-behavior/bad-behavior-generic.php' ) ) {
if ( file_exists( WP_CONTENT_DIR . '/plugins/bad-behavior/bad-behavior-generic.php' ) ) {
$bbfile = WP_CONTENT_DIR . '/plugins/bad-behavior/bad-behavior-generic.php';
} elseif( file_exists( WP_CONTENT_DIR . '/plugins/Bad-Behavior/bad-behavior-generic.php' ) ) {
} elseif ( file_exists( WP_CONTENT_DIR . '/plugins/Bad-Behavior/bad-behavior-generic.php' ) ) {
$bbfile = WP_CONTENT_DIR . '/plugins/Bad-Behavior/bad-behavior-generic.php';
} else {
$bbfile = false;
......@@ -34,27 +37,28 @@ function get_bb_file_loc() {
function wp_supercache_badbehaviour_admin() {
global $cache_badbehaviour, $wp_cache_config_file, $valid_nonce;
$cache_badbehaviour = $cache_badbehaviour == '' ? 0 : $cache_badbehaviour;
if ( $cache_badbehaviour == 'no' )
$cache_badbehaviour = '' === $cache_badbehaviour ? 0 : $cache_badbehaviour;
if ( 'no' === $cache_badbehaviour ) {
$cache_badbehaviour = 0;
}
$err = false;
if ( isset( $_POST['cache_badbehaviour'] ) && $valid_nonce ) {
$bbfile = get_bb_file_loc();
if( !$bbfile ) {
$_POST[ 'cache_badbehaviour' ] = 0;
if ( ! $bbfile ) {
$_POST['cache_badbehaviour'] = 0;
$err = __( 'Bad Behaviour not found. Please check your install.', 'wp-super-cache' );
}
if ( $cache_badbehaviour == (int)$_POST['cache_badbehaviour'] ) {
if ( $cache_badbehaviour === (int) $_POST['cache_badbehaviour'] ) {
$changed = false;
} else {
$changed = true;
}
$cache_badbehaviour = (int)$_POST['cache_badbehaviour'];
wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = 0;", $wp_cache_config_file);
wp_cache_replace_line('^ *\$cache_badbehaviour', "\$cache_badbehaviour = $cache_badbehaviour;", $wp_cache_config_file);
wp_cache_replace_line('^ *\$cache_badbehaviour_file', "\$cache_badbehaviour_file = '$bbfile';", $wp_cache_config_file);
$cache_badbehaviour = (int) $_POST['cache_badbehaviour'];
wp_cache_replace_line( '^ *\$cache_compression', "\$cache_compression = 0;", $wp_cache_config_file );
wp_cache_replace_line( '^ *\$cache_badbehaviour', "\$cache_badbehaviour = $cache_badbehaviour;", $wp_cache_config_file );
wp_cache_replace_line( '^ *\$cache_badbehaviour_file', "\$cache_badbehaviour_file = '$bbfile';", $wp_cache_config_file );
$changed = true;
}
$id = 'badbehavior-section';
......@@ -62,31 +66,33 @@ function wp_supercache_badbehaviour_admin() {
<fieldset id="<?php echo $id; ?>" class="options">
<h4><?php _e( 'Bad Behavior', 'wp-super-cache' ); ?></h4>
<form name="wp_manager" action="" method="post">
<label><input type="radio" name="cache_badbehaviour" value="1" <?php if( $cache_badbehaviour ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
<label><input type="radio" name="cache_badbehaviour" value="0" <?php if( !$cache_badbehaviour ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
<label><input type="radio" name="cache_badbehaviour" value="1" <?php if ( $cache_badbehaviour ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
<label><input type="radio" name="cache_badbehaviour" value="0" <?php if ( ! $cache_badbehaviour ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
<p><?php _e( '', 'wp-super-cache' ); ?></p><?php
echo '<p>' . sprintf( __( '(Only WPCache caching supported, disabled compression and requires <a href="http://www.bad-behavior.ioerror.us/">Bad Behavior</a> in "%s/plugins/bad-behavior/") ', 'wp-super-cache' ), WP_CONTENT_DIR ) . '</p>';
if ( isset( $changed ) && $changed ) {
if ( $cache_badbehaviour )
$status = __( "enabled", 'wp-super-cache' );
else
$status = __( "disabled", 'wp-super-cache' );
echo "<p><strong>" . sprintf( __( "Bad Behavior support is now %s", 'wp-super-cache' ), $status ) . "</strong></p>";
if ( $cache_badbehaviour ) {
$status = __( 'enabled', 'wp-super-cache' );
} else {
$status = __( 'disable', 'wp-super-cache' );
}
echo '<p><strong>' . sprintf( __( 'Bad Behavior support is now %s', 'wp-super-cache' ), $status ) . '</strong></p>';
}
echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
wp_nonce_field('wp-cache');
echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
wp_nonce_field( 'wp-cache' );
?>
</form>
</fieldset>
<?php
if( $err )
echo "<p><strong>" . __( 'Warning!', 'wp-super-cache' ) . "</strong> $err</p>";
if ( $err ) {
echo '<p><strong>' . __( 'Warning!', 'wp-super-cache' ) . "</strong> $err</p>";
}
}
add_cacheaction( 'cache_admin_page', 'wp_supercache_badbehaviour_admin' );
function wpsc_badbehaviour_list( $list ) {
$list[ 'badbehaviour' ] = array(
$list['badbehaviour'] = array(
'key' => 'badbehaviour',
'url' => 'http://www.bad-behavior.ioerror.us/',
'title' => __( 'Bad Behavior', 'wp-super-cache' ),
......@@ -95,5 +101,3 @@ function wpsc_badbehaviour_list( $list ) {
return $list;
}
add_cacheaction( 'wpsc_filter_list', 'wpsc_badbehaviour_list' );
?>
......@@ -3,28 +3,31 @@
function domain_mapping_gc_cache( $function, $directory ) {
global $cache_path;
if ( !function_exists( 'domain_mapping_warning' ) )
if ( ! function_exists( 'domain_mapping_warning' ) ) {
return false;
}
$siteurl = domain_mapping_siteurl( false );
if ( !$siteurl )
if ( ! $siteurl ) {
return false;
}
$protocol = ( isset( $_SERVER['HTTPS' ] ) && 'on' == strtolower( $_SERVER['HTTPS' ] ) ) ? 'https://' : 'http://';
$siteurl = trailingslashit( str_replace( $protocol, '', $siteurl ) );
$protocol = ( isset( $_SERVER['HTTPS'] ) && 'on' === strtolower( $_SERVER['HTTPS'] ) ) ? 'https://' : 'http://';
$siteurl = trailingslashit( str_replace( $protocol, '', $siteurl ) );
if ( $directory == 'homepage' )
if ( 'homepage' === $directory ) {
$directory = '';
}
switch( $function ) {
case "rebuild":
switch ( $function ) {
case 'rebuild':
@wp_cache_rebuild_or_delete( $cache_path . 'supercache/' . $siteurl . $directory . 'index.html' );
@wp_cache_rebuild_or_delete( $cache_path . 'supercache/' . $siteurl . $directory . 'index.html.gz' );
break;
case "prune":
break;
case 'prune':
prune_super_cache( $cache_path . 'supercache/' . $siteurl . $directory . 'index.html', true, true );
prune_super_cache( $cache_path . 'supercache/' . $siteurl . $directory . 'index.html.gz', true, true );
break;
break;
}
return $directory;
......@@ -32,21 +35,23 @@ function domain_mapping_gc_cache( $function, $directory ) {
function domain_mapping_supercachedir( $dir ) {
global $cache_path;
if ( !function_exists( 'domain_mapping_warning' ) )
if ( ! function_exists( 'domain_mapping_warning' ) ) {
return $dir;
}