Fixed bug #14996: htmlArea RTE: Clicking in drop down boxes should mark text
[Packages/TYPO3.CMS.git] / typo3 / alt_palette.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2010 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 * Displays the secondary-options palette for the TCEFORMs wherever they are shown.
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 formRender extends t3lib_TCEforms
42 * 91: function printPalette($palArr)
43 *
44 *
45 * 154: class formRender_vert extends t3lib_TCEforms
46 * 163: function printPalette($palArr)
47 *
48 *
49 * 223: class SC_alt_palette
50 * 247: function init()
51 * 301: function main()
52 * 341: function printContent()
53 *
54 * TOTAL FUNCTIONS: 5
55 * (This index is automatically created/updated by the extension "extdeveval")
56 *
57 */
58
59
60
61 require('init.php');
62 require('template.php');
63 $LANG->includeLLFile('EXT:lang/locallang_alt_doc.xml');
64
65
66
67
68
69
70 /**
71 * Class for rendering the form fields.
72 * Extending the TCEforms class
73 *
74 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
75 * @package TYPO3
76 * @subpackage core
77 * @deprecated since TYPO3 4.3, will be removed in TYPO3 4.5
78 */
79 class formRender extends t3lib_TCEforms {
80
81 /**
82 * Creates the HTML content for the palette
83 * (Horizontally, for display in the top frame)
84 * (Used if GET var "backRef" IS set)
85 *
86 * @param array Array of information from which the fields are built.
87 * @return string HTML output
88 */
89 function printPalette($palArr) {
90 $out='';
91
92 // For each element on the palette, write a few table cells with the field name, content and control images:
93 foreach($palArr as $content) {
94 $iRow[]='
95 <td>'.
96 '<img name="req_'.$content['TABLE'].'_'.$content['ID'].'_'.$content['FIELD'].'" class="c-reqIcon" src="clear.gif" width="10" height="10" alt="" />'.
97 '<img name="cm_'.$content['TABLE'].'_'.$content['ID'].'_'.$content['FIELD'].'" class="c-cmIcon" src="clear.gif" width="7" height="10" alt="" />'.
98 '</td>
99 <td class="c-label">'.
100 $content['NAME'].'&nbsp;'.
101 '</td>
102 <td class="c-csh">'.
103 $content['ITEM'].$content['HELP_ICON'].
104 '</td>';
105 }
106
107 // Finally, wrap it all in a table:
108 $out='
109
110
111
112 <!--
113 TCEforms palette, rendered in top frame.
114 -->
115 <table border="0" cellpadding="0" cellspacing="0" id="typo3-TCEforms-palette">
116 <tr>
117 <td class="c-close">'.
118 '<a href="#" onclick="closePal();return false;">' . t3lib_iconWorks::getSpriteIcon('actions-document-close', array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.close', TRUE))) . '</a>'.
119 '</td>'.
120 implode('',$iRow).'
121 </tr>
122 </table>
123
124 ';
125
126 // Return the result:
127 return $out;
128 }
129 }
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144 /**
145 * Child class for alternative rendering of form fields (when the secondary fields are shown in a little window rather than the top bar).
146 * (Used if GET var "backRef" is not set, presuming a window is opened instead.)
147 *
148 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
149 * @package TYPO3
150 * @subpackage core
151 */
152 class formRender_vert extends t3lib_TCEforms {
153
154 /**
155 * Creates the HTML content for the palette.
156 * (Vertically, for display in a browser window, not top frame)
157 *
158 * @param array Array of information from which the fields are built.
159 * @return string HTML output
160 */
161 function printPalette($palArr) {
162 $out='';
163 $bgColor=' bgcolor="'.$this->colorScheme[2].'"';
164
165 // For each element on the palette, write a few table cells with the field name, content and control images:
166 foreach($palArr as $content) {
167 $iRow[]='
168 <tr>
169 <td><img src="clear.gif" width="'.intval($this->paletteMargin).'" height="1" alt="" /></td>
170 <td'.$bgColor.'>&nbsp;</td>
171 <td nowrap="nowrap"'.$bgColor.'><font color="'.$this->colorScheme[4].'">'.$content['NAME'].'</font></td>
172 </tr>';
173 $iRow[]='
174 <tr>
175 <td></td>
176 <td valign="top"><img name="req_'.$content['TABLE'].'_'.$content['ID'].'_'.$content['FIELD'].'" src="clear.gif" width="10" height="10" vspace="4" alt="" /><img name="cm_'.$content['TABLE'].'_'.$content['ID'].'_'.$content['FIELD'].'" src="clear.gif" width="7" height="10" vspace="4" alt="" /></td>
177 <td nowrap="nowrap" valign="top">'.$content['ITEM'].$content['HELP_ICON'].'</td>
178 </tr>';
179 }
180
181 // Adding the close button:
182 $iRow[]='
183 <tr>
184 <td></td>
185 <td></td>
186 <td nowrap="nowrap" valign="top">
187 <br />
188 <input type="submit" value="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.close',1).'" onclick="closePal(); return false;" />
189 </td>
190 </tr>';
191
192 // Finally, wrap it all in a table:
193 $out='
194 <table border="0" cellpadding="0" cellspacing="0" id="typo3-TCEforms-palette-vert">
195 '.implode('',$iRow).'
196 </table>';
197
198 // Return content:
199 return $out;
200 }
201 }
202
203
204
205
206
207
208
209
210
211
212
213 /**
214 * Script Class for rendering the palette form for TCEforms in some other frame (in top frame, horizontally)
215 * It can also be called in a pop-up window in which case a vertically oriented set of form fields are rendered instead.
216 *
217 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
218 * @package TYPO3
219 * @subpackage core
220 */
221 class SC_alt_palette {
222
223 // Internal:
224 var $content; // Content accumulation
225 var $backRef; // String, which is the reference back to the window which opened this one.
226 var $formRef; // String, which is the reference to the form.
227 var $doc; // Template object.
228
229 // Internal, static: GPvar:
230 var $formName; // Form name
231 var $GPbackref; // The value of the original backRef GPvar (not necessarily the same as $this->backRef)
232 var $inData; // Contains tablename, uid and palette number
233 var $prependFormFieldNames; // Prefix for form fields.
234 var $rec; // The "record" with the data to display in the form fields.
235
236
237
238
239
240 /**
241 * Constructor for the class
242 *
243 * @return void
244 */
245 function init() {
246
247 // Setting GPvars, etc.
248 $this->formName = $this->sanitizeHtmlName(t3lib_div::_GP('formName'));
249 $this->GPbackref = $this->sanitizeHtmlName(t3lib_div::_GP('backRef'));
250 $this->inData = t3lib_div::_GP('inData');
251 // safeguards the input with whitelisting
252 if (!preg_match('/^[a-zA-Z0-9\-_\:]+$/', $this->inData)) {
253 $this->inData = '';
254 }
255 $this->prependFormFieldNames =
256 $this->sanitizeHtmlName(t3lib_div::_GP('prependFormFieldNames'));
257 $this->rec = t3lib_div::_GP('rec');
258
259 // Making references:
260 $this->backRef = $this->GPbackref ? $this->GPbackref : 'window.opener';
261
262 $this->formRef = $this->backRef.'.document.'.$this->formName;
263
264 // Start template object:
265 $this->doc = t3lib_div::makeInstance('template');
266 $this->doc->bodyTagMargins['x']=0;
267 $this->doc->bodyTagMargins['y']=0;
268 $this->doc->form='<form action="#" method="post" name="'.htmlspecialchars($this->formName).'" onsubmit="return false;">';
269 $this->doc->backPath = '';
270
271 // In case the palette is opened in a SEPARATE window (as the case is with frontend editing) then another body-tag id should be used (so we don't get the background image for the palette shown!)
272 if (!$this->GPbackref) $this->doc->bodyTagId.= '-vert';
273
274 // Setting JavaScript functions for the header:
275 $this->doc->JScode = $this->doc->wrapScriptTags('
276 var serialNumber = "";
277 function timeout_func() { //
278 if ('.$this->backRef.' && '.$this->backRef.'.document && '.$this->formRef.') {
279 if ('.$this->formRef.'["_serialNumber"]) {
280 if (serialNumber) {
281 if ('.$this->formRef.'["_serialNumber"].value != serialNumber) {closePal(); return false;}
282 } else {
283 serialNumber = '.$this->formRef.'["_serialNumber"].value;
284 }
285 }
286 window.setTimeout("timeout_func();",1*1000);
287 } else closePal();
288 }
289 function closePal() { //
290 '.($this->GPbackref?'window.location.href="alt_topmenu_dummy.php";':'close();').'
291 }
292 timeout_func();
293 onBlur="alert();";
294 ');
295 }
296
297 /**
298 * Sanitizes HTML names, IDs, frame names etc.
299 *
300 * @param string $input the string to sanitize
301 *
302 * @return string the unchanged $input if $input is considered to be harmless,
303 * an empty string otherwise
304 */
305 protected function sanitizeHtmlName($input) {
306 $result = $input;
307
308 if (!preg_match('/^[a-zA-Z][a-zA-Z0-9_\-\.]*$/', $result)) {
309 $result = '';
310 }
311
312 return $result;
313 }
314
315 /**
316 * Main function, rendering the palette form
317 *
318 * @return void
319 */
320 function main() {
321
322 $this->content='';
323
324 $inData = explode(':',$this->inData);
325
326 // Begin edit:
327 if (is_array($inData) && count($inData)==3) {
328
329 // Create the TCEforms object:
330 $tceforms = $this->GPbackref ? new formRender() : new formRender_vert();
331 $tceforms->initDefaultBEMode();
332 $tceforms->palFieldTemplate='###FIELD_PALETTE###';
333 $tceforms->palettesCollapsed=0;
334 $tceforms->isPalettedoc=$this->backRef;
335
336 $tceforms->formName = $this->formName;
337 $tceforms->prependFormFieldNames = $this->prependFormFieldNames;
338
339 // Initialize other data:
340 $table=$inData[0];
341 $theUid=$inData[1];
342 $thePalNum = $inData[2];
343 $this->rec['uid']=$theUid;
344
345 // Getting the palette fields rendered:
346 $panel.=$tceforms->getPaletteFields($table,$this->rec,$thePalNum,'',implode(',',array_keys($this->rec)));
347 $formContent=$panel;
348
349 // Add all the content, including JavaScript as needed.
350 $this->content.=$tceforms->printNeededJSFunctions_top().$formContent.$tceforms->printNeededJSFunctions();
351 }
352
353 // Assemble the page:
354 $tempContent = $this->content;
355 $this->content = $this->doc->startPage('TYPO3 Edit Palette');
356 $this->content.= $tempContent;
357 }
358
359 /**
360 * Outputting the accumulated content to screen
361 *
362 * @return void
363 */
364 function printContent() {
365 $this->content.= $this->doc->endPage();
366 $this->content = $this->doc->insertStylesAndJS($this->content);
367 echo $this->content;
368 }
369 }
370
371
372 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_palette.php']) {
373 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_palette.php']);
374 }
375
376
377
378 // Make instance:
379 $SOBE = t3lib_div::makeInstance('SC_alt_palette');
380 $SOBE->init();
381 $SOBE->main();
382 $SOBE->printContent();
383
384 ?>