diff --git a/etemplate/inc/class.boetemplate.inc.php b/etemplate/inc/class.boetemplate.inc.php index d820beea13..4d040c96aa 100644 --- a/etemplate/inc/class.boetemplate.inc.php +++ b/etemplate/inc/class.boetemplate.inc.php @@ -408,17 +408,63 @@ return $old; } - /*! - @function read - @abstract Reads an eTemplate from the cache or database / filesystem (and updates the cache) - @param as discripted in soetemplate::read - @result True if a fitting template is found, else False - */ - function read($name,$template='default',$lang='default',$group=0,$version='') - { - $cname = ($template == '' ? 'default' : $template).'/'.$name.($lang == 'default' ? '' : '.'.$lang); - if (isset($GLOBALS['phpgw_info']['etemplate']['cache'][$cname])) + function cache_name($name='',$template='default',$lang='default') + { + if (empty($name)) + { + $name = $this->name; + $template = $this->template; + $lang = $this->lang; + } + elseif (is_array($name)) + { + $template = $name['template']; + $lang = $name['lang']; + $name = $name['name']; + } + if (empty($template)) + { + $template = 'default'; + } + $cname = $template . '/' . $name . (!empty($lang) && $lang != 'default' ? '.' . $lang : ''); + //echo "cache_name('$name','$template','$lang') = '$cname'"; + + return $cname; + } + + /*! + @function store_in_cache() + @abstract stores the etemplate in the cache in phpgw_info + */ + function store_in_cache() + { + //echo "
store_in_cache('$this->name','$this->template','$this->lang','$this->version')
\n"; + $GLOBALS['phpgw_info']['etemplate']['cache'][$this->cache_name()] = $this->as_array(1); + } + + function in_cache($name,$template='default',$lang='default',$group=0,$version='') + { + $cname = $this->cache_name($name,$template,$lang); + if (is_array($name)) + { + $version = $name['version']; + $name = $name['name']; + } + if (!isset($GLOBALS['phpgw_info']['etemplate']['cache'][$cname]) || + !empty($version) && $GLOBALS['phpgw_info']['etemplate']['cache'][$cname]['version'] != $version) + { + //echo " NOT found in cache\n"; + return False; + } + //echo " found in cache\n"; + return $cname; + } + + function read_from_cache($name,$template='default',$lang='default',$group=0,$version='') + { + //if (is_array($name)) $version = $name['version']; echo "read_from_cache(,,,version='$version'): "; + if ($cname = $this->in_cache($name,$template,$lang,$group)) { reset($this->db_cols); while (list($db_col,$col) = each($this->db_cols)) @@ -427,16 +473,28 @@ } $this->rows = count($this->data) - 1; $this->cols = count($this->data[1]); // 1 = first row, not 0 - echo "\n\n"; return True; } - if (!soetemplate::read($name,$template,$lang,$group,$version)) - return False; + return False; + } - echo "\n\n"; - $GLOBALS['phpgw_info']['etemplate']['cache'][$cname] = $this->as_array(1); - - return true; + /*! + @function read + @abstract Reads an eTemplate from the cache or database / filesystem (and updates the cache) + @param as discripted in soetemplate::read + @result True if a fitting template is found, else False + */ + function read($name,$template='default',$lang='default',$group=0,$version='') + { + if (!$this->read_from_cache($name,$template,$lang,$group,$version)) + { + if (!soetemplate::read($name,$template,$lang,$group,$version)) + { + return False; + } + $this->store_in_cache(); + } + return True; } /*! @@ -447,13 +505,9 @@ */ function save($name='',$template='.',$lang='.',$group='',$version='.') { - $result = soetemplate::save($name,$template,$lang,$group,$version); - - if ($result) + if ($result = soetemplate::save($name,$template,$lang,$group,$version)) { - $cname = ($template == '' ? 'default' : $template).'/'.$name.($lang == 'default' ? '' : '.'.$lang); - - $GLOBALS['phpgw_info']['etemplate']['cache'][$cname] = $this->as_array(1); + $this->store_in_cache(); } return $result; } diff --git a/etemplate/inc/class.soetemplate.inc.php b/etemplate/inc/class.soetemplate.inc.php index efa74c03de..f814d6c2be 100644 --- a/etemplate/inc/class.soetemplate.inc.php +++ b/etemplate/inc/class.soetemplate.inc.php @@ -42,6 +42,7 @@ 'import_dump' => True, 'writeLangFile' => True ); + var $debug; // =1 show some debug-messages, = 'app.name' show messages only for eTemplate 'app.name' var $name; // name of the template, e.g. 'infolog.edit' var $template; // '' = default (not 'default') var $lang; // '' if general template else language short, e.g. 'de' @@ -74,7 +75,14 @@ $this->db = $GLOBALS['phpgw']->db; $this->db_cols = $this->db_key_cols + $this->db_data_cols; - $this->read($name,$template,$lang,$group,$version,$rows,$cols); + if (empty($name)) + { + $this->init($name,$template,$lang,$group,$version,$rows,$cols); + } + else + { + $this->read($name,$template,$lang,$group,$version,$rows,$cols); + } } /*! @@ -157,7 +165,10 @@ function read($name,$template='default',$lang='default',$group=0,$version='') { $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"; + } if ($GLOBALS['phpgw_info']['server']['eTemplate-source'] == 'files' && $this->readfile()) { return True; @@ -201,10 +212,15 @@ } $sql .= " ORDER BY et_lang DESC,et_template DESC,et_version DESC"; + if ($this->debug == $this->name) + { + echo "soetemplate::read: sql='$sql'
\n"; + } $this->db->query($sql,__LINE__,__FILE__); if (!$this->db->next_record()) { - return $this->readfile(); + $version = $this->version; + return $this->readfile() && (empty($version) || $version == $this->version); } $this->db2obj(); @@ -229,7 +245,10 @@ if ($this->name == '' || $app == '' || $name == '' || !@file_exists($file) || !($f = @fopen($file,'r'))) { - //echo "Can't open '$file' !!!
\n"; + if ($this->debug == 1 || $this->debug == $this->name) + { + echo "Can't open '$file' !!!
\n"; + } return False; } $xul = fread ($f, filesize ($file)); @@ -239,7 +258,7 @@ { $this->xul_io = CreateObject('etemplate.xul_io'); } - if ($this->xul_io->import(&$this,$xul) != '') + if (!is_array($this->xul_io->import(&$this,$xul))) { return False; } diff --git a/etemplate/inc/class.uietemplate.inc.php b/etemplate/inc/class.uietemplate.inc.php index 55c32737a3..ac21a260c0 100644 --- a/etemplate/inc/class.uietemplate.inc.php +++ b/etemplate/inc/class.uietemplate.inc.php @@ -51,7 +51,7 @@ $this->html = CreateObject('etemplate.html'); // should be in the api (older version in infolog) $this->sbox = CreateObject('etemplate.sbox2'); // older version is in the api - if (!$this->read($name,$template,$lang,$group,$version)) + if (empty($name) || !$this->read($name,$template,$lang,$group,$version)) { $this->init($name,$template,$lang,$group,$version,$rows,$cols); return False;