@@ -204,10 +204,10 @@ public function deleteChart() {
204
204
* @access public
205
205
*/
206
206
public function renderChartPages () {
207
- define ( 'IFRAME_REQUEST ' , 1 );
207
+ defined ( ' IFRAME_REQUEST ' ) || define ( 'IFRAME_REQUEST ' , 1 );
208
208
209
209
// check chart, if chart not exists, will create new one and redirects to the same page with proper chart id
210
- $ chart_id = filter_input ( INPUT_GET , 'chart ' , FILTER_VALIDATE_INT );
210
+ $ chart_id = isset ( $ _GET [ ' chart ' ] ) ? filter_var ( $ _GET [ 'chart ' ] , FILTER_VALIDATE_INT ) : '' ;
211
211
if ( ! $ chart_id || ! ( $ chart = get_post ( $ chart_id ) ) || $ chart ->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
212
212
$ default_type = 'line ' ;
213
213
@@ -231,7 +231,7 @@ public function renderChartPages() {
231
231
}
232
232
233
233
wp_redirect ( add_query_arg ( 'chart ' , (int ) $ chart_id ) );
234
- exit ;
234
+ wp_die () ;
235
235
}
236
236
237
237
// enqueue and register scripts and styles
@@ -250,8 +250,8 @@ public function renderChartPages() {
250
250
}
251
251
252
252
// dispatch pages
253
- $ this ->_chart = $ chart ;
254
- switch ( filter_input ( INPUT_GET , 'tab ' ) ) {
253
+ $ this ->_chart = get_post ( $ chart_id ) ;
254
+ switch ( isset ( $ _GET [ 'tab ' ] ) ? $ _GET [ ' tab ' ] : '' ) {
255
255
case 'settings ' :
256
256
// changed by Ash/Upwork
257
257
$ this ->_handleDataAndSettingsPage ();
@@ -262,7 +262,7 @@ public function renderChartPages() {
262
262
break ;
263
263
}
264
264
265
- exit ;
265
+ wp_die () ;
266
266
}
267
267
268
268
/**
@@ -351,7 +351,7 @@ private function _handleDataPage() {
351
351
* Handle data and settings page
352
352
*/
353
353
private function _handleDataAndSettingsPage () {
354
- if ( $ _SERVER ['REQUEST_METHOD ' ] == 'POST ' && wp_verify_nonce ( filter_input ( INPUT_GET , 'nonce ' ) ) ) {
354
+ if ( $ _SERVER ['REQUEST_METHOD ' ] == 'POST ' && isset ( $ _GET [ 'nonce ' ] ) && wp_verify_nonce ( $ _GET [ ' nonce ' ] ) ) {
355
355
if ( $ this ->_chart ->post_status == 'auto-draft ' ) {
356
356
$ this ->_chart ->post_status = 'publish ' ;
357
357
wp_update_post ( $ this ->_chart ->to_array () );
@@ -443,21 +443,22 @@ public function renderFlattrScript() {
443
443
*/
444
444
public function uploadData () {
445
445
// validate nonce
446
- if ( ! wp_verify_nonce ( filter_input ( INPUT_GET , 'nonce ' ) ) ) {
446
+ // do not use filter_input as it does not work for phpunit test cases, use filter_var instead
447
+ if ( ! isset ( $ _GET ['nonce ' ] ) || ! wp_verify_nonce ( $ _GET ['nonce ' ] ) ) {
447
448
status_header ( 403 );
448
449
exit ;
449
450
}
450
451
451
452
// check chart, if chart exists
452
- $ chart_id = filter_input ( INPUT_GET , 'chart ' , FILTER_VALIDATE_INT );
453
+ $ chart_id = isset ( $ _GET [ ' chart ' ] ) ? filter_var ( $ _GET [ 'chart ' ] , FILTER_VALIDATE_INT ) : '' ;
453
454
if ( ! $ chart_id || ! ( $ chart = get_post ( $ chart_id ) ) || $ chart ->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
454
455
status_header ( 400 );
455
456
exit ;
456
457
}
457
458
458
459
$ source = null ;
459
460
$ render = new Visualizer_Render_Page_Update ();
460
- if ( filter_input ( INPUT_POST , 'remote_data ' , FILTER_VALIDATE_URL ) ) {
461
+ if ( isset ( $ _POST [ ' remote_data ' ] ) && filter_var ( $ _POST [ 'remote_data ' ] , FILTER_VALIDATE_URL ) ) {
461
462
$ source = new Visualizer_Source_Csv_Remote ( $ _POST ['remote_data ' ] );
462
463
} elseif ( isset ( $ _FILES ['local_data ' ] ) && $ _FILES ['local_data ' ]['error ' ] == 0 ) {
463
464
$ source = new Visualizer_Source_Csv ( $ _FILES ['local_data ' ]['tmp_name ' ] );
@@ -488,7 +489,7 @@ public function uploadData() {
488
489
}
489
490
490
491
$ render ->render ();
491
- exit ;
492
+ wp_die () ;
492
493
}
493
494
494
495
/**
@@ -551,7 +552,7 @@ public function exportData() {
551
552
$ chart_id = $ success = false ;
552
553
$ capable = current_user_can ( 'edit_posts ' );
553
554
if ( $ capable ) {
554
- $ chart_id = filter_input ( INPUT_GET , 'chart ' , FILTER_VALIDATE_INT , array ( 'options ' => array ( 'min_range ' => 1 ) ) );
555
+ $ chart_id = isset ( $ _GET [ ' chart ' ] ) ? filter_var ( $ _GET [ 'chart ' ] , FILTER_VALIDATE_INT , array ( 'options ' => array ( 'min_range ' => 1 ) ) ) : '' ;
555
556
if ( $ chart_id ) {
556
557
$ chart = get_post ( $ chart_id );
557
558
$ success = $ chart && $ chart ->post_type == Visualizer_Plugin::CPT_VISUALIZER ;
@@ -560,7 +561,7 @@ public function exportData() {
560
561
561
562
if ( $ success ) {
562
563
$ settings = get_post_meta ( $ chart_id , Visualizer_Plugin::CF_SETTINGS , true );
563
- $ filename = $ settings ['title ' ];
564
+ $ filename = isset ( $ settings ['title ' ] ) ? $ settings [ ' title ' ] : '' ;
564
565
if ( empty ( $ filename ) ) {
565
566
$ filename = 'export.csv ' ;
566
567
} else {
@@ -619,6 +620,6 @@ public function exportData() {
619
620
));
620
621
}// End if().
621
622
622
- exit ;
623
+ wp_die () ;
623
624
}
624
625
}
0 commit comments