| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Edit Table View |
|---|
| 4 | * |
|---|
| 5 | * @package TablePress |
|---|
| 6 | * @subpackage Views |
|---|
| 7 | * @author Tobias Bäthge |
|---|
| 8 | * @since 1.0.0 |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | // Prohibit direct script loading. |
|---|
| 12 | defined( 'ABSPATH' ) || die( 'No direct script access allowed!' ); |
|---|
| 13 | |
|---|
| 14 | /** |
|---|
| 15 | * Edit Table View class |
|---|
| 16 | * |
|---|
| 17 | * @package TablePress |
|---|
| 18 | * @subpackage Views |
|---|
| 19 | * @author Tobias Bäthge |
|---|
| 20 | * @since 1.0.0 |
|---|
| 21 | */ |
|---|
| 22 | class TablePress_Edit_View extends TablePress_View { |
|---|
| 23 | |
|---|
| 24 | /** |
|---|
| 25 | * List of WP feature pointers for this view. |
|---|
| 26 | * |
|---|
| 27 | * @since 2.0.0 |
|---|
| 28 | * @var string[] |
|---|
| 29 | */ |
|---|
| 30 | protected array $wp_pointers = array( 'tp20_edit_context_menu', 'tp21_edit_screen_options' ); |
|---|
| 31 | |
|---|
| 32 | /** |
|---|
| 33 | * Sets up the view with data and do things that are specific for this view. |
|---|
| 34 | * |
|---|
| 35 | * @since 1.0.0 |
|---|
| 36 | * |
|---|
| 37 | * @param string $action Action for this view. |
|---|
| 38 | * @param array<string, mixed> $data Data for this view. |
|---|
| 39 | */ |
|---|
| 40 | #[\Override] |
|---|
| 41 | public function setup( /* string */ $action, array $data ) /* : void */ { |
|---|
| 42 | // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited. |
|---|
| 43 | |
|---|
| 44 | parent::setup( $action, $data ); |
|---|
| 45 | |
|---|
| 46 | $this->add_text_box( 'no-javascript', array( $this, 'textbox_no_javascript' ), 'header' ); |
|---|
| 47 | |
|---|
| 48 | if ( isset( $data['table']['is_corrupted'] ) && $data['table']['is_corrupted'] ) { |
|---|
| 49 | $this->add_text_box( 'table-corrupted', array( $this, 'textbox_corrupted_table' ), 'header' ); |
|---|
| 50 | return; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | $this->process_action_messages( array( |
|---|
| 54 | 'success_add' => __( 'The table was added successfully.', 'tablepress' ), |
|---|
| 55 | 'success_copy' => _n( 'The table was copied successfully.', 'The tables were copied successfully.', 1, 'tablepress' ) . ' ' . sprintf( __( 'You are now seeing the copied table, which has the table ID “%s”.', 'tablepress' ), esc_html( $data['table']['id'] ) ), |
|---|
| 56 | 'success_import' => __( 'The table was imported successfully.', 'tablepress' ), |
|---|
| 57 | 'error_delete' => __( 'Error: The table could not be deleted.', 'tablepress' ), |
|---|
| 58 | ) ); |
|---|
| 59 | |
|---|
| 60 | // For the Advanced Editor. |
|---|
| 61 | wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|---|
| 62 | wp_enqueue_style( 'editor-buttons' ); |
|---|
| 63 | wp_enqueue_script( 'wpdialogs' ); |
|---|
| 64 | // For the "Insert Image" dialog. |
|---|
| 65 | add_filter( 'media_view_strings', array( $this, 'change_media_view_strings' ) ); |
|---|
| 66 | wp_enqueue_media(); |
|---|
| 67 | // For the "Insert Link" dialog. |
|---|
| 68 | wp_enqueue_script( 'wplink' ); |
|---|
| 69 | |
|---|
| 70 | $this->admin_page->enqueue_style( 'jspreadsheet' ); |
|---|
| 71 | $this->admin_page->enqueue_style( 'jsuites', array( 'tablepress-jspreadsheet' ) ); |
|---|
| 72 | $this->admin_page->enqueue_style( 'edit', array( 'tablepress-jspreadsheet', 'tablepress-jsuites' ) ); |
|---|
| 73 | if ( ! TABLEPRESS_IS_PLAYGROUND_PREVIEW && tb_tp_fs()->is_free_plan() ) { |
|---|
| 74 | $this->admin_page->enqueue_style( 'edit-features', array( 'tablepress-edit' ) ); |
|---|
| 75 | } |
|---|
| 76 | $this->admin_page->enqueue_script( 'jspreadsheet' ); |
|---|
| 77 | $this->admin_page->enqueue_script( 'jsuites', array( 'tablepress-jspreadsheet' ) ); |
|---|
| 78 | $this->admin_page->enqueue_script( 'edit', array( 'tablepress-jspreadsheet', 'tablepress-jsuites', 'jquery-core' ) ); |
|---|
| 79 | |
|---|
| 80 | $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' ); |
|---|
| 81 | $this->add_text_box( 'buttons-top', array( $this, 'textbox_buttons' ), 'normal' ); |
|---|
| 82 | $this->add_meta_box( 'table-information', __( 'Table Information', 'tablepress' ), array( $this, 'postbox_table_information' ), 'normal' ); |
|---|
| 83 | $this->add_meta_box( 'table-data', __( 'Table Content', 'tablepress' ), array( $this, 'postbox_table_data' ), 'normal' ); |
|---|
| 84 | $this->add_meta_box( 'table-manipulation', __( 'Table Manipulation', 'tablepress' ), array( $this, 'postbox_table_manipulation' ), 'normal' ); |
|---|
| 85 | $this->add_meta_box( 'table-options', __( 'Table Options', 'tablepress' ), array( $this, 'postbox_table_options' ), 'normal' ); |
|---|
| 86 | $this->add_meta_box( 'datatables-features', __( 'Table Features for Site Visitors', 'tablepress' ), array( $this, 'postbox_datatables_features' ), 'normal' ); |
|---|
| 87 | $this->add_text_box( 'hidden-containers', array( $this, 'textbox_hidden_containers' ), 'additional' ); |
|---|
| 88 | $this->add_text_box( 'buttons-bottom', array( $this, 'textbox_buttons' ), 'additional' ); |
|---|
| 89 | $this->add_text_box( 'other-actions', array( $this, 'textbox_other_actions' ), 'submit' ); |
|---|
| 90 | |
|---|
| 91 | add_filter( 'screen_settings', array( $this, 'add_screen_options_output' ), 10, 2 ); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | * Changes the Media View string "Insert into post" to "Insert into Table". |
|---|
| 96 | * |
|---|
| 97 | * @since 1.0.0 |
|---|
| 98 | * |
|---|
| 99 | * @param array<string, string> $strings Current set of Media View strings. |
|---|
| 100 | * @return array<string, string> Changed Media View strings. |
|---|
| 101 | */ |
|---|
| 102 | public function change_media_view_strings( array $strings ): array { |
|---|
| 103 | $strings['insertIntoPost'] = __( 'Insert into Table', 'tablepress' ); |
|---|
| 104 | return $strings; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | /** |
|---|
| 108 | * Adds custom screen options to the screen. |
|---|
| 109 | * |
|---|
| 110 | * @since 2.1.0 |
|---|
| 111 | * |
|---|
| 112 | * @param string $screen_settings Screen settings. |
|---|
| 113 | * @param WP_Screen $screen WP_Screen object. |
|---|
| 114 | * @return string Extended Screen settings. |
|---|
| 115 | */ |
|---|
| 116 | public function add_screen_options_output( /* string */ $screen_settings, WP_Screen $screen ): string { |
|---|
| 117 | // Don't use a type hint for the `$screen_settings` argument as many WordPress plugins seem to be returning `null` in their filter hook handlers. |
|---|
| 118 | |
|---|
| 119 | // Protect against other plugins not returning a string for the `$screen_settings` argument. |
|---|
| 120 | if ( ! is_string( $screen_settings ) ) { // @phpstan-ignore function.alreadyNarrowedType (The `is_string()` check is needed as the input is coming from a filter hook.) |
|---|
| 121 | $screen_settings = ''; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | $screen_settings = '<fieldset id="tablepress-screen-options" class="screen-options">'; |
|---|
| 125 | $screen_settings .= '<legend>' . __( 'Table editor settings', 'tablepress' ) . '</legend>'; |
|---|
| 126 | $screen_settings .= '<p>' . __( 'Adjust the default size of the table cells in the table editor below.', 'tablepress' ) . ' ' . __( 'Cells with many lines of text will expand to their full height when they are edited.', 'tablepress' ) . '</p>'; |
|---|
| 127 | $screen_settings .= '<p><em>' . __( 'Please note: These settings only influence the table editor view on this screen, but not the table that the site visitor sees!', 'tablepress' ) . '</em></p>'; |
|---|
| 128 | $screen_settings .= '<div>'; |
|---|
| 129 | $screen_settings .= '<label for="table_editor_column_width">' . __( 'Default column width:', 'tablepress' ) . '</label> '; |
|---|
| 130 | $input = '<input type="number" id="table_editor_column_width" class="small-text" value="' . esc_attr( TablePress::$model_options->get( 'table_editor_column_width' ) ) . '" min="30" max="9999">'; |
|---|
| 131 | /* translators: %s: Input field for the number of pixels */ |
|---|
| 132 | $screen_settings .= sprintf( __( '%s pixels', 'tablepress' ), $input ); |
|---|
| 133 | $screen_settings .= '</div>'; |
|---|
| 134 | $screen_settings .= '<div style="margin-top: 6px;">'; |
|---|
| 135 | $screen_settings .= '<label for="table_editor_line_clamp">' . __( 'Maximum visible lines of text:', 'tablepress' ) . '</label> '; |
|---|
| 136 | $input = '<input type="number" id="table_editor_line_clamp" class="tiny-text" value="' . esc_attr( TablePress::$model_options->get( 'table_editor_line_clamp' ) ) . '" min="0" max="999">'; |
|---|
| 137 | /* translators: %s: Input field for the number of lines */ |
|---|
| 138 | $screen_settings .= sprintf( __( '%s lines', 'tablepress' ), $input ); |
|---|
| 139 | $screen_settings .= '</div>'; |
|---|
| 140 | $screen_settings .= '</fieldset>'; |
|---|
| 141 | return $screen_settings; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | /** |
|---|
| 145 | * Renders the current view. |
|---|
| 146 | * |
|---|
| 147 | * In comparison to the parent class method, this contains handling for the no-js case and adjusts the HTML code structure. |
|---|
| 148 | * |
|---|
| 149 | * @since 2.0.0 |
|---|
| 150 | */ |
|---|
| 151 | #[\Override] |
|---|
| 152 | public function render(): void { |
|---|
| 153 | $this->print_javascript_data(); |
|---|
| 154 | |
|---|
| 155 | ?> |
|---|
| 156 | <div id="tablepress-page" class="wrap"> |
|---|
| 157 | <form> |
|---|
| 158 | <?php |
|---|
| 159 | $this->print_nav_tab_menu(); |
|---|
| 160 | ?> |
|---|
| 161 | <div id="tablepress-body"> |
|---|
| 162 | <hr class="wp-header-end"> |
|---|
| 163 | <?php |
|---|
| 164 | // Print all header messages. |
|---|
| 165 | foreach ( $this->header_messages as $message ) { |
|---|
| 166 | echo $message; |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | $this->do_text_boxes( 'header' ); |
|---|
| 170 | ?> |
|---|
| 171 | <div id="poststuff" class="hide-if-no-js"> |
|---|
| 172 | <div id="post-body" class="metabox-holder columns-1"> |
|---|
| 173 | <div id="postbox-container-2" class="postbox-container"> |
|---|
| 174 | <?php |
|---|
| 175 | $this->do_text_boxes( 'normal' ); |
|---|
| 176 | $this->do_meta_boxes( 'normal' ); |
|---|
| 177 | |
|---|
| 178 | $this->do_text_boxes( 'additional' ); |
|---|
| 179 | $this->do_meta_boxes( 'additional' ); |
|---|
| 180 | |
|---|
| 181 | $this->do_text_boxes( 'submit' ); |
|---|
| 182 | |
|---|
| 183 | $this->do_text_boxes( 'side' ); |
|---|
| 184 | $this->do_meta_boxes( 'side' ); |
|---|
| 185 | ?> |
|---|
| 186 | </div> |
|---|
| 187 | </div> |
|---|
| 188 | <br class="clear"> |
|---|
| 189 | </div> |
|---|
| 190 | </form> |
|---|
| 191 | </div> |
|---|
| 192 | </div> |
|---|
| 193 | <?php |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | /** |
|---|
| 197 | * Overrides parent class method, as the nonces for this view are generated in the JS code. |
|---|
| 198 | * |
|---|
| 199 | * @since 1.0.0 |
|---|
| 200 | * |
|---|
| 201 | * @param array<string, mixed> $data Data for this screen. |
|---|
| 202 | * @param array<string, mixed> $box Information about the text box. |
|---|
| 203 | */ |
|---|
| 204 | #[\Override] |
|---|
| 205 | protected function action_nonce_field( array $data, array $box ): void { |
|---|
| 206 | // Intentionally left empty. Nonces for this view are generated in `print_javascript_data()`. |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | /** |
|---|
| 210 | * Prints the table data for use in JS code and the main React container. |
|---|
| 211 | * |
|---|
| 212 | * @since 3.0.0 |
|---|
| 213 | */ |
|---|
| 214 | public function print_javascript_data(): void { |
|---|
| 215 | echo "<script>\n"; |
|---|
| 216 | echo "window.tp = window.tp || {};\n"; |
|---|
| 217 | |
|---|
| 218 | echo "tp.nonces = {\n"; |
|---|
| 219 | echo "\tedit_table: '" . wp_create_nonce( TablePress::nonce( $this->action, $this->data['table']['id'] ) ) . "',\n"; |
|---|
| 220 | echo "\tpreview_table: '" . wp_create_nonce( TablePress::nonce( 'preview_table', $this->data['table']['id'] ) ) . "',\n"; |
|---|
| 221 | echo "\tcopy_table: '" . wp_create_nonce( TablePress::nonce( 'copy_table', $this->data['table']['id'] ) ) . "',\n"; |
|---|
| 222 | echo "\tdelete_table: '" . wp_create_nonce( TablePress::nonce( 'delete_table', $this->data['table']['id'] ) ) . "',\n"; |
|---|
| 223 | echo "\tscreen_options: '" . wp_create_nonce( TablePress::nonce( 'screen_options' ) ) . "',\n"; |
|---|
| 224 | echo "};\n"; |
|---|
| 225 | |
|---|
| 226 | echo "tp.table = {\n"; |
|---|
| 227 | echo "\tid: '{$this->data['table']['id']}',\n"; |
|---|
| 228 | echo "\tshortcode: '" . esc_js( TablePress::$shortcode ) . "',\n"; |
|---|
| 229 | |
|---|
| 230 | // Add the table meta data. |
|---|
| 231 | $this->data['table']['meta'] = array( |
|---|
| 232 | 'id' => $this->data['table']['id'], |
|---|
| 233 | 'name' => $this->data['table']['name'], |
|---|
| 234 | 'description' => $this->data['table']['description'], |
|---|
| 235 | 'lastModified' => TablePress::format_datetime( $this->data['table']['last_modified'] ), |
|---|
| 236 | 'lastEditor' => TablePress::get_user_display_name( $this->data['table']['options']['last_editor'] ), |
|---|
| 237 | ); |
|---|
| 238 | |
|---|
| 239 | // JSON-encode array items separately to save some PHP memory. |
|---|
| 240 | foreach ( array( 'meta', 'data', 'options', 'visibility' ) as $item ) { |
|---|
| 241 | $json = $this->convert_to_json_parse_output( $this->data['table'][ $item ] ); |
|---|
| 242 | echo "\t{$item}: {$json},\n"; |
|---|
| 243 | } |
|---|
| 244 | echo "};\n"; |
|---|
| 245 | |
|---|
| 246 | echo "tp.screenOptions = {\n"; |
|---|
| 247 | echo "\ttable_editor_column_width: " . absint( TablePress::$model_options->get( 'table_editor_column_width' ) ) . ",\n"; |
|---|
| 248 | echo "\tshowCustomCommands: " . ( current_user_can( 'unfiltered_html' ) ? 'true' : 'false' ) . ",\n"; |
|---|
| 249 | echo "\toptionsUrl: '" . TablePress::url( array( 'action' => 'options' ) ) . "',\n"; |
|---|
| 250 | echo "\tcurrentUserCanEditTableId: " . ( current_user_can( 'tablepress_edit_table_id', $this->data['table']['id'] ) ? 'true' : 'false' ) . ",\n"; |
|---|
| 251 | echo "\tcurrentUserCanCopyTable: " . ( current_user_can( 'tablepress_copy_table', $this->data['table']['id'] ) ? 'true' : 'false' ) . ",\n"; |
|---|
| 252 | echo "\tcurrentUserCanDeleteTable: " . ( current_user_can( 'tablepress_delete_table', $this->data['table']['id'] ) ? 'true' : 'false' ) . ",\n"; |
|---|
| 253 | echo "\tcurrentUserCanExportTable: " . ( current_user_can( 'tablepress_export_table', $this->data['table']['id'] ) ? 'true' : 'false' ) . ",\n"; |
|---|
| 254 | echo "\tcurrentUserCanPreviewTable: " . ( current_user_can( 'tablepress_preview_table', $this->data['table']['id'] ) ? 'true' : 'false' ) . ",\n"; |
|---|
| 255 | echo "\tcopyUrl: '" . str_replace( '&', '&', TablePress::url( array( 'action' => 'copy_table', 'item' => $this->data['table']['id'], 'return' => 'edit' ), true, 'admin-post.php' ) ) . "',\n"; |
|---|
| 256 | echo "\tdeleteUrl: '" . str_replace( '&', '&', TablePress::url( array( 'action' => 'delete_table', 'item' => $this->data['table']['id'], 'return' => 'edit', 'return_item' => $this->data['table']['id'] ), true, 'admin-post.php' ) ) . "',\n"; |
|---|
| 257 | echo "\texportUrl: '" . str_replace( '&', '&', TablePress::url( array( 'action' => 'export', 'table_id' => $this->data['table']['id'] ) ) ) . "',\n"; |
|---|
| 258 | echo "\tpreviewUrl: '" . str_replace( '&', '&', TablePress::url( array( 'action' => 'preview_table', 'item' => $this->data['table']['id'], 'return' => 'edit', 'return_item' => $this->data['table']['id'] ), true, 'admin-post.php' ) ) . "',\n"; |
|---|
| 259 | echo "};\n"; |
|---|
| 260 | |
|---|
| 261 | echo "</script>\n"; |
|---|
| 262 | |
|---|
| 263 | echo '<div id="tablepress-edit-screen"></div>'; // React container. |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | /** |
|---|
| 267 | * Prints the content of the "Table Information" post meta box. |
|---|
| 268 | * |
|---|
| 269 | * @since 1.0.0 |
|---|
| 270 | * |
|---|
| 271 | * @param array<string, mixed> $data Data for this screen. |
|---|
| 272 | * @param array<string, mixed> $box Information about the meta box. |
|---|
| 273 | */ |
|---|
| 274 | public function postbox_table_information( array $data, array $box ): void { |
|---|
| 275 | echo '<div id="tablepress-table-information-section"></div>'; |
|---|
| 276 | |
|---|
| 277 | if ( ! TABLEPRESS_IS_PLAYGROUND_PREVIEW && tb_tp_fs()->is_free_plan() ) : |
|---|
| 278 | ?> |
|---|
| 279 | <div class="postbox premium-features"> |
|---|
| 280 | <div> |
|---|
| 281 | <div> |
|---|
| 282 | <div class="postbox-header"> |
|---|
| 283 | <h2><span class="dashicons dashicons-lightbulb"></span> <?php _e( 'TablePress has more to offer!', 'tablepress' ); ?></h2> |
|---|
| 284 | </div> |
|---|
| 285 | <div class="inside"> |
|---|
| 286 | <?php |
|---|
| 287 | TablePress::init_modules(); |
|---|
| 288 | $random_module_slug = array_rand( TablePress::$modules ); |
|---|
| 289 | $feature_module = TablePress::$modules[ $random_module_slug ]; |
|---|
| 290 | $module_url = esc_url( "https://tablepress.org/modules/{$random_module_slug}/?utm_source=plugin&utm_medium=textlink&utm_content=edit-screen" ); |
|---|
| 291 | |
|---|
| 292 | echo '<strong>' . __( 'Supercharge your tables with exceptional features:', 'tablepress' ) . '</strong>'; |
|---|
| 293 | echo '<h3><a href="' . $module_url . '">' . $feature_module['name'] . '</a></h3>'; |
|---|
| 294 | echo '<span>' . $feature_module['description'] . ' <a href="' . $module_url . '">' . __( 'Read more!', 'tablepress' ) . '</a></span>'; |
|---|
| 295 | ?> |
|---|
| 296 | </div> |
|---|
| 297 | </div> |
|---|
| 298 | <div class="buttons"> |
|---|
| 299 | <a href="https://tablepress.org/premium/?utm_source=plugin&utm_medium=textlink&utm_content=edit-screen" class="tablepress-button"> |
|---|
| 300 | <span><?php _e( 'Compare the TablePress premium versions', 'tablepress' ); ?></span> |
|---|
| 301 | <span class="dashicons dashicons-arrow-right-alt"></span> |
|---|
| 302 | </a> |
|---|
| 303 | </div> |
|---|
| 304 | </div> |
|---|
| 305 | </div> |
|---|
| 306 | <?php |
|---|
| 307 | endif; |
|---|
| 308 | } |
|---|
| 309 | |
|---|
| 310 | /** |
|---|
| 311 | * Prints the content of the "Table Content" post meta box. |
|---|
| 312 | * |
|---|
| 313 | * @since 1.0.0 |
|---|
| 314 | * |
|---|
| 315 | * @param array<string, mixed> $data Data for this screen. |
|---|
| 316 | * @param array<string, mixed> $box Information about the meta box. |
|---|
| 317 | */ |
|---|
| 318 | public function postbox_table_data( array $data, array $box ): void { |
|---|
| 319 | $css_variables = '--table-editor-line-clamp:' . absint( TablePress::$model_options->get( 'table_editor_line_clamp' ) ) . ';'; |
|---|
| 320 | $css_variables = esc_attr( $css_variables ); |
|---|
| 321 | echo "<div id=\"table-editor\" style=\"{$css_variables}\"></div>"; |
|---|
| 322 | } |
|---|
| 323 | |
|---|
| 324 | /** |
|---|
| 325 | * Prints the content of the "Table Manipulation" post meta box. |
|---|
| 326 | * |
|---|
| 327 | * @since 1.0.0 |
|---|
| 328 | * |
|---|
| 329 | * @param array<string, mixed> $data Data for this screen. |
|---|
| 330 | * @param array<string, mixed> $box Information about the meta box. |
|---|
| 331 | */ |
|---|
| 332 | public function postbox_table_manipulation( array $data, array $box ): void { |
|---|
| 333 | echo '<div id="tablepress-table-manipulation-section"></div>'; |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | /** |
|---|
| 337 | * Prints the container for the "Preview" and "Save Changes" buttons. |
|---|
| 338 | * |
|---|
| 339 | * @since 1.0.0 |
|---|
| 340 | * |
|---|
| 341 | * @param array<string, mixed> $data Data for this screen. |
|---|
| 342 | * @param array<string, mixed> $box Information about the text box. |
|---|
| 343 | */ |
|---|
| 344 | public function textbox_buttons( array $data, array $box ): void { |
|---|
| 345 | echo '<div id="tablepress-' . $box['id'] . '-section" class="section-has-react-loading-text">'; |
|---|
| 346 | echo '</div>'; |
|---|
| 347 | } |
|---|
| 348 | |
|---|
| 349 | /** |
|---|
| 350 | * Prints the container for the "Copy Table, "Export Table", and "Delete Table" buttons. |
|---|
| 351 | * |
|---|
| 352 | * @since 1.0.0 |
|---|
| 353 | * |
|---|
| 354 | * @param array<string, mixed> $data Data for this screen. |
|---|
| 355 | * @param array<string, mixed> $box Information about the text box. |
|---|
| 356 | */ |
|---|
| 357 | public function textbox_other_actions( array $data, array $box ): void { |
|---|
| 358 | echo '<div id="tablepress-other-actions-section"></div>'; |
|---|
| 359 | } |
|---|
| 360 | |
|---|
| 361 | /** |
|---|
| 362 | * Prints the hidden containers for the Preview. |
|---|
| 363 | * |
|---|
| 364 | * @since 1.0.0 |
|---|
| 365 | * |
|---|
| 366 | * @param array<string, mixed> $data Data for this screen. |
|---|
| 367 | * @param array<string, mixed> $box Information about the text box. |
|---|
| 368 | */ |
|---|
| 369 | public function textbox_hidden_containers( array $data, array $box ): void { |
|---|
| 370 | ?> |
|---|
| 371 | <div id="tablepress-table-preview-section"></div> |
|---|
| 372 | <div class="hidden-container"> |
|---|
| 373 | <div id="advanced-editor"> |
|---|
| 374 | <label id="advanced-editor-label" for="advanced-editor-content" class="screen-reader-text"><?php esc_html_e( 'Advanced Editor', 'tablepress' ); ?></label> |
|---|
| 375 | <?php |
|---|
| 376 | $wp_editor_options = array( |
|---|
| 377 | 'textarea_rows' => 10, |
|---|
| 378 | 'tinymce' => false, |
|---|
| 379 | 'quicktags' => array( |
|---|
| 380 | 'buttons' => 'strong,em,link,del,ins,img,code,spell,close', |
|---|
| 381 | ), |
|---|
| 382 | ); |
|---|
| 383 | wp_editor( '', 'advanced-editor-content', $wp_editor_options ); |
|---|
| 384 | ?> |
|---|
| 385 | </div> |
|---|
| 386 | <textarea id="textarea-insert-helper" class="hidden"></textarea> |
|---|
| 387 | </div> |
|---|
| 388 | <?php |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | /** |
|---|
| 392 | * Prints the content of the "Table Options" post meta box. |
|---|
| 393 | * |
|---|
| 394 | * @since 1.0.0 |
|---|
| 395 | * |
|---|
| 396 | * @param array<string, mixed> $data Data for this screen. |
|---|
| 397 | * @param array<string, mixed> $box Information about the meta box. |
|---|
| 398 | */ |
|---|
| 399 | public function postbox_table_options( array $data, array $box ): void { |
|---|
| 400 | echo '<div id="tablepress-table-options-section"></div>'; |
|---|
| 401 | } |
|---|
| 402 | |
|---|
| 403 | /** |
|---|
| 404 | * Prints the content of the "Table Features for Site Visitors" post meta box. |
|---|
| 405 | * |
|---|
| 406 | * @since 1.0.0 |
|---|
| 407 | * |
|---|
| 408 | * @param array<string, mixed> $data Data for this screen. |
|---|
| 409 | * @param array<string, mixed> $box Information about the meta box. |
|---|
| 410 | */ |
|---|
| 411 | public function postbox_datatables_features( array $data, array $box ): void { |
|---|
| 412 | echo '<div id="tablepress-datatables-features-section"></div>'; |
|---|
| 413 | } |
|---|
| 414 | |
|---|
| 415 | /** |
|---|
| 416 | * Prints a notification about a corrupted table. |
|---|
| 417 | * |
|---|
| 418 | * @since 1.4.0 |
|---|
| 419 | * |
|---|
| 420 | * @param array<string, mixed> $data Data for this screen. |
|---|
| 421 | * @param array<string, mixed> $box Information about the text box. |
|---|
| 422 | */ |
|---|
| 423 | public function textbox_corrupted_table( array $data, array $box ): void { |
|---|
| 424 | ?> |
|---|
| 425 | <div class="notice components-notice is-error"> |
|---|
| 426 | <div class="components-notice__content"> |
|---|
| 427 | <h3><em> |
|---|
| 428 | <?php _e( 'Attention: Unfortunately, an error occurred.', 'tablepress' ); ?> |
|---|
| 429 | </em></h3> |
|---|
| 430 | <p> |
|---|
| 431 | <?php |
|---|
| 432 | /* translators: %1$s: Table name, %2$s: Table ID */ |
|---|
| 433 | printf( __( 'The internal data of table “%1$s” (ID %2$s) is corrupted.', 'tablepress' ), esc_html( $data['table']['name'] ), esc_html( $data['table']['id'] ) ); |
|---|
| 434 | echo ' '; |
|---|
| 435 | /* translators: %s: Error message */ |
|---|
| 436 | printf( __( 'The following error was registered: %s.', 'tablepress' ), '<code>' . esc_html( $data['table']['json_error'] ) . '</code>' ); |
|---|
| 437 | ?> |
|---|
| 438 | </p> |
|---|
| 439 | <p> |
|---|
| 440 | <?php |
|---|
| 441 | _e( 'Because of this error, the table can not be edited at this time, to prevent possible further data loss.', 'tablepress' ); |
|---|
| 442 | echo ' '; |
|---|
| 443 | /* translators: %s: URL to TablePress FAQ page */ |
|---|
| 444 | printf( __( 'Please see the <a href="%s">TablePress FAQ page</a> for further instructions.', 'tablepress' ), 'https://tablepress.org/faq/corrupted-tables/' ); |
|---|
| 445 | ?> |
|---|
| 446 | </p> |
|---|
| 447 | <p> |
|---|
| 448 | <?php echo '<a href="' . esc_url( TablePress::url( array( 'action' => 'list' ) ) ) . '" class="components-button is-secondary is-compact">' . __( 'Back to the List of Tables', 'tablepress' ) . '</a>'; ?> |
|---|
| 449 | </p> |
|---|
| 450 | </div> |
|---|
| 451 | </div> |
|---|
| 452 | <?php |
|---|
| 453 | } |
|---|
| 454 | |
|---|
| 455 | /** |
|---|
| 456 | * Prints the screen head text. |
|---|
| 457 | * |
|---|
| 458 | * @since 1.0.0 |
|---|
| 459 | * |
|---|
| 460 | * @param array<string, mixed> $data Data for this screen. |
|---|
| 461 | * @param array<string, mixed> $box Information about the text box. |
|---|
| 462 | */ |
|---|
| 463 | public function textbox_head( array $data, array $box ): void { |
|---|
| 464 | echo '<p>'; |
|---|
| 465 | _e( 'To edit the content or modify the structure of this table, use the input fields and buttons below.', 'tablepress' ); |
|---|
| 466 | echo ' '; |
|---|
| 467 | // Show the instructions string depending on whether the Block Editor is used on the site or not. |
|---|
| 468 | if ( 'block' === $data['site_used_editor'] ) { |
|---|
| 469 | printf( __( 'To insert a table into a post or page, add a “%1$s” block in the block editor and select the desired table.', 'tablepress' ), __( 'TablePress table', 'tablepress' ) ); |
|---|
| 470 | } elseif ( 'elementor' === $data['site_used_editor'] ) { |
|---|
| 471 | printf( __( 'To insert a table into a post or page, add a “%1$s” widget in the Elementor editor and select the desired table.', 'tablepress' ), __( 'TablePress table', 'tablepress' ) ); |
|---|
| 472 | } else { |
|---|
| 473 | _e( 'To insert a table into a post or page, paste its Shortcode at the desired place in the editor.', 'tablepress' ); |
|---|
| 474 | } |
|---|
| 475 | echo '</p>'; |
|---|
| 476 | } |
|---|
| 477 | |
|---|
| 478 | /** |
|---|
| 479 | * Sets the content for the WP feature pointer about the drag and drop and sort on the "Edit" screen. |
|---|
| 480 | * |
|---|
| 481 | * @since 2.0.0 |
|---|
| 482 | */ |
|---|
| 483 | public function wp_pointer_tp20_edit_context_menu(): void { |
|---|
| 484 | $content = '<h3>' . __( 'TablePress feature: Context menu', 'tablepress' ) . '</h3>'; |
|---|
| 485 | $content .= '<p>' . __( 'Did you know?', 'tablepress' ) . ' ' . __( 'Right-clicking the table content fields will open a context menu for quick access to common editing tools.', 'tablepress' ) . '</p>'; |
|---|
| 486 | |
|---|
| 487 | $this->admin_page->print_wp_pointer_js( |
|---|
| 488 | 'tp20_edit_context_menu', |
|---|
| 489 | '#table-editor', |
|---|
| 490 | array( |
|---|
| 491 | 'content' => $content, |
|---|
| 492 | 'position' => array( 'edge' => 'bottom', 'align' => 'center' ), |
|---|
| 493 | ), |
|---|
| 494 | ); |
|---|
| 495 | } |
|---|
| 496 | |
|---|
| 497 | /** |
|---|
| 498 | * Sets the content for the WP feature pointer about the screen options for changing the cell size. |
|---|
| 499 | * |
|---|
| 500 | * @since 2.1.0 |
|---|
| 501 | */ |
|---|
| 502 | public function wp_pointer_tp21_edit_screen_options(): void { |
|---|
| 503 | $content = '<h3>' . __( 'TablePress feature: Column width and row height of the table editor', 'tablepress' ) . '</h3>'; |
|---|
| 504 | $content .= '<p>' . __( 'Did you know?', 'tablepress' ) . ' ' . sprintf( __( 'You can change the default cell size for the table editor on this “Edit” screen in the “%s”.', 'tablepress' ), __( 'Screen Options', 'default' ) ) . '</p>'; |
|---|
| 505 | |
|---|
| 506 | $this->admin_page->print_wp_pointer_js( |
|---|
| 507 | 'tp21_edit_screen_options', |
|---|
| 508 | '#screen-options-link-wrap', |
|---|
| 509 | array( |
|---|
| 510 | 'content' => $content, |
|---|
| 511 | 'position' => array( 'edge' => 'top', 'align' => 'right' ), |
|---|
| 512 | 'pointerClass' => 'wp-pointer pointer-tp21_edit_screen_options', |
|---|
| 513 | ), |
|---|
| 514 | ); |
|---|
| 515 | } |
|---|
| 516 | |
|---|
| 517 | } // class TablePress_Edit_View |
|---|