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