From b357bc3ebb0abcec735b0f388e66de534aef8156 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 13 Aug 2005 18:35:03 +0000 Subject: [PATCH] Now we can do the top level... bah --- template.php | 156 +++++++++++++++++++++++++++------------------------ 1 file changed, 82 insertions(+), 74 deletions(-) diff --git a/template.php b/template.php index c1c8aeb..f9cd185 100644 --- a/template.php +++ b/template.php @@ -474,95 +474,103 @@ class DB_Template // the information about the current active tag $tag_full = array(); - for ($i = 0; $i < strlen($template); $i++) + // start at 0 + $offset = 0; + + while (1) { - // we've found ourselves a conditional! - if (substr($template, $i, strlen($tag_start)) == $tag_start) + if (strpos($template, $tag_start) === false) { - // push the position into the tag stack - if ($tag_full) - { - array_push($stack, $i); - } - else - { - $tag_full['posi'] = $i; - } + break; } - // locate else tags - else if (substr($template, $i, strlen($tag_else)) == $tag_else) + + for ($i = $offset; $i < strlen($template); $i++) { - if (count($stack) == 0 AND !$tag_full['else']) + // we've found ourselves a conditional! + if (substr($template, $i, strlen($tag_start)) == $tag_start) { - $tag_full['else'] = $i; + // push the position into the tag stack + if ($tag_full) + { + array_push($stack, $i); + } + else + { + $tag_full['posi'] = $i; + } } - } - // do we have an end tag? - else if (substr($template, $i, strlen($tag_end)) == $tag_end) - { - if (count($stack) != 0) + // locate else tags + else if (substr($template, $i, strlen($tag_else)) == $tag_else) { - array_pop($stack); - continue; + if (count($stack) == 0 AND !$tag_full['else']) + { + $tag_full['else'] = $i; + } } - - // calculate the position of the end tag - $tag_full['posf'] = $i + strlen($tag_end) - 1; - - // extract the entire conditional from the template - $fullspread = substr($template, $tag_full['posi'], $tag_full['posf'] - $tag_full['posi'] + 1); - - // remove the beginning tag - $conditional = substr($fullspread, strlen($tag_start)); - - // find the end of the expression - $temp_end = strpos($conditional, $tag_start_end); - - // save the expression - $parsed[0] = stripslashes(substr($conditional, 0, $temp_end)); - - // remove the expression from the conditional - $conditional = substr($conditional, strlen($parsed[0]) + strlen($tag_start_end)); - - // remove the tailing end tag - $conditional = substr($conditional, 0, strlen($conditional) - strlen($tag_end)); - - // handle the else - if ($tag_full['else']) + // do we have an end tag? + else if (substr($template, $i, strlen($tag_end)) == $tag_end) { - // now relative to the start of the - echo $relpos = $tag_full['else'] - $tag_full['posi']; + if (count($stack) != 0) + { + array_pop($stack); + continue; + } - echo '>'; + // calculate the position of the end tag + $tag_full['posf'] = $i + strlen($tag_end) - 1; - // now relative to the start of iftrue - echo $temp2 = $relpos - 23; - print_around($conditional, $temp2); + // extract the entire conditional from the template + $fullspread = substr($template, $tag_full['posi'], $tag_full['posf'] - $tag_full['posi'] + 1); + // remove the beginning tag + $conditional = substr($fullspread, strlen($tag_start)); - // data2 = 23 + // find the end of the expression + $temp_end = strpos($conditional, $tag_start_end); - ### - $parsed[1] = substr($conditional, 0, $temp2); - $parsed[2] = substr($conditional, $temp2 + strlen($tag_else)); - } - else - { - $parsed[1] = $conditional; - $parsed[2] = ''; + // save the expression + $parsed[0] = stripslashes(substr($conditional, 0, $temp_end)); + + // remove the expression from the conditional + $conditional = substr($conditional, strlen($parsed[0]) + strlen($tag_start_end)); + + // remove the tailing end tag + $conditional = substr($conditional, 0, strlen($conditional) - strlen($tag_end)); + + // handle the else + if ($tag_full['else']) + { + // now relative to the start of the + $relpos = $tag_full['else'] - $tag_full['posi']; + + // calculate the length of the expression and opening tag + $length = strlen($parsed[0]) + strlen($tag_start) + strlen($tag_start_end); + + // relative to the start of iftrue + $elsepos = $relpos - $length; + + $parsed[1] = substr($conditional, 0, $elsepos); + $parsed[2] = substr($conditional, $elsepos + strlen($tag_else)); + } + // no else to handle + else + { + $parsed[1] = $conditional; + $parsed[2] = ''; + } + #var_dump($parsed); + + // final parsed output + $parsed = '" . ((' . stripslashes($parsed[0]) . ') ? "' . $parsed[1] . '" : "' . $parsed[2] . '") . "'; + + // replace the conditional + $template = str_replace($fullspread, $parsed, $template); + + // reset the parser + $offset = $tag_full['posi'] + strlen($tag_start) + strlen($tag_start_end); + $tag_full = array(); + break; } - #var_dump($parsed); - - // final parsed output - $parsed = '" . ((' . stripslashes($parsed[0]) . ') ? "' . $parsed[1] . '" : "' . $parsed[2] . '") . "'; - - // replace the conditional - $template = str_replace($fullspread, $parsed, $template); - - // reset the parser - //$i = $tag_full['posi'] + strlen($tag_start) + strlen($tag_start_end); - $tag_full = array(); - break; } } -- 2.43.5