PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 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 All 45 releases
← All changes | libraries/html-parser.class.php +16 -12 2.2.4 → 3.4 View file →
@@ -7,8 +7,10 @@
7 7 * @author Tobias Bäthge
8 8 * @since 2.0.0
9 9 */
10 10
11 +declare(strict_types=1);
12 +
11 13 // Prohibit direct script loading.
12 14 defined( 'ABSPATH' ) || die( 'No direct script access allowed!' );
13 15
14 16 /**
@@ -56,9 +58,9 @@
56 58 if ( 0 === count( $dom_tables ) ) {
57 59 return new WP_Error( 'table_import_html_dom_get_tables' );
58 60 }
59 61 libxml_clear_errors(); // Clear errors so that we only catch those inside the table in the next line.
60 - $table = simplexml_import_dom( $dom_tables->item( 0 ) ); // @phpstan-ignore-line
62 + $table = simplexml_import_dom( $dom_tables->item( 0 ) ); // @phpstan-ignore argument.type
61 63 if ( is_null( $table ) ) {
62 64 return new WP_Error( 'table_import_html_simplexml_import_dom_failed' );
63 65 }
64 66
@@ -64,19 +66,19 @@
64 66
65 67 $errors = libxml_get_errors();
66 68 libxml_clear_errors();
67 69 if ( ! empty( $errors ) ) {
68 - $output = '<strong>' . __( 'The imported file contains errors:', 'tablepress' ) . '</strong><br /><br />';
70 + $output = '<strong>' . __( 'The imported file contains errors:', 'tablepress' ) . '</strong><br><br>';
69 71 foreach ( $errors as $error ) {
70 72 switch ( $error->level ) {
71 73 case LIBXML_ERR_WARNING:
72 - $output .= "Warning {$error->code}: {$error->message} in line {$error->line}, column {$error->column}<br />";
74 + $output .= "Warning {$error->code}: {$error->message} in line {$error->line}, column {$error->column}<br>";
73 75 break;
74 76 case LIBXML_ERR_ERROR:
75 - $output .= "Error {$error->code}: {$error->message} in line {$error->line}, column {$error->column}<br />";
77 + $output .= "Error {$error->code}: {$error->message} in line {$error->line}, column {$error->column}<br>";
76 78 break;
77 79 case LIBXML_ERR_FATAL:
78 - $output .= "Fatal Error {$error->code}: {$error->message} in line {$error->line}, column {$error->column}<br />";
80 + $output .= "Fatal Error {$error->code}: {$error->message} in line {$error->line}, column {$error->column}<br>";
79 81 break;
80 82 }
81 83 }
82 84 wp_die( $output, 'Import Error', array( 'response' => 200, 'back_link' => true ) );
@@ -86,20 +88,22 @@
86 88 'data' => array(),
87 89 'options' => array(),
88 90 );
89 91 if ( isset( $table->thead ) ) {
90 - $html_table['data'] = array_merge( $html_table['data'], self::_import_html_rows( $table->thead[0]->tr ) ); // @phpstan-ignore-line
91 - $html_table['options']['table_head'] = true;
92 + $head_rows = self::_import_html_rows( $table->thead[0]->tr ); // @phpstan-ignore property.nonObject
93 + $html_table['data'] = array_merge( $html_table['data'], $head_rows );
94 + $html_table['options']['table_head'] = count( $head_rows );
92 95 }
93 96 if ( isset( $table->tbody ) ) {
94 - $html_table['data'] = array_merge( $html_table['data'], self::_import_html_rows( $table->tbody[0]->tr ) ); // @phpstan-ignore-line
97 + $html_table['data'] = array_merge( $html_table['data'], self::_import_html_rows( $table->tbody[0]->tr ) ); // @phpstan-ignore property.nonObject
95 98 }
96 99 if ( isset( $table->tr ) ) {
97 100 $html_table['data'] = array_merge( $html_table['data'], self::_import_html_rows( $table->tr ) );
98 101 }
99 102 if ( isset( $table->tfoot ) ) {
100 - $html_table['data'] = array_merge( $html_table['data'], self::_import_html_rows( $table->tfoot[0]->tr ) ); // @phpstan-ignore-line
101 - $html_table['options']['table_foot'] = true;
103 + $foot_rows = self::_import_html_rows( $table->tfoot[0]->tr ); // @phpstan-ignore property.nonObject
104 + $html_table['data'] = array_merge( $html_table['data'], $foot_rows );
105 + $html_table['options']['table_foot'] = count( $foot_rows );
102 106 }
103 107
104 108 return $html_table;
105 109 }
@@ -132,15 +136,15 @@
132 136 $new_row[] = $rowspans[ $row_idx ][ $column_idx ];
133 137 ++$column_idx;
134 138 }
135 139
136 - $cell_xml = $cell->asXml();
140 + $cell_xml = $cell->asXML();
137 141
138 142 // Get content between <td>...</td>, or <th>...</th>, possibly with HTML.
139 143 if ( false !== $cell_xml && 1 === preg_match( '#<t[d|h].*?>(.*)</t[d|h]>#is', $cell_xml, $matches ) ) {
140 144 /*
141 145 * Decode HTML entities again, as there might be some left especially in attributes of HTML tags in the cells,
142 - * see https://secure.php.net/manual/en/simplexmlelement.asxml.php#107137.
146 + * see https://www.php.net/manual/en/simplexmlelement.asxml.php#107137.
143 147 */
144 148 $new_row[] = html_entity_decode( $matches[1], ENT_NOQUOTES, 'UTF-8' );
145 149
146 150 // Search for colspan and rowspan attributes in the cell's HTML tag.