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