| @@ -7,8 +7,10 @@ | ||
| 7 | 7 | * @author Tobias Bäthge |
| 8 | 8 | * @since 1.0.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | +declare(strict_types=1); | |
| 12 | + | |
| 11 | 13 | // Prohibit direct script loading. |
| 12 | 14 | defined( 'ABSPATH' ) || die( 'No direct script access allowed!' ); |
| 13 | 15 | |
| 14 | 16 | /** |
| @@ -27,9 +29,9 @@ | ||
| 27 | 29 | * |
| 28 | 30 | * @since 1.0.0 |
| 29 | 31 | * @var string[] |
| 30 | 32 | */ |
| 31 | - protected $page_hooks = array(); | |
| 33 | + protected array $page_hooks = array(); | |
| 32 | 34 | |
| 33 | 35 | /** |
| 34 | 36 | * Actions that have a view and admin menu or nav tab menu entry. |
| 35 | 37 | * |
| @@ -35,17 +37,16 @@ | ||
| 35 | 37 | * |
| 36 | 38 | * @since 1.0.0 |
| 37 | 39 | * @var array<string, array<string, bool|string>> |
| 38 | 40 | */ |
| 39 | - protected $view_actions = array(); | |
| 41 | + protected array $view_actions = array(); | |
| 40 | 42 | |
| 41 | 43 | /** |
| 42 | 44 | * Instance of the TablePress Admin View that is rendered. |
| 43 | 45 | * |
| 44 | 46 | * @since 1.0.0 |
| 45 | - * @var TablePress_View | |
| 46 | 47 | */ |
| 47 | - protected $view; | |
| 48 | + protected \TablePress_View $view; | |
| 48 | 49 | |
| 49 | 50 | /** |
| 50 | 51 | * Initialize the Admin Controller, determine location the admin menu, set up actions. |
| 51 | 52 | * |
| @@ -94,14 +95,18 @@ | ||
| 94 | 95 | * @param string $entry_name The admin menu entry name. Default "TablePress". |
| 95 | 96 | */ |
| 96 | 97 | $admin_menu_entry_name = apply_filters( 'tablepress_admin_menu_entry_name', 'TablePress' ); |
| 97 | 98 | |
| 99 | + if ( TablePress::$model_options->get( 'message_plugin_update' ) && strtotime( '2026-10-10' ) >= strtotime( 'today' ) ) { | |
| 100 | + $admin_menu_entry_name .= ' <span class="dashicons dashicons-buddicons-community" aria-hidden="true" style="color:orange"></span>'; | |
| 101 | + } | |
| 102 | + | |
| 98 | 103 | $this->init_view_actions(); |
| 99 | 104 | $min_access_cap = $this->view_actions['list']['required_cap']; |
| 100 | 105 | |
| 101 | - if ( $this->is_top_level_page ) { | |
| 102 | - $icon_url = 'dashicons-list-view'; | |
| 103 | - switch ( $this->parent_page ) { | |
| 106 | + if ( TablePress::$controller->is_top_level_page ) { | |
| 107 | + $icon_url = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgdmlld0JveD0iLTMyIC0zMiA2NCA2NCIgZmlsbD0iI2ZmZiI+PHBhdGggZD0iTTAtMjUuODU0aC0yNS44NTR2NTEuNzA4aDUxLjcwOFYwSDIxdjIxaC00MnYtNDJIMFoiLz48cGF0aCBkPSJNLTE4LTE4aDEwdjEwaC0xMHpNLTE4LTVoMTBWNWgtMTB6TS01LTVINVY1SC01ek0tMTggOGgxMHYxMGgtMTB6TS01IDhINXYxMEgtNXpNOCA4aDEwdjEwSDh6TTUtMzFoNi4xOHY2LjE4SDV6TTE5LTI1aDYuMTh2Ni4xOEgxOXpNMC0xNWgzLjgydjMuODJIMHpNMTAtMjBoMy44MnYzLjgySDEwek0yNS0xMmgzLjgydjMuODJIMjV6TTgtMTNoMTB2MTBIOHoiLz48L3N2Zz4='; | |
| 108 | + switch ( TablePress::$controller->parent_page ) { | |
| 104 | 109 | case 'top': |
| 105 | 110 | $position = 3; // Position of Dashboard + 1. |
| 106 | 111 | break; |
| 107 | 112 | case 'bottom': |
| @@ -115,9 +120,9 @@ | ||
| 115 | 120 | // Prevent overwriting existing menu entries. |
| 116 | 121 | while ( isset( $GLOBALS['menu'][ $position ] ) ) { |
| 117 | 122 | ++$position; |
| 118 | 123 | } |
| 119 | - add_menu_page( 'TablePress', $admin_menu_entry_name, $min_access_cap, 'tablepress', $callback, $icon_url, $position ); // @phpstan-ignore-line | |
| 124 | + add_menu_page( 'TablePress', $admin_menu_entry_name, $min_access_cap, 'tablepress', $callback, $icon_url, $position ); // @phpstan-ignore argument.type | |
| 120 | 125 | foreach ( $this->view_actions as $action => $entry ) { |
| 121 | 126 | if ( ! $entry['show_entry'] ) { |
| 122 | 127 | continue; |
| 123 | 128 | } |
| @@ -124,17 +129,17 @@ | ||
| 124 | 129 | $slug = 'tablepress'; |
| 125 | 130 | if ( 'list' !== $action ) { |
| 126 | 131 | $slug .= '_' . $action; |
| 127 | 132 | } |
| 128 | - // @phpstan-ignore-next-line | |
| 129 | - $page_hook = add_submenu_page( 'tablepress', sprintf( __( '%1$s ‹ %2$s', 'tablepress' ), $entry['page_title'], 'TablePress' ), $entry['admin_menu_title'], $entry['required_cap'], $slug, $callback ); | |
| 133 | + /* translators: %1$s: Page title, %2$s: Plugin name (TablePress) */ | |
| 134 | + $page_hook = add_submenu_page( 'tablepress', sprintf( __( '%1$s ‹ %2$s', 'tablepress' ), $entry['page_title'], 'TablePress' ), $entry['admin_menu_title'], $entry['required_cap'], $slug, $callback ); // @phpstan-ignore argument.type, argument.type | |
| 130 | 135 | if ( false !== $page_hook ) { |
| 131 | 136 | $this->page_hooks[] = $page_hook; |
| 132 | 137 | } |
| 133 | 138 | } |
| 134 | 139 | } else { |
| 135 | - // @phpstan-ignore-next-line | |
| 136 | - $page_hook = add_submenu_page( $this->parent_page, 'TablePress', $admin_menu_entry_name, $min_access_cap, 'tablepress', $callback ); | |
| 140 | + // @phpstan-ignore argument.type | |
| 141 | + $page_hook = add_submenu_page( TablePress::$controller->parent_page, 'TablePress', $admin_menu_entry_name, $min_access_cap, 'tablepress', $callback ); | |
| 137 | 142 | if ( false !== $page_hook ) { |
| 138 | 143 | $this->page_hooks[] = $page_hook; |
| 139 | 144 | } |
| 140 | 145 | } |
| @@ -179,13 +184,8 @@ | ||
| 179 | 184 | add_action( 'admin_bar_menu', array( $this, 'add_wp_admin_bar_new_content_menu_entry' ), 71 ); |
| 180 | 185 | } |
| 181 | 186 | |
| 182 | 187 | add_action( 'load-plugins.php', array( $this, 'plugins_page' ) ); |
| 183 | - | |
| 184 | - // Add filters and actions for the integration into the WP WXR exporter and importer. | |
| 185 | - add_action( 'wp_import_insert_post', array( TablePress::$model_table, 'add_table_id_on_wp_import' ), 10, 4 ); | |
| 186 | - add_filter( 'wp_import_post_meta', array( TablePress::$model_table, 'prevent_table_id_post_meta_import_on_wp_import' ), 10, 3 ); | |
| 187 | - add_filter( 'wxr_export_skip_postmeta', array( TablePress::$model_table, 'add_table_id_to_wp_export' ), 10, 3 ); | |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
| 191 | 191 | * Loads additional JavaScript code for the TablePress table block (in the block editor context). |
| @@ -192,9 +192,8 @@ | ||
| 192 | 192 | * |
| 193 | 193 | * @since 2.2.0 |
| 194 | 194 | */ |
| 195 | 195 | public function enqueue_block_editor_assets(): void { |
| 196 | - // Add table information for the block editor to the page. | |
| 197 | 196 | $handle = generate_block_asset_handle( 'tablepress/table', 'editorScript' ); |
| 198 | 197 | $data = $this->get_block_editor_data(); |
| 199 | 198 | wp_add_inline_script( $handle, $data, 'before' ); |
| 200 | 199 | } |
| @@ -206,9 +205,9 @@ | ||
| 206 | 205 | */ |
| 207 | 206 | public function enqueue_block_assets(): void { |
| 208 | 207 | // Load the TablePress default CSS and the user's "Custom CSS" in the block editor iframe. |
| 209 | 208 | if ( is_admin() ) { |
| 210 | - TablePress::$controller->enqueue_css(); | |
| 209 | + TablePress::$controller->maybe_enqueue_css(); | |
| 211 | 210 | } |
| 212 | 211 | } |
| 213 | 212 | |
| 214 | 213 | /** |
| @@ -280,17 +279,17 @@ | ||
| 280 | 279 | $url = TablePress::url( array( 'action' => 'list' ) ); |
| 281 | 280 | } |
| 282 | 281 | |
| 283 | 282 | return <<<JS |
| 284 | -// Ensure the global `tp` object exists. | |
| 285 | -window.tp = window.tp || {}; | |
| 286 | -tp.url = '{$url}'; | |
| 287 | -tp.load_block_preview = {$load_block_preview}; | |
| 288 | -tp.table = {}; | |
| 289 | -tp.table.shortcode = '{$shortcode}'; | |
| 290 | -tp.table.template = JSON.parse( '{$template}' ); | |
| 291 | -tp.tables = JSON.parse( '{$tables}' ); | |
| 292 | -JS; | |
| 283 | + // Ensure the global `tp` object exists. | |
| 284 | + window.tp = window.tp || {}; | |
| 285 | + tp.url = '{$url}'; | |
| 286 | + tp.load_block_preview = {$load_block_preview}; | |
| 287 | + tp.table = {}; | |
| 288 | + tp.table.shortcode = '{$shortcode}'; | |
| 289 | + tp.table.template = JSON.parse( '{$template}' ); | |
| 290 | + tp.tables = JSON.parse( '{$tables}' ); | |
| 291 | + JS; | |
| 293 | 292 | } |
| 294 | 293 | |
| 295 | 294 | /** |
| 296 | 295 | * Register actions to add "Table" button to "HTML editor" and "Visual editor" toolbars. |
| @@ -302,15 +301,14 @@ | ||
| 302 | 301 | return; |
| 303 | 302 | } |
| 304 | 303 | |
| 305 | 304 | // Only load the toolbar integration if the Block Editor is not used. |
| 306 | - if ( TablePress::site_uses_block_editor() ) { | |
| 305 | + if ( 'block' === TablePress::site_used_editor() ) { | |
| 307 | 306 | return; |
| 308 | 307 | } |
| 309 | 308 | |
| 310 | 309 | add_thickbox(); // The files are usually already loaded by media upload functions. |
| 311 | - $admin_page = TablePress::load_class( 'TablePress_Admin_Page', 'class-admin-page-helper.php', 'classes' ); | |
| 312 | - $admin_page->enqueue_script( | |
| 310 | + TablePress::enqueue_script( | |
| 313 | 311 | 'quicktags-button', |
| 314 | 312 | array( 'quicktags', 'media-upload' ), |
| 315 | 313 | array( |
| 316 | 314 | 'editor_button' => array( |
| @@ -318,9 +316,9 @@ | ||
| 318 | 316 | 'title' => __( 'Insert a TablePress table', 'tablepress' ), |
| 319 | 317 | 'thickbox_title' => __( 'Insert a TablePress table', 'tablepress' ), |
| 320 | 318 | 'thickbox_url' => TablePress::url( array( 'action' => 'editor_button_thickbox' ), true, 'admin-post.php' ), |
| 321 | 319 | ), |
| 322 | - ) | |
| 320 | + ), | |
| 323 | 321 | ); |
| 324 | 322 | |
| 325 | 323 | // TinyMCE integration. |
| 326 | 324 | if ( user_can_richedit() ) { |
| @@ -374,9 +372,9 @@ | ||
| 374 | 372 | |
| 375 | 373 | $wp_admin_bar->add_menu( array( |
| 376 | 374 | 'parent' => 'new-content', |
| 377 | 375 | 'id' => 'new-tablepress-table', |
| 378 | - 'title' => __( 'TablePress Table', 'tablepress' ), | |
| 376 | + 'title' => __( 'TablePress table', 'tablepress' ), | |
| 379 | 377 | 'href' => TablePress::url( array( 'action' => 'add' ) ), |
| 380 | 378 | ) ); |
| 381 | 379 | } |
| 382 | 380 | |
| @@ -393,8 +391,9 @@ | ||
| 393 | 391 | 'tablepress-datatables-alphabetsearch/tablepress-datatables-alphabetsearch.php', |
| 394 | 392 | 'tablepress-datatables-column-filter-widgets/tablepress-datatables-column-filter-widgets.php', |
| 395 | 393 | 'tablepress-datatables-columnfilter/tablepress-datatables-columnfilter.php', |
| 396 | 394 | 'tablepress-datatables-fixedcolumns/tablepress-datatables-fixedcolumns.php', |
| 395 | + 'tablepress-datatables-inverted-filter/tablepress-datatables-inverted-filter.php', | |
| 397 | 396 | 'tablepress-datatables-row-details/tablepress-datatables-row-details.php', |
| 398 | 397 | 'tablepress-datatables-rowgroup/tablepress-datatables-rowgroup.php', |
| 399 | 398 | 'tablepress-responsive-tables/tablepress-responsive-tables.php', |
| 400 | 399 | ); |
| @@ -460,9 +459,9 @@ | ||
| 460 | 459 | if ( tb_tp_fs()->is_free_plan() ) { |
| 461 | 460 | echo '<p style="font-size:14px;">'; |
| 462 | 461 | _e( 'This TablePress Extension was retired.', 'tablepress' ); |
| 463 | 462 | echo ' '; |
| 464 | - _e( '<strong>The plugin will stop working with TablePress 3 later this year</strong> and will no longer receive updates or support!', 'tablepress' ); | |
| 463 | + _e( '<strong>The plugin does no longer work</strong> and will no longer receive updates or support!', 'tablepress' ); | |
| 465 | 464 | echo '<br>'; |
| 466 | 465 | _e( 'Keeping it activated can lead to errors on your website!', 'tablepress' ); |
| 467 | 466 | echo ' <strong>' . sprintf( __( '<a href="%s">Find out what you can do to continue using its features!</a>', 'tablepress' ), 'https://tablepress.org/upgrade-extensions/?utm_source=plugin&utm_medium=textlink&utm_content=plugins-list-table' ) . '</strong>'; |
| 468 | 467 | echo '</p>'; |
| @@ -492,9 +491,9 @@ | ||
| 492 | 491 | */ |
| 493 | 492 | public function load_admin_page(): void { |
| 494 | 493 | // Determine the action from either the GET parameter (for sub-menu entries, and the main admin menu entry). |
| 495 | 494 | $action = ( ! empty( $_GET['action'] ) ) ? $_GET['action'] : 'list'; // Default action is list. |
| 496 | - if ( $this->is_top_level_page ) { | |
| 495 | + if ( TablePress::$controller->is_top_level_page ) { | |
| 497 | 496 | // Or, for sub-menu entry of an admin menu "TablePress" entry, get it from the "page" GET parameter. |
| 498 | 497 | if ( 'tablepress' !== $_GET['page'] ) { |
| 499 | 498 | // Actions that are top-level entries, but don't have an action GET parameter (action is after last _ in string). |
| 500 | 499 | $action = substr( $_GET['page'], 11 ); // $_GET['page'] has the format 'tablepress_{$action}' |
| @@ -501,9 +500,9 @@ | ||
| 501 | 500 | } |
| 502 | 501 | } |
| 503 | 502 | |
| 504 | 503 | // Check if action is a supported action, and whether the user is allowed to access this screen. |
| 505 | - if ( ! isset( $this->view_actions[ $action ] ) || ! current_user_can( $this->view_actions[ $action ]['required_cap'] ) ) { // @phpstan-ignore-line (The array value for the capability is always a string.) | |
| 504 | + if ( ! isset( $this->view_actions[ $action ] ) || ! current_user_can( $this->view_actions[ $action ]['required_cap'] ) ) { // @phpstan-ignore argument.type (The array value for the capability is always a string.) | |
| 506 | 505 | wp_die( __( 'Sorry, you are not allowed to access this page.', 'default' ), 403 ); |
| 507 | 506 | } |
| 508 | 507 | |
| 509 | 508 | // Don't load TablePress assets on the Freemius opt-in/activation screen. |
| @@ -523,24 +522,24 @@ | ||
| 523 | 522 | } |
| 524 | 523 | |
| 525 | 524 | // Pre-define some view data. |
| 526 | 525 | $data = array( |
| 527 | - 'view_actions' => $this->view_actions, | |
| 528 | - 'message' => ( ! empty( $_GET['message'] ) ) ? $_GET['message'] : false, | |
| 529 | - 'error_details' => ( ! empty( $_GET['error_details'] ) ) ? $_GET['error_details'] : '', | |
| 530 | - 'site_uses_block_editor' => TablePress::site_uses_block_editor(), | |
| 526 | + 'view_actions' => $this->view_actions, | |
| 527 | + 'message' => ( ! empty( $_GET['message'] ) ) ? $_GET['message'] : false, | |
| 528 | + 'error_details' => ( ! empty( $_GET['error_details'] ) ) ? rawurldecode( wp_unslash( $_GET['error_details'] ) ) : '', | |
| 529 | + 'site_used_editor' => TablePress::site_used_editor(), | |
| 531 | 530 | ); |
| 532 | 531 | |
| 533 | 532 | // Depending on the action, load more necessary data for the corresponding view. |
| 534 | 533 | switch ( $action ) { |
| 535 | 534 | case 'list': |
| 536 | - $data['table_id'] = ( ! empty( $_GET['table_id'] ) ) ? $_GET['table_id'] : false; | |
| 535 | + $data['table_id'] = ( isset( $_GET['table_id'] ) ) ? preg_replace( '/[^a-zA-Z0-9_-]/', '', $_GET['table_id'] ) : false; | |
| 537 | 536 | // Prime the post meta cache for cached loading of last_editor. |
| 538 | 537 | $data['table_ids'] = TablePress::$model_table->load_all( true ); |
| 539 | 538 | $data['messages']['donation_nag'] = $this->maybe_show_donation_message(); |
| 540 | 539 | $data['messages']['first_visit'] = ! $data['messages']['donation_nag'] && TablePress::$model_options->get( 'message_first_visit' ); |
| 541 | 540 | $data['messages']['plugin_update'] = TablePress::$model_options->get( 'message_plugin_update' ); |
| 542 | - $data['messages']['superseded_extensions'] = TablePress::$model_options->get( 'message_superseded_extensions' ); | |
| 541 | + $data['messages']['superseded_extensions'] = current_user_can( 'manage_options' ) && TablePress::$model_options->get( 'message_superseded_extensions' ); | |
| 543 | 542 | $data['table_count'] = count( $data['table_ids'] ); |
| 544 | 543 | break; |
| 545 | 544 | case 'about': |
| 546 | 545 | $data['first_activation'] = TablePress::$model_options->get( 'first_activation' ); |
| @@ -551,9 +550,9 @@ | ||
| 551 | 550 | * (called here, as the credentials form posts to this handler again, due to how `request_filesystem_credentials()` works) |
| 552 | 551 | */ |
| 553 | 552 | if ( isset( $_GET['item'] ) && 'save_custom_css' === $_GET['item'] ) { |
| 554 | 553 | TablePress::check_nonce( 'options', $_GET['item'] ); // Nonce check here, as we don't have an explicit handler, and even viewing the screen needs to be checked. |
| 555 | - $action = 'options_custom_css'; // to load a different view | |
| 554 | + $action = 'options_custom_css'; // To load a different view. | |
| 556 | 555 | // Try saving "Custom CSS" to a file, otherwise this gets the HTML for the credentials form. |
| 557 | 556 | $tablepress_css = TablePress::load_class( 'TablePress_CSS', 'class-css.php', 'classes' ); |
| 558 | 557 | $result = $tablepress_css->save_custom_css_to_file_plugin_options( TablePress::$model_options->get( 'custom_css' ), TablePress::$model_options->get( 'custom_css_minified' ) ); |
| 559 | 558 | if ( is_string( $result ) ) { |
| @@ -574,12 +573,12 @@ | ||
| 574 | 573 | break; |
| 575 | 574 | } |
| 576 | 575 | $data['frontend_options']['use_custom_css'] = TablePress::$model_options->get( 'use_custom_css' ); |
| 577 | 576 | $data['frontend_options']['custom_css'] = TablePress::$model_options->get( 'custom_css' ); |
| 578 | - $data['user_options']['parent_page'] = $this->parent_page; | |
| 577 | + $data['user_options']['parent_page'] = TablePress::$controller->parent_page; | |
| 579 | 578 | break; |
| 580 | 579 | case 'edit': |
| 581 | - if ( empty( $_GET['table_id'] ) ) { | |
| 580 | + if ( ! isset( $_GET['table_id'] ) || ! preg_match( '/^[a-zA-Z0-9_-]+$/', $_GET['table_id'] ) ) { | |
| 582 | 581 | TablePress::redirect( array( 'action' => 'list', 'message' => 'error_no_table' ) ); |
| 583 | 582 | } |
| 584 | 583 | // Load table, with table data, options, and visibility settings. |
| 585 | 584 | $data['table'] = TablePress::$model_table->load( $_GET['table_id'], true, true ); |
| @@ -608,9 +607,9 @@ | ||
| 608 | 607 | |
| 609 | 608 | $data['tables'][ $table['id'] ] = $table['name']; |
| 610 | 609 | } |
| 611 | 610 | $data['tables_count'] = TablePress::$model_table->count_tables(); |
| 612 | - $data['export_ids'] = ( ! empty( $_GET['table_id'] ) ) ? explode( ',', $_GET['table_id'] ) : array(); | |
| 611 | + $data['export_ids'] = ( isset( $_GET['table_id'] ) && preg_match( '/^[,a-zA-Z0-9_-]+$/', $_GET['table_id'] ) ) ? explode( ',', $_GET['table_id'] ) : array(); | |
| 613 | 612 | $exporter = TablePress::load_class( 'TablePress_Export', 'class-export.php', 'classes' ); |
| 614 | 613 | $data['zip_support_available'] = $exporter->zip_support_available; |
| 615 | 614 | $data['export_formats'] = $exporter->export_formats; |
| 616 | 615 | $data['csv_delimiters'] = $exporter->csv_delimiters; |
| @@ -638,13 +637,13 @@ | ||
| 638 | 637 | $data['table_ids'] = $table_ids; // Backward compatibility for the retired "Table Auto Update" Extension, which still relies on this variable name. |
| 639 | 638 | $data['tables_count'] = TablePress::$model_table->count_tables(); |
| 640 | 639 | $importer = TablePress::load_class( 'TablePress_Import', 'class-import.php', 'classes' ); |
| 641 | 640 | $data['import_type'] = ( ! empty( $_GET['import_type'] ) ) ? $_GET['import_type'] : 'add'; |
| 642 | - $data['import_existing_table'] = ( ! empty( $_GET['import_existing_table'] ) ) ? $_GET['import_existing_table'] : ''; | |
| 641 | + $data['import_existing_table'] = $_GET['import_existing_table'] ?? ''; | |
| 643 | 642 | $data['import_source'] = ( ! empty( $_GET['import_source'] ) ) ? $_GET['import_source'] : 'file-upload'; |
| 644 | - $data['import_url'] = ( ! empty( $_GET['import_url'] ) ) ? wp_unslash( $_GET['import_url'] ) : 'https://'; | |
| 645 | - $data['import_server'] = ( ! empty( $_GET['import_server'] ) ) ? wp_unslash( $_GET['import_server'] ) : ABSPATH; | |
| 646 | - $data['import_form-field'] = ( ! empty( $_GET['import_form-field'] ) ) ? wp_unslash( $_GET['import_form-field'] ) : ''; | |
| 643 | + $data['import_url'] = ( ! empty( $_GET['import_url'] ) ) ? rawurldecode( wp_unslash( $_GET['import_url'] ) ) : 'https://'; | |
| 644 | + $data['import_server'] = ( ! empty( $_GET['import_server'] ) ) ? rawurldecode( wp_unslash( $_GET['import_server'] ) ) : ABSPATH; | |
| 645 | + $data['import_form-field'] = ( ! empty( $_GET['import_form-field'] ) ) ? rawurldecode( wp_unslash( $_GET['import_form-field'] ) ) : ''; | |
| 647 | 646 | $data['legacy_import'] = ( ! empty( $_GET['legacy_import'] ) ) ? $_GET['legacy_import'] : 'false'; |
| 648 | 647 | break; |
| 649 | 648 | } |
| 650 | 649 | |
| @@ -868,10 +867,10 @@ | ||
| 868 | 867 | |
| 869 | 868 | $add_table = wp_unslash( $_POST['table'] ); |
| 870 | 869 | |
| 871 | 870 | // Perform confidence checks of posted data. |
| 872 | - $name = ( isset( $add_table['name'] ) ) ? $add_table['name'] : ''; | |
| 873 | - $description = ( isset( $add_table['description'] ) ) ? $add_table['description'] : ''; | |
| 871 | + $name = $add_table['name'] ?? ''; | |
| 872 | + $description = $add_table['description'] ?? ''; | |
| 874 | 873 | if ( ! isset( $add_table['rows'], $add_table['columns'] ) ) { |
| 875 | 874 | TablePress::redirect( array( 'action' => 'add', 'message' => 'error_add', 'error_details' => 'The HTTP POST data does not contain the table size.' ) ); |
| 876 | 875 | } |
| 877 | 876 | |
| @@ -931,10 +930,10 @@ | ||
| 931 | 930 | if ( ! empty( $posted_options['admin_menu_parent_page'] ) && '-' !== $posted_options['admin_menu_parent_page'] ) { |
| 932 | 931 | $new_options['admin_menu_parent_page'] = $posted_options['admin_menu_parent_page']; |
| 933 | 932 | // Re-init parent information, as `TablePress::redirect()` URL might be wrong otherwise. |
| 934 | 933 | /** This filter is documented in classes/class-controller.php */ |
| 935 | - $this->parent_page = apply_filters( 'tablepress_admin_menu_parent_page', $posted_options['admin_menu_parent_page'] ); | |
| 936 | - $this->is_top_level_page = in_array( $this->parent_page, array( 'top', 'middle', 'bottom' ), true ); | |
| 934 | + TablePress::$controller->parent_page = apply_filters( 'tablepress_admin_menu_parent_page', $posted_options['admin_menu_parent_page'] ); | |
| 935 | + TablePress::$controller->is_top_level_page = in_array( TablePress::$controller->parent_page, array( 'top', 'middle', 'bottom' ), true ); | |
| 937 | 936 | } |
| 938 | 937 | |
| 939 | 938 | // Custom CSS can only be saved if the user is allowed to do so. |
| 940 | 939 | $update_custom_css_files = false; |
| @@ -945,13 +944,20 @@ | ||
| 945 | 944 | if ( isset( $posted_options['custom_css'] ) ) { |
| 946 | 945 | $new_options['custom_css'] = $posted_options['custom_css']; |
| 947 | 946 | |
| 948 | 947 | $tablepress_css = TablePress::load_class( 'TablePress_CSS', 'class-css.php', 'classes' ); |
| 949 | - // Sanitize and tidy up Custom CSS. | |
| 950 | - $new_options['custom_css'] = $tablepress_css->sanitize_css( $new_options['custom_css'] ); | |
| 951 | - // Minify Custom CSS. | |
| 952 | - $new_options['custom_css_minified'] = $tablepress_css->minify_css( $new_options['custom_css'] ); | |
| 953 | 948 | |
| 949 | + if ( '' !== $new_options['custom_css'] ) { | |
| 950 | + // Update "Custom CSS" to use DataTables 2 variants instead of old DataTables 1.x CSS classes. | |
| 951 | + $new_options['custom_css'] = TablePress::convert_datatables_api_data( $new_options['custom_css'] ); | |
| 952 | + // Sanitize and tidy up Custom CSS. | |
| 953 | + $new_options['custom_css'] = $tablepress_css->sanitize_css( $new_options['custom_css'] ); | |
| 954 | + // Minify Custom CSS. | |
| 955 | + $new_options['custom_css_minified'] = $tablepress_css->minify_css( $new_options['custom_css'] ); | |
| 956 | + } else { | |
| 957 | + $new_options['custom_css_minified'] = ''; | |
| 958 | + } | |
| 959 | + | |
| 954 | 960 | // Maybe update CSS files as well. |
| 955 | 961 | $custom_css_file_contents = $tablepress_css->load_custom_css_from_file( 'normal' ); |
| 956 | 962 | if ( false === $custom_css_file_contents ) { |
| 957 | 963 | $custom_css_file_contents = ''; |
| @@ -1005,10 +1011,9 @@ | ||
| 1005 | 1011 | |
| 1006 | 1012 | if ( empty( $export['format'] ) || ! isset( $exporter->export_formats[ $export['format'] ] ) ) { |
| 1007 | 1013 | TablePress::redirect( array( 'action' => 'export', 'message' => 'error_export', 'error_details' => 'The export format is invalid.' ) ); |
| 1008 | 1014 | } |
| 1009 | - if ( empty( $export['csv_delimiter'] ) ) { | |
| 1010 | - // Set a value, so that the variable exists. | |
| 1015 | + if ( ! isset( $export['csv_delimiter'] ) ) { | |
| 1011 | 1016 | $export['csv_delimiter'] = ''; |
| 1012 | 1017 | } |
| 1013 | 1018 | if ( 'csv' === $export['format'] && ! isset( $exporter->csv_delimiters[ $export['csv_delimiter'] ] ) ) { |
| 1014 | 1019 | TablePress::redirect( array( 'action' => 'export', 'message' => 'error_export', 'error_details' => 'The CSV delimiter is invalid.' ) ); |
| @@ -1052,9 +1057,13 @@ | ||
| 1052 | 1057 | */ |
| 1053 | 1058 | $download_filename = apply_filters( 'tablepress_export_filename', $download_filename, $table['id'], $table['name'], $export['format'], $export_to_zip ); |
| 1054 | 1059 | $download_filename = sanitize_file_name( $download_filename ); |
| 1055 | 1060 | // Export the table. |
| 1056 | - $export_data = $exporter->export_table( $table, $export['format'], $export['csv_delimiter'] ); | |
| 1061 | + $options = array(); | |
| 1062 | + if ( 'csv' === $export['format'] ) { | |
| 1063 | + $options['csv_delimiter'] = $export['csv_delimiter']; | |
| 1064 | + } | |
| 1065 | + $export_data = $exporter->export_table( $table, $export['format'], $options ); | |
| 1057 | 1066 | /** |
| 1058 | 1067 | * Filters the exported table data. |
| 1059 | 1068 | * |
| 1060 | 1069 | * @since 1.6.0 |
| @@ -1078,9 +1087,9 @@ | ||
| 1078 | 1087 | /** This filter is documented in controllers/controller-admin.php */ |
| 1079 | 1088 | $download_filename = apply_filters( 'tablepress_export_filename', $download_filename, '', '', $export['format'], $export_to_zip ); |
| 1080 | 1089 | $download_filename = sanitize_file_name( $download_filename ); |
| 1081 | 1090 | $full_filename = wp_tempnam( $download_filename ); |
| 1082 | - if ( true !== $zip_file->open( $full_filename, ZIPARCHIVE::OVERWRITE ) ) { | |
| 1091 | + if ( true !== $zip_file->open( $full_filename, ZipArchive::OVERWRITE ) ) { | |
| 1083 | 1092 | @unlink( $full_filename ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
| 1084 | 1093 | TablePress::redirect( array( 'action' => 'export', 'message' => 'error_create_zip_file', 'export_format' => $export['format'], 'csv_delimiter' => $export['csv_delimiter'], 'error_details' => 'The ZIP file could not be opened for writing.' ) ); |
| 1085 | 1094 | } |
| 1086 | 1095 | |
| @@ -1098,9 +1107,13 @@ | ||
| 1098 | 1107 | // Don't export if the table is corrupted. |
| 1099 | 1108 | if ( isset( $table['is_corrupted'] ) && $table['is_corrupted'] ) { |
| 1100 | 1109 | continue; |
| 1101 | 1110 | } |
| 1102 | - $export_data = $exporter->export_table( $table, $export['format'], $export['csv_delimiter'] ); | |
| 1111 | + $options = array(); | |
| 1112 | + if ( 'csv' === $export['format'] ) { | |
| 1113 | + $options['csv_delimiter'] = $export['csv_delimiter']; | |
| 1114 | + } | |
| 1115 | + $export_data = $exporter->export_table( $table, $export['format'], $options ); | |
| 1103 | 1116 | /** This filter is documented in controllers/controller-admin.php */ |
| 1104 | 1117 | $export_data = apply_filters( 'tablepress_export_data', $export_data, $table, $export['format'], $export['csv_delimiter'] ); |
| 1105 | 1118 | $export_filename = sprintf( '%1$s-%2$s-%3$s.%4$s', $table['id'], $table['name'], wp_date( 'Y-m-d' ), $export['format'] ); |
| 1106 | 1119 | /** This filter is documented in controllers/controller-admin.php */ |
| @@ -1110,9 +1123,9 @@ | ||
| 1110 | 1123 | } |
| 1111 | 1124 | |
| 1112 | 1125 | // If something went wrong, or no files were added to the ZIP file, bail out. |
| 1113 | 1126 | // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
| 1114 | - if ( ZIPARCHIVE::ER_OK !== $zip_file->status || 0 === $zip_file->numFiles ) { | |
| 1127 | + if ( ZipArchive::ER_OK !== $zip_file->status || 0 === $zip_file->numFiles ) { | |
| 1115 | 1128 | $zip_file->close(); |
| 1116 | 1129 | @unlink( $full_filename ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
| 1117 | 1130 | TablePress::redirect( array( 'action' => 'export', 'message' => 'error_create_zip_file', 'export_format' => $export['format'], 'csv_delimiter' => $export['csv_delimiter'], 'error_details' => 'The ZIP file could not be written or is empty.' ) ); |
| 1118 | 1131 | } |
| @@ -1210,9 +1223,9 @@ | ||
| 1210 | 1223 | 'import_source' => $import_config['source'], |
| 1211 | 1224 | 'legacy_import' => $import_config['legacy_import'], |
| 1212 | 1225 | ); |
| 1213 | 1226 | if ( in_array( $import_config['source'], array( 'url', 'server' ), true ) ) { |
| 1214 | - $redirect_parameters[ "import_{$import_config['source']}" ] = $import_config[ $import_config['source'] ]; | |
| 1227 | + $redirect_parameters[ "import_{$import_config['source']}" ] = rawurlencode( $import_config[ $import_config['source'] ] ); | |
| 1215 | 1228 | } |
| 1216 | 1229 | if ( is_wp_error( $import ) ) { |
| 1217 | 1230 | $redirect_parameters['error_details'] = TablePress::get_wp_error_string( $import ); |
| 1218 | 1231 | } elseif ( 0 < count( $import['errors'] ) ) { |
| @@ -1244,9 +1257,9 @@ | ||
| 1244 | 1257 | * |
| 1245 | 1258 | * @since 1.0.0 |
| 1246 | 1259 | */ |
| 1247 | 1260 | public function handle_get_action_hide_message(): void { |
| 1248 | - $message_item = ! empty( $_GET['item'] ) ? $_GET['item'] : ''; | |
| 1261 | + $message_item = $_GET['item'] ?? ''; | |
| 1249 | 1262 | TablePress::check_nonce( 'hide_message', $message_item ); |
| 1250 | 1263 | |
| 1251 | 1264 | if ( ! current_user_can( 'tablepress_list_tables' ) ) { |
| 1252 | 1265 | wp_die( __( 'Sorry, you are not allowed to access this page.', 'default' ), 403 ); |
| @@ -1382,12 +1395,12 @@ | ||
| 1382 | 1395 | $render_options['html_id'] = "tablepress-{$table['id']}"; |
| 1383 | 1396 | $render_options['block_preview'] = true; |
| 1384 | 1397 | $_render->set_input( $table, $render_options ); |
| 1385 | 1398 | $view_data = array( |
| 1386 | - 'table_id' => $table_id, | |
| 1387 | - 'head_html' => $_render->get_preview_css(), | |
| 1388 | - 'body_html' => $_render->get_output( 'html' ), | |
| 1389 | - 'site_uses_block_editor' => TablePress::site_uses_block_editor(), | |
| 1399 | + 'table_id' => $table_id, | |
| 1400 | + 'head_html' => $_render->get_preview_css(), | |
| 1401 | + 'body_html' => $_render->get_output( 'html' ), | |
| 1402 | + 'site_used_editor' => TablePress::site_used_editor(), | |
| 1390 | 1403 | ); |
| 1391 | 1404 | |
| 1392 | 1405 | $custom_css = TablePress::$model_options->get( 'custom_css' ); |
| 1393 | 1406 | $use_custom_css = ( TablePress::$model_options->get( 'use_custom_css' ) && '' !== $custom_css ); |