Hi I need to add [pawn][/pawn] BBcodes. You can find what they do here (http://forum.sa-mp.com). 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...
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
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.
Can you help me with it?
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(
\'~// <(.+?)>~i\',
\'~/\*(.+?)\*/~i\',
\'~#<(.+?)>~i\'
),
array(
\'<span style="color: green;">// <$1></span>\',
\'<span style="color: green;">/*$1*/</span>\',
\'<span style="color: blue;">#<$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,
),
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 (http://www.kayssplace.com/boards3/index.php?topic=3.msg11#msg11)
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 (http://www.kayssplace.com/boards3/index.php?topic=3.msg11#msg11)
Works almost perfect but /* text */ means text can be replaced and when I wrote <text> too..
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.
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.
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.
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.
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.
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...
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);
When I write ' ', it does: ' ' or when I do "HELP: You don't have to enter a comment.", it does "HELP: You don't have to enter a comment.".
That's my last error.
This is the code I have:
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,
),
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.
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?
It's probably because it's unparsed. But anything I try to get rid of it just screws the rest up.
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? :'(
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]
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.
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.
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. (https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Ffrancismori7.hyperphp.com%2Fseifforum%2FSmileys%2Fdefault%2Ficon_wink.gif&hash=3604f8a8c22bec1154d59cd484e5600d834a3189)
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\',
\'(\',
\')\',
\'[\',
\']\',
\'{\',
\'}\',
\''\'
),
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);
This doesn't work for now. It just ****s up everything.
Example: "true = color: blue">true"
Francis
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,
),
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.
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.
Okay, I found a way to enable [color] in [pawn]. Thanks for everything you made for me!!!!!!!!!!!
Francis
Good I'm glad you got something to work. :)
Look at your PMs on my forum ;).
Lol, I didn't have notification on. Thanks. :D
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!
Kays, is it possible to make it compatible on 2.0 beta 3? Thanks.
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
This is NOT for 2.0.
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
There is no code for 2.0 and I will not support it anyways.
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.
That's an easy fix though.
Quote from: [SAP]Francis on June 08, 2010, 11:16:41 PM
That's an easy fix though.
The # color issue? Please share the fix.