diff --git a/.travis.yml b/.travis.yml index 3274cf4..57b0368 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ jobs: include: - php: 7.3 env: WP_VERSION=latest WP_MULTISITE=1 WPSNIFF=1 - - php: 8.1 + - php: 8.2 env: WP_VERSION=latest WP_MULTISITE=1 WPSNIFF=1 - php: 8.0 env: WP_VERSION=5.9 WP_MULTISITE=0 diff --git a/aux-optimize.php b/aux-optimize.php index 6011406..b1e3199 100644 --- a/aux-optimize.php +++ b/aux-optimize.php @@ -25,11 +25,10 @@ function ewww_image_optimizer_aux_images() { ewwwio_debug_message( '' . __FUNCTION__ . '()' ); $output = ''; - global $eio_debug; if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) ) { ewwwio_debug_info(); echo '
'; - if ( ewwwio_is_file( EWWWIO_CONTENT_DIR . 'debug.log' ) ) { + if ( ewwwio_is_file( ewwwio()->debug_log_path() ) ) { ?>

@@ -43,7 +42,7 @@ function ewww_image_optimizer_aux_images() { echo '

'; echo '
' . wp_kses( - $eio_debug, + EWWW\Base::$debug_data, array( 'br' => array(), 'b' => array(), @@ -51,16 +50,14 @@ function ewww_image_optimizer_aux_images() { ) . '
'; } else { - ewww_image_optimizer_set_option( 'ewww_image_optimizer_debug', true ); ewwwio_debug_info(); - ewww_image_optimizer_set_option( 'ewww_image_optimizer_debug', false ); } if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_enable_help' ) ) { $current_user = wp_get_current_user(); $help_email = $current_user->user_email; $hs_debug = ''; - if ( ! empty( $eio_debug ) ) { - $hs_debug = str_replace( array( "'", '
', '', '', '=>' ), array( "\'", '\n', '**', '**', '=' ), $eio_debug ); + if ( ! empty( EWWW\Base::$debug_data ) ) { + $hs_debug = str_replace( array( "'", '
', '', '', '=>' ), array( "\'", '\n', '**', '**', '=' ), EWWW\Base::$debug_data ); } ?> @@ -68,13 +65,12 @@ function ewww_image_optimizer_aux_images() { window.Beacon('init', 'aa9c3d3b-d4bc-4e9b-b6cb-f11c9f69da87'); Beacon( 'prefill', { email: '', - text: '\n\n----------------------------------------\n', + text: '\n\n---------------------------------------\n', }); temp_debug_end(); } /** diff --git a/bulk.php b/bulk.php index ca944e1..b4f58ec 100644 --- a/bulk.php +++ b/bulk.php @@ -2162,10 +2162,9 @@ function ewww_image_optimizer_bulk_loop( $hook = '', $delay = 0 ) { $output['results'] .= sprintf( '

' . esc_html( _n( 'Elapsed: %s second', 'Elapsed: %s seconds', $elapsed, 'ewww-image-optimizer' ) ) . '

', number_format_i18n( $elapsed, 1 ) ); // Store the updated list of attachment IDs back in the 'bulk_attachments' option. if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) ) { - global $eio_debug; $debug_button = esc_html__( 'Show Debug Output', 'ewww-image-optimizer' ); $debug_id = uniqid(); - $output['results'] .= ""; + $output['results'] .= "'; } if ( ! empty( $next_image->file ) ) { $next_file = esc_html( $next_image->file ); diff --git a/classes/class-background-process-image.php b/classes/class-background-process-image.php index 17a6e74..9197b61 100644 --- a/classes/class-background-process-image.php +++ b/classes/class-background-process-image.php @@ -1,6 +1,6 @@ get_option( $this->prefix . 'debug' ) + ) { + self::$temp_debug = true; + } $this->debug_message( '' . __METHOD__ . '()' ); $this->debug_message( "plugin (resource) content_url: $this->content_url" ); $this->debug_message( "plugin (resource) content_dir: $this->content_dir" ); @@ -271,23 +298,34 @@ public function set_content_dir( $sub_folder ) { } /** - * Saves the in-memory debug log to a logfile in the plugin folder. + * Get the path to the current debug log, if one exists. Otherwise, generate a new filename. * - * @global string $eio_debug The in-memory debug log. + * @return string The full path to the debug log. + */ + public function debug_log_path() { + $potential_logs = \scandir( $this->content_dir ); + if ( $this->is_iterable( $potential_logs ) ) { + foreach ( $potential_logs as $potential_log ) { + if ( $this->str_ends_with( $potential_log, '.log' ) && false !== strpos( $potential_log, strtolower( __NAMESPACE__ ) . '-debug-' ) && is_file( $this->content_dir . $potential_log ) ) { + return $this->content_dir . $potential_log; + } + } + } + return $this->content_dir . strtolower( __NAMESPACE__ ) . '-debug-' . uniqid() . '.log'; + } + + /** + * Saves the in-memory debug log to a logfile in the plugin folder. */ public function debug_log() { - global $eio_debug; - global $ewwwio_temp_debug; - global $easyio_temp_debug; - $debug_log = $this->content_dir . 'debug.log'; + $debug_log = $this->debug_log_path(); if ( ! \is_dir( $this->content_dir ) && \is_writable( WP_CONTENT_DIR ) ) { \wp_mkdir_p( $this->content_dir ); } - $debug_enabled = $this->get_option( $this->prefix . 'debug' ); if ( - ! empty( $eio_debug ) && - empty( $easyio_temp_debug ) && - $debug_enabled && + ! empty( self::$debug_data ) && + empty( self::$temp_debug ) && + $this->get_option( $this->prefix . 'debug' ) && \is_dir( $this->content_dir ) && \is_writable( $this->content_dir ) ) { @@ -299,24 +337,22 @@ public function debug_log() { } else { if ( \filesize( $debug_log ) + 4000000 + \memory_get_usage( true ) > $memory_limit ) { \unlink( $debug_log ); + \clearstatcache(); + $debug_log = $this->debug_log_path(); \touch( $debug_log ); } } - if ( \filesize( $debug_log ) + \strlen( $eio_debug ) + 4000000 + \memory_get_usage( true ) <= $memory_limit && \is_writable( $debug_log ) ) { - $eio_debug = \str_replace( '
', "\n", $eio_debug ); - \file_put_contents( $debug_log, $timestamp . $eio_debug, FILE_APPEND ); + if ( \filesize( $debug_log ) + \strlen( self::$debug_data ) + 4000000 + \memory_get_usage( true ) <= $memory_limit && \is_writable( $debug_log ) ) { + self::$debug_data = \str_replace( '
', "\n", self::$debug_data ); + \file_put_contents( $debug_log, $timestamp . self::$debug_data, FILE_APPEND ); } } - $eio_debug = ''; + self::$debug_data = ''; } /** * Adds information to the in-memory debug log. * - * @global string $eio_debug The in-memory debug log. - * @global bool $easyio_temp_debug Indicator that we are temporarily debugging on the wp-admin. - * @global bool $ewwwio_temp_debug Indicator that we are temporarily debugging on the wp-admin. - * * @param string $message Debug information to add to the log. */ public function debug_message( $message ) { @@ -339,23 +375,29 @@ public function debug_message( $message ) { \WP_CLI::debug( $message ); return; } - global $ewwwio_temp_debug; - global $easyio_temp_debug; - if ( $easyio_temp_debug || $ewwwio_temp_debug || $this->get_option( $this->prefix . 'debug' ) ) { + if ( self::$temp_debug || $this->get_option( $this->prefix . 'debug' ) ) { $memory_limit = $this->memory_limit(); if ( \strlen( $message ) + 4000000 + \memory_get_usage( true ) <= $memory_limit ) { - global $eio_debug; - $message = \str_replace( "\n\n\n", '
', $message ); - $message = \str_replace( "\n\n", '
', $message ); - $message = \str_replace( "\n", '
', $message ); - $eio_debug .= "$message
"; + $message = \str_replace( "\n\n\n", '
', $message ); + $message = \str_replace( "\n\n", '
', $message ); + $message = \str_replace( "\n", '
', $message ); + self::$debug_data .= "$message
"; } else { - global $eio_debug; - $eio_debug = "not logging message, memory limit is $memory_limit"; + self::$debug_data = "not logging message, memory limit is $memory_limit"; } } } + /** + * Clears temp debugging mode and flushes the debug data if needed. + */ + public function temp_debug_end() { + if ( ! $this->get_option( $this->prefix . 'debug' ) ) { + self::$debug_data = ''; + } + self::$temp_debug = false; + } + /** * Escape any spaces in the filename. * diff --git a/classes/class-ewww-nextgen.php b/classes/class-ewww-nextgen.php index 5261ac2..72cfd96 100644 --- a/classes/class-ewww-nextgen.php +++ b/classes/class-ewww-nextgen.php @@ -628,8 +628,6 @@ public function ewww_manage_images_row_actions( $actions ) { /** * Output the html for the bulk optimize page. - * - * @global string $eio_debug In-memory debug log. */ public function ewww_ngg_bulk_preview() { if ( ! empty( $_REQUEST['doaction'] ) ) { @@ -738,9 +736,8 @@ public function ewww_ngg_bulk_preview() { } echo ''; if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) ) { - global $eio_debug; echo '
'; - echo '

' . esc_html__( 'Debugging Information', 'ewww-image-optimizer' ) . ':

' . wp_kses_post( $eio_debug ) . '
'; + echo '

' . esc_html__( 'Debugging Information', 'ewww-image-optimizer' ) . ':

' . wp_kses_post( EWWW\Base::$debug_data ) . '
'; } echo ''; } diff --git a/common.php b/common.php index 7f61861..e9f03ab 100644 --- a/common.php +++ b/common.php @@ -721,14 +721,6 @@ function ewww_image_optimizer_save_network_settings() { */ function ewww_image_optimizer_init() { ewwwio_debug_message( '' . __FUNCTION__ . '()' ); - // Check to see if this is the settings page and enable debugging temporarily if it is. - global $ewwwio_temp_debug; - $ewwwio_temp_debug = ! empty( $ewwwio_temp_debug ) ? $ewwwio_temp_debug : false; - if ( is_admin() && ! wp_doing_ajax() ) { - if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) ) { - $ewwwio_temp_debug = true; - } - } // For the settings page, check for the enable-local param and take appropriate action. if ( ! empty( $_GET['enable-local'] ) && ! empty( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'ewww_image_optimizer_options-options' ) ) { @@ -905,6 +897,9 @@ function ewww_image_optimizer_upgrade() { add_option( 'ewww_image_optimizer_wizard_complete', true, '', false ); add_site_option( 'ewww_image_optimizer_wizard_complete', true ); } + if ( is_file( EWWWIO_CONTENT_DIR . 'debug.log' ) && is_writable( EWWWIO_CONTENT_DIR . 'debug.log' ) ) { + unlink( EWWWIO_CONTENT_DIR . 'debug.log' ); + } ewww_image_optimizer_remove_obsolete_settings(); update_option( 'ewww_image_optimizer_version', EWWW_IMAGE_OPTIMIZER_VERSION ); } @@ -1110,14 +1105,18 @@ function ewww_image_optimizer_privacy_policy_content() { * @param object $screen Information about the page/screen currently being loaded. */ function ewww_image_optimizer_current_screen( $screen ) { - global $ewwwio_temp_debug; - global $eio_debug; - if ( false === strpos( $screen->id, 'settings_page_ewww-image-optimizer' ) && false === strpos( $screen->id, 'settings_page_easy-image-optimizer' ) ) { - $ewwwio_temp_debug = false; - if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) ) { - $eio_debug = ''; - } + if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) ) { + return; + } + ewwwio_debug_message( 'current screen: ' . $screen->id ); + if ( false !== strpos( $screen->id, 'settings_page_ewww-image-optimizer' ) ) { + return; } + if ( false !== strpos( $screen->id, 'media_page_ewww-image-optimizer-bulk' ) ) { + return; + } + EWWW\Base::$debug_data = ''; + EWWW\Base::$temp_debug = false; } /** @@ -6384,7 +6383,6 @@ function ewww_image_optimizer_size_format( $size, $precision = 1 ) { * @global object $wpdb * @global object $ewwwdb A clone of $wpdb unless it is lacking utf8 connectivity. * @global bool $ewww_defer Set to false to avoid deferring image optimization. - * @global string $eio_debug Contains in-memory debug log. * @global object $ewww_image Contains more information about the image currently being processed. * * @param array $attachment { @@ -6498,8 +6496,7 @@ function ewww_image_optimizer_aux_images_loop( $attachment = null, $auto = false number_format_i18n( $elapsed, 2 ) ); if ( get_site_option( 'ewww_image_optimizer_debug' ) ) { - global $eio_debug; - $output['results'] .= '
' . $eio_debug . '
'; + $output['results'] .= '
' . EWWW\Base::$debug_data . '
'; } $next_file = ewww_image_optimizer_absolutize_path( $wpdb->get_var( "SELECT path FROM $wpdb->ewwwio_images WHERE pending=1 LIMIT 1" ) ); if ( ! empty( $next_file ) ) { @@ -11365,11 +11362,8 @@ function ewww_image_optimizer_intro_wizard() { ewww_image_optimizer_set_option( 'ewww_image_optimizer_backup_files', 'cloud' ); } update_option( 'ewww_image_optimizer_wizard_complete', true, false ); - global $eio_debug; - $debug_info = ''; - if ( ! empty( $eio_debug ) ) { - $debug_info = $eio_debug; - } + $debug_info = EWWW\Base::$debug_data; + ewwwio()->temp_debug_end(); } wp_add_inline_script( 'ewww-settings-script', @@ -11656,7 +11650,7 @@ function ewww_image_optimizer_intro_wizard() { window.Beacon('init', 'aa9c3d3b-d4bc-4e9b-b6cb-f11c9f69da87'); Beacon( 'prefill', { email: '', - text: '\n\n----------------------------------------\n', + text: '\n\n---------------------------------------\n', }); temp_debug_end(); ?>
@@ -11764,7 +11755,7 @@ function ewww_image_optimizer_rescue_mode() { window.Beacon('init', 'aa9c3d3b-d4bc-4e9b-b6cb-f11c9f69da87'); Beacon( 'prefill', { email: '', - text: '\n\n----------------------------------------\n', + text: '\n\n---------------------------------------\n', }); ' . __FUNCTION__ . '()' ); - global $ewwwio_temp_debug; global $ewwwio_upgrading; - global $eio_debug; global $exactdn; global $eio_alt_webp; global $wpdb; @@ -11816,8 +11804,7 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) { } ewwwio_debug_info(); - $debug_info = $eio_debug; - ewww_image_optimizer_temp_debug_clear(); + $debug_info = EWWW\Base::$debug_data; $exactdn_sub_folder = false; if ( is_multisite() && is_network_admin() ) { @@ -11874,6 +11861,7 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) { ewww_image_optimizer_rescue_mode(); return; } + ewwwio()->temp_debug_end(); ewwwio()->hs_beacon->admin_notice( $network ); ?> @@ -12442,6 +12430,31 @@ class_exists( 'EWWW\ExactDN' ) && $premium_hide = ' style="display:none"'; } ?> + + + +

+ + + + +

+ + + +

+ +

+ + + +

+ + +

+ + + @@ -13132,29 +13145,6 @@ class_exists( 'EWWW\ExactDN' ) && - - - -

- - - -

- - -

- -

- - - -

- - -

- - -
@@ -13746,7 +13736,7 @@ class_exists( 'EWWW\ExactDN' ) && - + debug_log_path() ) ) : ?> @@ -13833,13 +13823,12 @@ class_exists( 'EWWW\ExactDN' ) && window.Beacon('init', 'aa9c3d3b-d4bc-4e9b-b6cb-f11c9f69da87'); Beacon( 'prefill', { email: '', - text: '\n\n----------------------------------------\n', + text: '\n\n---------------------------------------\n', }); debug_log_path(); if ( ewwwio_is_file( $debug_log ) ) { ewwwio_ob_clean(); header( 'Content-Type: text/plain;charset=UTF-8' ); @@ -14206,13 +14195,13 @@ function ewww_image_optimizer_view_debug_log() { } /** - * Removes the debug.log file from the plugin folder. + * Removes the debug log file. */ function ewww_image_optimizer_delete_debug_log() { if ( ! current_user_can( apply_filters( 'ewww_image_optimizer_admin_permissions', '' ) ) ) { wp_die( esc_html__( 'Access denied.', 'ewww-image-optimizer' ) ); } - $debug_log = EWWWIO_CONTENT_DIR . 'debug.log'; + $debug_log = ewwwio()->debug_log_path(); if ( ewwwio_is_file( $debug_log ) && is_writable( $debug_log ) ) { unlink( $debug_log ); } @@ -14225,13 +14214,13 @@ function ewww_image_optimizer_delete_debug_log() { } /** - * Download the debug.log file from the wp-admin. + * Download the debug log file from the wp-admin. */ function ewww_image_optimizer_download_debug_log() { if ( ! current_user_can( apply_filters( 'ewww_image_optimizer_admin_permissions', '' ) ) ) { wp_die( esc_html__( 'Access denied.', 'ewww-image-optimizer' ) ); } - $debug_log = EWWWIO_CONTENT_DIR . 'debug.log'; + $debug_log = ewwwio()->debug_log_path(); if ( ewwwio_is_file( $debug_log ) ) { ewwwio_ob_clean(); header( 'Content-Description: File Transfer' ); @@ -14250,11 +14239,10 @@ function ewww_image_optimizer_download_debug_log() { /** * Adds version information to the in-memory debug log. * - * @global string $eio_debug The in-memory debug log. * @global int $wp_version */ function ewwwio_debug_version_info() { - global $eio_debug; + $eio_debug = ''; if ( ! extension_loaded( 'suhosin' ) && function_exists( 'get_current_user' ) ) { $eio_debug .= get_current_user() . '
'; } @@ -14278,6 +14266,8 @@ function ewwwio_debug_version_info() { } } $eio_debug .= 'core plugin
'; + + EWWW\Base::$debug_data .= $eio_debug; } /** @@ -14296,18 +14286,6 @@ function ewwwio_debug_backtrace() { return maybe_serialize( $backtrace ); } -/** - * Make sure to clear temp debug option on shutdown. - */ -function ewww_image_optimizer_temp_debug_clear() { - global $ewwwio_temp_debug; - global $eio_debug; - if ( $ewwwio_temp_debug ) { - $eio_debug = ''; - } - $ewwwio_temp_debug = false; -} - /** * Finds the current PHP memory limit or a reasonable default. * diff --git a/ewww-image-optimizer.php b/ewww-image-optimizer.php index b877e1c..d3b7ad3 100644 --- a/ewww-image-optimizer.php +++ b/ewww-image-optimizer.php @@ -34,9 +34,8 @@ add_action( 'admin_notices', 'ewww_image_optimizer_dual_plugin' ); } elseif ( false === strpos( add_query_arg( '', '' ), 'ewwwio_disable=1' ) ) { - define( 'EWWW_IMAGE_OPTIMIZER_VERSION', 720.11 ); - // Initialize a couple globals. - $eio_debug = ''; + define( 'EWWW_IMAGE_OPTIMIZER_VERSION', 720.12 ); + // Initialize a global. $ewww_defer = true; if ( WP_DEBUG && function_exists( 'memory_get_usage' ) ) { diff --git a/readme.txt b/readme.txt index 472e51b..751c7a1 100644 --- a/readme.txt +++ b/readme.txt @@ -138,8 +138,10 @@ That's not a question, but since I made it up, I'll answer it. See this resource * If you would like to help translate this plugin in your language, [join the team](https://translate.wordpress.org/projects/wp-plugins/ewww-image-optimizer/) = 7.2.1 = +* changed: Scheduled Optimizer skips image errors faster * changed: use updated coding standards, and restructure code for async/background functions * removed: legacy image editor extensions for unmaintained plugins +* security: randomize filename of debug log = 7.2.0 = * added: Easy IO rewrites poster/thumbnail image URLs for video elements diff --git a/tests/test-utility.php b/tests/test-utility.php index 384948a..4513fb5 100644 --- a/tests/test-utility.php +++ b/tests/test-utility.php @@ -39,15 +39,13 @@ function test_sha256sum() { */ function test_mimetype() { $binaries = scandir( EWWW_IMAGE_OPTIMIZER_BINARY_PATH ); - global $eio_debug; - $eio_debug .= ''; ewww_image_optimizer_set_option( 'ewww_image_optimizer_debug', true ); foreach ( $binaries as $binary ) { $binary = trailingslashit( EWWW_IMAGE_OPTIMIZER_BINARY_PATH ) . $binary; if ( ! ewwwio_is_file( $binary ) ) { continue; } - $this->assertTrue( (bool) ewwwio()->mimetype( $binary, 'b' ), $binary . ":\n" . str_replace( '
', "\n", $eio_debug ) ); + $this->assertTrue( (bool) ewwwio()->mimetype( $binary, 'b' ), $binary . ":\n" . str_replace( '
', "\n", EWWW\Base::$debug_data ) ); } }