*** empty log message ***
[Packages/TYPO3.CMS.git] / typo3 / wizard_tsconfig.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 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,$propertyVal,$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
158 // Preparing some JavaScript code:
159 if (!is_array($this->P['fieldChangeFunc'])) $this->P['fieldChangeFunc']=array();
160 unset($this->P['fieldChangeFunc']['alert']);
161 reset($this->P['fieldChangeFunc']);
162 $update='';
163 while(list($k,$v)=each($this->P['fieldChangeFunc'])) {
164 $update.= '
165 window.opener.'.$v;
166 }
167
168 // Init the document table object:
169 $this->doc = t3lib_div::makeInstance('mediumDoc');
170 $this->doc->docType = 'xhtml_trans';
171 $this->doc->backPath = $BACK_PATH;
172 $this->doc->form='<form action="" name="editform">';
173
174 // Adding Styles (should go into stylesheet?)
175 $this->doc->inDocStylesArray[] = '
176 A:link {text-decoration: bold; color: '.$this->doc->hoverColor.';}
177 A:visited {text-decoration: bold; color: '.$this->doc->hoverColor.';}
178 A:active {text-decoration: bold; color: '.$this->doc->hoverColor.';}
179 A:hover {color: '.$this->doc->bgColor2.'}
180 ';
181
182 $this->doc->JScode.=$this->doc->wrapScriptTags('
183 function checkReference() { //
184 if (window.opener && window.opener.document && window.opener.document.'.$this->P['formName'].' && window.opener.document.'.$this->P['formName'].'["'.$this->P['itemName'].'"] ) {
185 return window.opener.document.'.$this->P['formName'].'["'.$this->P['itemName'].'"];
186 } else {
187 close();
188 }
189 }
190 function setValue(input) { //
191 var field = checkReference();
192 if (field) {
193 field.value=input+"\n"+field.value;
194 '.$update.'
195 window.opener.focus();
196 }
197 close();
198 }
199 function getValue() { //
200 var field = checkReference();
201 if (field) return field.value;
202 }
203 function mixerField(cmd,objString) { //
204 var temp;
205 switch(cmd) {
206 case "Indent":
207 temp = str_replace("\n","\n ","\n"+document.editform.mixer.value);
208 document.editform.mixer.value = temp.substr(1);
209 break;
210 case "Outdent":
211 temp = str_replace("\n ","\n","\n"+document.editform.mixer.value);
212 document.editform.mixer.value = temp.substr(1);
213 break;
214 case "Transfer":
215 setValue(document.editform.mixer.value);
216 break;
217 case "Wrap":
218 document.editform.mixer.value=objString+" {\n"+document.editform.mixer.value+"\n}";
219 break;
220 }
221 }
222 function str_replace(match,replace,string) { //
223 var input = ""+string;
224 var matchStr = ""+match;
225 if (!matchStr) {return string;}
226 var output = "";
227 var pointer=0;
228 var pos = input.indexOf(matchStr);
229 while (pos!=-1) {
230 output+=""+input.substr(pointer, pos-pointer)+replace;
231 pointer=pos+matchStr.length;
232 pos = input.indexOf(match,pos+1);
233 }
234 output+=""+input.substr(pointer);
235 return output;
236 }
237 function jump(show,objString) { //
238 document.location = "'.t3lib_div::linkThisScript(array('show'=>'','objString'=>'')).'&show="+show+"&objString="+objString;
239 }
240 ');
241
242
243 // Start the page:
244 $this->content.=$this->doc->startPage($LANG->getLL('tsprop'));
245 }
246
247 /**
248 * Main function, rendering the content of the TypoScript property browser, including links to online resources
249 *
250 * @return void
251 */
252 function main() {
253 global $LANG;
254
255 // Adding module content:
256 $this->content.=$this->doc->section($LANG->getLL('tsprop'),$this->browseTSprop($this->mode,$this->show),0,1);
257
258 // Adding link to TSref:
259 if ($this->mode=='tsref') {
260 $this->content.=$this->doc->section($LANG->getLL('tsprop_TSref'),'
261 <a href="'.htmlspecialchars('http://typo3.org/documentation/document-library/doc_core_tsref/').'" target="_blank">'.$LANG->getLL('tsprop_TSref',1).'</a>
262 ',0,1);
263 }
264 // Adding link to admin guides etc:
265 if ($this->mode=='page' || $this->mode=='beuser') {
266 $this->content.=$this->doc->section($LANG->getLL('tsprop_tsconfig'),'
267 <a href="'.htmlspecialchars('http://typo3.org/documentation/document-library/doc_core_tsconfig/').'" target="_blank">'.$LANG->getLL('tsprop_tsconfig',1).'</a>
268 ',0,1);
269 }
270 // Ending page:
271 $this->content.=$this->doc->endPage();
272 }
273
274 /**
275 * Outputting the accumulated content to screen
276 *
277 * @return void
278 */
279 function printContent() {
280 echo $this->content;
281 }
282
283 /**
284 * Create the content of the module:
285 *
286 * @param string Object string
287 * @param integer Pointing to an entry in static_tsconfig_help to show.
288 * @return string HTML
289 */
290 function browseTSprop($mode,$show) {
291 global $LANG;
292
293 // Get object tree:
294 $objTree = $this->getObjTree();
295
296 // Show single element, if show is set.
297 $out='';
298 if ($show) {
299 // Get the entry data:
300 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'static_tsconfig_help', 'uid='.intval($show));
301 $rec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
302 $table = unserialize($rec['appdata']);
303 $obj_string = strtr($this->objString,'()','[]'); // Title:
304
305 // Title and description:
306 $out.='<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('show'=>''))).'" class="typo3-goBack">'.
307 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/goback.gif','width="14" height="14"').' alt="" />'.
308 htmlspecialchars($obj_string).
309 '</a><br />';
310 if ($rec['title']) $out.= '<strong>'.htmlspecialchars($rec['title']).': </strong>';
311 if ($rec['description']) $out.= nl2br(htmlspecialchars(trim($rec['description']))).'<br />';
312
313 // Printing the content:
314 $out.= '<br />'.$this->printTable($table, $obj_string, $objTree[$mode.'.']);
315 $out.='<hr />';
316
317 // Printing the "mixer-field":
318 if (!$this->onlyProperty) {
319 $links=array();
320 $links[]='<a href="#" onclick="mixerField(\'Indent\');return false;">'.$LANG->getLL('tsprop_mixer_indent',1).'</a>';
321 $links[]='<a href="#" onclick="mixerField(\'Outdent\');return false;">'.$LANG->getLL('tsprop_mixer_outdent',1).'</a>';
322 $links[]='<a href="#" onclick="mixerField(\'Wrap\',unescape(\''.rawurlencode($obj_string).'\'));return false;">'.$LANG->getLL('tsprop_mixer_wrap',1).'</a>';
323 $links[]='<a href="#" onclick="mixerField(\'Transfer\');return false;">'.$LANG->getLL('tsprop_mixer_transfer',1).'</a>';
324 $out.='<textarea rows="5" name="mixer" wrap="off"'.$this->doc->formWidthText(48,'','off').'></textarea>';
325 $out.='<br /><strong>'.implode('&nbsp; | &nbsp;',$links).'</strong>';
326 $out.='<hr />';
327 }
328 }
329
330
331 // SECTION: Showing property tree:
332 $tmpl = t3lib_div::makeInstance('ext_TSparser');
333 $tmpl->tt_track = 0; // Do not log time-performance information
334 $tmpl->fixedLgd=0;
335 $tmpl->linkObjects=0;
336 $tmpl->bType='';
337 $tmpl->ext_expandAllNotes=1;
338 $tmpl->ext_noPMicons=1;
339 $tmpl->ext_noSpecialCharsOnLabels=1;
340
341 if (is_array($objTree[$mode.'.'])) {
342 $out.='
343
344
345 <!--
346 TSconfig, object tree:
347 -->
348 <table border="0" cellpadding="0" cellspacing="0" id="typo3-objtree">
349 <tr>
350 <td nowrap="nowrap">'.$tmpl->ext_getObjTree($this->removePointerObjects($objTree[$mode.'.']),'','').'</td>
351 </tr>
352 </table>';
353 }
354
355 return $out;
356 }
357
358
359
360
361
362
363
364 /***************************
365 *
366 * Module functions
367 *
368 ***************************/
369
370 /**
371 * Create object tree from static_tsconfig_help table
372 *
373 * @return array Object tree.
374 * @access private
375 */
376 function getObjTree() {
377 $hash = md5('WIZARD_TSCONFIG-objTree');
378 $objTree=array();
379
380 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,obj_string,title', 'static_tsconfig_help', '');
381 while($rec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
382 $rec['obj_string'] = $this->revertFromSpecialChars($rec['obj_string']);
383 $p = explode(';',$rec['obj_string']);
384 while(list(,$v)=each($p)) {
385 $p2 = t3lib_div::trimExplode(':',$v,1);
386 $subp=t3lib_div::trimExplode('/',$p2[1],1);
387 while(list(,$v2)=each($subp)) {
388 $this->setObj($objTree,explode('.',$p2[0].'.'.$v2),array($rec,$v2));
389 }
390 }
391 }
392 return $objTree;
393 }
394
395 /**
396 * Sets the information from a static_tsconfig_help record in the object array.
397 * Makes recursive calls.
398 *
399 * @param array Object tree array, passed by value!
400 * @param array Array of elements from object path (?)
401 * @param array Array with record and something else (?)
402 * @return void
403 * @access private
404 * @see getObjTree()
405 */
406 function setObj(&$objTree,$strArr,$params) {
407 $key = current($strArr);
408 reset($strArr);
409 if (count($strArr)>1) {
410 array_shift($strArr);
411 if (!isset($objTree[$key.'.'])) $objTree[$key.'.']=array();
412 $this->setObj($objTree[$key.'.'],$strArr,$params);
413 } else {
414 $objTree[$key]=$params;
415 $objTree[$key]['_LINK']=$this->doLink($params);
416 }
417 }
418
419 /**
420 * Converts &gt; and &lt; to > and <
421 *
422 * @param string Input string
423 * @return string Output string
424 * @access private
425 */
426 function revertFromSpecialChars($str) {
427 $str = str_replace('&gt;','>',$str);
428 $str = str_replace('&lt;','<',$str);
429 return $str;
430 }
431
432 /**
433 * Creates a link based on input params array:
434 *
435 * @param array Parameters
436 * @return string The link.
437 * @access private
438 */
439 function doLink($params) {
440 $title = trim($params[0]['title'])?trim($params[0]['title']):'[GO]';
441 $str = $this->linkToObj($title,$params[0]['uid'],$params[1]);
442 return $str;
443 }
444
445 /**
446 * Remove pointer strings from an array
447 *
448 * @param array Input array
449 * @return array Modified input array
450 * @access private
451 */
452 function removePointerObjects($objArray) {
453 reset($objArray);
454 while(list($k)=each($objArray)) {
455 if (substr(trim($k),0,2)=="->" && trim($k)!='->.') {
456 $objArray['->.'][substr(trim($k),2)]=$objArray[$k];
457 unset($objArray[$k]);
458 }
459 }
460 return $objArray;
461 }
462
463 /**
464 * Linking string to object by UID
465 *
466 * @param string String to link
467 * @param integer UID of a static_tsconfig_help record.
468 * @param string Title string for that record!
469 * @return string Linked string
470 */
471 function linkToObj($str,$uid,$objString='') {
472 $aOnClick='jump(\''.rawurlencode($uid).'\',\''.rawurlencode($objString).'\');return false;';
473 return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.htmlspecialchars($str).'</a>';
474 }
475
476 /**
477 * Creates a table of properties:
478 *
479 * @param array Array with properties for the current object path
480 * @param string Object path
481 * @param array Object tree
482 * @return string HTML content.
483 */
484 function printTable($table,$objString,$objTree) {
485 if (is_array($table['rows'])) {
486
487 // Initialize:
488 $lines=array();
489
490 // Adding header:
491 $lines[]='
492 <tr>
493 <td><img src="clear.gif" width="175" height="1" alt="" /></td>
494 <td><img src="clear.gif" width="100" height="1" alt="" /></td>
495 <td><img src="clear.gif" width="400" height="1" alt="" /></td>
496 <td><img src="clear.gif" width="70" height="1" alt="" /></td>
497 </tr>';
498 $lines[]='
499 <tr class="bgColor5">
500 <td><strong>Property:</strong></td>
501 <td><strong>Data type:</strong></td>
502 <td><strong>Description:</strong></td>
503 <td><strong>Default:</strong></td>
504 </tr>';
505
506 // Traverse the content of "rows":
507 foreach($table['rows'] as $row) {
508
509 // Linking:
510 $lP=t3lib_div::trimExplode(chr(10),$row['property'],1);
511 $lP2=array();
512 while(list($k,$lStr)=each($lP)) {
513 $lP2[$k] = $this->linkProperty($lStr,$lStr,$objString,$row['datatype']);
514 }
515 $linkedProperties=implode('<hr />',$lP2);
516
517 // Data type:
518 $dataType = $row['datatype'];
519
520 // Generally "->[something]"
521 $reg=array();
522 ereg('->[[:alnum:]_]*',$dataType,$reg);
523 if ($reg[0] && is_array($objTree[$reg[0]])) {
524 $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);
525 }
526
527 // stdWrap
528 if (!strstr($dataType,'->stdWrap') && strstr(strip_tags($dataType),'stdWrap')) {
529 // 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?
530 $dataType = str_replace('stdWrap','<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('show'=>$objTree['->stdWrap'][0]['uid'],'objString'=>$objString.'.'.$lP[0]))).'">stdWrap</a>',$dataType);
531 }
532
533
534 $lines[]='
535 <tr class="bgColor4">
536 <td valign="top" class="bgColor4-20"><strong>'.$linkedProperties.'</strong></td>
537 <td valign="top">'.nl2br($dataType.'&nbsp;').'</td>
538 <td valign="top">'.nl2br($row['description']).'</td>
539 <td valign="top">'.nl2br($row['default']).'</td>
540 </tr>';
541 }
542 // Return it all:
543 return '
544
545
546
547 <!--
548 TSconfig, attribute selector:
549 -->
550 <table border="0" cellpadding="0" cellspacing="1" width="500" id="typo3-attributes">
551 '.implode('',$lines).'
552 </table>';
553 }
554 }
555
556 /**
557 * Creates a link on a property.
558 *
559 * @param string String to link
560 * @param string Property value.
561 * @param string Object path prefix to value
562 * @param string Data type
563 * @return string Linked $str
564 */
565 function linkProperty($str,$propertyVal,$prefix,$datatype) {
566 $out='';
567
568 // Setting preset value:
569 if (strstr($datatype,'boolean')) {
570 $propertyVal.='=1'; // add preset "=1" to boolean values.
571 } else {
572 $propertyVal.='='; // add preset "="
573 }
574
575 // Adding mixer features; The plus icon:
576 if(!$this->onlyProperty) {
577 $aOnClick = 'document.editform.mixer.value=unescape(\' '.rawurlencode($propertyVal).'\')+\'\n\'+document.editform.mixer.value; return false;';
578 $out.= '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
579 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/plusbullet2.gif','width="18" height="16"').' title="'.$GLOBALS['LANG']->getLL('tsprop_addToList',1).'" align="top" alt="" />'.
580 '</a>';
581 $propertyVal = $prefix.'.'.$propertyVal;
582 }
583
584 // Wrap string:
585 $aOnClick = 'setValue(unescape(\''.rawurlencode($propertyVal).'\')); return false;';
586 $out.= '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$str.'</a>';
587
588 // Return link:
589 return $out;
590 }
591 }
592
593 // Include extension?
594 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_tsconfig.php']) {
595 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_tsconfig.php']);
596 }
597
598
599
600
601
602
603
604
605
606
607
608
609 // Make instance:
610 $SOBE = t3lib_div::makeInstance('SC_wizard_tsconfig');
611 $SOBE->init();
612 $SOBE->main();
613 $SOBE->printContent();
614 ?>