| @@ -18,9 +18,8 @@ | ||
| 18 | 18 | // | MA 02110-1301 USA | |
| 19 | 19 | // +----------------------------------------------------------------------+ |
| 20 | 20 | // | Author: Eugene Manuilov <eugene@manuilov.org> | |
| 21 | 21 | // +----------------------------------------------------------------------+ |
| 22 | - | |
| 23 | 22 | /** |
| 24 | 23 | * The module for all stuff related to getting, editing, creating and deleting charts. |
| 25 | 24 | * |
| 26 | 25 | * @category Visualizer |
| @@ -59,17 +58,16 @@ | ||
| 59 | 58 | $this->_addAjaxAction( Visualizer_Plugin::ACTION_EDIT_CHART, 'renderChartPages' ); |
| 60 | 59 | $this->_addAjaxAction( Visualizer_Plugin::ACTION_UPLOAD_DATA, 'uploadData' ); |
| 61 | 60 | $this->_addAjaxAction( Visualizer_Plugin::ACTION_CLONE_CHART, 'cloneChart' ); |
| 62 | 61 | |
| 63 | - // Added by Ash/Upwork | |
| 62 | + // Added by Ash/Upwork | |
| 64 | 63 | $this->_addAjaxAction( Visualizer_Plugin::ACTION_EXPORT_DATA, 'exportData' ); |
| 65 | - if( defined( 'Visualizer_Pro' ) ){ | |
| 66 | - global $Visualizer_Pro; | |
| 67 | - list($action, $name, $class) = $Visualizer_Pro->_getAjaxAction($this); | |
| 68 | - $this->_addAjaxAction($action, $name, $class); | |
| 69 | - } | |
| 70 | - // Added by Ash/Upwork | |
| 71 | - | |
| 64 | + if ( defined( 'Visualizer_Pro' ) ) { | |
| 65 | + global $Visualizer_Pro; | |
| 66 | + list($action, $name, $class) = $Visualizer_Pro->_getAjaxAction( $this ); | |
| 67 | + $this->_addAjaxAction( $action, $name, $class ); | |
| 68 | + } | |
| 69 | + // Added by Ash/Upwork | |
| 72 | 70 | } |
| 73 | 71 | |
| 74 | 72 | /** |
| 75 | 73 | * Sends json response. |
| @@ -127,10 +125,10 @@ | ||
| 127 | 125 | 'paged' => filter_input( INPUT_GET, 'page', FILTER_VALIDATE_INT, array( |
| 128 | 126 | 'options' => array( |
| 129 | 127 | 'min_range' => 1, |
| 130 | 128 | 'default' => 1, |
| 131 | - ) | |
| 132 | - ) ) | |
| 129 | + ), | |
| 130 | + ) ), | |
| 133 | 131 | ); |
| 134 | 132 | |
| 135 | 133 | $filter = filter_input( INPUT_GET, 'filter', FILTER_SANITIZE_STRING ); |
| 136 | 134 | if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) { |
| @@ -145,9 +143,9 @@ | ||
| 145 | 143 | |
| 146 | 144 | $query = new WP_Query( $query_args ); |
| 147 | 145 | |
| 148 | 146 | $charts = array(); |
| 149 | - while( $query->have_posts() ) { | |
| 147 | + while ( $query->have_posts() ) { | |
| 150 | 148 | $chart = $query->next_post(); |
| 151 | 149 | |
| 152 | 150 | $chart_data = $this->_getChartArray( $chart ); |
| 153 | 151 | $chart_data['id'] = $chart->ID; |
| @@ -205,13 +203,13 @@ | ||
| 205 | 203 | * |
| 206 | 204 | * @access public |
| 207 | 205 | */ |
| 208 | 206 | public function renderChartPages() { |
| 209 | - define ( 'IFRAME_REQUEST', 1 ); | |
| 207 | + define( 'IFRAME_REQUEST', 1 ); | |
| 210 | 208 | |
| 211 | 209 | // check chart, if chart not exists, will create new one and redirects to the same page with proper chart id |
| 212 | 210 | $chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT ); |
| 213 | - if ( !$chart_id || !( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) { | |
| 211 | + if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) { | |
| 214 | 212 | $default_type = 'line'; |
| 215 | 213 | |
| 216 | 214 | $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' ); |
| 217 | 215 | $source->fetch(); |
| @@ -223,17 +221,17 @@ | ||
| 223 | 221 | 'post_status' => 'auto-draft', |
| 224 | 222 | 'post_content' => $source->getData(), |
| 225 | 223 | ) ); |
| 226 | 224 | |
| 227 | - if ( $chart_id && !is_wp_error( $chart_id ) ) { | |
| 225 | + if ( $chart_id && ! is_wp_error( $chart_id ) ) { | |
| 228 | 226 | add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, $default_type ); |
| 229 | 227 | add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 ); |
| 230 | 228 | add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 231 | 229 | add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); |
| 232 | - add_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, array('focusTarget' => 'datum') ); | |
| 230 | + add_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, array( 'focusTarget' => 'datum' ) ); | |
| 233 | 231 | } |
| 234 | 232 | |
| 235 | - wp_redirect( add_query_arg( 'chart', (int)$chart_id ) ); | |
| 233 | + wp_redirect( add_query_arg( 'chart', (int) $chart_id ) ); | |
| 236 | 234 | exit; |
| 237 | 235 | } |
| 238 | 236 | |
| 239 | 237 | // enqueue and register scripts and styles |
| @@ -240,23 +238,23 @@ | ||
| 240 | 238 | wp_register_style( 'visualizer-frame', VISUALIZER_ABSURL . 'css/frame.css', array(), Visualizer_Plugin::VERSION ); |
| 241 | 239 | |
| 242 | 240 | wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true ); |
| 243 | 241 | wp_register_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true ); |
| 244 | - wp_register_script( 'google-jsapi-old', '//www.google.com/jsapi', array('google-jsapi-new'), null, true ); | |
| 242 | + wp_register_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true ); | |
| 245 | 243 | wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'google-jsapi-old', 'google-jsapi-new', 'visualizer-frame' ), Visualizer_Plugin::VERSION, true ); |
| 246 | 244 | wp_register_script( 'visualizer-preview', VISUALIZER_ABSURL . 'js/preview.js', array( 'wp-color-picker', 'visualizer-render' ), Visualizer_Plugin::VERSION, true ); |
| 247 | 245 | |
| 248 | - // added by Ash/Upwork | |
| 249 | - if( defined( 'Visualizer_Pro' ) ){ | |
| 250 | - global $Visualizer_Pro; | |
| 251 | - $Visualizer_Pro->_addScriptsAndStyles(); | |
| 252 | - } | |
| 246 | + // added by Ash/Upwork | |
| 247 | + if ( defined( 'Visualizer_Pro' ) ) { | |
| 248 | + global $Visualizer_Pro; | |
| 249 | + $Visualizer_Pro->_addScriptsAndStyles(); | |
| 250 | + } | |
| 253 | 251 | |
| 254 | 252 | // dispatch pages |
| 255 | 253 | $this->_chart = $chart; |
| 256 | 254 | switch ( filter_input( INPUT_GET, 'tab' ) ) { |
| 257 | 255 | case 'settings': |
| 258 | - // changed by Ash/Upwork | |
| 256 | + // changed by Ash/Upwork | |
| 259 | 257 | $this->_handleDataAndSettingsPage(); |
| 260 | 258 | break; |
| 261 | 259 | case 'type': |
| 262 | 260 | default: |
| @@ -294,9 +292,9 @@ | ||
| 294 | 292 | } |
| 295 | 293 | |
| 296 | 294 | // redirect to next tab |
| 297 | 295 | // changed by Ash/Upwork |
| 298 | - wp_redirect( add_query_arg( 'tab', 'settings' ) ); | |
| 296 | + wp_redirect( add_query_arg( 'tab', 'settings' ) ); | |
| 299 | 297 | return; |
| 300 | 298 | } |
| 301 | 299 | } |
| 302 | 300 | |
| @@ -307,9 +305,9 @@ | ||
| 307 | 305 | |
| 308 | 306 | wp_enqueue_style( 'visualizer-frame' ); |
| 309 | 307 | wp_enqueue_script( 'visualizer-frame' ); |
| 310 | 308 | |
| 311 | - wp_iframe( array( $render, 'render') ); | |
| 309 | + wp_iframe( array( $render, 'render' ) ); | |
| 312 | 310 | } |
| 313 | 311 | |
| 314 | 312 | /** |
| 315 | 313 | * Handles chart data page. |
| @@ -330,10 +328,10 @@ | ||
| 330 | 328 | wp_enqueue_style( 'visualizer-frame' ); |
| 331 | 329 | wp_enqueue_script( 'visualizer-render' ); |
| 332 | 330 | wp_localize_script( 'visualizer-render', 'visualizer', array( |
| 333 | 331 | 'l10n' => array( |
| 334 | - 'remotecsv_prompt' => esc_html__( 'Please, enter the URL of CSV file:', Visualizer_Plugin::NAME ), | |
| 335 | - 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', Visualizer_Plugin::NAME ), | |
| 332 | + 'remotecsv_prompt' => esc_html__( 'Please, enter the URL of CSV file:', 'visualizer' ), | |
| 333 | + 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ), | |
| 336 | 334 | ), |
| 337 | 335 | 'charts' => array( |
| 338 | 336 | 'canvas' => $data, |
| 339 | 337 | ), |
| @@ -338,22 +336,23 @@ | ||
| 338 | 336 | 'canvas' => $data, |
| 339 | 337 | ), |
| 340 | 338 | ) ); |
| 341 | 339 | |
| 342 | - // Added by Ash/Upwork | |
| 343 | - if( defined( 'Visualizer_Pro' ) ){ | |
| 344 | - global $Visualizer_Pro; | |
| 345 | - $Visualizer_Pro->_enqueueScriptsAndStyles($data); | |
| 346 | - } | |
| 347 | - // Added by Ash/Upwork | |
| 348 | - | |
| 340 | + // Added by Ash/Upwork | |
| 341 | + if ( defined( 'Visualizer_Pro' ) ) { | |
| 342 | + global $Visualizer_Pro; | |
| 343 | + $Visualizer_Pro->_enqueueScriptsAndStyles( $data ); | |
| 344 | + } | |
| 345 | + // Added by Ash/Upwork | |
| 349 | 346 | $this->_addAction( 'admin_head', 'renderFlattrScript' ); |
| 350 | 347 | |
| 351 | - wp_iframe( array( $render, 'render') ); | |
| 348 | + wp_iframe( array( $render, 'render' ) ); | |
| 352 | 349 | } |
| 353 | 350 | |
| 354 | - // changed by Ash/Upwork | |
| 355 | - private function _handleDataAndSettingsPage(){ | |
| 351 | + /** | |
| 352 | + * Handle data and settings page | |
| 353 | + */ | |
| 354 | + private function _handleDataAndSettingsPage() { | |
| 356 | 355 | if ( $_SERVER['REQUEST_METHOD'] == 'POST' && wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ) ) ) { |
| 357 | 356 | if ( $this->_chart->post_status == 'auto-draft' ) { |
| 358 | 357 | $this->_chart->post_status = 'publish'; |
| 359 | 358 | wp_update_post( $this->_chart->to_array() ); |
| @@ -363,9 +362,9 @@ | ||
| 363 | 362 | |
| 364 | 363 | $render = new Visualizer_Render_Page_Send(); |
| 365 | 364 | $render->text = sprintf( '[visualizer id="%d"]', $this->_chart->ID ); |
| 366 | 365 | |
| 367 | - wp_iframe( array( $render, 'render') ); | |
| 366 | + wp_iframe( array( $render, 'render' ) ); | |
| 368 | 367 | return; |
| 369 | 368 | } |
| 370 | 369 | |
| 371 | 370 | $data = $this->_getChartArray(); |
| @@ -376,14 +375,14 @@ | ||
| 376 | 375 | $sidebar = new $sidebar_class( $data['settings'] ); |
| 377 | 376 | $sidebar->__series = $data['series']; |
| 378 | 377 | $sidebar->__data = $data['data']; |
| 379 | 378 | } else { |
| 380 | - $sidebar = apply_filters("visualizer_pro_chart_type_sidebar", '', $data); | |
| 381 | - if ($sidebar != '') { | |
| 382 | - $sidebar->__series = $data['series']; | |
| 383 | - $sidebar->__data = $data['data']; | |
| 384 | - } | |
| 385 | - } | |
| 379 | + $sidebar = apply_filters( 'visualizer_pro_chart_type_sidebar', '', $data ); | |
| 380 | + if ( $sidebar != '' ) { | |
| 381 | + $sidebar->__series = $data['series']; | |
| 382 | + $sidebar->__data = $data['data']; | |
| 383 | + } | |
| 384 | + } | |
| 386 | 385 | |
| 387 | 386 | unset( $data['settings']['width'], $data['settings']['height'] ); |
| 388 | 387 | |
| 389 | 388 | wp_enqueue_style( 'visualizer-frame' ); |
| @@ -393,10 +392,10 @@ | ||
| 393 | 392 | wp_enqueue_script( 'visualizer-preview' ); |
| 394 | 393 | wp_enqueue_script( 'visualizer-render' ); |
| 395 | 394 | wp_localize_script( 'visualizer-render', 'visualizer', array( |
| 396 | 395 | 'l10n' => array( |
| 397 | - 'remotecsv_prompt' => esc_html__( 'Please, enter the URL of CSV file:', Visualizer_Plugin::NAME ), | |
| 398 | - 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', Visualizer_Plugin::NAME ), | |
| 396 | + 'remotecsv_prompt' => esc_html__( 'Please, enter the URL of CSV file:', 'visualizer' ), | |
| 397 | + 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ), | |
| 399 | 398 | ), |
| 400 | 399 | 'charts' => array( |
| 401 | 400 | 'canvas' => $data, |
| 402 | 401 | ), |
| @@ -408,25 +407,24 @@ | ||
| 408 | 407 | |
| 409 | 408 | $render->sidebar = $sidebar; |
| 410 | 409 | if ( filter_input( INPUT_GET, 'library', FILTER_VALIDATE_BOOLEAN ) ) { |
| 411 | 410 | $render->button = filter_input( INPUT_GET, 'action' ) == Visualizer_Plugin::ACTION_EDIT_CHART |
| 412 | - ? esc_html__( 'Save Chart', Visualizer_Plugin::NAME ) | |
| 413 | - : esc_html__( 'Create Chart', Visualizer_Plugin::NAME ); | |
| 411 | + ? esc_html__( 'Save Chart', 'visualizer' ) | |
| 412 | + : esc_html__( 'Create Chart', 'visualizer' ); | |
| 414 | 413 | } else { |
| 415 | - $render->button = esc_attr__( 'Insert Chart', Visualizer_Plugin::NAME ); | |
| 414 | + $render->button = esc_attr__( 'Insert Chart', 'visualizer' ); | |
| 416 | 415 | } |
| 417 | 416 | |
| 418 | - if( defined( 'Visualizer_Pro' ) ){ | |
| 419 | - global $Visualizer_Pro; | |
| 420 | - $Visualizer_Pro->_enqueueScriptsAndStyles($data); | |
| 421 | - } | |
| 417 | + if ( defined( 'Visualizer_Pro' ) ) { | |
| 418 | + global $Visualizer_Pro; | |
| 419 | + $Visualizer_Pro->_enqueueScriptsAndStyles( $data ); | |
| 420 | + } | |
| 422 | 421 | |
| 423 | 422 | $this->_addAction( 'admin_head', 'renderFlattrScript' ); |
| 424 | 423 | |
| 425 | - wp_iframe( array( $render, 'render') ); | |
| 426 | - } | |
| 427 | - // changed by Ash/Upwork | |
| 428 | - | |
| 424 | + wp_iframe( array( $render, 'render' ) ); | |
| 425 | + } | |
| 426 | + // changed by Ash/Upwork | |
| 429 | 427 | /** |
| 430 | 428 | * Renders flattr script in the iframe <head> |
| 431 | 429 | * |
| 432 | 430 | * @since 1.4.2 |
| @@ -434,9 +432,9 @@ | ||
| 434 | 432 | * |
| 435 | 433 | * @access public |
| 436 | 434 | */ |
| 437 | 435 | public function renderFlattrScript() { |
| 438 | - echo ''; | |
| 436 | + echo ''; | |
| 439 | 437 | } |
| 440 | 438 | |
| 441 | 439 | /** |
| 442 | 440 | * Parses uploaded CSV file and saves new data for the chart. |
| @@ -446,9 +444,9 @@ | ||
| 446 | 444 | * @access public |
| 447 | 445 | */ |
| 448 | 446 | public function uploadData() { |
| 449 | 447 | // validate nonce |
| 450 | - if ( !wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ) ) ) { | |
| 448 | + if ( ! wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ) ) ) { | |
| 451 | 449 | status_header( 403 ); |
| 452 | 450 | exit; |
| 453 | 451 | } |
| 454 | 452 | |
| @@ -453,9 +451,9 @@ | ||
| 453 | 451 | } |
| 454 | 452 | |
| 455 | 453 | // check chart, if chart exists |
| 456 | 454 | $chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT ); |
| 457 | - if ( !$chart_id || !( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) { | |
| 455 | + if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) { | |
| 458 | 456 | status_header( 400 ); |
| 459 | 457 | exit; |
| 460 | 458 | } |
| 461 | 459 | |
| @@ -461,20 +459,19 @@ | ||
| 461 | 459 | |
| 462 | 460 | $source = null; |
| 463 | 461 | $render = new Visualizer_Render_Page_Update(); |
| 464 | 462 | if ( filter_input( INPUT_POST, 'remote_data', FILTER_VALIDATE_URL ) ) { |
| 465 | - $source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] ); | |
| 463 | + $source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] ); | |
| 466 | 464 | } elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) { |
| 467 | - $source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] ); | |
| 465 | + $source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] ); | |
| 468 | 466 | |
| 469 | - // Added by Ash/Upwork | |
| 470 | - } elseif ( defined( 'Visualizer_Pro' ) && isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0){ | |
| 471 | - global $Visualizer_Pro; | |
| 472 | - $source = $Visualizer_Pro->_handleChartData($_POST['chart_data']); | |
| 473 | - // Added by Ash/Upwork | |
| 474 | - | |
| 475 | - } else { | |
| 476 | - $render->message = esc_html__( "CSV file with chart data was not uploaded. Please, try again.", Visualizer_Plugin::NAME ); | |
| 467 | + // Added by Ash/Upwork | |
| 468 | + } elseif ( defined( 'Visualizer_Pro' ) && isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0 ) { | |
| 469 | + global $Visualizer_Pro; | |
| 470 | + $source = $Visualizer_Pro->_handleChartData( $_POST['chart_data'] ); | |
| 471 | + // Added by Ash/Upwork | |
| 472 | + } else { | |
| 473 | + $render->message = esc_html__( 'CSV file with chart data was not uploaded. Please, try again.', 'visualizer' ); | |
| 477 | 474 | } |
| 478 | 475 | |
| 479 | 476 | if ( $source ) { |
| 480 | 477 | if ( $source->fetch() ) { |
| @@ -487,9 +484,9 @@ | ||
| 487 | 484 | |
| 488 | 485 | $render->data = json_encode( $source->getRawData() ); |
| 489 | 486 | $render->series = json_encode( $source->getSeries() ); |
| 490 | 487 | } else { |
| 491 | - $render->message = esc_html__( "CSV file is broken or invalid. Please, try again.", Visualizer_Plugin::NAME ); | |
| 488 | + $render->message = esc_html__( 'CSV file is broken or invalid. Please, try again.', 'visualizer' ); | |
| 492 | 489 | } |
| 493 | 490 | } |
| 494 | 491 | |
| 495 | 492 | $render->render(); |
| @@ -524,9 +521,9 @@ | ||
| 524 | 521 | 'post_status' => $chart->post_status, |
| 525 | 522 | 'post_content' => $chart->post_content, |
| 526 | 523 | ) ); |
| 527 | 524 | |
| 528 | - if ( $new_chart_id && !is_wp_error( $new_chart_id ) ) { | |
| 525 | + if ( $new_chart_id && ! is_wp_error( $new_chart_id ) ) { | |
| 529 | 526 | add_post_meta( $new_chart_id, Visualizer_Plugin::CF_CHART_TYPE, get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ) ); |
| 530 | 527 | add_post_meta( $new_chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, get_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, true ) ); |
| 531 | 528 | add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SOURCE, get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) ); |
| 532 | 529 | add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SERIES, get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true ) ); |
| @@ -550,9 +547,9 @@ | ||
| 550 | 547 | * |
| 551 | 548 | * @access public |
| 552 | 549 | */ |
| 553 | 550 | public function exportData() { |
| 554 | - check_ajax_referer(Visualizer_Plugin::ACTION_EXPORT_DATA . Visualizer_Plugin::VERSION, "security"); | |
| 551 | + check_ajax_referer( Visualizer_Plugin::ACTION_EXPORT_DATA . Visualizer_Plugin::VERSION, 'security' ); | |
| 555 | 552 | |
| 556 | 553 | $chart_id = $success = false; |
| 557 | 554 | $capable = current_user_can( 'edit_posts' ); |
| 558 | 555 | if ( $capable ) { |
| @@ -563,56 +560,67 @@ | ||
| 563 | 560 | } |
| 564 | 561 | } |
| 565 | 562 | |
| 566 | 563 | if ( $success ) { |
| 567 | - $settings = get_post_meta($chart_id, Visualizer_Plugin::CF_SETTINGS, true); | |
| 568 | - $filename = $settings["title"]; | |
| 569 | - if (empty($filename)) { | |
| 570 | - $filename = "export.csv"; | |
| 571 | - } else { | |
| 572 | - $filename .= ".csv"; | |
| 573 | - } | |
| 574 | - $rows = array(); | |
| 575 | - $series = get_post_meta($chart_id, Visualizer_Plugin::CF_SERIES, true); | |
| 576 | - $data = unserialize($chart->post_content); | |
| 577 | - if (!empty($series)) { | |
| 578 | - $row = array(); | |
| 579 | - foreach ($series as $array) { | |
| 580 | - $row[] = $array["label"]; | |
| 581 | - } | |
| 582 | - $rows[] = $row; | |
| 564 | + $settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ); | |
| 565 | + $filename = $settings['title']; | |
| 566 | + if ( empty( $filename ) ) { | |
| 567 | + $filename = 'export.csv'; | |
| 568 | + } else { | |
| 569 | + $filename .= '.csv'; | |
| 570 | + } | |
| 571 | + $rows = array(); | |
| 572 | + $series = get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true ); | |
| 573 | + $data = unserialize( $chart->post_content ); | |
| 574 | + if ( ! empty( $series ) ) { | |
| 575 | + $row = array(); | |
| 576 | + foreach ( $series as $array ) { | |
| 577 | + $row[] = $array['label']; | |
| 578 | + } | |
| 579 | + $rows[] = $row; | |
| 583 | 580 | |
| 584 | - $row = array(); | |
| 585 | - foreach ($series as $array) { | |
| 586 | - $row[] = $array["type"]; | |
| 587 | - } | |
| 588 | - $rows[] = $row; | |
| 589 | - } | |
| 581 | + $row = array(); | |
| 582 | + foreach ( $series as $array ) { | |
| 583 | + $row[] = $array['type']; | |
| 584 | + } | |
| 585 | + $rows[] = $row; | |
| 586 | + } | |
| 590 | 587 | |
| 591 | - if (!empty($data)) { | |
| 592 | - foreach ($data as $array) { | |
| 593 | - $rows[] = $array; | |
| 594 | - } | |
| 595 | - } | |
| 588 | + if ( ! empty( $data ) ) { | |
| 589 | + foreach ( $data as $array ) { | |
| 590 | + // ignore strings | |
| 591 | + if ( ! is_array( $array ) ) { continue; } | |
| 596 | 592 | |
| 597 | - $fp = tmpfile(); | |
| 598 | - foreach ($rows as $row) { | |
| 599 | - fputcsv($fp, $row); | |
| 600 | - } | |
| 601 | - rewind($fp); | |
| 593 | + // if this is an array of arrays... | |
| 594 | + if ( is_array( $array[0] ) ) { | |
| 595 | + foreach ( $array as $arr ) { | |
| 596 | + $rows[] = $arr; | |
| 597 | + } | |
| 598 | + } else { | |
| 599 | + // just an array | |
| 600 | + $rows[] = $array; | |
| 601 | + } | |
| 602 | + } | |
| 603 | + } | |
| 602 | 604 | |
| 603 | - $csv = ""; | |
| 604 | - while (($array = fgetcsv($fp)) !== FALSE) { | |
| 605 | - if (strlen($csv) > 0) $csv .= PHP_EOL; | |
| 606 | - $csv .= implode(",", $array); | |
| 607 | - } | |
| 608 | - fclose($fp); | |
| 605 | + $fp = tmpfile(); | |
| 606 | + foreach ( $rows as $row ) { | |
| 607 | + fputcsv( $fp, $row ); | |
| 608 | + } | |
| 609 | + rewind( $fp ); | |
| 609 | 610 | |
| 610 | - echo wp_send_json_success(array( | |
| 611 | - "csv" => $csv, | |
| 612 | - "name" => $filename | |
| 613 | - )); | |
| 611 | + $csv = ''; | |
| 612 | + while ( ($array = fgetcsv( $fp )) !== false ) { | |
| 613 | + if ( strlen( $csv ) > 0 ) { $csv .= PHP_EOL; } | |
| 614 | + $csv .= implode( ',', $array ); | |
| 615 | + } | |
| 616 | + fclose( $fp ); | |
| 617 | + | |
| 618 | + echo wp_send_json_success(array( | |
| 619 | + 'csv' => $csv, | |
| 620 | + 'name' => $filename, | |
| 621 | + )); | |
| 614 | 622 | } |
| 615 | 623 | |
| 616 | 624 | exit; |
| 617 | 625 | } |
| 618 | -} | |
| 626 | +} | |