Update #2 (final!): All is well now. Here is the code for dynamic_a() which implements nested conditionals:
Code:
function dynamic_a($logician_dfa_incoming1)
{
extract ($GLOBALS);
// Prevent successive conditionals on separate lines from generating
// spurious <br /> after running thru BbCode parser. You might not
// like this, it's optional.
$logician_dfa_incoming1 = ereg_replace("\]\][\r\n\f \t]*\[\[", "]][[", $logician_dfa_incoming1);
// Recursively process nested conditionals
$logician_dfa_incoming1 = trim(dynamic_b($logician_dfa_incoming1));
// Finish up by running result through BbCode parser
if (trim($logician_dfa_incoming1))
{
$parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
$logician_dfa_incoming1 = $parser->do_parse($logician_dfa_incoming1, 1, 1, 1, 1, 1, 1);
}
return $logician_dfa_incoming1;
}
function dynamic_b($dc3dreamer_dfa_incoming1)
{
extract ($GLOBALS);
while (preg_match("/\[\[(.*)\]\](.*)\[\[(\/\\1)\]\]/siU", $dc3dreamer_dfa_incoming1, $matches14))
{
@eval ('if ('.stripslashes($matches14[1]).') { $eval_deger= "1"; } else { $eval_deger= "0"; }');
if ($eval_deger == 1) //if conditional applied, replace with inner text
{
$dc3dreamer_dfa_incoming1 = dynamic_b(str_replace($matches14[0], $matches14[2], $dc3dreamer_dfa_incoming1));
}
else // Conditional not applied, delete the whole chunk
{
$dc3dreamer_dfa_incoming1 = dynamic_b(str_replace($matches14[0], '', $dc3dreamer_dfa_incoming1));
}
}
return $dc3dreamer_dfa_incoming1;
}
The recursion continues until there are no conditionals found, at which point the final result is passed through the BbCodeParser at the end of the first method. The trick was to remove line endings from conditionals that follow one another with just newlines between. They generated extra breaks and line spacing after going through the BbCode parser. You might want to remove the * in the regexp for the call to ereg_replace(). Er, do I really have to name my parameter variable like it might exist in the host page? I hope not, but I copied Logician's style. I would have used sumpin' like $src for the parameter var :nervous:
I'm slowly coming up to speed on PHP :nervous: I was killed by the $bbuserinfo[membergroupids] variable testing against values, till my ancient Perl tablets fell out on the ground. Yumba! It can be an array and it may not even exist! Well, rookie me! I got it now.
This is
so nice! Nested conditionals open up a whole new world of possibilities, but ...
Thank you Logician Thank you Logician Thank you Logician ...