FriendsOfFlarum / formatting

Customize TextFormatter with plugins through the admin interface
MIT License
22 stars 10 forks source link

Imgur images embedded as albums #14

Closed danielunited closed 4 years ago

danielunited commented 4 years ago

Image links from imgur seem to embed it as an album format (with the white imgur borders) instead of the image itself directly.

For example: https://grid.co.il/d/66/4

Comment content: https://i.imgur.com/FUUVV9u.jpg

clarkwinkelmann commented 4 years ago

I don't think there's anything we can do here. This extension simply enables the MediaEmbed feature of TextFormatter https://s9etextformatter.readthedocs.io/Plugins/MediaEmbed/Sites/

It seems MediaEmbed chose to use the "embed" mode of Imgur, which is what you see.

Maybe what you need is the AutoImage extension instead to turn an image link into an IMG tag automatically?

JoshyPHP commented 4 years ago

The more specialized plugins usually override the more generic ones by design. Autoimage won't override MediaEmbed because Autoimage is a catch-all for image URLs whereas MediaEmbed targets specific individual sites.

danielunited commented 4 years ago

I don't think there's anything we can do here. This extension simply enables the MediaEmbed feature of TextFormatter https://s9etextformatter.readthedocs.io/Plugins/MediaEmbed/Sites/

It seems MediaEmbed chose to use the "embed" mode of Imgur, which is what you see.

Maybe what you need is the AutoImage extension instead to turn an image link into an IMG tag automatically?

It used to work well for imgur images, and embed them without treating them as albums. This issue started occurring out of nowhere.

Perhaps we can fix it by letting i.imgur.com links be served as images, and imgur.com links be served as albums?

dsevillamartin commented 4 years ago

Either way, this'd be a change to the TextFormatter plugins - not much this extension can do about it (I don't want to add site specific configurations to this extension, it'll quickly increase in complexity I'm afraid).

JoshyPHP commented 4 years ago

No plan to change the default behaviour. It's configurable for a reason.

dsevillamartin commented 4 years ago

In other words - I think the solution here is to either have a separate extension that modifies the functionality or you change it for your own site through extend.php.

danielunited commented 4 years ago

Autoimage won't override MediaEmbed because Autoimage is a catch-all for image URLs whereas MediaEmbed targets specific individual sites.

No plan to change the default behaviour. It's configurable for a reason.

@JoshyPHP It's configurable, yes, but once again, the fact that this image: https://i.imgur.com/FUUVV9u.jpg is served as an album is a bug. I don't believe there's anyone who wants to show images in that format (with the white borders) unless they're actually an Imgur album.

The better option would be just to embed the image directly.

In other words, Imgur MediaEmbed needs to work for imgur.com links only, instead of i.imgur.com links. If it can't be done due to technical difficulties, that's another matter. But I just wanted to see that we're on the same page about this being a bug.

JoshyPHP commented 4 years ago

"bug" does not mean "something I don't like."

You don't like Imgur's style. If your argument is that it looks bad then I agree, it looks bad. It used to look good, now it looks bad and I wouldn't want to use it. Unfortunately, the plugin has always worked this way and I don't want to change an established, documented, and regression-tested behaviour because Imgur changed the style of their embeds.

If you want to post an image, you can use the image markup. If you want to change the default behaviour for the Imgur media site then change it or create your own. There's a dozen different ways to do that, I don't know which one is the best. You can use your own definition for Imgur and specifically target links from the imgur.com domain excluding i.imgur.com for example. You can alter $configurator->MediaEmbed->defaultSites['imgur'] before the site is added, too. I don't know whether it's a good idea but you could add a filter to the MEDIA tag to nuke URLs you don't like.

$configurator->tags['MEDIA']->filterChain->prepend('filterImgur');
function filterImgur($tag)
{
    if (strpos($tag->getAttribute('url'), 'i.imgur.com') !== false)
    {
        $tag->setAttribute('url', '');
    }
}

It's also possible to invalidate IMGUR tags based on their text content.

$configurator->tags['IMGUR']->filterChain->prepend('filterImgur($tag, $innerText)');
function filterImgur($tag, $innerText)
{
    if (strpos($innerText, 'i.imgur.com') !== false)
    {
        $tag->invalidate();
    }
}