removed all eval to get a slight better performance

This commit is contained in:
Ralf Becker 2002-10-03 23:47:14 +00:00
parent 9b2ae24745
commit 912566fdec
2 changed files with 54 additions and 46 deletions

View File

@ -54,7 +54,11 @@
{
$this->public_functions += array(
'disable_cells' => True,
'set_cell_attribute' => True
'set_cell_attribute' => True,
'get_cell_attribute' => True,
'get_array' => True,
'set_array' => True,
'unset_array' => True
);
$this->soetemplate();
@ -401,46 +405,49 @@
return isset($arr[$idx]);
}
function set_array(&$arr,$idx,$val,$set=True)
function set_array(&$arr,$idx,$val)
{
if (ereg('^([^[]*)(\\[.*\\])$',$idx,$regs)) // idx contains array-index
if (!is_array($arr))
{
$arr_idx = '['.$regs[1].']'.$regs[2];
die('set_array() $arr is no array');
}
else
$idxs = explode('[',str_replace(']','',$idx));
$pos = &$arr;
while (list($n,$idx) = each($idxs))
{
$arr_idx = "[$idx]";
$pos = &$pos[$idx];
}
if ($set)
{
$code = '$arr'.$arr_idx.' = $val;';
}
else
{
$code = 'unset($arr'.$arr_idx.');';
}
eval($code = str_replace(']',"']",str_replace('[',"['",$code)));
//echo "set_array: $code = '$val'<br>\n";
}
function unset_array(&$arr,$idx)
{
$this->set_array($arr,$idx,0,False);
$pos = $val;
}
function &get_array(&$arr,$idx)
{
if (ereg('^([^[]*)(\\[.*\\])$',$idx,$regs)) // idx contains array-index
if (!is_array($arr))
{
eval($code = str_replace(']',"']",str_replace('[',"['",'$val = &$arr['.$regs[1].']'.$regs[2].';')));
//echo "get_array: $code = '$val'<br>\n";
die('set_array() $arr is no array');
}
else
$idxs = explode('[',str_replace(']','',$idx));
$pos = &$arr;
while (list($n,$idx) = each($idxs))
{
$val = &$arr[$idx];
$pos = &$pos[$idx];
}
return $val;
return $pos;
}
function unset_array(&$arr,$idx)
{
if (!is_array($arr))
{
die('set_array() $arr is no array');
}
$idxs = explode('[',str_replace(']','',$idx));
$pos = &$arr;
while ((list($n,$idx) = each($idxs)) && $n < count($idxs)-1)
{
$pos = &$pos[$idx];
}
unset($pos[$idx]);
}
/*!

View File

@ -340,18 +340,18 @@
}
$name = $this->expand_name($cell['name'],$show_c,$show_row,$content['.c'],$content['.row'],$content);
if (ereg('^([^[]*)(\\[.*\\])$',$name,$regs)) // name contains array-index
$name_parts = explode('[',str_replace(']','',$name));
if (!empty($cname))
{
$form_name = $cname == '' ? $name : $cname.'['.$regs[1].']'.$regs[2];
eval(str_replace(']',"']",str_replace('[',"['",'$value = $content['.$regs[1].']'.$regs[2].';')));
$org_name = substr($regs[2],1,-1);
array_unshift($name_parts,$cname);
}
else
$form_name = array_shift($name_parts);
if (count($name_parts))
{
$form_name = $cname == '' ? $name : $cname.'['.$name.']';
$value = $content[$name];
$org_name = $name;
$form_name .= '['.implode('][',$name_parts).']';
}
$value = $this->get_array($content,$name);
if ($readonly = $cell['readonly'] || $readonlys[$name] || $readonlys['__ALL__'])
{
$options .= ' READONLY';
@ -372,14 +372,7 @@
$ext_type = $type;
$extra_label = $this->extensionPreProcess($ext_type,$form_name,$value,$cell,$readonlys[$name]);
if (!$regs)
{
$content[$name] = $value; // set result for template
}
else
{
eval(str_replace(']',"']",str_replace('[',"['",'$content['.$regs[1].']'.$regs[2].' = $value;')));
}
$this->set_array($content,$name,$value);
}
$label = $cell['label'];
if ($label[0] == '@')
@ -592,9 +585,17 @@
{
$sels += $sel_options[$name];
}
elseif (isset($sel_options[$org_name]))
elseif (count($name_parts))
{
$sels += $sel_options[$org_name];
$org_name = array_shift($name_parts);
if (count($name_parts))
{
$org_name .= '['.implode('][',$name_parts).']';
}
if (isset($sel_options[$org_name]))
{
$sels += $sel_options[$org_name];
}
}
if (isset($content["options-$name"]))
{