[TASK] Clean up phpDoc comments in typo3/
[Packages/TYPO3.CMS.git] / typo3 / wizard_tsconfig.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 /**
29 * Wizard for inserting TSconfig in form fields. (page,user or TS)
30 *
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 $GLOBALS['BACK_PATH'] = '';
38 require('init.php');
39 require('template.php');
40 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_wizards.xml');
41
42 /**
43 * TypoScript parser extension class.
44 *
45 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
46 * @package TYPO3
47 * @subpackage core
48 */
49 class ext_TSparser extends t3lib_tsparser_ext {
50
51 /**
52 * Pass through of incoming value for link.
53 *
54 * @param array $P P array
55 * @return string The "_LINK" key value, straight away.
56 */
57 function makeHtmlspecialchars($P) {
58 return $P['_LINK'];
59 }
60 }
61
62 /**
63 * Script Class for rendering the TSconfig/TypoScript property browser.
64 *
65 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
66 * @package TYPO3
67 * @subpackage core
68 */
69 class SC_wizard_tsconfig {
70
71 // Internal, dynamic:
72 /**
73 * document template object
74 *
75 * @var mediumDoc
76 */
77 var $doc;
78 // Content accumulation for the module.
79 var $content;
80
81 // Internal, static: GPvars
82 // Wizard parameters, coming from TCEforms linking to the wizard.
83 var $P;
84 // "page", "tsref" or "beuser"
85 var $mode;
86 // Pointing to an entry in static_tsconfig_help to show.
87 var $show;
88 // Object path - for display.
89 var $objString;
90 // If set, the "mixed-field" is not shown and you can select only one property at a time.
91 var $onlyProperty;
92
93 /**
94 * Initialization of the class
95 *
96 * @return void
97 */
98 function init() {
99 // Check if the tsconfig_help extension is loaded - which is mandatory for this wizard to work.
100 t3lib_extMgm::isLoaded('tsconfig_help', 1);
101
102 // Init GPvars:
103 $this->P = t3lib_div::_GP('P');
104 $this->mode = t3lib_div::_GP('mode');
105 $this->show = t3lib_div::_GP('show');
106 $this->objString = t3lib_div::_GP('objString');
107 $this->onlyProperty = t3lib_div::_GP('onlyProperty');
108 // Preparing some JavaScript code:
109 if (!$this->areFieldChangeFunctionsValid()) {
110 $this->P['fieldChangeFunc']=array();
111 }
112 unset($this->P['fieldChangeFunc']['alert']);
113 $update='';
114 foreach ($this->P['fieldChangeFunc'] as $k=>$v) {
115 $update .= '
116 window.opener.'.$v;
117 }
118
119 // Init the document table object:
120 $this->doc = t3lib_div::makeInstance('template');
121 $this->doc->backPath = $GLOBALS['BACK_PATH'];
122 $this->doc->form = '<form action="" name="editform">';
123
124 // Adding Styles (should go into stylesheet?)
125 $this->doc->inDocStylesArray[] = '
126 A:link {text-decoration: bold; color: '.$this->doc->hoverColor.';}
127 A:visited {text-decoration: bold; color: '.$this->doc->hoverColor.';}
128 A:active {text-decoration: bold; color: '.$this->doc->hoverColor.';}
129 A:hover {color: '.$this->doc->bgColor2.'}
130 ';
131
132 $this->doc->JScode.=$this->doc->wrapScriptTags('
133 function checkReference_name() { // Checks if the input field containing the name exists in the document
134 if (window.opener && window.opener.document && window.opener.document.'.$this->P['formName'].' && window.opener.document.'.$this->P['formName'].'["'.$this->P['itemName'].'"] ) {
135 return window.opener.document.'.$this->P['formName'].'["'.$this->P['itemName'].'"];
136 }
137 }
138 function checkReference_value() { // Checks if the input field containing the value exists in the document
139 if (window.opener && window.opener.document && window.opener.document.'.$this->P['formName'].' && window.opener.document.'.$this->P['formName'].'["'.$this->P['itemValue'].'"] ) {
140 return window.opener.document.'.$this->P['formName'].'["'.$this->P['itemValue'].'"];
141 }
142 }
143
144 /**
145 * [Describe function...]
146 *
147 * @param [type] $field,value: ...
148 * @return [type] ...
149 */
150 function setValue(field,value) {
151 var nameField = checkReference_name();
152 var valueField = checkReference_value();
153 if (nameField) {
154 if (valueField) { // This applies to the TS Object Browser module
155 nameField.value=field;
156 valueField.value=value;
157 } else { // This applies to the Info/Modify module and the Page TSconfig field
158 if (value) {
159 nameField.value=field+"="+value+"\n"+nameField.value;
160 } else {
161 nameField.value=field+"\n"+nameField.value;
162 }
163 }
164 '.$update.'
165 window.opener.focus();
166 }
167 close();
168 }
169 function getValue() { // This is never used. Remove it?
170 var field = checkReference_name();
171 if (field) {
172 return field.value;
173 } else {
174 close();
175 }
176 }
177
178 /**
179 * [Describe function...]
180 *
181 * @param [type] $cmd,objString: ...
182 * @return [type] ...
183 */
184 function mixerField(cmd,objString) {
185 var temp;
186 switch(cmd) {
187 case "Indent":
188 temp = str_replace("\n","\n ","\n"+document.editform.mixer.value);
189 document.editform.mixer.value = temp.substr(1);
190 break;
191 case "Outdent":
192 temp = str_replace("\n ","\n","\n"+document.editform.mixer.value);
193 document.editform.mixer.value = temp.substr(1);
194 break;
195 case "Transfer":
196 setValue(document.editform.mixer.value);
197 break;
198 case "Wrap":
199 document.editform.mixer.value=objString+" {\n"+document.editform.mixer.value+"\n}";
200 break;
201 }
202 }
203
204 /**
205 * [Describe function...]
206 *
207 * @param [type] $match,replace,string: ...
208 * @return [type] ...
209 */
210 function str_replace(match,replace,string) {
211 var input = ""+string;
212 var matchStr = ""+match;
213 if (!matchStr) {return string;}
214 var output = "";
215 var pointer=0;
216 var pos = input.indexOf(matchStr);
217 while (pos!=-1) {
218 output+=""+input.substr(pointer, pos-pointer)+replace;
219 pointer=pos+matchStr.length;
220 pos = input.indexOf(match, pos+1);
221 }
222 output+=""+input.substr(pointer);
223 return output;
224 }
225
226 /**
227 * [Describe function...]
228 *
229 * @param [type] $show,objString: ...
230 * @return [type] ...
231 */
232 function jump(show, objString) {
233 window.location.href = "'.t3lib_div::linkThisScript(array('show'=>'', 'objString'=>'')).'&show="+show+"&objString="+objString;
234 }
235 ');
236
237
238 // Start the page:
239 $this->content .= $this->doc->startPage($GLOBALS['LANG']->getLL('tsprop'));
240 }
241
242 /**
243 * Main function, rendering the content of the TypoScript property browser, including links to online resources
244 *
245 * @return void
246 */
247 function main() {
248 // Adding module content:
249 $this->content.=$this->doc->section($GLOBALS['LANG']->getLL('tsprop'), $this->browseTSprop($this->mode, $this->show), 0, 1);
250
251 // Adding link to TSref:
252 if ($this->mode == 'tsref') {
253 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('tsprop_TSref'), '
254 <a href="' . TYPO3_URL_DOCUMENTATION_TSREF . '" target="_blank">' . $GLOBALS['LANG']->getLL('tsprop_TSref', 1) . '</a>
255 ', 0, 1);
256 }
257 // Adding link to admin guides etc:
258 if ($this->mode == 'page' || $this->mode == 'beuser') {
259 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('tsprop_tsconfig'), '
260 <a href="' . TYPO3_URL_DOCUMENTATION_TSCONFIG . '" target="_blank">' . $GLOBALS['LANG']->getLL('tsprop_tsconfig', 1) . '</a>
261 ', 0, 1);
262 }
263 }
264
265 /**
266 * Outputting the accumulated content to screen
267 *
268 * @return void
269 */
270 function printContent() {
271 $this->content .= $this->doc->endPage();
272 $this->content = $this->doc->insertStylesAndJS($this->content);
273 echo $this->content;
274 }
275
276 /**
277 * Create the content of the module:
278 *
279 * @param string $mode Object string
280 * @param integer $show Pointing to an entry in static_tsconfig_help to show.
281 * @return string HTML
282 */
283 function browseTSprop($mode, $show) {
284 // Get object tree:
285 $objTree = $this->getObjTree();
286
287 // Show single element, if show is set.
288 $out = '';
289 if ($show) {
290 // Get the entry data:
291 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'static_tsconfig_help', 'uid='.intval($show));
292 $rec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
293 $table = unserialize($rec['appdata']);
294 // Title:
295 $obj_string = strtr($this->objString, '()', '[]');
296
297 // Title and description:
298 $out .= '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('show'=>''))).'" class="typo3-goBack">'.
299 t3lib_iconWorks::getSpriteIcon('actions-view-go-back') .
300 htmlspecialchars($obj_string).
301 '</a><br />';
302 if ($rec['title']) $out .= '<strong>'.htmlspecialchars($rec['title']).': </strong>';
303 if ($rec['description']) $out .= nl2br(htmlspecialchars(trim($rec['description']))).'<br />';
304
305 // Printing the content:
306 $out .= '<br />'.$this->printTable($table, $obj_string, $objTree[$mode.'.']);
307 $out .='<hr />';
308
309 // Printing the "mixer-field":
310 if (!$this->onlyProperty) {
311 $links = array();
312 $links[] = '<a href="#" onclick="mixerField(\'Indent\');return false;">'.$GLOBALS['LANG']->getLL('tsprop_mixer_indent', 1).'</a>';
313 $links[] = '<a href="#" onclick="mixerField(\'Outdent\');return false;">'.$GLOBALS['LANG']->getLL('tsprop_mixer_outdent', 1).'</a>';
314 $links[] = '<a href="#" onclick="mixerField(\'Wrap\',unescape(\''.rawurlencode($obj_string).'\'));return false;">'.$GLOBALS['LANG']->getLL('tsprop_mixer_wrap', 1).'</a>';
315 $links[] = '<a href="#" onclick="mixerField(\'Transfer\');return false;">'.$GLOBALS['LANG']->getLL('tsprop_mixer_transfer', 1).'</a>';
316 $out .= '<textarea rows="5" name="mixer" wrap="off"'.$this->doc->formWidthText(48, '', 'off').' class="fixed-font enable-tab"></textarea>';
317 $out .= '<br /><strong>'.implode('&nbsp; | &nbsp;', $links).'</strong>';
318 $out .= '<hr />';
319 }
320 }
321
322
323 // SECTION: Showing property tree:
324 $tmpl = t3lib_div::makeInstance('ext_TSparser');
325 // Do not log time-performance information
326 $tmpl->tt_track = 0;
327 $tmpl->fixedLgd = 0;
328 $tmpl->linkObjects = 0;
329 $tmpl->bType = '';
330 $tmpl->ext_expandAllNotes = 1;
331 $tmpl->ext_noPMicons = 1;
332 $tmpl->ext_noSpecialCharsOnLabels = 1;
333
334 if (is_array($objTree[$mode.'.'])) {
335 $out .= '
336
337
338 <!--
339 TSconfig, object tree:
340 -->
341 <table border="0" cellpadding="0" cellspacing="0" class="t3-tree t3-tree-config" id="typo3-objtree">
342 <tr class="t3-row-header"><td>TSref</td></tr>
343 <tr>
344 <td nowrap="nowrap">'.$tmpl->ext_getObjTree($this->removePointerObjects($objTree[$mode.'.']), '', '', '', '', '1').'</td>
345 </tr>
346 </table>';
347 }
348
349 return $out;
350 }
351
352 /***************************
353 *
354 * Module functions
355 *
356 ***************************/
357
358 /**
359 * Create object tree from static_tsconfig_help table
360 *
361 * @return array Object tree.
362 * @access private
363 */
364 function getObjTree() {
365 $objTree = array();
366
367 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,obj_string,title', 'static_tsconfig_help', '');
368 while ($rec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
369 $rec['obj_string'] = $this->revertFromSpecialChars($rec['obj_string']);
370 $p = explode(';', $rec['obj_string']);
371 foreach ($p as $v) {
372 $p2 = t3lib_div::trimExplode(':', $v, 1);
373 $subp = t3lib_div::trimExplode('/', $p2[1], 1);
374 foreach ($subp as $v2) {
375 $this->setObj($objTree, explode('.', $p2[0].'.'.$v2), array($rec, $v2));
376 }
377 }
378 }
379 return $objTree;
380 }
381
382 /**
383 * Sets the information from a static_tsconfig_help record in the object array.
384 * Makes recursive calls.
385 *
386 * @param array $objTree Object tree array, passed by value!
387 * @param array $strArr Array of elements from object path (?)
388 * @param array $params Array with record and something else (?)
389 * @return void
390 * @access private
391 * @see getObjTree()
392 */
393 function setObj(&$objTree, $strArr, $params) {
394 $key = current($strArr);
395 reset($strArr);
396 if (count($strArr) > 1) {
397 array_shift($strArr);
398 if (!isset($objTree[$key.'.'])) $objTree[$key.'.'] = array();
399 $this->setObj($objTree[$key.'.'], $strArr, $params);
400 } else {
401 $objTree[$key]=$params;
402 $objTree[$key]['_LINK']=$this->doLink($params);
403 }
404 }
405
406 /**
407 * Converts &gt; and &lt; to > and <
408 *
409 * @param string $str Input string
410 * @return string Output string
411 * @access private
412 */
413 function revertFromSpecialChars($str) {
414 $str = str_replace('&gt;', '>', $str);
415 $str = str_replace('&lt;', '<', $str);
416 return $str;
417 }
418
419 /**
420 * Creates a link based on input params array:
421 *
422 * @param array $params Parameters
423 * @return string The link.
424 * @access private
425 */
426 function doLink($params) {
427 $title = trim($params[0]['title'])?trim($params[0]['title']):'[GO]';
428 $str = $this->linkToObj($title, $params[0]['uid'], $params[1]);
429 return $str;
430 }
431
432 /**
433 * Remove pointer strings from an array
434 *
435 * @param array $objArray Input array
436 * @return array Modified input array
437 * @access private
438 */
439 function removePointerObjects($objArray) {
440 foreach ($objArray as $k => $value) {
441 if (substr(trim($k), 0, 2) == '->' && trim($k) != '->.') {
442 $objArray['->.'][substr(trim($k), 2)]=$objArray[$k];
443 unset($objArray[$k]);
444 }
445 }
446 return $objArray;
447 }
448
449 /**
450 * Linking string to object by UID
451 *
452 * @param string $str String to link
453 * @param integer $uid UID of a static_tsconfig_help record.
454 * @param string $objString Title string for that record!
455 * @return string Linked string
456 */
457 function linkToObj($str, $uid, $objString = '') {
458 $aOnClick = 'jump(\''.rawurlencode($uid).'\',\''.rawurlencode($objString).'\');return false;';
459 return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.htmlspecialchars($str).'</a>';
460 }
461
462 /**
463 * Creates a table of properties:
464 *
465 * @param array $table Array with properties for the current object path
466 * @param string $objString Object path
467 * @param array $objTree Object tree
468 * @return string HTML content.
469 */
470 function printTable($table, $objString, $objTree) {
471 if (is_array($table['rows'])) {
472
473 // Initialize:
474 $lines = array();
475
476 // Adding header:
477 $lines[] = '
478 <tr class="t3-row-header">
479 <td>Property:</td>
480 <td>Data type:</td>
481 <td>Description:</td>
482 <td>Default:</td>
483 </tr>';
484
485 // Traverse the content of "rows":
486 foreach ($table['rows'] as $i => $row) {
487
488 // Linking:
489 $lP = t3lib_div::trimExplode(LF, $row['property'], 1);
490 $lP2 = array();
491 foreach ($lP as $k => $lStr) {
492 $lP2[$k] = $this->linkProperty($lStr, $lStr, $objString, $row['datatype']);
493 }
494 $linkedProperties = implode('<hr />', $lP2);
495
496 // Data type:
497 $dataType = $row['datatype'];
498
499 // Generally "->[something]"
500 $reg = array();
501 preg_match('/->[[:alnum:]_]*/', $dataType, $reg);
502 if ($reg[0] && is_array($objTree[$reg[0]])) {
503 $dataType = str_replace($reg[0], '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('show' => $objTree[$reg[0]][0]['uid'], 'objString' => $objString . '.' . $lP[0]))) . '">' . htmlspecialchars($reg[0]) . '</a>', $dataType);
504 }
505
506 // stdWrap
507 if (!strstr($dataType, '->stdWrap') && strstr(strip_tags($dataType), 'stdWrap')) {
508 // Potential problem can be that "stdWrap" is substituted inside another A-tag. So maybe we should even check if there is already a <A>-tag present and if so, not make a substitution?
509 $dataType = str_replace('stdWrap', '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('show'=>$objTree['->stdWrap'][0]['uid'], 'objString'=>$objString.'.'.$lP[0]))).'">stdWrap</a>', $dataType);
510 }
511
512 $lines[] = '
513 <tr class="t3-row ' . ($i % 2 ? 't3-row-even' : 't3-row-odd') . '">
514 <td valign="top" class="bgColor4-20" nowrap="nowrap"><strong>'.$linkedProperties.'</strong></td>
515 <td valign="top">'.nl2br($dataType.'&nbsp;').'</td>
516 <td valign="top">'.nl2br($row['description']).'</td>
517 <td valign="top">'.nl2br($row['default']).'</td>
518 </tr>';
519 }
520 // Return it all:
521 return '
522
523
524
525 <!--
526 TSconfig, attribute selector:
527 -->
528 <table border="0" cellpadding="0" cellspacing="1" width="98%" class="t3-table" id="typo3-attributes">
529 '.implode('', $lines).'
530 </table>';
531 }
532 }
533
534 /**
535 * Creates a link on a property.
536 *
537 * @param string $str String to link
538 * @param string $propertyName Property value.
539 * @param string $prefix Object path prefix to value
540 * @param string $datatype Data type
541 * @return string Linked $str
542 */
543 function linkProperty($str, $propertyName, $prefix, $datatype) {
544 $out = '';
545
546 // Setting preset value:
547 if (strstr($datatype, 'boolean')) {
548 // preset "1" to boolean values.
549 $propertyVal = '1';
550 }
551
552 // Adding mixer features; The plus icon:
553 if (!$this->onlyProperty) {
554 $aOnClick = 'document.editform.mixer.value=unescape(\' '.rawurlencode($propertyName.'='.$propertyVal).'\')+\'\n\'+document.editform.mixer.value; return false;';
555 $out .= '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
556 t3lib_iconWorks::getSpriteIcon('actions-edit-add', array('title' => $GLOBALS['LANG']->getLL('tsprop_addToList', TRUE))) .
557 '</a>';
558 $propertyName = $prefix.'.'.$propertyName;
559 }
560
561 // Wrap string:
562 $aOnClick = 'setValue(unescape(\''.rawurlencode($propertyName).'\'), unescape(\''.rawurlencode($propertyVal).'\')); return false;';
563 $out .= '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$str.'</a>';
564
565 // Return link:
566 return $out;
567 }
568
569 /**
570 * Determines whether submitted field change functions are valid
571 * and are coming from the system and not from an external abuse.
572 *
573 * @return boolean Whether the submitted field change functions are valid
574 */
575 protected function areFieldChangeFunctionsValid() {
576 return (
577 isset($this->P['fieldChangeFunc']) && is_array($this->P['fieldChangeFunc']) && isset($this->P['fieldChangeFuncHash'])
578 && $this->P['fieldChangeFuncHash'] === t3lib_div::hmac(serialize($this->P['fieldChangeFunc']))
579 );
580 }
581 }
582
583 // Make instance:
584 $SOBE = t3lib_div::makeInstance('SC_wizard_tsconfig');
585 $SOBE->init();
586 $SOBE->main();
587 $SOBE->printContent();
588
589 ?>