| @@ -72,23 +72,16 @@ | ||
| 72 | 72 | public function getCharts() { |
| 73 | 73 | $query_args = array( |
| 74 | 74 | 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, |
| 75 | 75 | 'posts_per_page' => 9, |
| 76 | - 'paged' => filter_input( | |
| 77 | - INPUT_GET, 'page', FILTER_VALIDATE_INT, array( | |
| 78 | - 'options' => array( | |
| 79 | - 'min_range' => 1, | |
| 80 | - 'default' => 1, | |
| 81 | - ), | |
| 82 | - ) | |
| 83 | - ), | |
| 76 | + 'paged' => filter_input( INPUT_GET, 'page', FILTER_VALIDATE_INT, array( | |
| 77 | + 'options' => array( | |
| 78 | + 'min_range' => 1, | |
| 79 | + 'default' => 1, | |
| 80 | + ), | |
| 81 | + ) ), | |
| 84 | 82 | ); |
| 85 | 83 | $filter = filter_input( INPUT_GET, 's', FILTER_SANITIZE_STRING ); |
| 86 | - if ( empty( $filter ) ) { | |
| 87 | - // 'filter' is from the modal from the add media button. | |
| 88 | - $filter = filter_input( INPUT_GET, 'filter', FILTER_SANITIZE_STRING ); | |
| 89 | - } | |
| 90 | - | |
| 91 | 84 | if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) { |
| 92 | 85 | $query_args['meta_query'] = array( |
| 93 | 86 | array( |
| 94 | 87 | 'key' => Visualizer_Plugin::CF_CHART_TYPE, |
| @@ -104,15 +97,13 @@ | ||
| 104 | 97 | $chart_data = $this->_getChartArray( $chart ); |
| 105 | 98 | $chart_data['id'] = $chart->ID; |
| 106 | 99 | $charts[] = $chart_data; |
| 107 | 100 | } |
| 108 | - self::_sendResponse( | |
| 109 | - array( | |
| 110 | - 'success' => true, | |
| 111 | - 'data' => $charts, | |
| 112 | - 'total' => $query->max_num_pages, | |
| 113 | - ) | |
| 114 | - ); | |
| 101 | + self::_sendResponse( array( | |
| 102 | + 'success' => true, | |
| 103 | + 'data' => $charts, | |
| 104 | + 'total' => $query->max_num_pages, | |
| 105 | + ) ); | |
| 115 | 106 | } |
| 116 | 107 | |
| 117 | 108 | /** |
| 118 | 109 | * Returns chart data required for rendering. |
| @@ -171,15 +162,13 @@ | ||
| 171 | 162 | $chart_id = $success = false; |
| 172 | 163 | $nonce = wp_verify_nonce( filter_input( $input_method, 'nonce' ) ); |
| 173 | 164 | $capable = current_user_can( 'delete_posts' ); |
| 174 | 165 | if ( $nonce && $capable ) { |
| 175 | - $chart_id = filter_input( | |
| 176 | - $input_method, 'chart', FILTER_VALIDATE_INT, array( | |
| 177 | - 'options' => array( | |
| 178 | - 'min_range' => 1, | |
| 179 | - ), | |
| 180 | - ) | |
| 181 | - ); | |
| 166 | + $chart_id = filter_input( $input_method, 'chart', FILTER_VALIDATE_INT, array( | |
| 167 | + 'options' => array( | |
| 168 | + 'min_range' => 1, | |
| 169 | + ), | |
| 170 | + ) ); | |
| 182 | 171 | if ( $chart_id ) { |
| 183 | 172 | $chart = get_post( $chart_id ); |
| 184 | 173 | $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER; |
| 185 | 174 | } |
| @@ -187,13 +176,11 @@ | ||
| 187 | 176 | if ( $success ) { |
| 188 | 177 | wp_delete_post( $chart_id, true ); |
| 189 | 178 | } |
| 190 | 179 | if ( $is_post ) { |
| 191 | - self::_sendResponse( | |
| 192 | - array( | |
| 193 | - 'success' => $success, | |
| 194 | - ) | |
| 195 | - ); | |
| 180 | + self::_sendResponse( array( | |
| 181 | + 'success' => $success, | |
| 182 | + ) ); | |
| 196 | 183 | } |
| 197 | 184 | wp_redirect( wp_get_referer() ); |
| 198 | 185 | exit; |
| 199 | 186 | } |
| @@ -213,53 +200,41 @@ | ||
| 213 | 200 | if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) { |
| 214 | 201 | $default_type = 'line'; |
| 215 | 202 | $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' ); |
| 216 | 203 | $source->fetch(); |
| 217 | - $chart_id = wp_insert_post( | |
| 218 | - array( | |
| 219 | - 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, | |
| 220 | - 'post_title' => 'Visualization', | |
| 221 | - 'post_author' => get_current_user_id(), | |
| 222 | - 'post_status' => 'auto-draft', | |
| 223 | - 'post_content' => $source->getData(), | |
| 224 | - ) | |
| 225 | - ); | |
| 204 | + $chart_id = wp_insert_post( array( | |
| 205 | + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, | |
| 206 | + 'post_title' => 'Visualization', | |
| 207 | + 'post_author' => get_current_user_id(), | |
| 208 | + 'post_status' => 'auto-draft', | |
| 209 | + 'post_content' => $source->getData(), | |
| 210 | + ) ); | |
| 226 | 211 | if ( $chart_id && ! is_wp_error( $chart_id ) ) { |
| 227 | 212 | add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, $default_type ); |
| 228 | 213 | add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 ); |
| 229 | 214 | add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 230 | 215 | add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); |
| 231 | - add_post_meta( | |
| 232 | - $chart_id, Visualizer_Plugin::CF_SETTINGS, array( | |
| 233 | - 'focusTarget' => 'datum', | |
| 234 | - ) | |
| 235 | - ); | |
| 236 | - do_action( 'visualizer_pro_new_chart_defaults', $chart_id ); | |
| 216 | + add_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, array( | |
| 217 | + 'focusTarget' => 'datum', | |
| 218 | + ) ); | |
| 237 | 219 | } |
| 238 | 220 | wp_redirect( add_query_arg( 'chart', (int) $chart_id ) ); |
| 239 | 221 | defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); |
| 240 | 222 | } |
| 241 | 223 | // enqueue and register scripts and styles |
| 242 | - wp_register_script( 'visualizer-chosen', VISUALIZER_ABSURL . 'js/lib/chosen.jquery.min.js', array( 'jquery' ), Visualizer_Plugin::VERSION ); | |
| 243 | - wp_register_style( 'visualizer-chosen', VISUALIZER_ABSURL . 'css/lib/chosen.min.css', array(), Visualizer_Plugin::VERSION ); | |
| 244 | - | |
| 245 | - wp_register_style( 'visualizer-frame', VISUALIZER_ABSURL . 'css/frame.css', array( 'visualizer-chosen' ), Visualizer_Plugin::VERSION ); | |
| 246 | - wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'visualizer-chosen' ), Visualizer_Plugin::VERSION, true ); | |
| 224 | + wp_register_style( 'visualizer-frame', VISUALIZER_ABSURL . 'css/frame.css', array(), Visualizer_Plugin::VERSION ); | |
| 225 | + wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true ); | |
| 247 | 226 | wp_register_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true ); |
| 248 | 227 | wp_register_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true ); |
| 249 | - wp_register_script( | |
| 250 | - 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( | |
| 251 | - 'google-jsapi-old', | |
| 252 | - 'google-jsapi-new', | |
| 253 | - 'visualizer-frame', | |
| 254 | - ), Visualizer_Plugin::VERSION, true | |
| 255 | - ); | |
| 256 | - wp_register_script( | |
| 257 | - 'visualizer-preview', VISUALIZER_ABSURL . 'js/preview.js', array( | |
| 258 | - 'wp-color-picker', | |
| 259 | - 'visualizer-render', | |
| 260 | - ), Visualizer_Plugin::VERSION, true | |
| 261 | - ); | |
| 228 | + wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( | |
| 229 | + 'google-jsapi-old', | |
| 230 | + 'google-jsapi-new', | |
| 231 | + 'visualizer-frame', | |
| 232 | + ), Visualizer_Plugin::VERSION, true ); | |
| 233 | + wp_register_script( 'visualizer-preview', VISUALIZER_ABSURL . 'js/preview.js', array( | |
| 234 | + 'wp-color-picker', | |
| 235 | + 'visualizer-render', | |
| 236 | + ), Visualizer_Plugin::VERSION, true ); | |
| 262 | 237 | // added by Ash/Upwork |
| 263 | 238 | if ( VISUALIZER_PRO ) { |
| 264 | 239 | global $Visualizer_Pro; |
| 265 | 240 | $Visualizer_Pro->_addScriptsAndStyles(); |
| @@ -265,26 +240,17 @@ | ||
| 265 | 240 | $Visualizer_Pro->_addScriptsAndStyles(); |
| 266 | 241 | } |
| 267 | 242 | // dispatch pages |
| 268 | 243 | $this->_chart = get_post( $chart_id ); |
| 269 | - $tab = isset( $_GET['tab'] ) && ! empty( $_GET['tab'] ) ? $_GET['tab'] : 'visualizer'; | |
| 270 | - | |
| 271 | - // skip chart type pages only for existing charts. | |
| 272 | - if ( VISUALIZER_SKIP_CHART_TYPE_PAGE && 'auto-draft' !== $this->_chart->post_status ) { | |
| 273 | - $tab = 'settings'; | |
| 274 | - } | |
| 275 | - | |
| 276 | - switch ( $tab ) { | |
| 244 | + switch ( isset( $_GET['tab'] ) ? $_GET['tab'] : '' ) { | |
| 277 | 245 | case 'settings': |
| 246 | + // changed by Ash/Upwork | |
| 278 | 247 | $this->_handleDataAndSettingsPage(); |
| 279 | 248 | break; |
| 280 | - case 'type': // fall through. | |
| 281 | - case 'visualizer': // fall through. | |
| 249 | + case 'type': | |
| 250 | + default: | |
| 282 | 251 | $this->_handleTypesPage(); |
| 283 | 252 | break; |
| 284 | - default: | |
| 285 | - do_action( 'visualizer_pro_handle_tab', $tab, $this->_chart ); | |
| 286 | - break; | |
| 287 | 253 | } |
| 288 | 254 | defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); |
| 289 | 255 | } |
| 290 | 256 | |
| @@ -291,11 +257,8 @@ | ||
| 291 | 257 | /** |
| 292 | 258 | * Handle data and settings page |
| 293 | 259 | */ |
| 294 | 260 | private function _handleDataAndSettingsPage() { |
| 295 | - if ( isset( $_POST['map_api_key'] ) ) { | |
| 296 | - update_option( 'visualizer-map-api-key', $_POST['map_api_key'] ); | |
| 297 | - } | |
| 298 | 261 | if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'] ) ) { |
| 299 | 262 | if ( $this->_chart->post_status == 'auto-draft' ) { |
| 300 | 263 | $this->_chart->post_status = 'publish'; |
| 301 | 264 | wp_update_post( $this->_chart->to_array() ); |
| @@ -326,30 +289,16 @@ | ||
| 326 | 289 | wp_enqueue_style( 'wp-color-picker' ); |
| 327 | 290 | wp_enqueue_style( 'visualizer-frame' ); |
| 328 | 291 | wp_enqueue_script( 'visualizer-preview' ); |
| 329 | 292 | wp_enqueue_script( 'visualizer-render' ); |
| 330 | - wp_localize_script( | |
| 331 | - 'visualizer-render', 'visualizer', array( | |
| 332 | - 'l10n' => array( | |
| 333 | - 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ), | |
| 334 | - 'loading' => esc_html__( 'Loading...', 'visualizer' ), | |
| 335 | - ), | |
| 336 | - 'charts' => array( | |
| 337 | - 'canvas' => $data, | |
| 338 | - ), | |
| 339 | - 'language' => $this->get_language(), | |
| 340 | - 'map_api_key' => get_option( 'visualizer-map-api-key' ), | |
| 341 | - 'ajax' => array( | |
| 342 | - 'url' => admin_url( 'admin-ajax.php' ), | |
| 343 | - 'nonces' => array( | |
| 344 | - 'permissions' => wp_create_nonce( Visualizer_Plugin::ACTION_FETCH_PERMISSIONS_DATA ), | |
| 345 | - ), | |
| 346 | - 'actions' => array( | |
| 347 | - 'permissions' => Visualizer_Plugin::ACTION_FETCH_PERMISSIONS_DATA, | |
| 348 | - ), | |
| 349 | - ), | |
| 350 | - ) | |
| 351 | - ); | |
| 293 | + wp_localize_script( 'visualizer-render', 'visualizer', array( | |
| 294 | + 'l10n' => array( | |
| 295 | + 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ), | |
| 296 | + ), | |
| 297 | + 'charts' => array( | |
| 298 | + 'canvas' => $data, | |
| 299 | + ), | |
| 300 | + ) ); | |
| 352 | 301 | $render = new Visualizer_Render_Page_Data(); |
| 353 | 302 | $render->chart = $this->_chart; |
| 354 | 303 | $render->type = $data['type']; |
| 355 | 304 | $render->sidebar = $sidebar; |
| @@ -440,14 +389,8 @@ | ||
| 440 | 389 | } |
| 441 | 390 | if ( ! isset( $_POST['vz-import-time'] ) ) { |
| 442 | 391 | apply_filters( 'visualizer_pro_remove_schedule', $chart_id ); |
| 443 | 392 | } |
| 444 | - | |
| 445 | - if ( ! isset( $_POST['chart_data_src'] ) || Visualizer_Plugin::CF_SOURCE_FILTER !== $_POST['chart_data_src'] ) { | |
| 446 | - // delete the filters in case this chart is being uploaded from other data sources | |
| 447 | - delete_post_meta( $chart_id, 'visualizer-filter-config' ); | |
| 448 | - } | |
| 449 | - | |
| 450 | 393 | $source = null; |
| 451 | 394 | $render = new Visualizer_Render_Page_Update(); |
| 452 | 395 | if ( isset( $_POST['remote_data'] ) && filter_var( $_POST['remote_data'], FILTER_VALIDATE_URL ) ) { |
| 453 | 396 | $source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] ); |
| @@ -476,11 +419,9 @@ | ||
| 476 | 419 | $render->message = esc_html__( 'CSV file is broken or invalid. Please, try again.', 'visualizer' ); |
| 477 | 420 | } |
| 478 | 421 | } |
| 479 | 422 | $render->render(); |
| 480 | - if ( ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE ) ) { | |
| 481 | - defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); | |
| 482 | - } | |
| 423 | + defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); | |
| 483 | 424 | } |
| 484 | 425 | |
| 485 | 426 | /** |
| 486 | 427 | * Clones the chart. |
| @@ -493,15 +434,13 @@ | ||
| 493 | 434 | $chart_id = $success = false; |
| 494 | 435 | $nonce = wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ), Visualizer_Plugin::ACTION_CLONE_CHART ); |
| 495 | 436 | $capable = current_user_can( 'edit_posts' ); |
| 496 | 437 | if ( $nonce && $capable ) { |
| 497 | - $chart_id = filter_input( | |
| 498 | - INPUT_GET, 'chart', FILTER_VALIDATE_INT, array( | |
| 499 | - 'options' => array( | |
| 500 | - 'min_range' => 1, | |
| 501 | - ), | |
| 502 | - ) | |
| 503 | - ); | |
| 438 | + $chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT, array( | |
| 439 | + 'options' => array( | |
| 440 | + 'min_range' => 1, | |
| 441 | + ), | |
| 442 | + ) ); | |
| 504 | 443 | if ( $chart_id ) { |
| 505 | 444 | $chart = get_post( $chart_id ); |
| 506 | 445 | $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER; |
| 507 | 446 | } |
| @@ -507,17 +446,15 @@ | ||
| 507 | 446 | } |
| 508 | 447 | } |
| 509 | 448 | $redirect = wp_get_referer(); |
| 510 | 449 | if ( $success ) { |
| 511 | - $new_chart_id = wp_insert_post( | |
| 512 | - array( | |
| 513 | - 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, | |
| 514 | - 'post_title' => 'Visualization', | |
| 515 | - 'post_author' => get_current_user_id(), | |
| 516 | - 'post_status' => $chart->post_status, | |
| 517 | - 'post_content' => $chart->post_content, | |
| 518 | - ) | |
| 519 | - ); | |
| 450 | + $new_chart_id = wp_insert_post( array( | |
| 451 | + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, | |
| 452 | + 'post_title' => 'Visualization', | |
| 453 | + 'post_author' => get_current_user_id(), | |
| 454 | + 'post_status' => $chart->post_status, | |
| 455 | + 'post_content' => $chart->post_content, | |
| 456 | + ) ); | |
| 520 | 457 | if ( $new_chart_id && ! is_wp_error( $new_chart_id ) ) { |
| 521 | 458 | add_post_meta( $new_chart_id, Visualizer_Plugin::CF_CHART_TYPE, get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ) ); |
| 522 | 459 | add_post_meta( $new_chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, get_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, true ) ); |
| 523 | 460 | add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SOURCE, get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) ); |
| @@ -522,14 +459,12 @@ | ||
| 522 | 459 | add_post_meta( $new_chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, get_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, true ) ); |
| 523 | 460 | add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SOURCE, get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) ); |
| 524 | 461 | add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SERIES, get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true ) ); |
| 525 | 462 | add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SETTINGS, get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ) ); |
| 526 | - $redirect = add_query_arg( | |
| 527 | - array( | |
| 528 | - 'page' => 'visualizer', | |
| 529 | - 'type' => filter_input( INPUT_GET, 'type' ), | |
| 530 | - ), admin_url( 'upload.php' ) | |
| 531 | - ); | |
| 463 | + $redirect = add_query_arg( array( | |
| 464 | + 'page' => 'visualizer', | |
| 465 | + 'type' => filter_input( INPUT_GET, 'type' ), | |
| 466 | + ), admin_url( 'upload.php' ) ); | |
| 532 | 467 | } |
| 533 | 468 | } |
| 534 | 469 | wp_redirect( $redirect ); |
| 535 | 470 | exit; |
| @@ -543,25 +478,79 @@ | ||
| 543 | 478 | * @access public |
| 544 | 479 | */ |
| 545 | 480 | public function exportData() { |
| 546 | 481 | check_ajax_referer( Visualizer_Plugin::ACTION_EXPORT_DATA . Visualizer_Plugin::VERSION, 'security' ); |
| 482 | + $chart_id = $success = false; | |
| 547 | 483 | $capable = current_user_can( 'edit_posts' ); |
| 548 | 484 | if ( $capable ) { |
| 549 | - $chart_id = isset( $_GET['chart'] ) ? filter_var( | |
| 550 | - $_GET['chart'], FILTER_VALIDATE_INT, array( | |
| 551 | - 'options' => array( | |
| 552 | - 'min_range' => 1, | |
| 553 | - ), | |
| 554 | - ) | |
| 555 | - ) : ''; | |
| 485 | + $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT, array( | |
| 486 | + 'options' => array( | |
| 487 | + 'min_range' => 1, | |
| 488 | + ), | |
| 489 | + ) ) : ''; | |
| 556 | 490 | if ( $chart_id ) { |
| 557 | - $data = $this->_getDataAs( $chart_id, 'csv' ); | |
| 558 | - if ( $data ) { | |
| 559 | - echo wp_send_json_success( $data ); | |
| 491 | + $chart = get_post( $chart_id ); | |
| 492 | + $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER; | |
| 493 | + } | |
| 494 | + } | |
| 495 | + if ( $success ) { | |
| 496 | + $settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ); | |
| 497 | + $filename = isset( $settings['title'] ) ? $settings['title'] : ''; | |
| 498 | + if ( empty( $filename ) ) { | |
| 499 | + $filename = 'export.csv'; | |
| 500 | + } else { | |
| 501 | + $filename .= '.csv'; | |
| 502 | + } | |
| 503 | + $rows = array(); | |
| 504 | + $series = get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true ); | |
| 505 | + $data = unserialize( $chart->post_content ); | |
| 506 | + if ( ! empty( $series ) ) { | |
| 507 | + $row = array(); | |
| 508 | + foreach ( $series as $array ) { | |
| 509 | + $row[] = $array['label']; | |
| 560 | 510 | } |
| 511 | + $rows[] = $row; | |
| 512 | + $row = array(); | |
| 513 | + foreach ( $series as $array ) { | |
| 514 | + $row[] = $array['type']; | |
| 515 | + } | |
| 516 | + $rows[] = $row; | |
| 561 | 517 | } |
| 562 | - } | |
| 563 | - | |
| 518 | + if ( ! empty( $data ) ) { | |
| 519 | + foreach ( $data as $array ) { | |
| 520 | + // ignore strings | |
| 521 | + if ( ! is_array( $array ) ) { | |
| 522 | + continue; | |
| 523 | + } | |
| 524 | + // if this is an array of arrays... | |
| 525 | + if ( is_array( $array[0] ) ) { | |
| 526 | + foreach ( $array as $arr ) { | |
| 527 | + $rows[] = $arr; | |
| 528 | + } | |
| 529 | + } else { | |
| 530 | + // just an array | |
| 531 | + $rows[] = $array; | |
| 532 | + } | |
| 533 | + } | |
| 534 | + } | |
| 535 | + $fp = tmpfile(); | |
| 536 | + foreach ( $rows as $row ) { | |
| 537 | + fputcsv( $fp, $row ); | |
| 538 | + } | |
| 539 | + rewind( $fp ); | |
| 540 | + $csv = ''; | |
| 541 | + while ( ( $array = fgetcsv( $fp ) ) !== false ) { | |
| 542 | + if ( strlen( $csv ) > 0 ) { | |
| 543 | + $csv .= PHP_EOL; | |
| 544 | + } | |
| 545 | + $csv .= implode( ',', $array ); | |
| 546 | + } | |
| 547 | + fclose( $fp ); | |
| 548 | + echo wp_send_json_success( array( | |
| 549 | + 'csv' => $csv, | |
| 550 | + 'name' => $filename, | |
| 551 | + ) ); | |
| 552 | + }// End if(). | |
| 564 | 553 | defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); |
| 565 | 554 | } |
| 566 | 555 | |
| 567 | 556 | /** |
| @@ -578,19 +567,16 @@ | ||
| 578 | 567 | $render->type = $data['type']; |
| 579 | 568 | unset( $data['settings']['width'], $data['settings']['height'] ); |
| 580 | 569 | wp_enqueue_style( 'visualizer-frame' ); |
| 581 | 570 | wp_enqueue_script( 'visualizer-render' ); |
| 582 | - wp_localize_script( | |
| 583 | - 'visualizer-render', 'visualizer', array( | |
| 584 | - 'l10n' => array( | |
| 585 | - 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ), | |
| 586 | - 'loading' => esc_html__( 'Loading...', 'visualizer' ), | |
| 587 | - ), | |
| 588 | - 'charts' => array( | |
| 589 | - 'canvas' => $data, | |
| 590 | - ), | |
| 591 | - ) | |
| 592 | - ); | |
| 571 | + wp_localize_script( 'visualizer-render', 'visualizer', array( | |
| 572 | + 'l10n' => array( | |
| 573 | + 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ), | |
| 574 | + ), | |
| 575 | + 'charts' => array( | |
| 576 | + 'canvas' => $data, | |
| 577 | + ), | |
| 578 | + ) ); | |
| 593 | 579 | // Added by Ash/Upwork |
| 594 | 580 | if ( VISUALIZER_PRO ) { |
| 595 | 581 | global $Visualizer_Pro; |
| 596 | 582 | $Visualizer_Pro->_enqueueScriptsAndStyles( $data ); |