| verzia 1.5, 2002/05/10 00:35:01 |
verzia 1.6, 2002/07/23 19:41:20 |
|
|
| |
|
| // Los humusos! Extremly fast! |
// Los humusos! Extremly fast! |
| |
|
| |
// IMPORTANT TODO: |
| |
// I *really* think, that storing already modified (I mean quoting issues) |
| |
// variables in _set_vars array shoud increase performance noticeably! |
| |
|
| |
if (! isset($__phpTemplate_fnc_idx)) { |
| |
$__phpTemplate_fnc_idx = 0; |
| |
} |
| |
|
| |
define(PHP_TEMPLATE_METHOD_NORMAL, 0); |
| |
define(PHP_TEMPLATE_METHOD_FUNCTION, 1); |
| |
define(PHP_TEMPLATE_METHOD_VAR_KEEP, 2); |
| |
|
| class phpTemplate |
class phpTemplate |
| { |
{ |
| var $_cstr = array( |
var $_cstr = array( |
| Riadok 33 class phpTemplate |
|
| Riadok 45 class phpTemplate |
|
| var $_vars = array(); |
var $_vars = array(); |
| var $_set_vars = array(); |
var $_set_vars = array(); |
| var $_debug = 1; |
var $_debug = 1; |
| |
var $_method; |
| |
|
| function phpTemplate($filename = '') |
function phpTemplate($filename = '', $method = PHP_TEMPLATE_METHOD_NORMAL) |
| { |
{ |
| foreach (array_keys($this->_tag) as $key) { |
foreach (array_keys($this->_tag) as $key) { |
| $this->_tag[$key] = preg_quote($this->_tag[$key]); |
$this->_tag[$key] = preg_quote($this->_tag[$key]); |
| $this->_tag[$key.'_striped'] = stripslashes($this->_tag[$key]); |
$this->_tag[$key.'_striped'] = stripslashes($this->_tag[$key]); |
| } |
} |
| |
|
| |
$this->_method = $method; |
| $this->_filename = $filename; |
$this->_filename = $filename; |
| $this->reload(); |
$this->reload(); |
| |
|
| Riadok 196 class phpTemplate |
|
| Riadok 210 class phpTemplate |
|
| $this->set($k, $v, $type); |
$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 ($type == 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 ($type == 2) { |
| elseif ($type == 2) { |
|
| // TODO: lots of work |
// TODO: lots of work |
| $ar = $this->_stringTransform($value); |
$ar = $this->_stringTransform($value); |
| |
|
| Riadok 212 class phpTemplate |
|
| Riadok 224 class phpTemplate |
|
| array('', 'ob_start();'), $ar, |
array('', 'ob_start();'), $ar, |
| array('$'.$key.' = ob_get_contents(); ob_end_clean();'), |
array('$'.$key.' = ob_get_contents(); ob_end_clean();'), |
| $this->_array); |
$this->_array); |
| } |
} else { |
| else { |
|
| $this->_set_vars[$key] = $value; |
$this->_set_vars[$key] = $value; |
| } |
} |
| } |
} |
| Riadok 261 class phpTemplate |
|
| Riadok 272 class phpTemplate |
|
| function getCode() |
function getCode() |
| { |
{ |
| $ret = ''; |
$ret = ''; |
| /* |
/* |
| foreach ($this->_vars as $key) { |
foreach ($this->_vars as $key) { |
| if (isset($this->_set_vars[$key])) { |
if (isset($this->_set_vars[$key])) { |
| $val = $this->_set_vars[$key]; |
$val = $this->_set_vars[$key]; |
| |
if (! is_array($val)) { |
| |
$ret .= ('$' . $key . '=\'' |
| |
. str_replace("'", "\'", |
| |
str_replace("\\", "\\\\", $val)) . '\';' |
| |
. "\n"); |
| |
} |
| |
} |
| |
else { |
| |
$ret .= ('if (!isset($'.$key.'))$' . $key . '=\'\';' . "\n"); |
| |
} |
| |
} |
| |
*/ |
| |
|
| |
/* Note: |
| |
This was old subtitution code. But I turned on full error reporting |
| |
in phpMyEzin project and phptemplate causes undefined variable error. |
| |
*/ |
| |
|
| |
if ($this->_method & PHP_TEMPLATE_METHOD_VAR_KEEP) { |
| |
foreach ($this->_set_vars as $key => $val) { |
| if (! is_array($val)) { |
if (! is_array($val)) { |
| $ret .= ('$' . $key . '=\'' |
$ret .= ('$'.$key.'__phpTemplate_var_bck=$'.$key.';'); |
| . str_replace("'", "\'", |
|
| str_replace("\\", "\\\\", $val)) . '\';' |
|
| . "\n"); |
|
| } |
} |
| } |
} |
| else { |
} |
| $ret .= ('if (!isset($'.$key.'))$' . $key . '=\'\';' . "\n"); |
|
| |
foreach ($this->_set_vars as $key => $val) { |
| |
if (! is_array($val)) { |
| |
$ret .= ('$' . $key . '=\'' |
| |
. str_replace("'", "\'", str_replace("\\", "\\\\", $val)) |
| |
. '\';' . "\n"); |
| } |
} |
| } |
} |
| */ |
|
| /* Note: |
|
| This was old subtitution code. But I turned on full error reporting |
|
| in phpMyEzin project and phptemplate causes undefined variable error. |
|
| */ |
|
| |
|
| foreach ($this->_set_vars as $key => $val) { |
|
| if (! is_array($val)) { |
|
| $ret .= ('$' . $key . '=\'' |
|
| . str_replace("'", "\'", str_replace("\\", "\\\\", $val)) . '\';' . "\n"); |
|
| } |
|
| } |
|
| |
|
| |
|
| 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) { |
| $ret .= $this->_simpleEchoTransform($this->_array[$i]); |
$ret .= $this->_simpleEchoTransform($this->_array[$i]); |
| } |
} else { |
| else { |
|
| $ret .= ('echo(\'' . |
$ret .= ('echo(\'' . |
| str_replace("'", "\'", |
str_replace("'", "\'", |
| str_replace("\\", "\\\\", $this->_array[$i])) |
str_replace("\\", "\\\\", $this->_array[$i])) |
| Riadok 303 class phpTemplate |
|
| Riadok 322 class phpTemplate |
|
| } |
} |
| $ret .= "\n"; |
$ret .= "\n"; |
| } |
} |
| |
|
| |
if ($this->_method & PHP_TEMPLATE_METHOD_VAR_KEEP) { |
| |
foreach ($this->_set_vars as $key => $val) { |
| |
if (! is_array($val)) { |
| |
$ret .= ('$'.$key.'=$'.$key.'__phpTemplate_var_bck;'); |
| |
} |
| |
} |
| |
} |
| |
|
| /* |
/* |
| echo "<pre>CODE:\n"; |
echo "<pre>CODE:\n"; |
| echo htmlentities($ret); |
echo htmlentities($ret); |
| echo "</pre>"; |
echo "</pre>"; |
| */ |
*/ |
| return "{\n" . $ret . "}\n"; |
|
| |
if ($this->_method & PHP_TEMPLATE_METHOD_FUNCTION) { |
| |
/* getting function name */ |
| |
global $__phpTemplate_fnc_idx; |
| |
$function_name = '__phpTemplate_function_'.$__phpTemplate_fnc_idx; |
| |
$__phpTemplate_fnc_idx++; |
| |
|
| |
return "if (! function_exists('$function_name')) {" |
| |
." function $function_name() {\n" |
| |
. "$ret\n} }\n\n$function_name();"; |
| |
} |
| |
|
| |
return "{\n$ret\n}\n"; |
| } |
} |
| |
|
| function _simpleEchoTransform($str) |
function _simpleEchoTransform($str) |