/** * Load translation data (XMLTM file reader) * * @param string $locale Locale/Language to add data for, identical with locale identifier, * see IfwPsn_Vendor_Zend_Locale for more information * @param string $filename XMLTM file to add, full path must be given for access * @param array $option OPTIONAL Options to use * @throws IfwPsn_Vendor_Zend_Translation_Exception * @return array */ protected function _loadTranslationData($filename, $locale, array $options = array()) { $this->_data = array(); $this->_lang = $locale; if (!is_readable($filename)) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Translate/Exception.php'; throw new IfwPsn_Vendor_Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.'); } $encoding = $this->_findEncoding($filename); $this->_file = xml_parser_create($encoding); xml_set_object($this->_file, $this); xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0); xml_set_element_handler($this->_file, "_startElement", "_endElement"); xml_set_character_data_handler($this->_file, "_contentElement"); try { IfwPsn_Vendor_Zend_Xml_Security::scanFile($filename); } catch (IfwPsn_Vendor_Zend_Xml_Exception $e) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Translate/Exception.php'; throw new IfwPsn_Vendor_Zend_Translate_Exception($e->getMessage()); } if (!xml_parse($this->_file, file_get_contents($filename))) { $ex = sprintf('XML error: %s at line %d of file %s', xml_error_string(xml_get_error_code($this->_file)), xml_get_current_line_number($this->_file), $filename); xml_parser_free($this->_file); require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Translate/Exception.php'; throw new IfwPsn_Vendor_Zend_Translate_Exception($ex); } return $this->_data; }
/** * Loads the section $section from the config file (or string $xml for * access facilitated by nested object properties. * * Sections are defined in the XML as children of the root element. * * In order to extend another section, a section defines the "extends" * attribute having a value of the section name from which the extending * section inherits values. * * Note that the keys in $section will override any keys of the same * name in the sections that have been included via "extends". * * The $options parameter may be provided as either a boolean or an array. * If provided as a boolean, this sets the $allowModifications option of * IfwPsn_Vendor_Zend_Config. If provided as an array, there are two configuration * directives that may be set. For example: * * $options = array( * 'allowModifications' => false, * 'skipExtends' => false * ); * * @param string $xml XML file or string to process * @param mixed $section Section to process * @param array|boolean $options * @throws IfwPsn_Vendor_Zend_Config_Exception When xml is not set or cannot be loaded * @throws IfwPsn_Vendor_Zend_Config_Exception When section $sectionName cannot be found in $xml */ public function __construct($xml, $section = null, $options = false) { if (empty($xml)) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php'; throw new IfwPsn_Vendor_Zend_Config_Exception('Filename is not set'); } $allowModifications = false; if (is_bool($options)) { $allowModifications = $options; } elseif (is_array($options)) { if (isset($options['allowModifications'])) { $allowModifications = (bool) $options['allowModifications']; } if (isset($options['skipExtends'])) { $this->_skipExtends = (bool) $options['skipExtends']; } } set_error_handler(array($this, '_loadFileErrorHandler')); // Warnings and errors are suppressed if (strstr($xml, '<?xml')) { $config = IfwPsn_Vendor_Zend_Xml_Security::scan($xml); } else { try { if (!($config = IfwPsn_Vendor_Zend_Xml_Security::scanFile($xml))) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php'; throw new IfwPsn_Vendor_Zend_Config_Exception("Error failed to load {$xml} file"); } } catch (IfwPsn_Vendor_Zend_Xml_Exception $e) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php'; throw new IfwPsn_Vendor_Zend_Config_Exception($e->getMessage()); } } restore_error_handler(); // Check if there was a error while loading file if ($this->_loadFileErrorStr !== null) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php'; throw new IfwPsn_Vendor_Zend_Config_Exception($this->_loadFileErrorStr); } if ($section === null) { $dataArray = array(); foreach ($config as $sectionName => $sectionData) { $dataArray[$sectionName] = $this->_processExtends($config, $sectionName); } parent::__construct($dataArray, $allowModifications); } else { if (is_array($section)) { $dataArray = array(); foreach ($section as $sectionName) { if (!isset($config->{$sectionName})) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php'; throw new IfwPsn_Vendor_Zend_Config_Exception("Section '{$sectionName}' cannot be found in {$xml}"); } $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray); } parent::__construct($dataArray, $allowModifications); } else { if (!isset($config->{$section})) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php'; throw new IfwPsn_Vendor_Zend_Config_Exception("Section '{$section}' cannot be found in {$xml}"); } $dataArray = $this->_processExtends($config, $section); if (!is_array($dataArray)) { // Section in the XML file contains just one top level string $dataArray = array($section => $dataArray); } parent::__construct($dataArray, $allowModifications); } } $this->_loadedSection = $section; }
/** * Find possible routing to other path or locale * * @param string $locale * @param string $path * @param string $attribute * @param string $value * @param array $temp * @throws IfwPsn_Vendor_Zend_Locale_Exception * @access private */ private static function _findRoute($locale, $path, $attribute, $value, &$temp) { // load locale file if not already in cache // needed for alias tag when referring to other locale if (empty(self::$_ldml[(string) $locale])) { $filename = dirname(__FILE__) . '/Data/' . $locale . '.xml'; if (!file_exists($filename)) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Exception.php'; throw new IfwPsn_Vendor_Zend_Locale_Exception("Missing locale file '{$filename}' for '{$locale}' locale."); } self::$_ldml[(string) $locale] = IfwPsn_Vendor_Zend_Xml_Security::scanFile($filename); } // search for 'alias' tag in the search path for redirection $search = ''; $tok = strtok($path, '/'); // parse the complete path if (!empty(self::$_ldml[(string) $locale])) { while ($tok !== false) { $search .= '/' . $tok; if (strpos($search, '[@') !== false) { while (strrpos($search, '[@') > strrpos($search, ']')) { $tok = strtok('/'); if (empty($tok)) { $search .= '/'; } $search = $search . '/' . $tok; } } $result = self::$_ldml[(string) $locale]->xpath($search . '/alias'); // alias found if (!empty($result)) { $source = $result[0]['source']; $newpath = $result[0]['path']; // new path - path //ldml is to ignore if ($newpath != '//ldml') { // other path - parse to make real path while (substr($newpath, 0, 3) == '../') { $newpath = substr($newpath, 3); $search = substr($search, 0, strrpos($search, '/')); } // truncate ../ to realpath otherwise problems with alias $path = $search . '/' . $newpath; while (($tok = strtok('/')) !== false) { $path = $path . '/' . $tok; } } // reroute to other locale if ($source != 'locale') { $locale = $source; } $temp = self::_getFile($locale, $path, $attribute, $value, $temp); return false; } $tok = strtok('/'); } } return true; }