| verzia 1.2, 2002/03/18 23:25:53 |
verzia 1.3, 2002/03/25 01:39:41 |
| Riadok 169 class phpTemplate |
|
| Riadok 169 class phpTemplate |
|
| return $array; |
return $array; |
| } |
} |
| |
|
| function setCode($key, $evalcode = '') |
// TODO: constants instead of numbers 1, 2, ... |
| |
|
| |
function setParse($key, $value = '') |
| |
{ |
| |
$this->set($key, $value, 2); |
| |
} |
| |
|
| |
function setCode($key, $value = '') |
| { |
{ |
| $this->set($key, $evalcode, 1); |
$this->set($key, $value, 1); |
| } |
} |
| |
|
| function setValue($key, $value = '') |
function setValue($key, $value = '') |
| Riadok 179 class phpTemplate |
|
| Riadok 186 class phpTemplate |
|
| $this->set($key, $value); |
$this->set($key, $value); |
| } |
} |
| |
|
| function set($key, $value = '', $evalcode = 0) |
function set($key, $value = '', $type = 0) |
| { |
{ |
| if (is_array($key)) { |
if (is_array($key)) { |
| while (list($k, $v) = each($key)) { |
while (list($k, $v) = each($key)) { |
| if (! empty($k)) { |
if (! empty($k)) { |
| /* Empty values are allowed. Empty keys are NOT. */ |
/* Empty values are allowed. Empty keys are NOT. */ |
| |
|
| $this->set($k, $v, $evalcode); |
$this->set($k, $v, $type); |
| } |
} |
| } |
} |
| } |
} |
| else { |
else { |
| if (preg_match('/^[a-zA-Z_][\w\d_]*$/', $key)) { |
if (preg_match('/^[a-zA-Z_][\w\d_]*$/', $key)) { |
| if ($evalcode == 1) { |
if ($type == 1) { |
| $this->_set_vars[$key] = array($value); |
$this->_set_vars[$key] = array($value); |
| preg_match_all('/\$(\w[\w\d_]*)/', $value, $matches); |
preg_match_all('/\$(\w[\w\d_]*)/', $value, $matches); |
| $this->_vars = array_merge($this->_vars, $matches[1]); |
$this->_vars = array_merge($this->_vars, $matches[1]); |
| } |
} |
| elseif ($evalcode == 2) { |
elseif ($type == 2) { |
| // TODO: lots of work |
// TODO: lots of work |
| // $ar = _stringTransform($value); |
$ar = $this->_stringTransform($value); |
| |
|
| |
$this->_array = array_merge( |
| |
array('', 'ob_start();'), $ar, |
| |
array('$'.$key.' = ob_get_contents(); ob_end_clean();'), |
| |
$this->_array); |
| } |
} |
| else { |
else { |
| $this->_set_vars[$key] = $value; |
$this->_set_vars[$key] = $value; |
| Riadok 207 class phpTemplate |
|
| Riadok 219 class phpTemplate |
|
| } |
} |
| } |
} |
| |
|
| return; |
return true; |
| |
} |
| |
|
| |
function getParse() |
| |
{ |
| |
$ret .= $this->_tag[begin_striped] . $this->_tag[command_striped]; |
| |
|
| |
foreach ($this->_set_vars as $key => $val) { |
| |
if (! is_array($val)) { |
| |
$ret .= str_replace("\n", '\'."\n".\'', '$' . $key . '=\'' |
| |
. str_replace("'", "\'", $val) . '\';'); |
| |
} |
| |
} |
| |
|
| |
$ret .= $this->_tag[end_striped]; |
| |
|
| |
for ($i = 0; $i < count($this->_array); $i++) { |
| |
// TODO: byte counting (last bit check) |
| |
if ($i % 2) { |
| |
$ret .= $this->_tag[begin_striped] |
| |
. $this->_tag[command_striped] |
| |
. str_replace("\n", '\'."\n".\'', |
| |
$this->_simpleEchoTransform($this->_array[$i])) |
| |
. $this->_tag[end_striped]; |
| |
} |
| |
else { |
| |
$ret .= $this->_array[$i]; |
| |
} |
| |
} |
| |
/* |
| |
echo "<pre>getParse():\n"; |
| |
echo htmlentities($ret); |
| |
echo "</pre>"; |
| |
exit; |
| |
*/ |
| |
return $ret; |
| } |
} |
| |
|
| function getCode() |
function getCode() |
| { |
{ |
| |
$ret = ''; |
| |
|
| foreach ($this->_set_vars as $key => $val) { |
foreach ($this->_set_vars as $key => $val) { |
| if (! is_array($val)) { |
if (! is_array($val)) { |
| $ret .= ('$' . $key . '=\'' |
$ret .= ('$' . $key . '=\'' |
| Riadok 222 class phpTemplate |
|
| Riadok 271 class phpTemplate |
|
| for ($i = 0; $i < count($this->_array); $i++) { |
for ($i = 0; $i < count($this->_array); $i++) { |
| // TODO: byte counting (last bit check) |
// TODO: byte counting (last bit check) |
| if ($i % 2) { |
if ($i % 2) { |
| //if (preg_match("/^[\b]*echo[\b]*[\(]?[\b]*\$(\w[\w\d_]*)[\b]*[\)]?[\b]*;[\b]*$/", |
$ret .= $this->_simpleEchoTransform($this->_array[$i]); |
| |
|
| $ret .= $this->_simple_echo_transform($this->_array[$i]); |
|
| } |
} |
| else { |
else { |
| $ret .= ('echo(\'' . str_replace("'", "\'", $this->_array[$i]) |
$ret .= ('echo(\'' . str_replace("'", "\'", $this->_array[$i]) |
| Riadok 234 class phpTemplate |
|
| Riadok 281 class phpTemplate |
|
| } |
} |
| /* |
/* |
| echo "<pre>CODE:\n"; |
echo "<pre>CODE:\n"; |
| echo $ret; |
echo htmlentities($ret); |
| echo "</pre>"; |
echo "</pre>"; |
| */ |
*/ |
| return "{\n" . $ret . "}\n"; |
return "{\n" . $ret . "}\n"; |
| } |
} |
| |
|
| function _simple_echo_transform($str) |
function _simpleEchoTransform($str) |
| { |
{ |
| //echo "<b>SIMPLE ECHO ... called with $str</b><br>"; |
//echo "<b>SIMPLE ECHO ... called with $str</b><br>"; |
| if (preg_match_all('/echo[(]\s*\$(\w[\w\d_]*)\s*[)];/', $str, $matches)) { |
if (preg_match_all('/echo[(]\s*\$(\w[\w\d_]*)\s*[)];/', $str, $matches)) { |
| Riadok 248 class phpTemplate |
|
| Riadok 295 class phpTemplate |
|
| //echo "<b>than matched $val</b><br>"; |
//echo "<b>than matched $val</b><br>"; |
| if (is_array($this->_set_vars[$val])) { |
if (is_array($this->_set_vars[$val])) { |
| //echo "<b>and array founded containing [".$this->_set_vars[$val][0]."]</b><br>"; |
//echo "<b>and array founded containing [".$this->_set_vars[$val][0]."]</b><br>"; |
| $replacement = $this->_simple_echo_transform($this->_set_vars[$val][0]); |
$replacement = $this->_simpleEchoTransform($this->_set_vars[$val][0]); |
| $str = preg_replace('/echo[(]\s*\$'.$val.'\s*[)];/', $replacement, $str); |
$str = preg_replace('/echo[(]\s*\$'.$val.'\s*[)];/', $replacement, $str); |
| } |
} |
| else { |
else { |
| Riadok 265 class phpTemplate |
|
| Riadok 312 class phpTemplate |
|
| function getContent() |
function getContent() |
| { |
{ |
| ob_start(); |
ob_start(); |
| |
//echo "<hr><pre>" . htmlentities($this->getCode()) . "</pre>"; |
| eval($this->getCode()); |
eval($this->getCode()); |
| $content = ob_get_contents(); |
$content = ob_get_contents(); |
| ob_end_clean(); |
ob_end_clean(); |