See changelog (updated later)
[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-2004 Kasper Skaarhoj (kasper@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 <kasper@typo3.com>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 *
38 *
39 * 66: class tx_cms_webinfo_page extends t3lib_extobjbase
40 * 73: function modMenu()
41 * 100: function main()
42 *
43 *
44 * 191: class tx_cms_webinfo_hits extends tx_cms_webinfo_page
45 *
46 * TOTAL FUNCTIONS: 2
47 * (This index is automatically created/updated by the extension "extdeveval")
48 *
49 */
50
51 require_once(PATH_t3lib.'class.t3lib_pagetree.php');
52 require_once(PATH_t3lib.'class.t3lib_extobjbase.php');
53
54
55
56
57 /**
58 * Class for displaying translation status of pages in the tree.
59 *
60 * @author Kasper Skaarhoj <kasper@typo3.com>
61 * @package TYPO3
62 * @subpackage tx_cms
63 */
64 class tx_cms_webinfo_lang extends t3lib_extobjbase {
65
66 /**
67 * Returns the menu array
68 *
69 * @return array
70 */
71 function modMenu() {
72 global $LANG;
73
74 return array (
75 'depth' => array(
76 1 => $LANG->getLL('depth_1'),
77 2 => $LANG->getLL('depth_2'),
78 3 => $LANG->getLL('depth_3')
79 )
80 );
81 }
82
83 /**
84 * MAIN function for page information of localization
85 *
86 * @return string Output HTML for the module.
87 */
88 function main() {
89 global $BACK_PATH,$LANG,$SOBE;
90
91 if ($this->pObj->id) {
92 $theOutput = '';
93
94 // Depth selector:
95 $h_func = t3lib_BEfunc::getFuncMenu($this->pObj->id,'SET[depth]',$this->pObj->MOD_SETTINGS['depth'],$this->pObj->MOD_MENU['depth'],'index.php');
96 $theOutput.= $h_func;
97
98 // Add CSH:
99 $theOutput.= t3lib_BEfunc::cshItem('_MOD_web_info','lang',$GLOBALS['BACK_PATH'],'|<br/>');
100
101 // Showing the tree:
102 // Initialize starting point of page tree:
103 $treeStartingPoint = intval($this->pObj->id);
104 $treeStartingRecord = t3lib_BEfunc::getRecord('pages', $treeStartingPoint);
105 $depth = $this->pObj->MOD_SETTINGS['depth'];
106
107 // Initialize tree object:
108 $tree = t3lib_div::makeInstance('t3lib_pageTree');
109 $tree->init('AND '.$GLOBALS['BE_USER']->getPagePermsClause(1));
110 $tree->addField('l18n_cfg');
111
112 // Creating top icon; the current page
113 $HTML = t3lib_iconWorks::getIconImage('pages', $treeStartingRecord, $GLOBALS['BACK_PATH'],'align="top"');
114 $tree->tree[] = array(
115 'row' => $treeStartingRecord,
116 'HTML'=>$HTML
117 );
118
119 // Create the tree from starting point:
120 $tree->getTree($treeStartingPoint, $depth, '');
121 #debug($tree->tree);
122
123 // Add CSS needed:
124 $css_content = '
125 TABLE#langTable {
126 margin-top: 10px;
127 }
128 TABLE#langTable TR TD {
129 padding-left : 2px;
130 padding-right : 2px;
131 white-space: nowrap;
132 }
133 TD.c-blocked { background-color: red; }
134 TD.c-ok { background-color: #669966; }
135 TD.c-fallback { }
136 TD.c-leftLine {border-left: 2px solid black; }
137 .bgColor5 { font-weight: bold; }
138 ';
139 $marker = '/*###POSTCSSMARKER###*/';
140 $this->pObj->content = str_replace($marker,$css_content.chr(10).$marker,$this->pObj->content);
141
142 // Render information table:
143 $theOutput.= $this->renderL10nTable($tree);
144 }
145
146 return $theOutput;
147 }
148
149 /**
150 * Rendering the localization information table.
151 *
152 * @param array The Page tree data
153 * @return string HTML for the localization information table.
154 */
155 function renderL10nTable(&$tree) {
156 global $LANG;
157
158 // System languages retrieved:
159 $languages = $this->getSystemLanguages();
160
161 // Title length:
162 $titleLen = $GLOBALS['BE_USER']->uc['titleLen'];
163
164 // Put together the TREE:
165 $output = '';
166 $newOL_js = array();
167 $langRecUids = array();
168 foreach($tree->tree as $data) {
169 $tCells = array();
170 $langRecUids[0][] = $data['row']['uid'];
171
172 // Page icons / titles etc.
173 $tCells[] = '<td>'.
174 $data['HTML'].
175 htmlspecialchars(t3lib_div::fixed_lgd_cs($data['row']['title'],$titleLen)).
176 (strcmp($data['row']['nav_title'],'') ? ' [Nav: <em>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($data['row']['nav_title'],$titleLen)).'</em>]' : '').
177 '</td>';
178
179 // DEFAULT language:
180 // "View page" link is created:
181 $viewPageLink= '<a href="#" onclick="'.
182 htmlspecialchars(t3lib_BEfunc::viewOnClick($data['row']['uid'],$GLOBALS['BACK_PATH'],'','','','&L=###LANG_UID###')).'">'.
183 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/zoom.gif','width="12" height="12"').' title="'.$LANG->getLL('lang_renderl10n_viewPage','1').'" border="0" alt="" />'.
184 '</a>';
185 $status = $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-ok';
186
187 // Create links:
188 $info = '';
189 $editUid = $data['row']['uid'];
190 $params = '&edit[pages]['.$editUid.']=edit';
191 $info.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">'.
192 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editDefaultLanguagePage','1').'" border="0" alt="" />'.
193 '</a>';
194 $info.= '<a href="#" onclick="'.htmlspecialchars('top.loadEditId('.intval($data['row']['uid']).',"&SET[language]=0"); return false;').'">'.
195 '<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="" />'.
196 '</a>';
197 $info.= str_replace('###LANG_UID###','0',$viewPageLink);
198
199 $info.= '&nbsp;';
200 $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;';
201 $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;';
202
203 // Put into cell:
204 $tCells[] = '<td class="'.$status.' c-leftLine">'.$info.'</td>';
205 $tCells[] = '<td class="'.$status.'" title="'.$LANG->getLL('lang_renderl10n_CEcount','1').'" align="center">'.$this->getContentElementCount($data['row']['uid'],0).'</td>';
206
207 // Traverse system languages:
208 foreach($languages as $langRow) {
209 $row = $this->getLangStatus($data['row']['uid'], $langRow['uid']);
210 $info = '';
211
212 if (is_array($row)) {
213 $langRecUids[$langRow['uid']][] = $row['uid'];
214 $status = $row['_HIDDEN'] ? ($data['row']['l18n_cfg']&2 || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback') : 'c-ok';
215 $icon = t3lib_iconWorks::getIconImage(
216 'pages_language_overlay',
217 $row,
218 $GLOBALS['BACK_PATH'],
219 'align="top" class="c-recIcon"'
220 );
221
222 $info = $icon.
223 htmlspecialchars(t3lib_div::fixed_lgd_cs($row['title'],$titleLen)).
224 (strcmp($row['nav_title'],'') ? ' [Nav: <em>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['nav_title'],$titleLen)).'</em>]' : '').
225 ($row['_COUNT']>1 ? '<div>'.$LANG->getLL('lang_renderl10n_badThingThereAre','1').'</div>':'');
226 $tCells[] = '<td class="'.$status.' c-leftLine">'.$info.'</td>';
227
228 // Edit whole record:
229 $info = '';
230 $editUid = $row['uid'];
231 $params = '&edit[pages_language_overlay]['.$editUid.']=edit';
232 $info.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">'.
233 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editLanguageOverlayRecord','1').'" border="0" alt="" />'.
234 '</a>';
235
236 $info.= '<a href="#" onclick="'.htmlspecialchars('top.loadEditId('.intval($data['row']['uid']).',"&SET[language]='.$langRow['uid'].'"); return false;').'">'.
237 '<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="" />'.
238 '</a>';
239 $info.= str_replace('###LANG_UID###',$langRow['uid'],$viewPageLink);
240
241 $tCells[] = '<td class="'.$status.'">'.$info.'</td>';
242 $tCells[] = '<td class="'.$status.'" title="'.$LANG->getLL('lang_renderl10n_CEcount','1').'" align="center">'.$this->getContentElementCount($data['row']['uid'],$langRow['uid']).'</td>';
243 } else {
244 $status = $data['row']['l18n_cfg']&2 || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback';
245 $tCells[] = '<td class="'.$status.' c-leftLine">&nbsp;</td>';
246 $tCells[] = '<td class="'.$status.'">&nbsp;</td>';
247
248 $info = '';
249 $info.= '<input type="checkbox" name="newOL['.$langRow['uid'].']['.$data['row']['uid'].']" value="1" />';
250 $newOL_js[$langRow['uid']].= '
251 +(document.webinfoForm[\'newOL['.$langRow['uid'].']['.$data['row']['uid'].']\'].checked ? \'&edit[pages_language_overlay]['.$data['row']['uid'].']=new\' : \'\')
252 ';
253 $tCells[] = '<td class="'.$status.'">'.$info.'</td>';
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'])).'">
271 <img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editPageHeaders','1').'" border="0" alt="" />
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 // Title:
281 $tCells[] = '<td class="c-leftLine">'.htmlspecialchars($langRow['title']).'</td>';
282
283 // Edit language overlay records:
284 if (is_array($langRecUids[$langRow['uid']])) {
285 $params = '&edit[pages_language_overlay]['.implode(',',$langRecUids[$langRow['uid']]).']=edit&columnsOnly=title,nav_title,hidden';
286 $tCells[] = '<td><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_editLangOverlays','1').'" border="0" alt="" />
288 </a></td>';
289 } else {
290 $tCells[] = '<td>&nbsp;</td>';
291 }
292
293 // Create new overlay records:
294 $params = "'".$newOL_js[$langRow['uid']]."+'&columnsOnly=title,hidden,sys_language_uid&defVals[pages_language_overlay][sys_language_uid]=".$langRow['uid'];
295 $tCells[] = '<td><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
296 <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="" />
297 </a></td>';
298 }
299
300 $output = '
301 <tr class="bgColor5">
302 '.implode('
303 ',$tCells).'
304 </tr>'.$output;
305
306 $output = '
307
308 <table border="0" cellspacing="0" cellpadding="0" id="langTable">'.$output.'
309 </table>';
310
311 return $output;
312 }
313
314 /**
315 * Selects all system languages (from sys_language)
316 *
317 * @return array System language records in an array.
318 */
319 function getSystemLanguages() {
320 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
321 '*',
322 'sys_language',
323 '1'.t3lib_BEfunc::deleteClause('sys_language')
324 );
325
326 $outputArray = array();
327 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
328 $outputArray[] = $row;
329 }
330
331 return $outputArray;
332 }
333
334 /**
335 * Get an alternative language record for a specific page / language
336 *
337 * @return array pages_languages_overlay record
338 */
339 function getLangStatus($pageId, $langId) {
340 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
341 '*',
342 'pages_language_overlay',
343 'pid='.intval($pageId).
344 ' AND sys_language_uid='.intval($langId).
345 t3lib_BEfunc::deleteClause('pages_language_overlay')
346 );
347
348 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
349 if (is_array($row)) {
350 $row['_COUNT'] = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
351 $row['_HIDDEN'] = $row['hidden'] ||
352 (intval($row['endtime']) > 0 && intval($row['endtime']) < time()) ||
353 (time() < intval($row['starttime']));
354 }
355
356 return $row;
357 }
358
359 /**
360 * Counting content elements for a single language on a page.
361 *
362 * @param integer Page id to select for.
363 * @param integer Sys language uid
364 * @return integer Number of content elements from the PID where the language is set to a certain value.
365 */
366 function getContentElementCount($pageId,$sysLang) {
367 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
368 'count(*)',
369 'tt_content',
370 'pid='.intval($pageId).
371 ' AND sys_language_uid='.intval($sysLang).
372 t3lib_BEfunc::deleteClause('tt_content')
373 );
374
375 list($count) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
376 return $count ? $count : '-';
377 }
378 }
379
380
381 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php']) {
382 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php']);
383 }
384 ?>