Fixed bug #14050: CleanUp - CGL format of t3lib files - t3lib_scbase
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_transl8tools.php
old mode 100755 (executable)
new mode 100644 (file)
index ff5ed4d..c4587cd
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 2006-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -27,9 +27,9 @@
 /**
  * Contains translation tools
  *
- * $Id: class.t3lib_loaddbgroup.php 1816 2006-11-26 00:43:24Z mundaun $
+ * $Id$
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
@@ -60,7 +60,7 @@
 /**
  * Contains translation tools
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage t3lib
  */
@@ -68,27 +68,32 @@ class t3lib_transl8tools    {
 
        /**
         * Returns array of system languages
+        *
+        * Since TYPO3 4.5 the flagIcon is not returned as a filename in "gfx/flags/*" anymore,
+        * but as a string <flags-xx>. The calling party should call
+        * t3lib_iconWorks::getSpriteIcon(<flags-xx>) to get an HTML which will represent
+        * the flag of this language.
+        *
         * @param       integer         page id (only used to get TSconfig configuration setting flag and label for default language)
         * @param       string          Backpath for flags
-        * @return      array           
+        * @return      array           Array with languages (title, uid, flagIcon)
         */
        function getSystemLanguages($page_id=0,$backPath='')    {
                global $TCA,$LANG;
 
-                       // Icons and language titles:
-               t3lib_div::loadTCA('sys_language');
-               $flagAbsPath = t3lib_div::getFileAbsFileName($TCA['sys_language']['columns']['flag']['config']['fileFolder']);
-               $flagIconPath = $backPath.'../'.substr($flagAbsPath, strlen(PATH_site));
-
                $modSharedTSconfig = t3lib_BEfunc::getModTSconfig($page_id, 'mod.SHARED');
                $languageIconTitles = array();
 
-                       // Set default:
+                       // fallback "old iconstyles"
+               if (preg_match('/\.gif$/', $modSharedTSconfig['properties']['defaultLanguageFlag'])) {
+                       $modSharedTSconfig['properties']['defaultLanguageFlag'] = str_replace('.gif', '', $modSharedTSconfig['properties']['defaultLanguageFlag']);
+               }
+
                $languageIconTitles[0] = array(
                        'uid' => 0,
-                       'title' => strlen ($modSharedTSconfig['properties']['defaultLanguageLabel']) ? $modSharedTSconfig['properties']['defaultLanguageLabel'].' ('.$LANG->getLL('defaultLanguage').')' : $LANG->getLL('defaultLanguage'),
+                       'title' => strlen($modSharedTSconfig['properties']['defaultLanguageLabel']) ? $modSharedTSconfig['properties']['defaultLanguageLabel'].' ('.$GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_mod_web_list.xml:defaultLanguage').')' : $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_mod_web_list.xml:defaultLanguage'),
                        'ISOcode' => 'DEF',
-                       'flagIcon' => strlen($modSharedTSconfig['properties']['defaultLanguageFlag']) && @is_file($flagAbsPath.$modSharedTSconfig['properties']['defaultLanguageFlag']) ? $flagIconPath.$modSharedTSconfig['properties']['defaultLanguageFlag'] : null,
+                       'flagIcon' => strlen($modSharedTSconfig['properties']['defaultLanguageFlag']) ? 'flags-' . $modSharedTSconfig['properties']['defaultLanguageFlag'] : 'empty-empty',
                );
 
                        // Set "All" language:
@@ -96,7 +101,7 @@ class t3lib_transl8tools     {
                        'uid' => -1,
                        'title' => $LANG->getLL('multipleLanguages'),
                        'ISOcode' => 'DEF',
-                       'flagIcon' => $flagIconPath.'multi-language.gif',
+                       'flagIcon' => 'flags-multiple',
                );
 
                        // Find all system languages:
@@ -115,7 +120,7 @@ class t3lib_transl8tools    {
                                }
                        }
                        if (strlen ($row['flag'])) {
-                               $languageIconTitles[$row['uid']]['flagIcon'] = @is_file($flagAbsPath.$row['flag']) ? $flagIconPath.$row['flag'] : '';
+                               $languageIconTitles[$row['uid']]['flagIcon'] = t3lib_iconWorks::mapRecordTypeToSpriteIconName('sys_language', $row);
                        }
                }
 
@@ -129,15 +134,20 @@ class t3lib_transl8tools  {
         * @param       string          Table name
         * @param       integer         Record uid
         * @param       integer         Language uid. If zero, then all languages are selected.
+        * @param       array           The record to be translated
+        * @param       array           select fields for the query which fetches the translations of the current record
         * @return      array           Array with information. Errors will return string with message.
         */
-       function translationInfo($table,$uid,$sys_language_uid=0)       {
+       function translationInfo($table, $uid, $sys_language_uid = 0, $row = NULL, $selFieldList = '') {
                global $TCA;
 
                if ($TCA[$table] && $uid)       {
                        t3lib_div::loadTCA($table);
 
-                       $row = t3lib_BEfunc::getRecordWSOL($table,$uid);
+                       if ($row === NULL) {
+                               $row = t3lib_BEfunc::getRecordWSOL($table, $uid);
+                       }
+
                        if (is_array($row))     {
                                $trTable = $this->getTranslationTable($table);
                                if ($trTable)   {
@@ -146,11 +156,11 @@ class t3lib_transl8tools  {
 
                                                                // Look for translations of this record, index by language field value:
                                                        $translationsTemp = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-                                                               'uid,'.$TCA[$trTable]['ctrl']['languageField'],
+                                                               ($selFieldList ? $selFieldList : 'uid,'.$TCA[$trTable]['ctrl']['languageField']),
                                                                $trTable,
-                                                               'pid='.intval($table==='pages' ? $row['uid'] : $row['pid']).    // Making exception for pages of course where the translations will always be ON the page, not on the level above...
+                                                               $TCA[$trTable]['ctrl']['transOrigPointerField'] . '=' . intval($uid) .
+                                                                       ' AND pid=' . intval($table === 'pages' ? $row['uid'] : $row['pid']).   // Making exception for pages of course where the translations will always be ON the page, not on the level above...
                                                                        ' AND '.$TCA[$trTable]['ctrl']['languageField'].(!$sys_language_uid ? '>0' : '='.intval($sys_language_uid)).
-                                                                       ' AND '.$TCA[$trTable]['ctrl']['transOrigPointerField'].'='.intval($uid).
                                                                        t3lib_BEfunc::deleteClause($trTable).
                                                                        t3lib_BEfunc::versioningPlaceholderClause($trTable)
                                                        );
@@ -168,6 +178,7 @@ class t3lib_transl8tools    {
                                                        return array(
                                                                'table' => $table,
                                                                'uid' => $uid,
+                                                               'CType' => $row['CType'],
                                                                'sys_language_uid' => $row[$TCA[$table]['ctrl']['languageField']],
                                                                'translation_table' => $trTable,
                                                                'translations' => $translations,