From 3d857270a24d541b682d31da547fc86681793e7b Mon Sep 17 00:00:00 2001 From: stodorovic Date: Fri, 7 Sep 2018 13:33:03 +0200 Subject: [PATCH 1/2] Uses function fileperms instead of stat --- wp-cache.php | 251 +++++++++++++++++++++++++++------------------------ 1 file changed, 131 insertions(+), 120 deletions(-) diff --git a/wp-cache.php b/wp-cache.php index 27ebebe9..506037eb 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -381,55 +381,56 @@ function wp_cache_manager_error_checks() { } elseif ( !isset( $dismiss_readable_warning ) ) { $dismiss_readable_warning = 0; } - if( $dismiss_readable_warning == 0 && is_writeable_ACLSafe( WP_CONTENT_DIR . '/' ) ) { - $wp_content_stat = stat(WP_CONTENT_DIR . '/'); - $wp_content_mode = decoct( $wp_content_stat[ 'mode' ] & 0777 ); - if( substr( $wp_content_mode, -2 ) == '77' ) { - ?>

-

chmod 755 /

+ + if ( 0 === $dismiss_readable_warning && + is_writeable_ACLSafe( WP_CONTENT_DIR . '/' ) && + ( fileperms( WP_CONTENT_DIR . '/' ) & 077 ) === 077 + ) { + ?> +

+

chmod 755 /

This page explains how to change file permissions.', 'wp-super-cache' ); ?>

- - - - ' /> + + + + ' />

-
- +

' . __( 'Mobile rewrite rules detected', 'wp-super-cache' ) . "

"; - echo "

" . __( 'For best performance you should enable "Mobile device support" or delete the mobile rewrite rules in your .htaccess. Look for the 2 lines with the text "2.0\ MMP|240x320" and delete those.', 'wp-super-cache' ) . "

" . __( 'This will have no affect on ordinary users but mobile users will see uncached pages.', 'wp-super-cache' ) . "

"; - } elseif ( $wp_cache_mod_rewrite && $cache_enabled && $wp_cache_mobile_enabled && $scrules != '' && ( - ( '' != $wp_cache_mobile_prefixes && false === strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_prefixes ), ' ' ) ) ) || - ( '' != $wp_cache_mobile_browsers && false === strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) ) ) ) - ) { - ?> -

-

- -

  1. -
  2. Update Mod_Rewrite Rules button.', 'wp-super-cache' ); ?>
  3. -
  4. # BEGIN WPSuperCache and # END WPSuperCache and let the plugin regenerate them by reloading this page.', 'wp-super-cache' ), $home_path ); ?>
  5. -
  6. # BEGIN WPSuperCache and # END WPSuperCache. There are two sections that look very similar. Just below the line %%{HTTP:Cookie} !^.*(comment_author_|%s|wp-postpass_).*$ add these lines: (do it twice, once for each section)', 'wp-super-cache' ), $home_path, wpsc_get_logged_in_cookie() ); ?>

    -

' . __( 'Mobile rewrite rules detected', 'wp-super-cache' ) . "

"; + echo "

" . __( 'For best performance you should enable "Mobile device support" or delete the mobile rewrite rules in your .htaccess. Look for the 2 lines with the text "2.0\ MMP|240x320" and delete those.', 'wp-super-cache' ) . "

" . __( 'This will have no affect on ordinary users but mobile users will see uncached pages.', 'wp-super-cache' ) . "

"; + } elseif ( $wp_cache_mod_rewrite && $cache_enabled && $wp_cache_mobile_enabled && $scrules != '' && ( + ( '' != $wp_cache_mobile_prefixes && false === strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_prefixes ), ' ' ) ) ) || + ( '' != $wp_cache_mobile_browsers && false === strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) ) ) ) + ) { + ?> +

+

+ +

  1. +
  2. Update Mod_Rewrite Rules button.', 'wp-super-cache' ); ?>
  3. +
  4. # BEGIN WPSuperCache and # END WPSuperCache and let the plugin regenerate them by reloading this page.', 'wp-super-cache' ), $home_path ); ?>
  5. +
  6. # BEGIN WPSuperCache and # END WPSuperCache. There are two sections that look very similar. Just below the line %%{HTTP:Cookie} !^.*(comment_author_|%s|wp-postpass_).*$ add these lines: (do it twice, once for each section)', 'wp-super-cache' ), $home_path, wpsc_get_logged_in_cookie() ); ?>

    +

-

- Update Mod_Rewrite Rules button.', 'wp-super-cache' ); ?>

+

+ Update Mod_Rewrite Rules button.', 'wp-super-cache' ); ?>

+

+ + +

+ +

+ + +

+ '; if( is_array( $cached_direct_pages ) ) { $out = ''; @@ -2332,9 +2340,9 @@ function wp_cache_index_notice() { echo " | " . __( 'Logout', 'wp-super-cache' ) . ""; } echo ""; -?> + ?> -" . sprintf( __( "Edit %s and add the following line:
define('WP_CACHE', true);
Otherwise, WP-Cache will not be executed by WordPress core. ", 'wp-super-cache' ), $global ) . "

"; } return false; - } else { + } else { echo "
" . __( '

WP_CACHE constant added to wp-config.php

If you continue to see this warning message please see point 5 of the Troubleshooting Guide. The WP_CACHE line must be moved up.', 'wp-super-cache' ) . "

"; } return true; @@ -2733,82 +2741,85 @@ function wp_cache_files() { $cache_stats = get_option( 'supercache_stats' ); if ( !is_array( $cache_stats ) || ( isset( $_GET[ 'listfiles' ] ) ) || ( $valid_nonce && array_key_exists('action', $_GET) && $_GET[ 'action' ] == 'regenerate_cache_stats' ) ) { - $count = 0; - $expired = 0; - $now = time(); - $wp_cache_fsize = 0; - if ( ( $handle = @opendir( $blog_cache_dir ) ) ) { - if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletewpcache' ) { - $deleteuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', base64_decode( $_GET[ 'uri' ] ) ) ); - } else { - $deleteuri = ''; - } - - if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletesupercache' ) { - $supercacheuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) ); - $supercacheuri = trailingslashit( realpath( $cache_path . 'supercache/' . $supercacheuri ) ); - if ( wp_cache_confirm_delete( $supercacheuri ) ) { - printf( __( "Deleting supercache file: %s
", 'wp-super-cache' ), $supercacheuri ); - wpsc_delete_files( $supercacheuri ); - prune_super_cache( $supercacheuri . 'page', true ); - @rmdir( $supercacheuri ); + $count = 0; + $expired = 0; + $now = time(); + $wp_cache_fsize = 0; + if ( ( $handle = @opendir( $blog_cache_dir ) ) ) { + if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletewpcache' ) { + $deleteuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', base64_decode( $_GET[ 'uri' ] ) ) ); } else { - wp_die( __( 'Warning! You are not allowed to delete that file', 'wp-super-cache' ) ); + $deleteuri = ''; } - } - while( false !== ( $file = readdir( $handle ) ) ) { - if ( strpos( $file, $file_prefix ) !== false && substr( $file, -4 ) == '.php' ) { - if ( false == file_exists( $blog_cache_dir . 'meta/' . $file ) ) { - @unlink( $blog_cache_dir . $file ); - continue; // meta does not exist + + if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletesupercache' ) { + $supercacheuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) ); + $supercacheuri = trailingslashit( realpath( $cache_path . 'supercache/' . $supercacheuri ) ); + if ( wp_cache_confirm_delete( $supercacheuri ) ) { + printf( __( "Deleting supercache file: %s
", 'wp-super-cache' ), $supercacheuri ); + wpsc_delete_files( $supercacheuri ); + prune_super_cache( $supercacheuri . 'page', true ); + @rmdir( $supercacheuri ); + } else { + wp_die( __( 'Warning! You are not allowed to delete that file', 'wp-super-cache' ) ); } - $mtime = filemtime( $blog_cache_dir . 'meta/' . $file ); - $fsize = @filesize( $blog_cache_dir . $file ); - if ( $fsize > 0 ) - $fsize = $fsize - 15; // die() command takes 15 bytes at the start of the file - - $age = $now - $mtime; - if ( $valid_nonce && isset( $_GET[ 'listfiles' ] ) ) { - $meta = json_decode( wp_cache_get_legacy_cache( $blog_cache_dir . 'meta/' . $file ), true ); - if ( $deleteuri != '' && $meta[ 'uri' ] == $deleteuri ) { - printf( __( "Deleting wp-cache file: %s
", 'wp-super-cache' ), esc_html( $deleteuri ) ); - @unlink( $blog_cache_dir . 'meta/' . $file ); + } + + while( false !== ( $file = readdir( $handle ) ) ) { + if ( strpos( $file, $file_prefix ) !== false && substr( $file, -4 ) == '.php' ) { + if ( false == file_exists( $blog_cache_dir . 'meta/' . $file ) ) { @unlink( $blog_cache_dir . $file ); - continue; + continue; // meta does not exist } - $meta[ 'age' ] = $age; - foreach( $meta as $key => $val ) - $meta[ $key ] = esc_html( $val ); + $mtime = filemtime( $blog_cache_dir . 'meta/' . $file ); + $fsize = @filesize( $blog_cache_dir . $file ); + if ( $fsize > 0 ) { + $fsize = $fsize - 15; // die() command takes 15 bytes at the start of the file + } + + $age = $now - $mtime; + if ( $valid_nonce && isset( $_GET[ 'listfiles' ] ) ) { + $meta = json_decode( wp_cache_get_legacy_cache( $blog_cache_dir . 'meta/' . $file ), true ); + if ( $deleteuri != '' && $meta[ 'uri' ] == $deleteuri ) { + printf( __( "Deleting wp-cache file: %s
", 'wp-super-cache' ), esc_html( $deleteuri ) ); + @unlink( $blog_cache_dir . 'meta/' . $file ); + @unlink( $blog_cache_dir . $file ); + continue; + } + $meta[ 'age' ] = $age; + foreach ( $meta as $key => $val ) { + $meta[ $key ] = esc_html( $val ); + } + if ( $cache_max_time > 0 && $age > $cache_max_time ) { + $expired_list[ $age ][] = $meta; + } else { + $cached_list[ $age ][] = $meta; + } + } + if ( $cache_max_time > 0 && $age > $cache_max_time ) { - $expired_list[ $age ][] = $meta; + $expired++; } else { - $cached_list[ $age ][] = $meta; + $count++; } + $wp_cache_fsize += $fsize; } - - if ( $cache_max_time > 0 && $age > $cache_max_time ) { - $expired++; - } else { - $count++; - } - $wp_cache_fsize += $fsize; } + closedir($handle); } - closedir($handle); - } - if( $wp_cache_fsize != 0 ) { - $wp_cache_fsize = $wp_cache_fsize/1024; - } else { - $wp_cache_fsize = 0; - } - if( $wp_cache_fsize > 1024 ) { - $wp_cache_fsize = number_format( $wp_cache_fsize / 1024, 2 ) . "MB"; - } elseif( $wp_cache_fsize != 0 ) { - $wp_cache_fsize = number_format( $wp_cache_fsize, 2 ) . "KB"; - } else { - $wp_cache_fsize = '0KB'; - } - $cache_stats = wp_cache_regenerate_cache_file_stats(); + if( $wp_cache_fsize != 0 ) { + $wp_cache_fsize = $wp_cache_fsize/1024; + } else { + $wp_cache_fsize = 0; + } + if( $wp_cache_fsize > 1024 ) { + $wp_cache_fsize = number_format( $wp_cache_fsize / 1024, 2 ) . "MB"; + } elseif( $wp_cache_fsize != 0 ) { + $wp_cache_fsize = number_format( $wp_cache_fsize, 2 ) . "KB"; + } else { + $wp_cache_fsize = '0KB'; + } + $cache_stats = wp_cache_regenerate_cache_file_stats(); } else { echo "

" . __( 'Cache stats are not automatically generated. You must click the link below to regenerate the stats on this page.', 'wp-super-cache' ) . "

"; echo " 'wpsupercache', 'tab' => 'contents', 'action' => 'regenerate_cache_stats' ) ), 'wp-cache' ) . "'>" . __( 'Regenerate cache stats', 'wp-super-cache' ) . ""; From c81e9d7658354457be0f0ebd54dbf01c538e8835 Mon Sep 17 00:00:00 2001 From: stodorovic Date: Mon, 10 Sep 2018 13:26:21 +0200 Subject: [PATCH 2/2] Indent/html correction for wp_cache_manager_error_checks --- wp-cache.php | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/wp-cache.php b/wp-cache.php index 506037eb..4ba63bf7 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -412,20 +412,24 @@ function wp_cache_manager_error_checks() { echo '

' . __( 'Mobile rewrite rules detected', 'wp-super-cache' ) . "

"; echo "

" . __( 'For best performance you should enable "Mobile device support" or delete the mobile rewrite rules in your .htaccess. Look for the 2 lines with the text "2.0\ MMP|240x320" and delete those.', 'wp-super-cache' ) . "

" . __( 'This will have no affect on ordinary users but mobile users will see uncached pages.', 'wp-super-cache' ) . "

"; } elseif ( $wp_cache_mod_rewrite && $cache_enabled && $wp_cache_mobile_enabled && $scrules != '' && ( - ( '' != $wp_cache_mobile_prefixes && false === strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_prefixes ), ' ' ) ) ) || - ( '' != $wp_cache_mobile_browsers && false === strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) ) ) ) - ) { + ( '' != $wp_cache_mobile_prefixes && false === strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_prefixes ), ' ' ) ) ) || + ( '' != $wp_cache_mobile_browsers && false === strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) ) ) ) + ) { ?> -

-

- -

  1. +
    +

    +

    + +

      +
    1. Update Mod_Rewrite Rules button.', 'wp-super-cache' ); ?>
    2. -
    3. # BEGIN WPSuperCache and # END WPSuperCache and let the plugin regenerate them by reloading this page.', 'wp-super-cache' ), $home_path ); ?>
    4. -
    5. # BEGIN WPSuperCache and # END WPSuperCache. There are two sections that look very similar. Just below the line %%{HTTP:Cookie} !^.*(comment_author_|%s|wp-postpass_).*$ add these lines: (do it twice, once for each section)', 'wp-super-cache' ), $home_path, wpsc_get_logged_in_cookie() ); ?>

      -
    # BEGIN WPSuperCache and # END WPSuperCache and let the plugin regenerate them by reloading this page.', 'wp-super-cache' ), esc_attr( $home_path ) ); ?> +
  2. # BEGIN WPSuperCache and # END WPSuperCache. There are two sections that look very similar. Just below the line %%{HTTP:Cookie} !^.*(comment_author_|%s|wp-postpass_).*$ add these lines: (do it twice, once for each section)', 'wp-super-cache' ), esc_attr( $home_path ), wpsc_get_logged_in_cookie() ); ?> +
  3. +
+
+