From 0662bd28acffd10dd2501d46b0f4b722ec2a2f3d Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 19 Mar 2005 05:36:36 +0000 Subject: [PATCH] Removed unnecessary extraction of the condition. Made comments clearer and cleaner. Changed the else parser to use the $tag_else variable instead of just '' --- template.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/template.php b/template.php index 71c4f8c..3a25bae 100644 --- a/template.php +++ b/template.php @@ -409,32 +409,30 @@ class DB_Template // we've found ourselves a conditional! if (substr($template, $i, strlen($tag_start)) == $tag_start) { - // where do we end the condition + // where do we end the conditional $end = strpos($template, $tag_start_end, $i); $end += strlen($tag_start_end); - // extract the condition - $condition = substr($template, $i, $end - $i); - // complete the open array_push($stack, $i); //echo "OPEN `$i`: " . print_r($stack, true); } - // do we have an end? - // make sure that it's the whole tag + // do we have an end tag? else if (substr($template, $i, strlen($tag_end)) == $tag_end) { - // calculate the end of the tag + // calculate the position of the end tag $end = $i + strlen($tag_end); // find the most recently opened condition $last = array_pop($stack); + + // how deep are we nested? $depth = count($stack); //echo "CLOSE `$last`: " . print_r($stack, true); - // get the full condition + // get the full conditional $fullspread = substr($template, $last, $end - $last); // remove the beginning tag @@ -446,7 +444,7 @@ class DB_Template // save the expression $expression = stripslashes(substr($conditional, 0, $temp_end)); - // remove the condition from the broken conditional + // remove the expression from the broken conditional $conditional = substr($conditional, strlen($expression) + strlen($tag_start_end)); // remove the tailing end tag @@ -460,16 +458,20 @@ class DB_Template } } + // sort so the top-most ones are done first ksort($parsed); foreach ($parsed AS $depth => $conditionals) { + // sort so we do them in order ksort($conditionals); foreach ($conditionals AS $parsed) { + // replace the old with the new $template = str_replace($parsed['raw'], $parsed['parsed'], $template); } } - $template = str_replace('', '","', $template); + // hackish way to get end tags working + $template = str_replace($tag_else, '","', $template); return $template; } -- 2.22.5