here's everything in functions.php
The line in red is the line where I try to preg_replace {sometext} with $this->TEMP...since I suck at preg* I'm guessing it's to do with that.
<?php
class Template {
var $requiredVars = array();
var $templateVars = array();
var $codeLines = array();
var $forumLines = array();
var $code = array();
var $codeCompiled = array();
var $TEMP;
function forumAssign($forum_ID, $variablesArray) {
$createCode = '$this->forumLines[' . $forum_ID . '] = $variablesArray;';
eval($createCode);
return TRUE;
}
function createDocument($fileName) {
GLOBAL $total_category;
GLOBAL $total_forum;
$this->loadFile($fileName);
$this->templateVars = array_merge($this->templateVars, $this->requiredVars);
$this->codeCompiled = $this->parseCode();
eval($this->codeCompiled);
return TRUE;
}
function parseCode() {
GLOBAL $total_category;
GLOBAL $total_forum;
for ($i = 0; $i < sizeof($this->code); $i++) {
$currentLine = $this->code[$i];
if (preg_match("<!-- START (.*?) -->", $currentLine, $startString)) {
$this->codeLines[$i] = '$' . $startString[1] . '_count = $total_' . $startString[1] . ';';
if (strtoupper($startString[1]) == "FORUM") {
$this->codeLines[$i] .= "\n" . '$getForums = 1;';
}
$this->codeLines[$i] .= "\n" . 'for ($' . $startString[1] . '_current = 0; $' . $startString[1] . '_current < $' . $startString[1] . '_count; $' . $startString[1] . '_current++) {' . "\n";
$this->codeLines[$i] .= "\n" . 'if ($getForums == 1) {';
$this->codeLines[$i] .= "\n" . ' $currentForumID++;';
$this->codeLines[$i] .= "\n" . ' $this->TEMP = $currentForumID;';
$this->codeLines[$i] .= "\n" . '}';
} elseif (preg_match("<!-- END (.*?) -->", $currentLine, $endString)) {
$this->codeLines[$i] = "\n" . '}';
if (strtoupper($endString[1]) == "FORUM") {
$this->codeLines[$i] .= "\n" . '$getForums = 0;';
}
} else {
$this->codeLines[$i] = 'echo \'' . $currentLine . '\' . "\\n";';
}
foreach($this->templateVars as $key => $value) {
if ($value == "FORUM_NAME") {
[size=large][b][color=red]$this->codeLines[$i] = preg_replace("#{" . $key . "}#si", "$this->TEMP", $this->codeLines[$i]);[/color][/b][/size]
} else {
$this->codeLines[$i] = preg_replace("#{" . $key . "}#si", $value, $this->codeLines[$i]);
}
}
}
$codeReturn = "";
for ($z = sizeof($this->preCode) + 1; $z < $i; $z++) {
$codeReturn .= $this->codeLines[$z];
}
return $codeReturn;
}
function loadFile($fileToLoad) {
$this->code = @file($fileToLoad);
return TRUE;
}
}
?>