| 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', 'tp33_edit_quick_navigation' ); |
| 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 |
TablePress::enqueue_script( 'common', array( 'jquery-core', 'postbox' ) ); |
| 47 |
|
| 48 |
$this->add_text_box( 'no-javascript', array( $this, 'textbox_no_javascript' ), 'header' ); |
| 49 |
|
| 50 |
if ( isset( $data['table']['is_corrupted'] ) && $data['table']['is_corrupted'] ) { |
| 51 |
$this->add_text_box( 'table-corrupted', array( $this, 'textbox_corrupted_table' ), 'header' ); |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
$this->process_action_messages( array( |
| 56 |
'success_add' => __( 'The table was added successfully.', 'tablepress' ), |
| 57 |
'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'] ) ), |
| 58 |
'success_import' => __( 'The table was imported successfully.', 'tablepress' ), |
| 59 |
'error_delete' => __( 'Error: The table could not be deleted.', 'tablepress' ), |
| 60 |
) ); |
| 61 |
|
| 62 |
// For the Advanced Editor. |
| 63 |
wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
| 64 |
wp_enqueue_style( 'editor-buttons' ); |
| 65 |
wp_enqueue_script( 'wpdialogs' ); |
| 66 |
// For the "Insert Image" dialog. |
| 67 |
add_filter( 'media_view_strings', array( $this, 'change_media_view_strings' ) ); |
| 68 |
wp_enqueue_media(); |
| 69 |
// For the "Insert Link" dialog. |
| 70 |
wp_enqueue_script( 'wplink' ); |
| 71 |
|
| 72 |
TablePress::enqueue_style( 'jspreadsheet' ); |
| 73 |
TablePress::enqueue_style( 'jsuites', array( 'tablepress-jspreadsheet' ) ); |
| 74 |
TablePress::enqueue_style( 'edit', array( 'tablepress-jspreadsheet', 'tablepress-jsuites' ) ); |
| 75 |
if ( ! TABLEPRESS_IS_PLAYGROUND_PREVIEW && tb_tp_fs()->is_free_plan() ) { |
| 76 |
TablePress::enqueue_style( 'edit-features', array( 'tablepress-edit' ) ); |
| 77 |
} |
| 78 |
TablePress::enqueue_script( 'jspreadsheet' ); |
| 79 |
TablePress::enqueue_script( 'jsuites', array( 'tablepress-jspreadsheet' ) ); |
| 80 |
TablePress::enqueue_script( 'edit', array( 'tablepress-jspreadsheet', 'tablepress-jsuites', 'jquery-core' ) ); |
| 81 |
|
| 82 |
$this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' ); |
| 83 |
$this->add_text_box( 'header-bar', array( $this, 'textbox_header_bar' ), 'normal' ); |
| 84 |
$this->add_meta_box( 'table-information', __( 'Table Information', 'tablepress' ), array( $this, 'postbox_table_information' ), 'normal' ); |
| 85 |
$this->add_meta_box( 'table-data', __( 'Table Content', 'tablepress' ), array( $this, 'postbox_table_data' ), 'normal' ); |
| 86 |
$this->add_meta_box( 'table-manipulation', __( 'Table Manipulation', 'tablepress' ), array( $this, 'postbox_table_manipulation' ), 'normal' ); |
| 87 |
$this->add_meta_box( 'table-options', __( 'Table Options', 'tablepress' ), array( $this, 'postbox_table_options' ), 'normal' ); |
| 88 |
$this->add_meta_box( 'datatables-features', __( 'Table Features for Site Visitors', 'tablepress' ), array( $this, 'postbox_datatables_features' ), 'normal' ); |
| 89 |
$this->add_text_box( 'hidden-containers', array( $this, 'textbox_hidden_containers' ), 'additional' ); |
| 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::load_modules_data(); |
| 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 sticky "Header Bar". |
| 338 |
* |
| 339 |
* @since 3.3.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_header_bar( array $data, array $box ): void { |
| 345 |
echo '<div id="tablepress-header-bar-section" class="section-has-react-loading-text">'; |
| 346 |
if ( tb_tp_fs()->is_plan_or_trial__premium_only( 'pro' ) ) { |
| 347 |
echo '<div class="react-loading-text" style="line-height:36px;font-weight:bold">'; |
| 348 |
printf( |
| 349 |
__( 'The page is being loaded. If this text does not disappear soon, <a href="%1$s">click here to reload the page.</a>', 'tablepress' ), |
| 350 |
esc_url( TablePress::url( array( 'action' => 'edit', 'table_id' => $data['table']['id'], 'refresh_table_options' => 'true' ) ) ), |
| 351 |
); |
| 352 |
echo '</div>'; |
| 353 |
} |
| 354 |
echo '</div>'; |
| 355 |
} |
| 356 |
|
| 357 |
/** |
| 358 |
* Prints the hidden containers for the Preview. |
| 359 |
* |
| 360 |
* @since 1.0.0 |
| 361 |
* |
| 362 |
* @param array<string, mixed> $data Data for this screen. |
| 363 |
* @param array<string, mixed> $box Information about the text box. |
| 364 |
*/ |
| 365 |
public function textbox_hidden_containers( array $data, array $box ): void { |
| 366 |
?> |
| 367 |
<div id="tablepress-table-preview-section"></div> |
| 368 |
<div class="hidden-container"> |
| 369 |
<div id="advanced-editor"> |
| 370 |
<label id="advanced-editor-label" for="advanced-editor-content" class="screen-reader-text"><?php esc_html_e( 'Advanced Editor', 'tablepress' ); ?></label> |
| 371 |
<?php |
| 372 |
$wp_editor_options = array( |
| 373 |
'textarea_rows' => 10, |
| 374 |
'tinymce' => false, |
| 375 |
'quicktags' => array( |
| 376 |
'buttons' => 'strong,em,link,del,ins,img,code,spell,close', |
| 377 |
), |
| 378 |
); |
| 379 |
wp_editor( '', 'advanced-editor-content', $wp_editor_options ); |
| 380 |
?> |
| 381 |
</div> |
| 382 |
<textarea id="textarea-insert-helper" class="hidden"></textarea> |
| 383 |
</div> |
| 384 |
<?php |
| 385 |
} |
| 386 |
|
| 387 |
/** |
| 388 |
* Prints the content of the "Table Options" post meta box. |
| 389 |
* |
| 390 |
* @since 1.0.0 |
| 391 |
* |
| 392 |
* @param array<string, mixed> $data Data for this screen. |
| 393 |
* @param array<string, mixed> $box Information about the meta box. |
| 394 |
*/ |
| 395 |
public function postbox_table_options( array $data, array $box ): void { |
| 396 |
echo '<div id="tablepress-table-options-section"></div>'; |
| 397 |
} |
| 398 |
|
| 399 |
/** |
| 400 |
* Prints the content of the "Table Features for Site Visitors" post meta box. |
| 401 |
* |
| 402 |
* @since 1.0.0 |
| 403 |
* |
| 404 |
* @param array<string, mixed> $data Data for this screen. |
| 405 |
* @param array<string, mixed> $box Information about the meta box. |
| 406 |
*/ |
| 407 |
public function postbox_datatables_features( array $data, array $box ): void { |
| 408 |
echo '<div id="tablepress-datatables-features-section"></div>'; |
| 409 |
} |
| 410 |
|
| 411 |
/** |
| 412 |
* Prints a notification about a corrupted table. |
| 413 |
* |
| 414 |
* @since 1.4.0 |
| 415 |
* |
| 416 |
* @param array<string, mixed> $data Data for this screen. |
| 417 |
* @param array<string, mixed> $box Information about the text box. |
| 418 |
*/ |
| 419 |
public function textbox_corrupted_table( array $data, array $box ): void { |
| 420 |
?> |
| 421 |
<div class="notice components-notice is-error"> |
| 422 |
<div class="components-notice__content"> |
| 423 |
<h3><em> |
| 424 |
<?php _e( 'Attention: Unfortunately, an error occurred.', 'tablepress' ); ?> |
| 425 |
</em></h3> |
| 426 |
<p> |
| 427 |
<?php |
| 428 |
/* translators: %1$s: Table name, %2$s: Table ID */ |
| 429 |
printf( __( 'The internal data of table “%1$s” (ID %2$s) is corrupted.', 'tablepress' ), esc_html( $data['table']['name'] ), esc_html( $data['table']['id'] ) ); |
| 430 |
echo ' '; |
| 431 |
/* translators: %s: Error message */ |
| 432 |
printf( __( 'The following error was registered: %s.', 'tablepress' ), '<code>' . esc_html( $data['table']['json_error'] ) . '</code>' ); |
| 433 |
?> |
| 434 |
</p> |
| 435 |
<p> |
| 436 |
<?php |
| 437 |
_e( 'Because of this error, the table can not be edited at this time, to prevent possible further data loss.', 'tablepress' ); |
| 438 |
echo ' '; |
| 439 |
/* translators: %s: URL to TablePress FAQ page */ |
| 440 |
printf( __( 'Please see the <a href="%s">TablePress FAQ page</a> for further instructions.', 'tablepress' ), 'https://tablepress.org/faq/corrupted-tables/' ); |
| 441 |
?> |
| 442 |
</p> |
| 443 |
<p> |
| 444 |
<?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>'; ?> |
| 445 |
</p> |
| 446 |
</div> |
| 447 |
</div> |
| 448 |
<?php |
| 449 |
} |
| 450 |
|
| 451 |
/** |
| 452 |
* Prints the screen head text. |
| 453 |
* |
| 454 |
* @since 1.0.0 |
| 455 |
* |
| 456 |
* @param array<string, mixed> $data Data for this screen. |
| 457 |
* @param array<string, mixed> $box Information about the text box. |
| 458 |
*/ |
| 459 |
public function textbox_head( array $data, array $box ): void { |
| 460 |
echo '<p>'; |
| 461 |
_e( 'To edit the content or modify the structure of this table, use the input fields and buttons below.', 'tablepress' ); |
| 462 |
echo ' '; |
| 463 |
// Show the instructions string depending on whether the Block Editor is used on the site or not. |
| 464 |
if ( 'block' === $data['site_used_editor'] ) { |
| 465 |
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' ) ); |
| 466 |
} elseif ( 'elementor' === $data['site_used_editor'] ) { |
| 467 |
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' ) ); |
| 468 |
} else { |
| 469 |
_e( 'To insert a table into a post or page, paste its Shortcode at the desired place in the editor.', 'tablepress' ); |
| 470 |
} |
| 471 |
echo '</p>'; |
| 472 |
} |
| 473 |
|
| 474 |
/** |
| 475 |
* Sets the content for the WP feature pointer about the drag and drop and sort on the "Edit" screen. |
| 476 |
* |
| 477 |
* @since 2.0.0 |
| 478 |
*/ |
| 479 |
public function wp_pointer_tp20_edit_context_menu(): void { |
| 480 |
$content = '<h3>' . __( 'TablePress feature: Context menu', 'tablepress' ) . '</h3>'; |
| 481 |
$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>'; |
| 482 |
|
| 483 |
$this->print_wp_pointer_js( |
| 484 |
'tp20_edit_context_menu', |
| 485 |
'#table-editor', |
| 486 |
array( |
| 487 |
'content' => $content, |
| 488 |
'position' => array( 'edge' => 'bottom', 'align' => 'center' ), |
| 489 |
), |
| 490 |
); |
| 491 |
} |
| 492 |
|
| 493 |
/** |
| 494 |
* Sets the content for the WP feature pointer about the Quick Navigation on the "Edit" screen. |
| 495 |
* |
| 496 |
* @since 3.3.0 |
| 497 |
*/ |
| 498 |
public function wp_pointer_tp33_edit_quick_navigation(): void { |
| 499 |
$content = '<h3>' . __( 'TablePress feature: Quick Navigation', 'tablepress' ) . '</h3>'; |
| 500 |
$content .= '<p style="text-wrap:balance">' . __( 'You can quickly navigate between different sections of the table editor using the Quick Navigation menu.', 'tablepress' ) . ' ' . __( 'Just click the logo or use the <kbd>%metaKey%J</kbd> keyboard shortcut!', 'tablepress' ) . '</p>'; |
| 501 |
|
| 502 |
$this->print_wp_pointer_js( |
| 503 |
'tp33_edit_quick_navigation', |
| 504 |
'#tablepress-header-bar-section', |
| 505 |
array( |
| 506 |
'content' => $content, |
| 507 |
'position' => array( 'edge' => 'top', 'align' => is_rtl() ? 'right+16' : 'left-16' ), |
| 508 |
'pointerWidth' => 330, |
| 509 |
), |
| 510 |
); |
| 511 |
} |
| 512 |
|
| 513 |
} // class TablePress_Edit_View |
| 514 |
|