TYPO3 CMS  TYPO3_6-2
AbstractXmlParser.php
Go to the documentation of this file.
1 <?php
3 
22 
26  protected $sourcePath;
27 
31  protected $languageKey;
32 
36  protected $charset;
37 
47  public function getParsedData($sourcePath, $languageKey, $charset = '') {
48  $this->sourcePath = $sourcePath;
49  $this->languageKey = $languageKey;
50  $this->charset = $this->getCharset($languageKey, $charset);
51  if ($this->languageKey !== 'default') {
52  $this->sourcePath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(\TYPO3\CMS\Core\Utility\GeneralUtility::llXmlAutoFileName($this->sourcePath, $this->languageKey));
53  if (!@is_file($this->sourcePath)) {
54  // Global localization is not available, try split localization file
56  }
57  if (!@is_file($this->sourcePath)) {
58  throw new \TYPO3\CMS\Core\Localization\Exception\FileNotFoundException('Localization file does not exist', 1306332397);
59  }
60  }
61  $LOCAL_LANG = array();
63  return $LOCAL_LANG;
64  }
65 
73  protected function getCharset($languageKey, $charset = '') {
75  if (is_object($GLOBALS['LANG'])) {
76  $csConvObj = $GLOBALS['LANG']->csConvObj;
77  } elseif (is_object($GLOBALS['TSFE'])) {
78  $csConvObj = $GLOBALS['TSFE']->csConvObj;
79  } else {
80  $csConvObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Charset\\CharsetConverter');
81  }
82  if ($charset !== '') {
83  $targetCharset = $csConvObj->parse_charset($charset);
84  } else {
85  $targetCharset = 'utf-8';
86  }
87  return $targetCharset;
88  }
89 
96  protected function parseXmlFile() {
97  $xmlContent = file_get_contents($this->sourcePath);
98  // Disables the functionality to allow external entities to be loaded when parsing the XML, must be kept
99  $previousValueOfEntityLoader = libxml_disable_entity_loader(TRUE);
100  $rootXmlNode = simplexml_load_string($xmlContent, 'SimpleXmlElement', \LIBXML_NOWARNING);
101  libxml_disable_entity_loader($previousValueOfEntityLoader);
102  if (!isset($rootXmlNode) || $rootXmlNode === FALSE) {
103  throw new \TYPO3\CMS\Core\Localization\Exception\InvalidXmlFileException('The path provided does not point to existing and accessible well-formed XML file.', 1278155988);
104  }
105  return $this->doParsingFromRoot($rootXmlNode);
106  }
107 
114  abstract protected function doParsingFromRoot(\SimpleXMLElement $root);
115 
116 }
static llXmlAutoFileName($fileRef, $language, $sameLocation=FALSE)
getParsedData($sourcePath, $languageKey, $charset='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static getFileAbsFileName($filename, $onlyRelative=TRUE, $relToTYPO3_mainDir=FALSE)