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

SkippyNa

New member
Affected version
2.0.4
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:
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).
 
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
To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.
 
You're not currently showing as licensed. If you are licensed, please ensure you add your forum username to the "Forum users" page in your Customer area.

We hadn't rolled out the changes here, yet, but I have now. The URL you posted above should now work:

To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.
 
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.
 
Back
Top Bottom