flushedpancake
Member
Posts: 37
Registered: 4-1-2024
Member Is Offline
Mood: Optimistic
|
|
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]
|
|
lottos
Administrator
Posts: 477
Registered: 6-3-2002
Member Is Offline
Mood: pass me a TimTam
|
|
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]
|
|
|
flushedpancake
Member
Posts: 37
Registered: 4-1-2024
Member Is Offline
Mood: Optimistic
|
|
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]
|
|
lottos
Administrator
Posts: 477
Registered: 6-3-2002
Member Is Offline
Mood: pass me a TimTam
|
|
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.
|
|
flushedpancake
Member
Posts: 37
Registered: 4-1-2024
Member Is Offline
Mood: Optimistic
|
|
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]
|
|