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