Initial revision
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tsparser_ext.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 * TSParser extension class to t3lib_TStemplate
29 *
30 * Contains functions for the TS module in TYPO3 backend
31 *
32 * @author Kasper Skårhøj <kasper@typo3.com>
33 * @package TYPO3
34 * @subpackage t3lib
35 */
36
37 require_once(PATH_t3lib."class.t3lib_tstemplate.php");
38
39 class t3lib_tsparser_ext extends t3lib_TStemplate {
40
41 var $edit_divider = "###MOD_TS:EDITABLE_CONSTANTS###"; // This string is used to indicate the point in a template from where the editable constants are listed. Any vars before this point (if it exists though) is regarded as default values.
42 var $HTMLcolorList = "aqua,black,blue,fuchsia,gray,green,lime,maroon,navy,olive,purple,red,silver,teal,yellow,white";
43
44 // internal
45 var $categories = array(
46 "basic" => array(), // Constants of superior importance for the template-layout. This is dimensions, imagefiles and enabling of various features. The most basic constants, which you would almost always want to configure.
47 "menu" => array(), // Menu setup. This includes fontfiles, sizes, background images. Depending on the menutype.
48 "content" => array(), // All constants related to the display of pagecontent elements
49 "page" => array(), // General configuration like metatags, link targets
50 "advanced" => array(), // Advanced functions, which are used very seldomly.
51 "all" => array() // All constants are put here also!
52 ); // This will be filled with the available categories of the current template.
53 var $subCategories = array(
54 // Standard categories:
55 "enable" => Array("Enable features", "a"),
56 "dims" => Array("Dimensions, widths, heights, pixels", "b"),
57 "file" => Array("Files", "c"),
58 "typo" => Array("Typography", "d"),
59 "color" => Array("Colors", "e"),
60 "links" => Array("Links and targets", "f"),
61 "language" => Array("Language specific constants", "g"),
62
63 // subcategories based on the default content elements
64 "cheader" => Array("Content: 'Header'", "ma"),
65 "cheader_g" => Array("Content: 'Header', Graphical", "ma"),
66 "ctext" => Array("Content: 'Text'", "mb"),
67 // "ctextpic" =>
68 "cimage" => Array("Content: 'Image'", "md"),
69 "cbullets" => Array("Content: 'Bullet list'", "me"),
70 "ctable" => Array("Content: 'Table'", "mf"),
71 "cuploads" => Array("Content: 'Filelinks'", "mg"),
72 "cmultimedia" => Array("Content: 'Multimedia'", "mh"),
73 "cmailform" => Array("Content: 'Form'", "mi"),
74 "csearch" => Array("Content: 'Search'", "mj"),
75 "clogin" => Array("Content: 'Login'", "mk"),
76 "csplash" => Array("Content: 'Textbox'", "ml"),
77 "cmenu" => Array("Content: 'Menu/Sitemap'", "mm"),
78 "cshortcut" => Array("Content: 'Insert records'", "mn"),
79 "clist" => Array("Content: 'List of records'", "mo"),
80 "cscript" => Array("Content: 'Script'", "mp"),
81 "chtml" => Array("Content: 'HTML'", "mq")
82 );
83 var $resourceDimensions = array();
84 var $dirResources = array();
85
86 // var $matchAll = 0; // If set, all conditions are matched!
87
88 var $backend_info=1;
89
90 // tsconstanteditor
91 var $ext_inBrace=0;
92
93 // tsbrowser
94 var $tsbrowser_searchKeys = array();
95 var $tsbrowser_depthKeys = array();
96 var $constantMode="";
97 var $regexMode="";
98 var $fixedLgd="";
99 var $resourceCheck=0;
100 var $ext_lineNumberOffset=0;
101 var $ext_localGfxPrefix="";
102 var $ext_localWebGfxPrefix="";
103 var $ext_expandAllNotes=0;
104 var $ext_noPMicons=0;
105 var $ext_noSpecialCharsOnLabels=0;
106 var $ext_listOfTemplatesArr=array();
107 var $ext_lineNumberOffset_mode="";
108 var $ext_dontCheckIssetValues=0; // Dont change...
109 var $ext_noCEUploadAndCopying=0;
110 var $ext_printAll=0;
111 var $ext_CEformName="forms[0]";
112 var $ext_defaultOnlineResourceFlag=0;
113
114 // ts analyzer
115 var $templateTitles=array();
116
117 function flattenSetup($setupArray, $prefix, $resourceFlag) {
118 // This flattens a hierarchical setuparray to $this->flatSetup
119 // The original function fetched the resource-file if any ("file."). This functions doesn't.
120
121 if (is_array($setupArray)) {
122 $this->getFileName_backPath=PATH_site; // Setting absolute prefixed path for relative resources.
123 reset($setupArray);
124 while(list($key,$val)=each($setupArray)) {
125 if ($prefix || substr($key,0,16)!="TSConstantEditor") { // We don't want "TSConstantEditor" in the flattend setup.
126 if (is_array($val)) {
127 $this->flattenSetup($val,$prefix.$key, ($key=="file."));
128 } elseif ($resourceFlag && $this->resourceCheck) {
129 // debug($prefix.$key."-".$val);
130 // debug($this->getFileName($val),1);
131 $this->flatSetup[$prefix.$key] = $this->getFileName($val);
132 #debug(array($prefix.$key,$this->flatSetup[$prefix.$key],$val,$this->getFileName($val)));
133 if ($this->removeFromGetFilePath && substr($this->flatSetup[$prefix.$key],0,strlen($this->removeFromGetFilePath))==$this->removeFromGetFilePath) {
134 $this->flatSetup[$prefix.$key] = substr($this->flatSetup[$prefix.$key],strlen($this->removeFromGetFilePath));
135 // debug($this->flatSetup[$prefix.$key],1);
136 }
137 } else {
138 $this->flatSetup[$prefix.$key] = $val;
139 }
140 }
141 }
142 }
143 }
144 function substituteConstants($all) {
145 $this->Cmarker=substr(md5(uniqid("")),0,6);
146 reset($this->flatSetup);
147 while (list($const,$val)=each($this->flatSetup)) {
148 if (!is_array($val)) {
149 switch($this->constantMode) {
150 case "const":
151 $all = str_replace('{$'.$const.'}','##'.$this->Cmarker.'_B##{$'.$const.'}##'.$this->Cmarker.'_E##',$all);
152 break;
153 case "subst":
154 $all = str_replace('{$'.$const.'}','##'.$this->Cmarker.'_B##'.$val.'##'.$this->Cmarker.'_E##',$all);
155 break;
156 case "untouched":
157 break;
158 default:
159 $all = str_replace('{$'.$const.'}',$val,$all);
160 break;
161 }
162 }
163 }
164 return $all;
165 }
166 function substituteCMarkers($all) {
167 switch($this->constantMode) {
168 case "const":
169 $all = str_replace('##'.$this->Cmarker.'_B##', '<font color="green"><B>', $all);
170 $all = str_replace('##'.$this->Cmarker.'_E##', '</b></font>', $all);
171 break;
172 case "subst":
173 $all = str_replace('##'.$this->Cmarker.'_B##', '<font color="green"><B>', $all);
174 $all = str_replace('##'.$this->Cmarker.'_E##', '</b></font>', $all);
175 break;
176 default:
177 $all = $all;
178 break;
179 }
180 return $all;
181 }
182 function generateConfig_constants() {
183 // Parses the constants in $this->const with respect to the constant-editor in this module.
184 // In particular comments in the code are registered and the edit_divider is taken into account.
185 // These vars are also set lateron...
186 $this->setup["resources"]= $this->resources;
187 $this->setup["sitetitle"]= $this->sitetitle;
188
189 // parse constants
190 $constants = t3lib_div::makeInstance("t3lib_TSparser");
191 $constants->regComments=1; // Register comments!
192 $constants->setup = $this->const;
193
194 $matchObj = t3lib_div::makeInstance("t3lib_matchCondition");
195 // $matchObj->matchAlternative = array("[globalString = page | title = *test*]");
196 $matchObj->matchAll=1; // Matches ALL conditions in TypoScript
197
198 $c=0;
199 $cc=count($this->constants);
200 reset($this->constants);
201 while (list(,$str)=each($this->constants)) {
202 $c++;
203 if ($c==$cc) {
204 if (strstr($str,$this->edit_divider)) {
205 $parts = explode($this->edit_divider,$str,2);
206 $str=$parts[1];
207 $constants->parse($parts[0],$matchObj);
208 }
209 $this->flatSetup = Array();
210 $this->flattenSetup($constants->setup,"","");
211 $defaultConstants=$this->flatSetup;
212 }
213 $constants->parse($str,$matchObj);
214 }
215
216 $this->flatSetup = Array();
217 $this->flattenSetup($constants->setup,"","");
218 $this->setup["constants"] = $constants->setup;
219
220 return $this->ext_compareFlatSetups($defaultConstants);
221 }
222 function ext_getSetup($theSetup,$theKey) {
223 $parts = explode(".",$theKey,2);
224 // debug("-----------",1);
225 // debug($theKey,1);
226 if (strcmp($parts[0],"") && is_array($theSetup[$parts[0]."."])) {
227 // debug(trim($parts[1]),1);
228 if (strcmp(trim($parts[1]),"")) {
229 // debug(trim($parts[1]),1);
230 return $this->ext_getSetup($theSetup[$parts[0]."."],trim($parts[1]));
231 } else {
232 return array($theSetup[$parts[0]."."], $theSetup[$parts[0]]);
233 }
234 } else {
235 if (strcmp(trim($theKey),"")) {
236 return array(array(),$theSetup[$theKey]);
237 } else {
238 return array($theSetup,"");
239 }
240 }
241 }
242 function ext_getObjTree($arr, $depth_in, $depthData, $parentType="",$parentValue="") {
243 $HTML="";
244 $a=0;
245
246 reset($arr);
247 $keyArr_num=array();
248 $keyArr_alpha=array();
249 while (list($key,)=each($arr)) {
250 $key=ereg_replace("\.$","",$key);
251 if (substr($key,-1)!=".") {
252 if (t3lib_div::testInt($key)) {
253 $keyArr_num[$key]=$arr[$key];
254 } else {
255 $keyArr_alpha[$key]=$arr[$key];
256 }
257 }
258 }
259 ksort($keyArr_num);
260 $keyArr=$keyArr_num+$keyArr_alpha;
261 reset($keyArr);
262 $c=count($keyArr);
263 if ($depth_in) {$depth_in = $depth_in.".";}
264
265 // $validate_info= verify_TSobjects($keyArr,$parentType,$parentValue);
266 // debug($validate_info);
267
268 while (list($key,)=each($keyArr)) {
269 $a++;
270 $depth=$depth_in.$key;
271 if ($this->bType!="const" || substr($depth,0,1)!="_") { // this excludes all constants starting with "_" from being shown.
272 $goto = substr(md5($depth),0,6);
273 // debug($depth);
274 $deeper = (is_array($arr[$key."."]) && ($this->tsbrowser_depthKeys[$depth] || $this->ext_expandAllNotes)) ? 1 : 0;
275 $PM = "join";
276 $LN = ($a==$c)?"blank":"line";
277 $BTM = ($a==$c)?"bottom":"";
278 $PM = is_array($arr[$key."."]) && !$this->ext_noPMicons ? ($deeper ? "minus":"plus") : "join";
279
280 $HTML.=$depthData;
281 $theIcon='<IMG src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border=0>';
282 if ($PM=="join") {
283 $HTML.=$theIcon;
284 } else {
285 $HTML.='<a name="'.$goto.'" href="index.php?id='.$GLOBALS["SOBE"]->id.'&tsbr['.$depth.']='.($deeper?0:1).'#'.$goto.'">'.$theIcon.'</a>';
286 }
287
288 $label = $key;
289 if (t3lib_div::inList("types,resources,sitetitle",$depth) && $this->bType=="setup") { // Read only...
290 $label='<font color="#666666">'.$label.'</font>';
291 } else {
292 if ($this->linkObjects) {
293 $label = '<a href="index.php?id='.$GLOBALS["SOBE"]->id.'&sObj='.$depth.'">'.$label.'</a>';
294 }
295 }
296 // if (!isset($validate_info[$key])) {
297 // $HTML.='<font color="red">['.$label.']</font>';
298 // } else {
299 $HTML.="[".$label."]";
300 // }
301 if (isset($arr[$key])) {
302 $theValue = $arr[$key];
303 if ($this->fixedLgd) {
304 $imgBlocks = ceil(1+strlen($depthData)/77);
305 // debug($imgBlocks);
306 $lgdChars = 68-ceil(strlen("[".$key."]")*0.8)-$imgBlocks*3;
307 $theValue = $this->ext_fixed_lgd($theValue,$lgdChars);
308 }
309 if ($this->tsbrowser_searchKeys[$depth]) {
310 $HTML.='=<b><font color="red">'.$this->makeHtmlspecialchars($theValue).'</font></b>';
311 } else {
312 $HTML.="=<b>".$this->makeHtmlspecialchars($theValue)."</b>";
313 }
314 }
315 $HTML.="<BR>";
316
317 if ($deeper) {
318 $HTML.=$this->ext_getObjTree($arr[$key."."], $depth, $depthData.'<IMG src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$LN.'.gif" width="18" height="16" align="top">', $validate_info[$key], $arr[$key]);
319 }
320 }
321 }
322 return $HTML;
323 }
324 function makeHtmlspecialchars($theValue){
325 return $this->ext_noSpecialCharsOnLabels ? $theValue : htmlspecialchars($theValue);
326 }
327 function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray) {
328 reset($arr);
329 $keyArr=array();
330 while (list($key,)=each($arr)) {
331 $key=ereg_replace("\.$","",$key);
332 if (substr($key,-1)!=".") {
333 $keyArr[$key]=1;
334 }
335 }
336 reset($keyArr);
337 // asort($keyArr);
338 $c=count($keyArr);
339 if ($depth_in) {$depth_in = $depth_in.".";}
340 while (list($key,)=each($keyArr)) {
341 $depth=$depth_in.$key;
342 $deeper = is_array($arr[$key."."]);
343
344 if ($this->regexMode) {
345 if (ereg($searchString,$arr[$key])) { $this->tsbrowser_searchKeys[$depth]=1; }
346 } else {
347 if (stristr($arr[$key],$searchString)) { $this->tsbrowser_searchKeys[$depth]=1; }
348 }
349
350 if ($deeper) {
351 $cS = count($this->tsbrowser_searchKeys);
352 $keyArray = $this->ext_getSearchKeys($arr[$key."."], $depth, $searchString, $keyArray);
353 if ($cS != count($this->tsbrowser_searchKeys)) {
354 $keyArray[$depth]=1;
355 }
356 }
357 }
358 return $keyArray;
359 }
360 function ext_getRootlineNumber($pid) {
361 if ($pid && is_array($GLOBALS["rootLine"])) {
362 reset($GLOBALS["rootLine"]);
363 while(list($key,$val)=each($GLOBALS["rootLine"])) {
364 if ($val['uid']==$pid) return $key;
365 }
366 }
367 }
368 function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0) {
369 reset($arr);
370 $keyArr=array();
371 while (list($key,)=each($arr)) {
372 $key=ereg_replace("\.$","",$key);
373 if (substr($key,-1)!=".") {
374 $keyArr[$key]=1;
375 }
376 }
377 reset($keyArr);
378 $a=0;
379 $c=count($keyArr);
380 while (list($key,)=each($keyArr)) {
381 $HTML="";
382 $a++;
383 $deeper = is_array($arr[$key."."]);
384 $row=$arr[$key];
385
386 $PM = "join";
387 $LN = ($a==$c)?"blank":"line";
388 $BTM = ($a==$c)?"top":"";
389 $PM = "join";
390
391 $HTML.=$depthData;
392 $icon = substr($row["templateID"],0,3)=="sys" ? t3lib_iconWorks::getIcon("sys_template",array("root"=>$row["root"])) :
393 (substr($row["templateID"],0,6)=="static" ? t3lib_iconWorks::getIcon("static_template",array()) : 'gfx/i/default.gif');
394 $alttext= "[".$row['templateID']."]";
395 $alttext.= $row['pid'] ? " - ".t3lib_BEfunc::getRecordPath($row['pid'],$GLOBALS["SOBE"]->perms_clause,20) : "";
396 if (in_array($row['templateID'],$this->clearList_const) || in_array($row['templateID'],$this->clearList_setup)) {
397 $A_B='<a href="index.php?id='.$GLOBALS["SOBE"]->id.'&template='.$row['templateID'].'">';
398 $A_E="</A>";
399 } else {
400 $A_B="";
401 $A_E="";
402 }
403 $HTML.=($first?'':'<IMG src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border=0>').'<IMG src="'.$GLOBALS["BACK_PATH"].$icon.'" width="18" height="16" align="top" title="'.$alttext.'">'.$A_B.t3lib_div::fixed_lgd($row['title'],$GLOBALS["BE_USER"]->uc["titleLen"]).$A_E."&nbsp;&nbsp;";
404 $RL = $this->ext_getRootlineNumber($row['pid']);
405 $keyArray[] = '<tr>
406 <td nowrap>'.$HTML.'</td>
407 <td align=center>'.($row["root"]?"<b>X</b>":"").'&nbsp;&nbsp;</td>
408 <td align=center'.$row["bgcolor_setup"].'>'.fw(($row["clConf"]?"<b>X</b>":"")."&nbsp;&nbsp;").'</td>
409 <td align=center'.$row["bgcolor_const"].'>'.fw(($row["clConst"]?"<b>X</b>":"")."&nbsp;&nbsp;").'</td>
410 <td>'.($row["pid"]?"&nbsp;".$row["pid"].(strcmp($RL,"")?" (".$RL.")":"")."&nbsp;&nbsp;":"").'</td>
411 <td>'.($row["next"]?"&nbsp;".$row["next"]."&nbsp;&nbsp;":"").'</td>
412 </tr>';
413 if ($deeper) {
414 $keyArray = $this->ext_getTemplateHierarchyArr($arr[$key."."], $depthData.($first?'':'<IMG src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$LN.'.gif" width="18" height="16" align="top">'), $keyArray);
415 }
416 }
417 return $keyArray;
418 }
419 function ext_process_hierarchyInfo($depthDataArr,&$pointer) {
420 $parent = $this->hierarchyInfo[$pointer-1]['templateParent'];
421 while ($pointer>0 && $this->hierarchyInfo[$pointer-1]['templateParent']==$parent) {
422 $pointer--;
423 $row = $this->hierarchyInfo[$pointer];
424
425 $depthDataArr[$row['templateID']]=$row;
426 $depthDataArr[$row['templateID']]["bgcolor_setup"] = isset($this->clearList_setup_temp[$row['templateID']])?' bgColor="'.$GLOBALS["SOBE"]->doc->bgColor5.'"':'';
427 $depthDataArr[$row['templateID']]["bgcolor_const"] = isset($this->clearList_const_temp[$row['templateID']])?' bgColor="'.$GLOBALS["SOBE"]->doc->bgColor5.'"':'';
428 unset($this->clearList_setup_temp[$row['templateID']]);
429 unset($this->clearList_const_temp[$row['templateID']]);
430 $this->templateTitles[$row['templateID']]=$row["title"];
431
432 if ($row['templateID']==$this->hierarchyInfo[$pointer-1]['templateParent']) {
433 $depthDataArr[$row['templateID']."."] = $this->ext_process_hierarchyInfo(array(), $pointer);
434 }
435 }
436 return $depthDataArr;
437 }
438 function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0) {
439 $all="";
440 reset($config);
441 while (list(,$str)=each($config)) {
442 $all.="\n[GLOBAL]\n".$str;
443 }
444
445 if ($syntaxHL) {
446 $all = ereg_replace("^[^".chr(10)."]*.","",$all);
447 $all = chop($all);
448 $tsparser = t3lib_div::makeInstance("t3lib_TSparser");
449 $tsparser->lineNumberOffset=$this->ext_lineNumberOffset+1;
450 return $tsparser->doSyntaxHighlight($all,$lineNumbers?array($this->ext_lineNumberOffset+1):'',$syntaxHLBlockmode);
451 } else {
452 return $this->ext_formatTS($all,$lineNumbers,$comments,$crop);
453 }
454 }
455 function ext_fixed_lgd($string,$chars) {
456 // Returns a new string of max. $chars lenght
457 // If the string is longer, it will be truncated and prepended with "..."
458 // $chars must be an integer of at least 4
459 if ($chars >= 4) {
460 if(strlen($string)>$chars) {
461 return substr($string, 0, $chars-3)."...";
462 }
463 }
464 return $string;
465 }
466 function ext_lnBreakPointWrap($ln,$str) {
467 return '<A href="#" onClick="return brPoint('.$ln.','.($this->ext_lineNumberOffset_mode=="setup"?1:0).');">'.$str.'</a>';
468 }
469 function ext_formatTS($input, $ln, $comments=1, $crop=0) {
470 $input = ereg_replace("^[^".chr(10)."]*.","",$input);
471 $input = chop($input);
472 $cArr = explode(chr(10),$input);
473
474 reset($cArr);
475 $n = ceil(log10(count($cArr)+$this->ext_lineNumberOffset));
476 $lineNum="";
477 while(list($k,$v)=each($cArr)) {
478 $lln=$k+$this->ext_lineNumberOffset+1;
479 if ($ln) $lineNum = $this->ext_lnBreakPointWrap($lln,str_replace(" ",'&nbsp;',sprintf("% ".$n."d",$lln))).": ";
480 $v=htmlspecialchars($v);
481 if ($crop) {$v=$this->ext_fixed_lgd($v,($ln?71:77));}
482 $cArr[$k] = $lineNum.str_replace(" ",'&nbsp;',$v);
483
484 $firstChar = substr(trim($v),0,1);
485 if ($firstChar=="[") {
486 $cArr[$k] = '<font color="green"><b>'.$cArr[$k].'</b></font>';
487 } elseif ($firstChar=="/" || $firstChar=="#") {
488 if ($comments) {
489 $cArr[$k] = '<font color="#666666">'.$cArr[$k].'</font>';
490 } else {
491 unset($cArr[$k]);
492 }
493 }
494
495 /* if (ereg('\{\$[^\}]*\}',$v,$reg)) {
496 while(list(,$f)=each($reg)) {
497 debug($reg);
498 if ($f) {
499 $cArr[$k] = str_replace(htmlspecialchars($f),'<font color="green"><b>'.htmlspecialchars($f).'</b></font>',$cArr[$k]);
500 // debug($f);
501 }
502 }
503 }*/
504 }
505 $output = implode($cArr, "<BR>")."<BR>";
506 // $output = '<font face=verdana size=1 color=maroon>'.$output.'</font>';
507 return $output;
508 }
509 function ext_getFirstTemplate($id,$template_uid=0) {
510 // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
511 if (intval($id)) {
512 if ($template_uid) {
513 $addC = " AND uid=".$template_uid;
514 }
515 $query = "SELECT * FROM sys_template WHERE pid = ".intval($id).$addC." ".$this->whereClause." ORDER BY sorting LIMIT 1";
516 $res = mysql(TYPO3_db, $query);
517 echo mysql_error();
518 $row = mysql_fetch_assoc($res);
519 return $row; // Returns the template row if found.
520 }
521 }
522 function ext_getAllTemplates($id) {
523 // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
524 if (intval($id)) {
525 $query = "SELECT * FROM sys_template WHERE pid = ".intval($id)." ".$this->whereClause." ORDER BY sorting";
526 $res = mysql(TYPO3_db, $query);
527 echo mysql_error();
528 $outRes=array();
529 while($row = mysql_fetch_assoc($res)) {
530 $outRes[] = $row;
531 }
532 return $outRes; // Returns the template rows in an array.
533 }
534 }
535 function ext_compareFlatSetups($default) {
536 // This function compares the flattened constants (default and all).
537 // Returns an array with the constants from the whole template which may be edited by the module.
538
539 $editableComments=array();
540 reset($this->flatSetup);
541 while(list($const,$value)=each($this->flatSetup)) {
542 if (substr($const,-2)!=".." && isset($this->flatSetup[$const.".."])) {
543 $comment = trim($this->flatSetup[$const.".."]);
544 $c_arr = explode(chr(10),$comment);
545 while(list($k,$v)=each($c_arr)) {
546 $line=trim(ereg_replace("^[#\/]*","",$v));
547 if ($line) {
548 $parts = explode(";", $line);
549 while(list(,$par)=each($parts)) {
550 if (strstr($par,"=")) {
551 $keyValPair =explode("=",$par,2);
552 switch(trim(strtolower($keyValPair[0]))) {
553 case "type":
554 // Type:
555 /*
556 int (range; low-high, list: item,item,item = selector),
557 boolean (check),
558 string (default),
559 wrap,
560 html-color ...,
561 file
562 */
563 $editableComments[$const]["type"] = trim($keyValPair[1]);
564 break;
565 case "cat":
566 // list of categories.
567 $catSplit=explode("/",strtolower($keyValPair[1]));
568 $editableComments[$const]["cat"] = trim($catSplit[0]);
569 $catSplit[1]=trim($catSplit[1]); // This is the subcategory. Must be a key in $this->subCategories[]. catSplit[2] represents the search-order within the subcat.
570 if ($catSplit[1] && isset($this->subCategories[$catSplit[1]])) {
571 $editableComments[$const]["subcat_name"]=$catSplit[1];
572 $editableComments[$const]["subcat"]=$this->subCategories[$catSplit[1]][1]."/".$catSplit[1]."/".trim($catSplit[2])."z";
573 } else {
574 $editableComments[$const]["subcat"]="x"."/".trim($catSplit[2])."z";
575 }
576 break;
577 case "label":
578 // label
579 $editableComments[$const]["label"] = trim($keyValPair[1]);
580 break;
581 }
582 }
583 }
584 }
585 }
586 }
587 if (isset($editableComments[$const])) {
588 $editableComments[$const]["name"]=$const;
589 $editableComments[$const]["value"]=trim($value);
590 if (isset($default[$const])) {
591 $editableComments[$const]["default_value"]=trim($default[$const]);
592 }
593 }
594 }
595 return $editableComments;
596 }
597 function ext_categorizeEditableConstants($editConstArray) {
598 // Runs through the available constants and fills the $this->categories array with pointers and priority-info
599 reset($editConstArray);
600 while(list($constName,$constData)=each($editConstArray)) {
601 if (!$constData["type"]) {$constData["type"]="string";}
602 $cats = explode(",",$constData["cat"]);
603 reset($cats);
604 while (list(,$theCat)=each($cats)) { // if = only one category, while allows for many. We have agreed on only one category is the most basic way...
605 $theCat=trim($theCat);
606 if ($theCat) {
607 $this->categories[$theCat][$constName]=$constData["subcat"];
608 // $this->categories["all"][$constName]=$constData["subcat"];
609 }
610 }
611 }
612 // debug($this->categories);
613 }
614 function ext_getCategoryLabelArray() {
615 // Returns array used for labels in the menu.
616 $retArr = array();
617 while(list($k,$v)=each($this->categories)) {
618 if (count($v)) {
619 $retArr[$k]=strtoupper($k)." (".count($v).")";
620 }
621 }
622 return $retArr;
623 }
624 function ext_getTypeData($type) {
625 $retArr = array();
626 $type=trim($type);
627 if (!$type) {
628 $retArr["type"]="string";
629 } else {
630 $m=strcspn ($type," [");
631 $retArr["type"]=strtolower(substr($type,0,$m));
632 if (t3lib_div::inList("int,options,file,boolean,offset",$retArr["type"])) {
633 $p=trim(substr($type,$m));
634 ereg("\[(.*)\]",$p,$reg);
635 $p=trim($reg[1]);
636 if ($p) {
637 $retArr["paramstr"]=$p;
638 switch($retArr["type"]) {
639 case "int":
640 if (substr($retArr["paramstr"],0,1)=="-") {
641 $retArr["params"]=t3lib_div::intExplode("-",substr($retArr["paramstr"],1));
642 $retArr["params"][0]=intval("-".$retArr["params"][0]);
643 } else {
644 $retArr["params"]=t3lib_div::intExplode("-",$retArr["paramstr"]);
645 }
646 $retArr["paramstr"]=$retArr["params"][0]." - ".$retArr["params"][1];
647 break;
648 case "options":
649 $retArr["params"]=explode(",",$retArr["paramstr"]);
650 break;
651 }
652 }
653 }
654 }
655 // debug($retArr);
656 return $retArr;
657 }
658 function ext_getTSCE_config($category) {
659 $catConf=$this->setup["constants"]["TSConstantEditor."][$category."."];
660 $out=array();
661 if (is_array($catConf)) {
662 reset($catConf);
663 while(list($key,$val)=each($catConf)) {
664 switch($key) {
665 case "image":
666 $out["imagetag"] = $this->ext_getTSCE_config_image($catConf["image"]);
667 break;
668 case "description":
669 case "bulletlist":
670 case "header":
671 $out[$key] = $val;
672 break;
673 default:
674 if (t3lib_div::testInt($key)) {
675 $constRefs = explode(",",$val);
676 reset($constRefs);
677 while(list(,$const)=each($constRefs)) {
678 $const=trim($const);
679 if ($const && $const<=20) {
680 $out["constants"][$const].=$this->ext_getKeyImage($key);
681 }
682 }
683 }
684 break;
685 }
686 }
687 }
688 $this->helpConfig=$out;
689 }
690 function ext_getKeyImage($key) {
691 return '<img src="'.$this->ext_localWebGfxPrefix.'gfx/'.$key.'.gif" align="top" hspace=2>';
692 }
693 function ext_getTSCE_config_image($imgConf) {
694 if (substr($imgConf,0,4)=="gfx/") {
695 $iFile=$this->ext_localGfxPrefix.$imgConf;
696 $tFile=$this->ext_localWebGfxPrefix.$imgConf;
697 } elseif (substr($imgConf,0,4)=='EXT:') {
698 $iFile = t3lib_div::getFileAbsFileName($imgConf);
699 if ($iFile) {
700 $f = substr($iFile,strlen(PATH_site));
701 $tFile="../".$GLOBALS["BACK_PATH"].$f;
702 }
703 } else {
704 $f = "uploads/tf/".$this->extractFromResources($this->setup["resources"],$imgConf);
705 $iFile=PATH_site.$f;
706 $tFile="../".$GLOBALS["BACK_PATH"].$f;
707 }
708 $imageInfo=@getImagesize($iFile);
709 return '<img src="'.$tFile.'" '.$imageInfo[3].'>';
710 }
711 function ext_resourceDims() {
712 if ($this->setup["resources"]) {
713 $rArr=explode(",",$this->setup["resources"]);
714 while(list($c,$val)=each($rArr)) {
715 $val=trim($val);
716 $theFile = PATH_site."uploads/tf/".$val;
717 if ($val && @is_file($theFile)) {
718 $imgInfo = @getimagesize($theFile);
719 }
720 if (is_array($imgInfo)) {
721 $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
722 }
723 }
724 }
725 reset($this->dirResources);
726 while(list($c,$val)=each($this->dirResources)) {
727 $val=trim($val);
728 $imgInfo = @getimagesize(PATH_site.$val);
729 if (is_array($imgInfo)) {
730 $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
731 }
732 }
733 }
734 function ext_readDirResources($path) {
735 $path=trim($path);
736 if ($path && substr($path,0,10)=="fileadmin/") {
737 $path = ereg_replace("\/$","",$path);
738 $this->readDirectory(PATH_site.$path);
739 }
740 }
741 function readDirectory($path,$type="file") {
742 if(@is_dir($path)) {
743 $d = @dir($path);
744 $tempArray=Array();
745 if (is_object($d)) {
746 while($entry=$d->read()) {
747 if ($entry!="." && $entry!="..") {
748 $wholePath = $path."/".$entry; // Because of odd PHP-error where <BR>-tag is sometimes placed after a filename!!
749 if (@file_exists($wholePath) && (!$type || filetype($wholePath)==$type)) {
750 $fI = t3lib_div::split_fileref($wholePath);
751 $this->dirResources[]=substr($wholePath,strlen(PATH_site));
752 }
753 }
754 }
755 $d->close();
756 }
757 }
758 }
759 function ext_fNandV($params) {
760 $fN='data['.$params["name"].']';
761 $fV=$params["value"];
762 if (ereg("^{[\$][a-zA-Z0-9\.]*}$",trim($fV),$reg)) { // Values entered from the constantsedit cannot be constants! 230502; removed \{ and set {
763 $fV="";
764 }
765 $fV=htmlspecialchars($fV);
766
767 return array($fN,$fV,$params);
768 }
769 function ext_printFields($theConstants,$category) {
770 // This functions returns the HTML-code that creates the editor-layout of the module.
771 reset($theConstants);
772 $output="";
773 $subcat="";
774 if (is_array($this->categories[$category])) {
775
776 $help=$this->helpConfig;
777 $this->rArr=explode(",",$this->setup["resources"].",".implode($this->dirResources,","));
778
779 asort($this->categories[$category]);
780 while(list($name,$type)=each($this->categories[$category])) {
781 $params = $theConstants[$name];
782 if (is_array($params)) {
783 if ($subcat!=$params["subcat_name"]) {
784 $subcat=$params["subcat_name"];
785 $subcat_name = $params["subcat_name"] ? $this->subCategories[$params["subcat_name"]][0] : "Others";
786 $output.='<tr>';
787 $output.='<td colspan=2 bgColor="'.$GLOBALS["SOBE"]->doc->bgColor4.'"><div align="center"><b>'.$subcat_name.'</b></div></td>';
788 $output.='</tr>';
789 }
790
791 // if (substr($params["value"],0,2)!='{$') {
792 $label=$GLOBALS["LANG"]->sL($params["label"]);
793 $label_parts = explode(":",$label,2);
794 if (count($label_parts)==2) {
795 $head=trim($label_parts[0]);
796 $body=trim($label_parts[1]);
797 } else {
798 $head=trim($label_parts[0]);
799 $body="";
800 }
801 if (strlen($head)>35) {
802 if (!$body) {$body=$head;}
803 $head=t3lib_div::fixed_lgd($head,35);
804 }
805 $typeDat=$this->ext_getTypeData($params["type"]);
806 $checked="";
807 $p_field="";
808 $raname = substr(md5($params["name"]),0,10);
809 $aname="'".$raname."'";
810 if ($this->ext_dontCheckIssetValues || isset($this->objReg[$params["name"]])) {
811 $checked=" checked";
812 list($fN,$fV,$params)=$this->ext_fNandV($params);
813
814 switch($typeDat["type"]) {
815 case "int":
816 case "int+":
817 $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(5).' onChange="uFormUrl('.$aname.')">';
818 if ($typeDat["paramstr"]) {
819 $p_field.=' Range: '.$typeDat["paramstr"];
820 } elseif ($typeDat["type"]=="int+") {
821 $p_field.=' Range: 0 - ';
822 } else {
823 $p_field.=' (Integer)';
824 }
825 break;
826 case "color":
827 $colorNames=explode(",",",".$this->HTMLcolorList);
828 $p_field="";
829 while(list(,$val)=each($colorNames)) {
830 $sel="";
831 if ($val==strtolower($params["value"])) {$sel=" selected";}
832 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.'</option>';
833 }
834 $p_field='<select name="C'.$fN.'" onChange="document.'.$this->ext_CEformName.'[\''.$fN.'\'].value=this.options[this.selectedIndex].value; uFormUrl('.$aname.');">'.$p_field.'</select>';
835
836 $p_field.='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(7).' onChange="uFormUrl('.$aname.')">';
837 break;
838 case "wrap":
839 $wArr = explode("|",$fV);
840 $p_field='<input type="text" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(29).' onChange="uFormUrl('.$aname.')">';
841 $p_field.=' | ';
842 $p_field.='<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(15).' onChange="uFormUrl('.$aname.')">';
843 break;
844 case "offset":
845 $wArr = explode(",",$fV);
846 $labels = t3lib_div::trimExplode(",",$typeDat["paramstr"]);
847 $p_field=($labels[0]?$labels[0]:"x").':<input type="text" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
848 $p_field.=' , ';
849 $p_field.=($labels[1]?$labels[1]:"y").':<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
850 for ($aa=2;$aa<count($labels);$aa++) {
851 if ($labels[$aa]) {
852 $p_field.=' , '.$labels[$aa].':<input type="text" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
853 } else {
854 $p_field.='<input type="hidden" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'">';
855 }
856 }
857 break;
858 case "options":
859 if (is_array($typeDat["params"])) {
860 $p_field="";
861 while(list(,$val)=each($typeDat["params"])) {
862 $vParts = explode("=",$val,2);
863 $label = $vParts[0];
864 $val = isset($vParts[1]) ? $vParts[1] : $vParts[0];
865
866 // option tag:
867 $sel="";
868 if ($val==$params["value"]) {$sel=" selected";}
869 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$GLOBALS["LANG"]->sL($label).'</option>';
870 }
871 $p_field='<select name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
872 }
873 break;
874 case "boolean":
875 $p_field='<input type="Hidden" name="'.$fN.'" value="0">';
876 $sel=""; if ($fV) {$sel=" checked";}
877 $p_field.='<input type="Checkbox" name="'.$fN.'" value="'.($typeDat["paramstr"]?$typeDat["paramstr"]:1).'"'.$sel.' onClick="uFormUrl('.$aname.')">';
878 break;
879 case "comment":
880 $p_field='<input type="Hidden" name="'.$fN.'" value="#">';
881 $sel=""; if (!$fV) {$sel=" checked";}
882 $p_field.='<input type="Checkbox" name="'.$fN.'" value=""'.$sel.' onClick="uFormUrl('.$aname.')">';
883 break;
884 case "file":
885 $p_field='<option value=""></option>';
886 // debug($params["value"]);
887 $theImage="";
888 // if ($this->) {
889 $selectThisFile = $this->extractFromResources($this->setup["resources"],$params["value"]);
890 if ($params["value"] && !$selectThisFile) {
891 if (in_array($params["value"],$this->dirResources)) {
892 $selectThisFile=$params["value"];
893 }
894 }
895 // debug($selectThisFile);
896 // extensionlist
897 $extList = $typeDat["paramstr"];
898 $p_field='<option value="">('.$extList.')</option>';
899 if ($extList=="IMAGE_EXT") {
900 $extList = $GLOBALS["TYPO3_CONF_VARS"]["GFX"]["imagefile_ext"];
901 }
902 reset($this->rArr);
903 $onlineResourceFlag=$this->ext_defaultOnlineResourceFlag;
904
905 while(list($c,$val)=each($this->rArr)) {
906 $val=trim($val);
907 $fI=t3lib_div::split_fileref($val);
908 // debug($fI);
909 if ($val && (!$extList || t3lib_div::inList($extList,$fI["fileext"]))) {
910 if ($onlineResourceFlag<=0 && substr($fI["path"],0,10)=="fileadmin/") {
911 if ($onlineResourceFlag<0) {
912 $p_field.='<option value=""></option>';
913 }
914 $p_field.='<option value="">__'.$fI["path"].'__:</option>';
915 $onlineResourceFlag=1;
916 }
917 $dims=$this->resourceDimensions[$val];
918 $sel="";
919
920 // Check if $params["value"] is in the list of resources.
921 if ($selectThisFile && $selectThisFile==$val) {
922 $sel=" selected";
923 if ($onlineResourceFlag<=0) {
924 $theImage=t3lib_BEfunc::thumbCode(array("resources"=>$selectThisFile),"sys_template","resources",$GLOBALS["BACK_PATH"],"");
925 } else {
926 $theImage=t3lib_BEfunc::thumbCode(array("resources"=>$fI["file"]),"sys_template","resources",$GLOBALS["BACK_PATH"],"",$fI["path"]);
927 }
928 }
929
930 if ($onlineResourceFlag<=0) {
931 $onlineResourceFlag--;
932 // Value is set with a *
933 $val = $this->ext_setStar($val);
934 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.$dims.'</option>';
935 } else {
936 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$fI["file"].$dims.'</option>';
937 }
938 }
939 }
940 if (trim($params["value"]) && !$selectThisFile) {
941 $val = $params["value"];
942 $p_field.='<option value=""></option>';
943 $p_field.='<option value="'.htmlspecialchars($val).'" selected>'.$val.'</option>';
944 }
945 // }
946 $p_field='<select name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
947 $p_field.=$theImage;
948
949 if (!$this->ext_noCEUploadAndCopying) {
950 // Copy a resource
951 $copyFile = $this->extractFromResources($this->setup["resources"],$params["value"]);
952 if (!$copyFile) {
953 if ($params["value"]) {
954 $copyFile=PATH_site.$this->ext_detectAndFixExtensionPrefix($params["value"]);
955 }
956 } else {
957 // $copyFile=PATH_site."uploads/tf/".$copyFile;
958 $copyFile="";
959 }
960 #debug($copyFile);
961 if ($copyFile && @is_file($copyFile)) {
962 $p_field.='<img src=clear.gif width=20 height=1><img src="'.$GLOBALS["BACK_PATH"].'gfx/clip_copy.gif" width="12" height="12" border="0"><input type="Checkbox" name="_copyResource['.$params["name"].']" value="'.htmlspecialchars($copyFile).'" onClick="uFormUrl('.$aname.');if (this.checked) {alert(unescape(\''.rawurlencode(sprintf("This will make a copy of the current file, '%s'. Do you really want that?",$params["value"])).'\'));}">';
963 }
964 // Upload?
965 $p_field.='<BR>';
966 $p_field.='<input type="file" name="upload_'.$fN.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth().' onChange="uFormUrl('.$aname.')">';
967 }
968 break;
969 default:
970 case "small":
971 $fwidth= $typeDat["type"]=="small" ? 10 : 46;
972 $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth($fwidth).' onChange="uFormUrl('.$aname.')">';
973 break;
974 }
975 }
976 if (!$this->ext_dontCheckIssetValues) $p_field='<input type="Checkbox" name="check['.$params["name"].']" value="1"'.$checked.' onClick="uFormUrl('.$aname.')">'.$p_field;
977 if ($typeDat["type"]=="color" && substr($params["value"],0,2)!='{$') {
978 $p_field='<table border=0 cellpadding=0 cellspacing=0><tr><td nowrap>'.$p_field.'</td><td>&nbsp;</td><td bgcolor="'.$params["value"].'"><img src="clear.gif" width=50 height=10></td></tr></table>';
979 } else {
980 $p_field='<nobr>'.$p_field.'</nobr><br>';
981 }
982
983 $p_name = '<font color="#666666">['.$params["name"].']</font><BR>';
984 $p_dlabel='<font color="#666666"><b>Default:</b> '.htmlspecialchars($params["default_value"]).'</font><BR>';
985 $p_label = '<b>'.htmlspecialchars($head).'</b>';
986 $p_descrip = $body ? htmlspecialchars($body)."<BR>" : "";
987
988 $output.='<tr>';
989 $output.='<td valign=top nowrap><a name="'.$raname.'"></a>'.$help["constants"][$params["name"]].$p_label.'</td>';
990 $output.='<td valign=top align="right">'.$p_name.'</td>';
991 $output.='</tr>';
992 $output.='<tr>';
993 $output.='<td colspan=2>'.$p_descrip.$p_field.$p_dlabel.'<br></td>';
994 $output.='</tr>';
995 // }
996 } else {
997 debug("Error. Constant did not exits. Should not happen.");
998 }
999 }
1000 $output='<table border=0 cellpadding=0 cellspacing=0>'.$output.'</table>';
1001 }
1002 return $output;
1003 }
1004
1005 // ***************************
1006 // Processing input values
1007 // ***************************
1008 function ext_regObjectPositions($constants) {
1009 // This runs through the lines of the constants-field of the active template and registers the constants-names and linepositions in an array, $this->objReg
1010 $this->raw = explode(chr(10),$constants);
1011 $this->rawP=0;
1012
1013 $this->objReg=array(); // resetting the objReg if the divider is found!!
1014 $this->ext_regObjects("");
1015 }
1016 function ext_regObjects($pre) {
1017 // works with regObjectPositions. "expands" the names of the TypoScript objects
1018 while (isset($this->raw[$this->rawP])) {
1019 $line = ltrim($this->raw[$this->rawP]);
1020 if (strstr($line,$this->edit_divider)) {
1021 $this->objReg=array(); // resetting the objReg if the divider is found!!
1022 }
1023 $this->rawP++;
1024 if ($line) {
1025 if (substr($line,0,1)=="[") {
1026 // return $line;
1027 } elseif (strcspn($line,"}#/")!=0) {
1028 $varL = strcspn($line," {=<");
1029 $var=substr($line,0,$varL);
1030 $line = ltrim(substr($line,$varL));
1031 switch(substr($line,0,1)) {
1032 case "=":
1033 $this->objReg[$pre.$var]=$this->rawP-1;
1034 break;
1035 case "{":
1036 $this->ext_inBrace++;
1037 $this->ext_regObjects($pre.$var.".");
1038 break;
1039 }
1040 $this->lastComment="";
1041 } elseif (substr($line,0,1)=="}") {
1042 $this->lastComment="";
1043 $this->ext_inBrace--;
1044 if ($this->ext_inBrace<0) {
1045 $this->ext_inBrace=0;
1046 } else {
1047 break;
1048 }
1049 }
1050 }
1051 }
1052 }
1053 function ext_putValueInConf($key, $var) {
1054 // Puts the value $var to the TypoScript value $key in the current lines of the templates.
1055 // If the $key is not found in the template constants field, a new line is inserted in the bottom.
1056 $theValue = " ".trim($var);
1057 if (isset($this->objReg[$key])) {
1058 $lineNum = $this->objReg[$key];
1059 $parts = explode("=",$this->raw[$lineNum],2);
1060 if (count($parts)==2) {
1061 $parts[1]= $theValue;
1062 }
1063 $this->raw[$lineNum]=implode($parts,"=");
1064 } else {
1065 $this->raw[]=$key." =".$theValue;
1066 }
1067 $this->changed=1;
1068 }
1069 function ext_removeValueInConf($key) {
1070 // Removes the value in the configuration
1071 if (isset($this->objReg[$key])) {
1072 $lineNum = $this->objReg[$key];
1073 unset($this->raw[$lineNum]);
1074 }
1075 $this->changed=1;
1076 }
1077 function ext_depthKeys($arr,$settings) {
1078 reset($arr);
1079 $tsbrArray=array();
1080 while(list($theK,$theV)=each($arr)) {
1081 $theKeyParts = explode(".",$theK);
1082 $depth="";
1083 $c=count($theKeyParts);
1084 $a=0;
1085 while(list(,$p)=each($theKeyParts)) {
1086 $a++;
1087 $depth.=($depth?".":"").$p;
1088 $tsbrArray[$depth]= ($c==$a) ? $theV : 1;
1089 }
1090 }
1091 // Modify settings
1092 reset($tsbrArray);
1093 while(list($theK,$theV)=each($tsbrArray)) {
1094 if ($theV) {
1095 $settings[$theK] = 1;
1096 } else {
1097 unset($settings[$theK]);
1098 }
1099 }
1100 return $settings;
1101 }
1102 function ext_procesInput($http_post_vars,$http_post_files,$theConstants,$tplRow) {
1103 $data=$http_post_vars["data"];
1104 $check=$http_post_vars["check"];
1105 $copyResource=$http_post_vars["_copyResource"];
1106 $Wdata=$http_post_vars["Wdata"];
1107 $W2data=$http_post_vars["W2data"];
1108 $W3data=$http_post_vars["W3data"];
1109 $W4data=$http_post_vars["W4data"];
1110 $W5data=$http_post_vars["W5data"];
1111
1112 if (is_array($data)) {
1113 reset($data);
1114 while(list($key,$var)=each($data)) {
1115 if (isset($theConstants[$key])) {
1116 if ($this->ext_dontCheckIssetValues || isset($check[$key])) { // If checkbox is set, update the value
1117 list($var) = explode(chr(10),stripslashes($var)); // exploding with linebreak, just to make sure that no multiline input is given!
1118 $typeDat=$this->ext_getTypeData($theConstants[$key]["type"]);
1119 switch($typeDat["type"]) {
1120 case "int":
1121 if ($typeDat["paramstr"]) {
1122 $var=t3lib_div::intInRange($var,$typeDat["params"][0],$typeDat["params"][1]);
1123 } else {
1124 $var=intval($var);
1125 }
1126 break;
1127 case "int+":
1128 $var=t3lib_div::intInRange($var,0,10000);
1129 break;
1130 case "color":
1131 $col=array();
1132 if($var && !t3lib_div::inList($this->HTMLcolorList,strtolower($var))) {
1133 $var = ereg_replace("[^A-Fa-f0-9]*","",$var);
1134 $col[]=HexDec(substr($var,0,2));
1135 $col[]=HexDec(substr($var,2,2));
1136 $col[]=HexDec(substr($var,4,2));
1137 $var="#".strtoupper(substr("0".DecHex($col[0]),-2).substr("0".DecHex($col[1]),-2).substr("0".DecHex($col[2]),-2));
1138 }
1139 break;
1140 case "comment":
1141 if ($val) {
1142 $val="#";
1143 } else {
1144 $val="";
1145 }
1146 break;
1147 case "wrap":
1148 if (isset($Wdata[$key])) {
1149 $var.="|".stripslashes($Wdata[$key]);
1150 }
1151 break;
1152 case "offset":
1153 if (isset($Wdata[$key])) {
1154 $var=intval($var).",".intval($Wdata[$key]);
1155 if (isset($W2data[$key])) {
1156 $var.=",".intval($W2data[$key]);
1157 if (isset($W3data[$key])) {
1158 $var.=",".intval($W3data[$key]);
1159 if (isset($W4data[$key])) {
1160 $var.=",".intval($W4data[$key]);
1161 if (isset($W5data[$key])) {
1162 $var.=",".intval($W5data[$key]);
1163 }
1164 }
1165 }
1166 }
1167 }
1168 break;
1169 case "boolean":
1170 if ($var) {
1171 $var = $typeDat["paramstr"] ? $typeDat["paramstr"] : 1;
1172 }
1173 break;
1174 case "file":
1175 if (!$this->ext_noCEUploadAndCopying) {
1176 if ($http_post_files["upload_data"]["name"][$key] && $http_post_files["upload_data"]["tmp_name"][$key]!="none") {
1177 $var = $this->upload_copy_file(
1178 $typeDat,
1179 $tplRow,
1180 trim($http_post_files["upload_data"]["name"][$key]),
1181 $http_post_files["upload_data"]["tmp_name"][$key]
1182 );
1183 }
1184 if ($copyResource[$key]) {
1185 $var = $this->upload_copy_file(
1186 $typeDat,
1187 $tplRow,
1188 basename($copyResource[$key]),
1189 $copyResource[$key]
1190 );
1191 }
1192 }
1193 break;
1194 }
1195 if ($this->ext_printAll || strcmp($theConstants[$key]["value"],$var)) {
1196 $this->ext_putValueInConf($key, $var); // Put value in, if changed.
1197 }
1198 unset($check[$key]); // Remove the entry because it has been "used"
1199 } else {
1200 $this->ext_removeValueInConf($key);
1201 }
1202 }
1203 }
1204 }
1205 // Remaining keys in $check indicates fields that are just clicked "on" to be edited. Therefore we get the default value and puts that in the template as a start...
1206 if (!$this->ext_dontCheckIssetValues && is_array($check)) {
1207 reset($check);
1208 while(list($key,$var)=each($check)) {
1209 if (isset($theConstants[$key])) {
1210 $dValue = $theConstants[$key]["default_value"];
1211 // debug($dValue);
1212 $this->ext_putValueInConf($key, $dValue);
1213 // debug($key,1);
1214 }
1215 }
1216 }
1217 // debug($this->objReg);
1218 }
1219 function upload_copy_file($typeDat,&$tplRow,$theRealFileName,$tmp_name) {
1220 // extensions
1221 $extList = $typeDat["paramstr"];
1222 if ($extList=="IMAGE_EXT") {
1223 $extList = $GLOBALS["TYPO3_CONF_VARS"]["GFX"]["imagefile_ext"];
1224 }
1225 $fI=t3lib_div::split_fileref($theRealFileName);
1226 if ($theRealFileName && (!$extList || t3lib_div::inList($extList,$fI["fileext"]))) {
1227 // Saving resource
1228 $alternativeFileName=array();
1229 $alternativeFileName[$tmp_name] = $theRealFileName;
1230 // Making list of resources
1231 $resList = $tplRow["resources"];
1232 $resList = $tmp_name.",".$resList;
1233 $resList=implode(t3lib_div::trimExplode(",",$resList,1),",");
1234 // Making data-array
1235 $recData=array();
1236 $recData["sys_template"][$tplRow["uid"]]["resources"] = $resList;
1237 // Saving
1238 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
1239 $tce->stripslashes_values=0;
1240 $tce->alternativeFileName = $alternativeFileName;
1241 $tce->start($recData,Array());
1242 $tce->process_datamap();
1243
1244 $tmpRow = t3lib_BEfunc::getRecord("sys_template",$tplRow["uid"],"resources");
1245 $tplRow["resources"] = $tmpRow["resources"];
1246
1247 // Setting the value
1248 $var = $this->ext_setStar($theRealFileName);
1249 }
1250 return $var;
1251 }
1252 function ext_prevPageWithTemplate($id,$perms_clause) {
1253 $rootLine = t3lib_BEfunc::BEgetRootLine($id,$perms_clause?" AND ".$perms_clause:"");
1254 reset($rootLine);
1255 while(list(,$p)=each($rootLine)) {
1256 if ($this->ext_getFirstTemplate($p["uid"])) {
1257 return $p;
1258 }
1259 }
1260 }
1261 function ext_setStar($val) {
1262 $fParts = explode(".",strrev($val),2);
1263 $val=ereg_replace("_[0-9][0-9]$","",strrev($fParts[1]))."*.".strrev($fParts[0]);
1264 return $val;
1265 }
1266 function ext_detectAndFixExtensionPrefix($value) {
1267 if (substr($value,0,4)=="EXT:") {
1268 $parts = explode("/",substr($value,4),2);
1269 #debug($parts);
1270 $extPath = t3lib_extMgm::siteRelPath($parts[0]);
1271 $value = $extPath.$parts[1];
1272 return $value;
1273 } else {
1274 return $value;
1275 }
1276 }
1277 }
1278
1279
1280 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["t3lib/class.t3lib_tsparser_ext.php"]) {
1281 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["t3lib/class.t3lib_tsparser_ext.php"]);
1282 }
1283 ?>