Fixed bug #15424: [web_info] allow more than 3 levels for pagetree overview and local...
[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-2010 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 * Class for displaying translation status of pages in the tree.
54 *
55 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
56 * @package TYPO3
57 * @subpackage tx_cms
58 */
59 class tx_cms_webinfo_lang extends t3lib_extobjbase {
60
61 /**
62 * Returns the menu array
63 *
64 * @return array
65 */
66 function modMenu() {
67 global $LANG;
68
69 $menuArray = array (
70 'depth' => array(
71 0 => $LANG->getLL('depth_0'),
72 1 => $LANG->getLL('depth_1'),
73 2 => $LANG->getLL('depth_2'),
74 3 => $LANG->getLL('depth_3'),
75 999 => $LANG->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_infi'),
76 ),
77 );
78
79 // Languages:
80 $lang = $this->getSystemLanguages();
81 $menuArray['lang']=array(
82 0 => '[All]'
83 );
84 foreach($lang as $langRec) {
85 $menuArray['lang'][$langRec['uid']] = $langRec['title'];
86 }
87
88 return $menuArray;
89 }
90
91 /**
92 * MAIN function for page information of localization
93 *
94 * @return string Output HTML for the module.
95 */
96 function main() {
97 global $BACK_PATH,$LANG,$SOBE;
98
99 if ($this->pObj->id) {
100 $theOutput = '';
101
102 // Depth selector:
103 $h_func = t3lib_BEfunc::getFuncMenu($this->pObj->id,'SET[depth]',$this->pObj->MOD_SETTINGS['depth'],$this->pObj->MOD_MENU['depth'],'index.php');
104 $h_func.= t3lib_BEfunc::getFuncMenu($this->pObj->id,'SET[lang]',$this->pObj->MOD_SETTINGS['lang'],$this->pObj->MOD_MENU['lang'],'index.php');
105 $theOutput.= $h_func;
106
107 // Add CSH:
108 $theOutput .= t3lib_BEfunc::cshItem('_MOD_web_info', 'lang', $GLOBALS['BACK_PATH'], '|<br />');
109
110 // Showing the tree:
111 // Initialize starting point of page tree:
112 $treeStartingPoint = intval($this->pObj->id);
113 $treeStartingRecord = t3lib_BEfunc::getRecordWSOL('pages', $treeStartingPoint);
114 $depth = $this->pObj->MOD_SETTINGS['depth'];
115
116 // Initialize tree object:
117 $tree = t3lib_div::makeInstance('t3lib_pageTree');
118 $tree->init('AND '.$GLOBALS['BE_USER']->getPagePermsClause(1));
119 $tree->addField('l18n_cfg');
120
121 // Creating top icon; the current page
122 $HTML = t3lib_iconWorks::getSpriteIconForRecord('pages', $treeStartingRecord);
123 $tree->tree[] = array(
124 'row' => $treeStartingRecord,
125 'HTML'=>$HTML
126 );
127
128 // Create the tree from starting point:
129 if ($depth) $tree->getTree($treeStartingPoint, $depth, '');
130
131 // Render information table:
132 $theOutput.= $this->renderL10nTable($tree);
133 }
134
135 return $theOutput;
136 }
137
138 /**
139 * Rendering the localization information table.
140 *
141 * @param array The Page tree data
142 * @return string HTML for the localization information table.
143 */
144 function renderL10nTable(&$tree) {
145 global $LANG;
146
147 // System languages retrieved:
148 $languages = $this->getSystemLanguages();
149
150 // Title length:
151 $titleLen = $GLOBALS['BE_USER']->uc['titleLen'];
152
153 // Put together the TREE:
154 $output = '';
155 $newOL_js = array();
156 $langRecUids = array();
157 foreach($tree->tree as $data) {
158 $tCells = array();
159 $langRecUids[0][] = $data['row']['uid'];
160
161 // Page icons / titles etc.
162 $tCells[] = '<td'.($data['row']['_CSSCLASS'] ? ' class="'.$data['row']['_CSSCLASS'].'"' : '').'>'.
163 $data['HTML'].
164 htmlspecialchars(t3lib_div::fixed_lgd_cs($data['row']['title'],$titleLen)).
165 (strcmp($data['row']['nav_title'],'') ? ' [Nav: <em>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($data['row']['nav_title'],$titleLen)).'</em>]' : '').
166 '</td>';
167
168 // DEFAULT language:
169 // "View page" link is created:
170 $viewPageLink= '<a href="#" onclick="'.
171 htmlspecialchars(t3lib_BEfunc::viewOnClick($data['row']['uid'],$GLOBALS['BACK_PATH'],'','','','&L=###LANG_UID###')).'" title="' . $LANG->getLL('lang_renderl10n_viewPage', TRUE) . '">' .
172 t3lib_iconWorks::getSpriteIcon('actions-document-view') .
173 '</a>';
174 $status = $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-ok';
175
176 // Create links:
177 $info = '';
178 $editUid = $data['row']['uid'];
179 $params = '&edit[pages]['.$editUid.']=edit';
180 $info.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'" title="' . $LANG->getLL('lang_renderl10n_editDefaultLanguagePage', TRUE) . '">'.
181 t3lib_iconWorks::getSpriteIcon('actions-document-open') .
182 '</a>';
183 $info.= '<a href="#" onclick="'.htmlspecialchars('top.loadEditId('.intval($data['row']['uid']).',"&SET[language]=0"); return false;').'" title="' . $LANG->getLL('lang_renderl10n_editPage', TRUE) . '">' .
184 t3lib_iconWorks::getSpriteIcon('actions-page-open') .
185 '</a>';
186 $info.= str_replace('###LANG_UID###','0',$viewPageLink);
187
188 $info.= '&nbsp;';
189 $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;';
190 $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;';
191
192 // Put into cell:
193 $tCells[] = '<td class="'.$status.' c-leftLine">'.$info.'</td>';
194 $tCells[] = '<td class="'.$status.'" title="'.$LANG->getLL('lang_renderl10n_CEcount','1').'" align="center">'.$this->getContentElementCount($data['row']['uid'],0).'</td>';
195
196 $modSharedTSconfig = t3lib_BEfunc::getModTSconfig($data['row']['uid'], 'mod.SHARED');
197 $disableLanguages = isset($modSharedTSconfig['properties']['disableLanguages']) ? t3lib_div::trimExplode(',', $modSharedTSconfig['properties']['disableLanguages'], 1) : array();
198
199 // Traverse system languages:
200 foreach($languages as $langRow) {
201 if ($this->pObj->MOD_SETTINGS['lang']==0 || (int)$this->pObj->MOD_SETTINGS['lang']===(int)$langRow['uid']) {
202 $row = $this->getLangStatus($data['row']['uid'], $langRow['uid']);
203 $info = '';
204
205 if (is_array($row)) {
206 $langRecUids[$langRow['uid']][] = $row['uid'];
207 $status = $row['_HIDDEN'] ? (t3lib_div::hideIfNotTranslated($data['row']['l18n_cfg']) || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback') : 'c-ok';
208 $icon = t3lib_iconWorks::getSpriteIconForRecord(
209 'pages_language_overlay',
210 $row,
211 array('class' => 'c-recIcon')
212 );
213
214 $info = $icon.
215 htmlspecialchars(t3lib_div::fixed_lgd_cs($row['title'],$titleLen)).
216 (strcmp($row['nav_title'],'') ? ' [Nav: <em>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['nav_title'],$titleLen)).'</em>]' : '').
217 ($row['_COUNT']>1 ? '<div>'.$LANG->getLL('lang_renderl10n_badThingThereAre','1').'</div>':'');
218 $tCells[] = '<td class="'.$status.' c-leftLine">'.
219 $info.
220 '</td>';
221
222 // Edit whole record:
223 $info = '';
224 $editUid = $row['uid'];
225 $params = '&edit[pages_language_overlay]['.$editUid.']=edit';
226 $info.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'" title="' . $LANG->getLL('lang_renderl10n_editLanguageOverlayRecord', TRUE) . '">' .
227 t3lib_iconWorks::getSpriteIcon('actions-document-open') .
228 '</a>';
229
230 $info.= '<a href="#" onclick="'.htmlspecialchars('top.loadEditId('.intval($data['row']['uid']).',"&SET[language]='.$langRow['uid'].'"); return false;').'" title="' . $LANG->getLL('lang_renderl10n_editPageLang', TRUE) . '">' .
231 t3lib_iconWorks::getSpriteIcon('actions-page-open') .
232 '</a>';
233 $info.= str_replace('###LANG_UID###',$langRow['uid'],$viewPageLink);
234
235 $tCells[] = '<td class="'.$status.'">'.$info.'</td>';
236 $tCells[] = '<td class="'.$status.'" title="'.$LANG->getLL('lang_renderl10n_CEcount','1').'" align="center">'.$this->getContentElementCount($data['row']['uid'],$langRow['uid']).'</td>';
237 } else {
238 if (in_array($langRow['uid'], $disableLanguages)) {
239 // Language has been disabled for this page
240 $status = 'c-blocked';
241 $info = '';
242 } else {
243 $status = t3lib_div::hideIfNotTranslated($data['row']['l18n_cfg']) || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback';
244 $info = '<input type="checkbox" name="newOL['.$langRow['uid'].']['.$data['row']['uid'].']" value="1" />';
245 $newOL_js[$langRow['uid']].= '
246 +(document.webinfoForm[\'newOL['.$langRow['uid'].']['.$data['row']['uid'].']\'].checked ? \'&edit[pages_language_overlay]['.$data['row']['uid'].']=new\' : \'\')
247 ';
248 }
249
250 $tCells[] = '<td class="'.$status.' c-leftLine">&nbsp;</td>';
251 $tCells[] = '<td class="'.$status.'">&nbsp;</td>';
252 $tCells[] = '<td class="'.$status.'">'.$info.'</td>';
253 }
254 }
255 }
256
257 $output.= '
258 <tr class="bgColor4">
259 '.implode('
260 ',$tCells).'
261 </tr>';
262 }
263
264 // Put together HEADER:
265 $tCells = array();
266 $tCells[] = '<td>'.$LANG->getLL('lang_renderl10n_page','1').':</td>';
267
268 if (is_array($langRecUids[0])) {
269 $params = '&edit[pages]['.implode(',',$langRecUids[0]).']=edit&columnsOnly=title,nav_title,l18n_cfg,hidden';
270 $editIco = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'" title="' . $LANG->getLL('lang_renderl10n_editPageProperties', TRUE) . '">' .
271 t3lib_iconWorks::getSpriteIcon('actions-document-new') .
272 '</a>';
273 } else $editIco = '';
274 $tCells[] = '<td class="c-leftLine" colspan="2">'.
275 $LANG->getLL('lang_renderl10n_default','1').':'.
276 $editIco.
277 '</td>';
278
279 foreach($languages as $langRow) {
280 if ($this->pObj->MOD_SETTINGS['lang']==0 || (int)$this->pObj->MOD_SETTINGS['lang']===(int)$langRow['uid']) {
281 // Title:
282 $tCells[] = '<td class="c-leftLine">'.htmlspecialchars($langRow['title']).'</td>';
283
284 // Edit language overlay records:
285 if (is_array($langRecUids[$langRow['uid']])) {
286 $params = '&edit[pages_language_overlay]['.implode(',',$langRecUids[$langRow['uid']]).']=edit&columnsOnly=title,nav_title,hidden';
287 $tCells[] = '<td><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'" title="' . $LANG->getLL('lang_renderl10n_editLangOverlays', TRUE) . '">' .
288 t3lib_iconWorks::getSpriteIcon('actions-document-open') .
289 '</a></td>';
290 } else {
291 $tCells[] = '<td>&nbsp;</td>';
292 }
293
294 // Create new overlay records:
295 $params = "'".$newOL_js[$langRow['uid']]."+'&columnsOnly=title,hidden,sys_language_uid&defVals[pages_language_overlay][sys_language_uid]=".$langRow['uid'];
296 $tCells[] = '<td><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'" title="' . $LANG->getLL('lang_getlangsta_createNewTranslationHeaders', TRUE) . '">' .
297 t3lib_iconWorks::getSpriteIcon('actions-document-new') .
298 '</a></td>';
299 }
300 }
301
302 $output = '
303 <tr class="t3-row-header">
304 '.implode('
305 ',$tCells).'
306 </tr>'.$output;
307
308 $output = '
309
310 <table border="0" cellspacing="0" cellpadding="0" id="langTable" class="typo3-dblist">' . $output . '
311 </table>';
312
313 return $output;
314 }
315
316 /**
317 * Selects all system languages (from sys_language)
318 *
319 * @return array System language records in an array.
320 */
321 function getSystemLanguages() {
322 if (!$GLOBALS['BE_USER']->user['admin'] &&
323 strlen($GLOBALS['BE_USER']->groupData['allowed_languages'])) {
324
325 $allowed_languages = array_flip(explode(',', $GLOBALS['BE_USER']->groupData['allowed_languages']));
326 }
327
328 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
329 '*',
330 'sys_language',
331 '1=1'.t3lib_BEfunc::deleteClause('sys_language')
332 );
333
334 $outputArray = array();
335 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
336 if (is_array($allowed_languages) && count($allowed_languages)) {
337 if (isset($allowed_languages[$row['uid']])) {
338 $outputArray[] = $row;
339 }
340 }
341 else {
342 $outputArray[] = $row;
343 }
344 }
345
346 return $outputArray;
347 }
348
349 /**
350 * Get an alternative language record for a specific page / language
351 *
352 * @param integer Page ID to look up for.
353 * @param integer Language UID to select for.
354 * @return array pages_languages_overlay record
355 */
356 function getLangStatus($pageId, $langId) {
357 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
358 '*',
359 'pages_language_overlay',
360 'pid='.intval($pageId).
361 ' AND sys_language_uid='.intval($langId).
362 t3lib_BEfunc::deleteClause('pages_language_overlay').
363 t3lib_BEfunc::versioningPlaceholderClause('pages_language_overlay')
364 );
365
366 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
367 t3lib_BEfunc::workspaceOL('pages_language_overlay',$row);
368 if (is_array($row)) {
369 $row['_COUNT'] = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
370 $row['_HIDDEN'] = $row['hidden'] ||
371 (intval($row['endtime']) > 0 && intval($row['endtime']) < $GLOBALS['EXEC_TIME']) ||
372 ($GLOBALS['EXEC_TIME'] < intval($row['starttime']));
373 }
374
375 return $row;
376 }
377
378 /**
379 * Counting content elements for a single language on a page.
380 *
381 * @param integer Page id to select for.
382 * @param integer Sys language uid
383 * @return integer Number of content elements from the PID where the language is set to a certain value.
384 */
385 function getContentElementCount($pageId,$sysLang) {
386 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
387 'uid',
388 'tt_content',
389 'pid=' . intval($pageId) .
390 ' AND sys_language_uid=' . intval($sysLang) .
391 t3lib_BEfunc::deleteClause('tt_content') .
392 t3lib_BEfunc::versioningPlaceholderClause('tt_content')
393 );
394 return $count ? $count : '-';
395 }
396 }
397
398
399 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php']) {
400 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php']);
401 }
402
403 ?>