| 1 |
<?php |
| 2 |
/** |
| 3 |
* List Tables View |
| 4 |
* |
| 5 |
* @package TablePress |
| 6 |
* @subpackage Views |
| 7 |
* @author Tobias Bäthge |
| 8 |
* @since 1.0.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
declare(strict_types=1); |
| 12 |
|
| 13 |
// Prohibit direct script loading. |
| 14 |
defined( 'ABSPATH' ) || die( 'No direct script access allowed!' ); |
| 15 |
|
| 16 |
/** |
| 17 |
* List Tables View class |
| 18 |
* |
| 19 |
* @package TablePress |
| 20 |
* @subpackage Views |
| 21 |
* @author Tobias Bäthge |
| 22 |
* @since 1.0.0 |
| 23 |
*/ |
| 24 |
class TablePress_List_View extends TablePress_View { |
| 25 |
|
| 26 |
/** |
| 27 |
* Object for the All Tables List Table. |
| 28 |
* |
| 29 |
* @since 1.0.0 |
| 30 |
*/ |
| 31 |
protected \TablePress_All_Tables_List_Table $wp_list_table; |
| 32 |
|
| 33 |
/** |
| 34 |
* Set up the view with data and do things that are specific for this view. |
| 35 |
* |
| 36 |
* @since 1.0.0 |
| 37 |
* |
| 38 |
* @param string $action Action for this view. |
| 39 |
* @param array<string, mixed> $data Data for this view. |
| 40 |
*/ |
| 41 |
#[\Override] |
| 42 |
public function setup( /* string */ $action, array $data ) /* : void */ { |
| 43 |
// Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited. |
| 44 |
|
| 45 |
parent::setup( $action, $data ); |
| 46 |
|
| 47 |
TablePress::enqueue_script( 'list' ); |
| 48 |
|
| 49 |
$milestone_period_ended = ( strtotime( '2026-10-10' ) < strtotime( 'today' ) ); |
| 50 |
|
| 51 |
if ( $data['messages']['superseded_extensions'] ) { |
| 52 |
$superseded_extensions = array( |
| 53 |
'tablepress-advanced-access-rights/tablepress-advanced-access-rights.php' => array( |
| 54 |
'name' => 'TablePress Extension: Advanced Access Rights', |
| 55 |
'compatible' => true, |
| 56 |
), |
| 57 |
'tablepress-auto-export-tables/tablepress-auto-export-tables.php' => array( |
| 58 |
'name' => 'TablePress Extension: Automatic Table Export', |
| 59 |
'compatible' => true, |
| 60 |
), |
| 61 |
'tablepress-cell-highlighting/tablepress-cell-highlighting.php' => array( |
| 62 |
'name' => 'TablePress Extension: Cell Highlighting', |
| 63 |
'compatible' => true, |
| 64 |
), |
| 65 |
'tablepress-datatables-alphabetsearch/tablepress-datatables-alphabetsearch.php' => array( |
| 66 |
'name' => 'TablePress Extension: DataTables AlphabetSearch', |
| 67 |
'compatible' => false, |
| 68 |
), |
| 69 |
'tablepress-datatables-buttons/tablepress-datatables-buttons.php' => array( |
| 70 |
'name' => 'TablePress Extension: DataTables Buttons', |
| 71 |
'compatible' => true, |
| 72 |
), |
| 73 |
'tablepress-datatables-column-filter-widgets/tablepress-datatables-column-filter-widgets.php' => array( |
| 74 |
'name' => 'TablePress Extension: DataTables ColumnFilterWidgets', |
| 75 |
'compatible' => false, |
| 76 |
), |
| 77 |
'tablepress-datatables-columnfilter/tablepress-datatables-columnfilter.php' => array( |
| 78 |
'name' => 'TablePress Extension: DataTables Column Filter', |
| 79 |
'compatible' => false, |
| 80 |
), |
| 81 |
'tablepress-datatables-counter-column/tablepress-datatables-counter-column.php' => array( |
| 82 |
'name' => 'TablePress Extension: DataTables Counter Column', |
| 83 |
'compatible' => true, |
| 84 |
), |
| 85 |
'tablepress-datatables-fixedcolumns/tablepress-datatables-fixedcolumns.php' => array( |
| 86 |
'name' => 'TablePress Extension: DataTables FixedColumns', |
| 87 |
'compatible' => false, |
| 88 |
), |
| 89 |
'tablepress-datatables-fixedheader/tablepress-datatables-fixedheader.php' => array( |
| 90 |
'name' => 'TablePress Extension: DataTables FixedHeader', |
| 91 |
'compatible' => true, |
| 92 |
), |
| 93 |
'tablepress-datatables-inverted-filter/tablepress-datatables-inverted-filter.php' => array( |
| 94 |
'name' => 'TablePress Extension: DataTables Inverted Filter', |
| 95 |
'compatible' => false, |
| 96 |
), |
| 97 |
'tablepress-datatables-row-details/tablepress-datatables-row-details.php' => array( |
| 98 |
'name' => 'TablePress Extension: DataTables Row Details', |
| 99 |
'compatible' => false, |
| 100 |
), |
| 101 |
'tablepress-datatables-rowgroup/tablepress-datatables-rowgroup.php' => array( |
| 102 |
'name' => 'TablePress Extension: DataTables RowGroup', |
| 103 |
'compatible' => false, |
| 104 |
), |
| 105 |
'tablepress-responsive-tables/tablepress-responsive-tables.php' => array( |
| 106 |
'name' => 'TablePress Extension: Responsive Tables', |
| 107 |
'compatible' => false, |
| 108 |
), |
| 109 |
'tablepress-row-filter/tablepress-row-filter.php' => array( |
| 110 |
'name' => 'TablePress Extension: Row Filtering', |
| 111 |
'compatible' => true, |
| 112 |
), |
| 113 |
'tablepress-row-highlighting/tablepress-row-highlighting.php' => array( |
| 114 |
'name' => 'TablePress Extension: Row Highlighting', |
| 115 |
'compatible' => true, |
| 116 |
), |
| 117 |
'tablepress-table-auto-update/tablepress-table-auto-update.php' => array( |
| 118 |
'name' => 'TablePress Extension: Table Auto Update', |
| 119 |
'compatible' => true, |
| 120 |
), |
| 121 |
'tablepress-table-column-order/tablepress-table-column-order.php' => array( |
| 122 |
'name' => 'TablePress Extension: Table Column Order', |
| 123 |
'compatible' => true, |
| 124 |
), |
| 125 |
); |
| 126 |
|
| 127 |
$active_compatible_superseded_extensions = array(); |
| 128 |
$active_incompatible_superseded_extensions = array(); |
| 129 |
foreach ( $superseded_extensions as $plugin => $extension ) { |
| 130 |
if ( is_plugin_active( $plugin ) ) { |
| 131 |
if ( $extension['compatible'] ) { |
| 132 |
$active_compatible_superseded_extensions[] = $extension['name']; |
| 133 |
} else { |
| 134 |
$active_incompatible_superseded_extensions[] = $extension['name']; |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
/* |
| 140 |
* If no superseded extensions are used, hide the message, to prevent running the checks on every load of the view. |
| 141 |
* This leaves a small risk of an Extension being activated later, but that's acceptable as they are no longer publicly available. |
| 142 |
*/ |
| 143 |
if ( empty( $active_incompatible_superseded_extensions ) && ( empty( $active_compatible_superseded_extensions ) || ! tb_tp_fs()->is_free_plan() ) ) { |
| 144 |
TablePress::$model_options->update( 'message_superseded_extensions', false ); |
| 145 |
} |
| 146 |
|
| 147 |
$message = ''; |
| 148 |
|
| 149 |
$notice_css_classes = 'not-dismissible'; |
| 150 |
|
| 151 |
if ( ! empty( $active_incompatible_superseded_extensions ) ) { |
| 152 |
$notice_css_classes .= ' is-error notice-error'; |
| 153 |
|
| 154 |
$message .= '<p style="font-size:16px;">' . __( 'You are using <strong>TablePress Extension plugins</strong> on this website that have been retired many years ago.', 'tablepress' ) . '<br>' . __( 'For technical reasons, some or all features of these outdated plugins <strong>do no longer work</strong>:', 'tablepress' ) . '</p>'; |
| 155 |
$message .= '<ul style="list-style:disc;margin:0.5em 1em;font-size:16px;">'; |
| 156 |
foreach ( $active_incompatible_superseded_extensions as $extension ) { |
| 157 |
$message .= '<li>' . esc_html( $extension ) . '</li>'; |
| 158 |
} |
| 159 |
$message .= '</ul>'; |
| 160 |
$message .= '<p style="font-size:16px;"><strong>' . __( 'Keeping them activated can lead to errors on your website.', 'tablepress' ) . '</strong></p>'; |
| 161 |
|
| 162 |
if ( tb_tp_fs()->is_free_plan() ) { |
| 163 |
$message .= '<p style="font-size:16px;"><strong>' . sprintf( __( 'To continue using these features, <a href="%s">upgrade to a TablePress Premium license plan</a>!', 'tablepress' ), 'https://tablepress.org/upgrade-extensions/?utm_source=plugin&utm_medium=textlink&utm_content=superseded-extensions-message' ) . '</strong><br>' |
| 164 |
. __( 'TablePress Pro and TablePress Max come with updated and heavily improved versions of these features and include direct priority email support.', 'tablepress' ) . '</p>'; |
| 165 |
} |
| 166 |
|
| 167 |
if ( ! empty( $active_compatible_superseded_extensions ) && tb_tp_fs()->is_free_plan() ) { |
| 168 |
$message .= '<p style="margin-top:1em;font-size:14px;">' . __( 'In addition, these TablePress Extension plugins have been retired and might become incompatible in the future as well:', 'tablepress' ) . '</strong></p>'; |
| 169 |
$message .= '<ul style="list-style:disc;margin:0.5em 1em;font-size:14px;">'; |
| 170 |
foreach ( $active_compatible_superseded_extensions as $extension ) { |
| 171 |
$message .= '<li>' . esc_html( $extension ) . '</li>'; |
| 172 |
} |
| 173 |
$message .= '</ul>'; |
| 174 |
} |
| 175 |
} elseif ( ! empty( $active_compatible_superseded_extensions ) && tb_tp_fs()->is_free_plan() ) { |
| 176 |
$notice_css_classes .= ' is-warning notice-warning'; |
| 177 |
|
| 178 |
$message .= '<p style="font-size:14px;"><strong>' . __( 'You are using TablePress Extension plugins on this website that have been retired and will no longer receive updates or support:', 'tablepress' ) . '</strong></p>'; |
| 179 |
$message .= '<ul style="list-style:disc;margin:0.5em 1em;">'; |
| 180 |
foreach ( $active_compatible_superseded_extensions as $extension ) { |
| 181 |
$message .= '<li>' . esc_html( $extension ) . '</li>'; |
| 182 |
} |
| 183 |
$message .= '</ul>'; |
| 184 |
$message .= '<p style="font-size:14px;"><strong>' . __( 'It is possible that these become incompatible with TablePress or WordPress in the future!', 'tablepress' ) . '</strong></p>'; |
| 185 |
$message .= '<p style="margin-top:1em;font-size:14px;">' . sprintf( __( 'However, their features were heavily improved and are now part of the up-to-date <a href="%s">TablePress Premium versions</a>!', 'tablepress' ), 'https://tablepress.org/upgrade-extensions/?utm_source=plugin&utm_medium=textlink&utm_content=superseded-extensions-message' ) . '</p>'; |
| 186 |
} |
| 187 |
|
| 188 |
if ( '' !== $message ) { |
| 189 |
if ( tb_tp_fs()->is_free_plan() ) { |
| 190 |
$message .= '<p style="font-size:16px;margin-top:1.5em;"><strong>' . __( 'Upgrade to a TablePress Premium license plan now and get:', 'tablepress' ) . '</strong></p>'; |
| 191 |
$message .= '<ul style="list-style:disc;margin:0.5em 1em;font-size:16px;">'; |
| 192 |
$message .= '<li>' . __( 'Updated and heavily improved versions of these features!', 'tablepress' ) . '</li>'; |
| 193 |
$message .= '<li>' . __( 'Direct integration into the user interface!', 'tablepress' ) . '</li>'; |
| 194 |
$message .= '<li>' . __( 'Regular updates that ensure compatibility with WordPress!', 'tablepress' ) . '</li>'; |
| 195 |
$message .= '<li>' . __( 'Priority email support!', 'tablepress' ) . '</li>'; |
| 196 |
$message .= '</ul>'; |
| 197 |
$message .= '<p style="font-size:16px;"><strong>' . sprintf( __( 'And the best: %s', 'tablepress' ), sprintf( __( 'Use the promo code %1$s during the checkout process for a special offer!', 'tablepress' ), '<code>UPGRADE</code>' ) ) . '</strong></p>'; |
| 198 |
$message .= '<p style="margin-top:2em;">' . sprintf( '<a href="%s" class="components-button is-primary" style="font-size:14px;margin-right:3em;background:linear-gradient(135deg,#00d184 0%%,#0791e3 100%%);border:none;font-weight:bold;">%s<span class="dashicons dashicons-arrow-right-alt" style="vertical-align:middle;margin:0 0 4px 4px"></span></a>', 'https://tablepress.org/upgrade-extensions/?utm_source=plugin&utm_medium=button&utm_content=superseded-extensions-message', __( 'Upgrade to a TablePress Premium version now!', 'tablepress' ) ); |
| 199 |
} |
| 200 |
$message .= $this->ajax_link( array( 'action' => 'hide_message', 'item' => 'superseded_extensions', 'return' => 'list' ), __( 'Hide this message', 'tablepress' ) ) . '</p>'; |
| 201 |
|
| 202 |
$title = '<em>' . __( 'Important Notice!', 'tablepress' ) . '</em>'; |
| 203 |
|
| 204 |
$this->add_header_message( $message, $notice_css_classes, $title ); |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
if ( $data['messages']['first_visit'] && ( ! $data['messages']['plugin_update'] || $milestone_period_ended ) ) { |
| 209 |
$message = '<p style="font-size:14px;"><strong>' . __( 'Thank you for choosing TablePress, the most popular table plugin for WordPress!', 'tablepress' ) . '</strong></p>'; |
| 210 |
/* translators: %1$s: URL to FAQ, %2$s: URL to Documentation, %3$s: URL to Support, %4$s: URL to plugin website */ |
| 211 |
$message .= '<p>' . sprintf( __( 'If you encounter any questions or problems, please visit the <a href="%1$s">FAQ</a>, the <a href="%2$s">Documentation</a>, and the <a href="%3$s">Support</a> section on the <a href="%4$s">plugin website</a>.', 'tablepress' ), 'https://tablepress.org/faq/', 'https://tablepress.org/documentation/', 'https://tablepress.org/support/', 'https://tablepress.org/' ) . '</p>'; |
| 212 |
|
| 213 |
if ( tb_tp_fs()->is_free_plan() ) { |
| 214 |
$message .= '<p style="font-size:14px;"><strong>' . sprintf( __( 'More great features for you and your site’s visitors and priority email support are available with a Premium license plan of TablePress. <a href="%s">Go check them out!</a>', 'tablepress' ), 'https://tablepress.org/premium/?utm_source=plugin&utm_medium=textlink&utm_content=first-visit-message' ) . '</strong></p>'; |
| 215 |
} |
| 216 |
|
| 217 |
$message .= '<p style="margin-top:1em;">' . $this->ajax_link( array( 'action' => 'hide_message', 'item' => 'first_visit', 'return' => 'list' ), __( 'Hide this message', 'tablepress' ) ) . '</p>'; |
| 218 |
|
| 219 |
$title = '<em>' . __( 'Welcome!', 'tablepress' ) . '</em>'; |
| 220 |
|
| 221 |
$this->add_header_message( $message, 'notice-info not-dismissible', $title ); |
| 222 |
} |
| 223 |
|
| 224 |
if ( $data['messages']['donation_nag'] && ( ! $data['messages']['plugin_update'] || $milestone_period_ended ) ) { |
| 225 |
$message = '<p style="font-size:14px;"><img alt="' . esc_attr__( 'Tobias Bäthge, developer of TablePress', 'tablepress' ) . '" src="https://secure.gravatar.com/avatar/50f1cff2e27a1f522b18ce229c057bc5?s=250" height="125" width="125" style="float:left;margin:2px 15px 30px 0;border-radius:5px;">' |
| 226 |
. __( 'Hi, my name is Tobias, I’m the developer of the TablePress plugin.', 'tablepress' ) . '</p>'; |
| 227 |
$message .= '<p style="font-size:14px;">' . __( 'Thank you for using it!', 'tablepress' ) . ' '; |
| 228 |
if ( $data['table_count'] > 0 ) { |
| 229 |
/* translators: %s: Number of tables */ |
| 230 |
$message .= sprintf( _n( 'I hope that everything works and that you are satisfied with the results of managing your %s table.', 'I hope that everything works and that you are satisfied with the results of managing your %s tables.', $data['table_count'], 'tablepress' ), $data['table_count'] ); |
| 231 |
} else { |
| 232 |
/* translators: %s: URL to TablePress website */ |
| 233 |
$message .= sprintf( __( 'It looks like you haven’t added a table yet. If you need help to get started, please find more information in the FAQ and Documentation on the <a href="%s">TablePress website</a>.', 'tablepress' ), 'https://tablepress.org/' ); |
| 234 |
} |
| 235 |
$message .= '</p>'; |
| 236 |
$message .= '<p style="font-size:14px;"><strong>' . sprintf( __( 'I would like to invite you to check out the <a href="%s">Premium versions of TablePress</a>.', 'tablepress' ), 'https://tablepress.org/premium/?utm_source=plugin&utm_medium=textlink&utm_content=upgrade-message' ) . '<br>' |
| 237 |
. __( 'The available Pro and Max plans offer user support and many exciting and helpful features for your tables.', 'tablepress' ) . '</strong></p>'; |
| 238 |
$message .= '<p style="font-size:14px;">' . __( 'Sincerely, Tobias', 'tablepress' ) . '</p>'; |
| 239 |
$message .= '<p style="margin-top:1em;">' . sprintf( '<a href="%s" class="components-button is-primary" style="font-size:14px;margin-right:3em;color:#ffffff;">%s<span class="dashicons dashicons-arrow-right-alt" style="margin-inline:8px 0"></span></a>', 'https://tablepress.org/premium/?utm_source=plugin&utm_medium=button&utm_content=upgrade-message', __( 'Tell me more about the Premium features', 'tablepress' ) ) |
| 240 |
. $this->ajax_link( array( 'action' => 'hide_message', 'item' => 'donation_nag', 'return' => 'list' ), __( 'Hide this message', 'tablepress' ) ) . '</p>'; |
| 241 |
|
| 242 |
$title = '<em>' . __( 'TablePress has more to offer!', 'tablepress' ) . '</em>'; |
| 243 |
|
| 244 |
$this->add_header_message( $message, 'notice-success not-dismissible', $title ); |
| 245 |
} |
| 246 |
|
| 247 |
if ( $data['messages']['plugin_update'] ) { |
| 248 |
if ( $milestone_period_ended ) { |
| 249 |
$message = '<p>' . sprintf( __( 'To find out more about what’s new, please read the <a href="%s"><strong>release announcement</strong></a>.', 'tablepress' ), 'https://tablepress.org/news/?utm_source=plugin&utm_medium=textlink&utm_content=plugin-update-message' ) . '</p>'; |
| 250 |
|
| 251 |
if ( tb_tp_fs()->is_free_plan() ) { |
| 252 |
$message .= '<p><strong>' . sprintf( __( 'More great features and priority email support are available with a Premium license plan. <a href="%s">Check them out!</a>', 'tablepress' ), 'https://tablepress.org/premium/?utm_source=plugin&utm_medium=textlink&utm_content=plugin-update-message' ) . '</strong></p>'; |
| 253 |
} |
| 254 |
|
| 255 |
$title = '<em>' . sprintf( __( 'Thank you for updating to TablePress %s!', 'tablepress' ), TablePress::version ) . '</em>'; |
| 256 |
$class = 'notice-info not-dismissible'; |
| 257 |
} else { |
| 258 |
$texts_german = in_array( get_user_locale(), array( 'de_DE', 'de_AT', 'de_CH' ), true ); |
| 259 |
if ( $texts_german ) { |
| 260 |
$message = '<p style="font-size:16px;">Wir feiern <strong>25 Millionen Downloads</strong> von TablePress aus dem WordPress-Pluginverzeichnis!<br>Mach mit und <strong>spare 25 %</strong> beim Upgrade auf TablePress Pro oder TablePress Max!</p>'; |
| 261 |
} else { |
| 262 |
$message = '<p style="font-size:16px;">We’re celebrating <strong>25 million downloads</strong> of TablePress from the WordPress Plugin Directory!<br>Join us and <strong>get 25% off</strong> your TablePress Pro or TablePress Max upgrade!</p>'; |
| 263 |
} |
| 264 |
$url = 'https://tablepress.org/premium/?utm_source=plugin&utm_medium=notice&utm_campaign=upgrade-message340&utm_content=button'; |
| 265 |
$message .= '<p style="margin-top:1em;margin-bottom:24px;">' . sprintf( '<a href="%s" class="components-button is-primary" target="_blank"><span>%s</span><span class="dashicons dashicons-arrow-right-alt" style="margin-inline:8px 0"></span></a>', $url, $texts_german ? 'Spare jetzt 25 %' : 'Get 25% off now' ) . '</p>'; |
| 266 |
|
| 267 |
$filename = $texts_german ? 'admin/img/dl-25-period.svg' : 'admin/img/dl-25-comma.svg'; |
| 268 |
$message .= sprintf( '<img src="%1$s" alt="%2$s">', plugins_url( $filename, TABLEPRESS__FILE__ ), $texts_german ? 'Grafik mit einer Tabelle mit „Downloads“ in der Kopfzeile und der Zahl 25.000.000 im Tabellenkörper' : 'Graphic with a table with “Downloads” in the header and the number 25,000,000 in the body' ); |
| 269 |
|
| 270 |
$title = ''; |
| 271 |
$class = 'notice-milestone not-dismissible'; |
| 272 |
} |
| 273 |
|
| 274 |
$message .= '<p style="margin-top:1em;">' . $this->ajax_link( array( 'action' => 'hide_message', 'item' => 'plugin_update', 'return' => 'list' ), __( 'Hide this message', 'tablepress' ) ) . '</p>'; |
| 275 |
|
| 276 |
$this->add_header_message( $message, $class, $title ); |
| 277 |
} |
| 278 |
|
| 279 |
$this->process_action_messages( array( |
| 280 |
'success_delete' => _n( 'The table was deleted successfully.', 'The tables were deleted successfully.', 1, 'tablepress' ), |
| 281 |
'success_delete_plural' => _n( 'The table was deleted successfully.', 'The tables were deleted successfully.', 2, 'tablepress' ), |
| 282 |
'error_delete' => __( 'Error: The table could not be deleted.', 'tablepress' ), |
| 283 |
'success_copy' => _n( 'The table was copied successfully.', 'The tables were copied successfully.', 1, 'tablepress' ) |
| 284 |
. ( ( false !== $data['table_id'] ) |
| 285 |
? ' ' . ( current_user_can( 'tablepress_edit_table', $data['table_id'] ) |
| 286 |
? sprintf( __( 'You can now <a href="%1$s">edit the copied table</a>, which has the table ID “%2$s”.', 'tablepress' ), esc_url( TablePress::url( array( 'action' => 'edit', 'table_id' => $data['table_id'] ) ) ), esc_html( $data['table_id'] ) ) |
| 287 |
: sprintf( __( 'The copied table has the table ID “%s”.', 'tablepress' ), esc_html( $data['table_id'] ) ) ) |
| 288 |
: '' |
| 289 |
), |
| 290 |
'success_copy_plural' => _n( 'The table was copied successfully.', 'The tables were copied successfully.', 2, 'tablepress' ), |
| 291 |
'error_copy' => __( 'Error: The table could not be copied.', 'tablepress' ), |
| 292 |
'error_no_table' => __( 'Error: You did not specify a valid table ID.', 'tablepress' ), |
| 293 |
'error_load_table' => __( 'Error: This table could not be loaded!', 'tablepress' ), |
| 294 |
'error_bulk_action_invalid' => __( 'Error: This bulk action is invalid!', 'tablepress' ), |
| 295 |
'error_no_selection' => __( 'Error: You did not select any tables!', 'tablepress' ), |
| 296 |
'error_delete_not_all_tables' => __( 'Notice: Not all selected tables could be deleted!', 'tablepress' ), |
| 297 |
'error_copy_not_all_tables' => __( 'Notice: Not all selected tables could be copied!', 'tablepress' ), |
| 298 |
'success_import' => __( 'The tables were imported successfully.', 'tablepress' ), |
| 299 |
) ); |
| 300 |
|
| 301 |
$this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' ); |
| 302 |
$this->add_text_box( 'tables-list', array( $this, 'textbox_tables_list' ), 'normal' ); |
| 303 |
|
| 304 |
add_screen_option( 'per_page', array( 'label' => __( 'Tables', 'tablepress' ), 'default' => 20 ) ); // Admin_Controller contains function to allow changes to this in the Screen Options to be saved. |
| 305 |
$this->wp_list_table = TablePress::load_class( 'TablePress_All_Tables_List_Table', 'class-all-tables-list-table.php', 'views' ); |
| 306 |
$this->wp_list_table->set_items( $this->data['table_ids'] ); |
| 307 |
$this->wp_list_table->prepare_items(); |
| 308 |
|
| 309 |
// Cleanup Request URI string, which WP_List_Table uses to generate the sort URLs. |
| 310 |
$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'message', 'table_id' ), $_SERVER['REQUEST_URI'] ); |
| 311 |
} |
| 312 |
|
| 313 |
/** |
| 314 |
* Render the current view (in this view: without form tag). |
| 315 |
* |
| 316 |
* @since 1.0.0 |
| 317 |
*/ |
| 318 |
#[\Override] |
| 319 |
public function render(): void { |
| 320 |
?> |
| 321 |
<div id="tablepress-page" class="wrap"> |
| 322 |
<?php |
| 323 |
$this->print_nav_tab_menu(); |
| 324 |
?> |
| 325 |
<div id="tablepress-body"> |
| 326 |
<hr class="wp-header-end"> |
| 327 |
<script>document.querySelectorAll('.notice:has(~#tablepress-page)').forEach(e=>document.querySelector('.wp-header-end').after(e));</script> |
| 328 |
<?php |
| 329 |
// Print all header messages. |
| 330 |
foreach ( $this->header_messages as $message ) { |
| 331 |
echo $message; |
| 332 |
} |
| 333 |
|
| 334 |
// For this screen, this is done in textbox_tables_list(), to get the fields into the correct <form>: |
| 335 |
// $this->do_text_boxes( 'header' );. |
| 336 |
?> |
| 337 |
<div id="poststuff"> |
| 338 |
<div id="post-body" class="metabox-holder columns-<?php echo ( isset( $GLOBALS['screen_layout_columns'] ) && ( 2 === $GLOBALS['screen_layout_columns'] ) ) ? '2' : '1'; ?>"> |
| 339 |
<div id="postbox-container-2" class="postbox-container"> |
| 340 |
<?php |
| 341 |
$this->do_text_boxes( 'normal' ); |
| 342 |
$this->do_meta_boxes( 'normal' ); |
| 343 |
|
| 344 |
$this->do_text_boxes( 'additional' ); |
| 345 |
$this->do_meta_boxes( 'additional' ); |
| 346 |
|
| 347 |
// Print all submit buttons. |
| 348 |
$this->do_text_boxes( 'submit' ); |
| 349 |
?> |
| 350 |
</div> |
| 351 |
<div id="postbox-container-1" class="postbox-container"> |
| 352 |
<?php |
| 353 |
// Print all boxes in the sidebar. |
| 354 |
$this->do_text_boxes( 'side' ); |
| 355 |
$this->do_meta_boxes( 'side' ); |
| 356 |
?> |
| 357 |
</div> |
| 358 |
</div> |
| 359 |
<br class="clear"> |
| 360 |
</div> |
| 361 |
</div> |
| 362 |
</div> |
| 363 |
<?php |
| 364 |
} |
| 365 |
|
| 366 |
/** |
| 367 |
* Print the screen head text. |
| 368 |
* |
| 369 |
* @since 1.0.0 |
| 370 |
* |
| 371 |
* @param array<string, mixed> $data Data for this screen. |
| 372 |
* @param array<string, mixed> $box Information about the text box. |
| 373 |
*/ |
| 374 |
public function textbox_head( array $data, array $box ): void { |
| 375 |
echo '<p>'; |
| 376 |
_e( 'This is a list of your tables.', 'tablepress' ); |
| 377 |
echo ' '; |
| 378 |
// Show the instructions string depending on whether the Block Editor is used on the site or not. |
| 379 |
if ( 'block' === $data['site_used_editor'] ) { |
| 380 |
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' ) ); |
| 381 |
} elseif ( 'elementor' === $data['site_used_editor'] ) { |
| 382 |
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' ) ); |
| 383 |
} else { |
| 384 |
_e( 'To insert a table into a post or page, paste its Shortcode at the desired place in the editor.', 'tablepress' ); |
| 385 |
echo ' '; |
| 386 |
_e( 'Each table has a unique ID that needs to be adjusted in that Shortcode.', 'tablepress' ); |
| 387 |
} |
| 388 |
echo '</p>'; |
| 389 |
} |
| 390 |
|
| 391 |
/** |
| 392 |
* Print the content of the "All Tables" text 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 text box. |
| 398 |
*/ |
| 399 |
public function textbox_tables_list( array $data, array $box ): void { |
| 400 |
if ( ! empty( $_GET['s'] ) ) { |
| 401 |
printf( '<span class="subtitle">' . __( 'Search results for “%s”', 'tablepress' ) . '</span>', esc_html( wp_unslash( $_GET['s'] ) ) ); |
| 402 |
} |
| 403 |
?> |
| 404 |
<form method="get"> |
| 405 |
<?php |
| 406 |
if ( isset( $_GET['page'] ) ) { |
| 407 |
echo '<input type="hidden" name="page" value="' . esc_attr( $_GET['page'] ) . '">' . "\n"; |
| 408 |
} |
| 409 |
$this->wp_list_table->search_box( __( 'Search Tables', 'tablepress' ), 'tables_search' ); |
| 410 |
?> |
| 411 |
</form> |
| 412 |
<form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post"> |
| 413 |
<?php |
| 414 |
// This prints the nonce and action fields for this screen (done here instead of render(), due to moved <form>). |
| 415 |
$this->do_text_boxes( 'header' ); |
| 416 |
$this->wp_list_table->display(); |
| 417 |
?> |
| 418 |
</form> |
| 419 |
<div id="tablepress-list-screen"></div> |
| 420 |
<?php |
| 421 |
} |
| 422 |
|
| 423 |
/** |
| 424 |
* Create HTML code for an AJAXified link. |
| 425 |
* |
| 426 |
* @since 1.0.0 |
| 427 |
* |
| 428 |
* @param array<string, mixed> $params Parameters for the URL. |
| 429 |
* @param string $text Text for the link. |
| 430 |
* @return string HTML code for the link. |
| 431 |
*/ |
| 432 |
protected function ajax_link( array $params, string $text ): string { |
| 433 |
$class = 'ajax-link'; |
| 434 |
if ( ! empty( $params['class'] ) ) { |
| 435 |
$class .= ' ' . esc_attr( $params['class'] ); |
| 436 |
} |
| 437 |
$url = TablePress::url( $params, true, 'admin-post.php' ); |
| 438 |
$action = esc_attr( $params['action'] ); |
| 439 |
$item = esc_attr( $params['item'] ); |
| 440 |
$target = esc_attr( $params['target'] ?? '' ); |
| 441 |
return "<a class=\"{$class}\" href=\"{$url}\" data-action=\"{$action}\" data-item=\"{$item}\" data-target=\"{$target}\">{$text}</a>"; |
| 442 |
} |
| 443 |
|
| 444 |
} // class TablePress_List_View |
| 445 |
|