From 8384403af18b4a7e4cd11f8957010fb3b2901e6a Mon Sep 17 00:00:00 2001 From: Lai Power Date: Fri, 19 Aug 2022 16:16:01 +0000 Subject: [PATCH] updated plugin `Companion Auto Update` version 3.8.6 --- .../companion-auto-update/admin/dashboard.php | 134 ++- .../companion-auto-update/cau_emails.php | 1049 ++++++++--------- .../companion-auto-update/cau_functions.php | 35 +- .../companion-auto-update.php | 4 +- .../plugins/companion-auto-update/readme.txt | 14 +- 5 files changed, 627 insertions(+), 609 deletions(-) diff --git a/wp-content/plugins/companion-auto-update/admin/dashboard.php b/wp-content/plugins/companion-auto-update/admin/dashboard.php index fe61d0fa..4bb68d1b 100644 --- a/wp-content/plugins/companion-auto-update/admin/dashboard.php +++ b/wp-content/plugins/companion-auto-update/admin/dashboard.php @@ -26,10 +26,10 @@ if( isset( $_POST['submit'] ) ) { $table_name = $wpdb->prefix . "auto_updates"; // Auto updater - $plugins = isset( $_POST['plugins'] ) ? sanitize_text_field( $_POST['plugins'] ) : ''; - $themes = isset( $_POST['themes'] ) ? sanitize_text_field( $_POST['themes'] ) : ''; - $minor = isset( $_POST['minor'] ) ? sanitize_text_field( $_POST['minor'] ) : ''; - $major = isset( $_POST['major'] ) ? sanitize_text_field( $_POST['major'] ) : ''; + $plugins = isset( $_POST['plugins'] ) ? sanitize_text_field( $_POST['plugins'] ) : ''; + $themes = isset( $_POST['themes'] ) ? sanitize_text_field( $_POST['themes'] ) : ''; + $minor = isset( $_POST['minor'] ) ? sanitize_text_field( $_POST['minor'] ) : ''; + $major = isset( $_POST['major'] ) ? sanitize_text_field( $_POST['major'] ) : ''; $translations = isset( $_POST['translations'] ) ? sanitize_text_field( $_POST['translations'] ) : ''; $wpdb->query( $wpdb->prepare( "UPDATE $table_name SET onoroff = %s WHERE name = 'plugins'", $plugins ) ); @@ -39,11 +39,11 @@ if( isset( $_POST['submit'] ) ) { $wpdb->query( $wpdb->prepare( "UPDATE $table_name SET onoroff = %s WHERE name = 'translations'", $translations ) ); // Emails - $send = isset( $_POST['cau_send'] ) ? sanitize_text_field( $_POST['cau_send'] ) : ''; + $send = isset( $_POST['cau_send'] ) ? sanitize_text_field( $_POST['cau_send'] ) : ''; $sendupdate = isset( $_POST['cau_send_update'] ) ? sanitize_text_field( $_POST['cau_send_update'] ) : ''; $sendoutdated = isset( $_POST['cau_send_outdated'] ) ? sanitize_text_field( $_POST['cau_send_outdated'] ) : ''; - $wpemails = isset( $_POST['wpemails'] ) ? sanitize_text_field( $_POST['wpemails'] ) : ''; - $email = isset( $_POST['cau_email'] ) ? sanitize_text_field( $_POST['cau_email'] ) : ''; + $wpemails = isset( $_POST['wpemails'] ) ? sanitize_text_field( $_POST['wpemails'] ) : ''; + $email = isset( $_POST['cau_email'] ) ? sanitize_text_field( $_POST['cau_email'] ) : ''; $html_or_text = isset( $_POST['html_or_text'] ) ? sanitize_text_field( $_POST['html_or_text'] ) : 'html'; $dbupdateemails = isset( $_POST['dbupdateemails'] ) ? sanitize_text_field( $_POST['dbupdateemails'] ) : ''; @@ -56,8 +56,8 @@ if( isset( $_POST['submit'] ) ) { $wpdb->query( $wpdb->prepare( "UPDATE $table_name SET onoroff = %s WHERE name = 'dbupdateemails'", $dbupdateemails ) ); // Advanced - $allow_editor = isset( $_POST['allow_editor'] ) ? sanitize_text_field( $_POST['allow_editor'] ) : ''; - $allow_author = isset( $_POST['allow_author'] ) ? sanitize_text_field( $_POST['allow_author'] ) : ''; + $allow_editor = isset( $_POST['allow_editor'] ) ? sanitize_text_field( $_POST['allow_editor'] ) : ''; + $allow_author = isset( $_POST['allow_author'] ) ? sanitize_text_field( $_POST['allow_author'] ) : ''; $advanced_info_emails = isset( $_POST['advanced_info_emails'] ) ? sanitize_text_field( $_POST['advanced_info_emails'] ) : ''; $plugin_links_emails = isset( $_POST['plugin_links_emails'] ) ? sanitize_text_field( $_POST['plugin_links_emails'] ) : ''; @@ -76,21 +76,21 @@ if( isset( $_POST['submit'] ) ) { // Intervals // Set variables - $plugin_sc = sanitize_text_field( $_POST['plugin_schedule'] ); - $theme_sc = sanitize_text_field( $_POST['theme_schedule'] ); - $core_sc = sanitize_text_field( $_POST['core_schedule'] ); + $plugin_sc = sanitize_text_field( $_POST['plugin_schedule'] ); + $theme_sc = sanitize_text_field( $_POST['theme_schedule'] ); + $core_sc = sanitize_text_field( $_POST['core_schedule'] ); $schedule_mail = sanitize_text_field( $_POST['update_notifications'] ); $outdated_notifier = sanitize_text_field( $_POST['outdated_notifier'] ); // First clear schedules - wp_clear_scheduled_hook('wp_update_plugins'); - wp_clear_scheduled_hook('wp_update_themes'); - wp_clear_scheduled_hook('wp_version_check'); - wp_clear_scheduled_hook('cau_set_schedule_mail'); - wp_clear_scheduled_hook('cau_custom_hooks_plugins'); - wp_clear_scheduled_hook('cau_custom_hooks_themes'); - wp_clear_scheduled_hook('cau_log_updater'); - wp_clear_scheduled_hook('cau_outdated_notifier'); + wp_clear_scheduled_hook( 'wp_update_plugins' ); + wp_clear_scheduled_hook( 'wp_update_themes' ); + wp_clear_scheduled_hook( 'wp_version_check' ); + wp_clear_scheduled_hook( 'cau_set_schedule_mail' ); + wp_clear_scheduled_hook( 'cau_custom_hooks_plugins' ); + wp_clear_scheduled_hook( 'cau_custom_hooks_themes' ); + wp_clear_scheduled_hook( 'cau_log_updater' ); + wp_clear_scheduled_hook( 'cau_outdated_notifier' ); // Then set the new times @@ -109,11 +109,9 @@ if( isset( $_POST['submit'] ) ) { wp_schedule_event( ( $pluginSetTime - 1800 ), $plugin_sc, 'cau_log_updater' ); } else { - wp_schedule_event( time(), $plugin_sc, 'wp_update_plugins' ); wp_schedule_event( time(), $plugin_sc, 'cau_custom_hooks_plugins' ); wp_schedule_event( ( time() - 1800 ), $plugin_sc, 'cau_log_updater' ); - } // Themes @@ -130,10 +128,8 @@ if( isset( $_POST['submit'] ) ) { wp_schedule_event( $themeSetTime, $theme_sc, 'cau_custom_hooks_themes' ); } else { - wp_schedule_event( time(), $theme_sc, 'wp_update_themes' ); wp_schedule_event( time(), $theme_sc, 'cau_custom_hooks_themes' ); - } // Core @@ -149,9 +145,7 @@ if( isset( $_POST['submit'] ) ) { wp_schedule_event( $coreSetTime, $core_sc, 'wp_version_check' ); } else { - wp_schedule_event( time(), $core_sc, 'wp_version_check' ); - } // Update notifications @@ -167,9 +161,7 @@ if( isset( $_POST['submit'] ) ) { wp_schedule_event( $emailSetTime, $schedule_mail, 'cau_set_schedule_mail' ); } else { - wp_schedule_event( time(), $schedule_mail, 'cau_set_schedule_mail' ); - } // Outdated notifications @@ -185,9 +177,7 @@ if( isset( $_POST['submit'] ) ) { wp_schedule_event( $emailSetTime, $outdated_notifier, 'cau_outdated_notifier' ); } else { - wp_schedule_event( time(), $outdated_notifier, 'cau_outdated_notifier' ); - } @@ -195,26 +185,26 @@ if( isset( $_POST['submit'] ) ) { } +// Welcome screen for first time viewers if( isset( $_GET['welcome'] ) ) { - echo '
-

'.__( 'Welcome to Companion Auto Update', 'companion-auto-update' ).'

-
-

'.__( 'You\'re set and ready to go', 'companion-auto-update' ).'

-

'.__( 'The plugin is all set and ready to go with the recommended settings, but if you\'d like you can change them below.' ).'

-
-

'.__( 'Get Started' ).': '.__( 'Update filter', 'companion-auto-update' ).'   |   - '.__( 'More Actions' ).': '.__('Give feedback', 'companion-auto-update').' - '.__( 'Help us translate', 'companion-auto-update' ).'

+

'.__( 'Welcome to Companion Auto Update', 'companion-auto-update' ).'

+
+

'.__( 'You\'re set and ready to go', 'companion-auto-update' ).'

+

'.__( 'The plugin is all set and ready to go with the recommended settings, but if you\'d like you can change them below.' ).'

+
+

'.__( 'Get Started' ).': '.__( 'Update filter', 'companion-auto-update' ).'   |   + '.__( 'More Actions' ).': '.__('Give feedback', 'companion-auto-update').' - '.__( 'Help us translate', 'companion-auto-update' ).'

'; } -$cs_hooks_p = wp_get_schedule( 'cau_custom_hooks_plugins' ); -$cs_hooks_t = wp_get_schedule( 'cau_custom_hooks_themes' ); +$cs_hooks_p = wp_get_schedule( 'cau_custom_hooks_plugins' ); +$cs_hooks_t = wp_get_schedule( 'cau_custom_hooks_themes' ); ?> @@ -233,25 +223,17 @@ $cs_hooks_t = wp_get_schedule( 'cau_custom_hooks_themes' );

'; + $plugins_on = ( cau_get_db_value( 'plugins' ) == 'on' ) ? "CHECKED" : ""; + $themes_on = ( cau_get_db_value( 'themes' ) == 'on' ) ? "CHECKED" : ""; + $minor_on = ( cau_get_db_value( 'minor' ) == 'on' ) ? "CHECKED" : ""; + $major_on = ( cau_get_db_value( 'major' ) == 'on' ) ? "CHECKED" : ""; + $translations_on = ( cau_get_db_value( 'translations' ) == 'on' ) ? "CHECKED" : ""; - echo '

'; - - echo '

'; - - echo '

'; - - echo '

'; + echo "

"; + echo "

"; + echo "

"; + echo "

"; + echo "

"; ?> @@ -267,8 +249,12 @@ $cs_hooks_t = wp_get_schedule( 'cau_custom_hooks_themes' );

@@ -281,7 +267,7 @@ $cs_hooks_t = wp_get_schedule( 'cau_custom_hooks_themes' );

/> - +

@@ -299,7 +285,7 @@ $cs_hooks_t = wp_get_schedule( 'cau_custom_hooks_themes' ); @@ -443,23 +429,35 @@ $cs_hooks_t = wp_get_schedule( 'cau_custom_hooks_themes' );

+ +

- +

@@ -310,8 +296,8 @@ $cs_hooks_t = wp_get_schedule( 'cau_custom_hooks_themes' );

- > + >

-

-

+

+

-

+

diff --git a/wp-content/plugins/companion-auto-update/cau_emails.php b/wp-content/plugins/companion-auto-update/cau_emails.php index f1f29f94..19634c88 100644 --- a/wp-content/plugins/companion-auto-update/cau_emails.php +++ b/wp-content/plugins/companion-auto-update/cau_emails.php @@ -1,525 +1,524 @@ - $version ) { - if( $version == '' ) $version = __( "Unknown", "companion-auto-update" ); - $text .= "- ".sprintf( esc_html__( "%s tested up to: %s", "companion-auto-update" ), $plugin, $version )."\n"; - } - - } - - return $text; - -} - -// Set the content for the emails about pending updates -function cau_pending_message( $single, $plural, $list ) { - - // What markup to use - if( cau_is_html() ) $break = '
'; - else $break = "\n"; - - // Base text - $text = sprintf( esc_html__( 'You have pending %1$s updates on your WordPress site at %2$s.', 'companion-auto-update' ), $single, get_site_url() ); - $text .= $break; - - if( !empty( $list ) ) { - - $text .= $break; - $text .= sprintf( esc_html__( 'The following %1$s have new versions available.', 'companion-auto-update' ), $plural ); - $text .= $break; - - if( cau_is_html() ) $text .= "
    "; - foreach ( $list as $key => $value ) { - if( cau_is_html() ) { - $text .= "
  1. $value
  2. "; - } else { - $text .= "-$value\n"; - } - } - if( cau_is_html() ) $text .= "
"; - - $text .= $break; - } - - $text .= __( 'Leaving your site outdated is a security risk so please consider manually updating them.', 'companion-auto-update' ); - $text .= $break; - - // End - $text .= sprintf( esc_html__( 'Head over to %1$s and check the ones you want to update.', 'companion-auto-update' ), get_admin_url().'update-core.php' ); - - return $text; - -} - -// Set the content for the emails about recent updates -function cau_updated_message( $type, $updatedList ) { - - // What markup to use - if( cau_is_html() ) $break = '
'; - else $break = "\n"; - - // The message - $text = sprintf( esc_html__( - 'One or more %1$s on your WordPress site at %2$s have been updated by Companion Auto Update. No further action is needed on your part. -For more info on what is new visit your dashboard and check the changelog.', 'companion-auto-update' - ), $type, get_site_url() ); - - $text .= $break; - $text .= $break; - $text .= sprintf( esc_html__( - 'The following %1$s have been updated:', 'companion-auto-update' - ), $type ); - - $text .= $break; - $text .= $updatedList; - - $text .= $break; - $text .= __( "(You'll also receive this email if you manually updated a plugin or theme)", "companion-auto-update" ); - - return $text; - -} - -// Checks if plugins are out of date -function cau_list_outdated_software() { - - // Check if cau_get_db_value() function exists. - if ( !function_exists( 'cau_get_db_value' ) ) require_once( plugin_dir_path( __FILE__ ) . 'cau_function.php' ); - - // Set up mail - $subject = '['.get_bloginfo( 'name' ).'] ' . __( 'You have outdated plugins on your site.', 'companion-auto-update' ); - $type = __( 'plugin', 'companion-auto-update' ); - $type_plural = __( 'plugins', 'companion-auto-update' ); - $message = cau_outdated_message( $type, $type_plural, cau_list_outdated() ); - - // Send to all addresses - foreach ( cau_set_email() as $key => $value ) { - foreach ( $value as $k => $v ) { - wp_mail( $v, $subject, $message ); - } - break; - } - -} - -// Checks if theme updates are available -function cau_list_theme_updates() { - - global $wpdb; - $table_name = $wpdb->prefix . "auto_updates"; - - $configs = $wpdb->get_results( "SELECT * FROM $table_name WHERE name = 'themes'"); - foreach ( $configs as $config ) { - - if( $config->onoroff != 'on' ) { - - require_once ABSPATH . '/wp-admin/includes/update.php'; - $themes = get_theme_updates(); - $list = array(); - - if ( !empty( $themes ) ) { - - foreach ( $themes as $stylesheet => $theme ) { - array_push( $list, $theme->get( 'Name' ) ); - } - - $subject = '[' . get_bloginfo( 'name' ) . '] ' . __( 'Theme update available.', 'companion-auto-update' ); - $type = __('theme', 'companion-auto-update'); - $type_plural = __('themes', 'companion-auto-update'); - $message = cau_pending_message( $type, $type_plural, $list ); - - foreach ( cau_set_email() as $key => $value) { - foreach ($value as $k => $v) { - wp_mail( $v, $subject, $message ); - } - break; - } - } - - } - - } - -} - -// Checks if plugin updates are available -function cau_list_plugin_updates() { - - global $wpdb; - $table_name = $wpdb->prefix . "auto_updates"; - - $configs = $wpdb->get_results( "SELECT * FROM $table_name WHERE name = 'plugins'"); - foreach ( $configs as $config ) { - - if( $config->onoroff != 'on' ) { - - require_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); - - if ( !function_exists( 'get_plugin_updates' ) ) require_once ABSPATH . 'wp-admin/includes/update.php'; - $plugins = get_plugin_updates(); - - if ( !empty( $plugins ) ) { - - $list = array(); - foreach ( (array) $plugins as $plugin_file => $plugin_data ) { - $plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file, (array) $plugin_data, false, true ); - $name = $plugin_data->Name; - array_push( $list, $name ); - } - - $subject = '[' . get_bloginfo( 'name' ) . '] ' . __( 'Plugin update available.', 'companion-auto-update' ); - $type = __( 'plugin', 'companion-auto-update' ); - $type_plural = __( 'plugins', 'companion-auto-update' ); - $message = cau_pending_message( $type, $type_plural, $list ); - - foreach ( cau_set_email() as $key => $value) { - foreach ($value as $k => $v) { - wp_mail( $v, $subject, $message ); - } - break; - } - } - - } - - } -} - -// Alerts when plugin has been updated -function cau_plugin_updated() { - - // Check if cau_get_db_value() function exists. - if ( !function_exists( 'cau_get_db_value' ) ) require_once( plugin_dir_path( __FILE__ ) . 'cau_function.php' ); - - // Set the correct timezone for emails - date_default_timezone_set( cau_get_proper_timezone() ); - - // Create arrays - $pluginNames = array(); - $pluginDates = array(); - $pluginVersion = array(); - $pluginSlug = array(); - $pluginTimes = array(); - $themeNames = array(); - $themeDates = array(); - $themeTimes = array(); - - // Where to look for plugins - $plugdir = plugin_dir_path( __DIR__ ); - if ( !function_exists( 'get_plugins' ) ) require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Check if get_plugins() function exists. - $allPlugins = get_plugins(); - - // Where to look for themes - $themedir = get_theme_root(); - $allThemes = wp_get_themes(); - - // Mail schedule - $schedule_mail = wp_get_schedule( 'cau_set_schedule_mail' ); - - // Loop trough all plugins - foreach ( $allPlugins as $key => $value ) { - - // Get plugin data - $fullPath = $plugdir.'/'.$key; - $getFile = $path_parts = pathinfo( $fullPath ); - $pluginData = get_plugin_data( $fullPath ); - - // Get the slug - $explosion = explode( '/', $key ); - $actualSlug = array_shift( $explosion ); - - // Get last update date - $fileDate = date ( 'YmdHi', filemtime( $fullPath ) ); - - switch ( $schedule_mail ) { - case 'hourly': - $lastday = date( 'YmdHi', strtotime( '-1 hour', time() ) ); - break; - case 'twicedaily': - $lastday = date( 'YmdHi', strtotime( '-12 hours', time() ) ); - break; - default: - $lastday = date( 'YmdHi', strtotime( '-1 day', time() ) ); - break; - } - - $dateFormat = get_option( 'date_format' ); - $timestamp = date_i18n( $dateFormat, filemtime( $fullPath ) ); - $timestamp .= ' - '.date( 'H:i', filemtime( $fullPath ) ); - - if( $fileDate >= $lastday ) { - - // Get plugin name - foreach ( $pluginData as $dataKey => $dataValue ) { - if( $dataKey == 'Name') { - array_push( $pluginNames , $dataValue ); - } - if( $dataKey == 'Version') { - array_push( $pluginVersion , $dataValue ); - } - } - - array_push( $pluginDates, $fileDate ); - array_push( $pluginSlug, $actualSlug ); - array_push( $pluginTimes, $timestamp ); - } - - } - - // Loop trough all themes - foreach ( $allThemes as $key => $value ) { - - // Get theme data - $fullPath = $themedir.'/'.$key; - $getFile = $path_parts = pathinfo( $fullPath ); - - // Get last update date - $dateFormat = get_option( 'date_format' ); - $fileDate = date ( 'YmdHi', filemtime( $fullPath ) ); - - if( $schedule_mail == 'hourly' ) { - $lastday = date( 'YmdHi', strtotime( '-1 hour', time() ) ); - } elseif( $schedule_mail == 'twicedaily' ) { - $lastday = date( 'YmdHi', strtotime( '-12 hours', time() ) ); - } elseif( $schedule_mail == 'daily' ) { - $lastday = date( 'YmdHi', strtotime( '-1 day', time() ) ); - } - - $dateFormat = get_option( 'date_format' ); - $timestamp = date_i18n( $dateFormat, filemtime( $fullPath ) ); - $timestamp .= ' - '.date( 'H:i', filemtime( $fullPath ) ); - - if( $fileDate >= $lastday ) { - array_push( $themeNames, $path_parts['filename'] ); - array_push( $themeDates, $fileDate ); - array_push( $themeTimes, $timestamp ); - } - - } - - $totalNumP = 0; - $totalNumT = 0; - $updatedListP = ''; - $updatedListT = ''; - - if( cau_get_db_value( 'html_or_text' ) == 'html' ) { - $updatedListP .= '
    '; - $updatedListT .= '
      '; - } - - foreach ( $pluginDates as $key => $value ) { - - // Set up some var - $plugin_name = $pluginNames[$key]; - $plugin_slug = $pluginSlug[$key]; - $to_version = __( "to version", "companion-auto-update" ).' '.$pluginVersion[$key]; - $more_info_arr = array( __( "Time of update", "companion-auto-update" ) => $pluginTimes[$key] ); - - // Plugin links - if( cau_get_db_value( 'plugin_links_emails' ) == 'on' ) { - $more_info_arr[__( "Plugin details", "companion-auto-update" )] = "".__( "Visit", "companion-auto-update" ).""; - $more_info_arr[__( "Release notes", "companion-auto-update" )] = "".__( "Visit", "companion-auto-update" ).""; - $more_info_arr[__( "Support", "companion-auto-update" )] = "".__( "Visit", "companion-auto-update" ).""; - } - - // Email format - $use_html = ( cau_get_db_value( 'html_or_text' ) == 'html' ) ? true : false; - - // Email content - $updatedListP .= $use_html ? "
    1. " : "-"; // Start row - - $updatedListP .= $use_html ? "{$plugin_name} " : "{$plugin_name} "; // Show plugin name - $updatedListP .= $to_version; // To version - - // Get advanced info - if( cau_get_db_value( 'advanced_info_emails' ) == 'on' ) { - foreach( $more_info_arr as $label => $value ) { - $updatedListP .= $use_html ? "
      {$label}: {$value}" : "\n{$label}: {$value}"; - } - } - - $updatedListP .= $use_html ? "
    2. " : "\n"; // End row - - $totalNumP++; - } - - foreach ( $themeNames as $key => $value ) { - - if( cau_get_db_value( 'html_or_text' ) == 'html' ) { - - $more_info = ''; - if( cau_get_db_value( 'advanced_info_emails' ) == 'on' ) $more_info = "
      ".__( "Time of update", "companion-auto-update" ).": ".$themeTimes[$key].""; - $updatedListT .= "
    3. ".$themeNames[$key]."".$more_info."
    4. "; - - } else { - $updatedListT .= "- ".$themeNames[$key]."\n"; - } - - $totalNumT++; - } - - if( cau_get_db_value( 'html_or_text' ) == 'html' ) { - $updatedListP .= '
    '; - $updatedListT .= '
'; - } - - // Set the email content type - if( cau_get_db_value( 'html_or_text' ) == 'html' ) { - function cau_mail_content_type() { - return 'text/html'; - } - add_filter( 'wp_mail_content_type', 'cau_mail_content_type' ); - } - - // If plugins have been updated, send email - if( $totalNumP > 0 ) { - - // E-mail content - $subject = '[' . get_bloginfo( 'name' ) . '] ' . __('One or more plugins have been updated.', 'companion-auto-update'); - $type = __('plugins', 'companion-auto-update'); - $message = cau_updated_message( $type, $updatedListP ); - - // Send to all addresses - foreach ( cau_set_email() as $key => $value) { - foreach ($value as $k => $v) { - wp_mail( $v, $subject, $message ); - } - break; - } - - } - - // If themes have been updated, send email - if( $totalNumT > 0 ) { - - // E-mail content - $subject = '[' . get_bloginfo( 'name' ) . '] ' . __('One or more themes have been updated.', 'companion-auto-update'); - $type = __('themes', 'companion-auto-update'); - $message = cau_updated_message( $type, $updatedListT ); - - // Send to all addresses - foreach ( cau_set_email() as $key => $value) { - foreach ($value as $k => $v) { - wp_mail( $v, $subject, $message ); - } - break; - } - - } - - if( cau_get_db_value( 'html_or_text' ) == 'html' ) remove_filter( 'wp_mail_content_type', 'cau_mail_content_type' ); - - // Prevent duplicate emails by setting the event again - if( $totalNumT > 0 OR $totalNumP > 0 ) { - if( $schedule_mail == 'hourly' ) { - wp_clear_scheduled_hook('cau_set_schedule_mail'); - wp_schedule_event( strtotime( '+1 hour', time() ) , 'hourly', 'cau_set_schedule_mail' ); - } - } - -} - -function cau_notify_outofdate_db() { - - // Check if cau_get_db_value() function exists. - if ( !function_exists( 'cau_get_db_value' ) ) require_once( plugin_dir_path( __FILE__ ) . 'cau_function.php' ); - - // Database requires an update - if ( cau_incorrectDatabaseVersion() ) { - - // Set up mail - $subject = '[' . get_bloginfo( 'name' ) . '] ' . __( 'We need your help with something', 'companion-auto-update' ); - $message = __( 'Hi there! We need your help updating the database of Companion Auto Update to the latest version. No rush, old features will continue to work but some new features might not work until you update the database.', 'companion-auto-update' ); - - // Send to all addresses - foreach ( cau_set_email() as $key => $value ) { - foreach ( $value as $k => $v ) { - wp_mail( $v, $subject, $message ); - } - break; - } - - } - -} - + $version ) { + if( $version == '' ) $version = __( "Unknown", "companion-auto-update" ); + $text .= "- ".sprintf( esc_html__( "%s tested up to: %s", "companion-auto-update" ), $plugin, $version )."\n"; + } + + } + + return $text; + +} + +// Set the content for the emails about pending updates +function cau_pending_message( $single, $plural, $list ) { + + // What markup to use + if( cau_is_html() ) $break = '
'; + else $break = "\n"; + + // Base text + $text = sprintf( esc_html__( 'You have pending %1$s updates on your WordPress site at %2$s.', 'companion-auto-update' ), $single, get_site_url() ); + $text .= $break; + + if( !empty( $list ) ) { + + $text .= $break; + $text .= sprintf( esc_html__( 'The following %1$s have new versions available.', 'companion-auto-update' ), $plural ); + $text .= $break; + + if( cau_is_html() ) $text .= "
    "; + foreach ( $list as $key => $value ) { + if( cau_is_html() ) { + $text .= "
  1. $value
  2. "; + } else { + $text .= "-$value\n"; + } + } + if( cau_is_html() ) $text .= "
"; + + $text .= $break; + } + + $text .= __( 'Leaving your site outdated is a security risk so please consider manually updating them.', 'companion-auto-update' ); + $text .= $break; + + // End + $text .= sprintf( esc_html__( 'Head over to %1$s and check the ones you want to update.', 'companion-auto-update' ), get_admin_url().'update-core.php' ); + + return $text; + +} + +// Set the content for the emails about recent updates +function cau_updated_message( $type, $updatedList ) { + + // What markup to use + if( cau_is_html() ) $break = '
'; + else $break = "\n"; + + // The message + $text = sprintf( esc_html__( + 'One or more %1$s on your WordPress site at %2$s have been updated by Companion Auto Update. No further action is needed on your part. +For more info on what is new visit your dashboard and check the changelog.', 'companion-auto-update' + ), $type, get_site_url() ); + + $text .= $break; + $text .= $break; + $text .= sprintf( esc_html__( + 'The following %1$s have been updated:', 'companion-auto-update' + ), $type ); + + $text .= $break; + $text .= $updatedList; + + $text .= $break; + $text .= __( "(You'll also receive this email if you manually updated a plugin or theme)", "companion-auto-update" ); + + return $text; + +} + +// Checks if plugins are out of date +function cau_list_outdated_software() { + + // Check if cau_get_db_value() function exists. + if ( !function_exists( 'cau_get_db_value' ) ) require_once( plugin_dir_path( __FILE__ ) . 'cau_function.php' ); + + // Set up mail + $subject = '['.get_bloginfo( 'name' ).'] ' . __( 'You have outdated plugins on your site.', 'companion-auto-update' ); + $type = __( 'plugin', 'companion-auto-update' ); + $type_plural = __( 'plugins', 'companion-auto-update' ); + $message = cau_outdated_message( $type, $type_plural, cau_list_outdated() ); + + // Send to all addresses + foreach ( cau_set_email() as $key => $value ) { + foreach ( $value as $k => $v ) { + wp_mail( $v, $subject, $message ); + } + break; + } + +} + +// Checks if theme updates are available +function cau_list_theme_updates() { + + global $wpdb; + $table_name = $wpdb->prefix . "auto_updates"; + + $configs = $wpdb->get_results( "SELECT * FROM $table_name WHERE name = 'themes'"); + foreach ( $configs as $config ) { + + if( $config->onoroff != 'on' ) { + + require_once ABSPATH . '/wp-admin/includes/update.php'; + $themes = get_theme_updates(); + $list = array(); + + if ( !empty( $themes ) ) { + + foreach ( $themes as $stylesheet => $theme ) { + array_push( $list, $theme->get( 'Name' ) ); + } + + $subject = '[' . get_bloginfo( 'name' ) . '] ' . __( 'Theme update available.', 'companion-auto-update' ); + $type = __('theme', 'companion-auto-update'); + $type_plural = __('themes', 'companion-auto-update'); + $message = cau_pending_message( $type, $type_plural, $list ); + + foreach ( cau_set_email() as $key => $value) { + foreach ($value as $k => $v) { + wp_mail( $v, $subject, $message ); + } + break; + } + } + + } + + } + +} + +// Checks if plugin updates are available +function cau_list_plugin_updates() { + + global $wpdb; + $table_name = $wpdb->prefix . "auto_updates"; + + $configs = $wpdb->get_results( "SELECT * FROM $table_name WHERE name = 'plugins'"); + foreach ( $configs as $config ) { + + if( $config->onoroff != 'on' ) { + + require_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); + + if ( !function_exists( 'get_plugin_updates' ) ) require_once ABSPATH . 'wp-admin/includes/update.php'; + $plugins = get_plugin_updates(); + + if ( !empty( $plugins ) ) { + + $list = array(); + foreach ( (array) $plugins as $plugin_file => $plugin_data ) { + $plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file, (array) $plugin_data, false, true ); + $name = $plugin_data->Name; + array_push( $list, $name ); + } + + $subject = '[' . get_bloginfo( 'name' ) . '] ' . __( 'Plugin update available.', 'companion-auto-update' ); + $type = __( 'plugin', 'companion-auto-update' ); + $type_plural = __( 'plugins', 'companion-auto-update' ); + $message = cau_pending_message( $type, $type_plural, $list ); + + foreach ( cau_set_email() as $key => $value) { + foreach ($value as $k => $v) { + wp_mail( $v, $subject, $message ); + } + break; + } + } + + } + + } +} + +// Alerts when plugin has been updated +function cau_plugin_updated() { + + // Check if cau_get_db_value() function exists. + if ( !function_exists( 'cau_get_db_value' ) ) require_once( plugin_dir_path( __FILE__ ) . 'cau_function.php' ); + + // Set the correct timezone for emails + date_default_timezone_set( cau_get_proper_timezone() ); + + // Create arrays + $pluginNames = array(); + $pluginDates = array(); + $pluginVersion = array(); + $pluginSlug = array(); + $pluginTimes = array(); + $themeNames = array(); + $themeDates = array(); + $themeTimes = array(); + + // Where to look for plugins + $plugdir = plugin_dir_path( __DIR__ ); + if ( !function_exists( 'get_plugins' ) ) require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Check if get_plugins() function exists. + $allPlugins = get_plugins(); + + // Where to look for themes + $themedir = get_theme_root(); + $allThemes = wp_get_themes(); + + // Mail schedule + $schedule_mail = wp_get_schedule( 'cau_set_schedule_mail' ); + + // Loop trough all plugins + foreach ( $allPlugins as $key => $value ) { + + // Get plugin data + $fullPath = $plugdir.'/'.$key; + $getFile = $path_parts = pathinfo( $fullPath ); + $pluginData = get_plugin_data( $fullPath ); + + // Get the slug + $explosion = explode( '/', $key ); + $actualSlug = array_shift( $explosion ); + + // Get last update date + $fileDate = date ( 'YmdHi', filemtime( $fullPath ) ); + + switch ( $schedule_mail ) { + case 'hourly': + $lastday = date( 'YmdHi', strtotime( '-1 hour', time() ) ); + break; + case 'twicedaily': + $lastday = date( 'YmdHi', strtotime( '-12 hours', time() ) ); + break; + default: + $lastday = date( 'YmdHi', strtotime( '-1 day', time() ) ); + break; + } + + $dateFormat = get_option( 'date_format' ); + $timestamp = date_i18n( $dateFormat, filemtime( $fullPath ) ); + $timestamp .= ' - '.date( 'H:i', filemtime( $fullPath ) ); + + if( $fileDate >= $lastday ) { + + // Get plugin name + foreach ( $pluginData as $dataKey => $dataValue ) { + if( $dataKey == 'Name') { + array_push( $pluginNames , $dataValue ); + } + if( $dataKey == 'Version') { + array_push( $pluginVersion , $dataValue ); + } + } + + array_push( $pluginDates, $fileDate ); + array_push( $pluginSlug, $actualSlug ); + array_push( $pluginTimes, $timestamp ); + } + + } + + // Loop trough all themes + foreach ( $allThemes as $key => $value ) { + + // Get theme data + $fullPath = $themedir.'/'.$key; + $getFile = $path_parts = pathinfo( $fullPath ); + + // Get last update date + $dateFormat = get_option( 'date_format' ); + $fileDate = date ( 'YmdHi', filemtime( $fullPath ) ); + + if( $schedule_mail == 'hourly' ) { + $lastday = date( 'YmdHi', strtotime( '-1 hour', time() ) ); + } elseif( $schedule_mail == 'twicedaily' ) { + $lastday = date( 'YmdHi', strtotime( '-12 hours', time() ) ); + } elseif( $schedule_mail == 'daily' ) { + $lastday = date( 'YmdHi', strtotime( '-1 day', time() ) ); + } + + $dateFormat = get_option( 'date_format' ); + $timestamp = date_i18n( $dateFormat, filemtime( $fullPath ) ); + $timestamp .= ' - '.date( 'H:i', filemtime( $fullPath ) ); + + if( $fileDate >= $lastday ) { + array_push( $themeNames, $path_parts['filename'] ); + array_push( $themeDates, $fileDate ); + array_push( $themeTimes, $timestamp ); + } + + } + + $totalNumP = 0; + $totalNumT = 0; + $updatedListP = ''; + $updatedListT = ''; + + if( cau_get_db_value( 'html_or_text' ) == 'html' ) { + $updatedListP .= '
    '; + $updatedListT .= '
      '; + } + + foreach ( $pluginDates as $key => $value ) { + + // Set up some var + $plugin_name = $pluginNames[$key]; + $plugin_slug = $pluginSlug[$key]; + $to_version = __( "to version", "companion-auto-update" ).' '.$pluginVersion[$key]; + $more_info_arr = array( __( "Time of update", "companion-auto-update" ) => $pluginTimes[$key] ); + + // Plugin links + if( cau_get_db_value( 'plugin_links_emails' ) == 'on' ) { + $more_info_arr[__( "Plugin details", "companion-auto-update" )] = "".__( "Visit", "companion-auto-update" ).""; + $more_info_arr[__( "Release notes", "companion-auto-update" )] = "".__( "Visit", "companion-auto-update" ).""; + $more_info_arr[__( "Support", "companion-auto-update" )] = "".__( "Visit", "companion-auto-update" ).""; + } + + // Email format + $use_html = ( cau_get_db_value( 'html_or_text' ) == 'html' ) ? true : false; + + // Email content + $updatedListP .= $use_html ? "
    1. " : "-"; // Start row + + $updatedListP .= $use_html ? "{$plugin_name} " : "{$plugin_name} "; // Show plugin name + $updatedListP .= $to_version; // To version + + // Get advanced info + if( cau_get_db_value( 'advanced_info_emails' ) == 'on' ) { + foreach( $more_info_arr as $label => $value ) { + $updatedListP .= $use_html ? "
      {$label}: {$value}" : "\n{$label}: {$value}"; + } + } + + $updatedListP .= $use_html ? "
    2. " : "\n"; // End row + + $totalNumP++; + } + + foreach ( $themeNames as $key => $value ) { + + if( cau_get_db_value( 'html_or_text' ) == 'html' ) { + + $more_info = ''; + if( cau_get_db_value( 'advanced_info_emails' ) == 'on' ) $more_info = "
      ".__( "Time of update", "companion-auto-update" ).": ".$themeTimes[$key].""; + $updatedListT .= "
    3. ".$themeNames[$key]."".$more_info."
    4. "; + + } else { + $updatedListT .= "- ".$themeNames[$key]."\n"; + } + + $totalNumT++; + } + + if( cau_get_db_value( 'html_or_text' ) == 'html' ) { + $updatedListP .= '
    '; + $updatedListT .= '
'; + } + + // Set the email content type + if( cau_get_db_value( 'html_or_text' ) == 'html' ) { + function cau_mail_content_type() { + return 'text/html'; + } + add_filter( 'wp_mail_content_type', 'cau_mail_content_type' ); + } + + // If plugins have been updated, send email + if( $totalNumP > 0 ) { + + // E-mail content + $subject = '[' . get_bloginfo( 'name' ) . '] ' . __('One or more plugins have been updated.', 'companion-auto-update'); + $type = __('plugins', 'companion-auto-update'); + $message = cau_updated_message( $type, $updatedListP ); + + // Send to all addresses + foreach ( cau_set_email() as $key => $value) { + foreach ($value as $k => $v) { + wp_mail( $v, $subject, $message ); + } + break; + } + + } + + // If themes have been updated, send email + if( $totalNumT > 0 ) { + + // E-mail content + $subject = '[' . get_bloginfo( 'name' ) . '] ' . __('One or more themes have been updated.', 'companion-auto-update'); + $type = __('themes', 'companion-auto-update'); + $message = cau_updated_message( $type, $updatedListT ); + + // Send to all addresses + foreach ( cau_set_email() as $key => $value) { + foreach ($value as $k => $v) { + wp_mail( $v, $subject, $message ); + } + break; + } + + } + + if( cau_get_db_value( 'html_or_text' ) == 'html' ) remove_filter( 'wp_mail_content_type', 'cau_mail_content_type' ); + + // Prevent duplicate emails by setting the event again + if( $totalNumT > 0 OR $totalNumP > 0 ) { + if( $schedule_mail == 'hourly' ) { + wp_clear_scheduled_hook('cau_set_schedule_mail'); + wp_schedule_event( strtotime( '+1 hour', time() ) , 'hourly', 'cau_set_schedule_mail' ); + } + } + +} + +function cau_notify_outofdate_db() { + + // Check if cau_get_db_value() function exists. + if ( !function_exists( 'cau_get_db_value' ) ) require_once( plugin_dir_path( __FILE__ ) . 'cau_function.php' ); + + // Database requires an update + if ( cau_incorrectDatabaseVersion() ) { + + // Set up mail + $subject = '[' . get_bloginfo( 'name' ) . '] ' . __( 'We need your help with something', 'companion-auto-update' ); + $message = __( 'Hi there! We need your help updating the database of Companion Auto Update to the latest version. No rush, old features will continue to work but some new features might not work until you update the database.', 'companion-auto-update' ); + + // Send to all addresses + foreach ( cau_set_email() as $key => $value ) { + foreach ( $value as $k => $v ) { + wp_mail( $v, $subject, $message ); + } + break; + } + + } + +} diff --git a/wp-content/plugins/companion-auto-update/cau_functions.php b/wp-content/plugins/companion-auto-update/cau_functions.php index d00fa609..e97c835a 100644 --- a/wp-content/plugins/companion-auto-update/cau_functions.php +++ b/wp-content/plugins/companion-auto-update/cau_functions.php @@ -1,15 +1,33 @@ prefix.'auto_updates'; + $cau_configs = $wpdb->get_results( "SELECT name, onoroff FROM {$table_name} WHERE name = 'allow_editor' OR name = 'allow_author'" ); + + foreach ( $cau_configs as $config ) { + if( $config->onoroff == 'on' ) $allowed_roles[] = str_replace( "allow_", "", $config->name ); + } + + // Return array + return $allowed_roles; + +} + +// What user rights can edit plugin settings? TRUE/FALSE function cau_allowed_user_rights() { // Current user $user = wp_get_current_user(); // Allow roles - $allowed_roles = array( 'administrator' ); - if( cau_get_db_value( 'allow_editor' ) == 'on' ) array_push( $allowed_roles, 'editor' ); - if( cau_get_db_value( 'allow_author' ) == 'on' ) array_push( $allowed_roles, 'author' ); + $allowed_roles = cau_allowed_user_rights_array(); // Check if ( array_intersect( $allowed_roles, $user->roles ) ) { @@ -17,6 +35,7 @@ function cau_allowed_user_rights() { } else { return false; } + } // Get database value @@ -24,7 +43,7 @@ function cau_get_db_value( $name, $table = 'auto_updates' ) { global $wpdb; $table_name = $wpdb->prefix.$table; - $cau_configs = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table_name} WHERE name = '%s'", $name ) ); + $cau_configs = $wpdb->get_results( $wpdb->prepare( "SELECT onoroff FROM {$table_name} WHERE name = '%s'", $name ) ); foreach ( $cau_configs as $config ) return $config->onoroff; } @@ -1089,13 +1108,11 @@ function cau_active_plugin_info( $slug, $what ) { $allPlugins = get_plugins(); - foreach ($allPlugins as $key => $value) { + foreach( $allPlugins as $key => $value ) { $thisSlug = explode('/', $key); $thisSlugE = $thisSlug[0]; if( $thisSlug == $slug ) { - if( $what == 'version' ) return $value['Version']; - } } @@ -1437,4 +1454,4 @@ function cau_unhold_all_updates() { $plugin_file = $plugin->slug; $wpdb->query( $wpdb->prepare( "UPDATE {$updateLog} SET put_on_hold = '%s' WHERE slug = '%s'", '0', $plugin_file ) ); } -} \ No newline at end of file +} diff --git a/wp-content/plugins/companion-auto-update/companion-auto-update.php b/wp-content/plugins/companion-auto-update/companion-auto-update.php index 4fe206a2..47b64814 100644 --- a/wp-content/plugins/companion-auto-update/companion-auto-update.php +++ b/wp-content/plugins/companion-auto-update/companion-auto-update.php @@ -4,7 +4,7 @@ * Plugin Name: Companion Auto Update * Plugin URI: http://codeermeneer.nl/portfolio/companion-auto-update/ * Description: This plugin auto updates all plugins, all themes and the wordpress core. - * Version: 3.8.5 + * Version: 3.8.6 * Author: Papin Schipper * Author URI: http://codeermeneer.nl/ * Contributors: papin @@ -417,4 +417,4 @@ function cau_checkForIssues( $admin_bar ) { )); } } -add_action( 'admin_bar_menu', 'cau_checkForIssues', 150 ); \ No newline at end of file +add_action( 'admin_bar_menu', 'cau_checkForIssues', 150 ); diff --git a/wp-content/plugins/companion-auto-update/readme.txt b/wp-content/plugins/companion-auto-update/readme.txt index 92726126..0dbd2f7a 100644 --- a/wp-content/plugins/companion-auto-update/readme.txt +++ b/wp-content/plugins/companion-auto-update/readme.txt @@ -3,9 +3,9 @@ Contributors: Papin, qweb Donate link: https://www.paypal.me/dakel/10/ Tags: auto, automatic, background, update, updates, updating, automatic updates, automatic background updates, easy update, wordpress update, theme update, plugin update, up-to-date, security, update latest version, update core, update wp, update wp core, major updates, minor updates, update to new version, update core, update plugin, update plugins, update plugins automatically, update theme, plugin, theme, advance, control, mail, notifations, enable Requires at least: 3.6.0 -Tested up to: 5.9 +Tested up to: 6.0 Requires PHP: 5.1 -Stable tag: 3.8.5 +Stable tag: 3.8.6 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -17,10 +17,13 @@ Companion Auto Update is a powerful and completely free plugin that allows you t We understand that you might not always be able to check if your WordPress site has any updates that need to be installed. Especially when you maintain multiple websites keeping them up-to-date can be a lot of work. This plugin can help you with that. We'll keep your site up-to-date and keep you posted about what's happening and notify you when we need your help with something. +If you have a feature suggestion or idea you’d like to see in the plugin, we’d love to hear about it! [Suggest a Feature](https://codeermeneer.nl/contact/) + = Main features = 1. Auto-updating for plugins, themes, core and translation files +1. Set at what time you wish to update 1. Filter plugins and themes to not be updated -1. E-mail notifications about old software, pending updates and complete updates +1. E-mail notifications about old software, pending updates and completed updates 1. An update log with all updates 1. Option to delay automatic updates with an x number of days @@ -35,8 +38,6 @@ Sometimes developers will push an update that will cause errors on your site, th We want you to know what's happening on your website. This plugin offers settings for various email notifications. We can send you an email when an update is available, when a plugin has been updated or when wordpress has been updated. But if you don't want to recieve emails about this you can still log in and view the changelog to see what happened. -If you have a feature suggestion or idea you’d like to see in the plugin, we’d love to hear about it! [Suggest a Feature](https://codeermeneer.nl/contact/) - == Installation == How to install Companion Auto Update @@ -81,6 +82,9 @@ So obviously, some of you wondered what the difference would be between the defa == Changelog == += 3.8.6 (August 11, 2022) = +* Tweak: Code optimization for better performance + = 3.8.5 (March 17, 2022) = * New: Added more checks on the status page and added an explanation to some of them. * New: Added an list of delayed updates on the status page to help with troubleshooting.