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' ); ?>
' . sprintf( esc_html__( '%1$s › Job: %2$s', 'backwpup' ), BackWPup::get_plugin_data( 'name' ), '' . esc_html( BackWPup_Option::get( $jobid, 'name' ) ) . '' ). ''; //default tabs $tabs = array( 'job' => array( 'name' => esc_html__( 'General', 'backwpup' ), 'display' => TRUE ), 'cron' => array( 'name' => __( 'Schedule', 'backwpup' ), 'display' => TRUE ) ); //add jobtypes to tabs $job_job_types = BackWPup_Option::get( $jobid, 'type' ); foreach ( $job_types as $typeid => $typeclass ) { $tabid = 'jobtype-' . strtolower( $typeid ); $tabs[ $tabid ][ 'name' ] = $typeclass->info[ 'name' ]; $tabs[ $tabid ][ 'display' ] = TRUE; if ( ! in_array( $typeid, $job_job_types, true ) ) $tabs[ $tabid ][ 'display' ] = FALSE; } //add destinations to tabs $jobdests = BackWPup_Option::get( $jobid, 'destinations' ); foreach ( $destinations as $destid => $dest ) { $tabid = 'dest-' . strtolower( $destid ); $tabs[ $tabid ][ 'name' ] = sprintf( __( 'To: %s', 'backwpup' ), $dest[ 'info' ][ 'name' ] ); $tabs[ $tabid ][ 'display' ] = TRUE; if ( ! in_array( $destid, $jobdests, true ) ) $tabs[ $tabid ][ 'display' ] = FALSE; } //display tabs echo ''; //display messages BackWPup_Admin::display_messages(); echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; wp_nonce_field( 'backwpupeditjob_page' ); wp_nonce_field( 'backwpup_ajax_nonce', 'backwpupajaxnonce', FALSE ); switch ( $_GET[ 'tab' ] ) { case 'job': ?>

$typeclass ) { $addclass = ''; if ( $typeclass->creates_file() ) { $addclass .= ' filetype'; } echo '

'; if ( ! empty( $typeclass->info[ 'help' ] ) ) { echo '
' . esc_attr( $typeclass->info[ 'help' ] ) . ''; } echo '

'; } ?>

Note: In order for backup file tracking to work, %hash% must be included anywhere in the archive name.', 'backwpup' ) ?>

' . esc_html__( 'Preview: ', 'backwpup' ) . '' . esc_attr( $archivename ) . '' . esc_attr( $archive_format_option ) . '

'; echo '

'; echo "" . esc_attr__( 'Replacement patterns:', 'backwpup' ) . "
"; echo esc_attr__( '%d = Two digit day of the month, with leading zeros', 'backwpup' ) . '
'; echo esc_attr__( '%j = Day of the month, without leading zeros', 'backwpup' ) . '
'; echo esc_attr__( '%m = Day of the month, with leading zeros', 'backwpup' ) . '
'; echo esc_attr__( '%n = Representation of the month (without leading zeros)', 'backwpup' ) . '
'; echo esc_attr__( '%Y = Four digit representation for the year', 'backwpup' ) . '
'; echo esc_attr__( '%y = Two digit representation of the year', 'backwpup' ) . '
'; echo esc_attr__( '%a = Lowercase ante meridiem (am) and post meridiem (pm)', 'backwpup' ) . '
'; echo esc_attr__( '%A = Uppercase ante meridiem (AM) and post meridiem (PM)', 'backwpup' ) . '
'; echo esc_attr__( '%B = Swatch Internet Time', 'backwpup' ) . '
'; echo esc_attr__( '%g = Hour in 12-hour format, without leading zeros', 'backwpup' ) . '
'; echo esc_attr__( '%G = Hour in 24-hour format, without leading zeros', 'backwpup' ) . '
'; echo esc_attr__( '%h = Hour in 12-hour format, with leading zeros', 'backwpup' ) . '
'; echo esc_attr__( '%H = Hour in 24-hour format, with leading zeros', 'backwpup' ) . '
'; echo esc_attr__( '%i = Two digit representation of the minute', 'backwpup' ) . '
'; echo esc_attr__( '%s = Two digit representation of the second', 'backwpup' ) . '
'; echo '

'; ?>

'; } else { echo '

'; echo '
' . esc_html(__( 'ZipArchive PHP class is missing, so BackWPUp will use PclZip instead.', 'backwpup' )) . '

'; } echo '

'; if ( function_exists( 'gzopen' ) ) { echo '

'; } else { echo '

'; echo '
' . esc_html(sprintf( __( 'Disabled due to missing %s PHP function.', 'backwpup' ), 'gzopen()' )) . '

'; } ?>

$dest ) { $syncclass = ''; if ( ! $dest[ 'can_sync' ] ) { $syncclass = 'nosync'; } echo '

'; } ?>




WP-CLI to run jobs from commandline.', 'backwpup' ); ?>

BackWPup_Option::get( $jobid, 'cron' ), 'crontype' => BackWPup_Option::get( $jobid, 'cronselect' ) ) ); ?> > >


'; if ( strstr( $_GET[ 'tab' ], 'dest-' ) ) { $dest_object = BackWPup::get_destination( str_replace( 'dest-', '', $_GET[ 'tab' ] ) ); $dest_object->edit_tab( $jobid ); } if ( strstr( $_GET[ 'tab' ], 'jobtype-' ) ) { $id = strtoupper( str_replace( 'jobtype-', '', $_GET[ 'tab' ] ) ); $job_types[ $id ]->edit_tab( $jobid ); } echo '
'; } echo '

'; 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 '' . sprintf( __( 'ATTENTION: Job runs every %d minutes!', 'backwpup' ), $repeatmins ) . '
'; } $cron_next = BackWPup_Cron::cron_next( $cronstamp ) + ( get_option( 'gmt_offset' ) * 3600 ); if ( PHP_INT_MAX === $cron_next ) { echo '' . __( 'ATTENTION: Can\'t calculate cron!', 'backwpup' ) . '
'; } else { _e( 'Next runtime:', 'backwpup' ); echo ' ' . date_i18n( 'D, j M Y, H:i', $cron_next, TRUE ) . ''; } echo "

"; if ( $ajax ) die(); else return; } }