From ed81de3f8653284a285c8cdd920dd86f859a9c51 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 27 Sep 2002 16:17:39 +0000 Subject: [PATCH] big performance improvment by using references (droped php3 compatibility) --- etemplate/inc/class.boetemplate.inc.php | 86 ++++++++++++--- etemplate/inc/class.date_widget.inc.php | 17 +-- etemplate/inc/class.datefield_widget.inc.php | 4 +- etemplate/inc/class.editor.inc.php | 5 +- etemplate/inc/class.nextmatch_widget.inc.php | 8 +- etemplate/inc/class.soetemplate.inc.php | 16 ++- etemplate/inc/class.tab_widget.inc.php | 19 ++-- etemplate/inc/class.uietemplate.inc.php | 104 ++++++++++++------- 8 files changed, 180 insertions(+), 79 deletions(-) diff --git a/etemplate/inc/class.boetemplate.inc.php b/etemplate/inc/class.boetemplate.inc.php index e88a542e63..9574047664 100644 --- a/etemplate/inc/class.boetemplate.inc.php +++ b/etemplate/inc/class.boetemplate.inc.php @@ -269,13 +269,13 @@ $this->data[$row][$col][$attr] = $val; ++$n; } - if ($cell['type'] == 'template' && (is_object($cell['name']) || $cell['name'][0] != '@')) + if ($cell['type'] == 'template' && (is_object($cell['obj']) || $cell['name'][0] != '@')) { - if (!is_object($cell['name'])) + if (!is_object($cell['obj'])) { - $this->data[$row][$col]['name'] = CreateObject('etemplate.etemplate',$cell['name']); + $this->data[$row][$col]['obj'] = CreateObject('etemplate.etemplate',$cell['name']); } - $n += $this->data[$row][$col]['name']->set_cell_attribute($name,$attr,$val); + $n += $this->data[$row][$col]['obj']->set_cell_attribute($name,$attr,$val); } } } @@ -297,15 +297,15 @@ /*! @function loadExtension - @syntax loadExtension( $name,$ui='' ) + @syntax loadExtension( $type ) @author ralfbecker @abstact trys to load the Extension / Widget-class from the app or etemplate @param $name name of the extension, the classname should be class.${name}_widget.inc.php @discussion the $name might be "$name.$app" to give a app-name (default is the current app,or template-name) */ - function loadExtension($name,&$parent,$ui='html') + function loadExtension($type) { - list($class,$app) = explode('.',$name); + list($class,$app) = explode('.',$type); $class .= '_widget'; if ($app == '') @@ -322,19 +322,71 @@ } if (!file_exists(PHPGW_SERVER_ROOT."/$app/inc/class.$class.inc.php")) { - return $this->extension[$name] = False; + return $GLOBALS['phpgw_info']['etemplate']['extension'][$type] = False; } - $this->extension[$name] = CreateObject($app.'.'.$class,$ui); + $GLOBALS['phpgw_info']['etemplate']['extension'][$type] = CreateObject($app.'.'.$class,$ui='html'); - if(floor(phpversion()) >= 4) + return $GLOBALS['phpgw_info']['etemplate']['extension'][$type]->human_name; + } + + function haveExtension($type,$function='') + /* + @function haveExtension + @syntax haveExtension($type) + @abstract checks if extension is loaded and load it if it isnt + */ + { + return ($GLOBALS['phpgw_info']['etemplate']['extension'][$type] || $this->loadExtension($type,$ui)) && + ($function == '' || $GLOBALS['phpgw_info']['etemplate']['extension'][$type]->public_functions[$function]); + } + + function extensionPreProcess(&$cell,&$value,&$readonlys) + /* + @function extensionPreProcess + @syntax extensionPreProcess(&$cell,&$value,&$readonlys) + @param &$cell table-cell on which the extension operates + @param &$value value of the extensions content(-array) + @param &$readonlys value of the extensions readonly-setting(-array) + @abstract executes the pre_process-function of the extension $cell[]type] + */ + { + if (!$this->haveExtension($type = $cell['type'])) { - $this->extension[$name]->et = &$parent; + return False; } - else + return $GLOBALS['phpgw_info']['etemplate']['extension'][$type]->pre_process($cell,$value, + $GLOBALS['phpgw_info']['etemplate']['extension_data'][$type][$cell['name']],$readonlys,$this); + } + + function extensionPostProcess(&$cell,&$value) + /* + @function extensionPostProcess + @syntax extensionPostProcess(&$cell,&$value) + @abstract executes the post_process-function of the extension $cell[type] + */ + { + if (!$this->haveExtension($type = $cell['type'],'post_process')) { - $this->extension[$name]->et = $parent; + return False; } - return $this->extension[$name]; + return $GLOBALS['phpgw_info']['etemplate']['extension'][$type]->post_process($cell,$value, + $GLOBALS['phpgw_info']['etemplate']['extension_data'][$type][$cell['name']], + $GLOBALS['phpgw_info']['etemplate']['loop'],$this); + } + + function extensionRender(&$cell,$form_name,&$value,$readonly) + /* + @function extensionRender + @syntax extensionRender(&$cell,$form_name,&$value,$readonly) + @abstract executes the render-function of the extension $cell[type] + */ + { + if (!$this->haveExtension($type = $cell['type'],'render')) + { + return False; + } + return $GLOBALS['phpgw_info']['etemplate']['extension'][$name]->render($cell,$form_name,$value,$readonly, + $GLOBALS['phpgw_info']['etemplate']['extension_data'][$type][$cell['name']],$this); } /*! @@ -375,16 +427,16 @@ //echo "set_array: $code = '$val'\n"; } - function get_array(&$arr,$idx) + function &get_array(&$arr,$idx) { if (ereg('^([^[]*)(\\[.*\\])$',$idx,$regs)) // idx contains array-index { - eval($code = str_replace(']',"']",str_replace('[',"['",'$val = $arr['.$regs[1].']'.$regs[2].';'))); + eval($code = str_replace(']',"']",str_replace('[',"['",'$val = &$arr['.$regs[1].']'.$regs[2].';'))); //echo "get_array: $code = '$val'\n"; } else { - $val = $arr[$idx]; + $val = &$arr[$idx]; } return $val; } diff --git a/etemplate/inc/class.date_widget.inc.php b/etemplate/inc/class.date_widget.inc.php index edbe6a6154..f9bbe0ea8b 100644 --- a/etemplate/inc/class.date_widget.inc.php +++ b/etemplate/inc/class.date_widget.inc.php @@ -27,7 +27,7 @@ ); var $human_name = 'Date'; // this is the name for the editor - function date_widget($ui) + function date_widget($ui='') { switch($ui) { @@ -44,7 +44,7 @@ return 0; } - function pre_process(&$cell,&$value,&$extension_data,&$readonlys) + function pre_process(&$cell,&$value,&$extension_data,&$readonlys,&$tmpl) { if ($cell['size'] != '') { @@ -67,14 +67,17 @@ return True; // extra Label is ok } - function render($cell,$form_name,$value,$readonly) + function render(&$cell,$form_name,&$value,$readonly,&$extension_data,&$tmpl) { $func = 'render_'.$this->ui; - return $this->$func($cell,$form_name,$value,$readonly); + if (!method_exists($this,$func)) + return False; + + return $this->$func($cell,$form_name,$value,$readonly,$tmpl); } - function post_process(&$cell,&$value,&$extension_data,&$loop) + function post_process(&$cell,&$value,&$extension_data,&$loop,&$tmpl) { if (!isset($value)) { @@ -117,12 +120,12 @@ return True; } - function render_html($cell,$form_name,$value,$readonly) + function render_html($cell,$form_name,$value,$readonly,&$tmpl) { if ($readonly) { return $GLOBALS['phpgw']->common->dateformatorder($value[0],$value[1],$value[2],True); } - return $this->et->sbox->getDate($form_name.'[Y]',$form_name.'[m]',$form_name.'[d]',$value,$options); + return $tmpl->sbox->getDate($form_name.'[Y]',$form_name.'[m]',$form_name.'[d]',$value,$options); } } \ No newline at end of file diff --git a/etemplate/inc/class.datefield_widget.inc.php b/etemplate/inc/class.datefield_widget.inc.php index 71e134f246..e2d55c0c1a 100644 --- a/etemplate/inc/class.datefield_widget.inc.php +++ b/etemplate/inc/class.datefield_widget.inc.php @@ -30,7 +30,7 @@ { } - function pre_process(&$cell,&$value,&$extension_data,&$readonlys) + function pre_process(&$cell,&$value,&$extension_data,&$readonlys,&$tmpl) { if ($cell['size'] != '') { @@ -69,7 +69,7 @@ return True; // extra Label is ok } - function post_process(&$cell,&$value,&$extension_data,&$loop) + function post_process(&$cell,&$value,&$extension_data,&$loop,&$tmpl) { if (!isset($value)) { diff --git a/etemplate/inc/class.editor.inc.php b/etemplate/inc/class.editor.inc.php index 1d046ac7e1..7f1b9df952 100644 --- a/etemplate/inc/class.editor.inc.php +++ b/etemplate/inc/class.editor.inc.php @@ -592,6 +592,7 @@ function show($post_vars='') { + echo "this->etemplate->data = "; _debug_array($this->etemplate->data); if ($this->debug) { echo "

etemplate.editor.show: content="; _debug_array($post_vars); @@ -641,7 +642,7 @@ } else { - $show->data[$show->rows]['A']['name'] = $this->etemplate; + $show->data[$show->rows]['A']['obj'] = &$this->etemplate; $vals = $post_vars['vals']; $olds = $post_vars['olds']; @@ -673,7 +674,7 @@ if (ereg('class\\.([a-zA-Z0-9_]*)_widget.inc.php',$file,$regs) && ($ext = $this->etemplate->loadExtension($regs[1].'.'.$app,$this->etemplate))) { - $extensions[$regs[1]] = $ext->human_name; + $extensions[$regs[1]] = $ext; } } return $extensions; diff --git a/etemplate/inc/class.nextmatch_widget.inc.php b/etemplate/inc/class.nextmatch_widget.inc.php index e60e1ed7ec..caaee1c51a 100644 --- a/etemplate/inc/class.nextmatch_widget.inc.php +++ b/etemplate/inc/class.nextmatch_widget.inc.php @@ -25,7 +25,7 @@ 'pre_process' => True, 'post_process' => True ); - var $human_name = 'Nextmatch Widget'; // this is the name for the editor + var $human_name = 'Nextmatch'; // this is the name for the editor function nextmatch_widget($ui) { @@ -42,7 +42,7 @@ $total = $value['total'] = $obj->$method($value,$value['rows'],$readonlys['rows']); if ($value['start'] > $total) { - $value['start'] = 0; + $extension_data['start'] = $value['start'] = 0; $total = $obj->$method($value,$value['rows'],$readonlys['rows']); } $extension_data['total'] = $total; @@ -54,6 +54,7 @@ $value['template'] = new etemplate($value['template'],$tmpl->as_array()); $nextmatch = new etemplate('etemplate.nextmatch_widget'); + if ($value['no_cat']) { $nextmatch->disable_cells('cat_id'); @@ -77,7 +78,8 @@ $cell['type'] = 'template'; $cell['size'] = $cell['name']; - $cell['name'] = $nextmatch; + $cell['obj'] = &$nextmatch; + $cell['name'] = $nextmatch->name; $cell['label'] = $cell['help'] = ''; return False; // NO extra Label diff --git a/etemplate/inc/class.soetemplate.inc.php b/etemplate/inc/class.soetemplate.inc.php index 4f15ad71e8..8d2cc94a3c 100644 --- a/etemplate/inc/class.soetemplate.inc.php +++ b/etemplate/inc/class.soetemplate.inc.php @@ -180,7 +180,7 @@ $this->init($name,$template,$lang,$group,$version); if ($this->debug == 1 || $this->debug == $this->name) { - echo "

soetemplate::read('$this->name','$this->template','$this->lang','$this->version')

\n"; + echo "

soetemplate::read('$this->name','$this->template','$this->lang',$this->group,'$this->version')

\n"; } if ($GLOBALS['phpgw_info']['server']['eTemplate-source'] == 'files' && $this->readfile()) { @@ -438,6 +438,14 @@ */ function save($name='',$template='.',$lang='.',$group='',$version='.') { + if (is_array($name)) + { + $template = $name['template']; + $lang = $name['lang']; + $group = $name['group']; + $version = $name['version']; + $name = $name['name']; + } if ($name != '') { $this->name = $name; @@ -462,6 +470,10 @@ { return False; } + if ($this->debug > 0 || $this->debug == $this->name) + { + echo "

soetemplate::save('$this->name','$this->template','$this->lang',$this->group,'$this->version')

\n"; + } $this->delete(); // so we have always a new insert if ($this->name[0] != '.') // correct up old messed up templates @@ -717,7 +729,7 @@ if ($time = @filemtime($path)) { - $templ = new etemplate(".$app",'','##'); + $templ = new soetemplate(".$app",'','##'); if ($templ->lang != '##' || $templ->data[0] < $time) // need to import { $ret = $this->import_dump($app); diff --git a/etemplate/inc/class.tab_widget.inc.php b/etemplate/inc/class.tab_widget.inc.php index a7479fec65..c30740de98 100644 --- a/etemplate/inc/class.tab_widget.inc.php +++ b/etemplate/inc/class.tab_widget.inc.php @@ -51,11 +51,13 @@ { // save selected tab in persistent extension_data to use it in post_process $extension_data = $selected_tab = $name; - $tcell['name'] = $tab_active; + $tcell['obj'] = &$tab_active; + $tcell['name'] = $tab_active->name; } else { - $tcell['name'] = $tab; + $tcell['obj'] = &$tab; + $tcell['name'] = $tab->name; } $tcell['type'] = 'template'; $tcell['size'] = "_tab_widget[$name]"; @@ -73,7 +75,8 @@ if (!isset($selected_tab)) { - $tab_row['A']['name'] = $tab_active; + $tab_row['A']['obj'] = &$tab_active; + $tcell['name'] = $tab_active->name; $extension_data = $selected_tab = $names[0]; } $tabs->data[1] = $tab_row; @@ -82,12 +85,14 @@ $tabs->size = ',,,,0'; $tab_widget = new etemplate('etemplate.tab_widget'); - $tab_widget->set_cell_attribute('@tabs','name',$tabs); - $tab_widget->set_cell_attribute('@body','name', - $tmpl->tpls_in_file > 1 ? new etemplate($selected_tab,$tmpl->as_array()) : $selected_tab); + $tab_widget->set_cell_attribute('@tabs','obj',$tabs); + if ($tmpl->tpls_in_file > 1) + $tab_widget->set_cell_attribute('@body','obj',new etemplate($selected_tab,$tmpl->as_array())); + else + $tab_widget->set_cell_attribute('@body','name',$selected_tab); $cell['type'] = 'template'; - $cell['name'] = $tab_widget; + $cell['obj'] = &$tab_widget; $cell['label'] = $cell['help'] = ''; return False; // NO extra Label diff --git a/etemplate/inc/class.uietemplate.inc.php b/etemplate/inc/class.uietemplate.inc.php index 5822e1e015..868158d7e8 100644 --- a/etemplate/inc/class.uietemplate.inc.php +++ b/etemplate/inc/class.uietemplate.inc.php @@ -33,7 +33,6 @@ var $debug; // 1=calls to show and process_show, 2=content after process_show, // 3=calls to show_cell and process_show_cell, or template-name or cell-type var $html,$sbox; // instance of html / sbox2-class - var $loop = 0; // set by process_show if an other Exec-ProcessExec loop is needed /*! @function etemplate @@ -215,7 +214,7 @@ reset($this->data); if (isset($this->data[0])) { - list($nul,$width) = each($this->data); + list(,$width) = each($this->data); } else { @@ -223,11 +222,8 @@ } for ($r = 0; $row = 1+$r /*list($row,$cols) = each($this->data)*/; ++$r) { - $old_cols = $cols; $old_class = $class; $old_height = $height; - if (!(list($nul,$cols) = each($this->data))) // no further row + if (!(list($r_key) = each($this->data))) // no further row { - $cols = $old_cols; $class = $old_class; $height = $old_height; - list($nul,$cell) = each($cols); reset($cols); if (!($this->autorepeat_idx($cols['A'],0,$r,$idx,$idx_cname) && $idx_cname) && !($this->autorepeat_idx($cols['B'],1,$r,$idx,$idx_cname) && $idx_cname) || !$this->isset_array($content,$idx)) @@ -237,22 +233,26 @@ } else { - $height = $this->data[0]["h$row"]; - $class = $this->data[0]["c$row"]; + $cols = &$this->data[$r_key]; + $height = &$this->data[0]["h$row"]; + $class = &$this->data[0]["c$row"]; } + reset ($cols); $row_data = array(); for ($c = 0; True /*list($col,$cell) = each($cols)*/; ++$c) { - $old_cell = $cell; - if (!(list($nul,$cell) = each($cols))) // no further cols + if (!(list($c_key) = each($cols))) // no further cols { - $cell = $old_cell; if (!$this->autorepeat_idx($cell,$c,$r,$idx,$idx_cname,True) || !$this->isset_array($content,$idx)) { break; // no auto-col-repeat } } + else + { + $cell = &$cols[$c_key]; + } $col = $this->num2chrs($c); $row_data[$col] = $this->show_cell($cell,$content,$sel_options,$readonlys,$cname, $c,$r,$span); @@ -317,7 +317,7 @@ } list($span) = explode(',',$cell['span']); // evtl. overriten later for type template - if ($cell['name'][0] == '@') + if ($cell['name'][0] == '@' && $cell['type'] != 'template') { $cell['name'] = $this->get_array($content,substr($cell['name'],1)); } @@ -353,12 +353,11 @@ } $extra_label = True; - if (!$this->types[$cell['type']] && - (isset($this->extension[$cell['type']]) || $this->loadExtension($cell['type'],$this))) + if (!$this->types[$cell['type']] && $this->haveExtension($cell['type'])) { - $extra_label = $this->extension[$cell['type']]->pre_process($cell,$value, - $GLOBALS['phpgw_info']['etemplate']['extension_data'][$cell['type']][$cell['name']], - $readonlys[$name],$this); + $type = $cell['type']; + $extra_label = $this->extensionPreProcess($cell,$value,$readonlys[$name]); + //echo "

$type::pre_process"; _debug_array($cell); if (strstr($name,'|')) { $content = $this->complete_array_merge($content,$value); @@ -468,6 +467,34 @@ $html .= $this->html->hr($cell['size']); break; case 'template': // size: index in content-array (if not full content is past further on) + if (is_object($cell['name'])) + { + $cell['obj'] = &$cell['name']; + unset($cell['name']); + $cell['name'] = 'was Object'; + echo "

Object in Name in tpl '$this->name': "; _debug_array($this->data); + } + $obj_read = 'already loaded'; + if (!is_object($cell['obj'])) + { + if ($cell['name'][0] == '@') + { + $cell['obj'] = $this->get_array($content,substr($cell['name'],1)); + $obj_read = is_object($cell['obj']) ? 'obj from content' : 'obj read, obj-name from content'; + if (!is_object($cell['obj'])) + { + $cell['obj'] = new etemplate($cell['obj'],$this->as_array()); + } + } + else + { $obj_read = 'obj read'; + $cell['obj'] = new etemplate($cell['name'],$this->as_array()); + } + } + if ($this->debug >= 3 || $this->debug == $cell['type']) + { + echo "

show_cell::template(tpl=$this->name,name=$cell[name]): $obj_read

\n"; + } if ($this->autorepeat_idx($cell,$show_c,$show_row,$idx,$idx_cname) || $cell['size'] != '') { if ($span == '' && isset($content[$idx]['span'])) @@ -490,8 +517,7 @@ { $readonlys['__ALL__'] = True; } - $templ = is_object($cell['name']) ? $cell['name'] : new etemplate($cell['name'],$this->as_array()); - $html .= $templ->show($content,$sel_options,$readonlys,$cname,$show_c,$show_row); + $html .= $cell['obj']->show($content,$sel_options,$readonlys,$cname,$show_c,$show_row); break; case 'select': // size:[linesOnMultiselect] if (isset($sel_options[$name])) @@ -548,13 +574,13 @@ "enctype=\"multipart/form-data\" onSubmit=\"set_element2(this,'$path','$form_name')\""; break; default: - if (!isset($this->extension[$cell['type']])) + if ($this->haveExtension($cell['type'])) { - $html .= "unknown type '$cell[type]'"; + $html .= $this->extensionRender($cell,$form_name,$value,$readonly); } else { - $html .= $this->extension[$cell['type']]->render($cell,$form_name,$value,$readonly); + $html .= "unknown type '$cell[type]'"; } break; } @@ -613,11 +639,9 @@ } for ($r = 0; True /*list($row,$cols) = each($this->data)*/; ++$r) { - $old_cols = $cols; - if (!(list($nul,$cols) = each($this->data))) // no further row + if (!(list($r_key) = each($this->data))) // no further row { - $cols = $old_cols; - list($nul,$cell) = each($cols); reset($cols); + //list($nul,$cell) = each($cols); reset($cols); if ((!$this->autorepeat_idx($cols['A'],0,$r,$idx,$idx_cname) || $idx_cname == '' || !$this->isset_array($content,$idx)) && (!$this->autorepeat_idx($cols['B'],1,$r,$idx,$idx_cname) || @@ -626,13 +650,18 @@ break; // no auto-row-repeat } } + else + { + $cols = &$this->data[$r_key]; + } $row = 1+$r; + reset($cols); for ($c = 0; True /*list($col,$cell) = each($cols)*/; ++$c) { - $old_cell = $cell; - if (!(list($nul,$cell) = each($cols))) // no further cols + //$old_cell = $cell; + if (!(list($c_key/*,$cell*/) = each($cols))) // no further cols { - $cell = $old_cell; + //$cell = $old_cell; if (!$this->autorepeat_idx($cell,$c,$r,$idx,$idx_cname,True) || $idx_cname == '' || !$this->isset_array($content,$idx)) { @@ -641,6 +670,7 @@ } else { + $cell = &$cols[$c_key]; $this->autorepeat_idx($cell,$c,$r,$idx,$idx_cname,True); // get idx_cname } $col = $this->num2chrs($c); @@ -741,16 +771,13 @@ echo "'$value'

\n"; } } - if ((isset($this->extension[$cell['type']]) || $this->loadExtension($cell['type'],$this)) && - isset($this->extension[$cell['type']]->public_functions['post_process'])) + if ($this->haveExtension($cell['type'],'post_process')) { if ($this->debug > 1 || $this->debug && $this->debug == $this->name) { echo "

value for $cell[type]::post_process: "; _debug_array($value); } - $this->extension[$cell['type']]->post_process($cell,$value, - $GLOBALS['phpgw_info']['etemplate']['extension_data'][$cell['type']][$cell['name']], - $GLOBALS['phpgw_info']['etemplate']['loop'],$this); + $this->extensionPostProcess($cell,$value); if ($this->debug > 1 || $this->debug && $this->debug == $this->name) { @@ -788,13 +815,12 @@ } break; case 'template': - $templ = is_object($cell['name']) ? $cell['name'] : new etemplate($cell['name'],$this->as_array()); - $templ->process_show($value,$readonlys); - if ($templ->loop) + if (!is_object($cell['obj'])) { - $this->loop = True; - //echo "

".$this->name.": loop set in process_show(".$templ->name.")

\n"; + $cell['obj'] = new etemplate($cell['name'],$this->as_array()); } + //$templ = is_object($cell['name']) ? $cell['name'] : new etemplate($cell['name'],$this->as_array()); + $cell['obj']->process_show($value,$readonlys); break; case 'select': case 'select-cat':