Changeset 684622
- Timestamp:
- 03/20/2013 05:12:06 AM (13 years ago)
- Location:
- readymade-wordpress-importer-061/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (2 diffs)
-
wordpress-importer.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
readymade-wordpress-importer-061/trunk/readme.txt
r610536 r684622 1 1 === Plugin Name === 2 2 Contributors: ReadyMadeWeb 3 Donate link: 3 Donate link: 4 4 Tags: importer, wordpress, typepad, movabletype, attachments, import, uploads, transfer 5 5 Requires at least: 3.0 6 6 Tested up to: 3.4 7 Stable tag: 0.6. 47 Stable tag: 0.6.5 8 8 9 9 Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file. … … 33 33 == Changelog == 34 34 35 = 0.6.5 = 36 * Better handling for file names with url-unfriendly characters 37 35 38 = 0.6.4 = 36 * Usage of ssl when doing global host name resolution (when finding where to fetch and attachment from) 39 * Usage of ssl when doing global host name resolution (when finding where to fetch and attachment from) 37 40 * Bug fix for issue when URLs wouldn't be rewritten for attachments without an extension 38 41 -
readymade-wordpress-importer-061/trunk/wordpress-importer.php
r610533 r684622 6 6 Author: wordpressdotorg, snyderp@gmail.com 7 7 Author URI: http://readymadeweb.com 8 Version: 0.6. 48 Version: 0.6.5 9 9 Text Domain: wordpress-importer 10 10 License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html … … 103 103 */ 104 104 function import( $file ) { 105 set_time_limit(600);106 ini_set('max_input_time', 600);107 105 add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) ); 108 106 add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) ); … … 123 121 $this->backfill_attachment_urls(); 124 122 $this->remap_featured_images(); 125 126 123 $this->import_end(); 127 124 } … … 525 522 */ 526 523 function process_posts() { 524 527 525 foreach ( $this->posts as $post ) { 526 528 527 if ( ! post_type_exists( $post['post_type'] ) ) { 529 528 printf( __( 'Failed to import “%s”: Invalid post type %s', 'wordpress-importer' ), … … 598 597 599 598 $comment_post_ID = $post_id = $this->process_attachment( $postdata, $remote_url ); 599 600 600 } else { 601 601 602 $comment_post_ID = $post_id = wp_insert_post( $postdata, true ); 603 602 604 } 603 605 604 606 if ( is_wp_error( $post_id ) ) { 605 printf( __( 'Failed to import %s “%s”', 'wordpress-importer' ), 606 $post_type_object->labels->singular_name, esc_html($post['post_title']) ); 607 if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) 607 if ( $postdata['post_type'] === 'attachment' ) { 608 printf( __( 'Failed to import %s “%s” (%s)', 'wordpress-importer' ), 609 $post_type_object->labels->singular_name, esc_html($post['post_title']), 610 ! empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid']); 611 } else { 612 printf( __( 'Failed to import %s “%s”', 'wordpress-importer' ), 613 $post_type_object->labels->singular_name, esc_html($post['post_title']) ); 614 } 615 if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) { 608 616 echo ': ' . $post_id->get_error_message(); 617 } 609 618 echo '<br />'; 610 619 continue; … … 877 886 // extension information attached. We can get around this limitation 878 887 // by grabbing information about the file from the webserver 879 $file_type = wp_check_filetype( $file_name);888 $file_type = wp_check_filetype( $file_name ); 880 889 881 890 // If there is a situation where we're adding a file extension … … 894 903 } 895 904 896 // get placeholder file in the upload dir with a unique, sanitized filename 897 $upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] ); 905 // First check and see if the file already exists on date, in which 906 // case we'll just use the version on disk instead of downloading 907 // again. 908 $upload_dir = wp_upload_dir( $post['upload_date'] ); 909 $possible_existing_file = $upload_dir['path'] . '/' . $file_name; 910 if ( is_file( $possible_existing_file ) && filesize( $possible_existing_file ) > 0 ) { 911 912 $upload = array( 913 'file' => $possible_existing_file, 914 'url' => $upload_dir['url'] . '/' . $file_name, 915 'error' => false, 916 ); 917 } 918 else { 919 920 // get placeholder file in the upload dir with a unique, sanitized filename 921 $upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] ); 922 } 923 898 924 if ( $upload['error'] ) 899 925 return new WP_Error( 'upload_dir_error', $upload['error'] ); … … 1105 1131 */ 1106 1132 function max_attachment_size() { 1107 return apply_filters( 'import_attachment_size_limit', 0 );1133 return apply_filters( 'import_attachment_size_limit', 10000000 ); 1108 1134 } 1109 1135 … … 1166 1192 curl_setopt( $curl, CURLOPT_HEADER, true ); 1167 1193 curl_setopt( $curl, CURLOPT_NOBODY, true ); 1194 curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true ); 1195 curl_setopt( $curl, CURLOPT_MAXREDIRS, 10 ); 1168 1196 curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true ); 1169 1197 curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 5); … … 1211 1239 function fetch_attachment($url, $file_path) { 1212 1240 1241 // If the file already exists locally, we don't need to re-download 1242 // it. We can instead just read the relevant info off the disk 1243 // and save some network time 1244 if ( file_exists( $file_path ) && filesize( $file_path ) > 100) { 1245 1246 return array( 1247 'response' => '200', 1248 'content-length' => filesize( $file_path ), 1249 ); 1250 } 1251 1213 1252 $url_parts = parse_url( $url ); 1214 1253 $world_ip = $this->global_ip_for_host( $url_parts['host'] ); … … 1227 1266 $headers = array('Host: ' . $url_parts['host']); 1228 1267 1229 $url = $url_parts['scheme'] . "://" . $world_ip . $url_parts['path'];1268 $url = $url_parts['scheme'] . "://" . $world_ip . str_replace(' ', '%20', $url_parts['path']); 1230 1269 1231 1270 $curl = curl_init(); … … 1233 1272 curl_setopt( $curl, CURLOPT_URL, $url ); 1234 1273 curl_setopt( $curl, CURLOPT_HEADER, false ); 1274 curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true ); 1275 curl_setopt( $curl, CURLOPT_MAXREDIRS, 10 ); 1235 1276 curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true ); 1236 1277
Note: See TracChangeset
for help on using the changeset viewer.