Fixed New longer imgur album links do not display correctly. Code fix inside.

Affected version
2.0.4

SkippyNa

New member
Imgur has changed the ID length of album links, apparently. Now they're not 5 characters anymore, or at least sometimes they are not.

I'm pretty new to Xenforo but I found the bbcode helper for Imgur in src/XF/BbCode/Helper/Imgur.php

The code checks for album links just by seeing if the ID is 5 characters. The below code I changed it to do a string search for the imgur.com/a/ section that the album links seem to always contain. There may be more eloquent solutions, but this one was a quick fix.

PHP:
public static function matchCallback($url, $matchedId, \XF\Entity\BbCodeMediaSite $site, $siteId)
{
        // if (strlen($matchedId) == 5) // XXX: Xenforo 2.0.4 version
        // hack 2018-04-20 fix new longer imgur links
        if (strpos($url, 'imgur.com/a/'))
                {
                        $matchedId = 'a/' . $matchedId;
                }

                return $matchedId;
}
 
Last edited:

Chris D

XenForo developer
Staff member
Thanks. The eventual fix was slightly different and we've now added support for Imgur's "reddit" links (for sub-reddit image hosting on Imgur).
 

SkippyNa

New member
Thanks. The eventual fix was slightly different and we've now added support for Imgur's "reddit" links (for sub-reddit image hosting on Imgur).

Awesome, glad I could help. Is there a place where I can see the final solution? Then I can update mine xenforo install to match it.


Also.. I found another imgur link format that isn't working. I'll look into it as well, but maybe you might know the best way to address it.
Code:
https://imgur.com/gallery/s0xtxYc
 

SkippyNa

New member
You're not currently showing as licensed

Ah yeah, I'm one of 3 guys who run another site and one of the other guys is registered as the licensed Xenforo person :) I'll see if he can add me.

Thanks for getting the fix rolled out :) Looks great. I updated my code for the gallery link too.
 
Top