Added support for XML based locallang files (step 1, basic code)
authorKasper Skårhøj <kasper@typo3.org>
Sun, 6 Jun 2004 13:41:14 +0000 (13:41 +0000)
committerKasper Skårhøj <kasper@typo3.org>
Sun, 6 Jun 2004 13:41:14 +0000 (13:41 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@340 709f56b5-9817-0410-a4d7-c38de5d9e867

TODO.txt
t3lib/class.t3lib_div.php
typo3/alt_doc.php
typo3/alt_doc_nodoc.php
typo3/alt_palette.php
typo3/sysext/lang/lang.php

index dc227d5..f63b16f 100755 (executable)
--- a/TODO.txt
+++ b/TODO.txt
@@ -9,7 +9,7 @@ General:
 - Feature: "admin" can click a button which wipes out all record-lockings. (Message-Id: <200301281752.23246.mundaun@gmx.ch>)
 - Feature: Controlling access to function menu modules as well (thus we could have a user-module inside ?Template? which could edit the constants field)
 - Feature: Web >plugins -> to be a main module where people can place modules for their extension.
-- Substitute "->include_once[] = ...." with "require_once()" directly in classes - BUT the problem might be that class files accesses $TYPO3_CONF_VARS (for XCLASS inclusion) and if that is not accessible from the function including the script THEN all XCLASSes of that class will break!!!
+- Substitute "->include_once[] = ...." with "require_once()" directly in classes - BUT the problem is that class files accesses $TYPO3_CONF_VARS (for XCLASS inclusion) and that is not accessible from the function including the script unless "global $TYPO3_CONF_VARS" is set before inclusion. THEN all XCLASSes of that class will break!!!
 
 TCEmain:
 - Commenting of the class.
index 30e292f..88fdc97 100755 (executable)
@@ -2021,6 +2021,39 @@ class t3lib_div {
        }
 
        /**
+        * Writes $content to a filename in the typo3temp/ folder (and possibly a subfolder...)
+        *
+        * @param       string          FileNAME to write to inside "typo3temp/". No directory prefixed, just filename with extension.
+        * @param       string          Content string to write
+        * @param       string          Optional sub-directory in typo3temp/ to store the files in. (eg. "123" if the subdir should be "typo3temp/123/"). No trailing slash, only ONE level!
+        * @return      string          Returns false on success, otherwise an error string telling about the problem.
+        */
+       function writeFileToTypo3tempDir($filename,$content,$subdir='') {
+               if ($filename && strlen($filename)<60 && t3lib_div::validPathStr($filename) && !strstr('/',$filename))  {
+                       if (defined('PATH_site'))       {
+                               $dirName = PATH_site.'typo3temp/';      // Setting main temporary directory name (standard)
+                               if (@is_dir($dirName))  {
+                                               // Checking if the "subdir" string is set and if so, create directory if not present:
+                                       if ($subdir)    {
+                                               $dirName.= $subdir.'/';
+                                               if (!@is_dir($dirName)) {
+                                                       t3lib_div::mkdir($dirName);
+                                               }
+                                       }
+                                               // Checking dir-name again (sub-dir might have been created):
+                                       if (@is_dir($dirName))  {
+                                               $tempFile = t3lib_div::getFileAbsFileName($dirName.$filename);
+                                               if ($tempFile)  {
+                                                       t3lib_div::writeFile($tempFile,$content);
+                                                       if (!@is_file($tempFile))       return 'File not written to disk! Write permission error in filesystem?';
+                                               } else return 'For some reason, the temporary file was not valid!';
+                                       } else return '"'.$dirName.'" is not a directory!';
+                               } else return 'PATH_site + "typo3temp/" was not a directory!';
+                       } else return 'PATH_site constant was NOT defined!';
+               } else return 'Input filename was invalid!';
+       }
+
+       /**
         * Wrapper function for mkdir, setting folder permissions according to $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask']
         * Usage: 6
         *
index 513925c..81d1619 100755 (executable)
@@ -71,9 +71,9 @@
  */
 
 
-require ('init.php');
-require ('template.php');
-include ('sysext/lang/locallang_alt_doc.php');
+require('init.php');
+require('template.php');
+$LANG->includeLLFile('EXT:lang/locallang_alt_doc.php');
 require_once (PATH_t3lib.'class.t3lib_tceforms.php');
 require_once (PATH_t3lib.'class.t3lib_clipboard.php');
 
index 6232d4c..d6bea77 100755 (executable)
  *
  */
 
-require ('init.php');
-require ('template.php');
-include ('sysext/lang/locallang_alt_doc.php');
-require_once (PATH_t3lib.'class.t3lib_loadmodules.php');
+require('init.php');
+require('template.php');
+$LANG->includeLLFile('EXT:lang/locallang_alt_doc.php');
+require_once(PATH_t3lib.'class.t3lib_loadmodules.php');
 
 
 if (t3lib_extMgm::isLoaded('taskcenter') && t3lib_extMgm::isLoaded('taskcenter_recent'))       {
index 9cc1f4f..499c685 100755 (executable)
 
 
 
-require ('init.php');
-require ('template.php');
-require_once (PATH_t3lib.'class.t3lib_tceforms.php');
-require_once (PATH_t3lib.'class.t3lib_transferdata.php');
-require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
-include ('sysext/lang/locallang_alt_doc.php');
+require('init.php');
+require('template.php');
+require_once(PATH_t3lib.'class.t3lib_tceforms.php');
+require_once(PATH_t3lib.'class.t3lib_transferdata.php');
+require_once(PATH_t3lib.'class.t3lib_loaddbgroup.php');
+$LANG->includeLLFile('EXT:lang/locallang_alt_doc.php');
 
 
 
index fd9c5e3..ee964f1 100755 (executable)
@@ -426,13 +426,73 @@ class language {
         */
        function readLLfile($fileRef)   {
                $file = t3lib_div::getFileAbsFileName($fileRef);
-               if (@is_file($file))    {
-                       include($file);
+               if ($file)      {
+                       $baseFile = ereg_replace('\.(php|xml)$', '', $file);
+
+                       if (@is_file($baseFile.'.xml')) {
+                               $LOCAL_LANG = $this->readLLXMLfile($baseFile.'.xml', $this->lang);
+                       } elseif (@is_file($baseFile.'.php'))   {
+                               include($baseFile.'.php');
+                       }
                }
                return is_array($LOCAL_LANG)?$LOCAL_LANG:array();
        }
 
        /**
+        * Includes a locallang-xml file and returns the $LOCAL_LANG array
+        *
+        * @param       string
+        * @param       string
+        * @return      array
+        */
+       function readLLXMLfile($fileRef,$langKey)       {
+
+               if (@is_file($fileRef)) {
+                               // Set charset:
+                       $origCharset = $this->csConvObj->parse_charset($this->csConvObj->charSetArray[$langKey] ? $this->csConvObj->charSetArray[$langKey] : 'iso-8859-1');
+
+                               // Cache file name:
+                       $hashSource = substr($fileRef,strlen(PATH_site)).'|'.date('d-m-Y H:i:s',filemtime($fileRef));
+                       $cacheFileName = 'cache_llxml_'.t3lib_div::md5int($hashSource).'.'.$langKey.'.'.$origCharset.'.ser';
+                       $cacheFileName_dirPrefix = PATH_site.'typo3temp/llxml/';
+
+#$pt = t3lib_div::milliseconds();
+                               // Check if cache file exists...
+                       if (!@is_file($cacheFileName_dirPrefix.$cacheFileName)) {       // ... if it doesn't, create content and write it:
+
+                                       // Read XML, parse it and set default LOCAL_LANG array content:
+                               $xmlString = t3lib_div::getUrl($fileRef);
+                               $xmlContent = t3lib_div::xml2array($xmlString);
+                               $LOCAL_LANG = array();
+                               $LOCAL_LANG['default'] = $xmlContent['data']['default'];
+
+                                       // Specific language, convert from utf-8 to backend language charset:
+                                       // NOTICE: Converting from utf-8 back to "native" language may be a temporary solution until we can totally discard "locallang.php" files altogether (and use utf-8 for everything). But doing this conversion is the quickest way to migrate now and the source is in utf-8 anyway which is the main point.
+                               if ($langKey && $langKey!='default')    {
+                                       $LOCAL_LANG[$langKey] = $xmlContent['data'][$langKey];
+
+                                       if (is_array($LOCAL_LANG[$langKey]) && $origCharset!='utf-8')   {
+                                               foreach($LOCAL_LANG[$langKey] as $labelKey => $labelValue)      {
+                                                       $LOCAL_LANG[$langKey][$labelKey] = $this->csConvObj->utf8_decode($labelValue,$origCharset);
+                                               }
+                                       }
+                               }
+
+                               $serContent = array('origFile'=>$hashSource, 'LOCAL_LANG'=>$LOCAL_LANG);
+                               t3lib_div::writeFileToTypo3tempDir($cacheFileName, serialize($serContent), 'llxml');
+#debug('Saving cache...', basename($fileRef).' - '.$cacheFileName_dirPrefix.$cacheFileName);
+#debug(t3lib_div::milliseconds()-$pt);
+                       } else {
+                               $serContent = unserialize(t3lib_div::getUrl($cacheFileName_dirPrefix.$cacheFileName));
+                               $LOCAL_LANG = $serContent['LOCAL_LANG'];
+#debug('Getting cache...', basename($fileRef).' - '.$cacheFileName_dirPrefix.$cacheFileName);
+#debug(t3lib_div::milliseconds()-$pt);
+                       }
+                       return $LOCAL_LANG;
+               }
+       }
+
+       /**
         * Returns localized fileRef (.[langkey].php)
         *
         * @param       string          Filename/path of a 'locallang.php' file