XF 2.0 BBCode with multiple options

Hello,

I am looking at merging a rather large community 1 million+ posts from phpBB to Xenforo. However, I've run in to some issues with 2.0 and BBCodes with multiple options, I knew roughly how to do it in Xenforo 1.x but I've had no luck doing it in 2.0

Basically an example of one the most common bbcode formatting we would use would be as followed:

Code:
[flegend=#B40000,#FFFFFF,Title]CONTENT[/flegend]

I was wondering if anyone would be able to point me in the right direction or provide me with some examples?

Any help is appreciated and I am very grateful for all those who take their time to reply.

Thanks,
Jack.
 
Sorry, should have posted a picture.

On our current phpBB installation it looks like this.

To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.
 
Here is my PHP callback for my TD tag from phpBB with 3 parameters.

You can use it like
Code:
[td=classname,rowspan,colspan]xxx[/td]

PHP:
public static function td($tagChildren, $tagOption, $tag, array $options, \XF\BbCode\Renderer\AbstractRenderer $renderer)
{
    $res = $renderer->renderSubTree($tagChildren, $options);
    $toptions = trim(strip_tags($tag['option']));
    $toptions = preg_split("|,|", $toptions, -1, PREG_SPLIT_NO_EMPTY);
    // [td={IDENTIFIER},{NUMBER1},{NUMBER2}]{TEXT}[/td]
    @list($class, $num1, $num2) = $toptions;
    if ($tmp = trim($class)) {
        $classTag = "class=\"$tmp\"";
    }
    if ($tmp = trim($num1)) {
        $rowSpan = "rowspan=\"$tmp\"";
    }
    if ($tmp = trim($num2)) {
        $colSpan = "colspan=\"$tmp\"";
    }
    return "<td {$classTag} {$rowSpan} {$colSpan}>{$res}</td>";
}
 
Here is my PHP callback for my TD tag from phpBB with 3 parameters.

You can use it like
Code:
[td=classname,rowspan,colspan]xxx[/td]

PHP:
public static function td($tagChildren, $tagOption, $tag, array $options, \XF\BbCode\Renderer\AbstractRenderer $renderer)
{
    $res = $renderer->renderSubTree($tagChildren, $options);
    $toptions = trim(strip_tags($tag['option']));
    $toptions = preg_split("|,|", $toptions, -1, PREG_SPLIT_NO_EMPTY);
    // [td={IDENTIFIER},{NUMBER1},{NUMBER2}]{TEXT}[/td]
    @list($class, $num1, $num2) = $toptions;
    if ($tmp = trim($class)) {
        $classTag = "class=\"$tmp\"";
    }
    if ($tmp = trim($num1)) {
        $rowSpan = "rowspan=\"$tmp\"";
    }
    if ($tmp = trim($num2)) {
        $colSpan = "colspan=\"$tmp\"";
    }
    return "<td {$classTag} {$rowSpan} {$colSpan}>{$res}</td>";
}
So this would be added to a file and then uploaded to addons folder? What you have posted above is not the full file though, is it? What else is required?

Then when creating the BBCode, the callback & method would be something like: AddOn\Path\To\td::td
 
This file should be addons/MyAddon/Bbcode/BbcodeParser.php

Then the callback should be: "MyAddon\Bbcode\BbcodeParser::td"

PHP:
<?php
    
namespace MyAddon\Bbcode;

class BbcodeParser {

    public static function td($tagChildren, $tagOption, $tag, array $options, \XF\BbCode\Renderer\AbstractRenderer $renderer)
    {
        $res = $renderer->renderSubTree($tagChildren, $options);
        $toptions = trim(strip_tags($tag['option']));
        $toptions = preg_split("|,|", $toptions, -1, PREG_SPLIT_NO_EMPTY);
        // [td={IDENTIFIER},{NUMBER1},{NUMBER2}]{TEXT}[/td]
        @list($class, $num1, $num2) = $toptions;
        if ($tmp = trim($class)) {
            $classTag = "class=\"$tmp\"";
        }
        if ($tmp = trim($num1)) {
            $rowSpan = "rowspan=\"$tmp\"";
        }
        if ($tmp = trim($num2)) {
            $colSpan = "colspan=\"$tmp\"";
        }
        return "<td {$classTag} {$rowSpan} {$colSpan}>{$res}</td>";
    }

}
 
This file should be addons/MyAddon/Bbcode/BbcodeParser.php

Then the callback should be: "MyAddon\Bbcode\BbcodeParser::td"

PHP:
<?php
   
namespace MyAddon\Bbcode;

class BbcodeParser {

    public static function td($tagChildren, $tagOption, $tag, array $options, \XF\BbCode\Renderer\AbstractRenderer $renderer)
    {
        $res = $renderer->renderSubTree($tagChildren, $options);
        $toptions = trim(strip_tags($tag['option']));
        $toptions = preg_split("|,|", $toptions, -1, PREG_SPLIT_NO_EMPTY);
        // [td={IDENTIFIER},{NUMBER1},{NUMBER2}]{TEXT}[/td]
        @list($class, $num1, $num2) = $toptions;
        if ($tmp = trim($class)) {
            $classTag = "class=\"$tmp\"";
        }
        if ($tmp = trim($num1)) {
            $rowSpan = "rowspan=\"$tmp\"";
        }
        if ($tmp = trim($num2)) {
            $colSpan = "colspan=\"$tmp\"";
        }
        return "<td {$classTag} {$rowSpan} {$colSpan}>{$res}</td>";
    }

}
Brilliant, thanks. That has setup now.

I've tried using something like [td=test,2,2]test[/td] in a post though and all that is being output is the word 'test'. Inspected the element and it's not wrapped in a <td>
 
I've tried using something like [td=test,2,2]test[/td] in a post though and all that is being output is the word 'test'. Inspected the element and it's not wrapped in a <td>
Did you change from "Simple replacement" to "PHP-Callback"? And set parameters to "Yes" or "Optional"?
 
I have no clue then... it works as expected here.
Did you change anything in the code i posted?
Can you post your class?
Odd. I must be doing something wrong!

PHP:
<?php
   
namespace TFC\Bbcode;

class BbcodeParser {

    public static function td($tagChildren, $tagOption, $tag, array $options, \XF\BbCode\Renderer\AbstractRenderer $renderer)
    {
        $res = $renderer->renderSubTree($tagChildren, $options);
        $toptions = trim(strip_tags($tag['option']));
        $toptions = preg_split("|,|", $toptions, -1, PREG_SPLIT_NO_EMPTY);
        // [td={IDENTIFIER},{NUMBER1},{NUMBER2}]{TEXT}[/td]
        @list($class, $num1, $num2) = $toptions;
        if ($tmp = trim($class)) {
            $classTag = "class=\"$tmp\"";
        }
        if ($tmp = trim($num1)) {
            $rowSpan = "rowspan=\"$tmp\"";
        }
        if ($tmp = trim($num2)) {
            $colSpan = "colspan=\"$tmp\"";
        }
        return "<td {$classTag} {$rowSpan} {$colSpan}>{$res}</td>";
    }

}

This is in a file called BbcodeParser.php and uploaded to /src/addons/TFC/BBCode/
 
namespace TFC\Bbcode;
This is in a file called BbcodeParser.php and uploaded to /src/addons/TFC/BBCode/
BBCode in path and Bbcode in namespace. Capitalizing are different. Are you on linux or windows server?
But you should get an error when you saved the settings in admin if the class were not found, so shouldnt be that either.

I dont know - you could debug with putting error-log statements in the td function here and there to see whats happening.
 
Linux server. Fixed the capitalisation issue... but yea, that didn't make a difference. Must be something to do with my setup though. I'll try disabling all addons etc.
 
Top Bottom