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