| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <?php if ( ! defined( 'ABSPATH' ) ) exit;
- /**
- * 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 array
- */
- var $errors = array();
- /**
- * @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;
- if ( ! WPN_Helper::is_func_disabled( 'ignore_user_abort' ) ) {
- 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'] )? esc_html( $_REQUEST['step'] ) : 'loading';
- // Get our total steps
- $this->total_steps = isset ( $_REQUEST['total_steps'] )? esc_html( $_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['errors'] = ( $this->errors ) ? $this->errors : FALSE;
- $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.
- }
- }
|