edit_auth( $jobid ); } } /** * Save Form data */ public static function save_post_form($tab, $jobid) { if ( ! current_user_can( 'backwpup_jobs_edit' ) ) { return __( 'Sorry, you don\'t have permissions to do that.', 'backwpup' ); } $job_types = BackWPup::get_job_types(); switch ( $tab ) { case 'job': BackWPup_Option::update( $jobid, 'jobid', $jobid ); //set type of backup $backuptype = 'archive'; if ( class_exists( 'BackWPup_Pro', false ) && $_POST['backuptype'] === 'sync' ) { $backuptype = 'sync'; } BackWPup_Option::update( $jobid, 'backuptype', $backuptype ); $type_post = isset( $_POST['type'] ) ? (array) $_POST['type'] : array(); //check existing type foreach ( $type_post as $key => $value ) { if ( ! isset( $job_types[ $value ] ) ) { unset( $type_post[ $key ] ); } } sort( $type_post ); BackWPup_Option::update( $jobid, 'type', $type_post ); //test if job type makes backup $makes_file = false; /* @var BackWPup_JobTypes $job_type */ foreach ( $job_types as $type_id => $job_type ) { if ( in_array( $type_id, $type_post, true ) ) { if ( $job_type->creates_file() ) { $makes_file = true; break; } } } if ( $makes_file ) { $destinations_post = isset( $_POST['destinations'] ) ? (array) $_POST['destinations'] : array(); } else { $destinations_post = array(); } $destinations = BackWPup::get_registered_destinations(); foreach ( $destinations_post as $key => $dest_id ) { //remove all destinations that not exists if ( ! isset( $destinations[ $dest_id ] ) ) { unset( $destinations_post[ $key ] ); continue; } //if sync remove all not sync destinations if ( $backuptype === 'sync' ) { if ( ! $destinations[ $dest_id ]['can_sync'] ) { unset( $destinations_post[ $key ] ); } } } sort( $destinations_post ); BackWPup_Option::update( $jobid, 'destinations', $destinations_post ); $name = sanitize_text_field( trim( $_POST['name'] ) ); if ( ! $name || $name === __( 'New Job', 'backwpup' ) ) { $name = sprintf( __( 'Job with ID %d', 'backwpup' ), $jobid ); } BackWPup_Option::update( $jobid, 'name', $name ); $emails = explode( ',', sanitize_text_field( $_POST['mailaddresslog'] ) ); foreach ( $emails as $key => $email ) { $emails[ $key ] = sanitize_email( trim( $email ) ); if ( ! is_email( $emails[ $key ] ) ) { unset( $emails[ $key ] ); } } $mailaddresslog = implode( ', ', $emails ); BackWPup_Option::update( $jobid, 'mailaddresslog', $mailaddresslog ); $mailaddresssenderlog = trim( $_POST['mailaddresssenderlog'] ); BackWPup_Option::update( $jobid, 'mailaddresssenderlog', $mailaddresssenderlog ); BackWPup_Option::update( $jobid, 'mailerroronly', ! empty( $_POST['mailerroronly'] ) ); $archiveformat = in_array( $_POST['archiveformat'], array( '.zip', '.tar', '.tar.gz' ), true ) ? $_POST['archiveformat'] : '.zip'; BackWPup_Option::update( $jobid, 'archiveformat', $archiveformat ); BackWPup_Option::update( $jobid, 'archiveencryption', ! empty( $_POST['archiveencryption'] ) ); BackWPup_Option::update( $jobid, 'archivename', BackWPup_Job::sanitize_file_name( BackWPup_Option::normalize_archive_name( $_POST['archivename'], $jobid, false ) ) ); break; case 'cron': $activetype = in_array( $_POST['activetype'], array( '', 'wpcron', 'easycron', 'link' ), true ) ? $_POST['activetype'] : ''; BackWPup_Option::update( $jobid, 'activetype', $activetype ); $cronselect = $_POST['cronselect'] === 'advanced' ? 'advanced' : 'basic'; BackWPup_Option::update( $jobid, 'cronselect', $cronselect ); //save advanced if ( $cronselect === 'advanced' ) { if ( empty( $_POST['cronminutes'] ) || $_POST['cronminutes'][0] === '*' ) { if ( ! empty( $_POST['cronminutes'][1] ) ) { $_POST['cronminutes'] = array( '*/' . $_POST['cronminutes'][1] ); } else { $_POST['cronminutes'] = array( '*' ); } } if ( empty( $_POST['cronhours'] ) || $_POST['cronhours'][0] === '*' ) { if ( ! empty( $_POST['cronhours'][1] ) ) { $_POST['cronhours'] = array( '*/' . $_POST['cronhours'][1] ); } else { $_POST['cronhours'] = array( '*' ); } } if ( empty( $_POST['cronmday'] ) || $_POST['cronmday'][0] === '*' ) { if ( ! empty( $_POST['cronmday'][1] ) ) { $_POST['cronmday'] = array( '*/' . $_POST['cronmday'][1] ); } else { $_POST['cronmday'] = array( '*' ); } } if ( empty( $_POST['cronmon'] ) || $_POST['cronmon'][0] === '*' ) { if ( ! empty( $_POST['cronmon'][1] ) ) { $_POST['cronmon'] = array( '*/' . $_POST['cronmon'][1] ); } else { $_POST['cronmon'] = array( '*' ); } } if ( empty( $_POST['cronwday'] ) || $_POST['cronwday'][0] === '*' ) { if ( ! empty( $_POST['cronwday'][1] ) ) { $_POST['cronwday'] = array( '*/' . $_POST['cronwday'][1] ); } else { $_POST['cronwday'] = array( '*' ); } } $cron = implode( ",", $_POST['cronminutes'] ) . ' ' . implode( ",", $_POST['cronhours'] ) . ' ' . implode( ",", $_POST['cronmday'] ) . ' ' . implode( ",", $_POST['cronmon'] ) . ' ' . implode( ",", $_POST['cronwday'] ); BackWPup_Option::update( $jobid, 'cron', $cron ); } else { //Save basic if ( $_POST['cronbtype'] === 'mon' ) { BackWPup_Option::update( $jobid, 'cron', absint( $_POST['moncronminutes'] ) . ' ' . absint( $_POST['moncronhours'] ) . ' ' . absint( $_POST['moncronmday'] ) . ' * *' ); } if ( $_POST['cronbtype'] === 'week' ) { BackWPup_Option::update( $jobid, 'cron', absint( $_POST['weekcronminutes'] ) . ' ' . absint( $_POST['weekcronhours'] ) . ' * * ' . absint( $_POST['weekcronwday'] ) ); } if ( $_POST['cronbtype'] === 'day' ) { BackWPup_Option::update( $jobid, 'cron', absint( $_POST['daycronminutes'] ) . ' ' . absint( $_POST['daycronhours'] ) . ' * * *' ); } if ( $_POST['cronbtype'] === 'hour' ) { BackWPup_Option::update( $jobid, 'cron', absint( $_POST['hourcronminutes'] ) . ' * * * *' ); } } //reschedule $activetype = BackWPup_Option::get( $jobid, 'activetype' ); wp_clear_scheduled_hook( 'backwpup_cron', array( 'id' => $jobid ) ); if ( $activetype === 'wpcron' ) { $cron_next = BackWPup_Cron::cron_next( BackWPup_Option::get( $jobid, 'cron' ) ); wp_schedule_single_event( $cron_next, 'backwpup_cron', array( 'id' => $jobid ) ); } $easy_cron_job_id = BackWPup_Option::get( $jobid, 'easycronjobid' ); if ( $activetype === 'easycron' ) { BackWPup_EasyCron::update( $jobid ); } elseif ( $easy_cron_job_id ) { BackWPup_EasyCron::delete( $jobid ); } break; default: if ( strstr( $tab, 'dest-' ) ) { $dest_class = BackWPup::get_destination( str_replace( 'dest-', '', $tab ) ); $dest_class->edit_form_post_save( $jobid ); } if ( strstr( $tab, 'jobtype-' ) ) { $id = strtoupper( str_replace( 'jobtype-', '', $tab ) ); $job_types[ $id ]->edit_form_post_save( $jobid ); } } //saved message $messages = BackWPup_Admin::get_messages(); if ( empty( $messages['error'] ) ) { $url = BackWPup_Job::get_jobrun_url( 'runnowlink', $jobid ); BackWPup_Admin::message( sprintf( __( 'Changes for job %s saved.', 'backwpup' ), BackWPup_Option::get( $jobid, 'name' ) ) . ' ' . __( 'Jobs overview', 'backwpup' ) . ' | ' . __( 'Run now', 'backwpup' ) . '' ); } } /** * * Output css * * @return void */ public static function admin_print_styles() { ?> admin_print_styles(); } elseif ( substr( $_GET[ 'tab' ], 0, 8 ) == 'jobtype-' ) { $job_type = BackWPup::get_job_types(); $id = strtoupper( str_replace( 'jobtype-', '', $_GET[ 'tab' ] ) ); $job_type[ $id ]->admin_print_styles( ); } } /** * * Output js * * @return void */ public static function admin_print_scripts() { wp_enqueue_script( 'backwpupgeneral' ); //add js for the first tabs if ( $_GET[ 'tab' ] == 'job' ) { if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { wp_enqueue_script( 'backwpuptabjob', BackWPup::get_plugin_data( 'URL' ) . '/assets/js/page_edit_tab_job.js', array('jquery'), time(), TRUE ); } else { wp_enqueue_script( 'backwpuptabjob', BackWPup::get_plugin_data( 'URL' ) . '/assets/js/page_edit_tab_job.min.js', array('jquery'), BackWPup::get_plugin_data( 'Version' ), TRUE ); } } elseif ( $_GET[ 'tab' ] == 'cron' ) { if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { wp_enqueue_script( 'backwpuptabcron', BackWPup::get_plugin_data( 'URL' ) . '/assets/js/page_edit_tab_cron.js', array('jquery'), time(), TRUE ); } else { wp_enqueue_script( 'backwpuptabcron', BackWPup::get_plugin_data( 'URL' ) . '/assets/js/page_edit_tab_cron.min.js', array('jquery'), BackWPup::get_plugin_data( 'Version' ), TRUE ); } } //add js for all other tabs elseif ( strstr( $_GET[ 'tab' ], 'dest-' ) ) { $dest_object = BackWPup::get_destination( str_replace( 'dest-', '', $_GET[ 'tab' ] ) ); $dest_object->admin_print_scripts(); } elseif ( strstr( $_GET[ 'tab' ], 'jobtype-' ) ) { $job_type = BackWPup::get_job_types(); $id = strtoupper( str_replace( 'jobtype-', '', $_GET[ 'tab' ] ) ); $job_type[ $id ]->admin_print_scripts( ); } } /** * */ public static function page() { if ( ! empty( $_GET[ 'jobid' ] ) ) { $jobid = (int)$_GET[ 'jobid' ]; } else { //generate jobid if not exists $jobid = BackWPup_Option::next_job_id(); } $destinations = BackWPup::get_registered_destinations(); $job_types = BackWPup::get_job_types(); // Is encryption disabled? $disable_encryption = true; if ( (get_site_option( 'backwpup_cfg_encryption' ) === 'symmetric' && get_site_option( 'backwpup_cfg_encryptionkey' )) || (get_site_option( 'backwpup_cfg_encryption' ) === 'asymmetric' && get_site_option( 'backwpup_cfg_publickey' )) ) { $disable_encryption = false; } $archive_format_option = BackWPup_Option::get( $jobid, 'archiveformat' ); ?>
'; submit_button( __( 'Save changes', 'backwpup' ), 'primary', 'save', FALSE, array( 'tabindex' => '2', 'accesskey' => 'p' ) ); echo '
'; ?> edit_inline_js(); } if ( strstr( $_GET[ 'tab' ], 'jobtype-' ) ) { $id = strtoupper( str_replace( 'jobtype-', '', sanitize_text_field( $_GET[ 'tab' ] ) ) ); $job_types[ $id ]->edit_inline_js(); } } /** * @static * * @param string $args * * @return mixed */ public static function ajax_cron_text( $args = '' ) { if ( is_array( $args ) ) { extract( $args ); $ajax = FALSE; } else { if ( ! current_user_can( 'backwpup_jobs_edit' ) ) wp_die( -1 ); check_ajax_referer( 'backwpup_ajax_nonce' ); if ( empty( $_POST[ 'cronminutes' ] ) || $_POST[ 'cronminutes' ][ 0 ] == '*' ) { if ( ! empty( $_POST[ 'cronminutes' ][ 1 ] ) ) $_POST[ 'cronminutes' ] = array( '*/' . $_POST[ 'cronminutes' ][ 1 ] ); else $_POST[ 'cronminutes' ] = array( '*' ); } if ( empty( $_POST[ 'cronhours' ] ) || $_POST[ 'cronhours' ][ 0 ] == '*' ) { if ( ! empty( $_POST[ 'cronhours' ][ 1 ] ) ) $_POST[ 'cronhours' ] = array( '*/' . $_POST[ 'cronhours' ][ 1 ] ); else $_POST[ 'cronhours' ] = array( '*' ); } if ( empty( $_POST[ 'cronmday' ] ) || $_POST[ 'cronmday' ][ 0 ] == '*' ) { if ( ! empty( $_POST[ 'cronmday' ][ 1 ] ) ) $_POST[ 'cronmday' ] = array( '*/' . $_POST[ 'cronmday' ][ 1 ] ); else $_POST[ 'cronmday' ] = array( '*' ); } if ( empty( $_POST[ 'cronmon' ] ) || $_POST[ 'cronmon' ][ 0 ] == '*' ) { if ( ! empty( $_POST[ 'cronmon' ][ 1 ] ) ) $_POST[ 'cronmon' ] = array( '*/' . $_POST[ 'cronmon' ][ 1 ] ); else $_POST[ 'cronmon' ] = array( '*' ); } if ( empty( $_POST[ 'cronwday' ] ) || $_POST[ 'cronwday' ][ 0 ] == '*' ) { if ( ! empty( $_POST[ 'cronwday' ][ 1 ] ) ) $_POST[ 'cronwday' ] = array( '*/' . $_POST[ 'cronwday' ][ 1 ] ); else $_POST[ 'cronwday' ] = array( '*' ); } $crontype = $_POST[ 'crontype' ]; $cronstamp = implode( ",", $_POST[ 'cronminutes' ] ) . ' ' . implode( ",", $_POST[ 'cronhours' ] ) . ' ' . implode( ",", $_POST[ 'cronmday' ] ) . ' ' . implode( ",", $_POST[ 'cronmon' ] ) . ' ' . implode( ",", $_POST[ 'cronwday' ] ); $ajax = TRUE; } echo '';
if ( $crontype == 'advanced' ) {
echo str_replace( '\"','"', __( 'Working as Cron schedule:', 'backwpup' ) );
echo ' ' . esc_attr( $cronstamp ). '
';
}
list( $cronstr[ 'minutes' ], $cronstr[ 'hours' ], $cronstr[ 'mday' ], $cronstr[ 'mon' ], $cronstr[ 'wday' ] ) = explode( ' ', $cronstamp, 5 );
if ( FALSE !== strpos( $cronstr[ 'minutes' ], '*/' ) || $cronstr[ 'minutes' ] == '*' ) {
$repeatmins = str_replace( '*/', '', $cronstr[ 'minutes' ] );
if ( $repeatmins == '*' || empty( $repeatmins ) )
$repeatmins = 5;
echo '
';
}
$cron_next = BackWPup_Cron::cron_next( $cronstamp ) + ( get_option( 'gmt_offset' ) * 3600 );
if ( PHP_INT_MAX === $cron_next ) {
echo '
';
}
else {
_e( 'Next runtime:', 'backwpup' );
echo ' ' . date_i18n( 'D, j M Y, H:i', $cron_next, TRUE ) . '';
}
echo "