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