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