PluginProbe
TablePress – Tables in WordPress made easy / 3.0
TablePress – Tables in WordPress made easy v3.0
3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 2.4.4 All 44 releases
← All changes | classes/class-render.php +352 -292 1.143.0 View file →
@@ -12,8 +12,9 @@
12 12 defined( 'ABSPATH' ) || die( 'No direct script access allowed!' );
13 13
14 14 /**
15 15 * TablePress Rendering Class
16 + *
16 17 * @package TablePress
17 18 * @subpackage Rendering
18 19 * @author Tobias Bäthge
19 20 * @since 1.0.0
@@ -23,25 +24,25 @@
23 24 /**
24 25 * Table data that is rendered.
25 26 *
26 27 * @since 1.0.0
27 - * @var array
28 + * @var array<string, mixed>
28 29 */
29 - protected $table = array();
30 + protected array $table = array();
30 31
31 32 /**
32 33 * Table options that influence the output result.
33 34 *
34 35 * @since 1.0.0
35 - * @var array
36 + * @var array<string, mixed>
36 37 */
37 - protected $render_options = array();
38 + protected array $render_options = array();
38 39
39 40 /**
40 - * Rendered HTML of the table.
41 + * Rendered HTML code of the table or PHP array.
41 42 *
42 43 * @since 1.0.0
43 - * @var string
44 + * @var string|array<int, array<int, string>>
44 45 */
45 46 protected $output;
46 47
47 48 /**
@@ -47,11 +48,11 @@
47 48 /**
48 49 * Trigger words for colspan, rowspan, or the combination of both.
49 50 *
50 51 * @since 1.0.0
51 - * @var array
52 + * @var array<string, string>
52 53 */
53 - protected $span_trigger = array(
54 + protected array $span_trigger = array(
54 55 'colspan' => '#colspan#',
55 56 'rowspan' => '#rowspan#',
56 57 'span' => '#span#',
57 58 );
@@ -59,35 +60,40 @@
59 60 /**
60 61 * Buffer to store the counts of rowspan per column, initialized in _render_table().
61 62 *
62 63 * @since 1.0.0
63 - * @var array
64 + * @var int[]
64 65 */
65 - protected $rowspan = array();
66 + protected array $rowspan = array();
66 67
67 68 /**
68 69 * Buffer to store the counts of colspan per row, initialized in _render_table().
69 70 *
70 71 * @since 1.0.0
71 - * @var array
72 + * @var int[]
72 73 */
73 - protected $colspan = array();
74 + protected array $colspan = array();
74 75
75 76 /**
77 + * Whether the table has connected cells (colspan or rowspan), set in _render_table().
78 + *
79 + * @since 3.0.0
80 + */
81 + protected bool $tbody_has_connected_cells = false;
82 +
83 + /**
76 84 * Index of the last row of the visible data in the table, set in _render_table().
77 85 *
78 86 * @since 1.0.0
79 - * @var int
80 87 */
81 - protected $last_row_idx;
88 + protected int $last_row_idx;
82 89
83 90 /**
84 91 * Index of the last column of the visible data in the table, set in _render_table().
85 92 *
86 93 * @since 1.0.0
87 - * @var int
88 94 */
89 - protected $last_column_idx;
95 + protected int $last_column_idx;
90 96
91 97 /**
92 98 * Class constructor.
93 99 *
@@ -101,21 +107,21 @@
101 107 * Set the table (data, options, visibility, ...) that is to be rendered.
102 108 *
103 109 * @since 1.0.0
104 110 *
105 - * @param array $table Table to be rendered.
106 - * @param array $render_options Options for rendering, from both "Edit" screen and Shortcode.
111 + * @param array<string, mixed> $table Table to be rendered.
112 + * @param array<string, mixed> $render_options Options for rendering, from both "Edit" screen and Shortcode.
107 113 */
108 - public function set_input( array $table, array $render_options ) {
114 + public function set_input( array $table, array $render_options ): void {
109 115 $this->table = $table;
110 116 $this->render_options = $render_options;
111 117 /**
112 - * Filter the table before the render process.
118 + * Filters the table before the render process.
113 119 *
114 120 * @since 1.0.0
115 121 *
116 - * @param array $table The table.
117 - * @param array $render_options The render options for the table.
122 + * @param array<string, mixed> $table The table.
123 + * @param array<string, mixed> $render_options The render options for the table.
118 124 */
119 125 $this->table = apply_filters( 'tablepress_table_raw_render_data', $this->table, $this->render_options );
120 126 }
121 127
@@ -122,18 +128,39 @@
122 128 /**
123 129 * Process the table rendering and return the HTML output.
124 130 *
125 131 * @since 1.0.0
132 + * @since 2.0.0 Add the $format parameter.
126 133 *
127 - * @return string HTML of the rendered table (or an error message).
134 + * @param string $format Optional. Output format, 'html' (default) or 'array'.
135 + * @return string|array<int, array<int, string>> HTML code of the rendered table, or a PHP array, or an error message.
128 136 */
129 - public function get_output() {
137 + public function get_output( string $format = 'html' ) /* : string|array */ {
130 138 // Evaluate math expressions/formulas.
131 139 $this->_evaluate_table_data();
132 140 // Remove hidden rows and columns.
133 141 $this->_prepare_render_data();
134 - // Generate HTML output.
135 - $this->_render_table();
142 +
143 + if ( 'html' !== $format ) {
144 + add_filter( 'tablepress_cell_content', 'wptexturize' );
145 + }
146 +
147 + // Evaluate Shortcodes and escape cell content.
148 + $this->_process_render_data();
149 +
150 + if ( 'html' !== $format ) {
151 + remove_filter( 'tablepress_cell_content', 'wptexturize' );
152 + }
153 +
154 + switch ( $format ) {
155 + case 'html':
156 + $this->_render_table();
157 + break;
158 + case 'array':
159 + $this->output = $this->table['data'];
160 + break;
161 + }
162 +
136 163 return $this->output;
137 164 }
138 165
139 166 /**
@@ -140,21 +167,24 @@
140 167 * Loop through the table to evaluate math expressions/formulas.
141 168 *
142 169 * @since 1.0.0
143 170 */
144 - protected function _evaluate_table_data() {
171 + protected function _evaluate_table_data(): void {
145 172 $orig_table = $this->table;
146 173
147 - $formula_evaluator = TablePress::load_class( 'TablePress_Evaluate', 'class-evaluate.php', 'classes' );
148 - $this->table['data'] = $formula_evaluator->evaluate_table_data( $this->table['data'], $this->table['id'] );
174 + if ( $this->render_options['evaluate_formulas'] ) {
175 + $formula_evaluator = TablePress::load_class( 'TablePress_Evaluate', 'class-evaluate.php', 'classes' );
176 + $this->table['data'] = $formula_evaluator->evaluate_table_data( $this->table['data'], $this->table['id'] );
177 + }
178 +
149 179 /**
150 - * Filter the table after evaluating formulas in the table.
180 + * Filters the table after evaluating formulas in the table.
151 181 *
152 182 * @since 1.0.0
153 183 *
154 - * @param array $table The table with evaluated formulas.
155 - * @param array $orig_table The table with unevaluated formulas.
156 - * @param array $render_options The render options for the table.
184 + * @param array<string, mixed> $table The table with evaluated formulas.
185 + * @param array<string, mixed> $orig_table The table with unevaluated formulas.
186 + * @param array<string, mixed> $render_options The render options for the table.
157 187 */
158 188 $this->table = apply_filters( 'tablepress_table_evaluate_data', $this->table, $orig_table, $this->render_options );
159 189 }
160 190
@@ -162,9 +192,9 @@
162 192 * Remove all cells from the data set that shall not be rendered, because they are hidden.
163 193 *
164 194 * @since 1.0.0
165 195 */
166 - protected function _prepare_render_data() {
196 + protected function _prepare_render_data(): void {
167 197 $orig_table = $this->table;
168 198
169 199 $num_rows = count( $this->table['data'] );
170 200 $num_columns = ( $num_rows > 0 ) ? count( $this->table['data'][0] ) : 0;
@@ -192,13 +222,13 @@
192 222 foreach ( $this->render_options[ "{$action}_{$element}" ] as $key => $value ) {
193 223 $range_dash = strpos( $value, '-' );
194 224 if ( false !== $range_dash ) {
195 225 unset( $this->render_options[ "{$action}_{$element}" ][ $key ] );
196 - $start = substr( $value, 0, $range_dash );
226 + $start = trim( substr( $value, 0, $range_dash ) );
197 227 if ( ! is_numeric( $start ) ) {
198 228 $start = TablePress::letter_to_number( $start );
199 229 }
200 - $end = substr( $value, $range_dash + 1 );
230 + $end = trim( substr( $value, $range_dash + 1 ) );
201 231 if ( ! is_numeric( $end ) ) {
202 232 $end = TablePress::letter_to_number( $end );
203 233 }
204 234 $current_range = range( $start, $end );
@@ -205,13 +235,15 @@
205 235 $range_cells = array_merge( $range_cells, $current_range );
206 236 }
207 237 }
208 238 $this->render_options[ "{$action}_{$element}" ] = array_merge( $this->render_options[ "{$action}_{$element}" ], $range_cells );
239 +
209 240 /*
210 241 * Parse single letters and change from regular numbering to zero-based numbering,
211 - * as rows/columns are indexed from 0 internally, but from 1 externally
242 + * as rows/columns are indexed from 0 internally, but from 1 externally.
212 243 */
213 244 foreach ( $this->render_options[ "{$action}_{$element}" ] as $key => $value ) {
245 + $value = trim( $value );
214 246 if ( ! is_numeric( $value ) ) {
215 247 $value = TablePress::letter_to_number( $value );
216 248 }
217 249 $this->render_options[ "{$action}_{$element}" ][ $key ] = (int) $value - 1;
@@ -246,25 +278,80 @@
246 278 $this->table['data'][ $row_idx ] = array_merge( $row );
247 279 }
248 280
249 281 /**
250 - * Filter the table after processing the table visibility information.
282 + * Filters the table after processing the table visibility information.
251 283 *
252 284 * @since 1.0.0
253 285 *
254 - * @param array $table The processed table.
255 - * @param array $orig_table The unprocessed table.
256 - * @param array $render_options The render options for the table.
286 + * @param array<string, mixed> $table The processed table.
287 + * @param array<string, mixed> $orig_table The unprocessed table.
288 + * @param array<string, mixed> $render_options The render options for the table.
257 289 */
258 290 $this->table = apply_filters( 'tablepress_table_render_data', $this->table, $orig_table, $this->render_options );
259 291 }
260 292
261 293 /**
294 + * Generate the data that is to be rendered.
295 + *
296 + * @since 2.0.0
297 + */
298 + protected function _process_render_data(): void {
299 + $orig_table = $this->table;
300 +
301 + // Deactivate nl2br() for this render process, if "convert_line_breaks" Shortcode parameter is set to false.
302 + if ( ! $this->render_options['convert_line_breaks'] ) {
303 + add_filter( 'tablepress_apply_nl2br', '__return_false', 9 ); // Priority 9, so that this filter can easily be overwritten at the default priority.
304 + }
305 +
306 + foreach ( $this->table['data'] as $row_idx => $row ) {
307 + foreach ( $row as $col_idx => $cell_content ) {
308 + // Print formulas that are escaped with '= (like in Excel) as text.
309 + if ( str_starts_with( $cell_content, "'=" ) ) {
310 + $cell_content = substr( $cell_content, 1 );
311 + }
312 + $cell_content = $this->safe_output( $cell_content );
313 + if ( str_contains( $cell_content, '[' ) ) {
314 + $cell_content = do_shortcode( $cell_content );
315 + }
316 + /**
317 + * Filters the content of a single cell, after formulas have been evaluated, the output has been sanitized, and Shortcodes have been evaluated.
318 + *
319 + * @since 1.0.0
320 + *
321 + * @param string $cell_content The cell content.
322 + * @param string $table_id The current table ID.
323 + * @param int $row_idx The row number of the cell.
324 + * @param int $col_idx The column number of the cell.
325 + */
326 + $cell_content = apply_filters( 'tablepress_cell_content', $cell_content, $this->table['id'], $row_idx + 1, $col_idx + 1 );
327 + $this->table['data'][ $row_idx ][ $col_idx ] = $cell_content;
328 + }
329 + }
330 +
331 + // Re-instate nl2br() behavior after this render process, if "convert_line_breaks" Shortcode parameter is set to false.
332 + if ( ! $this->render_options['convert_line_breaks'] ) {
333 + remove_filter( 'tablepress_apply_nl2br', '__return_false', 9 ); // Priority 9, so that this filter can easily be overwritten at the default priority.
334 + }
335 +
336 + /**
337 + * Filters the table after processing the table content handling.
338 + *
339 + * @since 2.0.0
340 + *
341 + * @param array<string, mixed> $table The processed table.
342 + * @param array<string, mixed> $orig_table The unprocessed table.
343 + * @param array<string, mixed> $render_options The render options for the table.
344 + */
345 + $this->table = apply_filters( 'tablepress_table_content_render_data', $this->table, $orig_table, $this->render_options );
346 + }
347 +
348 + /**
262 349 * Generate the HTML output of the table.
263 350 *
264 351 * @since 1.0.0
265 352 */
266 - protected function _render_table() {
353 + protected function _render_table(): void {
267 354 $num_rows = count( $this->table['data'] );
268 355 $num_columns = ( $num_rows > 0 ) ? count( $this->table['data'][0] ) : 0;
269 356
270 357 // Check if there are rows and columns in the table (might not be the case after removing hidden rows/columns!).
@@ -277,14 +364,14 @@
277 364 $this->rowspan = array_fill( 0, $num_columns, 1 );
278 365 $this->colspan = array_fill( 0, $num_rows, 1 );
279 366
280 367 /**
281 - * Filter the trigger keywords for "colspan" and "rowspan"
368 + * Filters the trigger keywords for "colspan" and "rowspan"
282 369 *
283 370 * @since 1.0.0
284 371 *
285 - * @param array $span_trigger The trigger keywords for combining table cells.
286 - * @param string $table_id The current table ID.
372 + * @param array<string, string> $span_trigger The trigger keywords for combining table cells.
373 + * @param string $table_id The current table ID.
287 374 */
288 375 $this->span_trigger = apply_filters( 'tablepress_span_trigger_keywords', $this->span_trigger, $this->table['id'] );
289 376
290 377 // Explode from string to array.
@@ -295,9 +382,9 @@
295 382 $output = '';
296 383
297 384 if ( $this->render_options['print_name'] ) {
298 385 /**
299 - * Filter the HTML tag that wraps the printed table name.
386 + * Filters the HTML tag that wraps the printed table name.
300 387 *
301 388 * @since 1.0.0
302 389 *
303 390 * @param string $tag The HTML tag around the table name. Default h2.
@@ -309,9 +396,9 @@
309 396 if ( ! empty( $this->render_options['html_id'] ) ) {
310 397 $name_attributes['id'] = "{$this->render_options['html_id']}-name";
311 398 }
312 399 /**
313 - * Filter the class attribute for the printed table name.
400 + * Filters the class attribute for the printed table name.
314 401 *
315 402 * @since 1.0.0
316 403 * @deprecated 1.13.0 Use {@see 'tablepress_table_name_tag_attributes'} instead.
317 404 *
@@ -319,15 +406,15 @@
319 406 * @param string $table_id The current table ID.
320 407 */
321 408 $name_attributes['class'] = apply_filters_deprecated( 'tablepress_print_name_css_class', array( "tablepress-table-name tablepress-table-name-id-{$this->table['id']}", $this->table['id'] ), 'TablePress 1.13.0', 'tablepress_table_name_tag_attributes' );
322 409 /**
323 - * Filter the attributes for the table name (HTML h2 element, by default).
410 + * Filters the attributes for the table name (HTML h2 element, by default).
324 411 *
325 412 * @since 1.13.0
326 413 *
327 - * @param array $name_attributes The attributes for the table name element.
328 - * @param array $table The current table.
329 - * @param array $render_options The render options for the table.
414 + * @param array<string, string> $name_attributes The attributes for the table name element.
415 + * @param array<string, mixed> $table The current table.
416 + * @param array<string, mixed> $render_options The render options for the table.
330 417 */
331 418 $name_attributes = apply_filters( 'tablepress_table_name_tag_attributes', $name_attributes, $this->table, $this->render_options );
332 419 $name_attributes = $this->_attributes_array_to_string( $name_attributes );
333 420
@@ -334,9 +421,9 @@
334 421 $print_name_html = "<{$name_html_tag}{$name_attributes}>" . $this->safe_output( $this->table['name'] ) . "</{$name_html_tag}>\n";
335 422 }
336 423 if ( $this->render_options['print_description'] ) {
337 424 /**
338 - * Filter the HTML tag that wraps the printed table description.
425 + * Filters the HTML tag that wraps the printed table description.
339 426 *
340 427 * @since 1.0.0
341 428 *
342 429 * @param string $tag The HTML tag around the table description. Default span.
@@ -348,9 +435,9 @@
348 435 if ( ! empty( $this->render_options['html_id'] ) ) {
349 436 $description_attributes['id'] = "{$this->render_options['html_id']}-description";
350 437 }
351 438 /**
352 - * Filter the class attribute for the printed table description.
439 + * Filters the class attribute for the printed table description.
353 440 *
354 441 * @since 1.0.0
355 442 * @deprecated 1.13.0 Use {@see 'tablepress_table_description_tag_attributes'} instead.
356 443 *
@@ -358,15 +445,15 @@
358 445 * @param string $table_id The current table ID.
359 446 */
360 447 $description_attributes['class'] = apply_filters_deprecated( 'tablepress_print_description_css_class', array( "tablepress-table-description tablepress-table-description-id-{$this->table['id']}", $this->table['id'] ), 'TablePress 1.13.0', 'tablepress_table_description_tag_attributes' );
361 448 /**
362 - * Filter the attributes for the table description (HTML span element, by default).
449 + * Filters the attributes for the table description (HTML span element, by default).
363 450 *
364 451 * @since 1.13.0
365 452 *
366 - * @param array $description_attributes The attributes for the table description element.
367 - * @param array $table The current table.
368 - * @param array $render_options The render options for the table.
453 + * @param array<string, string> $description_attributes The attributes for the table description element.
454 + * @param array<string, mixed> $table The current table.
455 + * @param array<string, mixed> $render_options The render options for the table.
369 456 */
370 457 $description_attributes = apply_filters( 'tablepress_table_description_tag_attributes', $description_attributes, $this->table, $this->render_options );
371 458 $description_attributes = $this->_attributes_array_to_string( $description_attributes );
372 459
@@ -379,50 +466,56 @@
379 466 if ( $this->render_options['print_description'] && 'above' === $this->render_options['print_description_position'] ) {
380 467 $output .= $print_description_html;
381 468 }
382 469
383 - // Deactivate nl2br() for this render process, if "convert_line_breaks" Shortcode parameter is set to false.
384 - if ( ! $this->render_options['convert_line_breaks'] ) {
385 - add_filter( 'tablepress_apply_nl2br', '__return_false', 9 ); // Priority 9, so that this filter can easily be overwritten at the default priority.
386 - }
387 -
388 - $thead = '';
389 - $tfoot = '';
470 + $thead = array();
471 + $tfoot = array();
390 472 $tbody = array();
391 473
392 474 $this->last_row_idx = $num_rows - 1;
393 475 $this->last_column_idx = $num_columns - 1;
476 +
394 477 // Loop through rows in reversed order, to search for rowspan trigger keyword.
395 - for ( $row_idx = $this->last_row_idx; $row_idx >= 0; $row_idx-- ) {
396 - // Last row, need to check for footer (but only if at least two rows).
397 - if ( $this->last_row_idx === $row_idx && $this->render_options['table_foot'] && $num_rows > 1 ) {
398 - $tfoot = $this->_render_row( $row_idx, 'th' );
399 - continue;
478 + $row_idx = $this->last_row_idx;
479 +
480 + // Render the table footer rows, if there is at least one extra row.
481 + if ( $this->render_options['table_foot'] > 0 && $num_rows >= $this->render_options['table_head'] + $this->render_options['table_foot'] ) { // @phpstan-ignore greaterOrEqual.invalid (`table_head` and `table_foot` are integers.)
482 + $last_tbody_idx = $this->last_row_idx - $this->render_options['table_foot'];
483 + while ( $row_idx > $last_tbody_idx ) {
484 + $tfoot[] = $this->_render_row( $row_idx, 'th' );
485 + --$row_idx;
400 486 }
401 - // First row, need to check for head (but only if at least two rows).
402 - if ( 0 === $row_idx && $this->render_options['table_head'] && $num_rows > 1 ) {
403 - $thead = $this->_render_row( $row_idx, 'th' );
404 - continue;
405 - }
406 - // Neither first nor last row (with respective head/foot enabled), so render as body row.
487 + // Reverse rows because we looped through the rows in reverse order.
488 + $tfoot = array_reverse( $tfoot );
489 + }
490 +
491 + // Render the table body rows.
492 + $last_thead_idx = $this->render_options['table_head'] - 1;
493 + while ( $row_idx > $last_thead_idx ) {
407 494 $tbody[] = $this->_render_row( $row_idx, 'td' );
495 + --$row_idx;
408 496 }
497 + // Reverse rows because we looped through the rows in reverse order.
498 + $tbody = array_reverse( $tbody );
409 499
410 - // Re-instate nl2br() behavior after this render process, if "convert_line_breaks" Shortcode parameter is set to false.
411 - if ( ! $this->render_options['convert_line_breaks'] ) {
412 - remove_filter( 'tablepress_apply_nl2br', '__return_false', 9 ); // Priority 9, so that this filter can easily be overwritten at the default priority.
500 + // Render the table header rows, if rows are left.
501 + while ( $row_idx > -1 ) {
502 + $thead[] = $this->_render_row( $row_idx, 'th' );
503 + --$row_idx;
413 504 }
505 + // Reverse rows because we looped through the rows in reverse order.
506 + $thead = array_reverse( $thead );
414 507
415 508 // <caption> tag.
416 509 /**
417 - * Filter the content for the HTML caption element of the table.
510 + * Filters the content for the HTML caption element of the table.
418 511 *
419 512 * If the "Edit" link for a table is shown, it is also added to the caption element.
420 513 *
421 514 * @since 1.0.0
422 515 *
423 - * @param string $caption The content for the HTML caption element of the table. Default empty.
424 - * @param array $table The current table.
516 + * @param string $caption The content for the HTML caption element of the table. Default empty.
517 + * @param array<string, mixed> $table The current table.
425 518 */
426 519 $caption = apply_filters( 'tablepress_print_caption_text', '', $this->table );
427 520 $caption_style = '';
428 521 $caption_class = '';
@@ -427,9 +520,9 @@
427 520 $caption_style = '';
428 521 $caption_class = '';
429 522 if ( ! empty( $caption ) ) {
430 523 /**
431 - * Filter the class attribute for the HTML caption element of the table.
524 + * Filters the class attribute for the HTML caption element of the table.
432 525 *
433 526 * @since 1.0.0
434 527 *
435 528 * @param string $class The class attribute for the HTML caption element of the table.
@@ -452,9 +545,9 @@
452 545
453 546 // <colgroup> tag.
454 547 $colgroup = '';
455 548 /**
456 - * Filter whether the HTML colgroup tag shall be added to the table output.
549 + * Filters whether the HTML colgroup tag shall be added to the table output.
457 550 *
458 551 * @since 1.0.0
459 552 *
460 553 * @param bool $print Whether the colgroup element shall be printed.
@@ -463,9 +556,9 @@
463 556 if ( apply_filters( 'tablepress_print_colgroup_tag', false, $this->table['id'] ) ) {
464 557 for ( $col_idx = 0; $col_idx < $num_columns; $col_idx++ ) {
465 558 $attributes = ' class="colgroup-column-' . ( $col_idx + 1 ) . ' "';
466 559 /**
467 - * Filter the attributes of the HTML col tags in the HTML colgroup tag.
560 + * Filters the attributes of the HTML col tags in the HTML colgroup tag.
468 561 *
469 562 * @since 1.0.0
470 563 *
471 564 * @param string $attributes The attributes in the col element.
@@ -472,9 +565,9 @@
472 565 * @param string $table_id The current table ID.
473 566 * @param int $col_idx The number of the column.
474 567 */
475 568 $attributes = apply_filters( 'tablepress_colgroup_tag_attributes', $attributes, $this->table['id'], $col_idx + 1 );
476 - $colgroup .= "\t<col{$attributes}/>\n";
569 + $colgroup .= "\t<col{$attributes} />\n";
477 570 }
478 571 }
479 572 if ( ! empty( $colgroup ) ) {
480 573 $colgroup = "<colgroup>\n{$colgroup}</colgroup>\n";
@@ -479,18 +572,36 @@
479 572 if ( ! empty( $colgroup ) ) {
480 573 $colgroup = "<colgroup>\n{$colgroup}</colgroup>\n";
481 574 }
482 575
483 - // <thead>, <tfoot>, and <tbody> tags.
576 + /*
577 + * <thead>, <tfoot>, and <tbody> tags.
578 + */
579 +
484 580 if ( ! empty( $thead ) ) {
485 - $thead = "<thead>\n{$thead}</thead>\n";
581 + $thead = "<thead>\n" . implode( '', $thead ) . "</thead>\n";
582 + } else {
583 + $thead = '';
486 584 }
585 +
487 586 if ( ! empty( $tfoot ) ) {
488 - $tfoot = "<tfoot>\n{$tfoot}</tfoot>\n";
587 + $tfoot = "<tfoot>\n" . implode( '', $tfoot ) . "</tfoot>\n";
588 + } else {
589 + $tfoot = '';
489 590 }
490 - $tbody_class = ( $this->render_options['row_hover'] ) ? ' class="row-hover"' : '';
491 - // Reverse rows because we looped through the rows in reverse order.
492 - $tbody = array_reverse( $tbody );
591 +
592 + $tbody_classes = array();
593 + if ( $this->render_options['alternating_row_colors'] ) {
594 + $tbody_classes[] = 'row-striping';
595 + }
596 + if ( $this->render_options['row_hover'] ) {
597 + $tbody_classes[] = 'row-hover';
598 + }
599 + $tbody_class = implode( ' ', $tbody_classes );
600 + if ( '' !== $tbody_class ) {
601 + $tbody_class = ' class="' . esc_attr( $tbody_class ) . '"';
602 + }
603 +
493 604 $tbody = "<tbody{$tbody_class}>\n" . implode( '', $tbody ) . "</tbody>\n";
494 605
495 606 // Attributes for the table (HTML table element).
496 607 $table_attributes = array();
@@ -500,16 +611,23 @@
500 611 $table_attributes['id'] = $this->render_options['html_id'];
501 612 }
502 613
503 614 // "class" attribute.
504 - $css_classes = array( 'tablepress', "tablepress-id-{$this->table['id']}", $this->render_options['extra_css_classes'] );
615 + $css_classes = array(
616 + 'tablepress',
617 + "tablepress-id-{$this->table['id']}",
618 + $this->render_options['extra_css_classes'],
619 + );
620 + if ( $this->tbody_has_connected_cells ) {
621 + $css_classes[] = 'tbody-has-connected-cells';
622 + }
505 623 /**
506 - * Filter the CSS classes that are given to the HTML table element.
624 + * Filters the CSS classes that are given to the HTML table element.
507 625 *
508 626 * @since 1.0.0
509 627 *
510 - * @param array $css_classes The CSS classes for the table element.
511 - * @param string $table_id The current table ID.
628 + * @param string[] $css_classes The CSS classes for the table element.
629 + * @param string $table_id The current table ID.
512 630 */
513 631 $css_classes = apply_filters( 'tablepress_table_css_classes', $css_classes, $this->table['id'] );
514 632 // $css_classes might contain several classes in one array entry.
515 633 $css_classes = explode( ' ', implode( ' ', $css_classes ) );
@@ -530,16 +648,16 @@
530 648
531 649 // "summary" attribute.
532 650 $summary = '';
533 651 /**
534 - * Filter the content for the summary attribute of the HTML table element.
652 + * Filters the content for the summary attribute of the HTML table element.
535 653 *
536 654 * The attribute is only added if it is not empty.
537 655 *
538 656 * @since 1.0.0
539 657 *
540 - * @param string $summary The content for the summary attribute of the table. Default empty.
541 - * @param array $table The current table.
658 + * @param string $summary The content for the summary attribute of the table. Default empty.
659 + * @param array<string, mixed> $table The current table.
542 660 */
543 661 $summary = apply_filters( 'tablepress_print_summary_attr', $summary, $this->table );
544 662 if ( ! empty( $summary ) ) {
545 663 $table_attributes['summary'] = esc_attr( $summary );
@@ -552,39 +670,53 @@
552 670 }
553 671 }
554 672
555 673 /**
556 - * Filter the attributes for the table (HTML table element).
674 + * Filters the attributes for the table (HTML table element).
557 675 *
558 676 * @since 1.4.0
559 677 *
560 - * @param array $table_attributes The attributes for the table element.
561 - * @param array $table The current table.
562 - * @param array $render_options The render options for the table.
678 + * @param array<string, string> $table_attributes The attributes for the table element.
679 + * @param array<string, mixed> $table The current table.
680 + * @param array<string, mixed> $render_options The render options for the table.
563 681 */
564 682 $table_attributes = apply_filters( 'tablepress_table_tag_attributes', $table_attributes, $this->table, $this->render_options );
565 683 $table_attributes = $this->_attributes_array_to_string( $table_attributes );
566 684
567 - $output .= "\n<table{$table_attributes}>\n";
568 - $output .= $caption . $colgroup . $thead . $tbody . $tfoot;
569 - $output .= "</table>\n";
685 + $table_html = "<table{$table_attributes}>\n";
686 + $table_html .= $caption . $colgroup . $thead . $tbody . $tfoot;
687 + $table_html .= '</table>';
570 688
689 + /**
690 + * Filters the generated HTML code for the table, without HTML elements around it.
691 + *
692 + * @since 2.4.0
693 + *
694 + * @param string $output The generated HTML for the table, without HTML elements around it.
695 + * @param array<string, mixed> $table The current table.
696 + * @param array<string, mixed> $render_options The render options for the table, without HTML elements around it.
697 + */
698 + $table_html = apply_filters( 'tablepress_table_html', $table_html, $this->table, $this->render_options );
699 +
700 + $output .= "\n{$table_html}\n";
701 + unset( $table_html ); // Unset the potentially large variable to free up memory.
702 +
571 703 // name/description below table (HTML already generated above).
572 704 if ( $this->render_options['print_name'] && 'below' === $this->render_options['print_name_position'] ) {
573 - $output .= $print_name_html;
705 + $output .= $print_name_html; // @phpstan-ignore variable.undefined (The variable is set above.)
574 706 }
575 707 if ( $this->render_options['print_description'] && 'below' === $this->render_options['print_description_position'] ) {
576 - $output .= $print_description_html;
708 + $output .= $print_description_html; // @phpstan-ignore variable.undefined (The variable is set above.)
577 709 }
578 710
579 711 /**
580 - * Filter the generated HTML code for table.
712 + * Filters the generated HTML code for the table and HTML elements around it.
581 713 *
582 714 * @since 1.0.0
583 715 *
584 - * @param string $output The generated HTML for the table.
585 - * @param array $table The current table.
586 - * @param array $render_options The render options for the table.
716 + * @param string $output The generated HTML for the table and HTML elements around it.
717 + * @param array<string, mixed> $table The current table.
718 + * @param array<string, mixed> $render_options The render options for the table and HTML elements around it.
587 719 */
588 720 $this->output = apply_filters( 'tablepress_table_output', $output, $this->table, $this->render_options );
589 721 }
590 722
@@ -596,40 +728,22 @@
596 728 * @param int $row_idx Index of the row to be rendered.
597 729 * @param string $tag HTML tag to use for the cells (td or th).
598 730 * @return string HTML for the row.
599 731 */
600 - protected function _render_row( $row_idx, $tag ) {
732 + protected function _render_row( int $row_idx, string $tag ): string {
601 733 $row_cells = array();
602 734 // Loop through cells in reversed order, to search for colspan or rowspan trigger words.
603 735 for ( $col_idx = $this->last_column_idx; $col_idx >= 0; $col_idx-- ) {
604 736 $cell_content = $this->table['data'][ $row_idx ][ $col_idx ];
605 737
606 - // Print formulas that are escaped with '= (like in Excel) as text.
607 - if ( "'=" === substr( $cell_content, 0, 2 ) ) {
608 - $cell_content = substr( $cell_content, 1 );
609 - }
610 - $cell_content = do_shortcode( $this->safe_output( $cell_content ) );
611 - /**
612 - * Filter the content of a single cell.
613 - *
614 - * Filter the content of a single cell, after formulas have been evaluated, the output has been sanitized, and Shortcodes have been evaluated.
615 - *
616 - * @since 1.0.0
617 - *
618 - * @param string $cell_content The cell content.
619 - * @param string $table_id The current table ID.
620 - * @param int $row_idx The row number of the cell.
621 - * @param int $col_idx The column number of the cell.
622 - */
623 - $cell_content = apply_filters( 'tablepress_cell_content', $cell_content, $this->table['id'], $row_idx + 1, $col_idx + 1 );
624 -
625 738 if ( $this->span_trigger['rowspan'] === $cell_content ) { // There will be a rowspan.
626 - // Check for #rowspan# in first row, which doesn't make sense.
627 - if ( ( $row_idx > 1 && $row_idx < $this->last_row_idx )
628 - || ( 1 === $row_idx && ! $this->render_options['table_head'] ) // No rowspan into table head.
629 - || ( $this->last_row_idx === $row_idx && ! $this->render_options['table_foot'] ) ) { // No rowspan out of table foot.
739 + if ( ! (
740 + ( 0 === $row_idx ) // No rowspan inside first row.
741 + || ( $this->render_options['table_head'] === $row_idx ) // No rowspan into table head.
742 + || ( $this->last_row_idx - $this->render_options['table_foot'] + 1 === $row_idx ) // No rowspan out of table foot.
743 + ) ) {
630 744 // Increase counter for rowspan in this column.
631 - $this->rowspan[ $col_idx ]++;
745 + ++$this->rowspan[ $col_idx ];
632 746 // Reset counter for colspan in this row, combined col- and rowspan might be happening.
633 747 $this->colspan[ $row_idx ] = 1;
634 748 continue;
635 749 }
@@ -635,13 +749,15 @@
635 749 }
636 750 // Invalid rowspan, so we set cell content from #rowspan# to empty.
637 751 $cell_content = '';
638 752 } elseif ( $this->span_trigger['colspan'] === $cell_content ) { // There will be a colspan.
639 - // Check for #colspan# in first column, which doesn't make sense.
640 - if ( $col_idx > 1
641 - || ( 1 === $col_idx && ! $this->render_options['first_column_th'] ) ) { // No colspan into first column head.
753 + if ( ! (
754 + ( ( 0 === $row_idx ) && 1 === $this->render_options['table_head'] && $this->render_options['use_datatables'] ) // Don't allow colspan inside a single row table head, as DataTables seems to have a bug here.
755 + || ( 0 === $col_idx ) // No colspan inside first column.
756 + || ( 1 === $col_idx && $this->render_options['first_column_th'] ) // No colspan into first column head.
757 + ) ) {
642 758 // Increase counter for colspan in this row.
643 - $this->colspan[ $row_idx ]++;
759 + ++$this->colspan[ $row_idx ];
644 760 // Reset counter for rowspan in this column, combined col- and rowspan might be happening.
645 761 $this->rowspan[ $col_idx ] = 1;
646 762 continue;
647 763 }
@@ -647,22 +763,20 @@
647 763 }
648 764 // Invalid colspan, so we set cell content from #colspan# to empty.
649 765 $cell_content = '';
650 766 } elseif ( $this->span_trigger['span'] === $cell_content ) { // There will be a combined col- and rowspan.
651 - // Check for #span# in first column or first or last row, which is not always possible.
652 - if ( ( $row_idx > 1 && $row_idx < $this->last_row_idx && $col_idx > 1 )
653 - // We are in first, second, or last row or in the first or second column, so more checks are necessary.
654 - || ( ( 1 === $row_idx && ! $this->render_options['table_head'] ) // No rowspan into table head.
655 - && ( $col_idx > 1 || ( 1 === $col_idx && ! $this->render_options['first_column_th'] ) ) ) // And no colspan into first column head.
656 - || ( ( $this->last_row_idx === $row_idx && ! $this->render_options['table_foot'] ) // No rowspan out of table foot.
657 - && ( $col_idx > 1 || ( 1 === $col_idx && ! $this->render_options['first_column_th'] ) ) ) ) { // And no colspan into first column head.
767 + if ( ! (
768 + ( 0 === $row_idx ) // No rowspan inside first row.
769 + || ( $this->render_options['table_head'] === $row_idx ) // No rowspan into table head.
770 + || ( $this->last_row_idx - $this->render_options['table_foot'] + 1 === $row_idx ) // No rowspan out of table foot.
771 + ) && ! (
772 + ( 0 === $col_idx ) // No colspan inside first column.
773 + || ( 1 === $col_idx && $this->render_options['first_column_th'] ) // No colspan into first column head.
774 + ) ) {
658 775 continue;
659 776 }
660 777 // Invalid span, so we set cell content from #span# to empty.
661 778 $cell_content = '';
662 - } elseif ( '' === $cell_content && 0 === $row_idx && $this->render_options['table_head'] ) {
663 - // Make empty cells have a space in the table head, to give sorting arrows the correct position in IE9.
664 - $cell_content = '&nbsp;';
665 779 }
666 780
667 781 // Attributes for the table cell (HTML td or th element).
668 782 $tag_attributes = array();
@@ -668,18 +782,26 @@
668 782 $tag_attributes = array();
669 783
670 784 // "colspan" and "rowspan" attributes.
671 785 if ( $this->colspan[ $row_idx ] > 1 ) { // We have colspaned cells.
672 - $tag_attributes['colspan'] = $this->colspan[ $row_idx ];
786 + $tag_attributes['colspan'] = (string) $this->colspan[ $row_idx ];
787 + if ( ! $this->tbody_has_connected_cells && $row_idx > $this->render_options['table_head'] - 1 && $row_idx < $this->last_row_idx - $this->render_options['table_foot'] + 1 ) {
788 + // Set flag that there are connected cells in the tbody.
789 + $this->tbody_has_connected_cells = true;
790 + }
673 791 }
674 792 if ( $this->rowspan[ $col_idx ] > 1 ) { // We have rowspaned cells.
675 - $tag_attributes['rowspan'] = $this->rowspan[ $col_idx ];
793 + $tag_attributes['rowspan'] = (string) $this->rowspan[ $col_idx ];
794 + if ( ! $this->tbody_has_connected_cells && $row_idx > $this->render_options['table_head'] - 1 && $row_idx < $this->last_row_idx - $this->render_options['table_foot'] + 1 ) {
795 + // Set flag that there are connected cells in the tbody.
796 + $this->tbody_has_connected_cells = true;
797 + }
676 798 }
677 799
678 800 // "class" attribute.
679 801 $cell_class = 'column-' . ( $col_idx + 1 );
680 802 /**
681 - * Filter the CSS classes that are given to a single cell (HTML td element) of a table.
803 + * Filters the CSS classes that are given to a single cell (HTML td element) of a table.
682 804 *
683 805 * @since 1.0.0
684 806 *
685 807 * @param string $cell_class The CSS classes for the cell.
@@ -700,19 +822,19 @@
700 822 $tag_attributes['style'] = 'width:' . preg_replace( '#[^0-9a-z.%]#', '', $this->render_options['column_widths'][ $col_idx ] ) . ';';
701 823 }
702 824
703 825 /**
704 - * Filter the attributes for the table cell (HTML td or th element).
826 + * Filters the attributes for the table cell (HTML td or th element).
705 827 *
706 828 * @since 1.4.0
707 829 *
708 - * @param array $tag_attributes The attributes for the td or th element.
709 - * @param string $table_id The current table ID.
710 - * @param string $cell_content The cell content.
711 - * @param int $row_idx The row number of the cell.
712 - * @param int $col_idx The column number of the cell.
713 - * @param int $colspan_row The number of combined columns for this cell.
714 - * @param int $rowspan_col The number of combined rows for this cell.
830 + * @param array<string, string> $tag_attributes The attributes for the td or th element.
831 + * @param string $table_id The current table ID.
832 + * @param string $cell_content The cell content.
833 + * @param int $row_idx The row number of the cell.
834 + * @param int $col_idx The column number of the cell.
835 + * @param int $colspan_row The number of combined columns for this cell.
836 + * @param int $rowspan_col The number of combined rows for this cell.
715 837 */
716 838 $tag_attributes = apply_filters( 'tablepress_cell_tag_attributes', $tag_attributes, $this->table['id'], $cell_content, $row_idx + 1, $col_idx + 1, $this->colspan[ $row_idx ], $this->rowspan[ $col_idx ] );
717 839 $tag_attributes = $this->_attributes_array_to_string( $tag_attributes );
718 840
@@ -729,21 +851,18 @@
729 851 $tr_attributes = array();
730 852
731 853 // "class" attribute.
732 854 $row_classes = 'row-' . ( $row_idx + 1 );
733 - if ( $this->render_options['alternating_row_colors'] ) {
734 - $row_classes .= ( 1 === ( $row_idx % 2 ) ) ? ' even' : ' odd';
735 - }
736 855 /**
737 - * Filter the CSS classes that are given to a row (HTML tr element) of a table.
856 + * Filters the CSS classes that are given to a row (HTML tr element) of a table.
738 857 *
739 858 * @since 1.0.0
740 859 *
741 - * @param string $row_classes The CSS classes for the row.
742 - * @param string $table_id The current table ID.
743 - * @param array $row_cells The HTML code for the cells of the row.
744 - * @param int $row_idx The row number.
745 - * @param array $row_data The content of the cells of the row.
860 + * @param string $row_classes The CSS classes for the row.
861 + * @param string $table_id The current table ID.
862 + * @param string[] $row_cells The HTML code for the cells of the row.
863 + * @param int $row_idx The row number.
864 + * @param string[] $row_data The content of the cells of the row.
746 865 */
747 866 $row_classes = apply_filters( 'tablepress_row_css_class', $row_classes, $this->table['id'], $row_cells, $row_idx + 1, $this->table['data'][ $row_idx ] );
748 867 if ( ! empty( $row_classes ) ) {
749 868 $tr_attributes['class'] = $row_classes;
@@ -749,16 +868,16 @@
749 868 $tr_attributes['class'] = $row_classes;
750 869 }
751 870
752 871 /**
753 - * Filter the attributes for the table row (HTML tr element).
872 + * Filters the attributes for the table row (HTML tr element).
754 873 *
755 874 * @since 1.4.0
756 875 *
757 - * @param array $tr_attributes The attributes for the tr element.
758 - * @param string $table_id The current table ID.
759 - * @param int $row_idx The row number.
760 - * @param array $row_data The content of the cells of the row.
876 + * @param array<string, mixed> $tr_attributes The attributes for the tr element.
877 + * @param string $table_id The current table ID.
878 + * @param int $row_idx The row number.
879 + * @param string[] $row_data The content of the cells of the row.
761 880 */
762 881 $tr_attributes = apply_filters( 'tablepress_row_tag_attributes', $tr_attributes, $this->table['id'], $row_idx + 1, $this->table['data'][ $row_idx ] );
763 882 $tr_attributes = $this->_attributes_array_to_string( $tr_attributes );
764 883
@@ -771,12 +890,12 @@
771 890 * Convert an array of HTML tag attributes to a string.
772 891 *
773 892 * @since 1.4.0
774 893 *
775 - * @param array $attributes Attributes for the HTML tag in the array keys, and their values in the array values.
894 + * @param array<string, string> $attributes Attributes for the HTML tag in the array keys, and their values in the array values.
776 895 * @return string The attributes as a string for usage in a HTML element.
777 896 */
778 - protected function _attributes_array_to_string( array $attributes ) {
897 + protected function _attributes_array_to_string( array $attributes ): string {
779 898 $attributes_string = '';
780 899 foreach ( $attributes as $attribute => $value ) {
781 900 $attributes_string .= " {$attribute}=\"{$value}\"";
782 901 }
@@ -785,23 +904,21 @@
785 904
786 905 /**
787 906 * Possibly replace certain HTML entities and replace line breaks with HTML.
788 907 *
789 - * @TODO: Find a better solution than this function, e.g. something like wpautop().
790 - *
791 908 * @since 1.0.0
792 909 *
793 - * @param string $string The string to process.
910 + * @param string $text The string to process.
794 911 * @return string Processed string for output.
795 912 */
796 - protected function safe_output( $string ) {
913 + protected function safe_output( string $text ): string {
797 914 /*
798 915 * Replace any & with &amp; that is not already an encoded entity (from function htmlentities2 in WP 2.8).
799 916 * A complete htmlentities2() or htmlspecialchars() would encode <HTML> tags, which we don't want.
800 917 */
801 - $string = preg_replace( '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/', '&amp;', $string );
918 + $text = (string) preg_replace( '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/', '&amp;', $text );
802 919 /**
803 - * Filter whether line breaks in the cell content shall be replaced with HTML br tags.
920 + * Filters whether line breaks in the cell content shall be replaced with HTML br tags.
804 921 *
805 922 * @since 1.0.0
806 923 *
807 924 * @param bool $replace Whether to replace line breaks with HTML br tags. Default true.
@@ -807,11 +924,11 @@
807 924 * @param bool $replace Whether to replace line breaks with HTML br tags. Default true.
808 925 * @param string $table_id The current table ID.
809 926 */
810 927 if ( apply_filters( 'tablepress_apply_nl2br', true, $this->table['id'] ) ) {
811 - $string = nl2br( $string );
928 + $text = nl2br( $text );
812 929 }
813 - return $string;
930 + return $text;
814 931 }
815 932
816 933 /**
817 934 * Get the default render options, null means: Use option from "Edit" screen.
@@ -817,46 +934,49 @@
817 934 * Get the default render options, null means: Use option from "Edit" screen.
818 935 *
819 936 * @since 1.0.0
820 937 *
821 - * @return array Default render options.
938 + * @return array<string, mixed> Default render options.
822 939 */
823 - public function get_default_render_options() {
940 + public function get_default_render_options(): array {
824 941 // Attention: Array keys have to be lowercase, otherwise they won't match the Shortcode attributes, which will be passed in lowercase by WP.
825 942 return array(
826 - 'id' => '',
827 - 'column_widths' => '',
828 943 'alternating_row_colors' => null,
829 - 'row_hover' => null,
830 - 'table_head' => null,
831 - 'table_foot' => null,
832 - 'first_column_th' => false,
833 - 'print_name' => null,
834 - 'print_name_position' => null,
835 - 'print_description' => null,
836 - 'print_description_position' => null,
944 + 'block_preview' => false,
945 + 'border' => false,
837 946 'cache_table_output' => true,
947 + 'cellpadding' => false,
948 + 'cellspacing' => false,
949 + 'column_widths' => '',
838 950 'convert_line_breaks' => true,
839 - 'extra_css_classes' => null,
840 - 'use_datatables' => null,
841 - 'datatables_sort' => null,
951 + 'datatables_custom_commands' => null,
952 + 'datatables_datetime' => '',
953 + 'datatables_filter' => null,
954 + 'datatables_info' => null,
955 + 'datatables_lengthchange' => null,
956 + 'datatables_locale' => get_locale(),
842 957 'datatables_paginate' => null,
843 958 'datatables_paginate_entries' => null,
844 - 'datatables_lengthchange' => null,
845 - 'datatables_filter' => null,
846 - 'datatables_info' => null,
847 959 'datatables_scrollx' => null,
848 960 'datatables_scrolly' => false,
849 - 'datatables_custom_commands' => null,
850 - 'datatables_locale' => get_locale(),
851 - 'show_rows' => '',
852 - 'show_columns' => '',
961 + 'datatables_sort' => null,
962 + 'evaluate_formulas' => true,
963 + 'extra_css_classes' => null,
964 + 'first_column_th' => false,
965 + 'hide_columns' => '',
853 966 'hide_rows' => '',
854 - 'hide_columns' => '',
855 - 'cellspacing' => false,
856 - 'cellpadding' => false,
857 - 'border' => false,
967 + 'id' => '',
968 + 'print_description' => null,
969 + 'print_description_position' => null,
970 + 'print_name' => null,
971 + 'print_name_position' => null,
972 + 'row_hover' => null,
858 973 'shortcode_debug' => false,
974 + 'show_columns' => '',
975 + 'show_rows' => '',
976 + 'table_foot' => null,
977 + 'table_head' => null,
978 + 'use_datatables' => null,
859 979 );
860 980 }
861 981
862 982 /**
@@ -865,90 +985,30 @@
865 985 * @since 1.0.0
866 986 *
867 987 * @return string CSS for the Preview iframe.
868 988 */
869 - public function get_preview_css() {
870 - if ( is_rtl() ) {
871 - $rtl = "\ndirection: rtl;";
872 - $rtl_align = 'right';
873 - } else {
874 - $rtl = '';
875 - $rtl_align = 'left';
989 + public function get_preview_css(): string {
990 + $is_rtl = is_rtl();
991 + $tablepress_css = TablePress::load_class( 'TablePress_CSS', 'class-css.php', 'classes' );
992 + $default_css_minified = $tablepress_css->load_default_css_from_file( $is_rtl );
993 + if ( false === $default_css_minified ) {
994 + $default_css_minified = '';
876 995 }
996 +
997 + $rtl_direction = $is_rtl ? "\ndirection: rtl;" : '';
998 +
877 999 return <<<CSS
878 -<style type="text/css">
879 -/* iframe */
880 -body {
881 - margin: 10px;
882 - font-family: sans-serif;{$rtl}
883 -}
884 -/* Inline Shortcodes, in texts */
885 -.table-shortcode-inline {
886 - background: transparent;
887 - border: none;
888 - color: #333333;
889 - width: 110px;
890 - margin: 0;
891 - padding: 0;
892 - -webkit-box-shadow: none;
893 - box-shadow: none;
894 - text-align: center;
895 - font-weight: bold;
896 - font-size: 100%;
897 -}
898 -.table-shortcode {
899 - cursor: text;
900 -}
901 -/* Default table styling */
902 -.tablepress {
903 - border-collapse: collapse;
904 - border-spacing: 0;
905 - width: 100%;
906 - margin-bottom: 1em;
907 - border: none;
908 -}
909 -.tablepress td,
910 -.tablepress th {
911 - padding: 8px;
912 - border: none;
913 - background: none;
914 - text-align: {$rtl_align};
915 -}
916 -.tablepress tbody td {
917 - vertical-align: top;
918 -}
919 -.tablepress tbody tr td,
920 -.tablepress tfoot tr th {
921 - border-top: 1px solid #dddddd;
922 -}
923 -.tablepress tbody tr:first-child td {
924 - border-top: 0;
925 -}
926 -.tablepress thead tr th {
927 - border-bottom: 1px solid #dddddd;
928 -}
929 -.tablepress thead th,
930 -.tablepress tfoot th {
931 - background-color: #d9edf7;
932 - font-weight: bold;
933 - vertical-align: middle;
934 -}
935 -.tablepress tbody tr.odd td {
936 - background-color: #f9f9f9;
937 -}
938 -.tablepress tbody tr.even td {
939 - background-color: #ffffff;
940 -}
941 -.tablepress .row-hover tr:hover td {
942 - background-color: #f3f3f3;
943 -}
944 -.tablepress img {
945 - margin: 0;
946 - padding: 0;
947 - border: none;
948 - max-width: none;
949 -}
950 -</style>
951 -CSS;
1000 + <style>
1001 + /* iframe */
1002 + body {
1003 + margin: 10px;
1004 + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;{$rtl_direction}
1005 + }
1006 + p {
1007 + font-size: 13px;
1008 + }
1009 + {$default_css_minified}
1010 + </style>
1011 + CSS;
952 1012 }
953 1013
954 1014 } // class TablePress_Render