PluginProbe
TablePress – Tables in WordPress made easy / 3.2
TablePress – Tables in WordPress made easy v3.2
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-import-legacy.php +15 -21 2.23.2 View file →
@@ -23,28 +23,28 @@
23 23
24 24 /**
25 25 * File/Data Formats that are available for import.
26 26 *
27 + * The constructor also adds 'html', if the PHP prerequisites are met.
28 + *
27 29 * @since 1.0.0
28 - * @var array<string, string>
30 + * @var string[]
29 31 */
30 - public $import_formats = array();
32 + public array $import_formats = array( 'csv', 'json', 'xls', 'xlsx' );
31 33
32 34 /**
33 35 * Whether HTML import support is available in the PHP installation on the server.
34 36 *
35 37 * @since 1.0.0
36 - * @var bool
37 38 */
38 - public $html_import_support_available = false;
39 + public bool $html_import_support_available = false;
39 40
40 41 /**
41 42 * Data to be imported.
42 43 *
43 44 * @since 1.0.0
44 - * @var string
45 45 */
46 - protected $import_data;
46 + protected string $import_data;
47 47
48 48 /**
49 49 * Imported table.
50 50 *
@@ -62,17 +62,11 @@
62 62 if ( class_exists( 'DOMDocument', false ) && function_exists( 'simplexml_import_dom' ) && function_exists( 'libxml_use_internal_errors' ) ) {
63 63 $this->html_import_support_available = true;
64 64 }
65 65
66 - // Initiate here, because function call not possible outside a class method.
67 - $this->import_formats = array();
68 - $this->import_formats['csv'] = __( 'CSV - Character-Separated Values', 'tablepress' );
69 66 if ( $this->html_import_support_available ) {
70 - $this->import_formats['html'] = __( 'HTML - Hypertext Markup Language', 'tablepress' );
67 + $this->import_formats[] = 'html';
71 68 }
72 - $this->import_formats['json'] = __( 'JSON - JavaScript Object Notation', 'tablepress' );
73 - $this->import_formats['xls'] = __( 'XLS - Microsoft Excel 97-2003 (experimental)', 'tablepress' );
74 - $this->import_formats['xlsx'] = __( 'XLSX - Microsoft Excel 2007-2019 (experimental)', 'tablepress' );
75 69 }
76 70
77 71 /**
78 72 * Import a table.
@@ -126,9 +120,9 @@
126 120 array_walk_recursive(
127 121 $this->imported_table['data'],
128 122 static function ( /* string|int|float|bool|null */ &$cell_content, int $col_idx ): void {
129 123 $cell_content = (string) $cell_content;
130 - }
124 + },
131 125 );
132 126
133 127 return $this->imported_table;
134 128 }
@@ -181,9 +175,9 @@
181 175
182 176 // Check if JSON could be decoded.
183 177 if ( is_null( $json_table ) ) {
184 178 $json_error = json_last_error_msg();
185 - $output = '<strong>' . __( 'The imported file contains errors:', 'tablepress' ) . "</strong><br /><br />JSON error: {$json_error}<br />";
179 + $output = '<strong>' . __( 'The imported file contains errors:', 'tablepress' ) . "</strong><br><br>JSON error: {$json_error}<br>";
186 180 wp_die( $output, 'Import Error', array( 'response' => 200, 'back_link' => true ) );
187 181 }
188 182
189 183 // Specifically cast to an array again.
@@ -261,11 +255,11 @@
261 255 foreach ( $table as &$row ) {
262 256 foreach ( $row as &$cell ) {
263 257 $cell = $cell['val'];
264 258 }
265 - unset( $cell );
259 + unset( $cell ); // Unset use-by-reference parameter of foreach loop.
266 260 }
267 - unset( $row );
261 + unset( $row ); // Unset use-by-reference parameter of foreach loop.
268 262
269 263 $this->imported_table = array( 'data' => $table );
270 264 }
271 265
@@ -278,9 +272,9 @@
278 272 TablePress::load_file( 'simplexlsx.class.php', 'libraries' );
279 273 $xlsx_file = \Shuchkin\SimpleXLSX::parse( $this->import_data, true );
280 274
281 275 if ( ! $xlsx_file ) {
282 - $output = '<strong>' . __( 'The imported file contains errors:', 'tablepress' ) . '</strong><br /><br />' . \Shuchkin\SimpleXLSX::parseError() . '<br />';
276 + $output = '<strong>' . __( 'The imported file contains errors:', 'tablepress' ) . '</strong><br><br>' . \Shuchkin\SimpleXLSX::parseError() . '<br>';
283 277 wp_die( $output, 'Import Error', array( 'response' => 200, 'back_link' => true ) );
284 278 }
285 279
286 280 $this->imported_table = array( 'data' => $xlsx_file->rows() );
@@ -321,9 +315,9 @@
321 315 if ( function_exists( 'mb_detect_encoding' ) ) {
322 316 $current_encoding = mb_detect_encoding( $this->import_data, 'ASCII, UTF-8, ISO-8859-1' );
323 317 if ( 'UTF-8' !== $current_encoding ) {
324 318 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
325 - $data = @iconv( $current_encoding, 'UTF-8', $this->import_data ); // @phpstan-ignore-line
319 + $data = @iconv( $current_encoding, 'UTF-8', $this->import_data ); // @phpstan-ignore argument.type
326 320 if ( false !== $data ) {
327 321 $this->import_data = $data;
328 322 return;
329 323 }
@@ -337,9 +331,9 @@
337 331 * This function uses call by reference to save PHP memory on large arrays.
338 332 *
339 333 * @since 2.0.0
340 334 *
341 - * @param string[] $an_array Array in which Windows line breaks should be replaced by Unix line breaks.
335 + * @param array<int, array<int, string>> $an_array Array in which Windows line breaks should be replaced by Unix line breaks.
342 336 */
343 337 protected function normalize_line_endings( array &$an_array ): void {
344 338 array_walk_recursive(
345 339 $an_array,
@@ -344,9 +338,9 @@
344 338 array_walk_recursive(
345 339 $an_array,
346 340 static function ( string &$cell_content, int $col_idx ): void {
347 341 $cell_content = str_replace( "\r\n", "\n", $cell_content );
348 - }
342 + },
349 343 );
350 344 }
351 345
352 346 } // class TablePress_Import_Legacy