Added more comments, $Id$ keywords etc for the whole core of TYPO3.
[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 *
32 * @author Kasper Skaarhoj <kasper@typo3.com>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 *
38 *
39 * 92: class ext_TSparser extends t3lib_tsparser_ext
40 * 98: function makeHtmlspecialchars($P)
41 *
42 *
43 * 119: class SC_wizard_tsconfig
44 * 129: function init()
45 * 228: function main()
46 * 251: function printContent()
47 *
48 * SECTION: OTHER FUNCTIONS:
49 * 276: function revertFromSpecialChars($str)
50 * 288: function getObjTree($whichman="")
51 * 316: function setObj(&$objTree,$strArr,$params)
52 * 335: function doLink($params)
53 * 348: function browseTSprop($mode,$show)
54 * 401: function removePointerObjects($objArray)
55 * 421: function linkToObj($str,$uid,$objString="")
56 * 433: function printTable($table,$objString,$objTree)
57 * 499: function linkProperty($str,$propertyVal,$prefix,$datatype)
58 *
59 * TOTAL FUNCTIONS: 13
60 * (This index is automatically created/updated by the extension "extdeveval")
61 *
62 */
63
64
65
66 $BACK_PATH='';
67 require ('init.php');
68 require ('template.php');
69 include ('sysext/lang/locallang_wizards.php');
70 require_once (PATH_t3lib.'class.t3lib_parsehtml.php');
71 require_once (PATH_t3lib.'class.t3lib_tstemplate.php');
72 require_once (PATH_t3lib.'class.t3lib_tsparser_ext.php');
73
74
75
76
77
78
79
80
81
82
83
84
85 /**
86 * TypoScript parser extension class.
87 *
88 * @author Kasper Skaarhoj <kasper@typo3.com>
89 * @package TYPO3
90 * @subpackage core
91 */
92 class ext_TSparser extends t3lib_tsparser_ext {
93
94 /**
95 * @param [type] $P: ...
96 * @return [type] ...
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
114 *
115 * @author Kasper Skaarhoj <kasper@typo3.com>
116 * @package TYPO3
117 * @subpackage core
118 */
119 class SC_wizard_tsconfig {
120 var $content;
121 var $P;
122 var $mode;
123 var $show;
124 var $doc;
125
126 /**
127 * @return [type] ...
128 */
129 function init() {
130 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
131
132 t3lib_extMgm::isLoaded("tsconfig_help",1);
133
134 $this->P = t3lib_div::GPvar("P",1);
135
136 if (!is_array($this->P["fieldChangeFunc"])) $this->P["fieldChangeFunc"]=array();
137 unset($this->P["fieldChangeFunc"]["alert"]);
138 reset($this->P["fieldChangeFunc"]);
139 $update="";
140 while(list($k,$v)=each($this->P["fieldChangeFunc"])) {
141 $update.= "
142 window.opener.".$v;
143 }
144
145
146 $this->doc = t3lib_div::makeInstance("mediumDoc");
147 $this->doc->backPath = $BACK_PATH;
148 $this->doc->form='<form action="" name="editform">';
149 $this->doc->JScode='
150 <style>
151 A:link {text-decoration: bold; color: '.$this->doc->hoverColor.';}
152 A:visited {text-decoration: bold; color: '.$this->doc->hoverColor.';}
153 A:active {text-decoration: bold; color: '.$this->doc->hoverColor.';}
154 A:hover {color: '.$this->doc->bgColor2.'}
155 </style>
156 <script language="javascript" type="text/javascript">
157 function checkReference() { //
158 if (window.opener && window.opener.document && window.opener.document.'.$this->P["formName"].' && window.opener.document.'.$this->P["formName"].'["'.$this->P["itemName"].'"] ) {
159 return window.opener.document.'.$this->P["formName"].'["'.$this->P["itemName"].'"];
160 } else {
161 close();
162 }
163 }
164 function setValue(input) { //
165 var field = checkReference();
166 if (field) {
167 field.value=input+"\n"+field.value;
168 '.$update.'
169 window.opener.focus();
170 }
171 close();
172 }
173 function getValue() { //
174 var field = checkReference();
175 if (field) return field.value;
176 }
177 function mixerField(cmd,objString) { //
178 var temp;
179 switch(cmd) {
180 case "Indent":
181 temp = str_replace("\n","\n ","\n"+document.editform.mixer.value);
182 document.editform.mixer.value = temp.substr(1);
183 break;
184 case "Outdent":
185 temp = str_replace("\n ","\n","\n"+document.editform.mixer.value);
186 document.editform.mixer.value = temp.substr(1);
187 break;
188 case "Transfer":
189 setValue(document.editform.mixer.value);
190 break;
191 case "Wrap":
192 document.editform.mixer.value=objString+" {\n"+document.editform.mixer.value+"\n}";
193 break;
194 }
195 }
196 function str_replace(match,replace,string) { //
197 var input = ""+string;
198 var matchStr = ""+match;
199 if (!matchStr) {return string;}
200 var output = "";
201 var pointer=0;
202 var pos = input.indexOf(matchStr);
203 while (pos!=-1) {
204 output+=""+input.substr(pointer, pos-pointer)+replace;
205 pointer=pos+matchStr.length;
206 pos = input.indexOf(match,pos+1);
207 }
208 output+=""+input.substr(pointer);
209 return output;
210 }
211 function jump(show,objString) { //
212 document.location = "'.t3lib_div::linkThisScript(array("show"=>"","objString"=>"")).'&show="+show+"&objString="+objString;
213 }
214 </script>
215 ';
216
217
218 $this->content.=$this->doc->startPage($LANG->getLL("tsprop"));
219 $this->mode = t3lib_div::GPvar("mode");
220 $this->show = t3lib_div::GPvar("show");
221 }
222
223 /**
224 * [Describe function...]
225 *
226 * @return [type] ...
227 */
228 function main() {
229 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
230
231 $this->content.=$this->doc->section($LANG->getLL("tsprop"),$this->browseTSprop($this->mode,$this->show),0,1);
232 if ($this->mode=="tsref") {
233 $this->content.=$this->doc->section($LANG->getLL("tsprop_TSref"),'
234 <a href="'.$BACK_PATH.t3lib_extMgm::extRelPath("tsconfig_help").'man/TSref.html">'.$LANG->getLL("tsprop_localHTML").'</a><BR>
235 <a href="http://www.typo3.com/doclink.php?doc=tsref" target="_blank">'.$LANG->getLL("tsprop_pdf").'</a>
236 ',0,1);
237 }
238 if ($this->mode=="page" || $this->mode=="beuser") {
239 $this->content.=$this->doc->section($LANG->getLL("tsprop_adminguide"),'
240 <a href="'.$BACK_PATH.t3lib_extMgm::extRelPath("tsconfig_help").'man/adminguide.html">'.$LANG->getLL("tsprop_localHTML").'</a><BR>
241 <a href="http://www.typo3.com/doclink.php?doc=adminguide" target="_blank">'.$LANG->getLL("tsprop_pdf").'</a>
242 ',0,1);
243 }
244 }
245
246 /**
247 * [Describe function...]
248 *
249 * @return [type] ...
250 */
251 function printContent() {
252 global $SOBE;
253
254 $this->content.=$this->doc->endPage();
255 echo $this->content;
256 }
257
258
259
260
261
262
263
264
265
266 /***************************
267 *
268 * OTHER FUNCTIONS:
269 *
270 ***************************/
271
272 /**
273 * @param [type] $str: ...
274 * @return [type] ...
275 */
276 function revertFromSpecialChars($str) {
277 $str = str_replace("&gt;",">",$str);
278 $str = str_replace("&lt;","<",$str);
279 return $str;
280 }
281
282 /**
283 * [Describe function...]
284 *
285 * @param [type] $whichman: ...
286 * @return [type] ...
287 */
288 function getObjTree($whichman="") {
289 $hash = md5("WIZARD_TSCONFIG-objTree");
290
291 $query="SELECT uid,obj_string,title FROM static_tsconfig_help".($whichman?" WHERE guide='".addslashes($whichman)."'":"");
292 $res = mysql(TYPO3_db,$query);
293 $objTree=array();
294 while($rec=mysql_fetch_assoc($res)) {
295 $rec["obj_string"] = $this->revertFromSpecialChars($rec["obj_string"]);
296 $p = explode(";",$rec["obj_string"]);
297 while(list(,$v)=each($p)) {
298 $p2 = t3lib_div::trimExplode(":",$v,1);
299 $subp=t3lib_div::trimExplode("/",$p2[1],1);
300 while(list(,$v2)=each($subp)) {
301 $this->setObj($objTree,explode(".",$p2[0].".".$v2),array($rec,$v2));
302 }
303 }
304 }
305 return $objTree;
306 }
307
308 /**
309 * [Describe function...]
310 *
311 * @param [type] $$objTree: ...
312 * @param [type] $strArr: ...
313 * @param [type] $params: ...
314 * @return [type] ...
315 */
316 function setObj(&$objTree,$strArr,$params) {
317 $key = current($strArr);
318 reset($strArr);
319 if (count($strArr)>1) {
320 array_shift($strArr);
321 if (!isset($objTree[$key."."])) $objTree[$key."."]=array();
322 $this->setObj($objTree[$key."."],$strArr,$params);
323 } else {
324 $objTree[$key]=$params;
325 $objTree[$key]["_LINK"]=$this->doLink($params);
326 }
327 }
328
329 /**
330 * [Describe function...]
331 *
332 * @param [type] $params: ...
333 * @return [type] ...
334 */
335 function doLink($params) {
336 $title = htmlspecialchars(trim($params[0]["title"])?trim($params[0]["title"]):"[GO]");
337 $str = $this->linkToObj($title,$params[0]["uid"],$params[1]);
338 return $str;
339 }
340
341 /**
342 * [Describe function...]
343 *
344 * @param [type] $mode: ...
345 * @param [type] $show: ...
346 * @return [type] ...
347 */
348 function browseTSprop($mode,$show) {
349 $whichman="adminguide";
350
351 $objTree = $this->getObjTree("");
352 $out="";
353 if ($show) {
354 $query="SELECT * FROM static_tsconfig_help WHERE uid='".intval($show)."'";
355 $res = mysql(TYPO3_db,$query);
356 $rec=mysql_fetch_assoc($res);
357 $table = unserialize($rec["appdata"]);
358 $obj_string = strtr(t3lib_div::GPvar("objString"),"()","[]");
359
360 $out.='<a href="'.t3lib_div::linkThisScript(array("show"=>"")).'" class="typo3-goBack"><img src="gfx/goback.gif" width="14" height="14" hspace=2 border="0" align=top>';
361 $out.= '<font size=2 color="black"><strong>'.$obj_string.'</strong></font></a><BR>';
362 if ($rec["title"]) $out.= '<strong>'.$rec["title"].': </strong>';
363 if ($rec["description"]) $out.= nl2br(trim($rec["description"])).'<BR>';
364
365 $out.= '<BR>'.$this->printTable($table, $obj_string, $objTree[$mode."."]);
366 $out.="<HR>";
367
368 if (!t3lib_div::GPvar("onlyProperty")) {
369 $links=array();
370 $links[]='<a href="#" onClick="mixerField(\'Indent\');return false;">Indent +2</a>';
371 $links[]='<a href="#" onClick="mixerField(\'Outdent\');return false;">Outdent -2</a>';
372 $links[]='<a href="#" onClick="mixerField(\'Wrap\',unescape(\''.rawurlencode($obj_string).'\'));return false;">Wrap</a>';
373 $links[]='<a href="#" onClick="mixerField(\'Transfer\');return false;">Transfer & Close</a>';
374 $out.='<textarea rows="5" name="mixer" wrap="off"'.$this->doc->formWidthText(48,"","off").'></textarea>';
375 $out.='<BR><strong>'.implode("&nbsp; | &nbsp;",$links).'</strong>';
376 $out.="<HR>";
377 }
378 }
379
380 $tmpl = t3lib_div::makeInstance("ext_TSparser");
381 $tmpl->tt_track = 0; // Do not log time-performance information
382 $tmpl->fixedLgd=0;
383 $tmpl->linkObjects=0;
384 $tmpl->bType="";
385 $tmpl->ext_expandAllNotes=1;
386 $tmpl->ext_noPMicons=1;
387 $tmpl->ext_noSpecialCharsOnLabels=1;
388
389 if (is_array($objTree[$mode."."])) {
390 $out.='<table border=0 cellpadding=0 cellspacing=0><tr><td nowrap>'.$tmpl->ext_getObjTree($this->removePointerObjects($objTree[$mode."."]),"","").'</td></tr></table>';
391 }
392 return $out;
393 }
394
395 /**
396 * [Describe function...]
397 *
398 * @param [type] $objArray: ...
399 * @return [type] ...
400 */
401 function removePointerObjects($objArray) {
402 reset($objArray);
403 while(list($k)=each($objArray)) {
404 if (substr(trim($k),0,2)=="->" && trim($k)!="->.") {
405 $objArray["->."][substr(trim($k),2)]=$objArray[$k];
406 unset($objArray[$k]);
407 }
408 }
409 // debug($objArray);
410 return $objArray;
411 }
412
413 /**
414 * [Describe function...]
415 *
416 * @param [type] $str: ...
417 * @param [type] $uid: ...
418 * @param [type] $objString: ...
419 * @return [type] ...
420 */
421 function linkToObj($str,$uid,$objString="") {
422 return '<a href="#" onClick="jump(\''.rawurlencode($uid).'\',\''.rawurlencode($objString).'\');return false;">'.$str.'</a>';
423 }
424
425 /**
426 * [Describe function...]
427 *
428 * @param [type] $table: ...
429 * @param [type] $objString: ...
430 * @param [type] $objTree: ...
431 * @return [type] ...
432 */
433 function printTable($table,$objString,$objTree) {
434 if (is_array($table["rows"])) {
435 $lines=array();
436
437 $lines[]='<tr>
438 <td><img src=clear.gif width=175 height=1></td>
439 <td><img src=clear.gif width=100 height=1></td>
440 <td><img src=clear.gif width=400 height=1></td>
441 <td><img src=clear.gif width=70 height=1></td>
442 </tr>';
443 $lines[]='<tr bgcolor="'.$this->doc->bgColor5.'">
444 <td><strong>Property:</strong></td>
445 <td><strong>Data type:</strong></td>
446 <td><strong>Description:</strong></td>
447 <td><strong>Default:</strong></td>
448 </tr>';
449
450
451 reset($table["rows"]);
452 while(list(,$row)=each($table["rows"])) {
453 // Linking:
454 $lP=t3lib_div::trimExplode(chr(10),$row["property"],1);
455 $lP2=array();
456 while(list($k,$lStr)=each($lP)) {
457 $lP2[$k] = $this->linkProperty($lStr,$lStr,$objString,$row["datatype"]);
458 }
459 $linkedProperties=implode("<HR>",$lP2);
460
461 // Data type:
462 # $dataType = $this->revertFromSpecialChars($row["datatype"]); // 260902: Removed because it make HTML-tags back to HTML tags - while they should stay non-tags (eg imgs)
463 $dataType = $row["datatype"];
464
465 // Generally "->[something]"
466 $reg=array();
467 ereg("->[[:alnum:]_]*",$dataType,$reg);
468 if ($reg[0] && is_array($objTree[$reg[0]])) {
469 // debug($objTree[$reg[0]]);
470 $dataType = str_replace($reg[0],'<a href="'.t3lib_div::linkThisScript(array("show"=>$objTree[$reg[0]][0]["uid"],"objString"=>$objString.".".$lP[0])).'">'.$reg[0].'</a>',$dataType);
471 }
472 // stdWrap
473 if (!strstr($dataType,"->stdWrap") && strstr(strip_tags($dataType),"stdWrap")) {
474 // 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?
475 $dataType = str_replace("stdWrap",'<a href="'.t3lib_div::linkThisScript(array("show"=>$objTree["->stdWrap"][0]["uid"],"objString"=>$objString.".".$lP[0])).'">stdWrap</a>',$dataType);
476 }
477
478
479 $lines[]='<tr bgColor="'.$GLOBALS["TBE_TEMPLATE"]->bgColor4.'">
480 <td valign=top bgColor="'.t3lib_div::modifyHtmlColor($GLOBALS["TBE_TEMPLATE"]->bgColor4,-20,-20,-20).'"><strong>'.$linkedProperties.'</strong></td>
481 <td valign=top>'.nl2br($dataType."&nbsp;").'</td>
482 <td valign=top>'.nl2br($row["description"]).'</td>
483 <td valign=top>'.nl2br($row["default"]).'</td>
484 </tr>';
485 }
486 return '<table border=0 cellpadding=0 cellspacing=1 width=500>'.implode("",$lines).'</table>';
487 }
488 }
489
490 /**
491 * [Describe function...]
492 *
493 * @param [type] $str: ...
494 * @param [type] $propertyVal: ...
495 * @param [type] $prefix: ...
496 * @param [type] $datatype: ...
497 * @return [type] ...
498 */
499 function linkProperty($str,$propertyVal,$prefix,$datatype) {
500 $out="";
501 if (strstr($datatype,"boolean")) {
502 $propertyVal.="=1"; // add preset "=1" to boolean values.
503 } else {
504 $propertyVal.="="; // add preset "="
505 }
506
507 if(!t3lib_div::GPvar("onlyProperty")) {
508 $out.= '<a href="#" onClick="document.editform.mixer.value=unescape(\' '.rawurlencode($propertyVal).'\')+\'\n\'+document.editform.mixer.value; return false;"><img src="gfx/plusbullet2.gif" width="18" height="16" border="0" title="Add to list..." align=top></a>';
509 $propertyVal = $prefix.".".$propertyVal;
510 }
511 $out.= '<a href="#" onClick="setValue(unescape(\''.rawurlencode($propertyVal).'\')); return false;">'.$str.'</a>';
512 return $out;
513 }
514 }
515
516 // Include extension?
517 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_tsconfig.php']) {
518 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_tsconfig.php']);
519 }
520
521
522
523
524
525
526
527
528
529
530
531
532 // Make instance:
533 $SOBE = t3lib_div::makeInstance('SC_wizard_tsconfig');
534 $SOBE->init();
535 $SOBE->main();
536 $SOBE->printContent();
537 ?>