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