Changeset 1202006
- Timestamp:
- 07/19/2015 10:40:19 PM (11 years ago)
- Location:
- tp2wp-importer/trunk
- Files:
-
- 3 edited
-
CHANGELOG.md (modified) (1 diff)
-
attachments/functions.php (modified) (10 diffs)
-
tp2wp-importer.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tp2wp-importer/trunk/CHANGELOG.md
r1201963 r1202006 1 1 TP2WP Wordpress plugin Changelog 2 2 === 3 4 1.0.10 5 --- 6 * Handle rewriting links to popup versions of images within the plugin 7 (previously was only handled in the [coversion](https://convert.tp2wp.com/) 8 process. 9 * Remove some redundant checking on remote mimetypes, for some quicker 10 imports. 11 * Small, code-style cleanups 3 12 4 13 1.0.9 -
tp2wp-importer/trunk/attachments/functions.php
r1192055 r1202006 86 86 foreach ( $attachments as $url ) { 87 87 88 // First check and see if the extracted attachment looks like a file 88 // There are some cases where we want to modify the URL as we're 89 // processing it, so want to have a copy of the original url 90 // before processing, so that we are sure to rewrite all references 91 // in the body and the excerpt. 92 $found_attachment_url = $url; 93 94 // First, check and see if the given attachment is on a domain 95 // we're watching for files to import. If its not, then we 96 // can trivially skip it. 97 $is_on_domain = tp2wp_importer_attachments_is_url_on_domains( $url, $domains ); 98 if ( ! $is_on_domain ) { 99 $work_performed[$found_attachment_url] = array( false, __( 'Not from a domain being imported from.' ) ); 100 continue; 101 } 102 103 // Next, we can also quickly check to see if the given URL looks like 104 // a TypePad popup URL, which doesn't actually point to a new file, 105 // but instead just points to the file with "-popup" attached to the end. 106 // In this case, we don't want to worry about the attachment itself, 107 // we just instead want to always rewrite the link with the -popup 108 // removed (and then fallback on the redirection from the /.a/ version 109 // of the attachment (using the old typepad pattern) to the wordpress 110 // location. 111 if ( tp2wp_importer_attachments_is_popup_url( $url ) ) { 112 $url = substr( $url, 0, strlen( $url ) - 6 ); 113 } 114 115 // Next, check and see if the extracted attachment looks like a file 89 116 // that should be imported at all. If its not, we can store that 90 117 // result and continue on to the next item quickly. 91 $rs = tp2wp_importer_attachments_should_import_attachment( $url , $domains);118 $rs = tp2wp_importer_attachments_should_import_attachment( $url ); 92 119 list( $should_be_imported, $error ) = $rs; 93 120 94 121 if ( ! $should_be_imported ) { 95 $work_performed[$ url] = $rs;122 $work_performed[$found_attachment_url] = $rs; 96 123 continue; 97 124 } … … 103 130 list( $fetched_succeded, $fetched_details ) = $fetched_rs; 104 131 if ( ! $fetched_succeded ) { 105 $work_performed[$ url] = $fetched_rs;132 $work_performed[$found_attachment_url] = $fetched_rs; 106 133 continue; 107 134 } … … 148 175 // Note that we haven't yet changed the text of the post, which we'll 149 176 // do after we've finished importing all of the attachments. 150 $work_performed[$ url] = array( true, $local_url );177 $work_performed[$found_attachment_url] = array( true, $local_url ); 151 178 } 152 179 … … 210 237 // Make sure we don't loop in base64 embedded images 211 238 if ( strpos( $match['img_asset'], 'data:image' ) === 0) { 212 213 239 continue; 214 215 } else {216 217 $asset_url = $match['img_asset'];218 219 240 } 241 242 $asset_url = $match['img_asset']; 220 243 221 244 } elseif ( ! empty( $match['tp_img_asset'] ) ) { … … 287 310 curl_setopt( $curl, CURLOPT_MAXREDIRS, 10 ); 288 311 curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true ); 289 curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 5 );312 curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 5 ); 290 313 $header_info = curl_exec( $curl ); 291 314 curl_close( $curl ); … … 338 361 * @param string $url 339 362 * An absolute URL to a HTTP hosted file. 340 * @param array $domains341 * An array of domains that should be imported from. Files served342 * from hosts not in this list will be ignored. If this is not provided,343 * than the domain check is ignored.344 363 * 345 364 * @return array … … 349 368 * If the first value is true, the second will always be an empty string. 350 369 */ 351 function tp2wp_importer_attachments_should_import_attachment ($url , $domains = null) {370 function tp2wp_importer_attachments_should_import_attachment ($url) { 352 371 353 372 $url_parts = parse_url( $url ); … … 357 376 if ( ! $url_parts ) { 358 377 return array( false, __( 'Unparsable URL' ) ); 359 }360 361 // Similarly, if the remote file is hosted on a domain other than362 // one we've been told to import from, ignore it.363 $domain = strtolower( $url_parts['host'] );364 if ( $domains && ! in_array( $domain, $domains ) ) {365 return array( false, __( 'Not from a domain being imported from.' ) );366 378 } 367 379 … … 389 401 390 402 /** 403 * Returns a boolean description of whether the given URL is hosted on one 404 * of a given array of domains (used to determine whether an attachment 405 * should be imported). 406 * 407 * @param string $url 408 * An absolute URL to a HTTP hosted file. 409 * @param array $domains 410 * An array of domains that should be imported from. Files served 411 * from hosts not in this list will be ignored. If this is not provided, 412 * than the domain check is ignored. 413 * 414 * @return bool 415 * Returns true if the given url is hosted from one of given domains. 416 */ 417 function tp2wp_importer_attachments_is_url_on_domains ($url, $domains = null) { 418 419 $url_parts = parse_url( $url ); 420 421 // If the URL is unpredictably oddly formatted, don't try to make 422 // any more sense of it, just quick fail it 423 if ( ! $url_parts ) { 424 return false; 425 } 426 427 // Similarly, if the remote file is hosted on a domain other than 428 // one we've been told to import from, ignore it. 429 $domain = strtolower( $url_parts['host'] ); 430 if ( $domains && ! in_array( $domain, $domains ) ) { 431 return false; 432 } 433 434 return true; 435 } 436 437 /** 438 * Returns a boolean description of whether the given URL appears to be 439 * a TypePad / MoveableType popup url (ie if it just has '-popup' at the end 440 * of the URL). 441 * 442 * @param string $url 443 * A valid URL to a HTTP(s) hosted file. 444 * 445 * @return bool 446 * A boolean description of whether, from the URL, this looks like a popup 447 * version of an attachment. 448 */ 449 function tp2wp_importer_attachments_is_popup_url ($url) { 450 451 $popup_index = stripos( $url, '-popup' ); 452 453 if ($popup_index === false) { 454 return false; 455 } 456 457 $url_length = strlen( $url ); 458 return ( $popup_index === ( $url_length - 6 ) ); 459 } 460 461 462 /** 391 463 * Returns what the local path for an attachment should be, given a specified 392 464 * upload directory. … … 410 482 */ 411 483 function tp2wp_importer_attachments_import_attachment ($url, $date = null) { 412 413 // First check and see if the given attachment looks like it should be414 // imported at all. If not, we can quick return and not need to415 // process any further.416 $rs = tp2wp_importer_attachments_should_import_attachment( $url );417 list( $success, $error ) = $rs;418 if ( ! $success ) {419 return $rs;420 }421 484 422 485 $local_filename = tp2wp_importer_attachments_generate_local_filename( $url ); -
tp2wp-importer/trunk/tp2wp-importer.php
r1192055 r1202006 7 7 Author: Peter Snyder, ReadyMadeWeb 8 8 Author URI: https://tp2wp.com 9 Version: 1.0. 99 Version: 1.0.10 10 10 Text Domain: tp2wp-importer 11 11 License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
Note: See TracChangeset
for help on using the changeset viewer.