XF 2.0 Custom bbcode callback - IF statement?

Case

Well-known member
Is it possible to add an IF statement to a custom bbcode callback so the code return would depend on what the user has entered in the bbcode options?

A basic example of what I'm using below. A bbcode with 2 options...

PHP:
class BbcodeParser {
    public static function test($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);
        @list($option1, $option2) = $toptions;
        if ($tmp = trim($option1)) {
            $one = "$tmp";
        }
        if ($tmp = trim($option2)) {
            $two = "$tmp";
        }
        
        return "{$one} {$two}";
    }
}

So could I add an IF statement in there somewhere to say something like... IF ($option1 = 2) then return "THIS".

I've tried adding one in a few places but none seem to work.
 
if ($tmp = trim($option1)) {
$one = "$tmp";
return "THIS";
}
elseif ($tmp = trim($option2)) {
$two = "$tmp";
return "THAT";
}
else
return "ERROR"
 
if ($tmp = trim($option1)) {
$one = "$tmp";
return "THIS";
}
elseif ($tmp = trim($option2)) {
$two = "$tmp";
return "THAT";
}
else
return "ERROR"
Thanks. How does this work though? So lets say I wanted to get "THAT" to show when the user enters "hello" in the $option2 bbcode option.
 
It's been a while since I handled BBCode callbacks, so don't know it from memory. My guess would be to dump $options and $tagOption
, see what values it takes and then do something like

if($tagOption === "your value") {
// first block
} elseif($tagOption === "hello") {
//second block
}
 
Code:
$toptions = preg_split("|,|", $toptions, -1, PREG_SPLIT_NO_EMPTY);

Don't use regular expression functions unless you gain an actual advantage over native functions in terms of complexity.
The same effect of the code above can be achieved by:
Code:
$toptions = array_values(array_filter(explode(',', $toptions)));
 
Back
Top Bottom