Skip to content
This repository has been archived by the owner on Oct 13, 2020. It is now read-only.

Non-standard file extensions return incorrect cached filename #121

Open
doytch opened this issue Mar 18, 2015 · 0 comments
Open

Non-standard file extensions return incorrect cached filename #121

doytch opened this issue Mar 18, 2015 · 0 comments

Comments

@doytch
Copy link

doytch commented Mar 18, 2015

We're currently using WPThumb to provide caching for images in RSS feeds and just had a support ticket that revealed what appears to be an interesting little bug in wpthumb().

The URLs we're having issues with are of the following type:
http:https://static.wixstatic.com/media/d0e46d_df8b7f8076b84f9e993305c484132979.jpg_srb_300_300_75_22_0.50_1.20_0.00_jpg_srb

Obviously, the filename has a few quirks in it. When the image is downloaded and stored in the cached folder, everything appears to be functioning well. For example, that image will get stored some place like wp-content/uploads/cache/remote/static-wixstatic-com/3427518221.jpg

However, when we attempt to look up the cached path for it later, wpthumb() returns an URL like wp-content/uploads/cache/remote/static-wixstatic-com/3427518221.00_jpg_srb. Note the extension is .00_jpg_srb rather than .jpg

In the meantime, I've worked around this with our customers by using the following filter:

add_filter( 'wpthumb_cache_file_path', 'my_interpret_bad_extensions', 10, 2);
function my_interpret_bad_extensions( $path, $obj ) {
    $basename = basename( $path );
    $dirname = dirname( $path );
    $components = explode( '.', $basename );

    if ( sizeof( $components ) !== 2 ) {
        return $path;
    }

    $name = $components[0];
    $ext = $components[1];

    if ( strlen( $ext ) > 4 ) {
        if ( stripos( $ext, 'jpg' ) !== FALSE ) {
            $ext = 'jpg';
        } else if ( stripos( $ext, 'png' ) !== FALSE ) {
            $ext = 'png';
        } else if ( stripos( $ext, 'gif' ) !== FALSE ) {
            $ext = 'gif';
        }
    }

    return trailingslashit( $dirname ) . $name . '.' . $ext;
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant