| @@ -26,9 +26,9 @@ | ||
| 26 | 26 | * |
| 27 | 27 | * @since 1.0.0 |
| 28 | 28 | * @var array<string, string> |
| 29 | 29 | */ |
| 30 | - public $export_formats = array(); | |
| 30 | + public array $export_formats = array(); | |
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Delimiters for the CSV export. |
| 34 | 34 | * |
| @@ -34,17 +34,16 @@ | ||
| 34 | 34 | * |
| 35 | 35 | * @since 1.0.0 |
| 36 | 36 | * @var array<string, string> |
| 37 | 37 | */ |
| 38 | - public $csv_delimiters = array(); | |
| 38 | + public array $csv_delimiters = array(); | |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Whether ZIP archive support is available in the PHP installation on the server. |
| 42 | 42 | * |
| 43 | 43 | * @since 1.0.0 |
| 44 | - * @var bool | |
| 45 | 44 | */ |
| 46 | - public $zip_support_available = false; | |
| 45 | + public bool $zip_support_available = false; | |
| 47 | 46 | |
| 48 | 47 | /** |
| 49 | 48 | * Initialize the Export class. |
| 50 | 49 | * |
| @@ -62,10 +61,9 @@ | ||
| 62 | 61 | ',' => __( ', (comma)', 'tablepress' ), |
| 63 | 62 | 'tab' => __( '\t (tabulator)', 'tablepress' ), |
| 64 | 63 | ); |
| 65 | 64 | |
| 66 | - /** This filter is documented in the WordPress function unzip_file() in wp-admin/includes/file.php */ | |
| 67 | - if ( class_exists( 'ZipArchive', false ) && apply_filters( 'unzip_file_use_ziparchive', true ) ) { | |
| 65 | + if ( class_exists( 'ZipArchive', false ) ) { | |
| 68 | 66 | $this->zip_support_available = true; |
| 69 | 67 | } |
| 70 | 68 | } |
| 71 | 69 | |
| @@ -102,15 +100,15 @@ | ||
| 102 | 100 | $tfoot = ''; |
| 103 | 101 | $tbody = array(); |
| 104 | 102 | |
| 105 | 103 | foreach ( $table['data'] as $row_idx => $row ) { |
| 106 | - // First row, need to check for head (but only if at least two rows). | |
| 107 | - if ( 0 === $row_idx && $table['options']['table_head'] && $num_rows > 1 ) { | |
| 104 | + // Table head rows, but only if there's at least one additional row. | |
| 105 | + if ( $row_idx < $table['options']['table_head'] && $num_rows > $table['options']['table_head'] ) { | |
| 108 | 106 | $thead = $this->html_render_row( $row, 'th' ); |
| 109 | 107 | continue; |
| 110 | 108 | } |
| 111 | - // Last row, need to check for footer (but only if at least two rows). | |
| 112 | - if ( $last_row_idx === $row_idx && $table['options']['table_foot'] && $num_rows > 1 ) { | |
| 109 | + // Table foot rows, but only if there's at least one additional row. | |
| 110 | + if ( $row_idx > $last_row_idx - $table['options']['table_foot'] && $num_rows > $table['options']['table_foot'] ) { | |
| 113 | 111 | $tfoot = $this->html_render_row( $row, 'th' ); |
| 114 | 112 | continue; |
| 115 | 113 | } |
| 116 | 114 | // Neither first nor last row (with respective head/foot enabled), so render as body row. |
| @@ -171,10 +169,13 @@ | ||
| 171 | 169 | 'IMAGE(', |
| 172 | 170 | 'HYPERLINK(', |
| 173 | 171 | 'WEBSERVICE(', |
| 174 | 172 | ); |
| 173 | + | |
| 174 | + $fn_stripos = function_exists( 'mb_stripos' ) ? 'mb_stripos' : 'stripos'; | |
| 175 | + | |
| 175 | 176 | foreach ( $functions_to_escape as $function ) { |
| 176 | - if ( false !== stripos( $cell_content, $function ) ) { | |
| 177 | + if ( false !== $fn_stripos( $cell_content, $function ) ) { | |
| 177 | 178 | $cell_content = "'" . $cell_content; // Prepend a ' to indicate that the cell format is a text string. |
| 178 | 179 | break; |
| 179 | 180 | } |
| 180 | 181 | } |
| @@ -222,9 +223,9 @@ | ||
| 222 | 223 | /* |
| 223 | 224 | * Replace any & with & that is not already an encoded entity (from function htmlentities2 in WP 2.8). |
| 224 | 225 | * A complete htmlentities2() or htmlspecialchars() would encode <HTML> tags, which we don't want. |
| 225 | 226 | */ |
| 226 | - $cell_content = preg_replace( '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/', '&', $cell_content ); | |
| 227 | + $cell_content = (string) preg_replace( '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/', '&', $cell_content ); | |
| 227 | 228 | $cell_content = "\t\t\t<{$html_tag}>{$cell_content}</{$html_tag}>\n"; |
| 228 | 229 | } |
| 229 | 230 | |
| 230 | 231 | } // class TablePress_Export |