Failure to import twitter avatars with long extensions

Failure to import twitter avatars with long extensions

Issue ID:3612
Issue Category:bug
Component:plugin
Priority:normal
Status:active
Assigned:evan
Version:1.0
Keywords:avatar, extension, filename, twitter

The TwitterBridge plugin has a bug that causes avatars to not be imported whenever a file extension is longer than 3 characters like e.g. .jpeg

A patch is attached.

Also there's a problem when people upload their twitter avatar without any extension. I saw this with one of my subscriptions. This should also be fixed, but is not fixed in the attached patch.

AttachmentSize
twitteravatar.patch623 bytes

Updates

#1

I have been working quite a lot in modifying TwitterBridge and have come up with a solution that I'm currently using on freesocial.org

My TwitterBridge twitterimport.php file can be found at http://gitorious.org/~mmn/statusnet/freesocial/blobs/master/plugins/Twit...

* In function checkAvatar the filename construction is like this:
$path_parts = pathinfo($user->profile_image_url);
$ext = $path_parts['extension'];
$img_root = basename($path_parts['basename'], "_normal.{$ext}");
$newname = "Twitter_{$user->id}-original-{$img_root}.{$ext}";

* In function updateAvatar it's like this:
$path_parts = pathinfo($user->profile_image_url);
$ext = $path_parts['extension'];
$img_root = basename($path_parts['basename'], "_normal.{$ext}");
$url = $path_parts['dirname'] . "/{$img_root}_reasonably_small.{$ext}";
$filename = "Twitter_{$user->id}-original-{$img_root}.{$ext}";

This may differ from vanilla StatusNet as my Avatar fixes are also applied there:
https://gitorious.org/statusnet/mainline/merge_requests/186

...would you (and others) prefer my use of basename() or your patch if I make a merge request at Gitorious? .)

#2

I'd be happy if your changes would be merged. The only thing is that they don't seem to resolve the bug that occurs when twitter users have avatars without file name extension like http://twitter.com/joindiaspora

#3

Hm, I'll have to look at how important the $pathparts['extension'] is in deciding.

From what I remember off the top of my head that's done using the MIME_Type class, which is much more accurate than trusting a file extension. But there's a risk there is some small snippets of code that have to be rewritten.

I'll see what I can do! .)

#4

This should take care of extension-less as well as long-extension filenames!
https://gitorious.org/statusnet/mainline/merge_requests/192

Attaching diff

AttachmentSize
4c853f8117dcc47d689d2fcccc63ed457f110abd.txt 2.68 KB

#5

Hm I noticed however that my merge request doesn't handle the situation as it should when the extension is '.jpeg'

To do that the getMediatype() function must handle the '.jpeg' case next to the '.jpg'. (or the returned mediatype will be 'image/png').

Do you have any examples of Twitter users that have 'jpeg' extensions? I couldn't find any in my brief inspection.

#6

Hi Mikael, thanks for your great work! I hope Evan gives you commit access to statusnet mainline soon! :)

Here's a Twitter user using .jpeg extension: https://twitter.com/#!/SeeroiberJenny

Login or Register to modify this issue, or to receive updates by email.

You can also subscribe to the RSS feed for updates to this issue.