* Always use fputs() for writing to logfiles. There is no case when it can't be...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / web_info / class.tx_cms_webinfo_lang.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 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 a class with functions for page related overview of translations.
29 *
30 * $Id$
31 *
32 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 *
38 *
39 * 65: class tx_cms_webinfo_lang extends t3lib_extobjbase
40 * 72: function modMenu()
41 * 89: function main()
42 * 156: function renderL10nTable(&$tree)
43 * 320: function getSystemLanguages()
44 * 342: function getLangStatus($pageId, $langId)
45 * 369: function getContentElementCount($pageId,$sysLang)
46 *
47 * TOTAL FUNCTIONS: 6
48 * (This index is automatically created/updated by the extension "extdeveval")
49 *
50 */
51
52 require_once(PATH_t3lib.'class.t3lib_pagetree.php');
53 require_once(PATH_t3lib.'class.t3lib_extobjbase.php');
54
55
56
57
58 /**
59 * Class for displaying translation status of pages in the tree.
60 *
61 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
62 * @package TYPO3
63 * @subpackage tx_cms
64 */
65 class tx_cms_webinfo_lang extends t3lib_extobjbase {
66
67 /**
68 * Returns the menu array
69 *
70 * @return array
71 */
72 function modMenu() {
73 global $LANG;
74
75 $menuArray = array (
76 'depth' => array(
77 1 => $LANG->getLL('depth_1'),
78 2 => $LANG->getLL('depth_2'),
79 3 => $LANG->getLL('depth_3')
80 ),
81 'details' => ''
82 );
83
84 // Languages:
85 $lang = $this->getSystemLanguages();
86 $menuArray['lang']=array(
87 0 => '[All]'
88 );
89 foreach($lang as $langRec) {
90 $menuArray['lang'][$langRec['uid']] = $langRec['title'];
91 }
92
93 return $menuArray;
94 }
95
96 /**
97 * MAIN function for page information of localization
98 *
99 * @return string Output HTML for the module.
100 */
101 function main() {
102 global $BACK_PATH,$LANG,$SOBE;
103
104 if ($this->pObj->id) {
105 $theOutput = '';
106
107 // Depth selector:
108 $h_func = t3lib_BEfunc::getFuncMenu($this->pObj->id,'SET[depth]',$this->pObj->MOD_SETTINGS['depth'],$this->pObj->MOD_MENU['depth'],'index.php');
109 $h_func.= t3lib_BEfunc::getFuncMenu($this->pObj->id,'SET[lang]',$this->pObj->MOD_SETTINGS['lang'],$this->pObj->MOD_MENU['lang'],'index.php');
110 $h_func.= t3lib_BEfunc::getFuncCheck($this->pObj->id,'SET[details]',$this->pObj->MOD_SETTINGS['details'],'index.php').' Details';
111 $theOutput.= $h_func;
112
113 // Add CSH:
114 $theOutput.= t3lib_BEfunc::cshItem('_MOD_web_info','lang',$GLOBALS['BACK_PATH'],'|<br/>');
115
116 // Showing the tree:
117 // Initialize starting point of page tree:
118 $treeStartingPoint = intval($this->pObj->id);
119 $treeStartingRecord = t3lib_BEfunc::getRecordWSOL('pages', $treeStartingPoint);
120 $depth = $this->pObj->MOD_SETTINGS['depth'];
121
122 // Initialize tree object:
123 $tree = t3lib_div::makeInstance('t3lib_pageTree');
124 $tree->init('AND '.$GLOBALS['BE_USER']->getPagePermsClause(1));
125 $tree->addField('l18n_cfg');
126
127 // Creating top icon; the current page
128 $HTML = t3lib_iconWorks::getIconImage('pages', $treeStartingRecord, $GLOBALS['BACK_PATH'],'align="top"');
129 $tree->tree[] = array(
130 'row' => $treeStartingRecord,
131 'HTML'=>$HTML
132 );
133
134 // Create the tree from starting point:
135 $tree->getTree($treeStartingPoint, $depth, '');
136 #debug($tree->tree);
137
138 // Add CSS needed:
139 $css_content = '
140 TABLE#langTable {
141 margin-top: 10px;
142 }
143 TABLE#langTable TR TD {
144 padding-left : 2px;
145 padding-right : 2px;
146 white-space: nowrap;
147 }
148 TD.c-blocked { background-color: red; }
149 TD.c-ok { background-color: #669966; }
150 TD.c-fallback { }
151 TD.c-leftLine {border-left: 2px solid black; }
152 .bgColor5 { font-weight: bold; }
153 ';
154 $marker = '/*###POSTCSSMARKER###*/';
155 $this->pObj->content = str_replace($marker,$css_content.chr(10).$marker,$this->pObj->content);
156
157 // Render information table:
158 $theOutput.= $this->renderL10nTable($tree);
159 }
160
161 return $theOutput;
162 }
163
164 /**
165 * Rendering the localization information table.
166 *
167 * @param array The Page tree data
168 * @return string HTML for the localization information table.
169 */
170 function renderL10nTable(&$tree) {
171 global $LANG;
172
173 // System languages retrieved:
174 $languages = $this->getSystemLanguages();
175
176 // Title length:
177 $titleLen = $GLOBALS['BE_USER']->uc['titleLen'];
178
179 // Put together the TREE:
180 $output = '';
181 $newOL_js = array();
182 $langRecUids = array();
183 foreach($tree->tree as $data) {
184 $tCells = array();
185 $langRecUids[0][] = $data['row']['uid'];
186
187 // Page icons / titles etc.
188 $tCells[] = '<td'.($data['row']['_CSSCLASS'] ? ' class="'.$data['row']['_CSSCLASS'].'"' : '').'>'.
189 $data['HTML'].
190 htmlspecialchars(t3lib_div::fixed_lgd_cs($data['row']['title'],$titleLen)).
191 (strcmp($data['row']['nav_title'],'') ? ' [Nav: <em>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($data['row']['nav_title'],$titleLen)).'</em>]' : '').
192 '</td>';
193
194 // DEFAULT language:
195 // "View page" link is created:
196 $viewPageLink= '<a href="#" onclick="'.
197 htmlspecialchars(t3lib_BEfunc::viewOnClick($data['row']['uid'],$GLOBALS['BACK_PATH'],'','','','&L=###LANG_UID###')).'">'.
198 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/zoom.gif','width="12" height="12"').' title="'.$LANG->getLL('lang_renderl10n_viewPage','1').'" border="0" alt="" />'.
199 '</a>';
200 $status = $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-ok';
201
202 // Create links:
203 $info = '';
204 $editUid = $data['row']['uid'];
205 $params = '&edit[pages]['.$editUid.']=edit';
206 $info.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">'.
207 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editDefaultLanguagePage','1').'" border="0" alt="" />'.
208 '</a>';
209 $info.= '<a href="#" onclick="'.htmlspecialchars('top.loadEditId('.intval($data['row']['uid']).',"&SET[language]=0"); return false;').'">'.
210 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit_page.gif','width="12" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editPage','1').'" border="0" alt="" />'.
211 '</a>';
212 $info.= str_replace('###LANG_UID###','0',$viewPageLink);
213
214 $info.= '&nbsp;';
215 $info.= $data['row']['l18n_cfg']&1 ? '<span title="'.$LANG->sL('LLL:EXT:cms/locallang_tca.php:pages.l18n_cfg.I.1','1').'">D</span>' : '&nbsp;';
216 $info.= t3lib_div::hideIfNotTranslated($data['row']['l18n_cfg']) ? '<span title="'.$LANG->sL('LLL:EXT:cms/locallang_tca.php:pages.l18n_cfg.I.2','1').'">N</span>' : '&nbsp;';
217
218 // Put into cell:
219 $tCells[] = '<td class="'.$status.' c-leftLine">'.$info.'</td>';
220 $tCells[] = '<td class="'.$status.'" title="'.$LANG->getLL('lang_renderl10n_CEcount','1').'" align="center">'.$this->getContentElementCount($data['row']['uid'],0).'</td>';
221
222 // Traverse system languages:
223 foreach($languages as $langRow) {
224 if ($this->pObj->MOD_SETTINGS['lang']==0 || (int)$this->pObj->MOD_SETTINGS['lang']===(int)$langRow['uid']) {
225 $row = $this->getLangStatus($data['row']['uid'], $langRow['uid']);
226 $info = '';
227
228 if (is_array($row)) {
229 $langRecUids[$langRow['uid']][] = $row['uid'];
230 $status = $row['_HIDDEN'] ? (t3lib_div::hideIfNotTranslated($data['row']['l18n_cfg']) || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback') : 'c-ok';
231 $icon = t3lib_iconWorks::getIconImage(
232 'pages_language_overlay',
233 $row,
234 $GLOBALS['BACK_PATH'],
235 'align="top" class="c-recIcon"'
236 );
237
238 $info = $icon.
239 htmlspecialchars(t3lib_div::fixed_lgd_cs($row['title'],$titleLen)).
240 (strcmp($row['nav_title'],'') ? ' [Nav: <em>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['nav_title'],$titleLen)).'</em>]' : '').
241 ($row['_COUNT']>1 ? '<div>'.$LANG->getLL('lang_renderl10n_badThingThereAre','1').'</div>':'');
242 $tCells[] = '<td class="'.$status.' c-leftLine">'.
243 $info.
244 ($this->pObj->MOD_SETTINGS['details'] ? $this->getLocalizedElementInfo($data['row']['uid'],$langRow['uid']) : '').
245 '</td>';
246
247 // Edit whole record:
248 $info = '';
249 $editUid = $row['uid'];
250 $params = '&edit[pages_language_overlay]['.$editUid.']=edit';
251 $info.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">'.
252 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editLanguageOverlayRecord','1').'" border="0" alt="" />'.
253 '</a>';
254
255 $info.= '<a href="#" onclick="'.htmlspecialchars('top.loadEditId('.intval($data['row']['uid']).',"&SET[language]='.$langRow['uid'].'"); return false;').'">'.
256 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit_page.gif','width="12" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editPageLang','1').'" border="0" alt="" />'.
257 '</a>';
258 $info.= str_replace('###LANG_UID###',$langRow['uid'],$viewPageLink);
259
260 $tCells[] = '<td class="'.$status.'">'.$info.'</td>';
261 $tCells[] = '<td class="'.$status.'" title="'.$LANG->getLL('lang_renderl10n_CEcount','1').'" align="center">'.$this->getContentElementCount($data['row']['uid'],$langRow['uid']).'</td>';
262 } else {
263 $status = t3lib_div::hideIfNotTranslated($data['row']['l18n_cfg']) || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback';
264 $tCells[] = '<td class="'.$status.' c-leftLine">&nbsp;</td>';
265 $tCells[] = '<td class="'.$status.'">&nbsp;</td>';
266
267 $info = '';
268 $info.= '<input type="checkbox" name="newOL['.$langRow['uid'].']['.$data['row']['uid'].']" value="1" />';
269 $newOL_js[$langRow['uid']].= '
270 +(document.webinfoForm[\'newOL['.$langRow['uid'].']['.$data['row']['uid'].']\'].checked ? \'&edit[pages_language_overlay]['.$data['row']['uid'].']=new\' : \'\')
271 ';
272 $tCells[] = '<td class="'.$status.'">'.$info.'</td>';
273 }
274 }
275 }
276
277 $output.= '
278 <tr class="bgColor4">
279 '.implode('
280 ',$tCells).'
281 </tr>';
282 }
283
284 // Put together HEADER:
285 $tCells = array();
286 $tCells[] = '<td>'.$LANG->getLL('lang_renderl10n_page','1').':</td>';
287
288 if (is_array($langRecUids[0])) {
289 $params = '&edit[pages]['.implode(',',$langRecUids[0]).']=edit&columnsOnly=title,nav_title,l18n_cfg,hidden';
290 $editIco = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
291 <img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editPageProperties','1').'" border="0" alt="" />
292 </a>';
293 } else $editIco = '';
294 $tCells[] = '<td class="c-leftLine" colspan="2">'.
295 $LANG->getLL('lang_renderl10n_default','1').':'.
296 $editIco.
297 '</td>';
298
299 foreach($languages as $langRow) {
300 if ($this->pObj->MOD_SETTINGS['lang']==0 || (int)$this->pObj->MOD_SETTINGS['lang']===(int)$langRow['uid']) {
301 // Title:
302 $tCells[] = '<td class="c-leftLine">'.htmlspecialchars($langRow['title']).'</td>';
303
304 // Edit language overlay records:
305 if (is_array($langRecUids[$langRow['uid']])) {
306 $params = '&edit[pages_language_overlay]['.implode(',',$langRecUids[$langRow['uid']]).']=edit&columnsOnly=title,nav_title,hidden';
307 $tCells[] = '<td><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
308 <img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editLangOverlays','1').'" border="0" alt="" />
309 </a></td>';
310 } else {
311 $tCells[] = '<td>&nbsp;</td>';
312 }
313
314 // Create new overlay records:
315 $params = "'".$newOL_js[$langRow['uid']]."+'&columnsOnly=title,hidden,sys_language_uid&defVals[pages_language_overlay][sys_language_uid]=".$langRow['uid'];
316 $tCells[] = '<td><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
317 <img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/new_el.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_getlangsta_createNewTranslationHeaders','1').'" border="0" alt="" />
318 </a></td>';
319 }
320 }
321
322 $output = '
323 <tr class="bgColor5">
324 '.implode('
325 ',$tCells).'
326 </tr>'.$output;
327
328 $output = '
329
330 <table border="0" cellspacing="0" cellpadding="0" id="langTable">'.$output.'
331 </table>';
332
333 return $output;
334 }
335
336 /**
337 * Selects all system languages (from sys_language)
338 *
339 * @return array System language records in an array.
340 */
341 function getSystemLanguages() {
342 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
343 '*',
344 'sys_language',
345 '1'.t3lib_BEfunc::deleteClause('sys_language')
346 );
347
348 $outputArray = array();
349 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
350 $outputArray[] = $row;
351 }
352
353 return $outputArray;
354 }
355
356 /**
357 * Get an alternative language record for a specific page / language
358 *
359 * @param integer Page ID to look up for.
360 * @param integer Language UID to select for.
361 * @return array pages_languages_overlay record
362 */
363 function getLangStatus($pageId, $langId) {
364 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
365 '*',
366 'pages_language_overlay',
367 'pid='.intval($pageId).
368 ' AND sys_language_uid='.intval($langId).
369 t3lib_BEfunc::deleteClause('pages_language_overlay').
370 t3lib_BEfunc::versioningPlaceholderClause('pages_language_overlay')
371 );
372
373 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
374 if (is_array($row)) {
375 t3lib_BEfunc::workspaceOL('pages_language_overlay',$row);
376 $row['_COUNT'] = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
377 $row['_HIDDEN'] = $row['hidden'] ||
378 (intval($row['endtime']) > 0 && intval($row['endtime']) < time()) ||
379 (time() < intval($row['starttime']));
380 }
381
382 return $row;
383 }
384
385 /**
386 * Counting content elements for a single language on a page.
387 *
388 * @param integer Page id to select for.
389 * @param integer Sys language uid
390 * @return integer Number of content elements from the PID where the language is set to a certain value.
391 */
392 function getLocalizedElementInfo($pageId,$sysLang) {
393 global $TCA;
394
395 $info = '<hr/>';
396 foreach($TCA as $table => $cfg) {
397 if ($table!='pages' && $TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField']) {
398 # $info.='<h3>'.$table.'</h3>';
399 if ($TCA[$table]['ctrl']['transOrigPointerTable']) {
400 #$info.='Table "'.$table.'" is skipped because it had a transOrigPointerTable set which is not supported - yet.';
401 } else {
402
403 // First, select all records that are default language OR international:
404 $allRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
405 '*',
406 $table,
407 'pid='.intval($pageId).
408 ' AND '.$TCA[$table]['ctrl']['languageField'].'<=0'.
409 t3lib_BEfunc::deleteClause($table).
410 t3lib_BEfunc::versioningPlaceholderClause($table)
411 );
412 if (count($allRows)) {
413 $info.='<h3>'.$table.'</h3>';
414
415 $info.='[<b>'.$TCA[$table]['ctrl']['languageField'].'</b>]';
416 $info.='[<b>'.$TCA[$table]['ctrl']['transOrigPointerField'].'</b>]';
417 $info.='[<b>'.$TCA[$table]['ctrl']['transOrigDiffSourceField'].'</b>]';
418
419 // Now, for each record, look for localization:
420 $translationsUids = array(0);
421 foreach($allRows as $row) {
422 $info.='UID:'.$row['uid'].'/lang:'.$row[$TCA[$table]['ctrl']['languageField']].' has translations:';
423 $translations = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
424 '*',
425 $table,
426 'pid='.intval($pageId).
427 ' AND '.$TCA[$table]['ctrl']['languageField'].'='.intval($sysLang).
428 ' AND '.$TCA[$table]['ctrl']['transOrigPointerField'].'='.intval($row['uid']).
429 t3lib_BEfunc::deleteClause($table).
430 t3lib_BEfunc::versioningPlaceholderClause($table)
431 );
432
433 foreach($translations as $c => $tr) {
434 $info.=($c>0 ? 'UPS!!':'').'['.$tr['uid'].'],';
435 $translationsUids[] = $tr['uid'];
436 }
437
438
439
440 $info.='<br/>';
441 }
442
443 // Look for "lost" translations
444 $lostTranslations = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
445 'uid',
446 $table,
447 'pid='.intval($pageId).
448 ' AND '.$TCA[$table]['ctrl']['languageField'].'='.intval($sysLang).
449 ' AND uid NOT IN ('.implode(',',$translationsUids).')'.
450 t3lib_BEfunc::deleteClause($table).
451 t3lib_BEfunc::versioningPlaceholderClause($table)
452 );
453 if (count($lostTranslations)) {
454 $info.=t3lib_div::view_array($lostTranslations);
455 }
456 }
457 }
458 }
459 }
460 return $info;
461 }
462
463 /**
464 * Counting content elements for a single language on a page.
465 *
466 * @param integer Page id to select for.
467 * @param integer Sys language uid
468 * @return integer Number of content elements from the PID where the language is set to a certain value.
469 */
470 function getContentElementCount($pageId,$sysLang) {
471 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
472 'count(*)',
473 'tt_content',
474 'pid='.intval($pageId).
475 ' AND sys_language_uid='.intval($sysLang).
476 t3lib_BEfunc::deleteClause('tt_content').
477 t3lib_BEfunc::versioningPlaceholderClause('tt_content')
478 );
479
480 list($count) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
481 return $count ? $count : '-';
482 }
483 }
484
485
486 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php']) {
487 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php']);
488 }
489 ?>