Initial revision
[Packages/TYPO3.CMS.git] / misc / 3.6.0 / TCAupdate.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skårhøj (kasper@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 * Dev-script: Translation of TBE
29 *
30 * This script prints out all language-labels in Typo3 and provides a way of checking for missing translations.
31 *
32 * @author Kasper Skårhøj <kasper@typo3.com>
33 */
34
35 die("<strong>This script is for typo3 development, tables.php language maintenance only. You'll probably find it useless for what you do.</strong><br><br>MUST remove this line in TCAupdate script before it'll work for you. This is a security precaution. Anyways, you must be logged in as admin as well.");
36
37
38
39
40 define("TYPO3_MOD_PATH", "dev/");
41 $BACK_PATH="../";
42 require ($BACK_PATH."init.php");
43 if (!$BE_USER->isAdmin()) die("Must be admin.");
44
45
46
47 $exitOnExistingValues=1; // If set, the script does NOT allow existing labels to be overridden
48
49
50 function getValueOfCodeLine($str) {
51 $p = explode("=>",$str,2);
52 if (substr($p[1],0,6)=='$LANG_') {
53 return "";
54 } else {
55 ereg('^"(.*)",$',trim($p[1]),$reg);
56 return $reg[1];
57 }
58 }
59 function trim_remove_quote($val) {
60 $val = trim($val);
61 $val = ereg_replace('^"','',$val);
62 $val = ereg_replace('"$','',$val);
63 return $val;
64 }
65 function insertLabel($line,$newVal,$langIndex,$lineNumber=0,$values="") {
66 $values = $values ? $values : getValueOfCodeLine($line);
67 $vParts = explode("|",$values);
68 $vParts=array_pad ($vParts, count($GLOBALS["langArray"]), "");
69 if (trim($vParts[$langIndex])) {
70 echo ("<font color=blue>There was already content in this line for language index <strong>".$langIndex."</strong> (line# ".$lineNumber."):<BR></font>".$line);
71 if ($GLOBALS["exitOnExistingValues"]) {
72 echo '<BR><BR><font color=Red><strong>THE VALUE "'.$newVal.'" IS NOT UPDATED because $exitOnExistingValues is set</strong></font><BR><BR>';
73 return $line;
74 }
75 }
76
77 if (strstr($newVal,"|")) {
78 echo ("<font color=blue>There was a '|' character in the value. THis is not allowed!:<BR></font>".$line);
79 if ($GLOBALS["exitOnExistingValues"]) {
80 echo '<BR><BR><font color=Red><strong>THE VALUE "'.$newVal.'" IS NOT UPDATED because $exitOnExistingValues is set</strong></font><BR><BR>';
81 return $line;
82 }
83 }
84
85 if (strstr($newVal,"'") || strstr($newVal,'"')) {
86 echo ("<font color=blue>There was a \" or ' character in the value. Please check if you need to slash the character! (line# ".$lineNumber."):<BR></font>".$line);
87 }
88
89 $vParts[$langIndex]=$newVal;
90 $newValues = implode("|",$vParts);
91 $newLine = str_replace($values,$newValues,$line);
92 //debug($line);
93 debug(array($line,$newLine));
94
95 return $newLine;
96 }
97
98
99
100
101 // PROCESS INPUT:
102 if (t3lib_div::GPvar("TCAinput")) {
103 $lines = t3lib_div::trimExplode(chr(10),t3lib_div::GPvar("TCAinput"),0);
104 reset($lines);
105 $parsedLabels=array();
106 $langKey="";
107 while(list($n,$lineContent)=each($lines)) {
108 if (ereg("\*\*\*([[:alnum:]/_ -]*)\*\*\*",$lineContent,$reg)) {
109 $langKey = strtolower(trim($reg[1]));
110 debug("LANGKEY found: ".$langKey,1);
111 }
112 if ($langKey) {
113 if (ereg("___([[:alnum:]/_-]*)___",$lineContent,$reg)) {
114 $parts = explode("/",$reg[1]);
115 if (count($parts)==4 && $parts[3]=="items") {
116 for ($a=1;$a<20;$a++) { // 20 is safety...
117 if (trim($lines[$n+$a])) {
118 $labelP = explode(":",$lines[$n+$a],2);
119 $parsedLabels[$reg[1]."/".trim($labelP[0])]=trim_remove_quote($labelP[1]);
120 } else break;
121 }
122 } else {
123 $labelP = explode(":",$lines[$n+1],2);
124 if (trim(strtolower($labelP[0]))=="label") {
125 $parsedLabels[$reg[1]]=trim_remove_quote($labelP[1]);
126 }
127 }
128 }
129 }
130 }
131
132 $langArray = explode("|",TYPO3_languages);
133 debug($langArray);
134 $langSplitIndex = 0;
135 reset($langArray);
136 while(list($n,$lK)=each($langArray)) {
137 if (!strcmp($lK,$langKey) && $langKey) {
138 $langSplitIndex=$n;
139 break;
140 }
141 }
142 debug("LANG SPLIT INDEX: ".$langSplitIndex,1);
143 echo "<BR>";
144 debug("PARSED LABELS:",1);
145 debug($parsedLabels);
146
147
148 $tables_def_files=explode(",","tables,tbl_sys,tbl_tt,tbl_tt_content,tbl_users");
149
150 // PROCESS TABLES.PHP
151 if ($langSplitIndex) {
152 reset($tables_def_files);
153 while(list(,$cur_table_def_file)=each($tables_def_files)) {
154 $curTableCounter=0;
155 $tables_php = explode(chr(10),t3lib_div::getUrl(PATH_t3lib."stddb/".$cur_table_def_file.".php"));
156 reset($tables_php);
157 while(list($lineN,$line)=each($tables_php)) {
158 // Ended?
159 switch($mode) {
160 case "LANG_GENERAL_LABELS":
161 if (!strcmp(trim($line),');')) {
162 $mode="";
163 } else {
164 list(,$LGL_key) = explode('"',$line);
165 $key = "LANG_GENERAL_LABELS/".$LGL_key;
166 if (isset($parsedLabels[$key])) {
167 debug($LGL_key,1);
168 $tables_php[$lineN] = insertLabel($line,$parsedLabels[$key],$langSplitIndex,$lineN);
169 unset($parsedLabels[$key]);
170 $curTableCounter++;
171 }
172 }
173 break;
174 case "TABLE":
175 switch($part) {
176 case "ctrl":
177 if (substr(trim($line),0,7)=='"title"') {
178 $key = "tables_php/".$table."/ctrl/title";
179 if (isset($parsedLabels[$key])) {
180 $tables_php[$lineN] = insertLabel($line,$parsedLabels[$key],$langSplitIndex,$lineN);
181 unset($parsedLabels[$key]);
182 $curTableCounter++;
183 }
184 }
185 break;
186 case "columns":
187
188 //if (strstr($line,"JPG/Very High")) debug("HERE IT IS!");
189
190 if (substr($line,0,3)==' "') {
191 list($theField) = explode('"',substr($line,3));
192 $itemsMode=0;
193 } elseif ($theField) {
194 if (substr(trim($line),0,7)=='"items"') {
195 $itemsMode=1;
196 }
197 if ($itemsMode) {
198 if (substr(trim(strtolower($line)),0,5)=='array') {
199 $lParts = explode('"',$line);
200 if (!strstr($line,'$LANG_GENERAL_LABELS') && count($lParts)>=3) { // 3-5-7
201 $valKey = strcmp(ereg_replace("[^0-9]","",$lParts[2]),"")?ereg_replace("[^0-9]","",$lParts[2]):$lParts[3];
202 $key = "tables_php/".$table."/".$theField."/items/".$valKey;
203 if (isset($parsedLabels[$key])) {
204 $tables_php[$lineN] = insertLabel($line,$parsedLabels[$key],$langSplitIndex,$lineN,$lParts[1]);
205 unset($parsedLabels[$key]);
206 $curTableCounter++;
207 }// else debug(array("Not-found key: ".$key,$lParts));
208 }
209 }
210 } else {
211 if (substr(trim($line),0,7)=='"label"') {
212 $key = $table."/".$theField;
213 if (isset($parsedLabels[$key])) {
214 debug($theField,1);
215 $tables_php[$lineN] = insertLabel($line,$parsedLabels[$key],$langSplitIndex,$lineN);
216 unset($parsedLabels[$key]);
217 $curTableCounter++;
218 }
219 }
220 }
221 }
222 break;
223 }
224
225 break;
226 }
227
228 if (!strcmp(trim($line),'$LANG_GENERAL_LABELS = array(')) {
229 $mode = "LANG_GENERAL_LABELS";
230 }
231 if (!strcmp(substr(trim($line),0,6),'$TCA["')) {
232 $mode = "TABLE";
233 list($table) = explode('"',substr(trim($line),6));
234 $part = "";
235
236 echo "<HR>";
237 debug($table,1);
238 }
239
240 if ($mode=="TABLE") {
241 if (!strcmp(substr($line,0,2),' "')) {
242 $part="";
243 }
244 if (!strcmp(rtrim($line),' "ctrl" => Array (')) {
245 $part="ctrl";
246 debug(strtoupper($part),1);
247 }
248 if (!strcmp(rtrim($line),' "columns" => Array (')) {
249 $part="columns";
250 $theField="";
251 debug(strtoupper($part),1);
252 }
253 }
254 }
255
256 if ($curTableCounter) {
257 $fileName = PATH_t3lib."stddb/".$cur_table_def_file."_updated_".date("Ymdhis").".php";
258 echo "<HR>".$fileName.": ".$curTableCounter." labels to update<BR>";
259 if (t3lib_div::GPvar("submit_write")) {
260 echo "<font color=red>WRITING ".$curTableCounter." labels to '".$fileName."':</font><BR>";
261 t3lib_div::writeFile($fileName,implode(chr(10), $tables_php));
262 }
263 }
264 }
265 }
266
267
268 echo "<BR>";
269 debug("REMAINING LABELS:",1);
270 debug($parsedLabels);
271 }
272
273
274
275
276
277
278
279
280
281 ?>
282 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
283
284 <html>
285 <head>
286 <style>
287 TD{font-family: Verdana,Arial,Helvetica,Sans-serif; font-size: 10px;}
288 INPUT{font-family: Verdana,Arial,Helvetica,Sans-serif; font-size: 10px; width:300px;}
289 BODY{font-family: Verdana,Arial,Helvetica,Sans-serif; font-size: 10px;}
290
291 </style>
292 <title>TYPO3 TCA Update</title>
293 </head>
294 <body>
295
296 <form action="TCAupdate.php" method="POST">
297 <h1>TCA Update</h1>
298 This document is able to process the tables.php file and merge it with output for tables.php-fields made with "translations.php".
299 <br>
300 <br>
301 <textarea cols="80" rows="30" name="TCAinput" wrap=OFF><?php echo t3lib_div::formatForTextarea(t3lib_div::GPvar("TCAinput"));?></textarea><BR>
302 <input type="submit" name="submit" value="Analyse and Merge"><BR><input type="submit" name="submit_write" value="WRITE to <?php echo "*_updated_".date("Ymdhis").".php"; ?>">
303 </form>
304 </body>
305 </html>
306 <?php
307
308
309
310
311
312
313
314
315
316
317 // IF a translator delivers a tables.php which is already correctly translated, insert this in the end of that tables.php file and it will generate the keys which can be parsed and merged by this script!
318 /*
319
320
321
322
323 $keyNumber=13; // language number among lang-keys (1 being default)
324 define("TYPO3_languages", "default|dk|de|no|it|fr|es|nl|cz|pl|si|fi|tr"); // 13 languages, WOW!!
325
326 function splitLine($code) {
327 $splitParts = explode("|",$code);
328 return trim($splitParts[$GLOBALS["keyNumber"]-1]);
329 }
330
331 echo "<PRE>";
332 echo "*** ".strtoupper(splitLine(TYPO3_languages))." ***
333
334 ";
335
336
337
338 reset($TCA);
339 while(list($table,$conf)=each($TCA)) {
340 if (splitLine($conf["ctrl"]["title"])) {
341 echo "___tables_php/".$table."/ctrl/title___\n";
342 echo "Label : ".splitLine($conf["ctrl"]["title"])."\n\n\n";
343 }
344
345 reset($conf["columns"]);
346 while(list($field,$config)=each($conf["columns"])) {
347 if (splitLine($config["label"])) {
348 echo "___".$table."/".$field."___\n";
349 echo "Label : ".splitLine($config["label"])."\n\n\n";
350 }
351 if (is_array($config["config"]["items"])) {
352 reset($config["config"]["items"]);
353 echo "___tables_php/".$table."/".$field."/items___\n";
354 while(list(,$vv)=each($config["config"]["items"])) {
355 if (splitLine($vv[0])) {
356 echo $vv[1]." : ".splitLine($vv[0])."\n";
357 }
358 }
359 echo "\n\n";
360 }
361 }
362 }
363
364 reset($LANG_GENERAL_LABELS);
365 while(list($k,$v)=each($LANG_GENERAL_LABELS)) {
366 if (splitLine($v)) {
367 echo "___LANG_GENERAL_LABELS/".$k."___\n";
368 echo "Label : ".splitLine($v)."\n\n\n";
369 }
370 }
371
372 echo "</PRE>";
373
374 */
375
376
377
378 ?>