Index: install/install_toolkit.php =================================================================== --- install/install_toolkit.php (revision 15137) +++ install/install_toolkit.php (working copy) @@ -672,34 +672,30 @@ */ function getModuleInfo($module_name) { - if ($module_name == 'core') { + if ( $module_name == 'core' ) { $info_file = FULL_PATH . '/' . $module_name . '/install/module_info.xml'; } else { $info_file = MODULES_PATH . '/' . $module_name . '/install/module_info.xml'; } - if (!file_exists($info_file)) { + if ( !file_exists($info_file) ) { return Array (); } - $xml_helper = $this->Application->recallObject('kXMLHelper'); - /* @var $xml_helper kXMLHelper */ + $ret = Array (); + $module_info = simplexml_load_file($info_file); - $root_node =& $xml_helper->Parse( file_get_contents($info_file) ); - - if (!is_object($root_node) || !preg_match('/^kxmlnode/i', get_class($root_node)) || ($root_node->Name == 'ERROR')) { + if ( $module_info === false ) { // non-valid xml file return Array (); } - $ret = Array (); - $current_node =& $root_node->firstChild; + foreach ($module_info as $node) { + /* @var $node SimpleXMLElement */ + $ret[strtolower($node->getName())] = trim($node); + } - do { - $ret[ strtolower($current_node->Name) ] = trim($current_node->Data); - } while (($current_node =& $current_node->NextSibling())); - return $ret; } Index: units/helpers/controls/minput_helper.php =================================================================== --- units/helpers/controls/minput_helper.php (revision 15145) +++ units/helpers/controls/minput_helper.php (working copy) @@ -109,31 +109,22 @@ function parseMInputXML($xml) { - $xml_helper = $this->Application->recallObject('kXMLHelper'); - /* @var $xml_helper kXMLHelper */ + $records = Array (); + $records_node = simplexml_load_string($xml); - $root_node =& $xml_helper->Parse($xml); - $root_node =& $root_node->FindChild('records'); - - if ( !$root_node || !$root_node->firstChild ) { + if ( $records_node === false ) { return false; } - $records = Array (); - $current_node = $root_node->firstChild; - /* @var $current_node kXMLNode */ - - do { + foreach ($records_node as $record_node) { $record = Array (); - $sub_node =& $current_node->firstChild; - /* @var $current_node kXMLNode */ - do { - $record[ $sub_node->Attributes['NAME'] ] = $sub_node->Data; - } while ( ($sub_node =& $sub_node->NextSibling()) ); + foreach ($record_node as $field_node) { + $record[(string)$field_node['name']] = (string)$field_node; + } $records[] = $record; - } while ( ($current_node =& $current_node->NextSibling()) ); + } return $records; } Index: units/helpers/language_import_helper.php =================================================================== --- units/helpers/language_import_helper.php (revision 15137) +++ units/helpers/language_import_helper.php (working copy) @@ -592,27 +592,23 @@ function _parseXML($filename) { - if ($this->_debugMode) { + if ( $this->_debugMode ) { $start_time = microtime(true); $this->Application->Debugger->appendHTML(__CLASS__ . '::' . __FUNCTION__ . '("' . $filename . '")'); } - $fdata = file_get_contents($filename); + $languages = simplexml_load_file($filename); - $xml_parser = $this->Application->recallObject('kXMLHelper'); - /* @var $xml_parser kXMLHelper */ - - $root_node =& $xml_parser->Parse($fdata); - if (!is_object($root_node) || !is_a($root_node, 'kXMLNode')) { + if ( $languages === false) { // invalid language pack contents return false; } - if ($root_node->Children) { - $this->_processLanguages($root_node->firstChild); + if ( $languages->count() ) { + $this->_processLanguages($languages); } - if ($this->_debugMode) { + if ( $this->_debugMode ) { $this->Application->Debugger->appendHTML(__CLASS__ . '::' . __FUNCTION__ . '("' . $filename . '"): ' . (microtime(true) - $start_time)); } @@ -707,25 +703,23 @@ /** * Processes parsed XML * - * @param kXMLNode $language_node + * @param SimpleXMLElement $languages */ - function _processLanguages(&$language_node) + function _processLanguages($languages) { - if (array_key_exists('VERSION', $language_node->Parent->Attributes)) { - // version present -> use it - $version = $language_node->Parent->Attributes['VERSION']; - } - else { + $version = (int)$languages['Version']; + + if ( !$version ) { // version missing -> guess it - if (is_object($language_node->FindChild('DATEFORMAT'))) { + if ( $languages->DATEFORMAT->getName() ) { $version = 1; } - elseif (array_key_exists('CHARSET', $language_node->Attributes)) { + elseif ( (string)$languages->LANGUAGE['Charset'] != '' ) { $version = 2; } } - if ($version == 1) { + if ( $version == 1 ) { $field_mapping = Array ( 'DATEFORMAT' => 'DateFormat', 'TIMEFORMAT' => 'TimeFormat', @@ -742,75 +736,58 @@ $export_fields = $this->_getExportFields(); } - do { + foreach ($languages as $language_node) { $language_id = false; $fields_hash = Array ( - 'PackName' => $language_node->Attributes['PACKNAME'], - 'LocalName' => $language_node->Attributes['PACKNAME'], - 'Encoding' => $language_node->Attributes['ENCODING'], + 'PackName' => (string)$language_node['PackName'], + 'LocalName' => (string)$language_node['PackName'], + 'Encoding' => (string)$language_node['Encoding'], 'Charset' => 'utf-8', 'SynchronizationModes' => Language::SYNCHRONIZE_DEFAULT, ); - if ($version > 1) { + if ( $version > 1 ) { foreach ($export_fields as $export_field) { - $attribute_name = strtoupper($export_field); - - if (array_key_exists($attribute_name, $language_node->Attributes)) { - $fields_hash[$export_field] = $language_node->Attributes[$attribute_name]; + if ( (string)$language_node[$export_field] ) { + $fields_hash[$export_field] = (string)$language_node[$export_field]; } } } - $sub_node =& $language_node->firstChild; - /* @var $sub_node kXMLNode */ + $container_nodes = Array ('PHRASES', 'EVENTS', 'COUNTRIES'); - do { - switch ($sub_node->Name) { - case 'PHRASES': - if ($sub_node->Children) { - if (!$language_id) { - $language_id = $this->_processLanguage($fields_hash); - } + foreach ($language_node as $sub_node) { + /* @var $sub_node SimpleXMLElement */ - if ($this->_debugMode) { - $start_time = microtime(true); - } + if ( in_array($sub_node->getName(), $container_nodes) ) { + if ( !$sub_node->count() ) { + continue; + } - $this->_processPhrases($sub_node->firstChild, $language_id, $fields_hash['Encoding']); + if ( !$language_id ) { + $language_id = $this->_processLanguage($fields_hash); + } + } - if ($this->_debugMode) { - $this->Application->Debugger->appendHTML(__CLASS__ . '::' . '_processPhrases: ' . (microtime(true) - $start_time)); - } - } + switch ($sub_node->getName()) { + case 'PHRASES': + $this->_processPhrases($sub_node, $language_id, $fields_hash['Encoding']); break; case 'EVENTS': - if ($sub_node->Children) { - if (!$language_id) { - $language_id = $this->_processLanguage($fields_hash); - } - - $this->_processEvents($sub_node->firstChild, $language_id, $fields_hash['Encoding']); - } + $this->_processEvents($sub_node, $language_id, $fields_hash['Encoding']); break; case 'COUNTRIES': - if ($sub_node->Children) { - if (!$language_id) { - $language_id = $this->_processLanguage($fields_hash); - } - - $this->_processCountries($sub_node->firstChild, $language_id, $fields_hash['Encoding']); - } + $this->_processCountries($sub_node, $language_id, $fields_hash['Encoding']); break; case 'REPLACEMENTS': // added since v2 - $replacements = $sub_node->Data; + $replacements = (string)$sub_node; - if ($fields_hash['Encoding'] != 'plain') { + if ( $fields_hash['Encoding'] != 'plain' ) { $replacements = base64_decode($replacements); } @@ -818,54 +795,56 @@ break; default: - if ($version == 1) { - $fields_hash[ $field_mapping[$sub_node->Name] ] = $sub_node->Data; + if ( $version == 1 ) { + $fields_hash[$field_mapping[$sub_node->Name]] = (string)$sub_node; } break; } - } while (($sub_node =& $sub_node->NextSibling())); - } while (($language_node =& $language_node->NextSibling())); + } + } } /** * Performs phases import * - * @param kXMLNode $phrase_node + * @param SimpleXMLElement $phrases * @param int $language_id * @param string $language_encoding */ - function _processPhrases(&$phrase_node, $language_id, $language_encoding) + function _processPhrases($phrases, $language_id, $language_encoding) { static $other_translations = Array (); - if ($this->Application->isDebugMode()) { + if ( $this->Application->isDebugMode() ) { $this->Application->Debugger->profileStart('L[' . $language_id . ']P', 'Language: ' . $language_id . '; Phrases Import'); } - do { - $phrase_key = mb_strtoupper($phrase_node->Attributes['LABEL']); + foreach ($phrases as $phrase_node) { + /* @var $phrase_node SimpleXMLElement */ + $phrase_key = mb_strtoupper($phrase_node['Label']); + $fields_hash = Array ( - 'Phrase' => $phrase_node->Attributes['LABEL'], + 'Phrase' => (string)$phrase_node['Label'], 'PhraseKey' => $phrase_key, - 'PhraseType' => $phrase_node->Attributes['TYPE'], - 'Module' => array_key_exists('MODULE', $phrase_node->Attributes) ? $phrase_node->Attributes['MODULE'] : 'Core', - 'LastChanged' => adodb_mktime(), + 'PhraseType' => (int)$phrase_node['Type'], + 'Module' => (string)$phrase_node['Module'] ? (string)$phrase_node['Module'] : 'Core', + 'LastChanged' => TIMENOW, 'LastChangeIP' => $this->ip_address, ); - $translation = $phrase_node->Data; - $hint_translation = isset($phrase_node->Attributes['HINT']) ? $phrase_node->Attributes['HINT'] : ''; - $column_translation = isset($phrase_node->Attributes['COLUMN']) ? $phrase_node->Attributes['COLUMN'] : ''; + $translation = (string)$phrase_node; + $hint_translation = (string)$phrase_node['Hint']; + $column_translation = (string)$phrase_node['Column']; - if (array_key_exists($fields_hash['PhraseType'], $this->phrase_types_allowed)) { - if ($language_encoding != 'plain') { + if ( array_key_exists($fields_hash['PhraseType'], $this->phrase_types_allowed) ) { + if ( $language_encoding != 'plain' ) { $translation = base64_decode($translation); $hint_translation = base64_decode($hint_translation); $column_translation = base64_decode($column_translation); } - if (array_key_exists($phrase_key, $other_translations)) { + if ( array_key_exists($phrase_key, $other_translations) ) { $other_translations[$phrase_key]['l' . $language_id . '_Translation'] = $translation; $other_translations[$phrase_key]['l' . $language_id . '_HintTranslation'] = $hint_translation; $other_translations[$phrase_key]['l' . $language_id . '_ColumnTranslation'] = $column_translation; @@ -881,9 +860,9 @@ $fields_hash = array_merge($fields_hash, $other_translations[$phrase_key]); $this->Conn->doInsert($fields_hash, $this->_tables['phrases'], 'REPLACE', false); } - } while (($phrase_node =& $phrase_node->NextSibling())); + } - if ($this->Application->isDebugMode()) { + if ( $this->Application->isDebugMode() ) { $this->Application->Debugger->profileFinish('L[' . $language_id . ']P', 'Language: ' . $language_id . '; Phrases Import'); } @@ -893,68 +872,73 @@ /** * Performs email event import * - * @param kXMLNode $event_node + * @param SimpleXMLElement $events * @param int $language_id * @param string $language_encoding */ - function _processEvents(&$event_node, $language_id, $language_encoding) + function _processEvents($events, $language_id, $language_encoding) { static $other_translations = Array (); - if ($this->Application->isDebugMode()) { + if ( $this->Application->isDebugMode() ) { $this->Application->Debugger->profileStart('L[' . $language_id . ']E', 'Language: ' . $language_id . '; Events Import'); } $email_message_helper = $this->Application->recallObject('EmailMessageHelper'); /* @var $email_message_helper EmailMessageHelper */ - do { - $event_id = $this->_getEventId($event_node->Attributes['EVENT'], $event_node->Attributes['TYPE']); - if ($event_id) { - if ($language_encoding == 'plain') { - $template = rtrim($event_node->Data); - } - else { - $template = base64_decode($event_node->Data); - } + foreach ($events as $event_node) { + /* @var $event_node SimpleXMLElement */ - $parsed = $email_message_helper->parseTemplate($template); + $event_id = $this->_getEventId((string)$event_node['Event'], (int)$event_node['Type']); - $fields_hash = Array ( - 'EventId' => $event_id, - 'Event' => $event_node->Attributes['EVENT'], - 'Type' => $event_node->Attributes['TYPE'], - 'MessageType' => $event_node->Attributes['MESSAGETYPE'], - ); + if ( !$event_id ) { + continue; + } - 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']; - } - else { - $other_translations[$event_id] = Array ( - 'l' . $language_id . '_Subject' => $parsed['Subject'], - 'l' . $language_id . '_Body' => $parsed['Body'], - ); - } + if ( $language_encoding == 'plain' ) { + $template = rtrim($event_node); + } + else { + $template = base64_decode($event_node); + } - if ($parsed['Headers']) { - $other_translations[$event_id]['Headers'] = $parsed['Headers']; - } - elseif (!$parsed['Headers'] && !array_key_exists('Headers', $other_translations[$event_id])) { - $other_translations[$event_id]['Headers'] = $parsed['Headers']; - } + $parsed = $email_message_helper->parseTemplate($template); - $fields_hash = array_merge($fields_hash, $other_translations[$event_id]); - $this->Conn->doInsert($fields_hash, $this->_tables['emailevents'], 'REPLACE', false); + $fields_hash = Array ( + 'EventId' => $event_id, + 'Event' => (string)$event_node['Event'], + 'Type' => (int)$event_node['Type'], + 'MessageType' => (string)$event_node['MessageType'], + ); + + 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']; } - } while (($event_node =& $event_node->NextSibling())); + else { + $other_translations[$event_id] = Array ( + 'l' . $language_id . '_Subject' => $parsed['Subject'], + 'l' . $language_id . '_Body' => $parsed['Body'], + ); + } - if ($this->Application->isDebugMode()) { + if ( $parsed['Headers'] ) { + $other_translations[$event_id]['Headers'] = $parsed['Headers']; + } + elseif ( !$parsed['Headers'] && !array_key_exists('Headers', $other_translations[$event_id]) ) { + $other_translations[$event_id]['Headers'] = $parsed['Headers']; + } + + $fields_hash = array_merge($fields_hash, $other_translations[$event_id]); + $this->Conn->doInsert($fields_hash, $this->_tables['emailevents'], 'REPLACE', false); + } + + if ( $this->Application->isDebugMode() ) { $this->Application->Debugger->profileFinish('L[' . $language_id . ']E', 'Language: ' . $language_id . '; Events Import'); } - if (isset($fields_hash)) { + if ( isset($fields_hash) ) { // at least one email event in language pack was found in database $this->Conn->doInsert($fields_hash, $this->_tables['emailevents'], 'REPLACE'); } @@ -963,53 +947,53 @@ /** * Performs country_state translation import * - * @param kXMLNode $country_state_node + * @param SimpleXMLElement $country_states * @param int $language_id * @param string $language_encoding * @param bool $process_states * @return void */ - function _processCountries(&$country_state_node, $language_id, $language_encoding, $process_states = false) + function _processCountries($country_states, $language_id, $language_encoding, $process_states = false) { static $other_translations = Array (); - do { - if ($process_states) { - $country_state_id = $this->_getStateId($country_state_node->Parent->Attributes['ISO'], $country_state_node->Attributes['ISO']); + foreach ($country_states as $country_state_node) { + /* @var $country_state_node SimpleXMLElement */ + + if ( $process_states ) { + $country_state_id = $this->_getStateId((string)$country_states['Iso'], (string)$country_state_node['Iso']); } else { - $country_state_id = $this->_getCountryId($country_state_node->Attributes['ISO']); + $country_state_id = $this->_getCountryId((string)$country_state_node['Iso']); } - if ($country_state_id) { - if ($language_encoding == 'plain') { - $translation = rtrim($country_state_node->Attributes['TRANSLATION']); - } - else { - $translation = base64_decode($country_state_node->Attributes['TRANSLATION']); - } + if ( !$country_state_id ) { + continue; + } - $fields_hash = Array ( - 'CountryStateId' => $country_state_id, - ); + if ( $language_encoding == 'plain' ) { + $translation = rtrim($country_state_node['Translation']); + } + else { + $translation = base64_decode($country_state_node['Translation']); + } - if (array_key_exists($country_state_id, $other_translations)) { - $other_translations[$country_state_id]['l' . $language_id . '_Name'] = $translation; - } - else { - $other_translations[$country_state_id] = Array ( - 'l' . $language_id . '_Name' => $translation, - ); - } + $fields_hash = Array ('CountryStateId' => $country_state_id); - $fields_hash = array_merge($fields_hash, $other_translations[$country_state_id]); - $this->Conn->doInsert($fields_hash, $this->_tables['country-state'], 'REPLACE', false); + if ( array_key_exists($country_state_id, $other_translations) ) { + $other_translations[$country_state_id]['l' . $language_id . '_Name'] = $translation; + } + else { + $other_translations[$country_state_id] = Array ('l' . $language_id . '_Name' => $translation); + } - if (!$process_states && $country_state_node->Children) { - $this->_processCountries($country_state_node->firstChild, $language_id, $language_encoding, true); - } + $fields_hash = array_merge($fields_hash, $other_translations[$country_state_id]); + $this->Conn->doInsert($fields_hash, $this->_tables['country-state'], 'REPLACE', false); + + if ( !$process_states && $country_state_node->count() ) { + $this->_processCountries($country_state_node, $language_id, $language_encoding, true); } - } while (($country_state_node =& $country_state_node->NextSibling())); + } $this->Conn->doInsert($fields_hash, $this->_tables['country-state'], 'REPLACE'); } Index: units/helpers/themes_helper.php =================================================================== --- units/helpers/themes_helper.php (revision 15137) +++ units/helpers/themes_helper.php (working copy) @@ -187,52 +187,45 @@ { $template_aliases = Array (); - $xml_parser = $this->Application->recallObject('kXMLHelper'); - /* @var $xml_parser kXMLHelper */ - foreach ($this->Application->ModuleInfo as $module_name => $module_info) { - if ( $module_name == 'In-Portal' ) { + $xml_file = $theme_path . '/' . $module_info['TemplatePath'] . '_install/theme.xml'; + + if ( $module_name == 'In-Portal' || !file_exists($xml_file) ) { continue; } - $xml_file = $theme_path . '/' . $module_info['TemplatePath'] . '_install/theme.xml'; + $theme = simplexml_load_file($xml_file); - if ( file_exists($xml_file) ) { - $xml_data = file_get_contents($xml_file); - $root_node =& $xml_parser->Parse($xml_data); + if ( $theme === false ) { + // broken xml OR no aliases defined + continue; + } - if ( !is_object($root_node) || !is_a($root_node, 'kXMLNode') || !$root_node->Children ) { - // broken xml OR no aliases defined - continue; - } + foreach ($theme as $design) { + /* @var $design SimpleXMLElement */ - $current_node =& $root_node->firstChild; - /* @var $current_node kXMLNode */ + $template_path = trim($design); + $module_override = (string)$design['module']; - do { - $template_path = trim($current_node->Data); - $module_override = $current_node->GetAttribute('module'); + if ( $module_override ) { + // allow to put template mappings form all modules into single theme.xml file + $module_folder = $this->Application->findModule('Name', $module_override, 'TemplatePath'); + } + else { + // no module specified -> use module based on theme.xml file location + $module_folder = $module_info['TemplatePath']; + } - if ( $module_override ) { - // allow to put template mappings form all modules into single theme.xml file - $module_folder = $this->Application->findModule('Name', $module_override, 'TemplatePath'); - } - else { - // no module specified -> use module based on theme.xml file location - $module_folder = $module_info['TemplatePath']; - } + // only store alias, when template exists on disk + if ( $this->getTemplateId($template_path, $theme_id) ) { + $alias = '#' . $module_folder . strtolower($design->getName()) . '#'; - // only store alias, when template exists on disk - if ( $this->getTemplateId($template_path, $theme_id) ) { - $alias = '#' . $module_folder . strtolower($current_node->Name) . '#'; + // remember alias in global theme mapping + $template_aliases[$alias] = $template_path; - // remember alias in global theme mapping - $template_aliases[$alias] = $template_path; - - // store alias in theme file record to use later in design dropdown - $this->updateTemplate($template_path, $theme_id, Array ('TemplateAlias' => $alias)); - } - } while ( ($current_node =& $current_node->NextSibling()) ); + // store alias in theme file record to use later in design dropdown + $this->updateTemplate($template_path, $theme_id, Array ('TemplateAlias' => $alias)); + } } }