[BUGFIX] Correct type of argument passed to BackendUtility::viewOnClick
[Packages/TYPO3.CMS.git] / typo3 / sysext / info / Classes / Controller / TranslationStatusController.php
1 <?php
2
3 namespace TYPO3\CMS\Info\Controller;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Backend\Tree\View\PageTreeView;
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
20 use TYPO3\CMS\Core\Database\ConnectionPool;
21 use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
22 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
23 use TYPO3\CMS\Core\Imaging\Icon;
24 use TYPO3\CMS\Core\Imaging\IconFactory;
25 use TYPO3\CMS\Core\Utility\GeneralUtility;
26
27 /**
28 * Class for displaying translation status of pages in the tree.
29 */
30 class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule
31 {
32 /**
33 * @var IconFactory
34 */
35 protected $iconFactory;
36
37 /**
38 * @var string
39 * static table for pages_language_overlay
40 */
41 protected static $pageLanguageOverlayTable = 'pages_language_overlay';
42
43 /**
44 * Construct for initialize class variables
45 */
46 public function __construct()
47 {
48 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
49 }
50
51 /**
52 * Returns the menu array
53 *
54 * @return array
55 */
56 public function modMenu()
57 {
58 $lang = $this->getLanguageService();
59 $menuArray = [
60 'depth' => [
61 0 => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_0'),
62 1 => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_1'),
63 2 => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_2'),
64 3 => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_3'),
65 4 => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_4'),
66 999 => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_infi')
67 ]
68 ];
69 // Languages:
70 $lang = $this->getSystemLanguages();
71 $menuArray['lang'] = [
72 0 => '[All]'
73 ];
74 foreach ($lang as $langRec) {
75 $menuArray['lang'][$langRec['uid']] = $langRec['title'];
76 }
77 return $menuArray;
78 }
79
80 /**
81 * MAIN function for page information of localization
82 *
83 * @return string Output HTML for the module.
84 */
85 public function main()
86 {
87 $theOutput = '<h1>' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_title')) . '</h1>';
88 if ($this->pObj->id) {
89 // Depth selector:
90 $theOutput .= '<div class="form-inline form-inline-spaced">';
91 $h_func = BackendUtility::getDropdownMenu($this->pObj->id, 'SET[depth]', $this->pObj->MOD_SETTINGS['depth'], $this->pObj->MOD_MENU['depth']);
92 $h_func .= BackendUtility::getDropdownMenu($this->pObj->id, 'SET[lang]', $this->pObj->MOD_SETTINGS['lang'], $this->pObj->MOD_MENU['lang']);
93 $theOutput .= $h_func;
94 // Add CSH:
95 $theOutput .= BackendUtility::cshItem('_MOD_web_info', 'lang', null, '<div class="form-group"><span class="btn btn-default btn-sm">|</span></div><br />');
96 $theOutput .= '</div>';
97 // Showing the tree:
98 // Initialize starting point of page tree:
99 $treeStartingPoint = (int)$this->pObj->id;
100 $treeStartingRecord = BackendUtility::getRecordWSOL('pages', $treeStartingPoint);
101 $depth = $this->pObj->MOD_SETTINGS['depth'];
102 // Initialize tree object:
103 $tree = GeneralUtility::makeInstance(PageTreeView::class);
104 $tree->init('AND ' . $this->getBackendUser()->getPagePermsClause(1));
105 $tree->addField('l18n_cfg');
106 // Creating top icon; the current page
107 $HTML = $this->iconFactory->getIconForRecord('pages', $treeStartingRecord, Icon::SIZE_SMALL)->render();
108 $tree->tree[] = [
109 'row' => $treeStartingRecord,
110 'HTML' => $HTML
111 ];
112 // Create the tree from starting point:
113 if ($depth) {
114 $tree->getTree($treeStartingPoint, $depth, '');
115 }
116 // Render information table:
117 $theOutput .= $this->renderL10nTable($tree);
118 }
119 return $theOutput;
120 }
121
122 /**
123 * Rendering the localization information table.
124 *
125 * @param array $tree The Page tree data
126 * @return string HTML for the localization information table.
127 */
128 public function renderL10nTable(&$tree)
129 {
130 $lang = $this->getLanguageService();
131 // System languages retrieved:
132 $languages = $this->getSystemLanguages();
133 // Title length:
134 $titleLen = $this->getBackendUser()->uc['titleLen'];
135 // Put together the TREE:
136 $output = '';
137 $newOL_js = [];
138 $langRecUids = [];
139 foreach ($tree->tree as $data) {
140 $tCells = [];
141 $langRecUids[0][] = $data['row']['uid'];
142 // Page icons / titles etc.
143 $tCells[] = '<td' . ($data['row']['_CSSCLASS'] ? ' class="' . $data['row']['_CSSCLASS'] . '"' : '') . '>' .
144 ($data['depthData'] ?: '') .
145 BackendUtility::wrapClickMenuOnIcon($data['HTML'], 'pages', $data['row']['uid']) .
146 '<a href="#" onclick="' . htmlspecialchars(
147 'top.loadEditId(' . (int)$data['row']['uid'] . ',"&SET[language]=0"); return false;'
148 ) . '" title="' . $lang->sL('LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editPage') . '">' .
149 htmlspecialchars(GeneralUtility::fixed_lgd_cs($data['row']['title'], $titleLen)) .
150 '</a>' .
151 ((string)$data['row']['nav_title'] !== '' ? ' [Nav: <em>' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($data['row']['nav_title'], $titleLen)) . '</em>]' : '') .
152 '</td>';
153 // DEFAULT language:
154 // "View page" link is created:
155 $viewPageLink = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick(
156 $data['row']['uid'], '', null, '', '', '&L=###LANG_UID###')
157 ) . '" class="btn btn-default" title="' . $lang->sL('LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_viewPage') . '">' .
158 $this->iconFactory->getIcon('actions-view', Icon::SIZE_SMALL)->render() . '</a>';
159 $status = GeneralUtility::hideIfDefaultLanguage($data['row']['l18n_cfg']) ? 'danger' : 'success';
160 // Create links:
161 $editUrl = BackendUtility::getModuleUrl('record_edit', [
162 'edit' => [
163 'pages' => [
164 $data['row']['uid'] => 'edit'
165 ]
166 ],
167 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
168 ]);
169 $info = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick(
170 $data['row']['uid'], '', null, '', '', '')
171 ) . '" class="btn btn-default" title="' . $lang->sL('LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_viewPage') . '">' .
172 $this->iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL)->render() . '</a>';
173 $info .= '<a href="' . htmlspecialchars($editUrl)
174 . '" class="btn btn-default" title="' . $lang->sL(
175 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editDefaultLanguagePage'
176 ) . '">' . $this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)->render() . '</a>';
177 $info .= '&nbsp;';
178 $info .= GeneralUtility::hideIfDefaultLanguage($data['row']['l18n_cfg']) ? '<span title="' . htmlspecialchars($lang->sL('LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.l18n_cfg.I.1')) . '">D</span>' : '&nbsp;';
179 $info .= GeneralUtility::hideIfNotTranslated($data['row']['l18n_cfg']) ? '<span title="' . htmlspecialchars($lang->sL('LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.l18n_cfg.I.2')) . '">N</span>' : '&nbsp;';
180 // Put into cell:
181 $tCells[] = '<td class="' . $status . ' col-border-left"><div class="btn-group">' . $info . '</div></td>';
182 $tCells[] = '<td class="' . $status . '" title="' . $lang->sL(
183 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_CEcount'
184 ) . '" align="center">' . $this->getContentElementCount($data['row']['uid'], 0) . '</td>';
185 $modSharedTSconfig = BackendUtility::getModTSconfig($data['row']['uid'], 'mod.SHARED');
186 $disableLanguages = isset($modSharedTSconfig['properties']['disableLanguages']) ? GeneralUtility::trimExplode(',', $modSharedTSconfig['properties']['disableLanguages'], true) : [];
187 // Traverse system languages:
188 foreach ($languages as $langRow) {
189 if ($this->pObj->MOD_SETTINGS['lang'] == 0 || (int)$this->pObj->MOD_SETTINGS['lang'] === (int)$langRow['uid']) {
190 $row = $this->getLangStatus($data['row']['uid'], $langRow['uid']);
191 $info = '';
192 if (is_array($row)) {
193 $langRecUids[$langRow['uid']][] = $row['uid'];
194 $status = $row['_HIDDEN'] ? (GeneralUtility::hideIfNotTranslated($data['row']['l18n_cfg']) || GeneralUtility::hideIfDefaultLanguage($data['row']['l18n_cfg']) ? 'danger' : '') : 'success';
195 $icon = $this->iconFactory->getIconForRecord('pages_language_overlay', $row, Icon::SIZE_SMALL)->render();
196 $info = $icon . htmlspecialchars(
197 GeneralUtility::fixed_lgd_cs($row['title'], $titleLen)
198 ) . ((string)$row['nav_title'] !== '' ? ' [Nav: <em>' . htmlspecialchars(
199 GeneralUtility::fixed_lgd_cs($row['nav_title'], $titleLen)
200 ) . '</em>]' : '') . ($row['_COUNT'] > 1 ? '<div>' . $lang->sL(
201 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_badThingThereAre'
202 ) . '</div>' : '');
203 $tCells[] = '<td class="' . $status . ' col-border-left">' .
204 '<a href="#" onclick="' . htmlspecialchars(
205 'top.loadEditId(' . (int)$data['row']['uid'] . ',"&SET[language]=' . $langRow['uid'] . '"); return false;'
206 ) . '" title="' . $lang->sL(
207 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editPageLang'
208 ) . '">' . $info . '</a></td>';
209 // Edit whole record:
210 // Create links:
211 $editUrl = BackendUtility::getModuleUrl('record_edit', [
212 'edit' => [
213 'pages_language_overlay' => [
214 $row['uid'] => 'edit'
215 ]
216 ],
217 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
218 ]);
219 $info = str_replace('###LANG_UID###', $langRow['uid'], $viewPageLink);
220 $info .= '<a href="' . htmlspecialchars($editUrl)
221 . '" class="btn btn-default" title="' . $lang->sL(
222 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editLanguageOverlayRecord'
223 ) . '">' . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>';
224 $tCells[] = '<td class="' . $status . '"><div class="btn-group">' . $info . '</div></td>';
225 $tCells[] = '<td class="' . $status . '" title="' . $lang->sL(
226 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_CEcount'
227 ) . '" align="center">' . $this->getContentElementCount($data['row']['uid'], $langRow['uid']) . '</td>';
228 } else {
229 if (in_array($langRow['uid'], $disableLanguages)) {
230 // Language has been disabled for this page
231 $status = 'danger';
232 $info = '';
233 } else {
234 $status = GeneralUtility::hideIfNotTranslated($data['row']['l18n_cfg']) || GeneralUtility::hideIfDefaultLanguage($data['row']['l18n_cfg']) ? 'danger' : '';
235 $info = '<div class="btn-group"><label class="btn btn-default btn-checkbox">';
236 $info .= '<input type="checkbox" name="newOL[' . $langRow['uid'] . '][' . $data['row']['uid'] . ']" value="1" />';
237 $info .= '<span class="t3-icon fa"></span></label></div>';
238 $newOL_js[$langRow['uid']] .= '
239 +(document.webinfoForm['
240 . GeneralUtility::quoteJSvalue('newOL[' . $langRow['uid'] . '][' . $data['row']['uid'] . ']')
241 . '].checked ? '
242 . GeneralUtility::quoteJSvalue('&edit[pages_language_overlay][' . $data['row']['uid'] . ']=new')
243 . ' : \'\')
244 ';
245 }
246 $tCells[] = '<td class="' . $status . ' col-border-left">&nbsp;</td>';
247 $tCells[] = '<td class="' . $status . '">&nbsp;</td>';
248 $tCells[] = '<td class="' . $status . '">' . $info . '</td>';
249 }
250 }
251 }
252 $output .= '
253 <tr>
254 ' . implode('
255 ', $tCells) . '
256 </tr>';
257 }
258 // Put together HEADER:
259 $tCells = [];
260 $tCells[] = '<td>' . $lang->sL('LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_page') . ':</td>';
261 if (is_array($langRecUids[0])) {
262 $editUrl = BackendUtility::getModuleUrl('record_edit', [
263 'edit' => [
264 'pages' => [
265 implode(',', $langRecUids[0]) => 'edit'
266 ]
267 ],
268 'columnsOnly' => 'title,nav_title,l18n_cfg,hidden',
269 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
270 ]);
271 $editIco = '<a href="' . htmlspecialchars($editUrl)
272 . '" class="btn btn-default" title="' . $lang->sL(
273 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editPageProperties'
274 ) . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
275 } else {
276 $editIco = '';
277 }
278 $tCells[] = '<td class="col-border-left" colspan="2">' . $lang->sL(
279 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_default'
280 ) . ':' . $editIco . '</td>';
281 foreach ($languages as $langRow) {
282 if ($this->pObj->MOD_SETTINGS['lang'] == 0 || (int)$this->pObj->MOD_SETTINGS['lang'] === (int)$langRow['uid']) {
283 // Title:
284 $tCells[] = '<td class="col-border-left">' . htmlspecialchars($langRow['title']) . '</td>';
285 // Edit language overlay records:
286 if (is_array($langRecUids[$langRow['uid']])) {
287 $editUrl = BackendUtility::getModuleUrl('record_edit', [
288 'edit' => [
289 'pages_language_overlay' => [
290 implode(',', $langRecUids[$langRow['uid']]) => 'edit'
291 ]
292 ],
293 'columnsOnly' => 'title,nav_title,hidden',
294 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
295 ]);
296 $editButton = '<a href="' . htmlspecialchars($editUrl)
297 . '" class="btn btn-default" title="' . $lang->sL(
298 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editLangOverlays'
299 ) . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
300 } else {
301 $editButton = '';
302 }
303 // Create new overlay records:
304 $params = '&columnsOnly=title,hidden,sys_language_uid&overrideVals[pages_language_overlay][sys_language_uid]=' . $langRow['uid'];
305 $onClick = BackendUtility::editOnClick($params);
306 if (!empty($newOL_js[$langRow['uid']])) {
307 $onClickArray = explode('?', $onClick, 2);
308 $lastElement = array_pop($onClickArray);
309 $onClickArray[] = '\'' . $newOL_js[$langRow['uid']] . ' + \'&' . $lastElement;
310 $onClick = implode('?', $onClickArray);
311 }
312 $newButton = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($onClick)
313 . '" title="' . $lang->sL(
314 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_getlangsta_createNewTranslationHeaders'
315 ) . '">' . $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render() . '</a>';
316
317 $tCells[] = '<td class="btn-group">' . $editButton . $newButton . '</td>';
318 $tCells[] = '<td>&nbsp;</td>';
319 }
320 }
321
322 $output =
323 '<div class="table-fit">' .
324 '<table class="table table-striped table-hover" id="langTable">' .
325 '<thead>' .
326 '<tr>' .
327 implode('', $tCells) .
328 '</tr>' .
329 '</thead>' .
330 '<tbody>' .
331 $output .
332 '</tbody>' .
333 '</table>' .
334 '</div>';
335 return $output;
336 }
337
338 /**
339 * Selects all system languages (from sys_language)
340 *
341 * @return array System language records in an array.
342 */
343 public function getSystemLanguages()
344 {
345 if (!$this->getBackendUser()->user['admin'] && $this->getBackendUser()->groupData['allowed_languages'] !== '') {
346 $allowed_languages = array_flip(explode(',', $this->getBackendUser()->groupData['allowed_languages']));
347 }
348 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
349 ->getQueryBuilderForTable('sys_language');
350 $queryBuilder
351 ->getRestrictions()
352 ->removeAll();
353 $queryBuilder
354 ->select('*')
355 ->from('sys_language')
356 ->orderBy('sorting');
357 $res = $queryBuilder->execute();
358 $outputArray = [];
359 if (is_array($allowed_languages) && !empty($allowed_languages)) {
360 while ($output = $res->fetch()) {
361 if (isset($allowed_languages[$output['uid']])) {
362 $outputArray[] = $output;
363 }
364 }
365 } else {
366 $outputArray = $res->fetchAll();
367 }
368 return $outputArray;
369 }
370
371 /**
372 * Get an alternative language record for a specific page / language
373 *
374 * @param int $pageId Page ID to look up for.
375 * @param int $langId Language UID to select for.
376 * @return array pages_languages_overlay record
377 */
378 public function getLangStatus($pageId, $langId)
379 {
380 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
381 ->getQueryBuilderForTable(static::$pageLanguageOverlayTable);
382 $queryBuilder
383 ->getRestrictions()
384 ->removeAll()
385 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class))
386 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
387 $result = $queryBuilder
388 ->select('*')
389 ->from(static::$pageLanguageOverlayTable)
390 ->where(
391 $queryBuilder->expr()->eq(
392 'pid',
393 $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)
394 )
395 )
396 ->andWhere(
397 $queryBuilder->expr()->eq(
398 'sys_language_uid',
399 $queryBuilder->createNamedParameter($langId, \PDO::PARAM_INT)
400 )
401 )
402 ->execute();
403
404 $row = $result->fetch();
405 BackendUtility::workspaceOL(static::$pageLanguageOverlayTable, $row);
406 if (is_array($row)) {
407 $row['_COUNT'] = $result->rowCount();
408 $row['_HIDDEN'] = $row['hidden'] || (int)$row['endtime'] > 0 && (int)$row['endtime'] < $GLOBALS['EXEC_TIME'] || $GLOBALS['EXEC_TIME'] < (int)$row['starttime'];
409 }
410 $result->closeCursor();
411 return $row;
412 }
413
414 /**
415 * Counting content elements for a single language on a page.
416 *
417 * @param int $pageId Page id to select for.
418 * @param int $sysLang Sys language uid
419 * @return int Number of content elements from the PID where the language is set to a certain value.
420 */
421 public function getContentElementCount($pageId, $sysLang)
422 {
423 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
424 ->getQueryBuilderForTable(static::$pageLanguageOverlayTable);
425 $queryBuilder->getRestrictions()
426 ->removeAll()
427 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
428 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
429 $count = $queryBuilder
430 ->count('uid')
431 ->from('tt_content')
432 ->where(
433 $queryBuilder->expr()->eq(
434 'pid',
435 $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)
436 )
437 )
438 ->andWhere(
439 $queryBuilder->expr()->eq(
440 'sys_language_uid',
441 $queryBuilder->createNamedParameter($sysLang, \PDO::PARAM_INT)
442 )
443 )
444 ->execute()
445 ->fetchColumn(0);
446 return $count ?: '-';
447 }
448
449 /**
450 * Returns LanguageService
451 *
452 * @return \TYPO3\CMS\Core\Localization\LanguageService
453 */
454 protected function getLanguageService()
455 {
456 return $GLOBALS['LANG'];
457 }
458
459 /**
460 * Returns the current BE user.
461 *
462 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
463 */
464 protected function getBackendUser()
465 {
466 return $GLOBALS['BE_USER'];
467 }
468 }