? t2xmlchk.php Index: Admin/Container/xml.php =================================================================== RCS file: /repository/pear/Translation2/Admin/Container/xml.php,v retrieving revision 1.8 diff -u -u -r1.8 xml.php --- Admin/Container/xml.php 10 Feb 2005 08:09:41 -0000 1.8 +++ Admin/Container/xml.php 16 Feb 2005 20:29:05 -0000 @@ -41,6 +41,12 @@ // {{{ class vars + /** + * Whether _saveData() is already registered at shutdown or not + * @var boolean + */ + var $_isScheduledSaving = false; + // }}} // {{{ addLang() @@ -251,7 +257,10 @@ { if ($this->options['save_on_shutdown']) { // save the changes on shutdown - register_shutdown_function(array(&$this, '_saveData')); + if (!$this->_isScheduledSaving) { + register_shutdown_function(array(&$this, '_saveData')); + $this->_isScheduledSaving = true; + } return true; } @@ -275,8 +284,16 @@ */ function _saveData() { - $this->_convertEncodings('to_xml'); - $this->_convertLangEncodings('to_xml'); + if ($this->options['save_on_shutdown']) { + $this->_convertEncodings('to_xml'); + $this->_convertLangEncodings('to_xml'); + $data =& $this->_data; + } else { + $this->_dataBuffer = $this->_data; + $this->_convertEncodings('to_xml', true); + $this->_convertLangEncodings('to_xml', true); + $data =& $this->_dataBuffer; + } // Serializing @@ -285,7 +302,7 @@ "\n" . " \n"; - foreach ($this->_data['languages'] as $lang => $spec) { + foreach ($data['languages'] as $lang => $spec) { extract ($spec); $xml .= " \n" . " " . @@ -307,7 +324,7 @@ $xml .= " \n" . " \n"; - foreach ($this->_data['pages'] as $page => $strings) { + foreach ($data['pages'] as $page => $strings) { $xml .= " \n"; foreach ($strings as $str_id => $translations) { @@ -325,6 +342,9 @@ $xml .= " \n" . "\n"; + // Possibly freeing some memory + unset ($this->_dataBuffer); + // Saving if (!$f = fopen ($this->_filename, 'w')) { Index: Container/xml.php =================================================================== RCS file: /repository/pear/Translation2/Container/xml.php,v retrieving revision 1.6 diff -u -u -r1.6 xml.php --- Container/xml.php 10 Feb 2005 08:09:42 -0000 1.6 +++ Container/xml.php 16 Feb 2005 20:29:05 -0000 @@ -88,11 +88,18 @@ /** * Unserialized XML data - * @var object + * @var array */ var $_data = null; /** + * Data buffer, used by encoding conversion + * @see Translation2_Container_xml:_convertEncodings() + * @var array + */ + var $_dataBuffer; + + /** * XML file name * @var string */ @@ -188,9 +195,11 @@ * Convert strings to/from XML unique charset (UTF-8) * * @param string ['from_xml' | 'to_xml'] + * @param boolean $useBuffer true: convert the content of the _dataBuffer property + * false: convert the content of the _data property * @return boolean|PEAR_Error */ - function _convertEncodings($direction) + function _convertEncodings($direction, $useBuffer=false) { if ($direction == 'from_xml') { $source_encoding = 'UTF-8'; @@ -198,15 +207,21 @@ $target_encoding = 'UTF-8'; } - foreach ($this->_data['pages'] as $page_id => $page_content) { + if ($useBuffer) { + $data =& $this->_dataBuffer; + } else { + $data =& $this->_data; + } + + foreach ($data['pages'] as $page_id => $page_content) { foreach ($page_content as $str_id => $translations) { foreach ($translations as $lang => $str) { if ($direction == 'from_xml') { $target_encoding = - strtoupper($this->_data['languages'][$lang]['encoding']); + strtoupper($data['languages'][$lang]['encoding']); } else { $source_encoding = - strtoupper($this->_data['languages'][$lang]['encoding']); + strtoupper($data['languages'][$lang]['encoding']); } if ($target_encoding != $source_encoding) { $res = iconv ($source_encoding, $target_encoding, $str); @@ -220,7 +235,7 @@ PEAR_ERROR_RETURN, E_USER_WARNING); } - $this->_data['pages'][$page_id][$str_id][$lang] = $res; + $data['pages'][$page_id][$str_id][$lang] = $res; } } } @@ -234,10 +249,12 @@ /** * Convert lang data to/from XML unique charset (UTF-8) * - * @param string $direction ['from_xml' | 'to_xml'] + * @param string $direction ['from_xml' | 'to_xml'] + * @param boolean $useBuffer true: convert the content of the _dataBuffer property + * false: convert the content of the _data property * @return boolean|PEAR_Error */ - function _convertLangEncodings($direction) + function _convertLangEncodings($direction, $useBuffer = false) { static $fields = array('name', 'meta', 'error_text'); @@ -247,7 +264,13 @@ $target_encoding = 'UTF-8'; } - foreach ($this->_data['languages'] as $lang_id => $lang) { + if ($useBuffer) { + $data =& $this->_dataBuffer; + } else { + $data =& $this->_data; + } + + foreach ($data['languages'] as $lang_id => $lang) { if ($direction == 'from_xml') { $target_encoding = strtoupper($lang['encoding']); } else { @@ -267,7 +290,7 @@ PEAR_ERROR_RETURN, E_USER_WARNING); } - $this->_data['languages'][$lang_id][$field] = $res; + $data['languages'][$lang_id][$field] = $res; } } } @@ -446,4 +469,4 @@ // }}} } -?> \ No newline at end of file +?>