Jump to content

bbcode image size


drisate

Recommended Posts

Hey guys. I am currently using an old version of the joomlaboard made out a very very old version of the simple machine forum. That board currently has a very basic bbcode feature. One thing that annoys me allot is that members can use the tag but when it's larger then 430px it breaks the webpage layout.

 

What i would like to do is find a way to detect the size and max it at 430

 

This is what the code looks like:

 

messageString = messageString.replace(/\[img size=([1-4][0-9][0-9])\](.*?)\[\/img\]/g,"<img src=\"$2\" border\"0\" alt=\"\" width=\"$1"\">");

messageString = messageString.replace(/\[img\](.*?)\[\/img\]/g,"<img src=\"$1\" border\"0\" alt=\"\" />");

 

I can do this in PHP but Javascript is beyond my comprehension ...

From what i understand the first one use $1 as the size value so if ($1>'"430") $i="430" How can i put that in there?

In the second part, we don't have the size value but the image source. So we need to extract the width of the image and if it's bigger than 430 restrict it to 430. But again, how to do i do that in javascript?

 

the full code look like this:

messageString = messageString.replace(/\[img size=([1-4][0-9][0-9])\](.*?)\[\/img\]/g,"<img src=\"$2\" border\"0\" alt=\"\" width=\"$1"\">");
messageString = messageString.replace(/\[img\](.*?)\[\/img\]/g,"<img src=\"$1\" border\"0\" alt=\"\" />");
messageString = messageString.replace(/(\[url\])(.*?)(\[\/url\])/g,"<a href=$2 target=\"_blank\">$2</a>");
messageString = messageString.replace(/\[url=(.*?)\](.*?)\[\/url\]/g,"<a href=\"$1\" target=\"_blank\">$2</a>");
messageString = messageString.replace(/\[size=([1-7])\](.+?)\[\/size\]/g,"<font size=\"$1\">$2</font>");
messageString = messageString.replace(/\[color=(.*?)\](.*?)\[\/color\]/g,"<span style=\"color: $1\">$2</span>");
messageString = messageString.replace(/\[file name=(.*?) size=(.*?)\](.*?)\[\/file\]/g,"<div class=\"sb_file_attachment\"><span class=\"contentheading\">File Attachment:</span><br>File name: <a href=\"$3\">$1</a><br>File size:$2 bytes</div>");

Link to comment
https://forums.phpfreaks.com/topic/137142-bbcode-image-size/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.