Fixed bug #9301: Missing colorization in Localization Overview of the page tree
[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-2008 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 0 => $LANG->getLL('depth_0'),
79 1 => $LANG->getLL('depth_1'),
80 2 => $LANG->getLL('depth_2'),
81 3 => $LANG->getLL('depth_3')
82 ),
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 $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 if ($depth) $tree->getTree($treeStartingPoint, $depth, '');
136 #debug($tree->tree);
137
138 // Add CSS needed:
139 $this->pObj->doc->inDocStylesArray[] = '
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: #f72116; }
149 td.c-ok { background-color: #86b571; }
150 td.c-fallback { }
151 td.c-leftLine {border-left: 2px solid black; }
152 .bgColor5 { font-weight: bold; }
153 ';
154
155 // Render information table:
156 $theOutput.= $this->renderL10nTable($tree);
157 }
158
159 return $theOutput;
160 }
161
162 /**
163 * Rendering the localization information table.
164 *
165 * @param array The Page tree data
166 * @return string HTML for the localization information table.
167 */
168 function renderL10nTable(&$tree) {
169 global $LANG;
170
171 // System languages retrieved:
172 $languages = $this->getSystemLanguages();
173
174 // Title length:
175 $titleLen = $GLOBALS['BE_USER']->uc['titleLen'];
176
177 // Put together the TREE:
178 $output = '';
179 $newOL_js = array();
180 $langRecUids = array();
181 foreach($tree->tree as $data) {
182 $tCells = array();
183 $langRecUids[0][] = $data['row']['uid'];
184
185 // Page icons / titles etc.
186 $tCells[] = '<td'.($data['row']['_CSSCLASS'] ? ' class="'.$data['row']['_CSSCLASS'].'"' : '').'>'.
187 $data['HTML'].
188 htmlspecialchars(t3lib_div::fixed_lgd_cs($data['row']['title'],$titleLen)).
189 (strcmp($data['row']['nav_title'],'') ? ' [Nav: <em>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($data['row']['nav_title'],$titleLen)).'</em>]' : '').
190 '</td>';
191
192 // DEFAULT language:
193 // "View page" link is created:
194 $viewPageLink= '<a href="#" onclick="'.
195 htmlspecialchars(t3lib_BEfunc::viewOnClick($data['row']['uid'],$GLOBALS['BACK_PATH'],'','','','&L=###LANG_UID###')).'">'.
196 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/zoom.gif','width="12" height="12"').' title="'.$LANG->getLL('lang_renderl10n_viewPage','1').'" border="0" alt="" />'.
197 '</a>';
198 $status = $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-ok';
199
200 // Create links:
201 $info = '';
202 $editUid = $data['row']['uid'];
203 $params = '&edit[pages]['.$editUid.']=edit';
204 $info.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">'.
205 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editDefaultLanguagePage','1').'" border="0" alt="" />'.
206 '</a>';
207 $info.= '<a href="#" onclick="'.htmlspecialchars('top.loadEditId('.intval($data['row']['uid']).',"&SET[language]=0"); return false;').'">'.
208 '<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="" />'.
209 '</a>';
210 $info.= str_replace('###LANG_UID###','0',$viewPageLink);
211
212 $info.= '&nbsp;';
213 $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;';
214 $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;';
215
216 // Put into cell:
217 $tCells[] = '<td class="'.$status.' c-leftLine">'.$info.'</td>';
218 $tCells[] = '<td class="'.$status.'" title="'.$LANG->getLL('lang_renderl10n_CEcount','1').'" align="center">'.$this->getContentElementCount($data['row']['uid'],0).'</td>';
219
220 // Traverse system languages:
221 foreach($languages as $langRow) {
222 if ($this->pObj->MOD_SETTINGS['lang']==0 || (int)$this->pObj->MOD_SETTINGS['lang']===(int)$langRow['uid']) {
223 $row = $this->getLangStatus($data['row']['uid'], $langRow['uid']);
224 $info = '';
225
226 if (is_array($row)) {
227 $langRecUids[$langRow['uid']][] = $row['uid'];
228 $status = $row['_HIDDEN'] ? (t3lib_div::hideIfNotTranslated($data['row']['l18n_cfg']) || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback') : 'c-ok';
229 $icon = t3lib_iconWorks::getIconImage(
230 'pages_language_overlay',
231 $row,
232 $GLOBALS['BACK_PATH'],
233 'align="top" class="c-recIcon"'
234 );
235
236 $info = $icon.
237 htmlspecialchars(t3lib_div::fixed_lgd_cs($row['title'],$titleLen)).
238 (strcmp($row['nav_title'],'') ? ' [Nav: <em>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['nav_title'],$titleLen)).'</em>]' : '').
239 ($row['_COUNT']>1 ? '<div>'.$LANG->getLL('lang_renderl10n_badThingThereAre','1').'</div>':'');
240 $tCells[] = '<td class="'.$status.' c-leftLine">'.
241 $info.
242 '</td>';
243
244 // Edit whole record:
245 $info = '';
246 $editUid = $row['uid'];
247 $params = '&edit[pages_language_overlay]['.$editUid.']=edit';
248 $info.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">'.
249 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editLanguageOverlayRecord','1').'" border="0" alt="" />'.
250 '</a>';
251
252 $info.= '<a href="#" onclick="'.htmlspecialchars('top.loadEditId('.intval($data['row']['uid']).',"&SET[language]='.$langRow['uid'].'"); return false;').'">'.
253 '<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="" />'.
254 '</a>';
255 $info.= str_replace('###LANG_UID###',$langRow['uid'],$viewPageLink);
256
257 $tCells[] = '<td class="'.$status.'">'.$info.'</td>';
258 $tCells[] = '<td class="'.$status.'" title="'.$LANG->getLL('lang_renderl10n_CEcount','1').'" align="center">'.$this->getContentElementCount($data['row']['uid'],$langRow['uid']).'</td>';
259 } else {
260 $status = t3lib_div::hideIfNotTranslated($data['row']['l18n_cfg']) || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback';
261 $tCells[] = '<td class="'.$status.' c-leftLine">&nbsp;</td>';
262 $tCells[] = '<td class="'.$status.'">&nbsp;</td>';
263
264 $info = '<input type="checkbox" name="newOL['.$langRow['uid'].']['.$data['row']['uid'].']" value="1" />';
265 $newOL_js[$langRow['uid']].= '
266 +(document.webinfoForm[\'newOL['.$langRow['uid'].']['.$data['row']['uid'].']\'].checked ? \'&edit[pages_language_overlay]['.$data['row']['uid'].']=new\' : \'\')
267 ';
268 $tCells[] = '<td class="'.$status.'">'.$info.'</td>';
269 }
270 }
271 }
272
273 $output.= '
274 <tr class="bgColor4">
275 '.implode('
276 ',$tCells).'
277 </tr>';
278 }
279
280 // Put together HEADER:
281 $tCells = array();
282 $tCells[] = '<td>'.$LANG->getLL('lang_renderl10n_page','1').':</td>';
283
284 if (is_array($langRecUids[0])) {
285 $params = '&edit[pages]['.implode(',',$langRecUids[0]).']=edit&columnsOnly=title,nav_title,l18n_cfg,hidden';
286 $editIco = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
287 <img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editPageProperties','1').'" border="0" alt="" />
288 </a>';
289 } else $editIco = '';
290 $tCells[] = '<td class="c-leftLine" colspan="2">'.
291 $LANG->getLL('lang_renderl10n_default','1').':'.
292 $editIco.
293 '</td>';
294
295 foreach($languages as $langRow) {
296 if ($this->pObj->MOD_SETTINGS['lang']==0 || (int)$this->pObj->MOD_SETTINGS['lang']===(int)$langRow['uid']) {
297 // Title:
298 $tCells[] = '<td class="c-leftLine">'.htmlspecialchars($langRow['title']).'</td>';
299
300 // Edit language overlay records:
301 if (is_array($langRecUids[$langRow['uid']])) {
302 $params = '&edit[pages_language_overlay]['.implode(',',$langRecUids[$langRow['uid']]).']=edit&columnsOnly=title,nav_title,hidden';
303 $tCells[] = '<td><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
304 <img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editLangOverlays','1').'" border="0" alt="" />
305 </a></td>';
306 } else {
307 $tCells[] = '<td>&nbsp;</td>';
308 }
309
310 // Create new overlay records:
311 $params = "'".$newOL_js[$langRow['uid']]."+'&columnsOnly=title,hidden,sys_language_uid&defVals[pages_language_overlay][sys_language_uid]=".$langRow['uid'];
312 $tCells[] = '<td><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
313 <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="" />
314 </a></td>';
315 }
316 }
317
318 $output = '
319 <tr class="bgColor5">
320 '.implode('
321 ',$tCells).'
322 </tr>'.$output;
323
324 $output = '
325
326 <table border="0" cellspacing="0" cellpadding="0" id="langTable">'.$output.'
327 </table>';
328
329 return $output;
330 }
331
332 /**
333 * Selects all system languages (from sys_language)
334 *
335 * @return array System language records in an array.
336 */
337 function getSystemLanguages() {
338 if (!$GLOBALS['BE_USER']->user['admin'] &&
339 strlen($GLOBALS['BE_USER']->dataLists['allowed_languages'])) {
340
341 $allowed_languages = array_flip(explode(',', $GLOBALS['BE_USER']->dataLists['allowed_languages']));
342 }
343
344 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
345 '*',
346 'sys_language',
347 '1=1'.t3lib_BEfunc::deleteClause('sys_language')
348 );
349
350 $outputArray = array();
351 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
352 if (is_array($allowed_languages) && count($allowed_languages)) {
353 if (isset($allowed_languages[$row['uid']])) {
354 $outputArray[] = $row;
355 }
356 }
357 else {
358 $outputArray[] = $row;
359 }
360 }
361
362 return $outputArray;
363 }
364
365 /**
366 * Get an alternative language record for a specific page / language
367 *
368 * @param integer Page ID to look up for.
369 * @param integer Language UID to select for.
370 * @return array pages_languages_overlay record
371 */
372 function getLangStatus($pageId, $langId) {
373 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
374 '*',
375 'pages_language_overlay',
376 'pid='.intval($pageId).
377 ' AND sys_language_uid='.intval($langId).
378 t3lib_BEfunc::deleteClause('pages_language_overlay').
379 t3lib_BEfunc::versioningPlaceholderClause('pages_language_overlay')
380 );
381
382 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
383 t3lib_BEfunc::workspaceOL('pages_language_overlay',$row);
384 if (is_array($row)) {
385 $row['_COUNT'] = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
386 $row['_HIDDEN'] = $row['hidden'] ||
387 (intval($row['endtime']) > 0 && intval($row['endtime']) < time()) ||
388 (time() < intval($row['starttime']));
389 }
390
391 return $row;
392 }
393
394 /**
395 * Counting content elements for a single language on a page.
396 *
397 * @param integer Page id to select for.
398 * @param integer Sys language uid
399 * @return integer Number of content elements from the PID where the language is set to a certain value.
400 */
401 function getContentElementCount($pageId,$sysLang) {
402 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
403 'count(*)',
404 'tt_content',
405 'pid='.intval($pageId).
406 ' AND sys_language_uid='.intval($sysLang).
407 t3lib_BEfunc::deleteClause('tt_content').
408 t3lib_BEfunc::versioningPlaceholderClause('tt_content')
409 );
410
411 list($count) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
412 return $count ? $count : '-';
413 }
414 }
415
416
417 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php']) {
418 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php']);
419 }
420
421 ?>