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

Kays

The only way I can get it to work properly is by adding a space after the pound sign. Weird

That's it for me. I've got to work tomorrow so I'm off to bed.

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

[SAP]Francis

But since PAWN is a coding language, it will **** it up. Ok, I'll keep #... in black, that's not so important. I even don't know how can I thank you. Give me ideas, maybe I'll accept.

Vehicles Forum

Founded By Francis Morissette

Kays

Finally figured that problem out. Should of done a View Source earlier. I cheated a little to get around it. :)

Not quite happy with it yet and will play with it a bit more. One of the things which will happen is if a word which is highlighted blue is ued in a comment or elsewhere, it will be blue in colour. For, if else, elseif and while can be vlalidated by checking for the opening brace "(". But not the rest unless what's inside a set of quotes can be identified. I don't know how far I'll get on it though.

But here's what I've got so far.


$data = str_replace(
array(
\'public\',
\'return\',
\'sizeof\',
\'switch\',
\'true\',
\'false\',
\'if\',
\'new\',
\'else\',
\'for(\',
\'while\',
\'(\',
\')\',
\'[\',
\']\',
\'{\',
\'}\',
\'&#039;\'
),
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>\',
\'<span style="color: red;">(</span>\',
\'<span style="color: red;">)</span>\',
\'<span style="color: red;">[</span>\',
\'<span style="color: red;">]</span>\',
\'<span style="color: red;">{</span>\',
\'<span style="color: red;">}</span>\',
\'|||\'
), $data);

$data = preg_replace(
array(
\'~#(.+?)\<br \/>~is\',
\'~\/\/(.+?)\<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);
$data = str_replace(\'|||\', \'&#039;\', $data);

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

[SAP]Francis

#23
This doesn't work for now. It just ****s up everything.
Example: "true = color: blue">true"

Francis

Vehicles Forum

Founded By Francis Morissette

Kays

That's strange. It works fine for me.
http://www.kayssplace.com/boards3/index.php?topic=3.0

Here's all of it
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>\',
\'<span style="color: red;">(</span>\',
\'<span style="color: red;">)</span>\',
\'<span style="color: red;">[</span>\',
\'<span style="color: red;">]</span>\',
\'<span style="color: red;">{</span>\',
\'<span style="color: red;">}</span>\',
\'|||\'
), $data);

$data = preg_replace(
array(
\'~#(.+?)\<br \/>~is\',
\'~\/\/(.+?)\<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);
    $data = str_replace(\'|||\', \''\', $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,
),

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

[SAP]Francis

#25
With this, my forum is now only a white page. -.-

Help me!

http://francismori7.hyperphp.com/seifforum

EDIT: It seems that only the main page does it.

http://francismori7.hyperphp.com/seifforum/index.php?board=4.0

EDIT2: Works again, but not with your code... Only works when I put the old one you gave me.

Vehicles Forum

Founded By Francis Morissette

Kays

Yet I don't have a problem with my test boards. Since I can't see what the problem is. Just use it as is and let's forget about any improvements.

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

[SAP]Francis

Okay, I found a way to enable [color] in [pawn]. Thanks for everything you made for me!!!!!!!!!!!

Francis

Vehicles Forum

Founded By Francis Morissette

Kays

Good I'm glad you got something to work. :)

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

[SAP]Francis


Vehicles Forum

Founded By Francis Morissette

Kays

Lol, I didn't have notification on. Thanks. :D

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 19, 2007, 09:34:21 PM
Lol, I didn't have notification on. Thanks. :D
No problem. You deserve it!

Vehicles Forum

Founded By Francis Morissette

[SAP]Francis

Kays, is it possible to make it compatible on 2.0 beta 3? Thanks.

Vehicles Forum

Founded By Francis Morissette

DarK TeaM PT

yeps because i dont know how to add the one PAWN buttom the tags are working but

this

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

i think isnt anymore implemented on 2.0 RC3 i didnt find it on posts template any guy know how can i do

[SAP]Francis


Vehicles Forum

Founded By Francis Morissette

DarK TeaM PT

yep i know and i already fixed but i have other problem its when we post long Scripts on 1.x versions it automaticly does on the right side the buttom to roll down or up but on 2.0 RC3 not and it does LOOONG Topics... if anyone know the solution please say and btw if there´s code for 2.0 Please send me link or post here i will be thanking so much

[SAP]Francis

There is no code for 2.0 and I will not support it anyways.

Vehicles Forum

Founded By Francis Morissette

Seif

Quote from: DarK TeaM PT on March 17, 2010, 02:33:08 PM
yep i know and i already fixed but i have other problem its when we post long Scripts on 1.x versions it automaticly does on the right side the buttom to roll down or up but on 2.0 RC3 not and it does LOOONG Topics... if anyone know the solution please say and btw if there´s code for 2.0 Please send me link or post here i will be thanking so much
Put it inside a div with overflow on scroll. Other than that, it works fine on SMF 2. Only problem so far is the #. It will make it blue but if the next line also has #, it will be black, but the line after will be blue if you use # again. Still trying to fix the problem.

[SAP]Francis


Vehicles Forum

Founded By Francis Morissette

Seif


Advertisement: