News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

New BBcode ( Alternate [code] )

Started by [SAP]Francis, November 17, 2007, 07:56:08 AM

Previous topic - Next topic

[SAP]Francis

Hi I need to add [pawn][/pawn] BBcodes. You can find what they do here. It's the same thing as [ code ] but it has colors in it. Example:

public = blue
return = blue
// <text> = green ( Only that line )
/* text */ = green ( All inside that )
sizeof = blue
switch = blue
true = blue
false = blue
#<text> = blue ( Only that line )
new = blue
OTHER = black


Any help Please?

PS: I really suck in PHP, that's why I ask... I am able to seek and replace though...

Vehicles Forum

Founded By Francis Morissette

Kays

Hi, thats not as simpe as you're first request. But let  me have a look at it. I'm assuming that you only want that text to be coloured. No promises though.

Btw, I assume that this is a spelling errror? swicth = blue

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

[SAP]Francis

Yeah, I edited my post, that's exactly what I want. If you want a preview: http://forum.sa-mp.com/

And yes, its switch.

Vehicles Forum

Founded By Francis Morissette

[SAP]Francis


Vehicles Forum

Founded By Francis Morissette

Kays

#4
That was fun. The brackets on <text> gave me a bit of trouble. :)

In Sources/Subs.pgp find:

array(
'tag' => 'pre',


And above it add:

array(
'tag' => 'pawn',
'type' => 'unparsed_content',
'content' => '<div class="codeheader">' . $txt['pawn'] . ':</div><div class="code">' . ($context['browser']['is_gecko'] ? '<pre style="margin-top: 0; display: inline;">$1</pre>' : '$1') . '</div>',
'validate' => create_function('&$tag, &$data, $disabled', '
global $context;

if (!isset($disabled[\'pawn\']))
{
$data = str_replace(
array(
\'public\',
\'return\',
\'sizeof\',
\'switch\',
\'true\',
\'false\',
),
array(
\'<span style="color: blue;">public</span>\',
\'<span style="color: blue;">return</span>\',
\'<span style="color: blue;">sizeof</span>\',
\'<span style="color: blue;">switch</span>\',
\'<span style="color: blue;">true</span>\',
\'<span style="color: blue;">false</span>\',
), $data);

$data = preg_replace(
array(
\'~// &lt;(.+?)&gt;~i\',
\'~/\*(.+?)\*/~i\',
\'~#&lt;(.+?)&gt;~i\'
),
array(
\'<span style="color: green;">// &lt;$1&gt;</span>\',
\'<span style="color: green;">/*$1*/</span>\',
\'<span style="color: blue;">#&lt;$1&gt;</span>\'
), $data);

// Older browsers are annoying, aren\'t they?
if ($context[\'browser\'][\'is_ie4\'] || $context[\'browser\'][\'is_ie5\'] || $context[\'browser\'][\'is_ie5.5\'])
$data = str_replace("\t", "<pre style=\"display: inline;\">\t</pre>", $data);
elseif (!$context[\'browser\'][\'is_gecko\'])
$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
}'),
'block_level' => true,
),


Now in the defaut theme in the languages folder add the following above ?> at the end of the page in Modifications.english.php

$txt['pawn'] = 'Pawn';

Finally in Post.template.php of the default theme find:

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

and above it add:

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

The one thing you do need to do is to make an image for it and to place it in the images/bbc folder of any theme you might be using. Since it neds a transperant border, check the other images for how it should be.

Here is a sample of what it loooks like

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

[SAP]Francis

Quote from: Kays on November 17, 2007, 12:49:49 PM
That was fun. The brackets on <text> gave me a bit of trouble. :)

In Sources/Subs.pgp find:

array(
'tag' => 'pre',


And above it add:

array(
'tag' => 'pawn',
'type' => 'unparsed_content',
'content' => '<div class="codeheader">' . $txt['pawn'] . ':</div><div class="code">' . ($context['browser']['is_gecko'] ? '<pre style="margin-top: 0; display: inline;">$1</pre>' : '$1') . '</div>',
'validate' => create_function('&$tag, &$data, $disabled', '

if (!isset($disabled[\'pawn\']))
{
                        $data = str_replace(
                        array(
                            \'public\',
                            \'return\',
                            \'// <text>\',
                            \'/* text */\',
                            \'sizeof\',
                            \'switch\',
                            \'true\',
                            \'false\',
                            \'#<text>\'
                        ),
                        array(
                            \'<span style="color: blue;">public</span>\',
                            \'<span style="color: blue;">return</span>\',
                            \'<span style="color: green;">// <text></span>\',
                            \'<span style="color: green;">/* text */</span>\',
                            \'<span style="color: blue;">sizeof</span>\',
                            \'<span style="color: blue;">switch</span>\',
                            \'<span style="color: blue;">true</span>\',
                            \'<span style="color: blue;">false</span>\',
                            \'<span style="color: blue;">#<text></span>\'
                        ), $data);

// Older browsers are annoying, aren\'t they?
if ($context[\'browser\'][\'is_ie4\'] || $context[\'browser\'][\'is_ie5\'] || $context[\'browser\'][\'is_ie5.5\'])
$data = str_replace("\t", "<pre style=\"display: inline;\">\t</pre>", $data);
elseif (!$context[\'browser\'][\'is_gecko\'])
$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
}'),
'block_level' => true,
),


Now in the defaut theme in the languages folder add the following above ?> at the end of the page in Modifications.english.php

$txt['pawn'] = 'Pawn';

Finally in Post.template.php of the default theme find:

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

and above it add:

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

The one thing you do need to do is to make an image for it and to place it in the images/bbc folder of any theme you might be using. Since it neds a transperant border, check the other images for how it should be.

Here is a sample of what it loooks like

Works almost perfect but /* text */ means text can be replaced and when I wrote <text> too..

Vehicles Forum

Founded By Francis Morissette

Kays

That will take a little more work since I'll have to use regular expressions for that. And I'm not that comfortable using then.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

[SAP]Francis

#7
Quote from: Kays on November 17, 2007, 02:23:18 PM
That will take a little more work since I'll have to use regular expressions for that. And I'm not that comfortable using then.
Can you just try, if you are not able to do it, that's not important.

Thanks.

Vehicles Forum

Founded By Francis Morissette

Kays

#8
Got it. I've updated my post with the new code. :)
Replace all of the code in Subs.php

Can you link me to a page with this in action when you've got it working. Curious to see what it looks like.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

[SAP]Francis

#9
Quote from: Kays on November 17, 2007, 07:04:59 PMCan you link me to a page with this in action when you've got it working. Curious to see what it looks like.
Thanks man, I will reply again if I need anything other. Here's the link: http://francismori7.hyperphp.com/seifforum/index.php?topic=18.0

EDIT: It doesn't work, go on the link and see the first line of the pawn code.

Vehicles Forum

Founded By Francis Morissette

Kays

Lol, it is working the way I wrote it.

I had assumed that the brackets "<>" were a part of the code. :)

The thing is that I need a start and end point. For the end point I was using the ">". The other options now are a space, which will limit you to one word. Or a line break, in which case the first example you linked me to might not work properly. But I'll look into it.

I see another problem "format". It looks like you'll need to add a space before and after each keyword in both arrays in the str_replace() code.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

[SAP]Francis

Quote from: Kays on November 17, 2007, 08:25:30 PM
Lol, it is working the way I wrote it.

I had assumed that the brackets "<>" were a part of the code. :)

The thing is that I need a start and end point. For the end point I was using the ">". The other options now are a space, which will limit you to one word. Or a line break, in which case the first example you linked me to might not work properly. But I'll look into it.
Thanks for helping me, continue trying. Please


Quote from: Kays on November 17, 2007, 08:25:30 PMI see another problem "format". It looks like you'll need to add a space before and after each keyword in both arrays in the str_replace() code.
I don't understand that part...

Vehicles Forum

Founded By Francis Morissette

Kays

The first part of format is blue. That's because it's not looking for whole words. Adding a space on either side will resolve that.
Change this \'public\', to \' public \',
And this \'<span style="color: blue;">public</span>\', to this \'<span style="color: blue;"> public </span>\',

For the other problem, this seems to work:

$data = preg_replace(
array(
\'~#(.+?)<br />~i\',
\'~//(.+?)<br />~i\',
\'~/\*(.+?)\*/~i\'
),
array(
\'<span style="color: blue;">#$1<br /></span>\',           
\'<span style="color: green;">//$1<br /></span>\',
\'<span style="color: green;">/*$1*/</span>\'
), $data);

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

[SAP]Francis

#13
When I write ' ', it does: &#039; ' or when I do "HELP: You don't have to enter a comment.", it does "HELP: You don&#039;t have to enter a comment.".

That's my last error.

This is the code I have:

Code (PHP) Select
array(
'tag' => 'pawn',
'type' => 'unparsed_content',
'content' => '<div class="codeheader">' . $txt['pawn'] . ':</div><div class="code">' . ($context['browser']['is_gecko'] ? '<pre style="margin-top: 0; display: inline;">$1</pre>' : '$1') . '</div>',
'validate' => create_function('&$tag, &$data, $disabled', '
global $context;

if (!isset($disabled[\'pawn\']))
{
$data = str_replace(
array(
\'public\',
\'return\',
\'sizeof\',
\'switch\',
\'true\',
\'false\',
\'if\',
\'new\',
\'else\',
\'for(\',
\'while\'
),
array(
\'<span style="color: blue;">public</span>\',
\'<span style="color: blue;">return</span>\',
\'<span style="color: blue;">sizeof</span>\',
\'<span style="color: blue;">switch</span>\',
\'<span style="color: blue;">true</span>\',
\'<span style="color: blue;">false</span>\',
\'<span style="color: blue;">if</span>\',
\'<span style="color: blue;">new</span>\',
\'<span style="color: blue;">else</span>\',
\'<span style="color: blue;">for</span>(\',
\'<span style="color: blue;">while</span>\'

), $data);

$data = preg_replace(
array(
\'~#(.+?)<br />~i\',
\'~//(.+?)<br />~i\',
\'~/\*(.+?)\*/~i\'
),
array(
\'<span style="color: blue;">#$1<br /></span>\',           
\'<span style="color: green;">//$1<br /></span>\',
\'<span style="color: green;">/*$1*/</span>\'
), $data);

// Older browsers are annoying, aren\'t they?
if ($context[\'browser\'][\'is_ie4\'] || $context[\'browser\'][\'is_ie5\'] || $context[\'browser\'][\'is_ie5.5\'])
$data = str_replace("\t", "<pre style=\"display: inline;\">\t</pre>", $data);
elseif (!$context[\'browser\'][\'is_gecko\'])
$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
}'),
'block_level' => true,
),

Vehicles Forum

Founded By Francis Morissette

Kays

That's curious. ' is the numeric entity for the apostrophe. But it only does it for the first one and not the rest of them.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

[SAP]Francis

Quote from: Kays on November 17, 2007, 09:32:14 PM
That's curious. ' is the numeric entity for the apostrophe. But it only does it for the first one and not the rest of them.
You know why?

Vehicles Forum

Founded By Francis Morissette

Kays

It's probably because it's unparsed. But anything I try to get rid of it just screws the rest up.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

[SAP]Francis

Quote from: Kays on November 17, 2007, 09:58:56 PM
It's probably because it's unparsed. But anything I try to get rid of it just screws the rest up.
Means it can't be fixed? :'(

Vehicles Forum

Founded By Francis Morissette

Kays

I found the line which is giving the problem It's the one for #text. The only solution I can see for now is to eliminate it. But I will look into it further to see if something can be done about it.

For now remove the following lines.

\'~#(.+?)<br />~i\',
and
\'<span style="color: blue;">#$1<br /></span>\',[\code]

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

[SAP]Francis

#19
Quote from: Kays on November 17, 2007, 10:33:46 PM
I found the line which is giving the problem It's the one for #text. The only solution I can see for now is to eliminate it. But I will look into it further to see if something can be done about it.

For now remove the following lines.

\'~#(.+?)<br />~i\',
and
\'<span style="color: blue;">#$1<br /></span>\',[\code]
Ok, I'll delete them. Thanks for helping a n00b in PHP. Continue looking, I'll try some things on my test board.

Vehicles Forum

Founded By Francis Morissette

Advertisement: