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
|
<?php /** * Class for performing actions incrementally. Internally used for converting submissions, exporting submissions, etc. * Very useful when interacting with large amounts of data. * * @package Ninja Forms * @subpackage Classes/Step Processing * @copyright Copyright (c) 2014, WPNINJAS * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License * @since 2.7.4 */
class NF_Step_Processing {
/** * @var action */ var $action = '';
/** * @var step */ var $step = '';
/** * @var total_steps */ var $total_steps = '';
/** * @var redirect */ var $redirect = '';
/** * @var args */ var $args = array();
/** * Get things rolling * * @since 2.7.4 * @return void */ function __construct() {
//Bail if we aren't in the admin. if ( ! is_admin() ) return false;
ignore_user_abort( true );
if ( ! nf_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { //set_time_limit( 0 ); }
add_action( 'wp_ajax_nf_' . $this->action, array( $this, 'processing' ) ); }
/** * Process our request. * Call the appropriate loading or step functions. * * @since 2.7.6 * @return void */ public function processing() {
// Get our passed arguments. These come from the querysting of the processing page. if ( isset ( $_REQUEST['args'] ) ) { $this->args = $_REQUEST['args']; if ( isset ( $this->args['redirect'] ) ) { $this->redirect = $this->args['redirect']; } } else { $this->args = array(); }
// Get our current step. $this->step = isset ( $_REQUEST['step'] )? $_REQUEST['step'] : 'loading';
// Get our total steps $this->total_steps = isset ( $_REQUEST['total_steps'] )? $_REQUEST['total_steps'] : 0;
// If our step is loading, then we need to return how many total steps there are along with the next step, which is 1. if ( 'loading' == $this->step ) { $return = $this->loading(); if ( ! isset ( $return['step'] ) ) { $saved_step = get_user_option( 'nf_step_processing_' . $this->action . '_step' ); if ( ! empty ( $saved_step ) ) { $this->step = $saved_step; } else { $this->step = 1; }
$return['step'] = $this->step; } if ( ! isset ( $return['complete'] ) ) { $return['complete'] = false; } } else { // We aren't on the loading step, so do our processing. $return = $this->step(); if ( ! isset ( $return['step'] ) ) { $this->step++; $return['step'] = $this->step; }
if ( ! isset ( $return['complete'] ) ) { if ( $this->step > $this->total_steps ) { $complete = true; } else { $complete = false; } $return['complete'] = $complete; }
$return['total_steps'] = $this->total_steps; }
$user_id = get_current_user_id();
if ( $return['complete'] ) { // Delete our step option delete_user_option( $user_id, 'nf_step_processing_' . $this->action . '_step' ); // Set our redirect variable. $return['redirect'] = $this->redirect; // Run our complete function $this->complete(); } else { // Save our current step so that we can resume if necessary update_user_option( $user_id, 'nf_step_processing_' . $this->action . '_step', $this->step ); }
if ( isset ( $this->redirect ) && ! empty ( $this->redirect ) ) { $this->args['redirect'] = $this->redirect; }
$return['args'] = $this->args;
echo json_encode( $return ); die();
}
/** * Run our loading process. * This function should be overwritten in child classes. * * @since 2.7.4 * @return array $args */ public function loading() { // This space left intentionally blank. }
/** * This function is called for every step. * This function should be overwritten in child classes. * * @since 2.7.4 * @return array $args */ public function step() { // This space left intentionally blank. }
/** * This function is called for every step. * This function should be overwritten in child classes. * * @since 2.7.4 * @return array $args */ public function complete() { // This space left intentionally blank. }
}
|