| @@ -130,15 +130,12 @@ | ||
| 130 | 130 | if ( in_array( $ip, $blocked_ips, true ) ) { |
| 131 | 131 | return new WP_Error( 'table_import_url_host_blocked', '', array( 'url' => $this->import_config['url'], 'ip' => $ip ) ); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - // Automatically adjust URLs of common services to point to a direct download URL. | |
| 135 | - $this->import_config['url'] = $this->fix_common_url_mistakes( $this->import_config['url'] ); | |
| 136 | - | |
| 137 | 134 | /** |
| 138 | 135 | * Load WP file functions to be sure that `download_url()` exists, in particular during Cron requests. |
| 139 | 136 | */ |
| 140 | - require_once ABSPATH . 'wp-admin/includes/file.php'; | |
| 137 | + require_once ABSPATH . 'wp-admin/includes/file.php'; // @phpstan-ignore requireOnce.fileNotFound (This is a WordPress core file that always exists.) | |
| 141 | 138 | |
| 142 | 139 | // Download URL to local file. |
| 143 | 140 | $location = download_url( $this->import_config['url'] ); |
| 144 | 141 | if ( is_wp_error( $location ) ) { |
| @@ -187,45 +184,8 @@ | ||
| 187 | 184 | return $import_files; |
| 188 | 185 | } |
| 189 | 186 | |
| 190 | 187 | /** |
| 191 | - * Fixes common mistakes in URLs from popular services to point to a direct download URL. | |
| 192 | - * | |
| 193 | - * Currently supports Google Sheets, Microsoft OneDrive, and Dropbox. | |
| 194 | - * See https://tablepress.org/tutorials/ for more specific instructions on how to get the correct URL. | |
| 195 | - * | |
| 196 | - * @since 3.2.4 | |
| 197 | - * | |
| 198 | - * @param string $url URL that shall be fixed. | |
| 199 | - * @return string Fixed URL. | |
| 200 | - */ | |
| 201 | - protected function fix_common_url_mistakes( string $url ): string { | |
| 202 | - /** | |
| 203 | - * Filters whether common URL mistakes shall be fixed automatically. | |
| 204 | - * | |
| 205 | - * @since 3.2.4 | |
| 206 | - * | |
| 207 | - * @param bool $fix_common_url_mistakes Whether to fix common URL mistakes. Default true. | |
| 208 | - */ | |
| 209 | - if ( ! apply_filters( 'tablepress_import_fix_common_url_mistakes', true ) ) { | |
| 210 | - return $url; | |
| 211 | - } | |
| 212 | - | |
| 213 | - if ( str_starts_with( $url, 'https://docs.google.com/spreadsheets/' ) && str_ends_with( $url, '/edit?usp=sharing' ) ) { | |
| 214 | - // Google Sheets "Sharing URL" to direct download URL. | |
| 215 | - $url = str_replace( '/edit?usp=sharing', '/export?format=csv', $url ); | |
| 216 | - } elseif ( str_starts_with( $url, 'https://1drv.ms/' ) && ! str_ends_with( $url, '&download=1' ) ) { | |
| 217 | - // OneDrive shared link to direct download link. | |
| 218 | - $url .= '&download=1'; | |
| 219 | - } elseif ( str_starts_with( $url, 'https://www.dropbox.com/' ) && str_ends_with( $url, '&dl=0' ) ) { | |
| 220 | - // Dropbox shared link to direct download link. | |
| 221 | - $url = str_replace( '&dl=0', '&dl=1', $url ); | |
| 222 | - } | |
| 223 | - | |
| 224 | - return $url; | |
| 225 | - } | |
| 226 | - | |
| 227 | - /** | |
| 228 | 188 | * Replaces ZIP archives in the import files with a list of their contents. |
| 229 | 189 | * |
| 230 | 190 | * ZIP files are removed from the list and their contents are added to the end of the list. |
| 231 | 191 | * |
| @@ -243,12 +203,8 @@ | ||
| 243 | 203 | continue; |
| 244 | 204 | } |
| 245 | 205 | |
| 246 | 206 | $file->extension = strtolower( pathinfo( $file->name, PATHINFO_EXTENSION ) ); |
| 247 | - if ( '' === $file->extension ) { | |
| 248 | - // If the file name has no extension, try to get it from the location (as WordPress tries adding an extension to that based on the MIME type, e.g. when downloading files). | |
| 249 | - $file->extension = strtolower( pathinfo( $file->location, PATHINFO_EXTENSION ) ); | |
| 250 | - } | |
| 251 | 207 | |
| 252 | 208 | if ( function_exists( 'mime_content_type' ) ) { |
| 253 | 209 | $mime_type = mime_content_type( $file->location ); |
| 254 | 210 | if ( false !== $mime_type ) { |
| @@ -413,9 +369,9 @@ | ||
| 413 | 369 | */ |
| 414 | 370 | protected function extract_zip_file_pclzip( File $zip_file ) /* : array|WP_Error */ { |
| 415 | 371 | mbstring_binary_safe_encoding(); |
| 416 | 372 | |
| 417 | - require_once ABSPATH . 'wp-admin/includes/class-pclzip.php'; | |
| 373 | + require_once ABSPATH . 'wp-admin/includes/class-pclzip.php'; // @phpstan-ignore requireOnce.fileNotFound (This is a WordPress core file that always exists.) | |
| 418 | 374 | |
| 419 | 375 | $archive = new PclZip( $zip_file->location ); |
| 420 | 376 | $archive_files = $archive->extract( PCLZIP_OPT_EXTRACT_AS_STRING ); // @phpstan-ignore arguments.count (PclZip::extract() uses `func_get_args()` to handle optional arguments.) |
| 421 | 377 | |
| @@ -678,9 +634,9 @@ | ||
| 678 | 634 | if ( '' === $format ) { |
| 679 | 635 | $format = 'csv'; |
| 680 | 636 | } |
| 681 | 637 | |
| 682 | - if ( ! in_array( $format, $this->importer->import_formats, true ) ) { // @phpstan-ignore property.notFound (`$this->importer` is an instance of `TablePress_Import_Legacy` which has the property `import_formats`.) | |
| 638 | + if ( ! isset( $this->importer->import_formats[ $format ] ) ) { | |
| 683 | 639 | return new WP_Error( 'table_import_legacy_unknown_format', '', $file->name ); |
| 684 | 640 | } |
| 685 | 641 | |
| 686 | 642 | $table = $this->importer->import_table( $format, $data ); |