Fixed bug #12508: Log usage of XLLfile to deprecation log (thanks to Steffen Gebert)
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_transl8tools.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2006-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Contains translation tools
29 *
30 * $Id$
31 *
32 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 *
38 *
39 * 67: class t3lib_transl8tools
40 * 74: function getSystemLanguages($page_id=0,$backPath='')
41 * 132: function translationInfo($table,$uid,$sys_language_uid=0)
42 * 187: function getTranslationTable($table)
43 * 197: function isTranslationInOwnTable($table)
44 * 209: function foreignTranslationTable($table)
45 *
46 * TOTAL FUNCTIONS: 5
47 * (This index is automatically created/updated by the extension "extdeveval")
48 *
49 */
50
51
52
53
54
55
56
57
58
59
60 /**
61 * Contains translation tools
62 *
63 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
64 * @package TYPO3
65 * @subpackage t3lib
66 */
67 class t3lib_transl8tools {
68
69 /**
70 * Returns array of system languages
71 * @param integer page id (only used to get TSconfig configuration setting flag and label for default language)
72 * @param string Backpath for flags
73 * @return array
74 */
75 function getSystemLanguages($page_id=0,$backPath='') {
76 global $TCA,$LANG;
77
78 // Icons and language titles:
79 t3lib_div::loadTCA('sys_language');
80 $flagAbsPath = t3lib_div::getFileAbsFileName($TCA['sys_language']['columns']['flag']['config']['fileFolder']);
81 $flagIconPath = $backPath.'../'.substr($flagAbsPath, strlen(PATH_site));
82
83 $modSharedTSconfig = t3lib_BEfunc::getModTSconfig($page_id, 'mod.SHARED');
84 $languageIconTitles = array();
85
86 // Set default:
87 $languageIconTitles[0] = array(
88 'uid' => 0,
89 'title' => strlen ($modSharedTSconfig['properties']['defaultLanguageLabel']) ? $modSharedTSconfig['properties']['defaultLanguageLabel'].' ('.$LANG->getLL('defaultLanguage').')' : $LANG->getLL('defaultLanguage'),
90 'ISOcode' => 'DEF',
91 'flagIcon' => strlen($modSharedTSconfig['properties']['defaultLanguageFlag']) && @is_file($flagAbsPath.$modSharedTSconfig['properties']['defaultLanguageFlag']) ? $flagIconPath.$modSharedTSconfig['properties']['defaultLanguageFlag'] : null,
92 );
93
94 // Set "All" language:
95 $languageIconTitles[-1]=array(
96 'uid' => -1,
97 'title' => $LANG->getLL('multipleLanguages'),
98 'ISOcode' => 'DEF',
99 'flagIcon' => $flagIconPath.'multi-language.gif',
100 );
101
102 // Find all system languages:
103 $sys_languages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
104 '*',
105 'sys_language',
106 ''
107 );
108 foreach($sys_languages as $row) {
109 $languageIconTitles[$row['uid']] = $row;
110
111 if ($row['static_lang_isocode'] && t3lib_extMgm::isLoaded('static_info_tables')) {
112 $staticLangRow = t3lib_BEfunc::getRecord('static_languages',$row['static_lang_isocode'],'lg_iso_2');
113 if ($staticLangRow['lg_iso_2']) {
114 $languageIconTitles[$row['uid']]['ISOcode'] = $staticLangRow['lg_iso_2'];
115 }
116 }
117 if (strlen ($row['flag'])) {
118 $languageIconTitles[$row['uid']]['flagIcon'] = @is_file($flagAbsPath.$row['flag']) ? $flagIconPath.$row['flag'] : '';
119 }
120 }
121
122 return $languageIconTitles;
123 }
124
125 /**
126 * Information about translation for an element
127 * Will overlay workspace version of record too!
128 *
129 * @param string Table name
130 * @param integer Record uid
131 * @param integer Language uid. If zero, then all languages are selected.
132 * @param array The record to be translated
133 * @param array select fields for the query which fetches the translations of the current record
134 * @return array Array with information. Errors will return string with message.
135 */
136 function translationInfo($table, $uid, $sys_language_uid = 0, $row = NULL, $selFieldList = '') {
137 global $TCA;
138
139 if ($TCA[$table] && $uid) {
140 t3lib_div::loadTCA($table);
141
142 if ($row === NULL) {
143 $row = t3lib_BEfunc::getRecordWSOL($table, $uid);
144 }
145
146 if (is_array($row)) {
147 $trTable = $this->getTranslationTable($table);
148 if ($trTable) {
149 if ($trTable!==$table || $row[$TCA[$table]['ctrl']['languageField']] <= 0) {
150 if ($trTable!==$table || $row[$TCA[$table]['ctrl']['transOrigPointerField']] == 0) {
151
152 // Look for translations of this record, index by language field value:
153 $translationsTemp = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
154 ($selFieldList ? $selFieldList : 'uid,'.$TCA[$trTable]['ctrl']['languageField']),
155 $trTable,
156 $TCA[$trTable]['ctrl']['transOrigPointerField'] . '=' . intval($uid) .
157 ' 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...
158 ' AND '.$TCA[$trTable]['ctrl']['languageField'].(!$sys_language_uid ? '>0' : '='.intval($sys_language_uid)).
159 t3lib_BEfunc::deleteClause($trTable).
160 t3lib_BEfunc::versioningPlaceholderClause($trTable)
161 );
162
163 $translations = array();
164 $translations_errors = array();
165 foreach($translationsTemp as $r) {
166 if (!isset($translations[$r[$TCA[$trTable]['ctrl']['languageField']]])) {
167 $translations[$r[$TCA[$trTable]['ctrl']['languageField']]] = $r;
168 } else {
169 $translations_errors[$r[$TCA[$trTable]['ctrl']['languageField']]][] = $r;
170 }
171 }
172
173 return array(
174 'table' => $table,
175 'uid' => $uid,
176 'CType' => $row['CType'],
177 'sys_language_uid' => $row[$TCA[$table]['ctrl']['languageField']],
178 'translation_table' => $trTable,
179 'translations' => $translations,
180 'excessive_translations' => $translations_errors
181 );
182 } else return 'Record "'.$table.'_'.$uid.'" seems to be a translation already (has a relation to record "'.$row[$TCA[$table]['ctrl']['transOrigPointerField']].'")';
183 } 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']].'")';
184 } else return 'Translation is not supported for this table!';
185 } else return 'Record "'.$table.'_'.$uid.'" was not found';
186 } else return 'No table "'.$table.'" or no UID value';
187 }
188
189 /**
190 * Returns the table in which translations for input table is found.
191 *
192 * @param [type] $table: ...
193 * @return [type] ...
194 */
195 function getTranslationTable($table) {
196 return $this->isTranslationInOwnTable($table) ? $table : $this->foreignTranslationTable($table);
197 }
198
199 /**
200 * Returns true, if the input table has localization enabled and done so with records from the same table
201 *
202 * @param [type] $table: ...
203 * @return [type] ...
204 */
205 function isTranslationInOwnTable($table) {
206 global $TCA;
207
208 return $TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField'] && !$TCA[$table]['ctrl']['transOrigPointerTable'];
209 }
210
211 /**
212 * Returns foreign translation table, if any
213 *
214 * @param [type] $table: ...
215 * @return [type] ...
216 */
217 function foreignTranslationTable($table) {
218 global $TCA;
219
220 $trTable = $TCA[$table]['ctrl']['transForeignTable'];
221
222 if ($trTable && $TCA[$trTable] && $TCA[$trTable]['ctrl']['languageField'] && $TCA[$trTable]['ctrl']['transOrigPointerField'] && $TCA[$trTable]['ctrl']['transOrigPointerTable']===$table) {
223 return $trTable;
224 }
225 }
226 }
227
228
229 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transl8tools.php']) {
230 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transl8tools.php']);
231 }
232 ?>