[TASK] Merge submodule version into core
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / Wizard / RteController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller\Wizard;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 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 use TYPO3\CMS\Backend\Utility\BackendUtility;
31 use TYPO3\CMS\Backend\Utility\IconUtility;
32 use TYPO3\CMS\Core\Utility\GeneralUtility;
33
34 /**
35 * Script Class for rendering the full screen RTE display
36 *
37 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
38 */
39 class RteController {
40
41 // Internal, dynamic:
42 /**
43 * document template object
44 *
45 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
46 * @todo Define visibility
47 */
48 public $doc;
49
50 // Content accumulation for the module.
51 /**
52 * @todo Define visibility
53 */
54 public $content;
55
56 // Internal, static: GPvars
57 // Wizard parameters, coming from TCEforms linking to the wizard.
58 /**
59 * @todo Define visibility
60 */
61 public $P;
62
63 // If set, launch a new window with the current records pid.
64 /**
65 * @todo Define visibility
66 */
67 public $popView;
68
69 // Set to the URL of this script including variables which is needed to re-display the form. See main()
70 /**
71 * @todo Define visibility
72 */
73 public $R_URI;
74
75 /**
76 * Initialization of the class
77 *
78 * @return void
79 * @todo Define visibility
80 */
81 public function init() {
82 // Setting GPvars:
83 $this->P = GeneralUtility::_GP('P');
84 $this->popView = GeneralUtility::_GP('popView');
85 $this->R_URI = GeneralUtility::linkThisScript(array('popView' => ''));
86 // "Module name":
87 $this->MCONF['name'] = 'xMOD_wizard_rte.php';
88 // Starting the document template object:
89 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
90 $this->doc->backPath = $GLOBALS['BACK_PATH'];
91 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/wizard_rte.html');
92 // Need to NOT have the page wrapped in DIV since if we do that we destroy
93 // the feature that the RTE spans the whole height of the page!!!
94 $this->doc->divClass = '';
95 $this->doc->form = '<form action="tce_db.php" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '" name="editform" onsubmit="return TBE_EDITOR.checkSubmit(1);">';
96 }
97
98 /**
99 * Main function, rendering the document with the iframe with the RTE in.
100 *
101 * @return void
102 * @todo Define visibility
103 */
104 public function main() {
105 // Translate id to the workspace version:
106 if ($versionRec = BackendUtility::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $this->P['table'], $this->P['uid'], 'uid')) {
107 $this->P['uid'] = $versionRec['uid'];
108 }
109 // If all parameters are available:
110 if ($this->P['table'] && $this->P['field'] && $this->P['uid'] && $this->checkEditAccess($this->P['table'], $this->P['uid'])) {
111 // Getting the raw record (we need only the pid-value from here...)
112 $rawRec = BackendUtility::getRecord($this->P['table'], $this->P['uid']);
113 BackendUtility::fixVersioningPid($this->P['table'], $rawRec);
114 // Setting JavaScript, including the pid value for viewing:
115 $this->doc->JScode = $this->doc->wrapScriptTags('
116 function jumpToUrl(URL,formEl) { //
117 if (document.editform) {
118 if (!TBE_EDITOR.isFormChanged()) {
119 window.location.href = URL;
120 } else if (formEl) {
121 if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
122 }
123 } else window.location.href = URL;
124 }
125 ' . ($this->popView ? BackendUtility::viewOnClick($rawRec['pid'], '', BackendUtility::BEgetRootLine($rawRec['pid'])) : '') . '
126 ');
127 // Initialize TCeforms - for rendering the field:
128 $tceforms = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\FormEngine');
129 // Init...
130 $tceforms->initDefaultBEMode();
131 // SPECIAL: Disables all wizards - we are NOT going to need them.
132 $tceforms->disableWizards = 1;
133 // SPECIAL: Setting background color of the RTE to ordinary background
134 $tceforms->colorScheme[0] = $this->doc->bgColor;
135 // Initialize style for RTE object:
136 // Getting reference to the RTE object used to render the field!
137 $RTEobj = BackendUtility::RTEgetObj();
138 if ($RTEobj->ID == 'rte') {
139 $RTEobj->RTEdivStyle = 'position:relative; left:0px; top:0px; height:100%; width:100%; border:solid 0px;';
140 }
141 // Fetching content of record:
142 $trData = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\DataPreprocessor');
143 $trData->lockRecords = 1;
144 $trData->fetchRecord($this->P['table'], $this->P['uid'], '');
145 // Getting the processed record content out:
146 $rec = reset($trData->regTableItems_data);
147 $rec['uid'] = $this->P['uid'];
148 $rec['pid'] = $rawRec['pid'];
149 // TSconfig, setting width:
150 $fieldTSConfig = $tceforms->setTSconfig($this->P['table'], $rec, $this->P['field']);
151 if (strcmp($fieldTSConfig['RTEfullScreenWidth'], '')) {
152 $width = $fieldTSConfig['RTEfullScreenWidth'];
153 } else {
154 $width = '100%';
155 }
156 // Get the form field and wrap it in the table with the buttons:
157 $formContent = $tceforms->getSoloField($this->P['table'], $rec, $this->P['field']);
158 $formContent = '
159
160
161 <!--
162 RTE wizard:
163 -->
164 <table border="0" cellpadding="0" cellspacing="0" width="' . $width . '" id="typo3-rtewizard">
165 <tr>
166 <td width="' . $width . '" colspan="2" id="c-formContent">' . $formContent . '</td>
167 <td></td>
168 </tr>
169 </table>';
170 // Adding hidden fields:
171 $formContent .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($this->R_URI) . '" />
172 <input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />' . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction');
173 // Finally, add the whole setup:
174 $this->content .= $tceforms->printNeededJSFunctions_top() . $formContent . $tceforms->printNeededJSFunctions();
175 } else {
176 // ERROR:
177 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('forms_title'), '<span class="typo3-red">' . $GLOBALS['LANG']->getLL('table_noData', 1) . '</span>', 0, 1);
178 }
179 // Setting up the buttons and markers for docheader
180 $docHeaderButtons = $this->getButtons();
181 $markers['CONTENT'] = $this->content;
182 // Build the <body> for the module
183 $this->content = $this->doc->startPage('');
184 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
185 $this->content .= $this->doc->endPage();
186 $this->content = $this->doc->insertStylesAndJS($this->content);
187 }
188
189 /**
190 * Outputting the accumulated content to screen
191 *
192 * @return void
193 * @todo Define visibility
194 */
195 public function printContent() {
196 $this->content .= $this->doc->endPage();
197 $this->content = $this->doc->insertStylesAndJS($this->content);
198 echo $this->content;
199 }
200
201 /**
202 * Create the panel of buttons for submitting the form or otherwise perform operations.
203 *
204 * @return array All available buttons as an assoc. array
205 */
206 protected function getButtons() {
207 $buttons = array(
208 'close' => '',
209 'save' => '',
210 'save_view' => '',
211 'save_close' => '',
212 'shortcut' => '',
213 'undo' => ''
214 );
215 if ($this->P['table'] && $this->P['field'] && $this->P['uid'] && $this->checkEditAccess($this->P['table'], $this->P['uid'])) {
216 $closeUrl = GeneralUtility::sanitizeLocalUrl($this->P['returnUrl']);
217 // Getting settings for the undo button:
218 $undoButton = 0;
219 $undoRes = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tstamp', 'sys_history', 'tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->P['table'], 'sys_history') . ' AND recuid=' . intval($this->P['uid']), '', 'tstamp DESC', '1');
220 if ($undoButtonR = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($undoRes)) {
221 $undoButton = 1;
222 }
223 // Close
224 $buttons['close'] = '<a href="#" onclick="' . htmlspecialchars(('jumpToUrl(unescape(\'' . rawurlencode($closeUrl) . '\')); return false;')) . '">' . '<img' . IconUtility::skinImg($this->doc->backPath, 'gfx/closedok.gif') . ' class="c-inputButton" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', 1) . '" alt="" />' . '</a>';
225 // Save
226 $buttons['save'] = '<a href="#" onclick="TBE_EDITOR.checkAndDoSubmit(1); return false;">' . '<img' . IconUtility::skinImg($this->doc->backPath, 'gfx/savedok.gif') . ' class="c-inputButton" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', 1) . '" alt="" />' . '</a>';
227 // Save & View
228 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('cms')) {
229 $buttons['save_view'] = '<a href="#" onclick="' . htmlspecialchars('document.editform.redirect.value+=\'&popView=1\'; TBE_EDITOR.checkAndDoSubmit(1); return false;') . '">' . '<img' . IconUtility::skinImg($this->doc->backPath, 'gfx/savedokshow.gif') . ' class="c-inputButton" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDocShow', 1) . '" alt="" />' . '</a>';
230 }
231 // Save & Close
232 $buttons['save_close'] = '<input type="image" class="c-inputButton" onclick="' . htmlspecialchars(('document.editform.redirect.value=\'' . $closeUrl . '\'; TBE_EDITOR.checkAndDoSubmit(1); return false;')) . '" name="_saveandclosedok"' . IconUtility::skinImg($this->doc->backPath, 'gfx/saveandclosedok.gif', '') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', 1) . '" />';
233 // Undo/Revert:
234 if ($undoButton) {
235 $buttons['undo'] = '<a href="#" onclick="' . htmlspecialchars(('window.location.href=\'show_rechis.php?element=' . rawurlencode(($this->P['table'] . ':' . $this->P['uid'])) . '&revert=' . rawurlencode(('field:' . $this->P['field'])) . '&sumUp=-1&returnUrl=' . rawurlencode($this->R_URI) . '\'; return false;')) . '">' . '<img' . IconUtility::skinImg($this->doc->backPath, 'gfx/undo.gif') . ' class="c-inputButton" title="' . htmlspecialchars(sprintf($GLOBALS['LANG']->getLL('rte_undoLastChange'), BackendUtility::calcAge(($GLOBALS['EXEC_TIME'] - $undoButtonR['tstamp']), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')))) . '" alt="" />' . '</a>';
236 }
237 // Shortcut
238 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
239 $buttons['shortcut'] = $this->doc->makeShortcutIcon('P', '', $this->MCONF['name'], 1);
240 }
241 }
242 return $buttons;
243 }
244
245 /**
246 * Checks access for element
247 *
248 * @param string $table Table name
249 * @param integer $uid Record uid
250 * @return void
251 * @todo Define visibility
252 */
253 public function checkEditAccess($table, $uid) {
254 $calcPRec = BackendUtility::getRecord($table, $uid);
255 BackendUtility::fixVersioningPid($table, $calcPRec);
256 if (is_array($calcPRec)) {
257 // If pages:
258 if ($table == 'pages') {
259 $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms($calcPRec);
260 $hasAccess = $CALC_PERMS & 2 ? TRUE : FALSE;
261 } else {
262 // Fetching pid-record first.
263 $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms(BackendUtility::getRecord('pages', $calcPRec['pid']));
264 $hasAccess = $CALC_PERMS & 16 ? TRUE : FALSE;
265 }
266 // Check internals regarding access:
267 if ($hasAccess) {
268 $hasAccess = $GLOBALS['BE_USER']->recordEditAccessInternals($table, $calcPRec);
269 }
270 } else {
271 $hasAccess = FALSE;
272 }
273 return $hasAccess;
274 }
275
276 }
277
278 ?>