From d10698d7fb6b23eeb4adbdb9627228ebaaf34d0a Mon Sep 17 00:00:00 2001 From: flyskyko Date: Tue, 6 Sep 2011 09:17:00 +0000 Subject: [PATCH] use eval() for lang code when first install git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9053 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- classes/context/Context.class.php | 17 ++++++++++++++++- classes/xml/XmlLangParser.class.php | 17 ++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/classes/context/Context.class.php b/classes/context/Context.class.php index f010966db..713294c18 100644 --- a/classes/context/Context.class.php +++ b/classes/context/Context.class.php @@ -468,7 +468,22 @@ class Context { if(in_array($filename, $self->loaded_lang_files)) return; $self->loaded_lang_files[] = $filename; - @include($filename); + if (is_readable($filename)) + @include($filename); + else + $self->_evalxmlLang($path); + } + + function _evalxmlLang($path) { + global $lang; + + if(substr($path,-1)!='/') $path .= '/'; + $file = $path.'lang.xml'; + + $oXmlLangParser = new XmlLangParser($file, $this->lang_type); + $content = $oXmlLangParser->getCompileContent(); + + eval($content); } function _loadXmlLang($path) { diff --git a/classes/xml/XmlLangParser.class.php b/classes/xml/XmlLangParser.class.php index fc69fd308..9a780a4d6 100644 --- a/classes/xml/XmlLangParser.class.php +++ b/classes/xml/XmlLangParser.class.php @@ -31,7 +31,7 @@ if(!file_exists($this->xml_file)) return false; if(!file_exists($this->php_file)){ $this->_compile(); - } else { + } else { if(filemtime($this->xml_file)>filemtime($this->php_file)) $this->_compile(); else return $this->php_file; } @@ -39,6 +39,13 @@ return $this->_writefile() ? $this->php_file : false; } + function getCompileContent() { + if(!file_exists($this->xml_file)) return false; + $this->_compile(); + + return $this->code; + } + /** * @brief compile a xml_file **/ @@ -81,21 +88,21 @@ $type = $item->attrs->type; if($type == 'array'){ - $this->code .= $var."=array();\n"; + $this->code .= $var."=array();\n"; $var .= '[\'%s\']'; }else{ - $this->code .= $var."=new stdClass;\n"; + $this->code .= $var."=new stdClass;\n"; $var .= '->%s'; } $items = $item->item; - if(!is_array($items)) $item = array($items); + if(!is_array($items)) $items = array($items); foreach($items as $item){ $this->_parseItem($item, $var); } } else { - $code = $this->_parseValues($value, $var); + $code = $this->_parseValues($value, $var); $this->code .= $code; } }