Initial revision
[Packages/TYPO3.CMS.git] / typo3 / wizard_tsconfig.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skårhøj (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 * @author Kasper Skårhøj <kasper@typo3.com>
31 * @package TYPO3
32 * @subpackage core
33 *
34 */
35
36
37
38 $BACK_PATH="";
39 require ("init.php");
40 require ("template.php");
41 include ("sysext/lang/locallang_wizards.php");
42 require_once (PATH_t3lib."class.t3lib_parsehtml.php");
43 require_once (PATH_t3lib."class.t3lib_tstemplate.php");
44 require_once (PATH_t3lib."class.t3lib_tsparser_ext.php");
45
46
47
48
49 // ***************************
50 // Script Classes
51 // ***************************
52 class ext_TSparser extends t3lib_tsparser_ext {
53 function makeHtmlspecialchars($P) {
54 return $P["_LINK"];
55 }
56 }
57 class SC_wizard_tsconfig {
58 var $content;
59 var $P;
60 var $mode;
61 var $show;
62 var $doc;
63
64 function init() {
65 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
66
67 t3lib_extMgm::isLoaded("tsconfig_help",1);
68
69 $this->P = t3lib_div::GPvar("P",1);
70
71 if (!is_array($this->P["fieldChangeFunc"])) $this->P["fieldChangeFunc"]=array();
72 unset($this->P["fieldChangeFunc"]["alert"]);
73 reset($this->P["fieldChangeFunc"]);
74 $update="";
75 while(list($k,$v)=each($this->P["fieldChangeFunc"])) {
76 $update.= "
77 window.opener.".$v;
78 }
79
80
81 $this->doc = t3lib_div::makeInstance("mediumDoc");
82 $this->doc->backPath = $BACK_PATH;
83 $this->doc->form='<form action="" name="editform">';
84 $this->doc->JScode='
85 <style>
86 A:link {text-decoration: bold; color: '.$this->doc->hoverColor.';}
87 A:visited {text-decoration: bold; color: '.$this->doc->hoverColor.';}
88 A:active {text-decoration: bold; color: '.$this->doc->hoverColor.';}
89 A:hover {color: '.$this->doc->bgColor2.'}
90 </style>
91 <script language="javascript" type="text/javascript">
92 function checkReference() {
93 if (window.opener && window.opener.document && window.opener.document.'.$this->P["formName"].' && window.opener.document.'.$this->P["formName"].'["'.$this->P["itemName"].'"] ) {
94 return window.opener.document.'.$this->P["formName"].'["'.$this->P["itemName"].'"];
95 } else {
96 close();
97 }
98 }
99 function setValue(input) {
100 var field = checkReference();
101 if (field) {
102 field.value=input+"\n"+field.value;
103 '.$update.'
104 window.opener.focus();
105 }
106 close();
107 }
108 function getValue() {
109 var field = checkReference();
110 if (field) return field.value;
111 }
112 function mixerField(cmd,objString) {
113 var temp;
114 switch(cmd) {
115 case "Indent":
116 temp = str_replace("\n","\n ","\n"+document.editform.mixer.value);
117 document.editform.mixer.value = temp.substr(1);
118 break;
119 case "Outdent":
120 temp = str_replace("\n ","\n","\n"+document.editform.mixer.value);
121 document.editform.mixer.value = temp.substr(1);
122 break;
123 case "Transfer":
124 setValue(document.editform.mixer.value);
125 break;
126 case "Wrap":
127 document.editform.mixer.value=objString+" {\n"+document.editform.mixer.value+"\n}";
128 break;
129 }
130 }
131 function str_replace(match,replace,string) {
132 var input = ""+string;
133 var matchStr = ""+match;
134 if (!matchStr) {return string;}
135 var output = "";
136 var pointer=0;
137 var pos = input.indexOf(matchStr);
138 while (pos!=-1) {
139 output+=""+input.substr(pointer, pos-pointer)+replace;
140 pointer=pos+matchStr.length;
141 pos = input.indexOf(match,pos+1);
142 }
143 output+=""+input.substr(pointer);
144 return output;
145 }
146 function jump(show,objString) {
147 document.location = "'.t3lib_div::linkThisScript(array("show"=>"","objString"=>"")).'&show="+show+"&objString="+objString;
148 }
149 </script>
150 ';
151
152
153 $this->content.=$this->doc->startPage($LANG->getLL("tsprop"));
154 $this->mode = t3lib_div::GPvar("mode");
155 $this->show = t3lib_div::GPvar("show");
156 }
157 function main() {
158 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
159
160 $this->content.=$this->doc->section($LANG->getLL("tsprop"),$this->browseTSprop($this->mode,$this->show),0,1);
161 if ($this->mode=="tsref") {
162 $this->content.=$this->doc->section($LANG->getLL("tsprop_TSref"),'
163 <a href="'.$BACK_PATH.t3lib_extMgm::extRelPath("tsconfig_help").'man/TSref.html">'.$LANG->getLL("tsprop_localHTML").'</a><BR>
164 <a href="http://www.typo3.com/doclink.php?doc=tsref" target="_blank">'.$LANG->getLL("tsprop_pdf").'</a>
165 ',0,1);
166 }
167 if ($this->mode=="page" || $this->mode=="beuser") {
168 $this->content.=$this->doc->section($LANG->getLL("tsprop_adminguide"),'
169 <a href="'.$BACK_PATH.t3lib_extMgm::extRelPath("tsconfig_help").'man/adminguide.html">'.$LANG->getLL("tsprop_localHTML").'</a><BR>
170 <a href="http://www.typo3.com/doclink.php?doc=adminguide" target="_blank">'.$LANG->getLL("tsprop_pdf").'</a>
171 ',0,1);
172 }
173 }
174 function printContent() {
175 global $SOBE;
176
177 $this->content.=$this->doc->endPage();
178 echo $this->content;
179 }
180
181 // ***************************
182 // OTHER FUNCTIONS:
183 // ***************************
184 function revertFromSpecialChars($str) {
185 $str = str_replace("&gt;",">",$str);
186 $str = str_replace("&lt;","<",$str);
187 return $str;
188 }
189 function getObjTree($whichman="") {
190 $hash = md5("WIZARD_TSCONFIG-objTree");
191
192 $query="SELECT uid,obj_string,title FROM static_tsconfig_help".($whichman?" WHERE guide='".addslashes($whichman)."'":"");
193 $res = mysql(TYPO3_db,$query);
194 $objTree=array();
195 while($rec=mysql_fetch_assoc($res)) {
196 $rec["obj_string"] = $this->revertFromSpecialChars($rec["obj_string"]);
197 $p = explode(";",$rec["obj_string"]);
198 while(list(,$v)=each($p)) {
199 $p2 = t3lib_div::trimExplode(":",$v,1);
200 $subp=t3lib_div::trimExplode("/",$p2[1],1);
201 while(list(,$v2)=each($subp)) {
202 $this->setObj($objTree,explode(".",$p2[0].".".$v2),array($rec,$v2));
203 }
204 }
205 }
206 return $objTree;
207 }
208 function setObj(&$objTree,$strArr,$params) {
209 $key = current($strArr);
210 reset($strArr);
211 if (count($strArr)>1) {
212 array_shift($strArr);
213 if (!isset($objTree[$key."."])) $objTree[$key."."]=array();
214 $this->setObj($objTree[$key."."],$strArr,$params);
215 } else {
216 $objTree[$key]=$params;
217 $objTree[$key]["_LINK"]=$this->doLink($params);
218 }
219 }
220 function doLink($params) {
221 $title = htmlspecialchars(trim($params[0]["title"])?trim($params[0]["title"]):"[GO]");
222 $str = $this->linkToObj($title,$params[0]["uid"],$params[1]);
223 return $str;
224 }
225 function browseTSprop($mode,$show) {
226 $whichman="adminguide";
227
228 $objTree = $this->getObjTree("");
229 $out="";
230 if ($show) {
231 $query="SELECT * FROM static_tsconfig_help WHERE uid='".intval($show)."'";
232 $res = mysql(TYPO3_db,$query);
233 $rec=mysql_fetch_assoc($res);
234 $table = unserialize($rec["appdata"]);
235 $obj_string = strtr(t3lib_div::GPvar("objString"),"()","[]");
236
237 $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>';
238 $out.= '<font size=2 color="black"><strong>'.$obj_string.'</strong></font></a><BR>';
239 if ($rec["title"]) $out.= '<strong>'.$rec["title"].': </strong>';
240 if ($rec["description"]) $out.= nl2br(trim($rec["description"])).'<BR>';
241
242 $out.= '<BR>'.$this->printTable($table, $obj_string, $objTree[$mode."."]);
243 $out.="<HR>";
244
245 if (!t3lib_div::GPvar("onlyProperty")) {
246 $links=array();
247 $links[]='<a href="#" onClick="mixerField(\'Indent\');return false;">Indent +2</a>';
248 $links[]='<a href="#" onClick="mixerField(\'Outdent\');return false;">Outdent -2</a>';
249 $links[]='<a href="#" onClick="mixerField(\'Wrap\',unescape(\''.rawurlencode($obj_string).'\'));return false;">Wrap</a>';
250 $links[]='<a href="#" onClick="mixerField(\'Transfer\');return false;">Transfer & Close</a>';
251 $out.='<textarea rows="5" name="mixer" wrap="off"'.$this->doc->formWidthText(48,"","off").'></textarea>';
252 $out.='<BR><strong>'.implode("&nbsp; | &nbsp;",$links).'</strong>';
253 $out.="<HR>";
254 }
255 }
256
257 $tmpl = t3lib_div::makeInstance("ext_TSparser");
258 $tmpl->tt_track = 0; // Do not log time-performance information
259 $tmpl->fixedLgd=0;
260 $tmpl->linkObjects=0;
261 $tmpl->bType="";
262 $tmpl->ext_expandAllNotes=1;
263 $tmpl->ext_noPMicons=1;
264 $tmpl->ext_noSpecialCharsOnLabels=1;
265
266 if (is_array($objTree[$mode."."])) {
267 $out.='<table border=0 cellpadding=0 cellspacing=0><tr><td nowrap>'.$tmpl->ext_getObjTree($this->removePointerObjects($objTree[$mode."."]),"","").'</td></tr></table>';
268 }
269 return $out;
270 }
271 function removePointerObjects($objArray) {
272 reset($objArray);
273 while(list($k)=each($objArray)) {
274 if (substr(trim($k),0,2)=="->" && trim($k)!="->.") {
275 $objArray["->."][substr(trim($k),2)]=$objArray[$k];
276 unset($objArray[$k]);
277 }
278 }
279 // debug($objArray);
280 return $objArray;
281 }
282 function linkToObj($str,$uid,$objString="") {
283 return '<a href="#" onClick="jump(\''.rawurlencode($uid).'\',\''.rawurlencode($objString).'\');return false;">'.$str.'</a>';
284 }
285 function printTable($table,$objString,$objTree) {
286 if (is_array($table["rows"])) {
287 $lines=array();
288
289 $lines[]='<tr>
290 <td><img src=clear.gif width=175 height=1></td>
291 <td><img src=clear.gif width=100 height=1></td>
292 <td><img src=clear.gif width=400 height=1></td>
293 <td><img src=clear.gif width=70 height=1></td>
294 </tr>';
295 $lines[]='<tr bgcolor="'.$this->doc->bgColor5.'">
296 <td><strong>Property:</strong></td>
297 <td><strong>Data type:</strong></td>
298 <td><strong>Description:</strong></td>
299 <td><strong>Default:</strong></td>
300 </tr>';
301
302
303 reset($table["rows"]);
304 while(list(,$row)=each($table["rows"])) {
305 // Linking:
306 $lP=t3lib_div::trimExplode(chr(10),$row["property"],1);
307 $lP2=array();
308 while(list($k,$lStr)=each($lP)) {
309 $lP2[$k] = $this->linkProperty($lStr,$lStr,$objString,$row["datatype"]);
310 }
311 $linkedProperties=implode("<HR>",$lP2);
312
313 // Data type:
314 # $dataType = $this->revertFromSpecialChars($row["datatype"]); // 260902: Removed because it make HTML-tags back to HTML tags - while they should stay non-tags (eg imgs)
315 $dataType = $row["datatype"];
316
317 // Generally "->[something]"
318 $reg=array();
319 ereg("->[[:alnum:]_]*",$dataType,$reg);
320 if ($reg[0] && is_array($objTree[$reg[0]])) {
321 // debug($objTree[$reg[0]]);
322 $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);
323 }
324 // stdWrap
325 if (!strstr($dataType,"->stdWrap") && strstr(strip_tags($dataType),"stdWrap")) {
326 // 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?
327 $dataType = str_replace("stdWrap",'<a href="'.t3lib_div::linkThisScript(array("show"=>$objTree["->stdWrap"][0]["uid"],"objString"=>$objString.".".$lP[0])).'">stdWrap</a>',$dataType);
328 }
329
330
331 $lines[]='<tr bgColor="'.$GLOBALS["TBE_TEMPLATE"]->bgColor4.'">
332 <td valign=top bgColor="'.t3lib_div::modifyHtmlColor($GLOBALS["TBE_TEMPLATE"]->bgColor4,-20,-20,-20).'"><strong>'.$linkedProperties.'</strong></td>
333 <td valign=top>'.nl2br($dataType."&nbsp;").'</td>
334 <td valign=top>'.nl2br($row["description"]).'</td>
335 <td valign=top>'.nl2br($row["default"]).'</td>
336 </tr>';
337 }
338 return '<table border=0 cellpadding=0 cellspacing=1 width=500>'.implode("",$lines).'</table>';
339 }
340 }
341 function linkProperty($str,$propertyVal,$prefix,$datatype) {
342 $out="";
343 if (strstr($datatype,"boolean")) {
344 $propertyVal.="=1"; // add preset "=1" to boolean values.
345 } else {
346 $propertyVal.="="; // add preset "="
347 }
348
349 if(!t3lib_div::GPvar("onlyProperty")) {
350 $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>';
351 $propertyVal = $prefix.".".$propertyVal;
352 }
353 $out.= '<a href="#" onClick="setValue(unescape(\''.rawurlencode($propertyVal).'\')); return false;">'.$str.'</a>';
354 return $out;
355 }
356 }
357
358 // Include extension?
359 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["typo3/wizard_tsconfig.php"]) {
360 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["typo3/wizard_tsconfig.php"]);
361 }
362
363
364
365
366
367
368
369
370
371
372
373
374 // Make instance:
375 $SOBE = t3lib_div::makeInstance("SC_wizard_tsconfig");
376 $SOBE->init();
377 $SOBE->main();
378 $SOBE->printContent();
379 ?>