| @@ -67,9 +67,10 @@ | ||
| 67 | 67 | $this->_addFilter( Visualizer_Plugin::FILTER_UNDO_REVISIONS, 'undoRevisions', 10, 2 ); |
| 68 | 68 | $this->_addFilter( Visualizer_Plugin::FILTER_HANDLE_REVISIONS, 'handleExistingRevisions', 10, 2 ); |
| 69 | 69 | $this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_DATA_AS, 'getDataAs', 10, 3 ); |
| 70 | 70 | $this->_addAction( 'pre_get_posts', 'PreGetPosts' ); |
| 71 | - register_shutdown_function( array( $this, 'onShutdown' ) ); | |
| 71 | + register_shutdown_function( array($this, 'onShutdown') ); | |
| 72 | + | |
| 72 | 73 | } |
| 73 | 74 | |
| 74 | 75 | /** |
| 75 | 76 | * Register a shutdown hook to catch fatal errors. |
| @@ -112,18 +113,18 @@ | ||
| 112 | 113 | * @access public |
| 113 | 114 | * @param string $tag The name of the AJAX action to which the $method is hooked. |
| 114 | 115 | * @param string $method Optional. The name of the method to be called. If the name of the method is not provided, tag name will be used as method name. |
| 115 | 116 | * @param bool $methodClass The root of the method. |
| 116 | - * @param boolean $logged_in Optional. Determines if we should register hook for logged in users. | |
| 117 | - * @param boolean $logged_out Optional. Determines if we should register hook for not logged in users. | |
| 117 | + * @param boolean $private Optional. Determines if we should register hook for logged in users. | |
| 118 | + * @param boolean $public Optional. Determines if we should register hook for not logged in users. | |
| 118 | 119 | * @return Visualizer_Module |
| 119 | 120 | */ |
| 120 | - protected function _addAjaxAction( $tag, $method = '', $methodClass = null, $logged_in = true, $logged_out = false ) { | |
| 121 | - if ( $logged_in ) { | |
| 121 | + protected function _addAjaxAction( $tag, $method = '', $methodClass = null, $private = true, $public = false ) { | |
| 122 | + if ( $private ) { | |
| 122 | 123 | $this->_addAction( 'wp_ajax_' . $tag, $method, $methodClass ); |
| 123 | 124 | } |
| 124 | 125 | |
| 125 | - if ( $logged_out ) { | |
| 126 | + if ( $public ) { | |
| 126 | 127 | $this->_addAction( 'wp_ajax_nopriv_' . $tag, $method, $methodClass ); |
| 127 | 128 | } |
| 128 | 129 | |
| 129 | 130 | return $this; |
| @@ -167,9 +168,9 @@ | ||
| 167 | 168 | * A wrapper around the actual function _getDataAs. This function is invoked as a filter. |
| 168 | 169 | * |
| 169 | 170 | * @since 3.2.0 |
| 170 | 171 | */ |
| 171 | - public function getDataAs( $data, $chart_id, $type ) { | |
| 172 | + public function getDataAs( $final, $chart_id, $type ) { | |
| 172 | 173 | return $this->_getDataAs( $chart_id, $type ); |
| 173 | 174 | } |
| 174 | 175 | |
| 175 | 176 | /** |
| @@ -268,17 +269,14 @@ | ||
| 268 | 269 | |
| 269 | 270 | $bom = chr( 0xEF ) . chr( 0xBB ) . chr( 0xBF ); |
| 270 | 271 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
| 271 | 272 | $fp = function_exists( 'tmpfile' ) ? @tmpfile() : null; |
| 272 | - if ( ! $fp ) { | |
| 273 | + if ( null === $fp ) { | |
| 273 | 274 | if ( ! function_exists( 'wp_tempnam' ) ) { |
| 274 | 275 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 275 | 276 | } |
| 276 | 277 | $fp = fopen( wp_tempnam(), 'w+' ); |
| 277 | 278 | } |
| 278 | - if ( ! $fp ) { | |
| 279 | - return array( 'csv' => '', 'name' => $filename, 'string' => '' ); | |
| 280 | - } | |
| 281 | 279 | if ( ! apply_filters( 'vizualizer_export_include_series_type', true ) ) { |
| 282 | 280 | unset( $rows[1] ); |
| 283 | 281 | $rows = array_values( $rows ); |
| 284 | 282 | } |
| @@ -288,10 +286,10 @@ | ||
| 288 | 286 | fputcsv( $fp, $row ); |
| 289 | 287 | } |
| 290 | 288 | rewind( $fp ); |
| 291 | 289 | $csv = ''; |
| 292 | - $array = fgetcsv( $fp ); | |
| 293 | - while ( $array !== false ) { | |
| 290 | + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition | |
| 291 | + while ( ( $array = fgetcsv( $fp ) ) !== false ) { | |
| 294 | 292 | if ( strlen( $csv ) > 0 ) { |
| 295 | 293 | $csv .= PHP_EOL; |
| 296 | 294 | } |
| 297 | 295 | // if enclosure is required, check every item of this line |
| @@ -305,10 +303,9 @@ | ||
| 305 | 303 | $temp_array[] = $item; |
| 306 | 304 | } |
| 307 | 305 | $array = $temp_array; |
| 308 | 306 | } |
| 309 | - $csv .= implode( ',', $array ); | |
| 310 | - $array = fgetcsv( $fp ); | |
| 307 | + $csv .= implode( ',', $array ); | |
| 311 | 308 | } |
| 312 | 309 | fclose( $fp ); |
| 313 | 310 | |
| 314 | 311 | return array( |
| @@ -332,9 +329,9 @@ | ||
| 332 | 329 | if ( ! apply_filters( 'vizualizer_export_include_series_type', true ) ) { |
| 333 | 330 | unset( $rows[1] ); |
| 334 | 331 | $rows = array_values( $rows ); |
| 335 | 332 | $rows = array_map( |
| 336 | - function ( $r ) { | |
| 333 | + function( $r ) { | |
| 337 | 334 | return array_map( 'strval', $r ); |
| 338 | 335 | }, |
| 339 | 336 | $rows |
| 340 | 337 | ); |
| @@ -404,9 +401,9 @@ | ||
| 404 | 401 | $index = 0; |
| 405 | 402 | foreach ( $rows as $row ) { |
| 406 | 403 | // skip the data type row. |
| 407 | 404 | if ( 1 === $index ) { |
| 408 | - ++$index; | |
| 405 | + $index++; | |
| 409 | 406 | continue; |
| 410 | 407 | } |
| 411 | 408 | |
| 412 | 409 | $table .= '<tr>'; |
| @@ -417,9 +414,9 @@ | ||
| 417 | 414 | $table .= '<td>' . $col . '</td>'; |
| 418 | 415 | } |
| 419 | 416 | } |
| 420 | 417 | $table .= '</tr>'; |
| 421 | - ++$index; | |
| 418 | + $index++; | |
| 422 | 419 | } |
| 423 | 420 | $table .= '</table>'; |
| 424 | 421 | |
| 425 | 422 | $html .= apply_filters( 'visualizer_print_table', $table ) . ' |
| @@ -432,11 +429,11 @@ | ||
| 432 | 429 | |
| 433 | 430 | /** |
| 434 | 431 | * Disable revisions temporarily for visualizer post type. |
| 435 | 432 | */ |
| 436 | - final protected function disableRevisionsTemporarily() { | |
| 433 | + protected final function disableRevisionsTemporarily() { | |
| 437 | 434 | add_filter( |
| 438 | - 'wp_revisions_to_keep', function ( $num, $post ) { | |
| 435 | + 'wp_revisions_to_keep', function( $num, $post ) { | |
| 439 | 436 | if ( $post->post_type === Visualizer_Plugin::CPT_VISUALIZER ) { |
| 440 | 437 | return 0; |
| 441 | 438 | } |
| 442 | 439 | return $num; |
| @@ -448,9 +445,9 @@ | ||
| 448 | 445 | * Undo revisions for the chart, and if necessary, restore the earliest version. |
| 449 | 446 | * |
| 450 | 447 | * @return bool If any revisions were found. |
| 451 | 448 | */ |
| 452 | - final public function undoRevisions( $chart_id, $restore = false ) { | |
| 449 | + public final function undoRevisions( $chart_id, $restore = false ) { | |
| 453 | 450 | do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'undoRevisions for %d with%s restore', $chart_id, ( $restore ? '' : 'out' ) ), 'debug', __FILE__, __LINE__ ); |
| 454 | 451 | if ( get_post_type( $chart_id ) !== Visualizer_Plugin::CPT_VISUALIZER ) { |
| 455 | 452 | return false; |
| 456 | 453 | } |
| @@ -480,19 +477,14 @@ | ||
| 480 | 477 | |
| 481 | 478 | /** |
| 482 | 479 | * If existing revisions exist for the chart, restore the earliest version and then create a new revision to initiate editing. |
| 483 | 480 | */ |
| 484 | - final public function handleExistingRevisions( $chart_id, $chart ) { | |
| 481 | + public final function handleExistingRevisions( $chart_id, $chart ) { | |
| 485 | 482 | |
| 486 | 483 | do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'handleExistingRevisions for %d', $chart_id ), 'debug', __FILE__, __LINE__ ); |
| 487 | 484 | if ( get_post_type( $chart_id ) !== Visualizer_Plugin::CPT_VISUALIZER ) { |
| 488 | 485 | return $chart_id; |
| 489 | 486 | } |
| 490 | - // AI Builder (D3) charts use their own publish flow — skip the classic revision-restore | |
| 491 | - // mechanism, which would otherwise overwrite the saved title and settings. | |
| 492 | - if ( 'd3' === get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, true ) ) { | |
| 493 | - return $chart; | |
| 494 | - } | |
| 495 | 487 | // undo revisions. |
| 496 | 488 | $revisions_found = $this->undoRevisions( $chart_id, true ); |
| 497 | 489 | |
| 498 | 490 | // create revision for the edit action. |
| @@ -536,55 +528,52 @@ | ||
| 536 | 528 | if ( VISUALIZER_TEST_JS_CUSTOMIZATION ) { |
| 537 | 529 | return $default; |
| 538 | 530 | } |
| 539 | 531 | |
| 540 | - try { | |
| 541 | - require_once ABSPATH . 'wp-admin/includes/file.php'; | |
| 542 | - WP_Filesystem(); | |
| 543 | - global $wp_filesystem; | |
| 544 | - if ( ! is_a( $wp_filesystem, 'WP_Filesystem_Base' ) ) { | |
| 545 | - return $default; | |
| 546 | - } | |
| 532 | + require_once( ABSPATH . 'wp-admin/includes/file.php' ); | |
| 533 | + WP_Filesystem(); | |
| 534 | + global $wp_filesystem; | |
| 535 | + if ( ! is_a( $wp_filesystem, 'WP_Filesystem_Base' ) ) { | |
| 536 | + $creds = request_filesystem_credentials( site_url() ); | |
| 537 | + wp_filesystem( $creds ); | |
| 538 | + } | |
| 547 | 539 | |
| 548 | - $multisite_arg = '/'; | |
| 549 | - if ( is_multisite() && ! is_main_site() ) { | |
| 550 | - $multisite_arg = '/sites/' . get_current_blog_id() . '/'; | |
| 551 | - } | |
| 540 | + $multisite_arg = '/'; | |
| 541 | + if ( is_multisite() && ! is_main_site() ) { | |
| 542 | + $multisite_arg = '/sites/' . get_current_blog_id() . '/'; | |
| 543 | + } | |
| 552 | 544 | |
| 553 | - $dir = $wp_filesystem->wp_content_dir() . 'uploads' . $multisite_arg . 'visualizer'; | |
| 554 | - $file = $wp_filesystem->wp_content_dir() . 'uploads' . $multisite_arg . 'visualizer/customization.js'; | |
| 545 | + $dir = $wp_filesystem->wp_content_dir() . 'uploads' . $multisite_arg . 'visualizer'; | |
| 546 | + $file = $wp_filesystem->wp_content_dir() . 'uploads' . $multisite_arg . 'visualizer/customization.js'; | |
| 555 | 547 | |
| 556 | - if ( $wp_filesystem->is_readable( $file ) ) { | |
| 557 | - return $specific; | |
| 558 | - } | |
| 548 | + if ( $wp_filesystem->is_readable( $file ) ) { | |
| 549 | + return $specific; | |
| 550 | + } | |
| 559 | 551 | |
| 560 | - if ( $wp_filesystem->exists( $file ) && ! $wp_filesystem->is_readable( $file ) ) { | |
| 561 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to read file %s', $file ), 'error', __FILE__, __LINE__ ); | |
| 552 | + if ( $wp_filesystem->exists( $file ) && ! $wp_filesystem->is_readable( $file ) ) { | |
| 553 | + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to read file %s', $file ), 'error', __FILE__, __LINE__ ); | |
| 554 | + return $default; | |
| 555 | + } | |
| 556 | + | |
| 557 | + if ( ! $wp_filesystem->exists( $dir ) ) { | |
| 558 | + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found | |
| 559 | + if ( ( $done = $wp_filesystem->mkdir( $dir ) ) === false ) { | |
| 560 | + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to create directory %s', $dir ), 'error', __FILE__, __LINE__ ); | |
| 562 | 561 | return $default; |
| 563 | 562 | } |
| 563 | + } | |
| 564 | 564 | |
| 565 | - if ( ! $wp_filesystem->exists( $dir ) ) { | |
| 566 | - $done = $wp_filesystem->mkdir( $dir ); | |
| 567 | - if ( $done === false ) { | |
| 568 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to create directory %s', $dir ), 'error', __FILE__, __LINE__ ); | |
| 569 | - return $default; | |
| 570 | - } | |
| 565 | + // if file does not exist, copy. | |
| 566 | + if ( ! $wp_filesystem->exists( $file ) ) { | |
| 567 | + $src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' ); | |
| 568 | + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found | |
| 569 | + if ( ( $done = $wp_filesystem->copy( $src, $file ) ) === false ) { | |
| 570 | + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to copy file %s to %s', $src, $file ), 'error', __FILE__, __LINE__ ); | |
| 571 | + return $default; | |
| 571 | 572 | } |
| 573 | + } | |
| 572 | 574 | |
| 573 | - // if file does not exist, copy. | |
| 574 | - if ( ! $wp_filesystem->exists( $file ) ) { | |
| 575 | - $src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' ); | |
| 576 | - $done = $wp_filesystem->copy( $src, $file ); | |
| 577 | - if ( $done === false ) { | |
| 578 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to copy file %s to %s', $src, $file ), 'error', __FILE__, __LINE__ ); | |
| 579 | - return $default; | |
| 580 | - } | |
| 581 | - } | |
| 582 | - | |
| 583 | - return $specific; | |
| 584 | - } catch ( \Throwable $e ) { | |
| 585 | - return $default; | |
| 586 | - } | |
| 575 | + return $specific; | |
| 587 | 576 | } |
| 588 | 577 | |
| 589 | 578 | /** |
| 590 | 579 | * Load the class for the given chart's chart type so that its assets can be loaded. |
| @@ -589,18 +578,15 @@ | ||
| 589 | 578 | /** |
| 590 | 579 | * Load the class for the given chart's chart type so that its assets can be loaded. |
| 591 | 580 | */ |
| 592 | 581 | protected function load_chart_type( $chart_id ) { |
| 593 | - // D3/AI charts have no traditional type class — return the library string directly. | |
| 594 | - $lib = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, true ); | |
| 595 | - if ( 'd3' === $lib ) { | |
| 596 | - return 'd3'; | |
| 597 | - } | |
| 598 | - | |
| 599 | 582 | $name = $this->load_chart_class_name( $chart_id ); |
| 600 | 583 | $class = null; |
| 601 | 584 | if ( class_exists( $name ) || true === apply_filters( 'visualizer_load_chart', false, $name ) ) { |
| 602 | - $class = new $name(); | |
| 585 | + if ( 'Visualizer_Render_Sidebar_Type_DataTable_DataTable' === $name ) { | |
| 586 | + $name = 'Visualizer_Render_Sidebar_Type_DataTable_Tabular'; | |
| 587 | + } | |
| 588 | + $class = new $name; | |
| 603 | 589 | } |
| 604 | 590 | |
| 605 | 591 | if ( is_null( $class ) && Visualizer_Module::is_pro() ) { |
| 606 | 592 | // lets see if this type exists in pro. New Lite(3.1.0+) & old Pro(1.8.0-). |
| @@ -759,9 +745,9 @@ | ||
| 759 | 745 | |
| 760 | 746 | /** |
| 761 | 747 | * Gets the features for the provided license type. |
| 762 | 748 | */ |
| 763 | - final public static function get_features_for_license( $plan ) { | |
| 749 | + public static final function get_features_for_license( $plan ) { | |
| 764 | 750 | $is_new_personal = apply_filters( 'visualizer_is_new_personal', false ); |
| 765 | 751 | switch ( $plan ) { |
| 766 | 752 | case 1: |
| 767 | 753 | $features = array( 'import-wp', 'import-wc-report', 'import-file', 'import-url' ); |