+ return is_array($LOCAL_LANG) ? $LOCAL_LANG : array();
+ }
+
+ /**
+ * Includes a locallang-php file and returns the $LOCAL_LANG array
+ * Works only when the frontend or backend has been initialized with a charset conversion object. See first code lines.
+ *
+ * @param string Absolute reference to locallang-PHP file
+ * @param string TYPO3 language key, eg. "dk" or "de" or "default"
+ * @param string Character set (optional)
+ * @return array LOCAL_LANG array in return.
+ */
+ function readLLPHPfile($fileRef, $langKey, $charset='') {
+
+ if (is_object($GLOBALS['LANG'])) {
+ $csConvObj = &$GLOBALS['LANG']->csConvObj;
+ } elseif (is_object($GLOBALS['TSFE'])) {
+ $csConvObj = &$GLOBALS['TSFE']->csConvObj;
+ } else {
+ $csConvObj = t3lib_div::makeInstance('t3lib_cs');
+ }
+
+ if (@is_file($fileRef) && $langKey) {
+
+ // Set charsets:
+ $sourceCharset = $csConvObj->parse_charset($csConvObj->charSetArray[$langKey] ? $csConvObj->charSetArray[$langKey] : 'iso-8859-1');
+ if ($charset) {
+ $targetCharset = $csConvObj->parse_charset($charset);
+ } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) {
+ // when forceCharset is set, we store ALL labels in this charset!!!
+ $targetCharset = $csConvObj->parse_charset($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']);
+ } else {
+ $targetCharset = $csConvObj->parse_charset($csConvObj->charSetArray[$langKey] ? $csConvObj->charSetArray[$langKey] : 'iso-8859-1');
+ }
+
+ // Cache file name:
+ $hashSource = substr($fileRef,strlen(PATH_site)).'|'.date('d-m-Y H:i:s',filemtime($fileRef)).'|version=2.3';
+ $cacheFileName = PATH_site.'typo3temp/llxml/'.
+ substr(basename($fileRef),10,15).
+ '_'.t3lib_div::shortMD5($hashSource).'.'.$langKey.'.'.$targetCharset.'.cache';
+ // Check if cache file exists...
+ if (!@is_file($cacheFileName)) { // ... if it doesn't, create content and write it:
+
+ // Get PHP data
+ include($fileRef);
+ if (!is_array($LOCAL_LANG)) {
+ die('\''.$fileRef.'\' is no TYPO3 language file)!');
+ }
+
+ // converting the default language (English)
+ // this needs to be done for a few accented loan words and extension names
+ if (is_array($LOCAL_LANG['default'] && $targetCharset!='iso-8859-1')) {
+ foreach($LOCAL_LANG['default'] as $labelKey => $labelValue) {
+ $LOCAL_LANG['default'][$labelKey] = $csConvObj->conv($labelValue,'iso-8859-1',$targetCharset);
+ }
+ }
+
+ if ($langKey!='default' && is_array($LOCAL_LANG[$langKey]) && $sourceCharset!=$targetCharset) {
+ foreach($LOCAL_LANG[$langKey] as $labelKey => $labelValue) {
+ $LOCAL_LANG[$langKey][$labelKey] = $csConvObj->conv($labelValue,$sourceCharset,$targetCharset);
+ }
+ }
+
+ // Cache the content now:
+ $serContent = array('origFile'=>$hashSource, 'LOCAL_LANG'=>array('default'=>$LOCAL_LANG['default'], $langKey=>$LOCAL_LANG[$langKey]));
+ $res = t3lib_div::writeFileToTypo3tempDir($cacheFileName, serialize($serContent));
+ if ($res) die('ERROR: '.$res);
+ } else {
+ // Get content from cache:
+ $serContent = unserialize(t3lib_div::getUrl($cacheFileName));
+ $LOCAL_LANG = $serContent['LOCAL_LANG'];
+ }
+
+ return $LOCAL_LANG;
+ }