XMB Forum Software
Not logged in [Login - Register]
Go To Bottom

Printable Version  
Author: Subject: Improved img tag
flushedpancake
Member
***


Avatar


Posts: 37
Registered: 4-1-2024
Member Is Offline

Mood: Optimistic

[*] posted on 4-7-2024 at 11:58 PM
Improved img tag


So what does this do?

Basically it makes images clickable in posts, but also allows the user to only specify an image width and let the browser auto determine the height (untested, but it should work).

In addition, it fixes the issue of posting a massive image and it stretching the tables, by making sure the maximum width is at most 100% of the screen, assuming viewport width is device-width (it's set to 500 for some reason in the header template by default, not sure if that makes any difference).

find in functions.inc.php

Code:
function bbcode_imgs


add after this
Code:
if ( $width < 1 || $height < 1 ) { $size = '';


add this:
Code:
} elseif ( $height < 1 ) { $size = "width='$width'";


and close the statement on the next line and add a space to meet xmb code standards.

replace return statement

Code:
return "<!-- nobr --><a href='$address'><img $size style='max-width:100%!important;' src='$address' alt='' border='0' /></a><!-- /nobr -->";




[insert witty quote here]
View user's profile View All Posts By User
lottos
Administrator
********




Posts: 477
Registered: 6-3-2002
Member Is Offline

Mood: pass me a TimTam

[*] posted on 4-8-2024 at 03:51 AM


Quote: Originally posted by flushedpancake  

Code:
return "<!-- nobr --> <img $size style='max-width:100%!important;' src='$address' alt='' border='0' /></a><!-- /nobr -->";



Is this missing the <a href... part to make the image clickable?

Also, wonder about handling this scenario, where someone posts an image via bbcode with a bbcode link that isn't to the image, eg:

Code:
[url=https://www.3rdPartyLinkedSite.com][img]https://images.somewebsite.com/Page-Banner-1800x700.jpg[/img][/url]
View user's profile View All Posts By User
flushedpancake
Member
***


Avatar


Posts: 37
Registered: 4-1-2024
Member Is Offline

Mood: Optimistic

[*] posted on 4-8-2024 at 07:43 AM


Yeah, by default it is.

And good question, now you mention it. I'd have assumed that the outer HTML tag would "override" the inner one, though this is awful from a semantics POV.

I guess either adding an extra parameter to specify a URL could work in this scenario, but handling existing posts on a large-scale forum to not break is the bigger question... especially given I'm not exactly good at php and do not want to break crap.



[insert witty quote here]
View user's profile View All Posts By User
lottos
Administrator
********




Posts: 477
Registered: 6-3-2002
Member Is Offline

Mood: pass me a TimTam

[*] posted on 4-8-2024 at 11:24 AM


Sorry, I'm probably not explaining it correctly. My post was 2 potential issues.

The 1st is that the code as is didn't supply a clickable image for me, so I assumed that perhaps the code was missing some a href part. If not, then I'm not sure how the image becomes clickable. Neither here nor there, the resizing is the more interesting part for me. Thank you.
View user's profile View All Posts By User
flushedpancake
Member
***


Avatar


Posts: 37
Registered: 4-1-2024
Member Is Offline

Mood: Optimistic

[*] posted on 4-8-2024 at 12:03 PM


I've just realised I accidentally pasted it without the anchor tag... LOL thank you for pointing that out.

Fixing this now.

edit: fixed now. the image should be clickable

also idk if !important is actually needed in the img style but I'm keeping it there just in case, since XMB tends to use HTML tag based widths and whatnot and these need to be overridden in some cases



[insert witty quote here]
View user's profile View All Posts By User

  Go To Top

Powered by XMB 1.9.12 (Debug Mode)
XMB Forum Software © 2001-2024 The XMB Group
[Queries: 16] [PHP: 39.2% - SQL: 60.8%]