class-wizard-job.php
32.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
<?php
/**
*
*/
class BackWPup_Pro_Wizard_Job extends BackWPup_Pro_Wizards {
private $destinations = array();
/**
*
*/
public function __construct() {
$this->info[ 'ID' ] = 'JOB';
$this->info[ 'name' ] = esc_html__( 'Create a job', 'backwpup' );
$this->info[ 'description' ] = esc_html__( 'Choose a job', 'backwpup' );
$this->info[ 'URI' ] = __( 'http://backwpup.com', 'backwpup' );
$this->info[ 'author' ] = 'Inpsyde GmbH';
$this->info[ 'authorURI' ] = __( 'http://inpsyde.com', 'backwpup' );
$this->info[ 'version' ] = BackWPup::get_plugin_data( 'Version' );
$this->info[ 'cap' ] = 'backwpup_jobs_edit';
$this->destinations = BackWPup::get_registered_destinations();
}
/**
* with steps has the wizard to to
*
* @param array $wizard_settings
*
* @return array
*/
public function get_steps( array $wizard_settings ) {
$job_types = BackWPup::get_job_types();
//generate steps
$steps = array();
if ( ! in_array( 'JOBTYPES', $wizard_settings[ 'wizard' ][ 'pre_config' ][ 'hide_steps' ], true ) )
$steps[] = array( 'id' => 'JOBTYPES', 'name' => esc_html__( 'Job Types', 'backwpup' ), 'description' => esc_html__( 'Select a task for your job.', 'backwpup' ) );
// generate job type steps
$job_crates_file = FALSE;
foreach ( $job_types as $id => $type ) {
if ( in_array( $id, $wizard_settings[ 'job_settings' ][ 'type' ], true ) ) {
if ( ! in_array( 'JOBTYPE-' . $id, $wizard_settings[ 'wizard' ][ 'pre_config' ][ 'hide_steps' ], true ) ) {
$steps[] = array( 'id' => 'JOBTYPE-' . $id,
'name' => $type->info[ 'name' ],
'description' => $type->info[ 'description' ]
);
}
if ( ! $job_crates_file ) {
$job_crates_file = $type->creates_file();
}
}
}
//steps when job creates files
if ( $job_crates_file ) {
if ( ! in_array( 'ARCHIVE', $wizard_settings[ 'wizard' ][ 'pre_config' ][ 'hide_steps' ], true ) ) {
$steps[] = array( 'id' => 'ARCHIVE',
'name' => esc_html__( 'Archive Settings', 'backwpup' ),
'description' => esc_html__( 'Settings for the Backup Archive', 'backwpup' )
);
}
if ( ! in_array( 'DESTINATIONS', $wizard_settings[ 'wizard' ][ 'pre_config' ][ 'hide_steps' ], true ) ) {
$steps[] = array( 'id' => 'DESTINATIONS',
'name' => esc_html__( 'Destinations', 'backwpup' ),
'description' => esc_html__( 'Where would you like to store the backup file?',
'backwpup' ),
'create' => FALSE
);
}
// generate destinations
if ( ! empty( $wizard_settings[ 'job_settings' ][ 'destinations' ] ) ) {
foreach ( $this->destinations as $id => $dest ) {
if ( in_array( $id, $wizard_settings[ 'job_settings' ][ 'destinations'], true ) && ! in_array( 'DEST-' . $id, $wizard_settings[ 'wizard' ][ 'pre_config' ][ 'hide_steps' ], true ) )
$steps[] = array( 'id' => 'DEST-' . $id, 'name' => $dest[ 'info' ][ 'name' ], 'description' => $dest[ 'info' ][ 'description' ] );
}
}
}
if ( ! in_array( 'SCHEDULE', $wizard_settings[ 'wizard' ][ 'pre_config' ][ 'hide_steps' ], true ) )
$steps[] = array( 'id' => 'SCHEDULE', 'name' => esc_html__( 'Scheduling', 'backwpup' ), 'description' => esc_html__( 'When would you like to start the job?', 'backwpup' ) );
return $steps;
}
/**
* Initiate Wizard Settings
*
* @param array $wizard_settings
*
* @return array
*/
public function initiate( array $wizard_settings ) {
// get job settings if a existing job opened
if ( empty( $wizard_settings[ 'job_settings' ] ) ) {
$wizard_settings[ 'job_settings' ] = BackWPup_Option::defaults_job();
if ( empty( $wizard_settings[ 'wizard' ][ 'pre_config' ] ) ) {
$wizard_settings[ 'wizard' ][ 'pre_config' ] = $this->get_pre_configurations( 'all' );
}
$wizard_settings[ 'job_settings' ] = array_merge( $wizard_settings[ 'job_settings' ],
$wizard_settings[ 'wizard' ][ 'pre_config' ][ 'job_settings' ] );
}
return $wizard_settings;
}
/**
* @param $wizard_settings
*/
public function admin_print_styles( array $wizard_settings ) {
//add css for all other steps
if ( strstr( $wizard_settings[ 'wizard' ][ 'step' ], 'DEST-' ) ) {
$dests_object = BackWPup::get_destination( str_replace( 'DEST-', '', $wizard_settings[ 'wizard' ][ 'step' ] ) );
$dests_object->wizard_admin_print_styles( );
}
elseif ( strstr( $wizard_settings[ 'wizard' ][ 'step' ], 'JOBTYPE-' ) ) {
$job_type = BackWPup::get_job_types();
$id = strtoupper( str_replace( 'JOBTYPE-', '', $wizard_settings[ 'wizard' ][ 'step' ] ) );
$job_type[ $id ]->wizard_admin_print_styles( );
}
}
/**
* called on page admin_print_scripts
*
* @param array $wizard_settings
*/
public function admin_print_scripts( array $wizard_settings ) {
//add js for the first step
if ( $wizard_settings[ 'wizard' ][ 'step' ] == '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 );
}
}
//add js for all other steps
elseif ( strstr( $wizard_settings[ 'wizard' ][ 'step' ], 'DEST-' ) ) {
$dests_object = BackWPup::get_destination( str_replace( 'DEST-', '', $wizard_settings[ 'wizard' ][ 'step' ] ) );
$dests_object->wizard_admin_print_scripts( );
}
elseif ( strstr( $wizard_settings[ 'wizard' ][ 'step' ], 'JOBTYPE-' ) ) {
$job_type = BackWPup::get_job_types();
$id = strtoupper( str_replace( 'JOBTYPE-', '', $wizard_settings[ 'wizard' ][ 'step' ] ) );
$job_type[ $id ]->wizard_admin_print_scripts( );
}
}
/**
* called on page inline_js
*
* @param array $wizard_settings
*/
public function inline_js( array $wizard_settings ) {
if ( $wizard_settings[ 'wizard' ][ 'step' ] == 'ARCHIVE' ) {
$this->inline_js_archive();
}
if ( $wizard_settings[ 'wizard' ][ 'step' ] == 'SCHEDULE' ) {
$this->inline_js_schedule();
}
// add inline js
if ( strstr( $wizard_settings[ 'wizard' ][ 'step' ], 'DEST-' ) ) {
$dests_object = BackWPup::get_destination( str_replace( 'DEST-', '', $wizard_settings[ 'wizard' ][ 'step' ] ) );
$dests_object->wizard_inline_js( );
}
if ( strstr( $wizard_settings[ 'wizard' ][ 'step' ], 'JOBTYPE-' ) ) {
$job_types = BackWPup::get_job_types();
$id = strtoupper( str_replace( 'JOBTYPE-', '', $wizard_settings[ 'wizard' ][ 'step' ] ) );
$job_types[ $id ]->wizard_inline_js( );
}
}
/**
* called on save
*
* @param array $wizard_settings
*
* @return array
*/
public function save( array $wizard_settings ) {
//call default wizard saves
if ( $wizard_settings[ 'wizard' ][ 'step' ] == 'JOBTYPES' ) {
$wizard_settings[ 'job_settings' ] = $this->save_jobtypes( $wizard_settings[ 'job_settings' ] );
} elseif ( $wizard_settings[ 'wizard' ][ 'step' ] == 'SCHEDULE' ) {
$wizard_settings[ 'job_settings' ] = $this->save_schedule( $wizard_settings[ 'job_settings' ] );
} elseif ( $wizard_settings[ 'wizard' ][ 'step' ] == 'DESTINATIONS' ) {
$wizard_settings[ 'job_settings' ] = $this->save_destinations( $wizard_settings[ 'job_settings' ] );
} elseif ( $wizard_settings[ 'wizard' ][ 'step' ] == 'ARCHIVE' ) {
$wizard_settings[ 'job_settings' ] = $this->save_archive( $wizard_settings[ 'job_settings' ] );
}
//call wizard saves for destination or jobtypes
elseif ( strstr( $wizard_settings[ 'wizard' ][ 'step' ], 'DEST-' ) ) {
$dests_object = BackWPup::get_destination( str_replace( 'DEST-', '', $wizard_settings[ 'wizard' ][ 'step' ] ) );
$wizard_settings[ 'job_settings' ] = $dests_object->wizard_save( $wizard_settings[ 'job_settings' ] );
}
elseif ( strstr( $wizard_settings[ 'wizard' ][ 'step' ], 'JOBTYPE-' ) ) {
$job_types = BackWPup::get_job_types();
$id = strtoupper( str_replace( 'JOBTYPE-', '', $wizard_settings[ 'wizard' ][ 'step' ] ) );
$wizard_settings[ 'job_settings' ] = $job_types[ $id ]->wizard_save( $wizard_settings[ 'job_settings' ] );
}
return $wizard_settings;
}
/**
* called on wizard page
*
* @param array $wizard_settings
*/
public function page( array $wizard_settings ) {
//call default wizard pages
if ( $wizard_settings[ 'wizard' ][ 'step' ] == 'JOBTYPES' )
$this->page_jobtypes( $wizard_settings[ 'job_settings' ] );
elseif ( $wizard_settings[ 'wizard' ][ 'step' ] == 'SCHEDULE' )
$this->page_schedule( $wizard_settings[ 'job_settings' ] );
elseif ( $wizard_settings[ 'wizard' ][ 'step' ] == 'DESTINATIONS' )
$this->page_destinations( $wizard_settings[ 'job_settings' ] );
elseif ( $wizard_settings[ 'wizard' ][ 'step' ] == 'ARCHIVE' )
$this->page_archive( $wizard_settings[ 'job_settings' ] );
//call wizard pages for destination or jobtypes
elseif ( strstr( $wizard_settings[ 'wizard' ][ 'step' ], 'DEST-' ) ) {
$dests_object = BackWPup::get_destination( str_replace( 'DEST-', '', $wizard_settings[ 'wizard' ][ 'step' ] ) );
$dests_object->wizard_page( $wizard_settings[ 'job_settings' ] );
}
elseif ( strstr( $wizard_settings[ 'wizard' ][ 'step' ], 'JOBTYPE-' ) ) {
$job_types = BackWPup::get_job_types();
$id = strtoupper( str_replace( 'JOBTYPE-', '', $wizard_settings[ 'wizard' ][ 'step' ] ) );
$job_types[ $id ]->wizard_page( $wizard_settings[ 'job_settings' ] );
}
}
/**
* called on wizard page jobtypes
*
* @param array $job_settings
*/
public function page_jobtypes( array $job_settings ) {
$job_types = BackWPup::get_job_types();
?>
<table class="form-table">
<tr>
<td>
<h3 class="title"><?php esc_html_e( 'This job is a …', 'backwpup' ) ?></h3>
<p><?php esc_html_e('Select one or more tasks for your backup job.','backwpup'); ?></p>
<fieldset>
<legend class="screen-reader-text"><span><?php esc_html_e( 'Job tasks', 'backwpup' ) ?></span></legend>
<?php
foreach ( $job_types as $id => $typeclass ) {
$addclass = '';
if ( $typeclass->creates_file( ) ) {
$addclass = ' filetype';
}
echo '<label for="jobtype-select-' . strtolower( $id ) . '"><input class="jobtype-select checkbox' . esc_attr( $addclass ) . '" id="jobtype-select-' . strtolower( $id ) . '" type="checkbox"' . checked( TRUE, in_array( $id, $job_settings[ 'type' ], true ), FALSE ) . ' name="type[]" value="' . $id . '" /> ' . esc_html( $typeclass->info[ 'description' ] ) . '</label><br />';
}
?>
</fieldset>
</td>
</tr>
</table>
<?php
}
/**
* called on wizard page schedule
*
* @param array $job_settings
*/
public function page_schedule( array $job_settings ) {
list( $cronstr[ 'minutes' ], $cronstr[ 'hours' ], $cronstr[ 'mday' ], $cronstr[ 'mon' ], $cronstr[ 'wday' ] ) = explode( ' ',
$job_settings[ 'cron' ],
5 );
if ( strstr( $cronstr[ 'minutes' ], '*/' ) ) {
$minutes = explode( '/', $cronstr[ 'minutes' ] );
} else {
$minutes = explode( ',', $cronstr[ 'minutes' ] );
}
if ( strstr( $cronstr[ 'hours' ], '*/' ) ) {
$hours = explode( '/', $cronstr[ 'hours' ] );
} else {
$hours = explode( ',', $cronstr[ 'hours' ] );
}
if ( strstr( $cronstr[ 'mday' ], '*/' ) ) {
$mday = explode( '/', $cronstr[ 'mday' ] );
} else {
$mday = explode( ',', $cronstr[ 'mday' ] );
}
if ( strstr( $cronstr[ 'mon' ], '*/' ) ) {
$mon = explode( '/', $cronstr[ 'mon' ] );
} else {
$mon = explode( ',', $cronstr[ 'mon' ] );
}
if ( strstr( $cronstr[ 'wday' ], '*/' ) ) {
$wday = explode( '/', $cronstr[ 'wday' ] );
} else {
$wday = explode( ',', $cronstr[ 'wday' ] );
}
?>
<table class="form-table">
<tr>
<td>
<h3 class="title"><?php esc_html_e( 'Scheduling', 'backwpup' ); ?></h3>
<label for="activetype"><input type="checkbox" id="activetype" <?php checked( $job_settings[ 'activetype' ], 'wpcron', TRUE ); ?> name="activetype" value="wpcron" /> <?php esc_html_e( 'Activate scheduling', 'backwpup') ?></label><br />
</td>
</tr>
<tr>
<td class="table_planung">
<h3 class="title hasdests scheduler"><?php esc_html_e( 'Scheduler', 'backwpup' ); ?></h3>
<table id="wpcronbasic" class="scheduler">
<tr>
<th>
<?php esc_html_e( 'Type', 'backwpup' ); ?>
</th>
<th>
</th>
<th>
<?php esc_html_e( 'Hour', 'backwpup' ); ?>
</th>
<th>
<?php esc_html_e( 'Minute', 'backwpup' ); ?>
</th>
</tr>
<tr>
<td><label for="idcronbtype-mon"><?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $mday[ 0 ] ), FALSE ) . ' name="cronbtype" id="idcronbtype-mon" value="mon" /> ' . esc_html__( 'monthly', 'backwpup' ); ?></label></td>
<td><select name="moncronmday"><?php for ( $i = 1; $i <= 31; $i ++ ) {
echo '<option ' . selected( in_array( "$i", $mday, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . esc_html__( 'on', 'backwpup' ) . ' ' . $i . '</option>';
} ?></select></td>
<td><select name="moncronhours"><?php for ( $i = 0; $i < 24; $i ++ ) {
echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
} ?></select></td>
<td><select name="moncronminutes"><?php for ( $i = 0; $i < 60; $i = $i + 10 ) {
echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
} ?></select></td>
</tr>
<tr>
<td><label for="idcronbtype-week"><?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $wday[ 0 ] ), FALSE ) . ' name="cronbtype" id="idcronbtype-week" value="week" /> ' . esc_html__( 'weekly', 'backwpup' ); ?></label></td>
<td><select name="weekcronwday">
<?php echo '<option ' . selected( in_array( "0", $wday, TRUE ), TRUE, FALSE ) . ' value="0" />' . esc_html__( 'Sunday', 'backwpup' ) . '</option>';
echo '<option ' . selected( in_array( "1", $wday, TRUE ), TRUE, FALSE ) . ' value="1" />' . esc_html__( 'Monday', 'backwpup' ) . '</option>';
echo '<option ' . selected( in_array( "2", $wday, TRUE ), TRUE, FALSE ) . ' value="2" />' . esc_html__( 'Tuesday', 'backwpup' ) . '</option>';
echo '<option ' . selected( in_array( "3", $wday, TRUE ), TRUE, FALSE ) . ' value="3" />' . esc_html__( 'Wednesday', 'backwpup' ) . '</option>';
echo '<option ' . selected( in_array( "4", $wday, TRUE ), TRUE, FALSE ) . ' value="4" />' . esc_html__( 'Thursday', 'backwpup' ) . '</option>';
echo '<option ' . selected( in_array( "5", $wday, TRUE ), TRUE, FALSE ) . ' value="5" />' . esc_html__( 'Friday', 'backwpup' ) . '</option>';
echo '<option ' . selected( in_array( "6", $wday, TRUE ), TRUE, FALSE ) . ' value="6" />' . esc_html__( 'Saturday', 'backwpup' ) . '</option>'; ?>
</select></td>
<td><select name="weekcronhours"><?php for ( $i = 0; $i < 24; $i ++ ) {
echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
} ?></select></td>
<td><select name="weekcronminutes"><?php for ( $i = 0; $i < 60; $i = $i + 10 ) {
echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
} ?></select></td>
</tr>
<tr>
<td><label for="idcronbtype-day"><?php echo '<input class="radio" type="radio"' . checked( "**", $mday[ 0 ] . $wday[ 0 ], FALSE ) . ' name="cronbtype" id="idcronbtype-day" value="day" /> ' . esc_html__( 'daily', 'backwpup' ); ?></label></td>
<td></td>
<td><select name="daycronhours"><?php for ( $i = 0; $i < 24; $i ++ ) {
echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
} ?></select></td>
<td><select name="daycronminutes"><?php for ( $i = 0; $i < 60; $i = $i + 10 ) {
echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
} ?></select></td>
</tr>
<tr>
<td><label for="idcronbtype-hour"><?php echo '<input class="radio" type="radio"' . checked( "*", $hours[ 0 ], FALSE, FALSE ) . ' name="cronbtype" id="idcronbtype-hour" value="hour" /> ' . esc_html__( 'hourly', 'backwpup' ); ?></label></td>
<td></td>
<td></td>
<td><select name="hourcronminutes"><?php for ( $i = 0; $i < 60; $i = $i + 10 ) {
echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
} ?></select></td>
</tr>
</table>
</td>
</tr>
</table>
<?php
}
/**
* called on wizard page archive
*
* @param array $job_settings
*/
public function page_archive( array $job_settings ) {
?>
<table class="form-table">
<tr>
<td>
<h3 class="title hasdests"><?php esc_html_e( 'Backup type', 'backwpup' ); ?></h3>
<p class="hasdests"></p>
<fieldset>
<legend class="screen-reader-text"><?php esc_html_e( 'Backup type', 'backwpup' ) ?></legend>
<label for="backuptype-sync"><input class="radio"
type="radio"<?php checked( 'sync', $job_settings[ 'backuptype' ], TRUE ); ?>
name="backuptype" id="backuptype-sync"
value="sync"/> <?php esc_html_e( 'Sync file by file to destination', 'backwpup' ); ?></label><br/>
<label for="backuptype-archive"><input class="radio"
type="radio"<?php checked( 'archive', $job_settings[ 'backuptype' ], TRUE ); ?>
name="backuptype" id="backuptype-archive"
value="archive"/> <?php esc_html_e( 'Create a backup archive', 'backwpup' ); ?></label><br/>
</fieldset>
</td>
</tr>
<tr class="archive">
<td>
<h3 class="title hasdests"><?php esc_html_e( 'Select a compression type for the backup archive', 'backwpup' ) ?></h3>
<p class="hasdests"></p>
<fieldset>
<legend class="screen-reader-text"><?php esc_html_e( 'Archive compression type', 'backwpup' ) ?></legend>
<?php
if ( class_exists( 'ZipArchive' ) ) {
echo '<label for="idarchiveformat-zip"><input class="radio" type="radio"' . checked( '.zip', $job_settings[ 'archiveformat' ],FALSE ) . ' name="archiveformat" id="idarchiveformat-zip" value=".zip" /> ' . esc_html__( 'Zip','backwpup' ) . '</label><br />';
echo '<p class="description">' . esc_html__( 'PHP Zip functions will be used if available (memory lees). Else PCLZip Class will used.','backwpup' ) . '</p>';
}else {
echo '<label for="idarchiveformat-zip"><input class="radio " type="radio"' . checked( '.zip', $job_settings[ 'archiveformat' ], FALSE ) . ' name="archiveformat" id="idarchiveformat-zip" value=".zip" disabled="disabled" /> ' . esc_html__( 'Zip', 'backwpup' ) . '</label><br />';
echo '<p class="description">' . esc_html__( 'Disabled because missing PHP function.','backwpup' ) . '</p>';
}
echo '<label for="idarchiveformat-tar"><input class="radio" type="radio"' . checked( '.tar', $job_settings[ 'archiveformat' ], FALSE ) . ' name="archiveformat" id="idarchiveformat-tar" value=".tar" title="' . esc_attr__( 'Tar (fast and memory less) uncompressed', 'backwpup' ) . '" /> ' . esc_html__( 'Tar', 'backwpup' ) . '</label><br />';
echo '<p class="description">' . esc_html__('Tar (fast and memory less) uncompressed', 'backwpup' ) . '</p>';
if ( function_exists( 'gzopen' ) ) {
echo '<label for="idarchiveformat-targz"><input class="radio" type="radio"' . checked( '.tar.gz', $job_settings[ 'archiveformat' ],FALSE ) . ' name="archiveformat" id="idarchiveformat-targz" value=".tar.gz" title="' . esc_attr__( 'A tared and GZipped archive (fast and memory less)', 'backwpup' ) . '" /> ' . esc_html__( 'Tar GZip','backwpup' ) . '</label><br />';
echo '<p class="description">' . esc_html__( 'A tared and GZipped archive (fast and memory less)', 'backwpup' ) . '</p>';
}else {
echo '<label for="idarchiveformat-targz"><input class="radio" type="radio "' . checked( '.tar.gz', $job_settings[ 'archiveformat' ], FALSE ) . ' name="archiveformat" id="idarchiveformat-targz" value=".tar.gz" disabled="disabled" /> ' . esc_html__( 'Tar GZip','backwpup' ) . '</label><br />';
echo '<p class="description">' . esc_html__( 'Disabled because missing PHP function.', 'backwpup' ) . '</p>';
}
if ( function_exists( 'bzopen' ) ) {
echo '<label for="idarchiveformat-tarbz2"><input class="radio" type="radio"' . checked( '.tar.bz2',$job_settings[ 'archiveformat' ],FALSE ) . ' name="archiveformat" id="idarchiveformat-tarbz2" value=".tar.bz2" /> ' . esc_html__( 'Tar BZip2', 'backwpup' ) . '</label><br />';
echo '<p class="description">' . esc_html__( 'A tared and BZipped archive (fast and memory less)', 'backwpup' ) . '</p>';
} else {
echo '<label for="idarchiveformat-tarbz2"><input class="radio" type="radio"' . checked( '.tar.bz2', $job_settings[ 'archiveformat' ], FALSE ) . ' name="archiveformat" id="idarchiveformat-tarbz2" value=".tar.bz2" disabled="disabled" /> ' . esc_html__( 'Tar BZip2','backwpup' ) . '</label><br />';
}
echo '<p class="description">' . esc_html__('Disabled because missing PHP function.', 'backwpup' ) . '</p>';
?>
</fieldset>
</td>
</tr>
</table>
<?php
}
/**
* called on wizard page destinations
*
* @param array $job_settings
*/
public function page_destinations( array $job_settings ) {
?>
<table class="form-table">
<tr>
<td>
<h3 class="title"><?php esc_html_e( 'Where to store the files', 'backwpup' ) ?></h3>
<p></p>
<fieldset>
<legend class="screen-reader-text"><?php esc_html_e( 'Destinations', 'backwpup' ) ?></legend>
<?php
foreach ( $this->destinations as $id => $dest ) {
if ( $job_settings[ 'backuptype' ] == 'archive' || ( $job_settings[ 'backuptype' ] == 'sync' && $dest[ 'can_sync' ] ) ) {
echo '<label for="dest-select-' . strtolower( $id ) . '">';
if ( ! empty( $dest[ 'error' ] ) ) {
echo '<span class="description">' . esc_html( $dest[ 'error' ] ) . '</span><br />';
}
echo '<input class="checkbox" id="dest-select-' . strtolower( $id ) . '" type="checkbox"' . checked( TRUE, in_array( $id, $job_settings[ 'destinations' ], true ), FALSE ) . ' name="destinations[]" value="' . esc_attr( $id ) . '" ' . disabled( ! empty( $dest[ 'error' ] ), TRUE, FALSE ) . ' /> ' . esc_html( $dest[ 'info' ][ 'description' ] ) . '</label><br />';
}
}
?>
</fieldset>
</td>
</tr>
</table>
<?php
}
/**
* @param $job_settings
*
* @return array
*/
public function save_jobtypes( array $job_settings ) {
$job_types = BackWPup::get_job_types();
if ( isset( $_POST[ 'type' ] ) && is_array( $_POST[ 'type' ] ) ) {
foreach ( (array) $_POST[ 'type' ] as $typeid ) {
if ( empty( $job_types[ $typeid ] ) ) {
unset( $_POST[ 'type' ][ $typeid ] );
}
}
if ( is_array( $_POST[ 'type' ] ) ) {
sort( $_POST[ 'type' ] );
}
} else {
$_POST[ 'type' ] = array();
}
$job_settings[ 'type' ] = $_POST[ 'type' ];
$creates_file = FALSE;
foreach ( $job_settings[ 'type' ] as $type ) {
if ( $job_types[ $type ]->creates_file() ) {
$creates_file = TRUE;
break;
}
}
if ( ! $creates_file ) {
$job_settings[ 'destinations' ] = array();
}
return $job_settings;
}
/**
* @param $job_settings
*
* @return array
*/
public function save_schedule( array $job_settings ) {
if ( isset( $_POST[ 'activetype' ] ) ) {
$job_settings[ 'activetype' ] = ( $_POST[ 'activetype' ] == 'wpcron' ) ? 'wpcron' : '';
} else {
$job_settings[ 'activetype' ] = '';
}
$job_settings[ 'cronselect' ] = 'basic';
if ( $_POST[ 'cronbtype' ] === 'mon' ) {
$job_settings[ 'cron' ] = $_POST[ 'moncronminutes' ] . ' ' . $_POST[ 'moncronhours' ] . ' ' . $_POST[ 'moncronmday' ] . ' * *';
}
if ( $_POST[ 'cronbtype' ] === 'week' ) {
$job_settings[ 'cron' ] = $_POST[ 'weekcronminutes' ] . ' ' . $_POST[ 'weekcronhours' ] . ' * * ' . $_POST[ 'weekcronwday' ];
}
if ( $_POST[ 'cronbtype' ] === 'day' ) {
$job_settings[ 'cron' ] = $_POST[ 'daycronminutes' ] . ' ' . $_POST[ 'daycronhours' ] . ' * * *';
}
if ( $_POST[ 'cronbtype' ] === 'hour' ) {
$job_settings[ 'cron' ] = $_POST[ 'hourcronminutes' ] . ' * * * *';
}
return $job_settings;
}
/**
* @param $job_settings
*
* @return array
*/
public function save_destinations( array $job_settings ) {
if ( isset( $_POST[ 'destinations' ] ) && is_array( $_POST[ 'destinations' ] ) ) {
foreach ( (array) $_POST[ 'destinations' ] as $dst_id ) {
if ( empty( $this->destinations[ $dst_id ] ) ) {
unset( $_POST[ 'destinations' ][ $dst_id ] );
}
}
if ( is_array( $_POST[ 'destinations' ] ) ) {
sort( $_POST[ 'destinations' ] );
}
} else {
$_POST[ 'destinations' ] = array();
}
$job_settings[ 'destinations' ] = $_POST[ 'destinations' ];
return $job_settings;
}
/**
* @param $job_settings
*
* @return array
*/
public function save_archive( array $job_settings ) {
$job_settings[ 'archiveformat' ] = $_POST[ 'archiveformat' ];
$job_settings[ 'archivename' ] = 'backwpup_' . BackWPup::get_plugin_data( 'hash' ) . '_%Y-%m-%d_%H-%i-%s';
$job_settings[ 'backuptype' ] = $_POST[ 'backuptype' ];
return $job_settings;
}
public function inline_js_archive() {
?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$('input[name="backuptype"]').change(function () {
if ($(this).val() == 'sync') {
$('.archive').hide();
$('.sync').show();
} else {
$('.archive').show();
$('.sync').hide();
}
});
if ($('input[name="backuptype"]:checked').val() == 'sync') {
$('.archive').hide();
$('.sync').show();
} else {
$('.archive').show();
$('.sync').hide();
}
});
</script>
<?php
}
public function inline_js_schedule() {
?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$('input[name="activetype"]').change(function () {
if ($(this).prop("checked")) {
$('.scheduler').show();
} else {
$('.scheduler').hide();
}
});
if ($('input[name="activetype"]').prop("checked")) {
$('.scheduler').show();
} else {
$('.scheduler').hide();
}
});
</script>
<?php
}
/**
* called if last button clicked
*
* @param array $wizard_settings
*/
public function execute( array $wizard_settings ) {
//get new jobid for new jobs
$exsitingjobids = BackWPup_Option::get_job_ids();
sort( $exsitingjobids );
$wizard_settings[ 'job_settings' ][ 'jobid' ] = end( $exsitingjobids ) + 1;
// set job name
$wizard_settings[ 'job_settings' ][ 'name' ] = sprintf( esc_html__('Wizard: %1$s','backwpup'), $wizard_settings[ 'wizard' ][ 'pre_config' ][ 'name'] );
//some default settings
$wizard_settings[ 'job_settings' ][ 'mailaddresslog' ] = sanitize_email( get_bloginfo( 'admin_email' ) );
$wizard_settings[ 'job_settings' ][ 'mailerroronly' ] = TRUE;
//reschedule job
$cron_next = BackWPup_Cron::cron_next( $wizard_settings[ 'job_settings' ][ 'cron' ] ) ;
wp_clear_scheduled_hook( 'backwpup_cron', array( 'id' => $wizard_settings[ 'job_settings' ][ 'jobid' ] ) );
if ( $wizard_settings[ 'job_settings' ][ 'activetype' ]== 'wpcron' ) {
wp_schedule_single_event( $cron_next, 'backwpup_cron', array( 'id' => $wizard_settings[ 'job_settings' ][ 'jobid' ] ) );
}
// save
foreach ( $wizard_settings[ 'job_settings' ] as $option_name => $option_value ) {
BackWPup_Option::update( $wizard_settings[ 'job_settings' ][ 'jobid' ], $option_name, $option_value );
}
//text
echo '<div id="message" class="updated below-h2"><p>' . sprintf( esc_html__( 'New job %s generated.', 'backwpup'),$wizard_settings[ 'job_settings' ][ 'name' ] ) . '</p></div>';
}
/**
* The name of the last button (execute button)
*
* @param $wizard_settings
* @return string
*/
public function get_last_button_name( array $wizard_settings ) {
return esc_html__( 'Create Job', 'backwpup' );
}
/**
* Should the wizard run step by step or can yup between steps
*
* @param $wizard_settings
* @return bool
*/
public function is_step_by_step( array $wizard_settings ) {
return TRUE;
}
/**
* Set Pre configurations
*
* @param null $id
* @return array
*/
public function get_pre_configurations( $id = NULL ) {
global $wpdb;
/* @var wpdb $wpdb */
//pre config for Database backup
$pre_configurations[ 'db' ][ 'name' ] = esc_html__( 'Database Backup and XML Export (Daily)', 'backwpup');
$pre_configurations[ 'db' ][ 'description' ] = esc_html__( 'Database Backup and XML Export (Daily)', 'backwpup');
//get tables that should not uses on DB configs
$dbdumpexclude = array();
$dbtables = $wpdb->get_results( 'SHOW TABLES FROM `' . DB_NAME . '`', ARRAY_N );
foreach ( $dbtables as $dbtable) {
if ( ! strstr( $dbtable[ 0 ], $wpdb->prefix) )
$dbdumpexclude[] = $dbtable[ 0 ];
}
$pre_configurations[ 'db' ][ 'job_settings' ] = array(
'type' => array( 'DBDUMP', 'WPEXP' ),
'dbdumpexclude' => $dbdumpexclude,
'cron' => '0 1 * * *',
'activetype' => 'wpcron'
);
$pre_configurations[ 'db' ][ 'hide_steps' ] = array( 'JOBTYPES', 'JOBTYPE-DBDUMP', 'JOBTYPE-WPEXP', 'SCHEDULE' );
//pre config for Database Check and optimize
$pre_configurations[ 'dbchop' ][ 'name' ] = esc_html__( 'Database Check (Weekly)', 'backwpup');
$pre_configurations[ 'dbchop' ][ 'description' ] = esc_html__( 'Database Check (Weekly)', 'backwpup');
$pre_configurations[ 'dbchop' ][ 'job_settings' ] = array(
'type' => array( 'DBCHECK' ),
'cron' => '30 3 * * 1',
'activetype' => 'wpcron'
);
$pre_configurations[ 'dbchop' ][ 'hide_steps' ] = array( 'JOBTYPES', 'JOBTYPE-DBCHECK', 'SCHEDULE' );
//pre config for uploads backup
$pre_configurations[ 'upfile' ][ 'name' ] = esc_html__( 'Backup uploads folder', 'backwpup');
$pre_configurations[ 'upfile' ][ 'description' ] = esc_html__( 'Backup uploads folder', 'backwpup');
$pre_configurations[ 'upfile' ][ 'job_settings' ] = array(
'type' => array( 'FILE' ),
'backupexcludethumbs' => FALSE,
'backupspecialfiles' => FALSE,
'backuproot' => FALSE,
'backupcontent' => FALSE,
'backupplugins' => FALSE,
'backupthemes' => FALSE,
'backupuploads' => TRUE
);
$pre_configurations[ 'upfile' ][ 'hide_steps' ] = array( 'JOBTYPES', 'JOBTYPE-FILE' );
//pre config for all file backup
$pre_configurations[ 'file' ][ 'name' ] = esc_html__( 'Backup all files', 'backwpup');
$pre_configurations[ 'file' ][ 'description' ] = esc_html__( 'Backup all files', 'backwpup');
$pre_configurations[ 'file' ][ 'job_settings' ] = array(
'type' => array( 'FILE' ),
'backupexcludethumbs' => FALSE,
'backupspecialfiles' => TRUE,
'backuproot' => TRUE,
'backupcontent' => TRUE,
'backupplugins' => TRUE,
'backupthemes' => TRUE,
'backupuploads' => TRUE
);
$pre_configurations[ 'file' ][ 'hide_steps' ] = array( 'JOBTYPES', 'JOBTYPE-FILE' );
//pre config for Needed files backup
$pre_configurations[ 'neddedfile' ][ 'name' ] = esc_html__( 'Essential files + list of plugins', 'backwpup');
$pre_configurations[ 'neddedfile' ][ 'description' ] = esc_html__( 'Backup essential files and folders, plus a list of installed plugins.', 'backwpup');
$pre_configurations[ 'neddedfile' ][ 'job_settings' ] = array(
'type' => array( 'FILE', 'WPPLUGIN' ),
'backupexcludethumbs' => TRUE,
'backupspecialfiles' => TRUE,
'backuproot' => FALSE,
'backuprootexcludedirs' => array( 'wp-includes', 'wp-admin' ),
'backupcontent' => TRUE,
'backupplugins' => FALSE,
'backupthemes' => TRUE,
'backupuploads' => TRUE
);
$pre_configurations[ 'neddedfile' ][ 'hide_steps' ] = array( 'JOBTYPES', 'JOBTYPE-FILE', 'JOBTYPE-WPPLUGIN' );
//Pre config where all must done self
$pre_configurations[ 'all' ][ 'name' ] = esc_html__( 'Custom configuration', 'backwpup');
$pre_configurations[ 'all' ][ 'description' ] = esc_html__( 'Custom configuration', 'backwpup');
$pre_configurations[ 'all' ][ 'job_settings' ] = array();
$pre_configurations[ 'all' ][ 'hide_steps' ] = array( 'WPPLUGIN' );
if ( $id == NULL ) {
$pre_configurations_names = array();
foreach ( $pre_configurations as $id => $values )
$pre_configurations_names[ $id ] = $values[ 'name' ];
return $pre_configurations_names;
} else {
return $pre_configurations[ $id ];
}
}
}