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