*** empty log message ***
[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 display (including hit statistics)
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
206 // Traverse system languages:
207 foreach($languages as $langRow) {
208 $row = $this->getLangStatus($data['row']['uid'], $langRow['uid']);
209 $info = '';
210
211 if (is_array($row)) {
212 $langRecUids[$langRow['uid']][] = $row['uid'];
213 $status = $row['_HIDDEN'] ? ($data['row']['l18n_cfg']&2 || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback') : 'c-ok';
214 $icon = t3lib_iconWorks::getIconImage(
215 'pages_language_overlay',
216 $row,
217 $GLOBALS['BACK_PATH'],
218 'align="top" class="c-recIcon"'
219 );
220
221 $info = $icon.
222 htmlspecialchars(t3lib_div::fixed_lgd_cs($row['title'],$titleLen)).
223 (strcmp($row['nav_title'],'') ? ' [Nav: <em>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['nav_title'],$titleLen)).'</em>]' : '').
224 ($row['_COUNT']>1 ? '<div>'.$LANG->getLL('lang_renderl10n_badThingThereAre','1').'</div>':'');
225 $tCells[] = '<td class="'.$status.' c-leftLine">'.$info.'</td>';
226
227 // Edit whole record:
228 $info = '';
229 $editUid = $row['uid'];
230 $params = '&edit[pages_language_overlay]['.$editUid.']=edit';
231 $info.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">'.
232 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editLanguageOverlayRecord','1').'" border="0" alt="" />'.
233 '</a>';
234
235 $info.= '<a href="#" onclick="'.htmlspecialchars('top.loadEditId('.intval($data['row']['uid']).',"&SET[language]='.$langRow['uid'].'"); return false;').'">'.
236 '<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="" />'.
237 '</a>';
238 $info.= str_replace('###LANG_UID###',$langRow['uid'],$viewPageLink);
239
240 $tCells[] = '<td class="'.$status.'">'.$info.'</td>';
241 $tCells[] = '<td class="'.$status.'">&nbsp;</td>';
242 } else {
243 $status = $data['row']['l18n_cfg']&2 || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback';
244 $tCells[] = '<td class="'.$status.' c-leftLine">&nbsp;</td>';
245 $tCells[] = '<td class="'.$status.'">&nbsp;</td>';
246
247 $info = '';
248 $info.= '<input type="checkbox" name="newOL['.$langRow['uid'].']['.$data['row']['uid'].']" value="1" />';
249 $newOL_js[$langRow['uid']].= '
250 +(document.webinfoForm[\'newOL['.$langRow['uid'].']['.$data['row']['uid'].']\'].checked ? \'&edit[pages_language_overlay]['.$data['row']['uid'].']=new\' : \'\')
251 ';
252 $tCells[] = '<td class="'.$status.'">'.$info.'</td>';
253 }
254 }
255
256 $output.= '
257 <tr class="bgColor4">
258 '.implode('
259 ',$tCells).'
260 </tr>';
261 }
262
263 // Put together HEADER:
264 $tCells = array();
265 $tCells[] = '<td>'.$LANG->getLL('lang_renderl10n_page','1').':</td>';
266
267 if (is_array($langRecUids[0])) {
268 $params = '&edit[pages]['.implode(',',$langRecUids[0]).']=edit&columnsOnly=title,nav_title,l18n_cfg,hidden';
269 $editIco = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
270 <img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editPageHeaders','1').'" border="0" alt="" />
271 </a>';
272 } else $editIco = '';
273 $tCells[] = '<td class="c-leftLine">'.
274 $LANG->getLL('lang_renderl10n_default','1').':'.
275 $editIco.
276 '</td>';
277
278 foreach($languages as $langRow) {
279 // Title:
280 $tCells[] = '<td class="c-leftLine">'.htmlspecialchars($langRow['title']).'</td>';
281
282 // Edit language overlay records:
283 if (is_array($langRecUids[$langRow['uid']])) {
284 $params = '&edit[pages_language_overlay]['.implode(',',$langRecUids[$langRow['uid']]).']=edit&columnsOnly=title,nav_title,hidden';
285 $tCells[] = '<td><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
286 <img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editLangOverlays','1').'" border="0" alt="" />
287 </a></td>';
288 } else {
289 $tCells[] = '<td>&nbsp;</td>';
290 }
291
292 // Create new overlay records:
293 $params = "'".$newOL_js[$langRow['uid']]."+'&columnsOnly=title,hidden,sys_language_uid&defVals[pages_language_overlay][sys_language_uid]=".$langRow['uid'];
294 $tCells[] = '<td><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
295 <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="" />
296 </a></td>';
297 }
298
299 $output = '
300 <tr class="bgColor5">
301 '.implode('
302 ',$tCells).'
303 </tr>'.$output;
304
305 $output = '
306
307 <table border="0" cellspacing="0" cellpadding="0" id="langTable">'.$output.'
308 </table>';
309
310 return $output;
311 }
312
313 /**
314 * Selects all system languages (from sys_language)
315 *
316 * @return array System language records in an array.
317 */
318 function getSystemLanguages() {
319 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
320 '*',
321 'sys_language',
322 '1'.t3lib_BEfunc::deleteClause('sys_language')
323 );
324
325 $outputArray = array();
326 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
327 $outputArray[] = $row;
328 }
329
330 return $outputArray;
331 }
332
333 /**
334 * Get an alternative language record for a specific page / language
335 *
336 * @return array pages_languages_overlay record
337 */
338 function getLangStatus($pageId, $langId) {
339 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
340 '*',
341 'pages_language_overlay',
342 'pid='.intval($pageId).
343 ' AND sys_language_uid='.intval($langId).
344 t3lib_BEfunc::deleteClause('pages_language_overlay')
345 );
346
347 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
348 if (is_array($row)) {
349 $row['_COUNT'] = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
350 $row['_HIDDEN'] = $row['hidden'] ||
351 (intval($row['endtime']) > 0 && intval($row['endtime']) < time()) ||
352 (time() < intval($row['starttime']));
353 }
354
355 return $row;
356 }
357 }
358
359
360 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php']) {
361 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php']);
362 }
363 ?>