Plugin Directory

Changeset 1202006


Ignore:
Timestamp:
07/19/2015 10:40:19 PM (11 years ago)
Author:
ReadyMadeWeb
Message:

Version 1.0.10 submitted

Location:
tp2wp-importer/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tp2wp-importer/trunk/CHANGELOG.md

    r1201963 r1202006  
    11TP2WP Wordpress plugin Changelog
    22===
     3
     41.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
    312
    4131.0.9
  • tp2wp-importer/trunk/attachments/functions.php

    r1192055 r1202006  
    8686    foreach ( $attachments as $url ) {
    8787
    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
    89116        // that should be imported at all.  If its not, we can store that
    90117        // 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 );
    92119        list( $should_be_imported, $error ) = $rs;
    93120
    94121        if ( ! $should_be_imported ) {
    95             $work_performed[$url] = $rs;
     122            $work_performed[$found_attachment_url] = $rs;
    96123            continue;
    97124        }
     
    103130        list( $fetched_succeded, $fetched_details ) = $fetched_rs;
    104131        if ( ! $fetched_succeded ) {
    105             $work_performed[$url] = $fetched_rs;
     132            $work_performed[$found_attachment_url] = $fetched_rs;
    106133            continue;
    107134        }
     
    148175        // Note that we haven't yet changed the text of the post, which we'll
    149176        // 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 );
    151178    }
    152179
     
    210237                    // Make sure we don't loop in base64 embedded images
    211238                    if ( strpos( $match['img_asset'], 'data:image' ) === 0) {
    212 
    213239                        continue;
    214 
    215                     } else {
    216 
    217                         $asset_url = $match['img_asset'];
    218 
    219240                    }
     241
     242                    $asset_url = $match['img_asset'];
    220243
    221244                } elseif ( ! empty( $match['tp_img_asset'] ) ) {
     
    287310    curl_setopt( $curl, CURLOPT_MAXREDIRS, 10 );
    288311    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
    289     curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 5);
     312    curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 5 );
    290313    $header_info = curl_exec( $curl );
    291314    curl_close( $curl );
     
    338361 * @param string $url
    339362 *   An absolute URL to a HTTP hosted file.
    340  * @param array $domains
    341  *   An array of domains that should be imported from.  Files served
    342  *   from hosts not in this list will be ignored.  If this is not provided,
    343  *   than the domain check is ignored.
    344363 *
    345364 * @return array
     
    349368 *   If the first value is true, the second will always be an empty string.
    350369 */
    351 function tp2wp_importer_attachments_should_import_attachment ($url, $domains = null) {
     370function tp2wp_importer_attachments_should_import_attachment ($url) {
    352371
    353372    $url_parts = parse_url( $url );
     
    357376    if ( ! $url_parts ) {
    358377        return array( false, __( 'Unparsable URL' ) );
    359     }
    360 
    361     // Similarly, if the remote file is hosted on a domain other than
    362     // 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.' ) );
    366378    }
    367379
     
    389401
    390402/**
     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 */
     417function 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 */
     449function 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/**
    391463 * Returns what the local path for an attachment should be, given a specified
    392464 * upload directory.
     
    410482 */
    411483function tp2wp_importer_attachments_import_attachment ($url, $date = null) {
    412 
    413     // First check and see if the given attachment looks like it should be
    414     // imported at all.  If not, we can quick return and not need to
    415     // process any further.
    416     $rs = tp2wp_importer_attachments_should_import_attachment( $url );
    417     list( $success, $error ) = $rs;
    418     if ( ! $success ) {
    419         return $rs;
    420     }
    421484
    422485    $local_filename = tp2wp_importer_attachments_generate_local_filename( $url );
  • tp2wp-importer/trunk/tp2wp-importer.php

    r1192055 r1202006  
    77Author: Peter Snyder, ReadyMadeWeb
    88Author URI: https://tp2wp.com
    9 Version: 1.0.9
     9Version: 1.0.10
    1010Text Domain: tp2wp-importer
    1111License: 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.