Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: Apnomis - maaliskuu 13, 2005, 01:34:44 IP

Otsikko: Is it possible to create my own BBC button?
Kirjoitti: Apnomis - maaliskuu 13, 2005, 01:34:44 IP
I want to create my own BBC button to compliment the current IMG button when users post. Basically it will resize big images to fit into my forum and turn them into a link that when clicked on loads the full sized image in a new window.

To achieve this currently you need to use this code:

[url=http://imagelink/picture.jpg][img width=546]http://imagelink/picture.jpg[/img][/url]

This has the same effect of resizing the picture and making it a link to the picture. But this is a bit difficult so I want there to be a new BB code that does the above automatically, say [imgfit] [/imgfit] or whatever, so they would type this in their post:

[imgfit]http://imagelink/picture.jpg[/imgfit]

And it would do the same thing.

Is this possible? If so how is it done?

Otsikko: Re: Is it possible to create my own BBC button?
Kirjoitti: Louis (CSpotkill) - maaliskuu 13, 2005, 02:21:00 IP
Open /Sources/Subs.php and search for this line. (Should be line 915.)

'~\[img(\s+width=([\d]http://+))?(\s+height=([\d]+))?\s*\](?:<br />)*(.+?)(?:<br />)*\[/img\]~ei' => isset($disabled['img']) ? '\'$5\'' : '\'<img src="$5" alt=""\' . (\'$2\' != \'\' ? \' width="$2"\' : \'\') . (\'$4\' != \'\' ? \' height="$4"\' : \'\') . \' border="0" />\'',

Below that, add something like this. (Change 546 to the desired width.)

// Resize images to fit.  [imgfit]image[/imgfit]
'~\[imgfit\](?:<br />)*(.+?)(?:<br />)*\[/imgfit\]~i' => isset($disabled['imgfit']) ? '$1' : '<a href="$1"><img src="$1" alt="Click for full-size image." width="546" border="0" /></a>',

Open /Themes/default/post.template.php and search for this line. (Should be line 637.)

'img' => array('code' => 'img', 'before' => '[img]', 'after' => '[/img]', 'description' => $txt[435]),

Below that, add something like:

'imgfit' => array('code' => 'imgfit', 'before' => '[imgfit]', 'after' => '[/imgfit]', 'description' => 'Resize images to fit'),

(Make sure there's a imgfit.gif in Themes\default\images\bbc\ for the button icon.)

Example: http://www.cszen.com/testforum/index.php?topic=1.msg7#msg7
Otsikko: Re: Is it possible to create my own BBC button?
Kirjoitti: Apnomis - maaliskuu 14, 2005, 06:19:48 AP
That's great thanks a lot!

I figured out where and how to add it into the theme, but I didn't know where to add it for it to actually recognise it as a command. I'll have a go at editting Subs.php tonight!
Otsikko: Re: Is it possible to create my own BBC button?
Kirjoitti: Apnomis - maaliskuu 14, 2005, 08:40:54 IP
Lainaus käyttäjältä: Louis (CSpotkill) - maaliskuu 13, 2005, 02:21:00 IP
Open /Sources/Subs.php and search for this line. (Should be line 915.)

// Resize images to fit.  [imgfit]http://image[/imgfit]
'~\[imgfit\](?:<br />)*(.+?)(?:<br />)*\[/imgfit\]~i' => isset($disabled['imgfit']) ? '$1' : '<a href="$1"><img src="$1" alt="Click for full-size image." width="546" border="0" /></a>',

Open /Themes/default/post.template.php and search for this line. (Should be line 637.)

'img' => array('code' => 'img', 'before' => '[img]', 'after' => '[/img]', 'description' => $txt[435]),


When I add that into the subs.php file I get this error:

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /usr/www/xxx/xxx/Sources/Subs.php on line 1593

Line 1593 seems completely unrelated, as it's something to do with the random news function, but when I remove the line I've added it works again, any idea what is causing this?
Otsikko: Re: Is it possible to create my own BBC button?
Kirjoitti: [Unknown] - maaliskuu 15, 2005, 03:55:37 AP
Try the below:

Open /Sources/Subs.php and search for this line. (Should be line 915.)

// Resize images to fit.  [imgfit]http://image[/imgfit]
'~\[imgfit\](?:<br />)*(.+?)(?:<br />)*\[/imgfit\]~i' => isset($disabled['imgfit']) ? '$1' : '<a href="$1"><img src="$1" alt="Click for full-size image." width="546" border="0" /></a>',




Open /Themes/default/post.template.php and search for this line. (Should be line 637.)

'img' => array('code' => 'img', 'before' => '[img]', 'after' => '[/img]', 'description' => $txt[435]),

-[Unknown]
Otsikko: Re: Is it possible to create my own BBC button?
Kirjoitti: Louis (CSpotkill) - maaliskuu 15, 2005, 10:44:30 AP
Thanks, Unknown. (Note to self: Use code tags instead of php tags, next time.)

If it still causes that error, look for an extra '] around that line (at least that's what caused it for someone else I was helping).
Otsikko: Re: Is it possible to create my own BBC button?
Kirjoitti: Apnomis - maaliskuu 15, 2005, 06:14:17 IP
Still getting the error? [Unknown] you appear to have used the exact same code? Or was it just that you did the same code in the code brackets?

Louis I can't see any extra '] here is what I copied plus the code above and below it:


// An image.  Width and height can be are optional.
'~\[img(\s+width=([\d]+))?(\s+height=([\d]+))?\s*\](?:<br />)*(.+?)(?:<br />)*\[/img\]~ei' => isset($disabled['img']) ? '\'$5\'' : '\'<img src="$5" alt=""\' . (\'$2\' != \'\' ? \' width="$2"\' : \'\') . (\'$4\' != \'\' ? \' height="$4"\' : \'\') . \' border="0" />\'',
// Resize images to fit.  [imgfit]http://image[/imgfit]
'~\[imgfit\](?:<br />)*(.+?)(?:<br />)*\[/imgfit\]~i' => isset($disabled['imgfit']) ? '$1' : '<a href="$1"><img src="$1" alt="Click for full-size image." width="546" border="0" /></a>',
// Size the font.  [size=large]HELLO![/size]
'~\[size=([\d]{1,2}p[xt]|(?:x-)?small(?:er)?|(?:x-)?large[r]?)\](.+?)\[/size\]~i' => isset($disabled['size']) ? '$2' : '<span style="font-size: $1;">$2</span>',
'~\[size=([\d])\](.+?)\[/size\]~i' => isset($disabled['size']) ? '$2' : '<font size="$1">$2</font>',


This is line 1593:



$context['random_news_line'] ']']']']= $context['news_lines'][rand(0, count($context['news_lines']) - 1)];




What's wrong with it???

Any idea's why it would work on yours but not mine?
Otsikko: Re: Is it possible to create my own BBC button?
Kirjoitti: [Unknown] - maaliskuu 15, 2005, 06:33:17 IP
Are you using Dreamweaver?  That really musses up some code :/.

-[Unknown]
Otsikko: Re: Is it possible to create my own BBC button?
Kirjoitti: Apnomis - maaliskuu 15, 2005, 07:32:31 IP
Yeah I am using Dreamweaver, it's not caused a problem anywhere else?

I'll try editing it in something else...


Edit: It's working now, it was because I openned it with Dreamweaver, it wasn't just line 1593, loads of lines seems to have duplicated bits of code. It's never done that to me before and I've edited loads of template files, and some of the default files with it. Bit of an odd bug???
Otsikko: Re: Is it possible to create my own BBC button?
Kirjoitti: Louis (CSpotkill) - maaliskuu 15, 2005, 10:10:14 IP
Line 1593 had the extra '] I was talking about: ']']']']

It may have been duplicated in a line after that. And yes, it's definitely a bug with dreamweaver.
Otsikko: Re: Is it possible to create my own BBC button?
Kirjoitti: Apnomis - maaliskuu 16, 2005, 04:57:14 AP
Lainaus käyttäjältä: Louis (CSpotkill) - maaliskuu 15, 2005, 10:10:14 IP
Line 1593 had the extra '] I was talking about: ']']']']

It may have been duplicated in a line after that. And yes, it's definitely a bug with dreamweaver.

I wondered if you did and I almost removed them, but when I saw that every line after that had the same configuration of ']']']'] I decided it must of been part of the code! I didn't realise that Dreamweaver would put them there! I wonder if it's anything to do with the length of subs.php? Maybe explain why it hasn't done it before, and why it only went odd after line 1593!

I'll have to see if there's anything on the Dreamweaver website about this...
Otsikko: Re: Is it possible to create my own BBC button?
Kirjoitti: Jerry - maaliskuu 16, 2005, 04:59:56 AP
[Unknown] says that is why your not supposed to use DreamWeaver :P I think they know about the bug not sure...
Otsikko: Re: Is it possible to create my own BBC button?
Kirjoitti: [Unknown] - maaliskuu 16, 2005, 08:02:50 AP
I've never reported it, but it's annoying enough I assumed I wouldn't have to.  It's been in at least the last two major versions of Dreamweaver...

-[unknown]
Otsikko: Re: Is it possible to create my own BBC button?
Kirjoitti: speedracer23 - maaliskuu 18, 2006, 02:01:02 IP
Any suggestions how to create a tag that will resize the images for RC2

eg

[bimg][/bimg]
Would give the same effect as
[img width=320 height=213]image[/img]


I don't want all image tags to be resized (Under the ACP) but only the ones specified.