Fixed a problem with the RTE
[Packages/TYPO3.CMS.git] / typo3 / wizard_rte.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skaarhoj (kasper@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 * $Id$
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
32 * XHTML compliant
33 *
34 * @author Kasper Skaarhoj <kasper@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 80: class SC_wizard_rte
42 * 98: function init()
43 * 122: function main()
44 * 273: function printContent()
45 *
46 * TOTAL FUNCTIONS: 3
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 include ('sysext/lang/locallang_wizards.php');
57 require_once (PATH_t3lib.'class.t3lib_tceforms.php');
58 require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
59 require_once (PATH_t3lib.'class.t3lib_transferdata.php');
60
61 t3lib_BEfunc::lockRecords();
62
63
64
65
66
67
68
69
70
71
72
73 /**
74 * Script Class for rendering the full screen RTE display
75 *
76 * @author Kasper Skaarhoj <kasper@typo3.com>
77 * @package TYPO3
78 * @subpackage core
79 */
80 class SC_wizard_rte {
81
82 // Internal, dynamic:
83 var $doc; // Document template object
84 var $content; // Content accumulation for the module.
85
86 // Internal, static: GPvars
87 var $P; // Wizard parameters, coming from TCEforms linking to the wizard.
88 var $popView; // If set, launch a new window with the current records pid.
89
90
91
92
93 /**
94 * Initialization of the class
95 *
96 * @return void
97 */
98 function init() {
99 global $BACK_PATH;
100
101 // Setting GPvars:
102 $this->P = t3lib_div::GPvar('P',1);
103 $this->popView = t3lib_div::GPVar('popView');
104
105 // "Module name":
106 $this->MCONF['name']='xMOD_wizard_rte.php';
107
108 // Starting the document template object:
109 $this->doc = t3lib_div::makeInstance('mediumDoc');
110 $this->doc->docType = 'xhtml_trans';
111 $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!!!
112 $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);">';
113 $this->doc->backPath = $BACK_PATH;
114
115 }
116
117 /**
118 * Main function, rendering the document with the iframe with the RTE in.
119 *
120 * @return void
121 */
122 function main() {
123 global $BE_USER,$LANG;
124
125 // If all parameters are available:
126 if ($this->P['table'] && $this->P['field'] && $this->P['uid']) {
127
128 // Getting the raw record (we need only the pid-value from here...)
129 $rawRec = t3lib_BEfunc::getRecord($this->P['table'],$this->P['uid']);
130
131 // Setting JavaScript, including the pid value for viewing:
132 $this->doc->JScode = $this->doc->wrapScriptTags('
133 function jumpToUrl(URL,formEl) { //
134 if (document.editform) {
135 if (!TBE_EDITOR_isFormChanged()) {
136 document.location = URL;
137 } else if (formEl) {
138 if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
139 }
140 } else document.location = URL;
141 }
142 '.($this->popView ? t3lib_BEfunc::viewOnClick($rawRec['pid'],'',t3lib_BEfunc::BEgetRootLine($rawRec['pid'])) : '').'
143 ');
144
145 // Create page HTML header:
146 $this->content.=$this->doc->startPage('');
147
148
149 // Initialize TCeforms - for rendering the field:
150 $tceforms = t3lib_div::makeInstance('t3lib_TCEforms');
151 $tceforms->initDefaultBEMode(); // Init...
152 $tceforms->disableWizards = 1; // SPECIAL: Disables all wizards - we are NOT going to need them.
153 # $tceforms->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
154 $tceforms->RTEdivStyle = 'position:relative; left:0px; top:0px; height:600px; width:100%; border:solid 0px;'; // SPECIAL: Setting style for the RTE <DIV> layer containing the IFRAME
155 $tceforms->colorScheme[0]=$this->doc->bgColor; // SPECIAL: Setting background color of the RTE to ordinary background
156
157 // Fetching content of record:
158 $trData = t3lib_div::makeInstance('t3lib_transferData');
159 $trData->lockRecords=1;
160 $trData->fetchRecord($this->P['table'],$this->P['uid'],'');
161
162 // Getting the processed record content out:
163 reset($trData->regTableItems_data);
164 $rec = current($trData->regTableItems_data);
165 $rec['uid'] = $this->P['uid'];
166 $rec['pid'] = $rawRec['pid'];
167
168 // Making the toolbar:
169 $closeUrl = $this->P['returnUrl'];
170 $R_URI=t3lib_div::linkThisScript(array('popView'=>''));
171
172 // Getting settings for the undo button:
173 $undoButton=0;
174 $undoQuery='SELECT tstamp FROM sys_history WHERE tablename="'.addslashes($this->P['table']).'" AND recuid="'.addslashes($this->P['uid']).'" ORDER BY tstamp DESC LIMIT 1';
175 $undoRes = mysql(TYPO3_db,$undoQuery);
176 if ($undoButtonR = mysql_fetch_assoc($undoRes)) {
177 $undoButton=1;
178 }
179
180 // ShortCut
181 if ($BE_USER->mayMakeShortcut()) {
182 $sCut = $this->doc->makeShortcutIcon('P','',$this->MCONF['name'],1);
183 } else {
184 $sCut ='';
185 }
186
187
188 // Make Toolbar of buttons:
189 $toolBarButtons=array();
190
191 // Save:
192 $toolBarButtons[]=
193 '<a href="#" onclick="TBE_EDITOR_checkAndDoSubmit(1); return false;">'.
194 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/savedok.gif','width="21" height="16"').' class="c-inputButton" title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc',1).'" alt="" />'.
195 '</a>';
196
197 // Save/View:
198 if (t3lib_extMgm::isLoaded('cms')) {
199 $toolBarButtons[]=
200 '<a href="#" onclick="'.htmlspecialchars('document.editform.redirect.value+=\'&popView=1\'; TBE_EDITOR_checkAndDoSubmit(1); return false;').'">'.
201 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/savedokshow.gif','width="21" height="16"').' class="c-inputButton" title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveDocShow',1).'" alt="" />'.
202 '</a>';
203 }
204 // Close:
205 $toolBarButtons[]=
206 '<a href="#" onclick="'.htmlspecialchars('jumpToUrl(unescape(\''.rawurlencode($closeUrl).'\')); return false;').'">'.
207 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/closedok.gif','width="21" height="16"').' class="c-inputButton" title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc',1).'" alt="" />'.
208 '</a>';
209
210 // Undo/Revert:
211 if ($undoButton) {
212 $toolBarButtons[]=
213 '<a href="#" onclick="'.htmlspecialchars('document.location=\'show_rechis.php?element='.rawurlencode($this->P['table'].':'.$this->P['uid']).'&revert='.rawurlencode('field:'.$this->P['field']).'&sumUp=-1&returnUrl='.rawurlencode($R_URI).'\'; return false;').'">'.
214 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/undo.gif','width="21" height="16"').' class="c-inputButton" title="'.htmlspecialchars(sprintf($LANG->getLL('rte_undoLastChange'),t3lib_BEfunc::calcAge(time()-$undoButtonR['tstamp'],$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')))).'" alt="" />'.
215 '</a>';
216 }
217
218 $panel = '<span class="c-saveButtons">'.implode('',$toolBarButtons).'</span>';
219
220
221 // TSconfig, setting width:
222 $fieldTSConfig = $tceforms->setTSconfig($this->P['table'],$rec,$this->P['field']);
223 if (strcmp($fieldTSConfig['RTEfullScreenWidth'],'')) {
224 $width=$fieldTSConfig['RTEfullScreenWidth'];
225 } else {
226 $width='500';
227 }
228
229 // Get the form field and wrap it in the table with the buttons:
230 $formContent = $tceforms->getSoloField($this->P['table'],$rec,$this->P['field']);
231 $formContent = '
232
233
234 <!--
235 RTE wizard:
236 -->
237 <table border="0" cellpadding="0" cellspacing="0" width="'.$width.'" height="98%" id="typo3-rtewizard">
238 <tr>
239 <td>'.$panel.'</td>
240 <td align="right">'.$sCut.'</td>
241 <td></td>
242 </tr>
243 <tr height="98%">
244 <td width="'.$width.'" colspan="2">'.$formContent.'</td>
245 <td></td>
246 </tr>
247 </table>';
248
249 // Adding hidden fields:
250 $formContent.= '<input type="hidden" name="redirect" value="'.htmlspecialchars($R_URI).'" />
251 <input type="hidden" name="_serialNumber" value="'.md5(microtime()).'" />';
252
253
254 // Finally, add the whole setup:
255 $this->content.=
256 $tceforms->printNeededJSFunctions_top().
257 $formContent.
258 $tceforms->printNeededJSFunctions();
259 } else {
260 // ERROR:
261 $this->content.=$this->doc->startPage('');
262 $this->content.=$this->doc->section($LANG->getLL('forms_title'),'<span class="typo3-red">'.$LANG->getLL('table_noData',1).'</span>',0,1);
263 }
264
265 // Ending page:
266 $this->content.=$this->doc->endPage();
267 }
268
269 /**
270 * Outputting the accumulated content to screen
271 *
272 * @return void
273 */
274 function printContent() {
275 echo $this->content;
276 }
277 }
278
279 // Include extension?
280 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_rte.php']) {
281 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_rte.php']);
282 }
283
284
285
286
287
288
289
290
291
292
293
294
295 // Make instance:
296 $SOBE = t3lib_div::makeInstance('SC_wizard_rte');
297 $SOBE->init();
298 $SOBE->main();
299 $SOBE->printContent();
300 ?>