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