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