Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2006 Kasper Skaarhoj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00055 class t3lib_transl8tools { 00056 00060 function getSystemLanguages($page_id=0,$backPath='') { 00061 global $TCA,$LANG; 00062 00063 // Icons and language titles: 00064 t3lib_div::loadTCA('sys_language'); 00065 $flagAbsPath = t3lib_div::getFileAbsFileName($TCA['sys_language']['columns']['flag']['config']['fileFolder']); 00066 $flagIconPath = $backPath.'../'.substr($flagAbsPath, strlen(PATH_site)); 00067 00068 $modSharedTSconfig = t3lib_BEfunc::getModTSconfig($page_id, 'mod.SHARED'); 00069 $languageIconTitles = array(); 00070 00071 // Set default: 00072 $languageIconTitles[0] = array( 00073 'uid' => 0, 00074 'title' => strlen ($modSharedTSconfig['properties']['defaultLanguageLabel']) ? $modSharedTSconfig['properties']['defaultLanguageLabel'].' ('.$LANG->getLL('defaultLanguage').')' : $LANG->getLL('defaultLanguage'), 00075 'ISOcode' => 'DEF', 00076 'flagIcon' => strlen($modSharedTSconfig['properties']['defaultLanguageFlag']) && @is_file($flagAbsPath.$modSharedTSconfig['properties']['defaultLanguageFlag']) ? $flagIconPath.$modSharedTSconfig['properties']['defaultLanguageFlag'] : null, 00077 ); 00078 00079 // Set "All" language: 00080 $languageIconTitles[-1]=array( 00081 'uid' => -1, 00082 'title' => $LANG->getLL('multipleLanguages'), 00083 'ISOcode' => 'DEF', 00084 'flagIcon' => $flagIconPath.'multi-language.gif', 00085 ); 00086 00087 // Find all system languages: 00088 $sys_languages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( 00089 '*', 00090 'sys_language', 00091 '' 00092 ); 00093 foreach($sys_languages as $row) { 00094 $languageIconTitles[$row['uid']] = $row; 00095 00096 if ($row['static_lang_isocode'] && t3lib_extMgm::isLoaded('static_info_tables')) { 00097 $staticLangRow = t3lib_BEfunc::getRecord('static_languages',$row['static_lang_isocode'],'lg_iso_2'); 00098 if ($staticLangRow['lg_iso_2']) { 00099 $languageIconTitles[$row['uid']]['ISOcode'] = $staticLangRow['lg_iso_2']; 00100 } 00101 } 00102 if (strlen ($row['flag'])) { 00103 $languageIconTitles[$row['uid']]['flagIcon'] = @is_file($flagAbsPath.$row['flag']) ? $flagIconPath.$row['flag'] : ''; 00104 } 00105 } 00106 00107 return $languageIconTitles; 00108 } 00109 00113 function translationInfo($table,$uid,$sys_language_uid=0) { 00114 global $TCA; 00115 00116 if ($TCA[$table] && $uid) { 00117 t3lib_div::loadTCA($table); 00118 00119 $row = t3lib_BEfunc::getRecordWSOL($table,$uid); 00120 if (is_array($row)) { 00121 $trTable = $this->getTranslationTable($table); 00122 if ($trTable) { 00123 if ($trTable!==$table || $row[$TCA[$table]['ctrl']['languageField']] <= 0) { 00124 if ($trTable!==$table || $row[$TCA[$table]['ctrl']['transOrigPointerField']] == 0) { 00125 00126 // Look for translations of this record, index by language field value: 00127 $translationsTemp = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( 00128 'uid,'.$TCA[$trTable]['ctrl']['languageField'], 00129 $trTable, 00130 '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... 00131 ' AND '.$TCA[$trTable]['ctrl']['languageField'].(!$sys_language_uid ? '>0' : '='.intval($sys_language_uid)). 00132 ' AND '.$TCA[$trTable]['ctrl']['transOrigPointerField'].'='.intval($uid). 00133 t3lib_BEfunc::deleteClause($trTable). 00134 t3lib_BEfunc::versioningPlaceholderClause($trTable) 00135 ); 00136 00137 $translations = array(); 00138 $translations_errors = array(); 00139 foreach($translationsTemp as $r) { 00140 if (!isset($translations[$r[$TCA[$trTable]['ctrl']['languageField']]])) { 00141 $translations[$r[$TCA[$trTable]['ctrl']['languageField']]] = $r; 00142 } else { 00143 $translations_errors[$r[$TCA[$trTable]['ctrl']['languageField']]][] = $r; 00144 } 00145 } 00146 00147 return array( 00148 'table' => $table, 00149 'uid' => $uid, 00150 'sys_language_uid' => $row[$TCA[$table]['ctrl']['languageField']], 00151 'translation_table' => $trTable, 00152 'translations' => $translations, 00153 'excessive_translations' => $translations_errors 00154 ); 00155 } else return 'Record "'.$table.'_'.$uid.'" seems to be a translation already (has a relation to record "'.$row[$TCA[$table]['ctrl']['transOrigPointerField']].'")'; 00156 } else return 'Record "'.$table.'_'.$uid.'" seems to be a translation already (has a language value "'.$row[$TCA[$table]['ctrl']['languageField']].'", relation to record "'.$row[$TCA[$table]['ctrl']['transOrigPointerField']].'")'; 00157 } else return 'Translation is not supported for this table!'; 00158 } else return 'Record "'.$table.'_'.$uid.'" was not found'; 00159 } else return 'No table "'.$table.'" or no UID value'; 00160 } 00161 00165 function getTranslationTable($table) { 00166 return $this->isTranslationInOwnTable($table) ? $table : $this->foreignTranslationTable($table); 00167 } 00168 00172 function isTranslationInOwnTable($table) { 00173 global $TCA; 00174 00175 return $TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField'] && !$TCA[$table]['ctrl']['transOrigPointerTable']; 00176 } 00177 00181 function foreignTranslationTable($table) { 00182 global $TCA; 00183 00184 $trTable = $TCA[$table]['ctrl']['transForeignTable']; 00185 00186 if ($trTable && $TCA[$trTable] && $TCA[$trTable]['ctrl']['languageField'] && $TCA[$trTable]['ctrl']['transOrigPointerField'] && $TCA[$trTable]['ctrl']['transOrigPointerTable']===$table) { 00187 return $trTable; 00188 } 00189 } 00190 } 00191 00192 00193 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transl8tools.php']) { 00194 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transl8tools.php']); 00195 } 00196 ?>