Skip to content

Commit c0c59b3

Browse files
test import from url #141
1 parent 2c6fce4 commit c0c59b3

File tree

6 files changed

+309
-241
lines changed

6 files changed

+309
-241
lines changed

classes/Visualizer/Module/Chart.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,21 +443,22 @@ public function renderFlattrScript() {
443443
*/
444444
public function uploadData() {
445445
// 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'] ) ) {
447448
status_header( 403 );
448449
exit;
449450
}
450451

451452
// 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 ) : '';
453454
if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
454455
status_header( 400 );
455456
exit;
456457
}
457458

458459
$source = null;
459460
$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 ) ) {
461462
$source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] );
462463
} elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) {
463464
$source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] );
@@ -488,7 +489,7 @@ public function uploadData() {
488489
}
489490

490491
$render->render();
491-
exit;
492+
wp_die();
492493
}
493494

494495
/**

index.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,32 +90,20 @@ function visualizer_launch() {
9090
define( 'VISUALIZER_CSV_ENCLOSURE', '"' );
9191
}
9292

93-
// don't load the plugin if cron job is running or doing autosave
94-
$doing_autosave = defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE;
95-
$doing_cron = defined( 'DOING_CRON' ) && DOING_CRON;
96-
$doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
97-
if ( $doing_autosave || $doing_cron ) {
98-
return;
99-
}
100-
10193
// instantiate the plugin
10294
$plugin = Visualizer_Plugin::instance();
10395

10496
// set general modules
10597
$plugin->setModule( Visualizer_Module_Setup::NAME );
10698
$plugin->setModule( Visualizer_Module_Sources::NAME );
10799

108-
if ( $doing_ajax ) {
109-
// set ajax modules
110-
$plugin->setModule( Visualizer_Module_Chart::NAME );
100+
$plugin->setModule( Visualizer_Module_Chart::NAME );
101+
if ( is_admin() ) {
102+
// set admin modules
103+
$plugin->setModule( Visualizer_Module_Admin::NAME );
111104
} else {
112-
if ( is_admin() ) {
113-
// set admin modules
114-
$plugin->setModule( Visualizer_Module_Admin::NAME );
115-
} else {
116-
// set frontend modules
117-
$plugin->setModule( Visualizer_Module_Frontend::NAME );
118-
}
105+
// set frontend modules
106+
$plugin->setModule( Visualizer_Module_Frontend::NAME );
119107
}
120108
}
121109

js/frame.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
parent.addClass('open');
3232
}
3333
});
34-
$('#vz-import-file').click(function () {
34+
$('#view-remote-file').click(function () {
3535
var url = $(this).parent().find('#remote-data').val();
3636

3737
if (url !== '') {

0 commit comments

Comments
 (0)