49354d4321af30fead1d643aa943ff7eed9c98b0
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / Controller / TranslationStatusController.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Controller;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Backend\Utility\IconUtility;
19
20 /**
21 * Class for displaying translation status of pages in the tree.
22 *
23 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
24 */
25 class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
26
27 /**
28 * Returns the menu array
29 *
30 * @return array
31 */
32 public function modMenu() {
33 global $LANG;
34 $menuArray = array(
35 'depth' => array(
36 0 => $LANG->getLL('depth_0'),
37 1 => $LANG->getLL('depth_1'),
38 2 => $LANG->getLL('depth_2'),
39 3 => $LANG->getLL('depth_3'),
40 999 => $LANG->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_infi')
41 )
42 );
43 // Languages:
44 $lang = $this->getSystemLanguages();
45 $menuArray['lang'] = array(
46 0 => '[All]'
47 );
48 foreach ($lang as $langRec) {
49 $menuArray['lang'][$langRec['uid']] = $langRec['title'];
50 }
51 return $menuArray;
52 }
53
54 /**
55 * MAIN function for page information of localization
56 *
57 * @return string Output HTML for the module.
58 */
59 public function main() {
60 global $BACK_PATH, $LANG, $SOBE;
61 $theOutput = $this->pObj->doc->header($LANG->sL('LLL:EXT:cms/web_info/locallang.xlf:lang_title'));
62 if ($this->pObj->id) {
63 // Depth selector:
64 $h_func = BackendUtility::getFuncMenu($this->pObj->id, 'SET[depth]', $this->pObj->MOD_SETTINGS['depth'], $this->pObj->MOD_MENU['depth']);
65 $h_func .= BackendUtility::getFuncMenu($this->pObj->id, 'SET[lang]', $this->pObj->MOD_SETTINGS['lang'], $this->pObj->MOD_MENU['lang']);
66 $theOutput .= $h_func;
67 // Add CSH:
68 $theOutput .= BackendUtility::cshItem('_MOD_web_info', 'lang', $GLOBALS['BACK_PATH'], '|<br />');
69 // Showing the tree:
70 // Initialize starting point of page tree:
71 $treeStartingPoint = (int)$this->pObj->id;
72 $treeStartingRecord = BackendUtility::getRecordWSOL('pages', $treeStartingPoint);
73 $depth = $this->pObj->MOD_SETTINGS['depth'];
74 // Initialize tree object:
75 $tree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\View\\PageTreeView');
76 $tree->init('AND ' . $GLOBALS['BE_USER']->getPagePermsClause(1));
77 $tree->addField('l18n_cfg');
78 // Creating top icon; the current page
79 $HTML = IconUtility::getSpriteIconForRecord('pages', $treeStartingRecord);
80 $tree->tree[] = array(
81 'row' => $treeStartingRecord,
82 'HTML' => $HTML
83 );
84 // Create the tree from starting point:
85 if ($depth) {
86 $tree->getTree($treeStartingPoint, $depth, '');
87 }
88 // Render information table:
89 $theOutput .= $this->renderL10nTable($tree);
90 }
91 return $theOutput;
92 }
93
94 /**
95 * Rendering the localization information table.
96 *
97 * @param array $tree The Page tree data
98 * @return string HTML for the localization information table.
99 */
100 public function renderL10nTable(&$tree) {
101 global $LANG;
102 // System languages retrieved:
103 $languages = $this->getSystemLanguages();
104 // Title length:
105 $titleLen = $GLOBALS['BE_USER']->uc['titleLen'];
106 // Put together the TREE:
107 $output = '';
108 $newOL_js = array();
109 $langRecUids = array();
110 foreach ($tree->tree as $data) {
111 $tCells = array();
112 $langRecUids[0][] = $data['row']['uid'];
113 // Page icons / titles etc.
114 $tCells[] = '<td' . ($data['row']['_CSSCLASS'] ? ' class="' . $data['row']['_CSSCLASS'] . '"' : '') . '>' . $data['HTML'] . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($data['row']['title'], $titleLen)) . ((string)$data['row']['nav_title'] !== '' ? ' [Nav: <em>' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($data['row']['nav_title'], $titleLen)) . '</em>]' : '') . '</td>';
115 // DEFAULT language:
116 // "View page" link is created:
117 $viewPageLink = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick(
118 $data['row']['uid'], $GLOBALS['BACK_PATH'], '', '', '', '&L=###LANG_UID###')
119 ) . '" title="' . $LANG->sL('LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_viewPage') . '">' .
120 IconUtility::getSpriteIcon('actions-document-view') . '</a>';
121 $status = $data['row']['l18n_cfg'] & 1 ? 'c-blocked' : 'c-ok';
122 // Create links:
123 $info = '';
124 $editUid = $data['row']['uid'];
125 $params = '&edit[pages][' . $editUid . ']=edit';
126 $info .= '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick(
127 $params, $GLOBALS['BACK_PATH'])
128 ) . '" title="' . $LANG->sL(
129 'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_editDefaultLanguagePage'
130 ) . '">' . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
131 $info .= '<a href="#" onclick="' . htmlspecialchars(
132 'top.loadEditId(' . (int)$data['row']['uid'] . ',"&SET[language]=0"); return false;'
133 ) . '" title="' . $LANG->sL('LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_editPage') . '">' .
134 IconUtility::getSpriteIcon('actions-page-open') . '</a>';
135 $info .= str_replace('###LANG_UID###', '0', $viewPageLink);
136 $info .= '&nbsp;';
137 $info .= $data['row']['l18n_cfg'] & 1 ? '<span title="' . $LANG->sL('LLL:EXT:cms/locallang_tca.xlf:pages.l18n_cfg.I.1', TRUE) . '">D</span>' : '&nbsp;';
138 $info .= \TYPO3\CMS\Core\Utility\GeneralUtility::hideIfNotTranslated($data['row']['l18n_cfg']) ? '<span title="' . $LANG->sL('LLL:EXT:cms/locallang_tca.xlf:pages.l18n_cfg.I.2', TRUE) . '">N</span>' : '&nbsp;';
139 // Put into cell:
140 $tCells[] = '<td class="' . $status . ' c-leftLine">' . $info . '</td>';
141 $tCells[] = '<td class="' . $status . '" title="' . $LANG->sL(
142 'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_CEcount'
143 ) . '" align="center">' . $this->getContentElementCount($data['row']['uid'], 0) . '</td>';
144 $modSharedTSconfig = BackendUtility::getModTSconfig($data['row']['uid'], 'mod.SHARED');
145 $disableLanguages = isset($modSharedTSconfig['properties']['disableLanguages']) ? \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $modSharedTSconfig['properties']['disableLanguages'], TRUE) : array();
146 // Traverse system languages:
147 foreach ($languages as $langRow) {
148 if ($this->pObj->MOD_SETTINGS['lang'] == 0 || (int)$this->pObj->MOD_SETTINGS['lang'] === (int)$langRow['uid']) {
149 $row = $this->getLangStatus($data['row']['uid'], $langRow['uid']);
150 $info = '';
151 if (is_array($row)) {
152 $langRecUids[$langRow['uid']][] = $row['uid'];
153 $status = $row['_HIDDEN'] ? (\TYPO3\CMS\Core\Utility\GeneralUtility::hideIfNotTranslated($data['row']['l18n_cfg']) || $data['row']['l18n_cfg'] & 1 ? 'c-blocked' : 'c-fallback') : 'c-ok';
154 $icon = IconUtility::getSpriteIconForRecord(
155 'pages_language_overlay',
156 $row,
157 array('class' => 'c-recIcon')
158 );
159 $info = $icon . htmlspecialchars(
160 \TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($row['title'], $titleLen)
161 ) . ((string)$row['nav_title'] !== '' ? ' [Nav: <em>' . htmlspecialchars(
162 \TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($row['nav_title'], $titleLen)
163 ) . '</em>]' : '') . ($row['_COUNT'] > 1 ? '<div>' . $LANG->sL(
164 'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_badThingThereAre'
165 ) . '</div>' : '');
166 $tCells[] = '<td class="' . $status . ' c-leftLine">' . $info . '</td>';
167 // Edit whole record:
168 $info = '';
169 $editUid = $row['uid'];
170 $params = '&edit[pages_language_overlay][' . $editUid . ']=edit';
171 $info .= '<a href="#" onclick="' . htmlspecialchars(
172 BackendUtility::editOnClick($params, $GLOBALS['BACK_PATH'])
173 ) . '" title="' . $LANG->sL(
174 'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_editLanguageOverlayRecord'
175 ) . '">' . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
176 $info .= '<a href="#" onclick="' . htmlspecialchars(
177 'top.loadEditId(' . (int)$data['row']['uid'] . ',"&SET[language]=' . $langRow['uid'] . '"); return false;'
178 ) . '" title="' . $LANG->sL(
179 'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_editPageLang'
180 ) . '">' . IconUtility::getSpriteIcon('actions-page-open') . '</a>';
181 $info .= str_replace('###LANG_UID###', $langRow['uid'], $viewPageLink);
182 $tCells[] = '<td class="' . $status . '">' . $info . '</td>';
183 $tCells[] = '<td class="' . $status . '" title="' . $LANG->sL(
184 'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_CEcount'
185 ) . '" align="center">' . $this->getContentElementCount($data['row']['uid'], $langRow['uid']) . '</td>';
186 } else {
187 if (in_array($langRow['uid'], $disableLanguages)) {
188 // Language has been disabled for this page
189 $status = 'c-blocked';
190 $info = '';
191 } else {
192 $status = \TYPO3\CMS\Core\Utility\GeneralUtility::hideIfNotTranslated($data['row']['l18n_cfg']) || $data['row']['l18n_cfg'] & 1 ? 'c-blocked' : 'c-fallback';
193 $info = '<input type="checkbox" name="newOL[' . $langRow['uid'] . '][' . $data['row']['uid'] . ']" value="1" />';
194 $newOL_js[$langRow['uid']] .= '
195 +(document.webinfoForm[\'newOL[' . $langRow['uid'] . '][' . $data['row']['uid'] . ']\'].checked ? \'&edit[pages_language_overlay][' . $data['row']['uid'] . ']=new\' : \'\')
196 ';
197 }
198 $tCells[] = '<td class="' . $status . ' c-leftLine">&nbsp;</td>';
199 $tCells[] = '<td class="' . $status . '">&nbsp;</td>';
200 $tCells[] = '<td class="' . $status . '">' . $info . '</td>';
201 }
202 }
203 }
204 $output .= '
205 <tr class="bgColor4">
206 ' . implode('
207 ', $tCells) . '
208 </tr>';
209 }
210 // Put together HEADER:
211 $tCells = array();
212 $tCells[] = '<td>' . $LANG->sL('LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_page') . ':</td>';
213 if (is_array($langRecUids[0])) {
214 $params = '&edit[pages][' . implode(',', $langRecUids[0]) . ']=edit&columnsOnly=title,nav_title,l18n_cfg,hidden';
215 $editIco = '<a href="#" onclick="' . htmlspecialchars(
216 BackendUtility::editOnClick($params, $GLOBALS['BACK_PATH'])
217 ) . '" title="' . $LANG->sL(
218 'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_editPageProperties'
219 ) . '">' . IconUtility::getSpriteIcon('actions-document-new') . '</a>';
220 } else {
221 $editIco = '';
222 }
223 $tCells[] = '<td class="c-leftLine" colspan="2">' . $LANG->sL(
224 'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_default'
225 ) . ':' . $editIco . '</td>';
226 foreach ($languages as $langRow) {
227 if ($this->pObj->MOD_SETTINGS['lang'] == 0 || (int)$this->pObj->MOD_SETTINGS['lang'] === (int)$langRow['uid']) {
228 // Title:
229 $tCells[] = '<td class="c-leftLine">' . htmlspecialchars($langRow['title']) . '</td>';
230 // Edit language overlay records:
231 if (is_array($langRecUids[$langRow['uid']])) {
232 $params = '&edit[pages_language_overlay][' .
233 implode(',', $langRecUids[$langRow['uid']]) .
234 ']=edit&columnsOnly=title,nav_title,hidden';
235 $tCells[] = '<td><a href="#" onclick="' . htmlspecialchars(
236 BackendUtility::editOnClick($params, $GLOBALS['BACK_PATH'])
237 ) . '" title="' . $LANG->sL(
238 'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_editLangOverlays'
239 ) . '">' . IconUtility::getSpriteIcon('actions-document-open') . '</a></td>';
240 } else {
241 $tCells[] = '<td>&nbsp;</td>';
242 }
243 // Create new overlay records:
244 $params = '\'' .
245 $newOL_js[$langRow['uid']] .
246 '+\'&columnsOnly=title,hidden,sys_language_uid&defVals[pages_language_overlay][sys_language_uid]=' .
247 $langRow['uid'];
248 $tCells[] = '<td><a href="#" onclick="' . htmlspecialchars(
249 BackendUtility::editOnClick($params, $GLOBALS['BACK_PATH'])
250 ) . '" title="' . $LANG->sL(
251 'LLL:EXT:cms/web_info/locallang.xlf:lang_getlangsta_createNewTranslationHeaders'
252 ) . '">' . IconUtility::getSpriteIcon('actions-document-new') . '</a></td>';
253 }
254 }
255
256 $output = '<table id="langTable" class="t3-table">' .
257 '<thead>' .
258 '<tr>' .
259 implode('', $tCells) .
260 '</tr>' .
261 '</thead>' .
262 '<tbody>' .
263 $output .
264 '</tbody>' .
265 '</table>';
266 return $output;
267 }
268
269 /**
270 * Selects all system languages (from sys_language)
271 *
272 * @return array System language records in an array.
273 */
274 public function getSystemLanguages() {
275 if (!$GLOBALS['BE_USER']->user['admin'] && strlen($GLOBALS['BE_USER']->groupData['allowed_languages'])) {
276 $allowed_languages = array_flip(explode(',', $GLOBALS['BE_USER']->groupData['allowed_languages']));
277 }
278 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_language', '1=1' . BackendUtility::deleteClause('sys_language'));
279 $outputArray = array();
280 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
281 if (is_array($allowed_languages) && count($allowed_languages)) {
282 if (isset($allowed_languages[$row['uid']])) {
283 $outputArray[] = $row;
284 }
285 } else {
286 $outputArray[] = $row;
287 }
288 }
289 return $outputArray;
290 }
291
292 /**
293 * Get an alternative language record for a specific page / language
294 *
295 * @param int $pageId Page ID to look up for.
296 * @param int $langId Language UID to select for.
297 * @return array pages_languages_overlay record
298 */
299 public function getLangStatus($pageId, $langId) {
300 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
301 '*',
302 'pages_language_overlay',
303 'pid=' . (int)$pageId .
304 ' AND sys_language_uid=' . (int)$langId .
305 BackendUtility::deleteClause('pages_language_overlay') .
306 BackendUtility::versioningPlaceholderClause('pages_language_overlay')
307 );
308 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
309 BackendUtility::workspaceOL('pages_language_overlay', $row);
310 if (is_array($row)) {
311 $row['_COUNT'] = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
312 $row['_HIDDEN'] = $row['hidden'] || (int)$row['endtime'] > 0 && (int)$row['endtime'] < $GLOBALS['EXEC_TIME'] || $GLOBALS['EXEC_TIME'] < (int)$row['starttime'];
313 }
314 return $row;
315 }
316
317 /**
318 * Counting content elements for a single language on a page.
319 *
320 * @param int $pageId Page id to select for.
321 * @param int $sysLang Sys language uid
322 * @return int Number of content elements from the PID where the language is set to a certain value.
323 */
324 public function getContentElementCount($pageId, $sysLang) {
325 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', 'tt_content', 'pid=' . (int)$pageId . ' AND sys_language_uid=' . (int)$sysLang . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content'));
326 return $count ?: '-';
327 }
328
329 }