Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions classes/Visualizer/Module/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ public function deleteChart() {
* @access public
*/
public function renderChartPages() {
define( 'IFRAME_REQUEST', 1 );
defined( 'IFRAME_REQUEST' ) || define( 'IFRAME_REQUEST', 1 );

// check chart, if chart not exists, will create new one and redirects to the same page with proper chart id
$chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT );
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
$default_type = 'line';

Expand All @@ -231,7 +231,7 @@ public function renderChartPages() {
}

wp_redirect( add_query_arg( 'chart', (int) $chart_id ) );
exit;
wp_die();
}

// enqueue and register scripts and styles
Expand All @@ -250,8 +250,8 @@ public function renderChartPages() {
}

// dispatch pages
$this->_chart = $chart;
switch ( filter_input( INPUT_GET, 'tab' ) ) {
$this->_chart = get_post( $chart_id );
switch ( isset( $_GET['tab'] ) ? $_GET['tab'] : '' ) {
case 'settings':
// changed by Ash/Upwork
$this->_handleDataAndSettingsPage();
Expand All @@ -262,7 +262,7 @@ public function renderChartPages() {
break;
}

exit;
wp_die();
}

/**
Expand Down Expand Up @@ -351,7 +351,7 @@ private function _handleDataPage() {
* Handle data and settings page
*/
private function _handleDataAndSettingsPage() {
if ( $_SERVER['REQUEST_METHOD'] == 'POST' && wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ) ) ) {
if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'] ) ) {
if ( $this->_chart->post_status == 'auto-draft' ) {
$this->_chart->post_status = 'publish';
wp_update_post( $this->_chart->to_array() );
Expand Down Expand Up @@ -443,21 +443,22 @@ public function renderFlattrScript() {
*/
public function uploadData() {
// validate nonce
if ( ! wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ) ) ) {
// do not use filter_input as it does not work for phpunit test cases, use filter_var instead
if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'] ) ) {
status_header( 403 );
exit;
}

// check chart, if chart exists
$chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT );
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
status_header( 400 );
exit;
}

$source = null;
$render = new Visualizer_Render_Page_Update();
if ( filter_input( INPUT_POST, 'remote_data', FILTER_VALIDATE_URL ) ) {
if ( isset( $_POST['remote_data'] ) && filter_var( $_POST['remote_data'], FILTER_VALIDATE_URL ) ) {
$source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] );
} elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) {
$source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] );
Expand Down Expand Up @@ -488,7 +489,7 @@ public function uploadData() {
}

$render->render();
exit;
wp_die();
}

/**
Expand Down Expand Up @@ -551,7 +552,7 @@ public function exportData() {
$chart_id = $success = false;
$capable = current_user_can( 'edit_posts' );
if ( $capable ) {
$chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1 ) ) );
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1 ) ) ) : '';
if ( $chart_id ) {
$chart = get_post( $chart_id );
$success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
Expand All @@ -560,7 +561,7 @@ public function exportData() {

if ( $success ) {
$settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true );
$filename = $settings['title'];
$filename = isset( $settings['title'] ) ? $settings['title'] : '';
if ( empty( $filename ) ) {
$filename = 'export.csv';
} else {
Expand Down Expand Up @@ -619,6 +620,6 @@ public function exportData() {
));
}// End if().

exit;
wp_die();
}
}
24 changes: 6 additions & 18 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,20 @@ function visualizer_launch() {
define( 'VISUALIZER_CSV_ENCLOSURE', '"' );
}

// don't load the plugin if cron job is running or doing autosave
$doing_autosave = defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE;
$doing_cron = defined( 'DOING_CRON' ) && DOING_CRON;
$doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
if ( $doing_autosave || $doing_cron ) {
return;
}

// instantiate the plugin
$plugin = Visualizer_Plugin::instance();

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

if ( $doing_ajax ) {
// set ajax modules
$plugin->setModule( Visualizer_Module_Chart::NAME );
$plugin->setModule( Visualizer_Module_Chart::NAME );
if ( is_admin() ) {
// set admin modules
$plugin->setModule( Visualizer_Module_Admin::NAME );
} else {
if ( is_admin() ) {
// set admin modules
$plugin->setModule( Visualizer_Module_Admin::NAME );
} else {
// set frontend modules
$plugin->setModule( Visualizer_Module_Frontend::NAME );
}
// set frontend modules
$plugin->setModule( Visualizer_Module_Frontend::NAME );
}
}

Expand Down
2 changes: 1 addition & 1 deletion js/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
parent.addClass('open');
}
});
$('#vz-import-file').click(function () {
$('#view-remote-file').click(function () {
var url = $(this).parent().find('#remote-data').val();

if (url !== '') {
Expand Down
Loading