| @@ -60,11 +60,159 @@ | ||
| 60 | 60 | $this->_addAjaxAction( Visualizer_Plugin::ACTION_EXPORT_DATA, 'exportData' ); |
| 61 | 61 | |
| 62 | 62 | $this->_addAjaxAction( Visualizer_Plugin::ACTION_FETCH_DB_DATA, 'getQueryData' ); |
| 63 | 63 | $this->_addAjaxAction( Visualizer_Plugin::ACTION_SAVE_DB_QUERY, 'saveQuery' ); |
| 64 | + | |
| 65 | + $this->_addAjaxAction( Visualizer_Plugin::ACTION_JSON_GET_ROOTS, 'getJsonRoots' ); | |
| 66 | + $this->_addAjaxAction( Visualizer_Plugin::ACTION_JSON_GET_DATA, 'getJsonData' ); | |
| 67 | + $this->_addAjaxAction( Visualizer_Plugin::ACTION_JSON_SET_DATA, 'setJsonData' ); | |
| 68 | + $this->_addAjaxAction( Visualizer_Plugin::ACTION_JSON_SET_SCHEDULE, 'setJsonSchedule' ); | |
| 69 | + | |
| 70 | + $this->_addAjaxAction( Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY, 'saveFilter' ); | |
| 71 | + | |
| 64 | 72 | } |
| 65 | 73 | |
| 66 | 74 | /** |
| 75 | + * Sets the schedule for how JSON-endpoint charts should be updated. | |
| 76 | + * | |
| 77 | + * @since ? | |
| 78 | + * | |
| 79 | + * @access public | |
| 80 | + */ | |
| 81 | + public function setJsonSchedule() { | |
| 82 | + check_ajax_referer( Visualizer_Plugin::ACTION_JSON_SET_SCHEDULE . Visualizer_Plugin::VERSION, 'security' ); | |
| 83 | + | |
| 84 | + $chart_id = filter_input( | |
| 85 | + INPUT_POST, | |
| 86 | + 'chart', | |
| 87 | + FILTER_VALIDATE_INT, | |
| 88 | + array( | |
| 89 | + 'options' => array( | |
| 90 | + 'min_range' => 1, | |
| 91 | + ), | |
| 92 | + ) | |
| 93 | + ); | |
| 94 | + | |
| 95 | + if ( ! $chart_id ) { | |
| 96 | + wp_send_json_error(); | |
| 97 | + } | |
| 98 | + | |
| 99 | + $time = filter_input( | |
| 100 | + INPUT_POST, | |
| 101 | + 'time', | |
| 102 | + FILTER_VALIDATE_INT, | |
| 103 | + array( | |
| 104 | + 'options' => array( | |
| 105 | + 'min_range' => -1, | |
| 106 | + ), | |
| 107 | + ) | |
| 108 | + ); | |
| 109 | + | |
| 110 | + delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE ); | |
| 111 | + | |
| 112 | + if ( -1 < $time ) { | |
| 113 | + add_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, $time ); | |
| 114 | + } | |
| 115 | + wp_send_json_success(); | |
| 116 | + } | |
| 117 | + | |
| 118 | + /** | |
| 119 | + * Get the root elements for JSON-endpoint. | |
| 120 | + * | |
| 121 | + * @since ? | |
| 122 | + * | |
| 123 | + * @access public | |
| 124 | + */ | |
| 125 | + public function getJsonRoots() { | |
| 126 | + check_ajax_referer( Visualizer_Plugin::ACTION_JSON_GET_ROOTS . Visualizer_Plugin::VERSION, 'security' ); | |
| 127 | + | |
| 128 | + $params = wp_parse_args( $_POST['params'] ); | |
| 129 | + | |
| 130 | + $source = new Visualizer_Source_Json( $params ); | |
| 131 | + | |
| 132 | + $roots = $source->fetchRoots(); | |
| 133 | + if ( empty( $roots ) ) { | |
| 134 | + wp_send_json_error( array( 'msg' => $source->get_error() ) ); | |
| 135 | + } | |
| 136 | + | |
| 137 | + wp_send_json_success( array( 'url' => $params['url'], 'roots' => $roots ) ); | |
| 138 | + } | |
| 139 | + | |
| 140 | + /** | |
| 141 | + * Get the data for the JSON-endpoint corresponding to the chosen root. | |
| 142 | + * | |
| 143 | + * @since ? | |
| 144 | + * | |
| 145 | + * @access public | |
| 146 | + */ | |
| 147 | + public function getJsonData() { | |
| 148 | + check_ajax_referer( Visualizer_Plugin::ACTION_JSON_GET_DATA . Visualizer_Plugin::VERSION, 'security' ); | |
| 149 | + | |
| 150 | + $params = wp_parse_args( $_POST['params'] ); | |
| 151 | + | |
| 152 | + $chart_id = $params['chart']; | |
| 153 | + | |
| 154 | + if ( empty( $chart_id ) ) { | |
| 155 | + wp_die(); | |
| 156 | + } | |
| 157 | + | |
| 158 | + $source = new Visualizer_Source_Json( $params ); | |
| 159 | + | |
| 160 | + $data = $source->parse(); | |
| 161 | + if ( empty( $data ) ) { | |
| 162 | + wp_send_json_error( array( 'msg' => esc_html__( 'Unable to fetch data from the endpoint. Please try again.', 'visualizer' ) ) ); | |
| 163 | + } | |
| 164 | + | |
| 165 | + $data = Visualizer_Render_Layout::show( 'editor-table', $data, $chart_id, 'viz-json-table', false, false ); | |
| 166 | + wp_send_json_success( array( 'table' => $data, 'root' => $params['root'], 'url' => $params['url'], 'paging' => $source->getPaginationElements() ) ); | |
| 167 | + } | |
| 168 | + | |
| 169 | + /** | |
| 170 | + * Updates the database with the correct post parameters for JSON-endpoint charts. | |
| 171 | + * | |
| 172 | + * @since ? | |
| 173 | + * | |
| 174 | + * @access public | |
| 175 | + */ | |
| 176 | + public function setJsonData() { | |
| 177 | + check_ajax_referer( Visualizer_Plugin::ACTION_JSON_SET_DATA . Visualizer_Plugin::VERSION, 'security' ); | |
| 178 | + | |
| 179 | + $params = $_POST; | |
| 180 | + $chart_id = $_GET['chart']; | |
| 181 | + | |
| 182 | + if ( empty( $chart_id ) ) { | |
| 183 | + wp_die(); | |
| 184 | + } | |
| 185 | + | |
| 186 | + $chart = get_post( $chart_id ); | |
| 187 | + | |
| 188 | + $source = new Visualizer_Source_Json( $params ); | |
| 189 | + $source->fetch(); | |
| 190 | + | |
| 191 | + $content = $source->getData(); | |
| 192 | + $chart->post_content = $content; | |
| 193 | + wp_update_post( $chart->to_array() ); | |
| 194 | + update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); | |
| 195 | + update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); | |
| 196 | + update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 ); | |
| 197 | + update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_URL, $params['url'] ); | |
| 198 | + update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_ROOT, $params['root'] ); | |
| 199 | + delete_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_PAGING ); | |
| 200 | + if ( ! empty( $params['paging'] ) ) { | |
| 201 | + add_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_PAGING, $params['paging'] ); | |
| 202 | + } | |
| 203 | + | |
| 204 | + $render = new Visualizer_Render_Page_Update(); | |
| 205 | + $render->id = $chart->ID; | |
| 206 | + $render->data = json_encode( $source->getRawData() ); | |
| 207 | + $render->series = json_encode( $source->getSeries() ); | |
| 208 | + $render->render(); | |
| 209 | + | |
| 210 | + defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); | |
| 211 | + } | |
| 212 | + | |
| 213 | + | |
| 214 | + /** | |
| 67 | 215 | * Fetches charts from database. |
| 68 | 216 | * |
| 69 | 217 | * This method is also called from the media pop-up (classic editor: create a post and add chart from insert content). |
| 70 | 218 | * |
| @@ -93,9 +241,9 @@ | ||
| 93 | 241 | // 'filter' is from the modal from the add media button. |
| 94 | 242 | $filter = filter_input( INPUT_GET, 'filter', FILTER_SANITIZE_STRING ); |
| 95 | 243 | } |
| 96 | 244 | |
| 97 | - if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) { | |
| 245 | + if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes(), true ) ) { | |
| 98 | 246 | $query_args['meta_query'] = array( |
| 99 | 247 | array( |
| 100 | 248 | 'key' => Visualizer_Plugin::CF_CHART_TYPE, |
| 101 | 249 | 'value' => $filter, |
| @@ -162,8 +310,10 @@ | ||
| 162 | 310 | $css = $arguments[0]; |
| 163 | 311 | $settings = $arguments[1]; |
| 164 | 312 | } |
| 165 | 313 | |
| 314 | + $date_formats = Visualizer_Source::get_date_formats_if_exists( $series, $data ); | |
| 315 | + | |
| 166 | 316 | return array( |
| 167 | 317 | 'type' => $type, |
| 168 | 318 | 'series' => $series, |
| 169 | 319 | 'settings' => $settings, |
| @@ -169,8 +319,9 @@ | ||
| 169 | 319 | 'settings' => $settings, |
| 170 | 320 | 'data' => $data, |
| 171 | 321 | 'library' => $library, |
| 172 | 322 | 'css' => $css, |
| 323 | + 'date_formats' => $date_formats, | |
| 173 | 324 | ); |
| 174 | 325 | } |
| 175 | 326 | |
| 176 | 327 | /** |
| @@ -197,9 +348,9 @@ | ||
| 197 | 348 | * |
| 198 | 349 | * @access public |
| 199 | 350 | */ |
| 200 | 351 | public function deleteChart() { |
| 201 | - $is_post = $_SERVER['REQUEST_METHOD'] == 'POST'; | |
| 352 | + $is_post = $_SERVER['REQUEST_METHOD'] === 'POST'; | |
| 202 | 353 | $input_method = $is_post ? INPUT_POST : INPUT_GET; |
| 203 | 354 | $chart_id = $success = false; |
| 204 | 355 | $nonce = wp_verify_nonce( filter_input( $input_method, 'nonce' ) ); |
| 205 | 356 | $capable = current_user_can( 'delete_posts' ); |
| @@ -215,9 +366,9 @@ | ||
| 215 | 366 | ) |
| 216 | 367 | ); |
| 217 | 368 | if ( $chart_id ) { |
| 218 | 369 | $chart = get_post( $chart_id ); |
| 219 | - $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER; | |
| 370 | + $success = $chart && $chart->post_type === Visualizer_Plugin::CPT_VISUALIZER; | |
| 220 | 371 | } |
| 221 | 372 | } |
| 222 | 373 | if ( $success ) { |
| 223 | 374 | wp_delete_post( $chart_id, true ); |
| @@ -228,13 +379,41 @@ | ||
| 228 | 379 | 'success' => $success, |
| 229 | 380 | ) |
| 230 | 381 | ); |
| 231 | 382 | } |
| 232 | - wp_redirect( wp_get_referer() ); | |
| 383 | + wp_redirect( remove_query_arg( 'vaction', wp_get_referer() ) ); | |
| 233 | 384 | exit; |
| 234 | 385 | } |
| 235 | 386 | |
| 236 | 387 | /** |
| 388 | + * Delete charts that are still in auto-draft mode. | |
| 389 | + */ | |
| 390 | + private function deleteOldCharts() { | |
| 391 | + $query = new WP_Query( | |
| 392 | + array( | |
| 393 | + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, | |
| 394 | + 'post_status' => 'auto-draft', | |
| 395 | + 'fields' => 'ids', | |
| 396 | + 'update_post_meta_cache' => false, | |
| 397 | + 'update_post_term_cache' => false, | |
| 398 | + 'posts_per_page' => 50, | |
| 399 | + 'date_query' => array( | |
| 400 | + array( | |
| 401 | + 'before' => 'today', | |
| 402 | + ), | |
| 403 | + ), | |
| 404 | + ) | |
| 405 | + ); | |
| 406 | + | |
| 407 | + if ( $query->have_posts() ) { | |
| 408 | + $ids = array(); | |
| 409 | + while ( $query->have_posts() ) { | |
| 410 | + wp_delete_post( $query->next_post(), true ); | |
| 411 | + } | |
| 412 | + } | |
| 413 | + } | |
| 414 | + | |
| 415 | + /** | |
| 237 | 416 | * Renders appropriate page for chart builder. Creates new auto draft chart |
| 238 | 417 | * if no chart has been specified. |
| 239 | 418 | * |
| 240 | 419 | * @since 1.0.0 |
| @@ -244,9 +423,10 @@ | ||
| 244 | 423 | public function renderChartPages() { |
| 245 | 424 | defined( 'IFRAME_REQUEST' ) || define( 'IFRAME_REQUEST', 1 ); |
| 246 | 425 | // check chart, if chart not exists, will create new one and redirects to the same page with proper chart id |
| 247 | 426 | $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : ''; |
| 248 | - if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) { | |
| 427 | + if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) { | |
| 428 | + $this->deleteOldCharts(); | |
| 249 | 429 | $default_type = isset( $_GET['type'] ) && ! empty( $_GET['type'] ) ? $_GET['type'] : 'line'; |
| 250 | 430 | $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' ); |
| 251 | 431 | $source->fetch(); |
| 252 | 432 | $chart_id = wp_insert_post( |
| @@ -262,8 +442,9 @@ | ||
| 262 | 442 | add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, $default_type ); |
| 263 | 443 | add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 ); |
| 264 | 444 | add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 265 | 445 | add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); |
| 446 | + add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, '' ); | |
| 266 | 447 | add_post_meta( |
| 267 | 448 | $chart_id, |
| 268 | 449 | Visualizer_Plugin::CF_SETTINGS, |
| 269 | 450 | array( |
| @@ -275,16 +456,23 @@ | ||
| 275 | 456 | wp_redirect( add_query_arg( 'chart', (int) $chart_id ) ); |
| 276 | 457 | defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); |
| 277 | 458 | } |
| 278 | 459 | |
| 279 | - $this->load_chart_type( $chart_id ); | |
| 460 | + $lib = $this->load_chart_type( $chart_id ); | |
| 280 | 461 | |
| 462 | + // the alpha color picker (RGBA) is not supported by google. | |
| 463 | + $color_picker_dep = 'wp-color-picker'; | |
| 464 | + if ( in_array( $lib, array( 'chartjs', 'datatables' ), true ) && ! wp_script_is( 'wp-color-picker-alpha', 'registered' ) ) { | |
| 465 | + wp_register_script( 'wp-color-picker-alpha', VISUALIZER_ABSURL . 'js/lib/wp-color-picker-alpha.min.js', array( 'wp-color-picker' ), Visualizer_Plugin::VERSION ); | |
| 466 | + $color_picker_dep = 'wp-color-picker-alpha'; | |
| 467 | + } | |
| 468 | + | |
| 281 | 469 | // enqueue and register scripts and styles |
| 282 | 470 | wp_register_script( 'visualizer-chosen', VISUALIZER_ABSURL . 'js/lib/chosen.jquery.min.js', array( 'jquery' ), Visualizer_Plugin::VERSION ); |
| 283 | 471 | wp_register_style( 'visualizer-chosen', VISUALIZER_ABSURL . 'css/lib/chosen.min.css', array(), Visualizer_Plugin::VERSION ); |
| 284 | 472 | |
| 285 | 473 | wp_register_style( 'visualizer-frame', VISUALIZER_ABSURL . 'css/frame.css', array( 'visualizer-chosen' ), Visualizer_Plugin::VERSION ); |
| 286 | - wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'visualizer-chosen' ), Visualizer_Plugin::VERSION, true ); | |
| 474 | + wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'visualizer-chosen', 'jquery-ui-accordion' ), Visualizer_Plugin::VERSION, true ); | |
| 287 | 475 | wp_register_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true ); |
| 288 | 476 | wp_register_script( |
| 289 | 477 | 'visualizer-render', |
| 290 | 478 | VISUALIZER_ABSURL . 'js/render-facade.js', |
| @@ -295,19 +483,23 @@ | ||
| 295 | 483 | wp_register_script( |
| 296 | 484 | 'visualizer-preview', |
| 297 | 485 | VISUALIZER_ABSURL . 'js/preview.js', |
| 298 | 486 | array( |
| 299 | - 'wp-color-picker', | |
| 487 | + $color_picker_dep, | |
| 300 | 488 | 'visualizer-render', |
| 301 | 489 | ), |
| 302 | 490 | Visualizer_Plugin::VERSION, |
| 303 | 491 | true |
| 304 | 492 | ); |
| 305 | - // added by Ash/Upwork | |
| 306 | - if ( VISUALIZER_PRO ) { | |
| 493 | + wp_register_script( 'visualizer-editor-simple', VISUALIZER_ABSURL . 'js/simple-editor.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true ); | |
| 494 | + | |
| 495 | + do_action( 'visualizer_add_scripts' ); | |
| 496 | + | |
| 497 | + if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) { | |
| 307 | 498 | global $Visualizer_Pro; |
| 308 | 499 | $Visualizer_Pro->_addScriptsAndStyles(); |
| 309 | 500 | } |
| 501 | + | |
| 310 | 502 | // dispatch pages |
| 311 | 503 | $this->_chart = get_post( $chart_id ); |
| 312 | 504 | $tab = isset( $_GET['tab'] ) && ! empty( $_GET['tab'] ) ? $_GET['tab'] : 'visualizer'; |
| 313 | 505 | |
| @@ -347,22 +539,23 @@ | ||
| 347 | 539 | */ |
| 348 | 540 | private function loadCodeEditorAssets() { |
| 349 | 541 | global $wp_version; |
| 350 | 542 | |
| 351 | - if ( ! VISUALIZER_PRO ) { | |
| 543 | + $wp_scripts = wp_scripts(); | |
| 544 | + | |
| 545 | + // data tables assets. | |
| 546 | + wp_register_script( 'visualizer-datatables', VISUALIZER_ABSURL . 'js/lib/datatables.min.js', array( 'jquery-ui-core' ), Visualizer_Plugin::VERSION ); | |
| 547 | + wp_register_style( 'visualizer-datatables', VISUALIZER_ABSURL . 'css/lib/datatables.min.css', array(), Visualizer_Plugin::VERSION ); | |
| 548 | + wp_register_style( 'visualizer-jquery-ui', sprintf( '//ajax.googleapis.com/ajax/libs/jqueryui/%s/themes/smoothness/jquery-ui.css', $wp_scripts->registered['jquery-ui-core']->ver ), array( 'visualizer-datatables' ), Visualizer_Plugin::VERSION ); | |
| 549 | + wp_enqueue_script( 'visualizer-datatables' ); | |
| 550 | + wp_enqueue_style( 'visualizer-jquery-ui' ); | |
| 551 | + | |
| 552 | + if ( ! Visualizer_Module::is_pro() ) { | |
| 352 | 553 | return; |
| 353 | 554 | } |
| 354 | 555 | |
| 355 | 556 | $table_col_mapping = Visualizer_Source_Query_Params::get_all_db_tables_column_mapping(); |
| 356 | 557 | |
| 357 | - // data tables assets. | |
| 358 | - wp_register_script( 'visualizer-datatables', '//cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js', array( 'jquery-ui-core' ), Visualizer_Plugin::VERSION ); | |
| 359 | - wp_register_style( 'visualizer-datatables', '//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css', array(), Visualizer_Plugin::VERSION ); | |
| 360 | - wp_register_style( 'visualizer-datatables-ui', '//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css', array( 'visualizer-datatables' ), Visualizer_Plugin::VERSION ); | |
| 361 | - | |
| 362 | - wp_enqueue_script( 'visualizer-datatables' ); | |
| 363 | - wp_enqueue_style( 'visualizer-datatables-ui' ); | |
| 364 | - | |
| 365 | 558 | if ( version_compare( $wp_version, '4.9.0', '<' ) ) { |
| 366 | 559 | // code mirror assets. |
| 367 | 560 | wp_register_script( 'visualizer-codemirror-core', '//codemirror.net/lib/codemirror.js', array( 'jquery' ), Visualizer_Plugin::VERSION ); |
| 368 | 561 | wp_register_script( 'visualizer-codemirror-placeholder', '//codemirror.net/addon/display/placeholder.js', array( 'visualizer-codemirror-core' ), Visualizer_Plugin::VERSION ); |
| @@ -402,10 +595,10 @@ | ||
| 402 | 595 | private function _handleDataAndSettingsPage() { |
| 403 | 596 | if ( isset( $_POST['map_api_key'] ) ) { |
| 404 | 597 | update_option( 'visualizer-map-api-key', $_POST['map_api_key'] ); |
| 405 | 598 | } |
| 406 | - if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'] ) ) { | |
| 407 | - if ( $this->_chart->post_status == 'auto-draft' ) { | |
| 599 | + if ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'] ) ) { | |
| 600 | + if ( $this->_chart->post_status === 'auto-draft' ) { | |
| 408 | 601 | $this->_chart->post_status = 'publish'; |
| 409 | 602 | |
| 410 | 603 | // ensure that a revision is not created. If a revision is created it will have the proper data and the parent of the revision will have default data. |
| 411 | 604 | // we do not want any difference in data so disable revisions temporarily. |
| @@ -414,8 +607,24 @@ | ||
| 414 | 607 | } |
| 415 | 608 | // save meta data only when it is NOT being canceled. |
| 416 | 609 | if ( ! ( isset( $_POST['cancel'] ) && 1 === intval( $_POST['cancel'] ) ) ) { |
| 417 | 610 | update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $_POST ); |
| 611 | + | |
| 612 | + // we will keep a parameter called 'internal_title' that will be set to the given title or, if empty, the chart ID | |
| 613 | + // this will help in searching with the chart id. | |
| 614 | + $settings = get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); | |
| 615 | + $title = null; | |
| 616 | + if ( isset( $settings['title'] ) && ! empty( $settings['title'] ) ) { | |
| 617 | + $title = $settings['title']; | |
| 618 | + if ( is_array( $title ) ) { | |
| 619 | + $title = $settings['title']['text']; | |
| 620 | + } | |
| 621 | + } | |
| 622 | + if ( empty( $title ) ) { | |
| 623 | + $title = $this->_chart->ID; | |
| 624 | + } | |
| 625 | + $settings['internal_title'] = $title; | |
| 626 | + update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $settings ); | |
| 418 | 627 | } |
| 419 | 628 | $render = new Visualizer_Render_Page_Send(); |
| 420 | 629 | $render->text = sprintf( '[visualizer id="%d"]', $this->_chart->ID ); |
| 421 | 630 | wp_iframe( array( $render, 'render' ) ); |
| @@ -423,9 +632,9 @@ | ||
| 423 | 632 | return; |
| 424 | 633 | } |
| 425 | 634 | $data = $this->_getChartArray(); |
| 426 | 635 | $sidebar = ''; |
| 427 | - $sidebar_class = 'Visualizer_Render_Sidebar_Type_' . ucfirst( $data['type'] ); | |
| 636 | + $sidebar_class = $this->load_chart_class_name( $this->_chart->ID ); | |
| 428 | 637 | if ( class_exists( $sidebar_class, true ) ) { |
| 429 | 638 | $sidebar = new $sidebar_class( $data['settings'] ); |
| 430 | 639 | $sidebar->__series = $data['series']; |
| 431 | 640 | $sidebar->__data = $data['data']; |
| @@ -430,14 +639,14 @@ | ||
| 430 | 639 | $sidebar->__series = $data['series']; |
| 431 | 640 | $sidebar->__data = $data['data']; |
| 432 | 641 | } else { |
| 433 | 642 | $sidebar = apply_filters( 'visualizer_pro_chart_type_sidebar', '', $data ); |
| 434 | - if ( $sidebar != '' ) { | |
| 643 | + if ( $sidebar !== '' ) { | |
| 435 | 644 | $sidebar->__series = $data['series']; |
| 436 | 645 | $sidebar->__data = $data['data']; |
| 437 | 646 | } |
| 438 | 647 | } |
| 439 | - unset( $data['settings']['width'], $data['settings']['height'] ); | |
| 648 | + unset( $data['settings']['width'], $data['settings']['height'], $data['settings']['chartArea'] ); | |
| 440 | 649 | wp_enqueue_style( 'wp-color-picker' ); |
| 441 | 650 | wp_enqueue_style( 'visualizer-frame' ); |
| 442 | 651 | wp_enqueue_script( 'visualizer-preview' ); |
| 443 | 652 | wp_enqueue_script( 'visualizer-chosen' ); |
| @@ -442,8 +651,25 @@ | ||
| 442 | 651 | wp_enqueue_script( 'visualizer-preview' ); |
| 443 | 652 | wp_enqueue_script( 'visualizer-chosen' ); |
| 444 | 653 | wp_enqueue_script( 'visualizer-render' ); |
| 445 | 654 | |
| 655 | + if ( ! Visualizer_Module::is_pro() ) { | |
| 656 | + wp_enqueue_script( 'visualizer-editor-simple' ); | |
| 657 | + wp_localize_script( | |
| 658 | + 'visualizer-editor-simple', | |
| 659 | + 'visualizer1', | |
| 660 | + array( | |
| 661 | + 'ajax' => array( | |
| 662 | + 'url' => admin_url( 'admin-ajax.php' ), | |
| 663 | + 'nonces' => array( | |
| 664 | + ), | |
| 665 | + 'actions' => array( | |
| 666 | + ), | |
| 667 | + ), | |
| 668 | + ) | |
| 669 | + ); | |
| 670 | + } | |
| 671 | + | |
| 446 | 672 | $table_col_mapping = $this->loadCodeEditorAssets(); |
| 447 | 673 | |
| 448 | 674 | wp_localize_script( |
| 449 | 675 | 'visualizer-render', |
| @@ -451,8 +677,9 @@ | ||
| 451 | 677 | array( |
| 452 | 678 | 'l10n' => array( |
| 453 | 679 | 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ), |
| 454 | 680 | 'loading' => esc_html__( 'Loading...', 'visualizer' ), |
| 681 | + 'json_error' => esc_html__( 'An error occured in fetching data.', 'visualizer' ), | |
| 455 | 682 | ), |
| 456 | 683 | 'charts' => array( |
| 457 | 684 | 'canvas' => $data, |
| 458 | 685 | 'id' => $this->_chart->ID, |
| @@ -463,19 +690,28 @@ | ||
| 463 | 690 | 'url' => admin_url( 'admin-ajax.php' ), |
| 464 | 691 | 'nonces' => array( |
| 465 | 692 | 'permissions' => wp_create_nonce( Visualizer_Plugin::ACTION_FETCH_PERMISSIONS_DATA ), |
| 466 | 693 | 'db_get_data' => wp_create_nonce( Visualizer_Plugin::ACTION_FETCH_DB_DATA . Visualizer_Plugin::VERSION ), |
| 694 | + 'json_get_roots' => wp_create_nonce( Visualizer_Plugin::ACTION_JSON_GET_ROOTS . Visualizer_Plugin::VERSION ), | |
| 695 | + 'json_get_data' => wp_create_nonce( Visualizer_Plugin::ACTION_JSON_GET_DATA . Visualizer_Plugin::VERSION ), | |
| 696 | + 'json_set_schedule' => wp_create_nonce( Visualizer_Plugin::ACTION_JSON_SET_SCHEDULE . Visualizer_Plugin::VERSION ), | |
| 467 | 697 | ), |
| 468 | 698 | 'actions' => array( |
| 469 | 699 | 'permissions' => Visualizer_Plugin::ACTION_FETCH_PERMISSIONS_DATA, |
| 470 | 700 | 'db_get_data' => Visualizer_Plugin::ACTION_FETCH_DB_DATA, |
| 701 | + 'json_get_roots' => Visualizer_Plugin::ACTION_JSON_GET_ROOTS, | |
| 702 | + 'json_get_data' => Visualizer_Plugin::ACTION_JSON_GET_DATA, | |
| 703 | + 'json_set_schedule' => Visualizer_Plugin::ACTION_JSON_SET_SCHEDULE, | |
| 471 | 704 | ), |
| 472 | 705 | ), |
| 473 | 706 | 'db_query' => array( |
| 474 | 707 | 'tables' => $table_col_mapping, |
| 475 | 708 | ), |
| 476 | - 'is_pro' => VISUALIZER_PRO, | |
| 709 | + 'is_pro' => Visualizer_Module::is_pro(), | |
| 477 | 710 | 'page_type' => 'chart', |
| 711 | + 'json_tag_separator' => Visualizer_Source_Json::TAG_SEPARATOR, | |
| 712 | + 'json_tag_separator_view' => Visualizer_Source_Json::TAG_SEPARATOR_VIEW, | |
| 713 | + 'is_front' => false, | |
| 478 | 714 | ) |
| 479 | 715 | ); |
| 480 | 716 | |
| 481 | 717 | $render = new Visualizer_Render_Page_Data(); |
| @@ -483,21 +719,25 @@ | ||
| 483 | 719 | $render->type = $data['type']; |
| 484 | 720 | $render->custom_css = $data['css']; |
| 485 | 721 | $render->sidebar = $sidebar; |
| 486 | 722 | if ( filter_input( INPUT_GET, 'library', FILTER_VALIDATE_BOOLEAN ) ) { |
| 487 | - $render->button = filter_input( INPUT_GET, 'action' ) == Visualizer_Plugin::ACTION_EDIT_CHART | |
| 723 | + $render->button = filter_input( INPUT_GET, 'action' ) === Visualizer_Plugin::ACTION_EDIT_CHART | |
| 488 | 724 | ? esc_html__( 'Save Chart', 'visualizer' ) |
| 489 | 725 | : esc_html__( 'Create Chart', 'visualizer' ); |
| 490 | - if ( filter_input( INPUT_GET, 'action' ) == Visualizer_Plugin::ACTION_EDIT_CHART ) { | |
| 726 | + if ( filter_input( INPUT_GET, 'action' ) === Visualizer_Plugin::ACTION_EDIT_CHART ) { | |
| 491 | 727 | $render->cancel_button = esc_html__( 'Cancel', 'visualizer' ); |
| 492 | 728 | } |
| 493 | 729 | } else { |
| 494 | 730 | $render->button = esc_attr__( 'Insert Chart', 'visualizer' ); |
| 495 | 731 | } |
| 496 | - if ( VISUALIZER_PRO ) { | |
| 732 | + | |
| 733 | + do_action( 'visualizer_enqueue_scripts_and_styles', $data ); | |
| 734 | + | |
| 735 | + if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) { | |
| 497 | 736 | global $Visualizer_Pro; |
| 498 | 737 | $Visualizer_Pro->_enqueueScriptsAndStyles( $data ); |
| 499 | 738 | } |
| 739 | + | |
| 500 | 740 | $this->_addAction( 'admin_head', 'renderFlattrScript' ); |
| 501 | 741 | wp_iframe( array( $render, 'render' ) ); |
| 502 | 742 | } |
| 503 | 743 | |
| @@ -509,13 +749,21 @@ | ||
| 509 | 749 | * @access private |
| 510 | 750 | */ |
| 511 | 751 | private function _handleTypesPage() { |
| 512 | 752 | // process post request |
| 513 | - if ( $_SERVER['REQUEST_METHOD'] == 'POST' && wp_verify_nonce( filter_input( INPUT_POST, 'nonce' ) ) ) { | |
| 753 | + if ( $_SERVER['REQUEST_METHOD'] === 'POST' && wp_verify_nonce( filter_input( INPUT_POST, 'nonce' ) ) ) { | |
| 514 | 754 | $type = filter_input( INPUT_POST, 'type' ); |
| 515 | - if ( in_array( $type, Visualizer_Plugin::getChartTypes() ) ) { | |
| 755 | + $library = filter_input( INPUT_POST, 'chart-library' ); | |
| 756 | + if ( in_array( $type, Visualizer_Plugin::getChartTypes(), true ) ) { | |
| 757 | + if ( empty( $library ) ) { | |
| 758 | + // library cannot be empty. | |
| 759 | + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Chart library empty while creating the chart! Aborting...', 'error', __FILE__, __LINE__ ); | |
| 760 | + return; | |
| 761 | + } | |
| 762 | + | |
| 516 | 763 | // save new chart type |
| 517 | 764 | update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_CHART_TYPE, $type ); |
| 765 | + update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_CHART_LIBRARY, $library ); | |
| 518 | 766 | // if the chart has default data, update it with appropriate default data for new type |
| 519 | 767 | if ( filter_var( get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, true ), FILTER_VALIDATE_BOOLEAN ) ) { |
| 520 | 768 | $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $type . '.csv' ); |
| 521 | 769 | $source->fetch(); |
| @@ -522,8 +770,11 @@ | ||
| 522 | 770 | $this->_chart->post_content = $source->getData(); |
| 523 | 771 | wp_update_post( $this->_chart->to_array() ); |
| 524 | 772 | update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); |
| 525 | 773 | } |
| 774 | + | |
| 775 | + Visualizer_Module_Utility::set_defaults( $this->_chart ); | |
| 776 | + | |
| 526 | 777 | // redirect to next tab |
| 527 | 778 | // changed by Ash/Upwork |
| 528 | 779 | wp_redirect( add_query_arg( 'tab', 'settings' ) ); |
| 529 | 780 | |
| @@ -531,9 +782,9 @@ | ||
| 531 | 782 | } |
| 532 | 783 | } |
| 533 | 784 | $render = new Visualizer_Render_Page_Types(); |
| 534 | 785 | $render->type = get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ); |
| 535 | - $render->types = Visualizer_Module_Admin::_getChartTypesLocalized(); | |
| 786 | + $render->types = Visualizer_Module_Admin::_getChartTypesLocalized( false, false, false, 'types' ); | |
| 536 | 787 | $render->chart = $this->_chart; |
| 537 | 788 | wp_enqueue_style( 'visualizer-frame' ); |
| 538 | 789 | wp_enqueue_script( 'visualizer-frame' ); |
| 539 | 790 | wp_iframe( array( $render, 'render' ) ); |
| @@ -549,10 +800,110 @@ | ||
| 549 | 800 | */ |
| 550 | 801 | public function renderFlattrScript() { |
| 551 | 802 | echo ''; |
| 552 | 803 | } |
| 553 | - // changed by Ash/Upwork | |
| 804 | + | |
| 554 | 805 | /** |
| 806 | + * Processes the CSV that is sent in the request as a string. | |
| 807 | + * | |
| 808 | + * @since 3.2.0 | |
| 809 | + */ | |
| 810 | + private function handleCSVasString( $data ) { | |
| 811 | + $source = null; | |
| 812 | + | |
| 813 | + // @issue https://github.com/Codeinwp/visualizer/issues/412 | |
| 814 | + if ( has_filter( 'visualizer_pro_handle_chart_data' ) ) { | |
| 815 | + $source = apply_filters( 'visualizer_pro_handle_chart_data', $data, '' ); | |
| 816 | + } else { | |
| 817 | + // data coming in from the text editor. | |
| 818 | + $tmpfile = tempnam( get_temp_dir(), Visualizer_Plugin::NAME ); | |
| 819 | + $handle = fopen( $tmpfile, 'w' ); | |
| 820 | + $values = preg_split( '/[\n\r]+/', stripslashes( trim( $data ) ) ); | |
| 821 | + if ( $values ) { | |
| 822 | + foreach ( $values as $row ) { | |
| 823 | + if ( empty( $row ) ) { | |
| 824 | + continue; | |
| 825 | + } | |
| 826 | + $columns = explode( ',', $row ); | |
| 827 | + fputcsv( $handle, $columns ); | |
| 828 | + } | |
| 829 | + } | |
| 830 | + $source = new Visualizer_Source_Csv( $tmpfile ); | |
| 831 | + fclose( $handle ); | |
| 832 | + } | |
| 833 | + return $source; | |
| 834 | + } | |
| 835 | + | |
| 836 | + /** | |
| 837 | + * Parses the data uploaded as an HTML table. | |
| 838 | + * | |
| 839 | + * @since 3.2.0 | |
| 840 | + * | |
| 841 | + * @access private | |
| 842 | + */ | |
| 843 | + private function handleTabularData() { | |
| 844 | + $csv = array(); | |
| 845 | + // the datatable mentions the headers twice, so lets remove the duplicates. | |
| 846 | + $headers = array_unique( array_filter( $_POST['header'] ) ); | |
| 847 | + $types = $_POST['type']; | |
| 848 | + | |
| 849 | + // capture all the indexes that correspond to excluded columns. | |
| 850 | + $exclude = array(); | |
| 851 | + $index = 0; | |
| 852 | + foreach ( $types as $type ) { | |
| 853 | + if ( empty( $type ) ) { | |
| 854 | + $exclude[] = $index; | |
| 855 | + } | |
| 856 | + $index++; | |
| 857 | + } | |
| 858 | + | |
| 859 | + // when N headers are being renamed, the number of headers increases by N | |
| 860 | + // because of the way datatable duplicates header information | |
| 861 | + // so unset the headers that have been renamed. | |
| 862 | + if ( count( $headers ) !== count( $types ) ) { | |
| 863 | + $to = count( $headers ); | |
| 864 | + for ( $i = count( $types ); $i < $to; $i++ ) { | |
| 865 | + unset( $headers[ $i + 1 ] ); | |
| 866 | + } | |
| 867 | + } | |
| 868 | + | |
| 869 | + $columns = array(); | |
| 870 | + for ( $i = 0; $i < count( $headers ); $i++ ) { | |
| 871 | + if ( ! isset( $_POST[ 'data' . $i ] ) ) { | |
| 872 | + continue; | |
| 873 | + } | |
| 874 | + $columns[ $i ] = $_POST[ 'data' . $i ]; | |
| 875 | + } | |
| 876 | + | |
| 877 | + $csv[] = $headers; | |
| 878 | + $csv[] = $types; | |
| 879 | + for ( $j = 0; $j < count( $columns[0] ); $j++ ) { | |
| 880 | + $row = array(); | |
| 881 | + for ( $i = 0; $i < count( $headers ); $i++ ) { | |
| 882 | + $row[] = $columns[ $i ][ $j ]; | |
| 883 | + } | |
| 884 | + $csv[] = $row; | |
| 885 | + } | |
| 886 | + | |
| 887 | + $tmpfile = tempnam( get_temp_dir(), Visualizer_Plugin::NAME ); | |
| 888 | + $handle = fopen( $tmpfile, 'w' ); | |
| 889 | + | |
| 890 | + if ( $csv ) { | |
| 891 | + $index = 0; | |
| 892 | + foreach ( $csv as $row ) { | |
| 893 | + // remove all the cells corresponding to the excluded headers. | |
| 894 | + foreach ( $exclude as $j ) { | |
| 895 | + unset( $row[ $j ] ); | |
| 896 | + } | |
| 897 | + fputcsv( $handle, $row ); | |
| 898 | + } | |
| 899 | + } | |
| 900 | + $source = new Visualizer_Source_Csv( $tmpfile ); | |
| 901 | + fclose( $handle ); | |
| 902 | + return $source; | |
| 903 | + } | |
| 904 | + | |
| 905 | + /** | |
| 555 | 906 | * Parses uploaded CSV file and saves new data for the chart. |
| 556 | 907 | * |
| 557 | 908 | * @since 1.0.0 |
| 558 | 909 | * |
| @@ -574,9 +925,9 @@ | ||
| 574 | 925 | |
| 575 | 926 | // check chart, if chart exists |
| 576 | 927 | // do not use filter_input as it does not work for phpunit test cases, use filter_var instead |
| 577 | 928 | $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : ''; |
| 578 | - if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) { | |
| 929 | + if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) { | |
| 579 | 930 | if ( ! $can_die ) { |
| 580 | 931 | return; |
| 581 | 932 | } |
| 582 | 933 | status_header( 400 ); |
| @@ -588,9 +939,11 @@ | ||
| 588 | 939 | } |
| 589 | 940 | |
| 590 | 941 | if ( ! isset( $_POST['chart_data_src'] ) || Visualizer_Plugin::CF_SOURCE_FILTER !== $_POST['chart_data_src'] ) { |
| 591 | 942 | // delete the filters in case this chart is being uploaded from other data sources |
| 592 | - delete_post_meta( $chart_id, 'visualizer-filter-config' ); | |
| 943 | + delete_post_meta( $chart_id, Visualizer_Plugin::CF_FILTER_CONFIG ); | |
| 944 | + delete_post_meta( $chart_id, '__transient-' . Visualizer_Plugin::CF_FILTER_CONFIG ); | |
| 945 | + delete_post_meta( $chart_id, '__transient-' . Visualizer_Plugin::CF_DB_QUERY ); | |
| 593 | 946 | |
| 594 | 947 | // delete "import from db" specific parameters. |
| 595 | 948 | delete_post_meta( $chart_id, Visualizer_Plugin::CF_DB_QUERY ); |
| 596 | 949 | delete_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE ); |
| @@ -595,8 +948,13 @@ | ||
| 595 | 948 | delete_post_meta( $chart_id, Visualizer_Plugin::CF_DB_QUERY ); |
| 596 | 949 | delete_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE ); |
| 597 | 950 | } |
| 598 | 951 | |
| 952 | + // delete json related data. | |
| 953 | + delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL ); | |
| 954 | + delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_ROOT ); | |
| 955 | + delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_PAGING ); | |
| 956 | + | |
| 599 | 957 | $source = null; |
| 600 | 958 | $render = new Visualizer_Render_Page_Update(); |
| 601 | 959 | if ( isset( $_POST['remote_data'] ) && filter_var( $_POST['remote_data'], FILTER_VALIDATE_URL ) ) { |
| 602 | 960 | $source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] ); |
| @@ -602,14 +960,17 @@ | ||
| 602 | 960 | $source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] ); |
| 603 | 961 | if ( isset( $_POST['vz-import-time'] ) ) { |
| 604 | 962 | apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $_POST['remote_data'], $_POST['vz-import-time'] ); |
| 605 | 963 | } |
| 964 | + // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison | |
| 606 | 965 | } elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) { |
| 607 | 966 | $source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] ); |
| 608 | 967 | } elseif ( isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0 ) { |
| 609 | - $source = apply_filters( 'visualizer_pro_handle_chart_data', $_POST['chart_data'], '' ); | |
| 968 | + $source = $this->handleCSVasString( $_POST['chart_data'] ); | |
| 969 | + } elseif ( isset( $_POST['table_data'] ) && 'yes' === $_POST['table_data'] ) { | |
| 970 | + $source = $this->handleTabularData(); | |
| 610 | 971 | } else { |
| 611 | - $render->message = esc_html__( 'CSV file with chart data was not uploaded. Please, try again.', 'visualizer' ); | |
| 972 | + $render->message = esc_html__( 'CSV file with chart data was not uploaded. Please try again.', 'visualizer' ); | |
| 612 | 973 | } |
| 613 | 974 | if ( $source ) { |
| 614 | 975 | if ( $source->fetch() ) { |
| 615 | 976 | $content = $source->getData(); |
| @@ -629,13 +990,22 @@ | ||
| 629 | 990 | wp_update_post( $chart->to_array() ); |
| 630 | 991 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); |
| 631 | 992 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 632 | 993 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 ); |
| 994 | + | |
| 995 | + Visualizer_Module_Utility::set_defaults( $chart, null ); | |
| 996 | + | |
| 997 | + $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); | |
| 998 | + | |
| 633 | 999 | $render->id = $chart->ID; |
| 634 | 1000 | $render->data = json_encode( $source->getRawData() ); |
| 635 | 1001 | $render->series = json_encode( $source->getSeries() ); |
| 1002 | + $render->settings = json_encode( $settings ); | |
| 636 | 1003 | } else { |
| 637 | - $render->message = esc_html__( 'CSV file is broken or invalid. Please, try again.', 'visualizer' ); | |
| 1004 | + $render->message = $source->get_error(); | |
| 1005 | + if ( empty( $render->message ) ) { | |
| 1006 | + $render->message = esc_html__( 'CSV file is broken or invalid. Please try again.', 'visualizer' ); | |
| 1007 | + } | |
| 638 | 1008 | } |
| 639 | 1009 | } |
| 640 | 1010 | $render->render(); |
| 641 | 1011 | if ( ! $can_die ) { |
| @@ -652,27 +1022,18 @@ | ||
| 652 | 1022 | * @access public |
| 653 | 1023 | */ |
| 654 | 1024 | public function cloneChart() { |
| 655 | 1025 | $chart_id = $success = false; |
| 656 | - $nonce = wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ), Visualizer_Plugin::ACTION_CLONE_CHART ); | |
| 1026 | + $nonce = isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'], Visualizer_Plugin::ACTION_CLONE_CHART ); | |
| 657 | 1027 | $capable = current_user_can( 'edit_posts' ); |
| 658 | 1028 | if ( $nonce && $capable ) { |
| 659 | - $chart_id = filter_input( | |
| 660 | - INPUT_GET, | |
| 661 | - 'chart', | |
| 662 | - FILTER_VALIDATE_INT, | |
| 663 | - array( | |
| 664 | - 'options' => array( | |
| 665 | - 'min_range' => 1, | |
| 666 | - ), | |
| 667 | - ) | |
| 668 | - ); | |
| 1029 | + $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : ''; | |
| 669 | 1030 | if ( $chart_id ) { |
| 670 | 1031 | $chart = get_post( $chart_id ); |
| 671 | - $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER; | |
| 1032 | + $success = $chart && $chart->post_type === Visualizer_Plugin::CPT_VISUALIZER; | |
| 672 | 1033 | } |
| 673 | 1034 | } |
| 674 | - $redirect = wp_get_referer(); | |
| 1035 | + $redirect = remove_query_arg( 'vaction', wp_get_referer() ); | |
| 675 | 1036 | if ( $success ) { |
| 676 | 1037 | $new_chart_id = wp_insert_post( |
| 677 | 1038 | array( |
| 678 | 1039 | 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, |
| @@ -681,23 +1042,32 @@ | ||
| 681 | 1042 | 'post_status' => $chart->post_status, |
| 682 | 1043 | 'post_content' => $chart->post_content, |
| 683 | 1044 | ) |
| 684 | 1045 | ); |
| 685 | - if ( $new_chart_id && ! is_wp_error( $new_chart_id ) ) { | |
| 686 | - add_post_meta( $new_chart_id, Visualizer_Plugin::CF_CHART_TYPE, get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ) ); | |
| 687 | - add_post_meta( $new_chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, get_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, true ) ); | |
| 688 | - add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SOURCE, get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) ); | |
| 689 | - add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SERIES, get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true ) ); | |
| 690 | - add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SETTINGS, get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ) ); | |
| 1046 | + if ( is_wp_error( $new_chart_id ) ) { | |
| 1047 | + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Error while cloning chart %d = %s', $chart_id, print_r( $new_chart_id, true ) ), 'error', __FILE__, __LINE__ ); | |
| 1048 | + } else { | |
| 1049 | + $post_meta = get_post_meta( $chart_id ); | |
| 1050 | + foreach ( $post_meta as $key => $value ) { | |
| 1051 | + if ( strpos( $key, 'visualizer-' ) !== false ) { | |
| 1052 | + add_post_meta( $new_chart_id, $key, maybe_unserialize( $value[0] ) ); | |
| 1053 | + } | |
| 1054 | + } | |
| 691 | 1055 | $redirect = add_query_arg( |
| 692 | 1056 | array( |
| 693 | 1057 | 'page' => 'visualizer', |
| 694 | 1058 | 'type' => filter_input( INPUT_GET, 'type' ), |
| 1059 | + 'vaction' => false, | |
| 695 | 1060 | ), |
| 696 | - admin_url( 'upload.php' ) | |
| 1061 | + admin_url( 'admin.php' ) | |
| 697 | 1062 | ); |
| 698 | 1063 | } |
| 699 | 1064 | } |
| 1065 | + | |
| 1066 | + if ( defined( 'WP_TESTS_DOMAIN' ) ) { | |
| 1067 | + wp_die(); | |
| 1068 | + } | |
| 1069 | + | |
| 700 | 1070 | wp_redirect( $redirect ); |
| 701 | 1071 | exit; |
| 702 | 1072 | } |
| 703 | 1073 | |
| @@ -743,9 +1113,9 @@ | ||
| 743 | 1113 | $data = $this->_getChartArray(); |
| 744 | 1114 | $render = new Visualizer_Render_Page_Data(); |
| 745 | 1115 | $render->chart = $this->_chart; |
| 746 | 1116 | $render->type = $data['type']; |
| 747 | - unset( $data['settings']['width'], $data['settings']['height'] ); | |
| 1117 | + unset( $data['settings']['width'], $data['settings']['height'], $data['settings']['chartArea'] ); | |
| 748 | 1118 | wp_enqueue_style( 'visualizer-frame' ); |
| 749 | 1119 | wp_enqueue_script( 'visualizer-render' ); |
| 750 | 1120 | wp_localize_script( |
| 751 | 1121 | 'visualizer-render', |
| @@ -759,13 +1129,16 @@ | ||
| 759 | 1129 | 'canvas' => $data, |
| 760 | 1130 | ), |
| 761 | 1131 | ) |
| 762 | 1132 | ); |
| 763 | - // Added by Ash/Upwork | |
| 764 | - if ( VISUALIZER_PRO ) { | |
| 1133 | + | |
| 1134 | + do_action( 'visualizer_enqueue_scripts_and_styles', $data ); | |
| 1135 | + | |
| 1136 | + if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) { | |
| 765 | 1137 | global $Visualizer_Pro; |
| 766 | 1138 | $Visualizer_Pro->_enqueueScriptsAndStyles( $data ); |
| 767 | 1139 | } |
| 1140 | + | |
| 768 | 1141 | // Added by Ash/Upwork |
| 769 | 1142 | $this->_addAction( 'admin_head', 'renderFlattrScript' ); |
| 770 | 1143 | wp_iframe( array( $render, 'render' ) ); |
| 771 | 1144 | } |
| @@ -838,8 +1211,37 @@ | ||
| 838 | 1211 | $render->message = $error; |
| 839 | 1212 | } |
| 840 | 1213 | } |
| 841 | 1214 | $render->render(); |
| 1215 | + if ( ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE ) ) { | |
| 1216 | + defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); | |
| 1217 | + } | |
| 1218 | + } | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + /** | |
| 1222 | + * Saves the filter query and the schedule. | |
| 1223 | + * | |
| 1224 | + * @access public | |
| 1225 | + */ | |
| 1226 | + public function saveFilter() { | |
| 1227 | + check_ajax_referer( Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY . Visualizer_Plugin::VERSION, 'security' ); | |
| 1228 | + | |
| 1229 | + $chart_id = filter_input( | |
| 1230 | + INPUT_GET, | |
| 1231 | + 'chart', | |
| 1232 | + FILTER_VALIDATE_INT, | |
| 1233 | + array( | |
| 1234 | + 'options' => array( | |
| 1235 | + 'min_range' => 1, | |
| 1236 | + ), | |
| 1237 | + ) | |
| 1238 | + ); | |
| 1239 | + | |
| 1240 | + $hours = $_POST['refresh']; | |
| 1241 | + | |
| 1242 | + do_action( 'visualizer_save_filter', $chart_id, $hours ); | |
| 1243 | + | |
| 842 | 1244 | if ( ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE ) ) { |
| 843 | 1245 | defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); |
| 844 | 1246 | } |
| 845 | 1247 | } |