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