Index: branches/5.2.x/core/units/helpers/language_import_helper.php =================================================================== diff -u -N -r15158 -r15222 --- branches/5.2.x/core/units/helpers/language_import_helper.php (.../language_import_helper.php) (revision 15158) +++ branches/5.2.x/core/units/helpers/language_import_helper.php (.../language_import_helper.php) (revision 15222) @@ -1,6 +1,6 @@ node. There are -* two more nodes PHRASES and EVENTS for phrase and email event translations. -* -* v2 -* ========== -* All data, that will end up in Language table is now attributes of LANGUAGE node -* and is name exactly as field name, that will be used to store that data. -* -* v4 -* ========== -* Hint & Column translation added to each phrase translation -*/ + * Language pack format version description + * + * v1 + * ========== + * All language properties are separate nodes inside node. There are + * two more nodes PHRASES and EVENTS for phrase and email event translations. + * + * v2 + * ========== + * All data, that will end up in Language table is now attributes of LANGUAGE node + * and is name exactly as field name, that will be used to store that data. + * + * v4 + * ========== + * Hint & Column translation added to each phrase translation + * + * v5 + * ========== + * Use separate xml nodes for subject, headers, html & plain translations + * + */ defined('FULL_PATH') or die('restricted access!'); @@ -101,6 +106,7 @@ var $_exportLimits = Array ( 'phrases' => false, 'emailevents' => false, + 'country-state' => false, ); /** @@ -115,7 +121,7 @@ * * @var int */ - var $_latestVersion = 4; + var $_latestVersion = 5; /** * Prefix-based serial numbers, that should be changed after import is finished @@ -223,9 +229,6 @@ $export_fields = $this->_getExportFields(); - $email_message_helper = $this->Application->recallObject('EmailMessageHelper'); - /* @var $email_message_helper EmailMessageHelper */ - // get languages $sql = 'SELECT * FROM ' . $this->Application->getUnitOption('lang','TableName') . ' @@ -271,25 +274,36 @@ ORDER BY `Event`, `Type`'; $events = $this->Conn->Query($sql, 'EventId'); - if (in_array('Core', $module_ids)) { + if ( in_array('Core', $module_ids) ) { + if ($this->_exportLimits['country-state']) { + $escaped_countries = $this->Conn->qstrArray($this->_exportLimits['country-state']); + $limit_where = '`IsoCode` IN (' . implode(',', $escaped_countries) . ')'; + } + else { + $limit_where = 'TRUE'; + } + + $country_table = $this->Application->getUnitOption('country-state', 'TableName'); + // countries $sql = 'SELECT * - FROM ' . $this->Application->getUnitOption('country-state', 'TableName') . ' - WHERE Type = ' . DESTINATION_TYPE_COUNTRY . ' + FROM ' . $country_table . ' + WHERE Type = ' . DESTINATION_TYPE_COUNTRY . ' AND ' . $limit_where . ' ORDER BY `IsoCode`'; $countries = $this->Conn->Query($sql, 'CountryStateId'); // states - $sql = 'SELECT * - FROM ' . $this->Application->getUnitOption('country-state', 'TableName') . ' - WHERE Type = ' . DESTINATION_TYPE_STATE . ' - ORDER BY `IsoCode`'; + $sql = 'SELECT state.* + FROM ' . $country_table . ' state + JOIN ' . $country_table . ' country ON country.CountryStateId = state.StateCountryId + WHERE state.Type = ' . DESTINATION_TYPE_STATE . ' AND ' . str_replace('`IsoCode`', 'country.`IsoCode`', $limit_where) . ' + ORDER BY state.`IsoCode`'; $states = $this->Conn->Query($sql, 'CountryStateId'); foreach ($states as $state_id => $state_data) { $country_id = $state_data['StateCountryId']; - if (!array_key_exists('States', $countries[$country_id])) { + if ( !array_key_exists('States', $countries[$country_id]) ) { $countries[$country_id]['States'] = Array (); } @@ -364,30 +378,33 @@ if ($events) { $ret .= "\t\t" . '' . "\n"; - foreach ($events as $event_id => $event) { + foreach ($events as $event_data) { $fields_hash = Array ( - 'Headers' => $event['Headers'], - 'Subject' => $event['l' . $language_id . '_Subject'], - 'Body' => $event['l' . $language_id . '_Body'], + 'HEADERS' => $event_data['Headers'], + 'SUBJECT' => $event_data['l' . $language_id . '_Subject'], + 'HTMLBODY' => $event_data['l' . $language_id . '_HtmlBody'], + 'PLAINTEXTBODY' => $event_data['l' . $language_id . '_PlainTextBody'], ); - $template = $email_message_helper->buildTemplate($fields_hash); + $data = ''; - if (!$template) { - // email event is not translated on given language - continue; + foreach ($fields_hash as $xml_node => $xml_content) { + if ( $xml_content ) { + $data .= "\t\t\t\t" . '<' . $xml_node . '>' . $this->_exportConvert($xml_content) . '' . "\n"; + } } - $data = $this->_exportEncoding == 'base64' ? base64_encode($template) : ''; - $ret .= "\t\t\t" . '' . $data . ''."\n"; + if ( $data ) { + $ret .= "\t\t\t" . '' . "\n" . $data . "\t\t\t" . '' . "\n"; + } } $ret .= "\t\t" . '' . "\n"; } if (in_array('Core', $module_ids) && $countries) { $ret .= "\t\t" . '' . "\n"; - foreach ($countries as $country_id => $country_data) { + foreach ($countries as $country_data) { $translation = $country_data['l' . $language_id . '_Name']; if (!$translation) { @@ -433,6 +450,18 @@ } /** + * Converts string before placing into export file + * + * @param string $string + * @return string + * @access protected + */ + protected function _exportConvert($string) + { + return $this->_exportEncoding == 'base64' ? base64_encode($string) : ''; + } + + /** * Sets language pack encoding (not charset) used during export * * @param string $encoding @@ -890,36 +919,39 @@ foreach ($events as $event_node) { /* @var $event_node SimpleXMLElement */ + $message_type = (string)$event_node['MessageType']; $event_id = $this->_getEventId((string)$event_node['Event'], (int)$event_node['Type']); if ( !$event_id ) { continue; } - if ( $language_encoding == 'plain' ) { - $template = rtrim($event_node); - } - else { - $template = base64_decode($event_node); - } - - $parsed = $email_message_helper->parseTemplate($template); - $fields_hash = Array ( 'EventId' => $event_id, 'Event' => (string)$event_node['Event'], 'Type' => (int)$event_node['Type'], - 'MessageType' => (string)$event_node['MessageType'], ); + if ( $message_type == '' ) { + $parsed = $email_message_helper->parseTemplate($event_node, ''); + $parsed = array_map($language_encoding == 'plain' ? 'rtrim' : 'base64_decode', $parsed); + + } + else { + $template = $language_encoding == 'plain' ? rtrim($event_node) : base64_decode($event_node); + $parsed = $email_message_helper->parseTemplate($template, $message_type); + } + if ( array_key_exists($event_id, $other_translations) ) { $other_translations[$event_id]['l' . $language_id . '_Subject'] = $parsed['Subject']; - $other_translations[$event_id]['l' . $language_id . '_Body'] = $parsed['Body']; + $other_translations[$event_id]['l' . $language_id . '_HtmlBody'] = $parsed['HtmlBody']; + $other_translations[$event_id]['l' . $language_id . '_PlainTextBody'] = $parsed['PlainTextBody']; } else { $other_translations[$event_id] = Array ( 'l' . $language_id . '_Subject' => $parsed['Subject'], - 'l' . $language_id . '_Body' => $parsed['Body'], + 'l' . $language_id . '_HtmlBody' => $parsed['HtmlBody'], + 'l' . $language_id . '_PlainTextBody' => $parsed['PlainTextBody'], ); }