settings_views = array_filter(
$settings_views,
function ($setting) {
return $setting instanceof Settings\SettingTab;
}
);
$this->settings_updaters = array_filter(
$settings_updaters,
function ($setting) {
return $setting instanceof Settings\SettingUpdatable;
}
);
}
/**
* @return array
*/
public static function get_information() {
global $wpdb;
$information = array();
// Wordpress version
$information['wpversion']['label'] = __( 'WordPress version', 'backwpup' );
$information['wpversion']['value'] = BackWPup::get_plugin_data( 'wp_version' );
// BackWPup version
if ( ! BackWPup::is_pro() ) {
$information['bwuversion']['label'] = esc_html__( 'BackWPup version', 'backwpup' );
$information['bwuversion']['value'] = BackWPup::get_plugin_data( 'Version' );
$information['bwuversion']['html'] = BackWPup::get_plugin_data( 'Version' ) .
' ' .
esc_html__( 'Get pro.', 'backwpup' ) . '';
} else {
$information['bwuversion']['label'] = __( 'BackWPup Pro version', 'backwpup' );
$information['bwuversion']['value'] = BackWPup::get_plugin_data( 'Version' );
}
// PHP version
$information['phpversion']['label'] = esc_html__( 'PHP version', 'backwpup' );
$bit = '';
if ( PHP_INT_SIZE === 4 ) {
$bit = ' (32bit)';
} elseif ( PHP_INT_SIZE === 8 ) {
$bit = ' (64bit)';
}
$information['phpversion']['value'] = PHP_VERSION . ' ' . $bit;
// MySQL version
$information['mysqlversion']['label'] = esc_html__( 'MySQL version', 'backwpup' );
$information['mysqlversion']['value'] = $wpdb->get_var( "SELECT VERSION() AS version" );
// Curl version
$information['curlversion']['label'] = esc_html__( 'cURL version', 'backwpup' );
if ( function_exists( 'curl_version' ) ) {
$curl_version = curl_version();
$information['curlversion']['value'] = $curl_version['version'];
$information['curlsslversion']['label'] = __( 'cURL SSL version', 'backwpup' );
$information['curlsslversion']['value'] = $curl_version['ssl_version'];
} else {
$information['curlversion']['value'] = esc_html__( 'unavailable', 'backwpup' );
}
// WP cron URL
$information['wpcronurl']['label'] = esc_html__( 'WP-Cron url', 'backwpup' );
$information['wpcronurl']['value'] = site_url( 'wp-cron.php' );
// Response test
$server_connect['label'] = __( 'Server self connect', 'backwpup' );
$raw_response = BackWPup_Job::get_jobrun_url( 'test' );
$response_code = wp_remote_retrieve_response_code( $raw_response );
$response_body = wp_remote_retrieve_body( $raw_response );
if ( strstr( $response_body, 'BackWPup test request' ) === false ) {
$server_connect['value'] = esc_html__( 'Not expected HTTP response:', 'backwpup' ) . "\n";
$server_connect['html'] = wp_kses( __( 'Not expected HTTP response:
', 'backwpup' ),
array( 'strong' => array() ) );
if ( ! $response_code ) {
$server_connect['value'] .= sprintf( wp_kses_post(
__( 'WP Http Error: %s', 'backwpup' ),
$raw_response->get_error_message()
) ) . "\n";
$server_connect['html'] = sprintf(
__( 'WP Http Error: %s
', 'backwpup' ),
esc_html( $raw_response->get_error_message() )
) . '
';
} else {
$server_connect['value'] .= sprintf( __( 'Status-Code: %d', 'backwpup' ), $response_code ) . "\n";
$server_connect['html'] .= sprintf(
__( 'Status-Code: %d
', 'backwpup' ),
esc_html( $response_code )
) . '
';
}
$response_headers = wp_remote_retrieve_headers( $raw_response );
foreach ( $response_headers as $key => $value ) {
$server_connect['value'] .= ucfirst( $key ) . ": $value\n";
$server_connect['html'] .= esc_html( ucfirst( $key ) ) . ': ' . esc_html(
$value
) . '
';
}
$content = wp_remote_retrieve_body( $raw_response );
if ( $content ) {
$server_connect['value'] .= sprintf( __( 'Content: %s', 'backwpup' ), $content );
$server_connect['html'] .= sprintf(
__( 'Content: %s
', 'backwpup' ),
esc_html( $content )
);
}
} else {
$server_connect['value'] = __( 'Response Test O.K.', 'backwpup' );
}
$information['serverconnect'] = $server_connect;
// Document root
$information['docroot']['label'] = 'Document root';
$information['docroot']['value'] = $_SERVER['DOCUMENT_ROOT'];
// Temp folder
$information['tmpfolder']['label'] = esc_html__( 'Temp folder', 'backwpup' );
if ( ! is_dir( BackWPup::get_plugin_data( 'TEMP' ) ) ) {
$information['tmpfolder']['value'] = sprintf(
esc_html__( 'Temp folder %s doesn\'t exist.', 'backwpup' ),
BackWPup::get_plugin_data( 'TEMP' )
);
} elseif ( ! is_writable( BackWPup::get_plugin_data( 'TEMP' ) ) ) {
$information['tmpfolder']['value'] = sprintf(
esc_html__( 'Temporary folder %s is not writable.', 'backwpup' ),
BackWPup::get_plugin_data( 'TEMP' )
);
} else {
$information['tmpfolder']['value'] = BackWPup::get_plugin_data( 'TEMP' );
}
// Log folder
$information['logfolder']['label'] = esc_html__( 'Log folder', 'backwpup' );
$log_folder = BackWPup_File::get_absolute_path(
get_site_option( 'backwpup_cfg_logfolder' )
);
if ( ! is_dir( $log_folder ) ) {
$information['logfolder']['value'] = sprintf(
esc_html__( 'Log folder %s does not exist.', 'backwpup' ),
$log_folder
);
} elseif ( ! is_writable( $log_folder ) ) {
$information['logfolder']['value'] = sprintf(
esc_html__( 'Log folder %s is not writable.', 'backwpup' ),
$log_folder
);
} else {
$information['logfolder']['value'] = $log_folder;
}
// Server
$information['server']['label'] = esc_html__( 'Server', 'backwpup' );
$information['server']['value'] = $_SERVER['SERVER_SOFTWARE'];
// OS
$information['os']['label'] = esc_html__( 'Operating System', 'backwpup' );
$information['os']['value'] = PHP_OS;
// PHP SAPI
$information['phpsapi']['label'] = esc_html__( 'PHP SAPI', 'backwpup' );
$information['phpsapi']['value'] = PHP_SAPI;
// PHP user
$information['phpuser']['label'] = esc_html__( 'Current PHP user', 'backwpup' );
if ( function_exists( 'get_current_user' ) ) {
$information['phpuser']['value'] = get_current_user();
} else {
$information['phpuser']['value'] = esc_html__( 'Function Disabled', 'backwpup' );
}
// Maximum execution time
$information['maxexectime']['label'] = esc_html__( 'Maximum execution time', 'backwpup' );
$information['maxexectime']['value'] = sprintf(
__( '%d seconds', 'backwpup' ),
ini_get( 'max_execution_time' )
);
// BackWPup Maximum script execution time
$information['jobmaxexecutiontime']['label'] = esc_html__( 'BackWPup maximum script execution time',
'backwpup' );
$information['jobmaxexecutiontime']['value'] = sprintf(
__( '%d seconds', 'backwpup' ),
absint( get_site_option( 'backwpup_cfg_jobmaxexecutiontime' ) )
);
// Alternate WP cron
$information['altwpcron']['label'] = esc_html__( 'Alternative WP Cron', 'backwpup' );
if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) {
$information['altwpcron']['value'] = esc_html__( 'On', 'backwpup' );
} else {
$information['altwpcron']['value'] = esc_html__( 'Off', 'backwpup' );
}
// Disable WP cron
$information['disablewpcron']['label'] = esc_html__( 'Disabled WP Cron', 'backwpup' );
if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
$information['disablewpcron']['value'] = esc_html__( 'On', 'backwpup' );
} else {
$information['disablewpcron']['value'] = esc_html__( 'Off', 'backwpup' );
}
// CHMOD dir
$information['chmoddir']['label'] = esc_html__( 'CHMOD Dir', 'backwpup' );
if ( defined( 'FS_CHMOD_DIR' ) ) {
$information['chmoddir']['value'] = FS_CHMOD_DIR;
} else {
$information['chmoddir']['value'] = '0755';
}
// Server time
$information['servertime']['label'] = esc_html__( 'Server Time', 'backwpup' );
$now = localtime( time(), true );
$information['servertime']['value'] = $now['tm_hour'] . ':' . $now['tm_min'];
// Blog time
$information['blogtime']['label'] = esc_html__( 'Blog Time', 'backwpup' );
$information['blogtime']['value'] = date( 'H:i', current_time( 'timestamp' ) );
// Blog timezone
$information['blogtz']['label'] = esc_html__( 'Blog Timezone', 'backwpup' );
$information['blogtz']['value'] = get_option( 'timezone_string' );
// Blog time offset
$information['blogoffset']['label'] = esc_html__( 'Blog Time offset', 'backwpup' );
$information['blogoffset']['value'] = sprintf(
esc_html__( '%s hours', 'backwpup' ),
(int) get_option( 'gmt_offset' )
);
// Blog language
$information['bloglang']['label'] = esc_html__( 'Blog language', 'backwpup' );
$information['bloglang']['value'] = get_bloginfo( 'language' );
// MySQL encoding
$information['mysqlencoding']['label'] = esc_html__( 'MySQL Client encoding', 'backwpup' );
$information['mysqlencoding']['value'] = defined( 'DB_CHARSET' ) ? DB_CHARSET : '';
// PHP memory limitesc_html__
$information['phpmemlimit']['label'] = esc_html__( 'PHP Memory limit', 'backwpup' );
$information['phpmemlimit']['value'] = ini_get( 'memory_limit' );
// WP memory limit
$information['wpmemlimit']['label'] = esc_html__( 'WP memory limit', 'backwpup' );
$information['wpmemlimit']['value'] = WP_MEMORY_LIMIT;
// WP maximum memory limit
$information['wpmaxmemlimit']['label'] = esc_html__( 'WP maximum memory limit', 'backwpup' );
$information['wpmaxmemlimit']['value'] = WP_MAX_MEMORY_LIMIT;
// Memory in use
$information['memusage']['label'] = esc_html__( 'Memory in use', 'backwpup' );
$information['memusage']['value'] = size_format( @memory_get_usage( true ), 2 );
// Disabled PHP functions
$disabled = esc_html( ini_get( 'disable_functions' ) );
if ( ! empty( $disabled ) ) {
$information['disabledfunctions']['label'] = esc_html__( 'Disabled PHP Functions:', 'backwpup' );
$information['disabledfunctions']['value'] = implode( ', ', explode( ',', $disabled ) );
}
// Loaded PHP extensions
$information['loadedextensions']['label'] = esc_html__( 'Loaded PHP Extensions:', 'backwpup' );
$extensions = get_loaded_extensions();
sort( $extensions );
$information['loadedextensions']['value'] = implode( ', ', $extensions );
return $information;
}
public function admin_print_scripts() {
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
wp_enqueue_script(
'backwpuppagesettings',
untrailingslashit( BackWPup::get_plugin_data( 'URL' ) ) . "/assets/js/page_settings{$suffix}.js",
array(
'jquery',
'backwpupgeneral',
'backwpup_clipboard',
),
filemtime( untrailingslashit( BackWPup::get_plugin_data( 'plugindir' ) ) . "/assets/js/page_settings{$suffix}.js" ),
true
);
if ( \BackWPup::is_pro() ) {
wp_enqueue_script(
'backwpuppagesettings-encryption',
untrailingslashit( BackWPup::get_plugin_data( 'URL' ) ) . "/assets/js/pro/settings-encryption{$suffix}.js",
array(
'underscore',
'jquery',
'backwpuppagesettings',
'thickbox',
),
filemtime( untrailingslashit( BackWPup::get_plugin_data( 'plugindir' ) ) . "/assets/js/pro/settings-encryption{$suffix}.js" ),
true
);
wp_localize_script(
'backwpuppagesettings-encryption',
'settingsEncryptionVariables',
array(
'validPublicKey' => esc_html__( 'Public key is valid.', 'backwpup' ),
'invalidPublicKey' => esc_html__( 'Public key is invalid.', 'backwpup' ),
'privateKeyMissed' => esc_html__( 'Please enter your private key.', 'backwpup' ),
'publicKeyMissed' => esc_html__(
'Please enter a public key first, or generate a key pair.',
'backwpup'
),
'mustDownloadPrivateKey' => esc_html__(
'Please download the private key before continuing. If you do not save it locally, you cannot decrypt your backups later.',
'backwpup'
),
'mustDownloadSymmetricKey' => esc_html__(
'Please download the key before continuing. If you do not save it locally, you cannot decrypt your backups later.',
'backwpup'
),
)
);
}
}
public function save_post_form() {
if ( ! current_user_can( 'backwpup_settings' ) ) {
return;
}
// Set default options if button clicked.
if ( isset( $_POST['default_settings'] ) && $_POST['default_settings'] ) { // phpcs:ignore
delete_site_option( 'backwpup_cfg_showadminbar' );
delete_site_option( 'backwpup_cfg_showfoldersize' );
delete_site_option( 'backwpup_cfg_jobstepretry' );
delete_site_option( 'backwpup_cfg_jobmaxexecutiontime' );
delete_site_option( 'backwpup_cfg_loglevel' );
delete_site_option( 'backwpup_cfg_jobwaittimems' );
delete_site_option( 'backwpup_cfg_jobrunauthkey' );
delete_site_option( 'backwpup_cfg_jobdooutput' );
delete_site_option( 'backwpup_cfg_windows' );
delete_site_option( 'backwpup_cfg_maxlogs' );
delete_site_option( 'backwpup_cfg_gzlogs' );
delete_site_option( 'backwpup_cfg_protectfolders' );
delete_site_option( 'backwpup_cfg_authentication' );
delete_site_option( 'backwpup_cfg_logfolder' );
delete_site_option( 'backwpup_cfg_dropboxappkey' );
delete_site_option( 'backwpup_cfg_dropboxappsecret' );
delete_site_option( 'backwpup_cfg_dropboxsandboxappkey' );
delete_site_option( 'backwpup_cfg_dropboxsandboxappsecret' );
delete_site_option( 'backwpup_cfg_sugarsynckey' );
delete_site_option( 'backwpup_cfg_sugarsyncsecret' );
delete_site_option( 'backwpup_cfg_sugarsyncappid' );
delete_site_option( 'backwpup_cfg_hash' );
delete_site_option('backwpup_cfg_phone_home_client');
foreach ( $this->settings_updaters as $setting ) {
$setting->reset();
}
delete_site_option(self::LICENSE_INSTANCE_KEY);
delete_site_option(self::LICENSE_API_KEY);
delete_site_option(self::LICENSE_PRODUCT_ID);
delete_site_option(self::LICENSE_STATUS);
BackWPup_Option::default_site_options();
BackWPup_Admin::message( __( 'Settings reset to default', 'backwpup' ) );
return;
}
foreach ( $this->settings_updaters as $setting ) {
$setting->update();
}
update_site_option( 'backwpup_cfg_showadminbar', ! empty( $_POST['showadminbarmenu'] ) );
update_site_option( 'backwpup_cfg_showfoldersize', ! empty( $_POST['showfoldersize'] ) );
if ( empty( $_POST['jobstepretry'] ) || 100 < $_POST['jobstepretry'] || 1 > $_POST['jobstepretry'] ) {
$_POST['jobstepretry'] = 3;
}
update_site_option( 'backwpup_cfg_jobstepretry', absint( $_POST['jobstepretry'] ) );
if ( (int) $_POST['jobmaxexecutiontime'] > 300 ) {
$_POST['jobmaxexecutiontime'] = 300;
}
update_site_option( 'backwpup_cfg_jobmaxexecutiontime', absint( $_POST['jobmaxexecutiontime'] ) );
update_site_option(
'backwpup_cfg_loglevel',
in_array(
$_POST['loglevel'],
array( 'normal_translated', 'normal', 'debug_translated', 'debug' ),
true
) ? $_POST['loglevel'] : 'normal_translated'
);
update_site_option( 'backwpup_cfg_jobwaittimems', absint( $_POST['jobwaittimems'] ) );
update_site_option( 'backwpup_cfg_jobdooutput', ! empty( $_POST['jobdooutput'] ) );
update_site_option( 'backwpup_cfg_windows', ! empty( $_POST['windows'] ) );
update_site_option( 'backwpup_cfg_maxlogs', absint( $_POST['maxlogs'] ) );
update_site_option( 'backwpup_cfg_gzlogs', ! empty( $_POST['gzlogs'] ) );
update_site_option( 'backwpup_cfg_protectfolders', ! empty( $_POST['protectfolders'] ) );
$_POST['jobrunauthkey'] = preg_replace( '/[^a-zA-Z0-9]/', '', trim( $_POST['jobrunauthkey'] ) );
update_site_option( 'backwpup_cfg_jobrunauthkey', $_POST['jobrunauthkey'] );
$_POST['logfolder'] = trailingslashit(
str_replace( '\\', '/', trim( stripslashes( sanitize_text_field( $_POST['logfolder'] ) ) ) )
);
//set def. folders
if ( empty( $_POST['logfolder'] ) || $_POST['logfolder'] === '/' ) {
delete_site_option( 'backwpup_cfg_logfolder' );
BackWPup_Option::default_site_options();
} else {
update_site_option( 'backwpup_cfg_logfolder', $_POST['logfolder'] );
}
$authentication = get_site_option(
'backwpup_cfg_authentication',
array(
'method' => '',
'basic_user' => '',
'basic_password' => '',
'user_id' => 0,
'query_arg' => '',
)
);
$authentication['method'] = ( in_array(
$_POST['authentication_method'],
array( 'user', 'basic', 'query_arg' ),
true
) ) ? $_POST['authentication_method'] : '';
$authentication['basic_user'] = sanitize_text_field( $_POST['authentication_basic_user'] );
$authentication['basic_password'] = BackWPup_Encryption::encrypt(
(string) $_POST['authentication_basic_password']
);
$authentication['query_arg'] = sanitize_text_field( $_POST['authentication_query_arg'] );
$authentication['user_id'] = absint( $_POST['authentication_user_id'] );
update_site_option( 'backwpup_cfg_authentication', $authentication );
delete_site_transient( 'backwpup_cookies' );
update_site_option('backwpup_cfg_phone_home_client', !empty($_POST['phone_home_client']));
do_action('backwpup_page_settings_save');
BackWPup_Admin::message(__('Settings saved', 'backwpup'));
}
public function page() {
?>