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