1 (edited by whatrevolution 2008-12-16 10:17)

Topic: [request (debug help)] BBcode [center][/center]

[center]I saw a reference to this in another thread, but no explicit request.[/center]

I peeked at Neck's [video] extension and made liberal use of copy/paste to end up with the following code:

Update (Slavok's edit, plus my own):

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE extension SYSTEM "ext-1.0.dtd">

<!--
/**
 * BBCode [center][/center] extension for PunBB forum
 * A new BBcode tag to center text.
 *
 * @author whatrevolution - http://www.honestlyillustrated.com
 * @license GPL - http://www.gnu.org/copyleft/gpl.html
 * @package pun_bbcode_center
 */
-->

<extension engine="1.0">
    <id>bbcode_center</id>
    <title>BBCode [center][/center]</title>
    <version>0.1.1</version>
    <description>A new BBcode tag to center text.</description>
    <author>whatrevolution - http://www.honestlyillustrated.com</author>
    <minversion>1.3</minversion>
    <maxtestedon>1.3.1</maxtestedon>

    <hooks>
        <hook id="ps_start"><![CDATA[

// tag handling function
function handle_center_tag($inputText) {
    return '<div style="text-align:center;">'.$inputText.'</div>';
}

        ]]></hook>

        <hook id="ps_preparse_tags_start"><![CDATA[

// add our tag to the list
$tags[] = 'center';
$tags_opened[] = 'center';
$tags_closed[] = 'center';
// $tags_inline[] = 'center';
// $tags_trim[] = 'center';

        ]]></hook>
        <hook id="ps_do_bbcode_replace"><![CDATA[

// add pattern to catch [center]blahblah[/center]
$pattern[] = '#\[center\](.*?)\[/center\]#se';
$replace[] = 'handle_center_tag(\'$1\')';

        ]]></hook>
    </hooks>
</extension>

Re: [request (debug help)] BBcode [center][/center]

I modified your code, now it works. Report here, if I missed something.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE extension SYSTEM "ext-1.0.dtd">

<!--
/**
 * BBCode [center][/center] extension for PunBB forum
 * A new BBcode tag to center text.
 *
 * @author whatrevolution - http://www.honestlyillustrated.com
 * @license GPL - http://www.gnu.org/copyleft/gpl.html
 * @package pun_bbcode_center
 */
-->

<extension engine="1.0">
    <id>bbcode_center</id>
    <title>BBCode [center][/center]</title>
    <version>0.1.0</version>
    <description>A new BBcode tag to center text.</description>
    <author>whatrevolution - http://www.honestlyillustrated.com</author>
    <minversion>1.3</minversion>
    <maxtestedon>1.3.1</maxtestedon>

    <hooks>
        <hook id="ps_start"><![CDATA[

// tag handling function
function handle_center_tag($inputText) {
    return '<center>'.$inputText.'</center>';
}

        ]]></hook>

        <hook id="ps_preparse_tags_start"><![CDATA[

// add our tag to the list
$tags[] = 'center';
$tags_opened[] = 'center';
$tags_closed[] = 'center';
$tags_inline[] = 'center';
$tags_trim[] = 'center';

        ]]></hook>
        <hook id="ps_do_bbcode_replace"><![CDATA[

// add pattern to catch [center]blahblah[/center]
$pattern[] = '#\[center\](.*?)\[/center\]#se';
$replace[] = 'handle_center_tag(\'$1\')';

        ]]></hook>
    </hooks>
</extension>

3

Re: [request (debug help)] BBcode [center][/center]

Would the above code work with self closing tags such as <hr /> ?

Re: [request (debug help)] BBcode [center][/center]

No, it wouldn't. <hr /> tags not displayed at the page because of css:

.brd br, .brd hr, .brd .hr, .brd .hidden {
    display: none;
    }

5

Re: [request (debug help)] BBcode [center][/center]

Hi Slavok,

the css is editable but is there a way similar to the extension above where the <hr /> tag can be parsed by BBCode. ie by having a custom [hr /] BBCode tag?

Re: [request (debug help)] BBcode [center][/center]

Hi, I think this will be work (after ps_do_bbcode_replace hook):

$pattern[] = '#\[hr\]#i';
$replace[] = '</p><hr/><p>';

7

Re: [request (debug help)] BBcode [center][/center]

Slavok wrote:
$pattern[] = '#\[hr\]#i'; $replace[] = '</p><hr/><p>';

Thanks Slavok,

changed it to

$pattern[] = '#\[hr /\]#i';
$replace[] = '</p><hr/><p>';

for compatibility with existing posts... Works just fine!!!

Re: [request (debug help)] BBcode [center][/center]

Thanks, Slavok.  Regex always gets me in that bind where I over-complicate the pattern, trying to write one that won't be too greedy.  Your (.*?) worries me, but I'll leave it for now.

I got rid of the <center> and replaced with <div>, because PunBB is strict XHTML.

This process showed me a potential defect in the BBCode parser; I'm heading to the bug reports board now.

9

Re: [request (debug help)] BBcode [center][/center]

Im tryed to modifi the extension to work on internal img and url tags.
Aksly it works, buth i not exactli know what i'm dan. I think whidt this modification, the handle_center_tag definition is not required.
Is this secure?

<hook id="ps_do_bbcode_replace"><![CDATA[
                                          
                                          // add pattern to catch [center]blahblah[/center]
                                          $pattern[] = '#\[center\](.*?)\[/center\]#ms';
                                          $replace[] = '<div style="text-align:center">$1</div>';
                                          
                                          ]]></hook>

ps:
I not spyk englis!

Re: [request (debug help)] BBcode [center][/center]

Hello.

I'm thinking about the idea of a table BBCode.  But since tables use several tags (<table>, <caption>, <tr>, <th>, <td>), could this extension work as well for such BBCodese ?  Because my tries I did up to now resulted in a PHP warning message.

Thanks in advance.

Ubuntu Linux 10.04 LTS / Windows XP SP2
GIMP 2.6.8 (advanced), Inkscape (newbie)
XHTML/CSS (advanced), PHP/MySQL (medium)
Don't ask what free software can do for you, but what you can do for free software.