| version 1.4, 2001/11/04 19:55:20 |
version 1.5, 2001/11/10 23:35:54 |
| Line 54 class ObjTemplate |
|
| Line 54 class ObjTemplate |
|
| |
|
| function load($filename) |
function load($filename) |
| { |
{ |
| if (file_exists($filename)) { |
if (file_exists($filename)) { # DEBUG |
| $this->array = $this->_string_transform(join('', file($filename))); |
$this->array = $this->_string_transform(join('', file($filename)), 0); |
| |
|
| return true; |
return true; |
| } |
} |
| Line 95 class ObjTemplate |
|
| Line 95 class ObjTemplate |
|
| |
|
| for ($i = 0; $i < count($ar); $i++) { |
for ($i = 0; $i < count($ar); $i++) { |
| if (is_array($ar[$i])) { |
if (is_array($ar[$i])) { |
| if (! strcmp($key, $ar[$i]['key'])) { |
if (is_array($ar[$i]['key'])) { |
| |
if (true == $this->_is_key($key, $ar[$i]['key'])) |
| |
return true; |
| |
} |
| |
elseif (! strcmp($key, $ar[$i]['key'])) { |
| return true; |
return true; |
| } |
} |
| elseif (! strcmp($this->cmd['if'], $ar[$i]['key'])) { |
elseif (! strcmp($this->cmd['if'], $ar[$i]['key'])) { |
| |
|
| |
if (is_array($ar[$i]['conditions'])) { |
| |
if (true == $this->_is_key($key, $ar[$i]['conditions'])) |
| |
return true; |
| |
} |
| |
else { |
| |
if (! strcmp($key, $ar[$i]['conditions'])) |
| |
return true; |
| |
} |
| |
|
| if (is_array($ar[$i]['true'])) { |
if (is_array($ar[$i]['true'])) { |
| if (true == $this->_is_key($key, $ar[$i]['true'])) |
if (true == $this->_is_key($key, $ar[$i]['true'])) |
| return true; |
return true; |
| Line 142 class ObjTemplate |
|
| Line 155 class ObjTemplate |
|
| { |
{ |
| for ($i = 0; $i < count($ar); $i++) { |
for ($i = 0; $i < count($ar); $i++) { |
| if (is_array($ar[$i])) { |
if (is_array($ar[$i])) { |
| if (! strcmp($key, $ar[$i]['key'])) { |
if (isset($ar[$i]['key'])) { |
| $ar[$i] = $value; |
if (is_array($ar[$i]['key'])) |
| |
$this->_set($key, $value, $ar[$i]['key']); |
| |
else |
| |
if (! strcmp($key, $ar[$i]['key'])) |
| |
$ar[$i] = $value; |
| } |
} |
| elseif (! strcmp($this->cmd['if'], $ar[$i]['key'])) { |
elseif (! strcmp($this->cmd['if'], $ar[$i]['key'])) { |
| |
if (is_array($ar[$i]['conditions'])) |
| |
$this->_set($key, $value, $ar[$i]['conditions']); |
| |
else |
| |
if (! strcmp($key, $ar[$i]['conditions'])) |
| |
$ar[$i] = $value; |
| |
|
| if (is_array($ar[$i]['true'])) |
if (is_array($ar[$i]['true'])) |
| $this->_set($key, $value, $ar[$i]['true']); |
$this->_set($key, $value, $ar[$i]['true']); |
| if (is_array($ar[$i]['false'])) |
if (is_array($ar[$i]['false'])) |
| Line 173 class ObjTemplate |
|
| Line 196 class ObjTemplate |
|
| for ($i = 0; $i < count($ar); $i++) { |
for ($i = 0; $i < count($ar); $i++) { |
| if (is_array($ar[$i])) { |
if (is_array($ar[$i])) { |
| if (! strcmp($this->cmd['if'], $ar[$i]['key'])) { |
if (! strcmp($this->cmd['if'], $ar[$i]['key'])) { |
| |
if (is_array($ar[$i]['conditions'])) |
| |
array_push($ar_out, $this->_get_keys($ar[$i]['conditions'])); |
| |
else |
| |
array_push($ar_out, $ar[$i]['conditions']); |
| |
|
| if (is_array($ar[$i]['true'])) |
if (is_array($ar[$i]['true'])) |
| $ar_out = array_merge($ar_out, $this->_get_keys($ar[$i]['true'])); |
$ar_out = array_merge($ar_out, $this->_get_keys($ar[$i]['true'])); |
| if (is_array($ar[$i]['false'])) |
if (is_array($ar[$i]['false'])) |
| $ar_out = array_merge($ar_out, $this->_get_keys($ar[$i]['false'])); |
$ar_out = array_merge($ar_out, $this->_get_keys($ar[$i]['false'])); |
| } |
} |
| elseif (isset($ar[$i]['key'])) { |
elseif (isset($ar[$i]['key'])) { |
| array_push($ar_out, $ar[$i]['key']); |
if (is_array($ar[$i]['key'])) |
| |
array_push($ar_out, $this->_get_keys($ar[$i]['key'])); |
| |
else |
| |
array_push($ar_out, $ar[$i]['key']); |
| } |
} |
| else { |
else { |
| $ar_out = array_merge($ar_out, $this->_get_keys($ar[$i])); |
$ar_out = array_merge($ar_out, $this->_get_keys($ar[$i])); |
| Line 214 class ObjTemplate |
|
| Line 245 class ObjTemplate |
|
| if (is_array($ar[$i])) { |
if (is_array($ar[$i])) { |
| if (! strcmp($this->cmd['if'], $ar[$i]['key'])) { |
if (! strcmp($this->cmd['if'], $ar[$i]['key'])) { |
| /* TODO: :) */ |
/* TODO: :) */ |
| if (is_array($ar[$i]['true'])); |
echo "IF conditions: [".$ar[$i]['conditions']."] -- "; |
| if (is_array($ar[$i]['false'])); |
if (eval("return (".$this->_final_join($ar[$i]['conditions']).");")) { |
| |
echo "returned true<br>"; |
| |
if (is_array($ar[$i]['true'])) |
| |
$string .= $this->_get_content($ar[$i]['true'], $mode); |
| |
} |
| |
else { |
| |
echo "returned false<br>"; |
| |
if (is_array($ar[$i]['false'])) |
| |
$string .= $this->_get_content($ar[$i]['false'], $mode); |
| |
} |
| } |
} |
| elseif (isset($ar[$i]['key'])) { |
elseif (isset($ar[$i]['key'])) { |
| switch ($mode) { |
if (is_array($ar[$i]['key'])) { |
| case "clean": |
$evalcode = "return (".$this->_final_join($ar[$i]['key']).");"; |
| ; |
print "evalcode = $evalcode<br>"; |
| break; |
$string .= eval($evalcode); |
| case "hide": |
} |
| $string .= $this->_generate_error("hide: " . $ar[$i]['key']); |
else { |
| break; |
switch ($mode) { |
| default: |
case "clean": |
| $string .= $this->tag['begin'] . $ar[$i]['key'] . $this->tag['end']; |
; |
| break; |
break; |
| |
case "hide": |
| |
$string .= $this->_generate_error("hide: " . $ar[$i]['key']); |
| |
break; |
| |
default: |
| |
$string .= $this->tag['begin'] . $ar[$i]['key'] . $this->tag['end']; |
| |
break; |
| |
} |
| } |
} |
| } |
} |
| else { |
else { |
| Line 259 class ObjTemplate |
|
| Line 306 class ObjTemplate |
|
| return $this->array; |
return $this->array; |
| } |
} |
| |
|
| |
function _start_explode($str) { |
| |
$char = '[\w\d_:]'; |
| |
$neg_char = '[^\w\d_:]'; |
| |
|
| |
if (preg_match("/^$char+$/", $str)) |
| |
return $str; |
| |
|
| |
$out_ar = array(); |
| |
$tmpstr = ''; |
| |
|
| |
if (preg_match("/^$char$/", $str[$i])) $type = 1; |
| |
else $type = 0; |
| |
|
| |
for ($i = 0; $i < strlen($str); $i++) { |
| |
if ($type == 1) { |
| |
if (preg_match("/^$char$/", $str[$i])) { |
| |
$tmpstr .= $str[$i]; |
| |
} |
| |
else { |
| |
array_push($out_ar, $tmpstr); |
| |
$tmpstr = ''; |
| |
$type = 0; |
| |
} |
| |
} |
| |
else { |
| |
if (preg_match("/^[\w]$/", $str[$i])) { |
| |
array_push($out_ar, array('key' => strtolower($tmpstr))); |
| |
$tmpstr = ''; |
| |
$type = 1; |
| |
} |
| |
else { |
| |
$tmpstr .= $str[$i]; |
| |
} |
| |
} |
| |
} |
| |
|
| |
array_push($out_ar, $type ? array('key' => strtolower($tmpstr)) : $tmpstr); |
| |
|
| |
return $out_ar; |
| |
} |
| |
|
| |
function _final_join($ar) { |
| |
if (is_array($ar)) { |
| |
$ret = ''; |
| |
foreach ($ar as $i) |
| |
if (! is_array($i)) |
| |
$ret .= $i; |
| |
|
| |
return $ret; |
| |
} |
| |
else |
| |
return "'$ar'"; |
| |
} |
| |
|
| /* |
/* |
| * Required improvements: |
* Required improvements: |
| * |
* |
| Line 280 class ObjTemplate |
|
| Line 381 class ObjTemplate |
|
| * Optimalization for this array spliting is strongly required. |
* Optimalization for this array spliting is strongly required. |
| */ |
*/ |
| |
|
| $regexp = $this->tag['begin'] . '(\w[\w\d_]*(' . $this->tag['delim'] . '[^\b%]+)*)' . |
$m_texts = $m_tags = array(); |
| ( isset($this->tag['end']) ? $this->tag['end'] : '\b' ); |
|
| |
if (0) { |
| |
/* |
| |
* Old method -- remove this. |
| |
*/ |
| |
|
| |
$regexp = $this->tag['begin'] . '(\w[\w\d_]*(' . $this->tag['delim'] . '[^\b%]+)*)' |
| |
. ( isset($this->tag['end']) ? $this->tag['end'] : '\b' ); |
| |
|
| |
preg_match_all("/$regexp/is", $string, $m_tags); |
| |
$m_tags = $m_tags[1]; |
| |
|
| |
$m_texts = preg_split("/$regexp/im", $string); |
| |
} |
| |
else { |
| |
$begin_tag_len = strlen($this->tag['begin']); |
| |
$end_tag_len = strlen($this->tag['end']); |
| |
$append = 0; |
| |
|
| |
while (1) { |
| |
$pos_begin = strpos($string, $this->tag['begin']); |
| |
if ($pos_begin === false) { |
| |
if ($append) { |
| |
$m_texts[count($m_texts) - 1] .= $string; |
| |
$append = 0; |
| |
} |
| |
else { |
| |
array_push($m_texts, $string); |
| |
} |
| |
break; |
| |
} |
| |
else { |
| |
$pos_real_begin = $pos_begin + $begin_tag_len; |
| |
$pos_end = strpos($string, $this->tag['end'], $pos_real_begin); |
| |
if ($pos_end === false) { |
| |
if ($append) { |
| |
$m_texts[count($m_texts) - 1] .= $string; |
| |
$append = 0; |
| |
} |
| |
else { |
| |
array_push($m_texts, $string); |
| |
} |
| |
break; |
| |
} |
| |
else { |
| |
$tmpstr = substr($string, $pos_real_begin, $pos_end - $pos_real_begin); |
| |
$pos_real_end = $pos_end + $end_tag_len; |
| |
|
| |
if (preg_match('/[\s]/', $tmpstr)) { |
| |
if ($debug) echo "MATCHED: [$tmpstr]<br>"; |
| |
$pos_begin_2nd = strpos($tmpstr . $this->tag['end'], |
| |
$this->tag['begin']); |
| |
if ($pos_begin_2nd === false) ; |
| |
else $pos_real_end = $pos_real_begin + $pos_begin_2nd; |
| |
|
| |
if ($append) { |
| |
$m_texts[count($m_texts) - 1] .= |
| |
substr($string, 0, $pos_real_end); |
| |
|
| |
if ($debug) print "-- appending: [".substr($string, 0, $pos_real_end)."]<br>"; |
| |
} |
| |
else { |
| |
array_push($m_texts, |
| |
substr($string, 0, $pos_real_end)); |
| |
if ($debug) print "-- pushing: [".substr($string, 0, $pos_real_end)."]<br>"; |
| |
} |
| |
|
| |
$append = 1; |
| |
} |
| |
else { |
| |
if ($debug) echo "NOT MATCHED: [$tmpstr]<br>"; |
| |
if ($append) { |
| |
$m_texts[count($m_texts) - 1] .= substr($string, 0, $pos_begin); |
| |
$append = 0; |
| |
} |
| |
else { |
| |
array_push($m_texts, substr($string, 0, $pos_begin)); |
| |
} |
| |
|
| |
array_push($m_tags, $tmpstr); |
| |
} |
| |
|
| preg_match_all("/$regexp/is", $string, $m_tags); |
$string = substr($string, $pos_real_end); |
| $m_tags = $m_tags[1]; |
} |
| |
} |
| |
} |
| |
} |
| |
|
| $m_texts = preg_split("/$regexp/im", $string); |
|
| |
|
| /* |
/* |
| * Debug informations printing. |
* Debug informations printing. |
| Line 342 class ObjTemplate |
|
| Line 525 class ObjTemplate |
|
| elseif (! strcasecmp($this->cmd['if'], $cmd_parts[0])) { |
elseif (! strcasecmp($this->cmd['if'], $cmd_parts[0])) { |
| $ar_out[$ar_out_idx] = array( |
$ar_out[$ar_out_idx] = array( |
| 'key' => $this->cmd['if'], |
'key' => $this->cmd['if'], |
| 'conditions' => strtolower($cmd_parts[1]) |
'conditions' => $this->_start_explode($cmd_parts[1]) |
| |
//'conditions' => strtolower($cmd_parts[1]) |
| ); |
); |
| $tmp_str = ''; |
$tmp_str = ''; |
| $level = 0; |
$level = 0; |
| Line 389 class ObjTemplate |
|
| Line 573 class ObjTemplate |
|
| |
|
| /* Others tags. */ |
/* Others tags. */ |
| else { |
else { |
| $ar_out[$ar_out_idx] = array('key' => strtolower($m_tags[$i])); |
//$ar_out[$ar_out_idx] = array('key' => strtolower($m_tags[$i])); |
| |
$ar_out[$ar_out_idx] = array('key' => $this->_start_explode($m_tags[$i])); |
| } |
} |
| |
|
| $ar_out_idx++; |
$ar_out_idx++; |
| } |
} |
| } |
} |
| /* TODO: remove this |
|
| if ($ar_out_idx <= 1) |
if ($debug && $ar_out_idx <= 1) |
| print "!!!! ar_out_idx = $ar_out_idx<br>"; |
print "_string_transform() DEBUG: ar_out_idx = $ar_out_idx<br>"; |
| */ |
|
| |
|
| return $ar_out_idx > 1 ? $ar_out : $ar_out[0]; |
return $ar_out_idx > 1 ? $ar_out : $ar_out[0]; |
| } |
} |