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