Tons of changes made to the CORE. All scripts has more a less been modified. Primaril...
[Packages/TYPO3.CMS.git] / typo3 / wizard_tsconfig.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skaarhoj (kasper@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 <kasper@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 94: class ext_TSparser extends t3lib_tsparser_ext
42 * 100: function makeHtmlspecialchars($P)
43 *
44 *
45 * 121: class SC_wizard_tsconfig
46 * 143: function init()
47 * 250: function main()
48 * 277: function printContent()
49 * 288: function browseTSprop($mode,$show)
50 *
51 * SECTION: Module functions
52 * 375: 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 include ('sysext/lang/locallang_wizards.php');
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 <kasper@typo3.com>
91 * @package TYPO3
92 * @subpackage core
93 */
94 class ext_TSparser extends t3lib_tsparser_ext {
95
96 /**
97 * @param array P array
98 * @return string The "_LINK" key value, straight away.
99 */
100 function makeHtmlspecialchars($P) {
101 return $P['_LINK'];
102 }
103 }
104
105
106
107
108
109
110
111
112
113
114 /**
115 * Script Class for rendering the TSconfig/TypoScript property browser.
116 *
117 * @author Kasper Skaarhoj <kasper@typo3.com>
118 * @package TYPO3
119 * @subpackage core
120 */
121 class SC_wizard_tsconfig {
122
123 // Internal, dynamic:
124 var $doc; // Document template object
125 var $content; // Content accumulation for the module.
126
127 // Internal, static: GPvars
128 var $P; // Wizard parameters, coming from TCEforms linking to the wizard.
129 var $mode; // "page", "tsref" or "beuser"
130 var $show; // Pointing to an entry in static_tsconfig_help to show.
131 var $objString; // Object path - for display.
132 var $onlyProperty; // If set, the "mixed-field" is not shown and you can select only one property at a time.
133
134
135
136
137
138 /**
139 * Initialization of the class
140 *
141 * @return void
142 */
143 function init() {
144 global $LANG,$BACK_PATH;
145
146 // Check if the tsconfig_help extension is loaded - which is mandatory for this wizard to work.
147 t3lib_extMgm::isLoaded('tsconfig_help',1);
148
149 // Init GPvars:
150 $this->P = t3lib_div::GPvar('P',1);
151 $this->mode = t3lib_div::GPvar('mode');
152 $this->show = t3lib_div::GPvar('show');
153 $this->objString = t3lib_div::GPvar('objString');
154 $this->onlyProperty = t3lib_div::GPvar('onlyProperty');
155
156 // Preparing some JavaScript code:
157 if (!is_array($this->P['fieldChangeFunc'])) $this->P['fieldChangeFunc']=array();
158 unset($this->P['fieldChangeFunc']['alert']);
159 reset($this->P['fieldChangeFunc']);
160 $update='';
161 while(list($k,$v)=each($this->P['fieldChangeFunc'])) {
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() { //
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 } else {
185 close();
186 }
187 }
188 function setValue(input) { //
189 var field = checkReference();
190 if (field) {
191 field.value=input+"\n"+field.value;
192 '.$update.'
193 window.opener.focus();
194 }
195 close();
196 }
197 function getValue() { //
198 var field = checkReference();
199 if (field) return field.value;
200 }
201 function mixerField(cmd,objString) { //
202 var temp;
203 switch(cmd) {
204 case "Indent":
205 temp = str_replace("\n","\n ","\n"+document.editform.mixer.value);
206 document.editform.mixer.value = temp.substr(1);
207 break;
208 case "Outdent":
209 temp = str_replace("\n ","\n","\n"+document.editform.mixer.value);
210 document.editform.mixer.value = temp.substr(1);
211 break;
212 case "Transfer":
213 setValue(document.editform.mixer.value);
214 break;
215 case "Wrap":
216 document.editform.mixer.value=objString+" {\n"+document.editform.mixer.value+"\n}";
217 break;
218 }
219 }
220 function str_replace(match,replace,string) { //
221 var input = ""+string;
222 var matchStr = ""+match;
223 if (!matchStr) {return string;}
224 var output = "";
225 var pointer=0;
226 var pos = input.indexOf(matchStr);
227 while (pos!=-1) {
228 output+=""+input.substr(pointer, pos-pointer)+replace;
229 pointer=pos+matchStr.length;
230 pos = input.indexOf(match,pos+1);
231 }
232 output+=""+input.substr(pointer);
233 return output;
234 }
235 function jump(show,objString) { //
236 document.location = "'.t3lib_div::linkThisScript(array('show'=>'','objString'=>'')).'&show="+show+"&objString="+objString;
237 }
238 ');
239
240
241 // Start the page:
242 $this->content.=$this->doc->startPage($LANG->getLL('tsprop'));
243 }
244
245 /**
246 * Main function, rendering the content of the TypoScript property browser, including links to online resources
247 *
248 * @return void
249 */
250 function main() {
251 global $LANG;
252
253 // Adding module content:
254 $this->content.=$this->doc->section($LANG->getLL('tsprop'),$this->browseTSprop($this->mode,$this->show),0,1);
255
256 // Adding link to TSref:
257 if ($this->mode=='tsref') {
258 $this->content.=$this->doc->section($LANG->getLL('tsprop_TSref'),'
259 <a href="'.htmlspecialchars('http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&cHash=4ad9d7acb4').'" target="_blank">'.$LANG->getLL('tsprop_TSref',1).'</a>
260 ',0,1);
261 }
262 // Adding link to admin guides etc:
263 if ($this->mode=='page' || $this->mode=='beuser') {
264 $this->content.=$this->doc->section($LANG->getLL('tsprop_tsconfig'),'
265 <a href="'.htmlspecialchars('http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=263&cHash=1f1b106a30').'" target="_blank">'.$LANG->getLL('tsprop_tsconfig',1).'</a>
266 ',0,1);
267 }
268 // Ending page:
269 $this->content.=$this->doc->endPage();
270 }
271
272 /**
273 * Outputting the accumulated content to screen
274 *
275 * @return void
276 */
277 function printContent() {
278 echo $this->content;
279 }
280
281 /**
282 * Create the content of the module:
283 *
284 * @param string Object string
285 * @param integer Pointing to an entry in static_tsconfig_help to show.
286 * @return string HTML
287 */
288 function browseTSprop($mode,$show) {
289 global $LANG;
290
291 // Get object tree:
292 $objTree = $this->getObjTree();
293
294 // Show single element, if show is set.
295 $out='';
296 if ($show) {
297 // Get the entry data:
298 $query='SELECT * FROM static_tsconfig_help WHERE uid='.intval($show);
299 $res = mysql(TYPO3_db,$query);
300 $rec=mysql_fetch_assoc($res);
301 $table = unserialize($rec['appdata']);
302 $obj_string = strtr($this->objString,'()','[]'); // Title:
303
304 // Title and description:
305 $out.='<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('show'=>''))).'" class="typo3-goBack">'.
306 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/goback.gif','width="14" height="14"').' alt="" />'.
307 htmlspecialchars($obj_string).
308 '</a><br />';
309 if ($rec['title']) $out.= '<strong>'.htmlspecialchars($rec['title']).': </strong>';
310 if ($rec['description']) $out.= nl2br(htmlspecialchars(trim($rec['description']))).'<br />';
311
312 // Printing the content:
313 $out.= '<br />'.$this->printTable($table, $obj_string, $objTree[$mode.'.']);
314 $out.='<hr />';
315
316 // Printing the "mixer-field":
317 if (!$this->onlyProperty) {
318 $links=array();
319 $links[]='<a href="#" onclick="mixerField(\'Indent\');return false;">'.$LANG->getLL('tsprop_mixer_indent',1).'</a>';
320 $links[]='<a href="#" onclick="mixerField(\'Outdent\');return false;">'.$LANG->getLL('tsprop_mixer_outdent',1).'</a>';
321 $links[]='<a href="#" onclick="mixerField(\'Wrap\',unescape(\''.rawurlencode($obj_string).'\'));return false;">'.$LANG->getLL('tsprop_mixer_wrap',1).'</a>';
322 $links[]='<a href="#" onclick="mixerField(\'Transfer\');return false;">'.$LANG->getLL('tsprop_mixer_transfer',1).'</a>';
323 $out.='<textarea rows="5" name="mixer" wrap="off"'.$this->doc->formWidthText(48,'','off').'></textarea>';
324 $out.='<br /><strong>'.implode('&nbsp; | &nbsp;',$links).'</strong>';
325 $out.='<hr />';
326 }
327 }
328
329
330 // SECTION: Showing property tree:
331 $tmpl = t3lib_div::makeInstance('ext_TSparser');
332 $tmpl->tt_track = 0; // Do not log time-performance information
333 $tmpl->fixedLgd=0;
334 $tmpl->linkObjects=0;
335 $tmpl->bType='';
336 $tmpl->ext_expandAllNotes=1;
337 $tmpl->ext_noPMicons=1;
338 $tmpl->ext_noSpecialCharsOnLabels=1;
339
340 if (is_array($objTree[$mode.'.'])) {
341 $out.='
342
343
344 <!--
345 TSconfig, object tree:
346 -->
347 <table border="0" cellpadding="0" cellspacing="0" id="typo3-objtree">
348 <tr>
349 <td nowrap="nowrap">'.$tmpl->ext_getObjTree($this->removePointerObjects($objTree[$mode.'.']),'','').'</td>
350 </tr>
351 </table>';
352 }
353
354 return $out;
355 }
356
357
358
359
360
361
362
363 /***************************
364 *
365 * Module functions
366 *
367 ***************************/
368
369 /**
370 * Create object tree from static_tsconfig_help table
371 *
372 * @return array Object tree.
373 * @access private
374 */
375 function getObjTree() {
376 $hash = md5('WIZARD_TSCONFIG-objTree');
377
378 $query='SELECT uid,obj_string,title FROM static_tsconfig_help';
379 $res = mysql(TYPO3_db,$query);
380 $objTree=array();
381 while($rec=mysql_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 ?>