Completed
Branch BUG/batch-strings-overridden (01c612)
by
unknown
09:40 queued 52s
created
modules/batch/EED_Batch.module.php 2 patches
Indentation   +309 added lines, -309 removed lines patch added patch discarded remove patch
@@ -25,335 +25,335 @@
 block discarded – undo
25 25
 class EED_Batch extends EED_Module
26 26
 {
27 27
 
28
-    /**
29
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
30
-     * processes data only
31
-     */
32
-    const batch_job = 'job';
33
-    /**
34
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
35
-     * produces a file for download
36
-     */
37
-    const batch_file_job = 'file';
38
-    /**
39
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT
40
-     * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ]
41
-     * at all
42
-     */
43
-    const batch_not_job = 'none';
28
+	/**
29
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
30
+	 * processes data only
31
+	 */
32
+	const batch_job = 'job';
33
+	/**
34
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
35
+	 * produces a file for download
36
+	 */
37
+	const batch_file_job = 'file';
38
+	/**
39
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT
40
+	 * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ]
41
+	 * at all
42
+	 */
43
+	const batch_not_job = 'none';
44 44
 
45
-    /**
46
-     *
47
-     * @var string 'file', or 'job', or false to indicate its not a batch request at all
48
-     */
49
-    protected $_batch_request_type = null;
45
+	/**
46
+	 *
47
+	 * @var string 'file', or 'job', or false to indicate its not a batch request at all
48
+	 */
49
+	protected $_batch_request_type = null;
50 50
 
51
-    /**
52
-     * Because we want to use the response in both the localized JS and in the body
53
-     * we need to make this response available between method calls
54
-     *
55
-     * @var \EventEspressoBatchRequest\Helpers\JobStepResponse
56
-     */
57
-    protected $_job_step_response = null;
51
+	/**
52
+	 * Because we want to use the response in both the localized JS and in the body
53
+	 * we need to make this response available between method calls
54
+	 *
55
+	 * @var \EventEspressoBatchRequest\Helpers\JobStepResponse
56
+	 */
57
+	protected $_job_step_response = null;
58 58
 
59
-    /**
60
-     * Gets the batch instance
61
-     *
62
-     * @return EED_Batch
63
-     */
64
-    public static function instance()
65
-    {
66
-        return self::get_instance();
67
-    }
59
+	/**
60
+	 * Gets the batch instance
61
+	 *
62
+	 * @return EED_Batch
63
+	 */
64
+	public static function instance()
65
+	{
66
+		return self::get_instance();
67
+	}
68 68
 
69
-    /**
70
-     * Sets hooks to enable batch jobs on the frontend. Disabled by default
71
-     * because it's an attack vector and there are currently no implementations
72
-     */
73
-    public static function set_hooks()
74
-    {
75
-        // because this is a possibel attack vector, let's have this disabled until
76
-        // we at least have a real use for it on the frontend
77
-        if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) {
78
-            add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts'));
79
-            add_filter('template_include', array(self::instance(), 'override_template'), 99);
80
-        }
81
-    }
69
+	/**
70
+	 * Sets hooks to enable batch jobs on the frontend. Disabled by default
71
+	 * because it's an attack vector and there are currently no implementations
72
+	 */
73
+	public static function set_hooks()
74
+	{
75
+		// because this is a possibel attack vector, let's have this disabled until
76
+		// we at least have a real use for it on the frontend
77
+		if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) {
78
+			add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts'));
79
+			add_filter('template_include', array(self::instance(), 'override_template'), 99);
80
+		}
81
+	}
82 82
 
83
-    /**
84
-     * Initializes some hooks for the admin in order to run batch jobs
85
-     */
86
-    public static function set_hooks_admin()
87
-    {
88
-        add_action('admin_menu', array(self::instance(), 'register_admin_pages'));
89
-        add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts'));
83
+	/**
84
+	 * Initializes some hooks for the admin in order to run batch jobs
85
+	 */
86
+	public static function set_hooks_admin()
87
+	{
88
+		add_action('admin_menu', array(self::instance(), 'register_admin_pages'));
89
+		add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts'));
90 90
 
91
-        // ajax
92
-        add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue'));
93
-        add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup'));
94
-        add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue'));
95
-        add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup'));
96
-    }
91
+		// ajax
92
+		add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue'));
93
+		add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup'));
94
+		add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue'));
95
+		add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup'));
96
+	}
97 97
 
98
-    /**
99
-     * Enqueues batch scripts on the frontend or admin, and creates a job
100
-     */
101
-    public function enqueue_scripts()
102
-    {
103
-        if (isset($_REQUEST['espresso_batch'])
104
-            ||
105
-            (
106
-                isset($_REQUEST['page'])
107
-                && $_REQUEST['page'] == 'espresso_batch'
108
-            )
109
-        ) {
110
-            switch ($this->batch_request_type()) {
111
-                case self::batch_job:
112
-                    $this->enqueue_scripts_styles_batch_create();
113
-                    break;
114
-                case self::batch_file_job:
115
-                    $this->enqueue_scripts_styles_batch_file_create();
116
-                    break;
117
-            }
118
-        }
119
-    }
98
+	/**
99
+	 * Enqueues batch scripts on the frontend or admin, and creates a job
100
+	 */
101
+	public function enqueue_scripts()
102
+	{
103
+		if (isset($_REQUEST['espresso_batch'])
104
+			||
105
+			(
106
+				isset($_REQUEST['page'])
107
+				&& $_REQUEST['page'] == 'espresso_batch'
108
+			)
109
+		) {
110
+			switch ($this->batch_request_type()) {
111
+				case self::batch_job:
112
+					$this->enqueue_scripts_styles_batch_create();
113
+					break;
114
+				case self::batch_file_job:
115
+					$this->enqueue_scripts_styles_batch_file_create();
116
+					break;
117
+			}
118
+		}
119
+	}
120 120
 
121
-    /**
122
-     * Create a batch job, enqueues a script to run it, and localizes some data for it
123
-     */
124
-    public function enqueue_scripts_styles_batch_create()
125
-    {
126
-        $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
127
-        wp_enqueue_script(
128
-            'batch_runner_init',
129
-            BATCH_URL . 'assets/batch_runner_init.js',
130
-            array('batch_runner'),
131
-            EVENT_ESPRESSO_VERSION,
132
-            true
133
-        );
134
-        wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array());
135
-        wp_localize_script(
136
-            'batch_runner_init',
137
-            'ee_job_i18n',
138
-            array(
139
-                'return_url' => $_REQUEST['return_url'],
140
-            )
141
-        );
142
-    }
121
+	/**
122
+	 * Create a batch job, enqueues a script to run it, and localizes some data for it
123
+	 */
124
+	public function enqueue_scripts_styles_batch_create()
125
+	{
126
+		$job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
127
+		wp_enqueue_script(
128
+			'batch_runner_init',
129
+			BATCH_URL . 'assets/batch_runner_init.js',
130
+			array('batch_runner'),
131
+			EVENT_ESPRESSO_VERSION,
132
+			true
133
+		);
134
+		wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array());
135
+		wp_localize_script(
136
+			'batch_runner_init',
137
+			'ee_job_i18n',
138
+			array(
139
+				'return_url' => $_REQUEST['return_url'],
140
+			)
141
+		);
142
+	}
143 143
 
144
-    /**
145
-     * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it
146
-     */
147
-    public function enqueue_scripts_styles_batch_file_create()
148
-    {
149
-        // creates a job based on the request variable
150
-        $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
151
-        wp_enqueue_script(
152
-            'batch_file_runner_init',
153
-            BATCH_URL . 'assets/batch_file_runner_init.js',
154
-            array('batch_runner'),
155
-            EVENT_ESPRESSO_VERSION,
156
-            true
157
-        );
158
-        wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array());
159
-        wp_localize_script(
160
-            'batch_file_runner_init',
161
-            'ee_job_i18n',
162
-            array(
163
-                'download_and_redirecting' => sprintf(
164
-                    __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'),
165
-                    '<a href="' . $_REQUEST['return_url'] . '">',
166
-                    '</a>'
167
-                ),
168
-                'return_url'               => $_REQUEST['return_url'],
169
-            )
170
-        );
171
-    }
144
+	/**
145
+	 * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it
146
+	 */
147
+	public function enqueue_scripts_styles_batch_file_create()
148
+	{
149
+		// creates a job based on the request variable
150
+		$job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
151
+		wp_enqueue_script(
152
+			'batch_file_runner_init',
153
+			BATCH_URL . 'assets/batch_file_runner_init.js',
154
+			array('batch_runner'),
155
+			EVENT_ESPRESSO_VERSION,
156
+			true
157
+		);
158
+		wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array());
159
+		wp_localize_script(
160
+			'batch_file_runner_init',
161
+			'ee_job_i18n',
162
+			array(
163
+				'download_and_redirecting' => sprintf(
164
+					__('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'),
165
+					'<a href="' . $_REQUEST['return_url'] . '">',
166
+					'</a>'
167
+				),
168
+				'return_url'               => $_REQUEST['return_url'],
169
+			)
170
+		);
171
+	}
172 172
 
173
-    /**
174
-     * Enqueues scripts and styles common to any batch job, and creates
175
-     * a job from the request data, and stores the response in the
176
-     * $this->_job_step_response property
177
-     *
178
-     * @return \EventEspressoBatchRequest\Helpers\JobStepResponse
179
-     */
180
-    protected function _enqueue_batch_job_scripts_and_styles_and_start_job()
181
-    {
182
-        // just copy the bits of EE admin's eei18n that we need in the JS
183
-        EE_Registry::$i18n_js_strings['batchJobError'] =  esc_html__(
184
-            'An error occurred and the job has been stopped. Please refresh the page to try again.',
185
-            'event_espresso'
186
-        );
187
-        wp_register_script(
188
-            'progress_bar',
189
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
190
-            array('jquery'),
191
-            EVENT_ESPRESSO_VERSION,
192
-            true
193
-        );
194
-        wp_enqueue_style(
195
-            'progress_bar',
196
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
197
-            array(),
198
-            EVENT_ESPRESSO_VERSION
199
-        );
200
-        wp_enqueue_script(
201
-            'batch_runner',
202
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
203
-            array('progress_bar', CoreAssetManager::JS_HANDLE_CORE),
204
-            EVENT_ESPRESSO_VERSION,
205
-            true
206
-        );
207
-        $job_handler_classname = stripslashes($_GET['job_handler']);
208
-        $request_data = array_diff_key(
209
-            $_REQUEST,
210
-            array_flip(array('action', 'page', 'ee', 'batch'))
211
-        );
212
-        $batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor();
213
-        // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport'
214
-        $job_response = $batch_runner->create_job($job_handler_classname, $request_data);
215
-        // remember the response for later. We need it to display the page body
216
-        $this->_job_step_response = $job_response;
217
-        return $job_response;
218
-    }
173
+	/**
174
+	 * Enqueues scripts and styles common to any batch job, and creates
175
+	 * a job from the request data, and stores the response in the
176
+	 * $this->_job_step_response property
177
+	 *
178
+	 * @return \EventEspressoBatchRequest\Helpers\JobStepResponse
179
+	 */
180
+	protected function _enqueue_batch_job_scripts_and_styles_and_start_job()
181
+	{
182
+		// just copy the bits of EE admin's eei18n that we need in the JS
183
+		EE_Registry::$i18n_js_strings['batchJobError'] =  esc_html__(
184
+			'An error occurred and the job has been stopped. Please refresh the page to try again.',
185
+			'event_espresso'
186
+		);
187
+		wp_register_script(
188
+			'progress_bar',
189
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
190
+			array('jquery'),
191
+			EVENT_ESPRESSO_VERSION,
192
+			true
193
+		);
194
+		wp_enqueue_style(
195
+			'progress_bar',
196
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
197
+			array(),
198
+			EVENT_ESPRESSO_VERSION
199
+		);
200
+		wp_enqueue_script(
201
+			'batch_runner',
202
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
203
+			array('progress_bar', CoreAssetManager::JS_HANDLE_CORE),
204
+			EVENT_ESPRESSO_VERSION,
205
+			true
206
+		);
207
+		$job_handler_classname = stripslashes($_GET['job_handler']);
208
+		$request_data = array_diff_key(
209
+			$_REQUEST,
210
+			array_flip(array('action', 'page', 'ee', 'batch'))
211
+		);
212
+		$batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor();
213
+		// eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport'
214
+		$job_response = $batch_runner->create_job($job_handler_classname, $request_data);
215
+		// remember the response for later. We need it to display the page body
216
+		$this->_job_step_response = $job_response;
217
+		return $job_response;
218
+	}
219 219
 
220
-    /**
221
-     * If we are doing a frontend batch job, this makes it so WP shows our template's HTML
222
-     *
223
-     * @param string $template
224
-     * @return string
225
-     */
226
-    public function override_template($template)
227
-    {
228
-        if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) {
229
-            return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html';
230
-        }
231
-        return $template;
232
-    }
220
+	/**
221
+	 * If we are doing a frontend batch job, this makes it so WP shows our template's HTML
222
+	 *
223
+	 * @param string $template
224
+	 * @return string
225
+	 */
226
+	public function override_template($template)
227
+	{
228
+		if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) {
229
+			return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html';
230
+		}
231
+		return $template;
232
+	}
233 233
 
234
-    /**
235
-     * Adds an admin page which doesn't appear in the admin menu
236
-     */
237
-    public function register_admin_pages()
238
-    {
239
-        add_submenu_page(
240
-            '', // parent slug. we don't want this to actually appear in the menu
241
-            __('Batch Job', 'event_espresso'), // page title
242
-            'n/a', // menu title
243
-            'read', // we want this page to actually be accessible to anyone,
244
-            'espresso_batch', // menu slug
245
-            array(self::instance(), 'show_admin_page')
246
-        );
247
-    }
234
+	/**
235
+	 * Adds an admin page which doesn't appear in the admin menu
236
+	 */
237
+	public function register_admin_pages()
238
+	{
239
+		add_submenu_page(
240
+			'', // parent slug. we don't want this to actually appear in the menu
241
+			__('Batch Job', 'event_espresso'), // page title
242
+			'n/a', // menu title
243
+			'read', // we want this page to actually be accessible to anyone,
244
+			'espresso_batch', // menu slug
245
+			array(self::instance(), 'show_admin_page')
246
+		);
247
+	}
248 248
 
249
-    /**
250
-     * Renders the admin page, after most of the work was already done during enqueuing scripts
251
-     * of creating the job and localizing some data
252
-     */
253
-    public function show_admin_page()
254
-    {
255
-        echo EEH_Template::locate_template(
256
-            EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html',
257
-            array('batch_request_type' => $this->batch_request_type())
258
-        );
259
-    }
249
+	/**
250
+	 * Renders the admin page, after most of the work was already done during enqueuing scripts
251
+	 * of creating the job and localizing some data
252
+	 */
253
+	public function show_admin_page()
254
+	{
255
+		echo EEH_Template::locate_template(
256
+			EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html',
257
+			array('batch_request_type' => $this->batch_request_type())
258
+		);
259
+	}
260 260
 
261
-    /**
262
-     * Receives ajax calls for continuing a job
263
-     */
264
-    public function batch_continue()
265
-    {
266
-        $job_id = sanitize_text_field($_REQUEST['job_id']);
267
-        $batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor();
268
-        $response_obj = $batch_runner->continue_job($job_id);
269
-        $this->_return_json($response_obj->to_array());
270
-    }
261
+	/**
262
+	 * Receives ajax calls for continuing a job
263
+	 */
264
+	public function batch_continue()
265
+	{
266
+		$job_id = sanitize_text_field($_REQUEST['job_id']);
267
+		$batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor();
268
+		$response_obj = $batch_runner->continue_job($job_id);
269
+		$this->_return_json($response_obj->to_array());
270
+	}
271 271
 
272
-    /**
273
-     * Receives the ajax call to cleanup a job
274
-     *
275
-     * @return type
276
-     */
277
-    public function batch_cleanup()
278
-    {
279
-        $job_id = sanitize_text_field($_REQUEST['job_id']);
280
-        $batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor();
281
-        $response_obj = $batch_runner->cleanup_job($job_id);
282
-        $this->_return_json($response_obj->to_array());
283
-    }
272
+	/**
273
+	 * Receives the ajax call to cleanup a job
274
+	 *
275
+	 * @return type
276
+	 */
277
+	public function batch_cleanup()
278
+	{
279
+		$job_id = sanitize_text_field($_REQUEST['job_id']);
280
+		$batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor();
281
+		$response_obj = $batch_runner->cleanup_job($job_id);
282
+		$this->_return_json($response_obj->to_array());
283
+	}
284 284
 
285 285
 
286
-    /**
287
-     * Returns a json response
288
-     *
289
-     * @param array $data The data we want to send echo via in the JSON response's "data" element
290
-     *
291
-     * The returned json object is created from an array in the following format:
292
-     * array(
293
-     *    'notices' => '', // - contains any EE_Error formatted notices
294
-     *    'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
295
-     *    We're also going to include the template args with every package (so js can pick out any specific template
296
-     *    args that might be included in here)
297
-     *    'isEEajax' => true,//indicates this is a response from EE
298
-     * )
299
-     */
300
-    protected function _return_json($data)
301
-    {
302
-        $json = array(
303
-            'notices'  => EE_Error::get_notices(),
304
-            'data'     => $data,
305
-            'isEEajax' => true
306
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
307
-        );
286
+	/**
287
+	 * Returns a json response
288
+	 *
289
+	 * @param array $data The data we want to send echo via in the JSON response's "data" element
290
+	 *
291
+	 * The returned json object is created from an array in the following format:
292
+	 * array(
293
+	 *    'notices' => '', // - contains any EE_Error formatted notices
294
+	 *    'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
295
+	 *    We're also going to include the template args with every package (so js can pick out any specific template
296
+	 *    args that might be included in here)
297
+	 *    'isEEajax' => true,//indicates this is a response from EE
298
+	 * )
299
+	 */
300
+	protected function _return_json($data)
301
+	{
302
+		$json = array(
303
+			'notices'  => EE_Error::get_notices(),
304
+			'data'     => $data,
305
+			'isEEajax' => true
306
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
307
+		);
308 308
 
309 309
 
310
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
311
-        if (null === error_get_last() || ! headers_sent()) {
312
-            header('Content-Type: application/json; charset=UTF-8');
313
-        }
314
-        echo wp_json_encode($json);
315
-        exit();
316
-    }
310
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
311
+		if (null === error_get_last() || ! headers_sent()) {
312
+			header('Content-Type: application/json; charset=UTF-8');
313
+		}
314
+		echo wp_json_encode($json);
315
+		exit();
316
+	}
317 317
 
318
-    /**
319
-     * Gets the job step response which was done during the enqueuing of scripts
320
-     *
321
-     * @return \EventEspressoBatchRequest\Helpers\JobStepResponse
322
-     */
323
-    public function job_step_response()
324
-    {
325
-        return $this->_job_step_response;
326
-    }
318
+	/**
319
+	 * Gets the job step response which was done during the enqueuing of scripts
320
+	 *
321
+	 * @return \EventEspressoBatchRequest\Helpers\JobStepResponse
322
+	 */
323
+	public function job_step_response()
324
+	{
325
+		return $this->_job_step_response;
326
+	}
327 327
 
328
-    /**
329
-     * Gets the batch request type indicated in the $_REQUEST
330
-     *
331
-     * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job
332
-     */
333
-    public function batch_request_type()
334
-    {
335
-        if ($this->_batch_request_type === null) {
336
-            if (isset($_GET['batch'])) {
337
-                if ($_GET['batch'] == self::batch_job) {
338
-                    $this->_batch_request_type = self::batch_job;
339
-                } elseif ($_GET['batch'] == self::batch_file_job) {
340
-                    $this->_batch_request_type = self::batch_file_job;
341
-                }
342
-            }
343
-            // if we didn't find that it was a batch request, indicate it wasn't
344
-            if ($this->_batch_request_type === null) {
345
-                $this->_batch_request_type = self::batch_not_job;
346
-            }
347
-        }
348
-        return $this->_batch_request_type;
349
-    }
328
+	/**
329
+	 * Gets the batch request type indicated in the $_REQUEST
330
+	 *
331
+	 * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job
332
+	 */
333
+	public function batch_request_type()
334
+	{
335
+		if ($this->_batch_request_type === null) {
336
+			if (isset($_GET['batch'])) {
337
+				if ($_GET['batch'] == self::batch_job) {
338
+					$this->_batch_request_type = self::batch_job;
339
+				} elseif ($_GET['batch'] == self::batch_file_job) {
340
+					$this->_batch_request_type = self::batch_file_job;
341
+				}
342
+			}
343
+			// if we didn't find that it was a batch request, indicate it wasn't
344
+			if ($this->_batch_request_type === null) {
345
+				$this->_batch_request_type = self::batch_not_job;
346
+			}
347
+		}
348
+		return $this->_batch_request_type;
349
+	}
350 350
 
351
-    /**
352
-     * Unnecessary
353
-     *
354
-     * @param type $WP
355
-     */
356
-    public function run($WP)
357
-    {
358
-    }
351
+	/**
352
+	 * Unnecessary
353
+	 *
354
+	 * @param type $WP
355
+	 */
356
+	public function run($WP)
357
+	{
358
+	}
359 359
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
         $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
127 127
         wp_enqueue_script(
128 128
             'batch_runner_init',
129
-            BATCH_URL . 'assets/batch_runner_init.js',
129
+            BATCH_URL.'assets/batch_runner_init.js',
130 130
             array('batch_runner'),
131 131
             EVENT_ESPRESSO_VERSION,
132 132
             true
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
         $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
151 151
         wp_enqueue_script(
152 152
             'batch_file_runner_init',
153
-            BATCH_URL . 'assets/batch_file_runner_init.js',
153
+            BATCH_URL.'assets/batch_file_runner_init.js',
154 154
             array('batch_runner'),
155 155
             EVENT_ESPRESSO_VERSION,
156 156
             true
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
             array(
163 163
                 'download_and_redirecting' => sprintf(
164 164
                     __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'),
165
-                    '<a href="' . $_REQUEST['return_url'] . '">',
165
+                    '<a href="'.$_REQUEST['return_url'].'">',
166 166
                     '</a>'
167 167
                 ),
168 168
                 'return_url'               => $_REQUEST['return_url'],
@@ -180,26 +180,26 @@  discard block
 block discarded – undo
180 180
     protected function _enqueue_batch_job_scripts_and_styles_and_start_job()
181 181
     {
182 182
         // just copy the bits of EE admin's eei18n that we need in the JS
183
-        EE_Registry::$i18n_js_strings['batchJobError'] =  esc_html__(
183
+        EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__(
184 184
             'An error occurred and the job has been stopped. Please refresh the page to try again.',
185 185
             'event_espresso'
186 186
         );
187 187
         wp_register_script(
188 188
             'progress_bar',
189
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
189
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.js',
190 190
             array('jquery'),
191 191
             EVENT_ESPRESSO_VERSION,
192 192
             true
193 193
         );
194 194
         wp_enqueue_style(
195 195
             'progress_bar',
196
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
196
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.css',
197 197
             array(),
198 198
             EVENT_ESPRESSO_VERSION
199 199
         );
200 200
         wp_enqueue_script(
201 201
             'batch_runner',
202
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
202
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/batch_runner.js',
203 203
             array('progress_bar', CoreAssetManager::JS_HANDLE_CORE),
204 204
             EVENT_ESPRESSO_VERSION,
205 205
             true
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
     public function override_template($template)
227 227
     {
228 228
         if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) {
229
-            return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html';
229
+            return EE_MODULES.'batch'.DS.'templates'.DS.'batch_frontend_wrapper.template.html';
230 230
         }
231 231
         return $template;
232 232
     }
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
     public function show_admin_page()
254 254
     {
255 255
         echo EEH_Template::locate_template(
256
-            EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html',
256
+            EE_MODULES.'batch'.DS.'templates'.DS.'batch_wrapper.template.html',
257 257
             array('batch_request_type' => $this->batch_request_type())
258 258
         );
259 259
     }
Please login to merge, or discard this patch.