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 | classes/class-import-legacy.php +13 -17 2.4.1 → 3.4 View file →
@@ -7,8 +7,10 @@
7 7 * @author Tobias Bäthge
8 8 * @since 1.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 /**
@@ -23,28 +25,28 @@
23 25
24 26 /**
25 27 * File/Data Formats that are available for import.
26 28 *
29 + * The constructor also adds 'html', if the PHP prerequisites are met.
30 + *
27 31 * @since 1.0.0
28 - * @var array<string, string>
32 + * @var string[]
29 33 */
30 - public $import_formats = array();
34 + public array $import_formats = array( 'csv', 'json', 'xls', 'xlsx' );
31 35
32 36 /**
33 37 * Whether HTML import support is available in the PHP installation on the server.
34 38 *
35 39 * @since 1.0.0
36 - * @var bool
37 40 */
38 - public $html_import_support_available = false;
41 + public bool $html_import_support_available = false;
39 42
40 43 /**
41 44 * Data to be imported.
42 45 *
43 46 * @since 1.0.0
44 - * @var string
45 47 */
46 - protected $import_data;
48 + protected string $import_data;
47 49
48 50 /**
49 51 * Imported table.
50 52 *
@@ -62,17 +64,11 @@
62 64 if ( class_exists( 'DOMDocument', false ) && function_exists( 'simplexml_import_dom' ) && function_exists( 'libxml_use_internal_errors' ) ) {
63 65 $this->html_import_support_available = true;
64 66 }
65 67
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 68 if ( $this->html_import_support_available ) {
70 - $this->import_formats['html'] = __( 'HTML - Hypertext Markup Language', 'tablepress' );
69 + $this->import_formats[] = 'html';
71 70 }
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 71 }
76 72
77 73 /**
78 74 * Import a table.
@@ -126,9 +122,9 @@
126 122 array_walk_recursive(
127 123 $this->imported_table['data'],
128 124 static function ( /* string|int|float|bool|null */ &$cell_content, int $col_idx ): void {
129 125 $cell_content = (string) $cell_content;
130 - }
126 + },
131 127 );
132 128
133 129 return $this->imported_table;
134 130 }
@@ -321,9 +317,9 @@
321 317 if ( function_exists( 'mb_detect_encoding' ) ) {
322 318 $current_encoding = mb_detect_encoding( $this->import_data, 'ASCII, UTF-8, ISO-8859-1' );
323 319 if ( 'UTF-8' !== $current_encoding ) {
324 320 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
325 - $data = @iconv( $current_encoding, 'UTF-8', $this->import_data ); // @phpstan-ignore-line
321 + $data = @iconv( $current_encoding, 'UTF-8', $this->import_data ); // @phpstan-ignore argument.type
326 322 if ( false !== $data ) {
327 323 $this->import_data = $data;
328 324 return;
329 325 }
@@ -337,9 +333,9 @@
337 333 * This function uses call by reference to save PHP memory on large arrays.
338 334 *
339 335 * @since 2.0.0
340 336 *
341 - * @param string[] $an_array Array in which Windows line breaks should be replaced by Unix line breaks.
337 + * @param array<int, array<int, string>> $an_array Array in which Windows line breaks should be replaced by Unix line breaks.
342 338 */
343 339 protected function normalize_line_endings( array &$an_array ): void {
344 340 array_walk_recursive(
345 341 $an_array,
@@ -344,9 +340,9 @@
344 340 array_walk_recursive(
345 341 $an_array,
346 342 static function ( string &$cell_content, int $col_idx ): void {
347 343 $cell_content = str_replace( "\r\n", "\n", $cell_content );
348 - }
344 + },
349 345 );
350 346 }
351 347
352 348 } // class TablePress_Import_Legacy