This commit was manufactured by cvs2svn to create tag
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tsparser_ext.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 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 * TSParser extension class to t3lib_TStemplate
29 *
30 * $Id$
31 * Contains functions for the TS module in TYPO3 backend
32 *
33 * @author Kasper Skaarhoj <kasper@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 103: class t3lib_tsparser_ext extends t3lib_TStemplate
41 * 191: function flattenSetup($setupArray, $prefix, $resourceFlag)
42 * 218: function substituteConstants($all)
43 * 247: function substituteCMarkers($all)
44 * 269: function generateConfig_constants()
45 * 318: function ext_getSetup($theSetup,$theKey)
46 * 349: function ext_getObjTree($arr, $depth_in, $depthData, $parentType="",$parentValue="")
47 * 437: function makeHtmlspecialchars($theValue)
48 * 450: function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray)
49 * 490: function ext_getRootlineNumber($pid)
50 * 508: function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0)
51 * 567: function ext_process_hierarchyInfo($depthDataArr,&$pointer)
52 * 598: function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0)
53 * 625: function ext_fixed_lgd($string,$chars)
54 * 641: function ext_lnBreakPointWrap($ln,$str)
55 * 654: function ext_formatTS($input, $ln, $comments=1, $crop=0)
56 * 693: function ext_getFirstTemplate($id,$template_uid=0)
57 * 712: function ext_getAllTemplates($id)
58 * 732: function ext_compareFlatSetups($default)
59 * 798: function ext_categorizeEditableConstants($editConstArray)
60 * 821: function ext_getCategoryLabelArray()
61 * 838: function ext_getTypeData($type)
62 * 879: function ext_getTSCE_config($category)
63 * 918: function ext_getKeyImage($key)
64 * 928: function ext_getTSCE_config_image($imgConf)
65 * 952: function ext_resourceDims()
66 * 982: function ext_readDirResources($path)
67 * 997: function readDirectory($path,$type="file")
68 * 1022: function ext_fNandV($params)
69 * 1040: function ext_printFields($theConstants,$category)
70 *
71 * SECTION: Processing input values
72 * 1297: function ext_regObjectPositions($constants)
73 * 1312: function ext_regObjects($pre)
74 * 1357: function ext_putValueInConf($key, $var)
75 * 1380: function ext_removeValueInConf($key)
76 * 1396: function ext_depthKeys($arr,$settings)
77 * 1431: function ext_procesInput($http_post_vars,$http_post_files,$theConstants,$tplRow)
78 * 1558: function upload_copy_file($typeDat,&$tplRow,$theRealFileName,$tmp_name)
79 * 1604: function ext_prevPageWithTemplate($id,$perms_clause)
80 * 1620: function ext_setStar($val)
81 * 1632: function ext_detectAndFixExtensionPrefix($value)
82 *
83 * TOTAL FUNCTIONS: 39
84 * (This index is automatically created/updated by the extension "extdeveval")
85 *
86 */
87
88 require_once(PATH_t3lib."class.t3lib_tstemplate.php");
89
90
91
92
93
94
95
96 /**
97 * TSParser extension class to t3lib_TStemplate
98 *
99 * @author Kasper Skaarhoj <kasper@typo3.com>
100 * @package TYPO3
101 * @subpackage t3lib
102 */
103 class t3lib_tsparser_ext extends t3lib_TStemplate {
104
105 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.
106 var $HTMLcolorList = "aqua,black,blue,fuchsia,gray,green,lime,maroon,navy,olive,purple,red,silver,teal,yellow,white";
107
108 // internal
109 var $categories = array(
110 "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.
111 "menu" => array(), // Menu setup. This includes fontfiles, sizes, background images. Depending on the menutype.
112 "content" => array(), // All constants related to the display of pagecontent elements
113 "page" => array(), // General configuration like metatags, link targets
114 "advanced" => array(), // Advanced functions, which are used very seldomly.
115 "all" => array() // All constants are put here also!
116 ); // This will be filled with the available categories of the current template.
117 var $subCategories = array(
118 // Standard categories:
119 "enable" => Array("Enable features", "a"),
120 "dims" => Array("Dimensions, widths, heights, pixels", "b"),
121 "file" => Array("Files", "c"),
122 "typo" => Array("Typography", "d"),
123 "color" => Array("Colors", "e"),
124 "links" => Array("Links and targets", "f"),
125 "language" => Array("Language specific constants", "g"),
126
127 // subcategories based on the default content elements
128 "cheader" => Array("Content: 'Header'", "ma"),
129 "cheader_g" => Array("Content: 'Header', Graphical", "ma"),
130 "ctext" => Array("Content: 'Text'", "mb"),
131 // "ctextpic" =>
132 "cimage" => Array("Content: 'Image'", "md"),
133 "cbullets" => Array("Content: 'Bullet list'", "me"),
134 "ctable" => Array("Content: 'Table'", "mf"),
135 "cuploads" => Array("Content: 'Filelinks'", "mg"),
136 "cmultimedia" => Array("Content: 'Multimedia'", "mh"),
137 "cmailform" => Array("Content: 'Form'", "mi"),
138 "csearch" => Array("Content: 'Search'", "mj"),
139 "clogin" => Array("Content: 'Login'", "mk"),
140 "csplash" => Array("Content: 'Textbox'", "ml"),
141 "cmenu" => Array("Content: 'Menu/Sitemap'", "mm"),
142 "cshortcut" => Array("Content: 'Insert records'", "mn"),
143 "clist" => Array("Content: 'List of records'", "mo"),
144 "cscript" => Array("Content: 'Script'", "mp"),
145 "chtml" => Array("Content: 'HTML'", "mq")
146 );
147 var $resourceDimensions = array();
148 var $dirResources = array();
149
150 // var $matchAll = 0; // If set, all conditions are matched!
151
152 var $backend_info=1;
153
154 // tsconstanteditor
155 var $ext_inBrace=0;
156
157 // tsbrowser
158 var $tsbrowser_searchKeys = array();
159 var $tsbrowser_depthKeys = array();
160 var $constantMode="";
161 var $regexMode="";
162 var $fixedLgd="";
163 var $resourceCheck=0;
164 var $ext_lineNumberOffset=0;
165 var $ext_localGfxPrefix="";
166 var $ext_localWebGfxPrefix="";
167 var $ext_expandAllNotes=0;
168 var $ext_noPMicons=0;
169 var $ext_noSpecialCharsOnLabels=0;
170 var $ext_listOfTemplatesArr=array();
171 var $ext_lineNumberOffset_mode="";
172 var $ext_dontCheckIssetValues=0; // Dont change...
173 var $ext_noCEUploadAndCopying=0;
174 var $ext_printAll=0;
175 var $ext_CEformName="forms[0]";
176 var $ext_defaultOnlineResourceFlag=0;
177
178 // ts analyzer
179 var $templateTitles=array();
180
181
182 /**
183 * This flattens a hierarchical setuparray to $this->flatSetup
184 * The original function fetched the resource-file if any ("file."). This functions doesn't.
185 *
186 * @param [type] $setupArray: ...
187 * @param [type] $prefix: ...
188 * @param [type] $resourceFlag: ...
189 * @return [type] ...
190 */
191 function flattenSetup($setupArray, $prefix, $resourceFlag) {
192 if (is_array($setupArray)) {
193 $this->getFileName_backPath=PATH_site; // Setting absolute prefixed path for relative resources.
194 reset($setupArray);
195 while(list($key,$val)=each($setupArray)) {
196 if ($prefix || substr($key,0,16)!="TSConstantEditor") { // We don't want "TSConstantEditor" in the flattend setup.
197 if (is_array($val)) {
198 $this->flattenSetup($val,$prefix.$key, ($key=="file."));
199 } elseif ($resourceFlag && $this->resourceCheck) {
200 $this->flatSetup[$prefix.$key] = $this->getFileName($val);
201 if ($this->removeFromGetFilePath && substr($this->flatSetup[$prefix.$key],0,strlen($this->removeFromGetFilePath))==$this->removeFromGetFilePath) {
202 $this->flatSetup[$prefix.$key] = substr($this->flatSetup[$prefix.$key],strlen($this->removeFromGetFilePath));
203 }
204 } else {
205 $this->flatSetup[$prefix.$key] = $val;
206 }
207 }
208 }
209 }
210 }
211
212 /**
213 * [Describe function...]
214 *
215 * @param [type] $all: ...
216 * @return [type] ...
217 */
218 function substituteConstants($all) {
219 $this->Cmarker=substr(md5(uniqid("")),0,6);
220 reset($this->flatSetup);
221 while (list($const,$val)=each($this->flatSetup)) {
222 if (!is_array($val)) {
223 switch($this->constantMode) {
224 case "const":
225 $all = str_replace('{$'.$const.'}','##'.$this->Cmarker.'_B##{$'.$const.'}##'.$this->Cmarker.'_E##',$all);
226 break;
227 case "subst":
228 $all = str_replace('{$'.$const.'}','##'.$this->Cmarker.'_B##'.$val.'##'.$this->Cmarker.'_E##',$all);
229 break;
230 case "untouched":
231 break;
232 default:
233 $all = str_replace('{$'.$const.'}',$val,$all);
234 break;
235 }
236 }
237 }
238 return $all;
239 }
240
241 /**
242 * [Describe function...]
243 *
244 * @param [type] $all: ...
245 * @return [type] ...
246 */
247 function substituteCMarkers($all) {
248 switch($this->constantMode) {
249 case "const":
250 $all = str_replace('##'.$this->Cmarker.'_B##', '<font color="green"><B>', $all);
251 $all = str_replace('##'.$this->Cmarker.'_E##', '</b></font>', $all);
252 break;
253 case "subst":
254 $all = str_replace('##'.$this->Cmarker.'_B##', '<font color="green"><B>', $all);
255 $all = str_replace('##'.$this->Cmarker.'_E##', '</b></font>', $all);
256 break;
257 default:
258 $all = $all;
259 break;
260 }
261 return $all;
262 }
263
264 /**
265 * [Describe function...]
266 *
267 * @return [type] ...
268 */
269 function generateConfig_constants() {
270 // Parses the constants in $this->const with respect to the constant-editor in this module.
271 // In particular comments in the code are registered and the edit_divider is taken into account.
272 // These vars are also set lateron...
273 $this->setup["resources"]= $this->resources;
274 $this->setup["sitetitle"]= $this->sitetitle;
275
276 // parse constants
277 $constants = t3lib_div::makeInstance("t3lib_TSparser");
278 $constants->regComments=1; // Register comments!
279 $constants->setup = $this->const;
280 $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup);
281
282 $matchObj = t3lib_div::makeInstance("t3lib_matchCondition");
283 // $matchObj->matchAlternative = array("[globalString = page | title = *test*]");
284 $matchObj->matchAll=1; // Matches ALL conditions in TypoScript
285
286 $c=0;
287 $cc=count($this->constants);
288 reset($this->constants);
289 while (list(,$str)=each($this->constants)) {
290 $c++;
291 if ($c==$cc) {
292 if (strstr($str,$this->edit_divider)) {
293 $parts = explode($this->edit_divider,$str,2);
294 $str=$parts[1];
295 $constants->parse($parts[0],$matchObj);
296 }
297 $this->flatSetup = Array();
298 $this->flattenSetup($constants->setup,"","");
299 $defaultConstants=$this->flatSetup;
300 }
301 $constants->parse($str,$matchObj);
302 }
303
304 $this->flatSetup = Array();
305 $this->flattenSetup($constants->setup,"","");
306 $this->setup["constants"] = $constants->setup;
307
308 return $this->ext_compareFlatSetups($defaultConstants);
309 }
310
311 /**
312 * [Describe function...]
313 *
314 * @param [type] $theSetup: ...
315 * @param [type] $theKey: ...
316 * @return [type] ...
317 */
318 function ext_getSetup($theSetup,$theKey) {
319 $parts = explode(".",$theKey,2);
320 // debug("-----------",1);
321 // debug($theKey,1);
322 if (strcmp($parts[0],"") && is_array($theSetup[$parts[0]."."])) {
323 // debug(trim($parts[1]),1);
324 if (strcmp(trim($parts[1]),"")) {
325 // debug(trim($parts[1]),1);
326 return $this->ext_getSetup($theSetup[$parts[0]."."],trim($parts[1]));
327 } else {
328 return array($theSetup[$parts[0]."."], $theSetup[$parts[0]]);
329 }
330 } else {
331 if (strcmp(trim($theKey),"")) {
332 return array(array(),$theSetup[$theKey]);
333 } else {
334 return array($theSetup,"");
335 }
336 }
337 }
338
339 /**
340 * [Describe function...]
341 *
342 * @param [type] $arr: ...
343 * @param [type] $depth_in: ...
344 * @param [type] $depthData: ...
345 * @param [type] $parentType: ...
346 * @param [type] $parentValue: ...
347 * @return [type] ...
348 */
349 function ext_getObjTree($arr, $depth_in, $depthData, $parentType="",$parentValue="") {
350 $HTML="";
351 $a=0;
352
353 reset($arr);
354 $keyArr_num=array();
355 $keyArr_alpha=array();
356 while (list($key,)=each($arr)) {
357 if (substr($key,-2)!="..") { // Don't do anything with comments / linenumber registrations...
358 $key=ereg_replace("\.$","",$key);
359 if (substr($key,-1)!=".") {
360 if (t3lib_div::testInt($key)) {
361 $keyArr_num[$key]=$arr[$key];
362 } else {
363 $keyArr_alpha[$key]=$arr[$key];
364 }
365 }
366 }
367 }
368 ksort($keyArr_num);
369 $keyArr=$keyArr_num+$keyArr_alpha;
370 reset($keyArr);
371 $c=count($keyArr);
372 if ($depth_in) {$depth_in = $depth_in.".";}
373
374 // $validate_info= verify_TSobjects($keyArr,$parentType,$parentValue);
375 // debug($validate_info);
376
377 while (list($key,)=each($keyArr)) {
378 $a++;
379 $depth=$depth_in.$key;
380 if ($this->bType!="const" || substr($depth,0,1)!="_") { // this excludes all constants starting with "_" from being shown.
381 $goto = substr(md5($depth),0,6);
382 // debug($depth);
383 $deeper = (is_array($arr[$key."."]) && ($this->tsbrowser_depthKeys[$depth] || $this->ext_expandAllNotes)) ? 1 : 0;
384 $PM = "join";
385 $LN = ($a==$c)?"blank":"line";
386 $BTM = ($a==$c)?"bottom":"";
387 $PM = is_array($arr[$key."."]) && !$this->ext_noPMicons ? ($deeper ? "minus":"plus") : "join";
388
389 $HTML.=$depthData;
390 $theIcon='<img src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border="0" alt="" />';
391 if ($PM=="join") {
392 $HTML.=$theIcon;
393 } else {
394 $aHref='index.php?id='.$GLOBALS["SOBE"]->id.'&tsbr['.$depth.']='.($deeper?0:1).'#'.$goto;
395 $HTML.='<a name="'.$goto.'" href="'.htmlspecialchars($aHref).'">'.$theIcon.'</a>';
396 }
397
398 $label = $key;
399 if (t3lib_div::inList("types,resources,sitetitle",$depth) && $this->bType=="setup") { // Read only...
400 $label='<font color="#666666">'.$label.'</font>';
401 } else {
402 if ($this->linkObjects) {
403 $aHref = 'index.php?id='.$GLOBALS["SOBE"]->id.'&sObj='.$depth;
404 if ($this->bType!="const") {
405 $ln = is_array($arr[$key.'.ln..']) ? 'Defined in: '.$this->lineNumberToScript($arr[$key.'.ln..']) : 'N/A';
406 } else {
407 $ln = '';
408 }
409 $label = '<a href="'.htmlspecialchars($aHref).'" title="'.htmlspecialchars($ln).'">'.$label.'</a>';
410 }
411 }
412
413 $HTML.="[".$label."]";
414
415 if (isset($arr[$key])) {
416 $theValue = $arr[$key];
417 if ($this->fixedLgd) {
418 $imgBlocks = ceil(1+strlen($depthData)/77);
419 $lgdChars = 68-ceil(strlen("[".$key."]")*0.8)-$imgBlocks*3;
420 $theValue = $this->ext_fixed_lgd($theValue,$lgdChars);
421 }
422 if ($this->tsbrowser_searchKeys[$depth]) {
423 $HTML.='=<b><font color="red">'.$this->makeHtmlspecialchars($theValue).'</font></b>';
424 } else {
425 $HTML.="=<b>".$this->makeHtmlspecialchars($theValue)."</b>";
426 }
427 }
428 $HTML.="<br />";
429
430 if ($deeper) {
431 $HTML.=$this->ext_getObjTree($arr[$key."."], $depth, $depthData.'<img src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$LN.'.gif" width="18" height="16" align="top" alt="" />', $validate_info[$key], $arr[$key]);
432 }
433 }
434 }
435 return $HTML;
436 }
437
438
439 function lineNumberToScript($lnArr) {
440 if (!is_array($this->lnToScript)) {
441 $this->lnToScript = array();
442 $c=1;
443 $c+=substr_count($GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'],chr(10))+2;
444 $this->lnToScript[$c] = '[Default]';
445
446 foreach($this->hierarchyInfoToRoot as $info) {
447 $c+=$info['configLines']+1;
448 $this->lnToScript[$c] = $info['title'];
449 }
450 }
451
452 foreach($lnArr as $k => $ln) {
453 foreach($this->lnToScript as $endLn => $title) {
454 if ($endLn >= intval($ln)) {
455 $lnArr[$k] = '"'.$title.'", '.$ln;
456 break;
457 }
458 }
459 }
460
461 return implode('; ',$lnArr);
462 }
463
464 /**
465 * [Describe function...]
466 *
467 * @param [type] $theValue: ...
468 * @return [type] ...
469 */
470 function makeHtmlspecialchars($theValue){
471 return $this->ext_noSpecialCharsOnLabels ? $theValue : htmlspecialchars($theValue);
472 }
473
474 /**
475 * [Describe function...]
476 *
477 * @param [type] $arr: ...
478 * @param [type] $depth_in: ...
479 * @param [type] $searchString: ...
480 * @param [type] $keyArray: ...
481 * @return [type] ...
482 */
483 function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray) {
484 reset($arr);
485 $keyArr=array();
486 while (list($key,)=each($arr)) {
487 $key=ereg_replace("\.$","",$key);
488 if (substr($key,-1)!=".") {
489 $keyArr[$key]=1;
490 }
491 }
492 reset($keyArr);
493 // asort($keyArr);
494 $c=count($keyArr);
495 if ($depth_in) {$depth_in = $depth_in.".";}
496 while (list($key,)=each($keyArr)) {
497 $depth=$depth_in.$key;
498 $deeper = is_array($arr[$key."."]);
499
500 if ($this->regexMode) {
501 if (ereg($searchString,$arr[$key])) { $this->tsbrowser_searchKeys[$depth]=1; }
502 } else {
503 if (stristr($arr[$key],$searchString)) { $this->tsbrowser_searchKeys[$depth]=1; }
504 }
505
506 if ($deeper) {
507 $cS = count($this->tsbrowser_searchKeys);
508 $keyArray = $this->ext_getSearchKeys($arr[$key."."], $depth, $searchString, $keyArray);
509 if ($cS != count($this->tsbrowser_searchKeys)) {
510 $keyArray[$depth]=1;
511 }
512 }
513 }
514 return $keyArray;
515 }
516
517 /**
518 * [Describe function...]
519 *
520 * @param [type] $pid: ...
521 * @return [type] ...
522 */
523 function ext_getRootlineNumber($pid) {
524 if ($pid && is_array($GLOBALS["rootLine"])) {
525 reset($GLOBALS["rootLine"]);
526 while(list($key,$val)=each($GLOBALS["rootLine"])) {
527 if ($val['uid']==$pid) return $key;
528 }
529 }
530 }
531
532 /**
533 * [Describe function...]
534 *
535 * @param [type] $arr: ...
536 * @param [type] $depthData: ...
537 * @param [type] $keyArray: ...
538 * @param [type] $first: ...
539 * @return [type] ...
540 */
541 function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0) {
542 reset($arr);
543 $keyArr=array();
544 while (list($key,)=each($arr)) {
545 $key=ereg_replace("\.$","",$key);
546 if (substr($key,-1)!=".") {
547 $keyArr[$key]=1;
548 }
549 }
550 reset($keyArr);
551 $a=0;
552 $c=count($keyArr);
553 while (list($key,)=each($keyArr)) {
554 $HTML="";
555 $a++;
556 $deeper = is_array($arr[$key."."]);
557 $row=$arr[$key];
558
559 $PM = "join";
560 $LN = ($a==$c)?"blank":"line";
561 $BTM = ($a==$c)?"top":"";
562 $PM = "join";
563
564 $HTML.=$depthData;
565 $icon = substr($row["templateID"],0,3)=="sys" ? t3lib_iconWorks::getIcon("sys_template",array("root"=>$row["root"])) :
566 (substr($row["templateID"],0,6)=="static" ? t3lib_iconWorks::getIcon("static_template",array()) : 'gfx/i/default.gif');
567 $alttext= "[".$row['templateID']."]";
568 $alttext.= $row['pid'] ? " - ".t3lib_BEfunc::getRecordPath($row['pid'],$GLOBALS["SOBE"]->perms_clause,20) : "";
569 if (in_array($row['templateID'],$this->clearList_const) || in_array($row['templateID'],$this->clearList_setup)) {
570 $A_B='<a href="index.php?id='.$GLOBALS["SOBE"]->id.'&template='.$row['templateID'].'">';
571 $A_E="</A>";
572 } else {
573 $A_B="";
574 $A_E="";
575 }
576 $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;";
577 $RL = $this->ext_getRootlineNumber($row['pid']);
578 $keyArray[] = '<tr>
579 <td nowrap>'.$HTML.'</td>
580 <td align=center>'.($row["root"]?"<b>X</b>":"").'&nbsp;&nbsp;</td>
581 <td align=center'.$row["bgcolor_setup"].'>'.fw(($row["clConf"]?"<b>X</b>":"")."&nbsp;&nbsp;").'</td>
582 <td align=center'.$row["bgcolor_const"].'>'.fw(($row["clConst"]?"<b>X</b>":"")."&nbsp;&nbsp;").'</td>
583 <td>'.($row["pid"]?"&nbsp;".$row["pid"].(strcmp($RL,"")?" (".$RL.")":"")."&nbsp;&nbsp;":"").'</td>
584 <td>'.($row["next"]?"&nbsp;".$row["next"]."&nbsp;&nbsp;":"").'</td>
585 </tr>';
586 if ($deeper) {
587 $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);
588 }
589 }
590 return $keyArray;
591 }
592
593 /**
594 * [Describe function...]
595 *
596 * @param [type] $depthDataArr: ...
597 * @param [type] $pointer: ...
598 * @return [type] ...
599 */
600 function ext_process_hierarchyInfo($depthDataArr,&$pointer) {
601 $parent = $this->hierarchyInfo[$pointer-1]['templateParent'];
602 while ($pointer>0 && $this->hierarchyInfo[$pointer-1]['templateParent']==$parent) {
603 $pointer--;
604 $row = $this->hierarchyInfo[$pointer];
605
606 $depthDataArr[$row['templateID']]=$row;
607 $depthDataArr[$row['templateID']]["bgcolor_setup"] = isset($this->clearList_setup_temp[$row['templateID']])?' class="bgColor5"':'';
608 $depthDataArr[$row['templateID']]["bgcolor_const"] = isset($this->clearList_const_temp[$row['templateID']])?' class="bgColor5"':'';
609 unset($this->clearList_setup_temp[$row['templateID']]);
610 unset($this->clearList_const_temp[$row['templateID']]);
611 $this->templateTitles[$row['templateID']]=$row["title"];
612
613 if ($row['templateID']==$this->hierarchyInfo[$pointer-1]['templateParent']) {
614 $depthDataArr[$row['templateID']."."] = $this->ext_process_hierarchyInfo(array(), $pointer);
615 }
616 }
617 return $depthDataArr;
618 }
619
620 /**
621 * [Describe function...]
622 *
623 * @param [type] $config: ...
624 * @param [type] $lineNumbers: ...
625 * @param [type] $comments: ...
626 * @param [type] $crop: ...
627 * @param [type] $syntaxHL: ...
628 * @param [type] $syntaxHLBlockmode: ...
629 * @return [type] ...
630 */
631 function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0) {
632 $all="";
633 reset($config);
634 while (list(,$str)=each($config)) {
635 $all.="\n[GLOBAL]\n".$str;
636 }
637
638 if ($syntaxHL) {
639 $all = ereg_replace("^[^".chr(10)."]*.","",$all);
640 $all = chop($all);
641 $tsparser = t3lib_div::makeInstance("t3lib_TSparser");
642 $tsparser->lineNumberOffset=$this->ext_lineNumberOffset+1;
643 return $tsparser->doSyntaxHighlight($all,$lineNumbers?array($this->ext_lineNumberOffset+1):'',$syntaxHLBlockmode);
644 } else {
645 return $this->ext_formatTS($all,$lineNumbers,$comments,$crop);
646 }
647 }
648
649 /**
650 * Returns a new string of max. $chars lenght
651 * If the string is longer, it will be truncated and prepended with "..."
652 * $chars must be an integer of at least 4
653 *
654 * @param [type] $string: ...
655 * @param [type] $chars: ...
656 * @return [type] ...
657 */
658 function ext_fixed_lgd($string,$chars) {
659 if ($chars >= 4) {
660 if(strlen($string)>$chars) {
661 return substr($string, 0, $chars-3)."...";
662 }
663 }
664 return $string;
665 }
666
667 /**
668 * [Describe function...]
669 *
670 * @param [type] $ln: ...
671 * @param [type] $str: ...
672 * @return [type] ...
673 */
674 function ext_lnBreakPointWrap($ln,$str) {
675 return '<A href="#" onClick="return brPoint('.$ln.','.($this->ext_lineNumberOffset_mode=="setup"?1:0).');">'.$str.'</a>';
676 }
677
678 /**
679 * [Describe function...]
680 *
681 * @param [type] $input: ...
682 * @param [type] $ln: ...
683 * @param [type] $comments: ...
684 * @param [type] $crop: ...
685 * @return [type] ...
686 */
687 function ext_formatTS($input, $ln, $comments=1, $crop=0) {
688 $input = ereg_replace("^[^".chr(10)."]*.","",$input);
689 $input = chop($input);
690 $cArr = explode(chr(10),$input);
691
692 reset($cArr);
693 $n = ceil(log10(count($cArr)+$this->ext_lineNumberOffset));
694 $lineNum="";
695 while(list($k,$v)=each($cArr)) {
696 $lln=$k+$this->ext_lineNumberOffset+1;
697 if ($ln) $lineNum = $this->ext_lnBreakPointWrap($lln,str_replace(" ",'&nbsp;',sprintf("% ".$n."d",$lln))).": ";
698 $v=htmlspecialchars($v);
699 if ($crop) {$v=$this->ext_fixed_lgd($v,($ln?71:77));}
700 $cArr[$k] = $lineNum.str_replace(" ",'&nbsp;',$v);
701
702 $firstChar = substr(trim($v),0,1);
703 if ($firstChar=="[") {
704 $cArr[$k] = '<font color="green"><b>'.$cArr[$k].'</b></font>';
705 } elseif ($firstChar=="/" || $firstChar=="#") {
706 if ($comments) {
707 $cArr[$k] = '<span class="typo3-dimmed">'.$cArr[$k].'</span>';
708 } else {
709 unset($cArr[$k]);
710 }
711 }
712
713
714 }
715 $output = implode($cArr, "<BR>")."<BR>";
716 return $output;
717 }
718
719 /**
720 * [Describe function...]
721 *
722 * @param [type] $id: ...
723 * @param [type] $template_uid: ...
724 * @return [type] ...
725 */
726 function ext_getFirstTemplate($id,$template_uid=0) {
727 // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
728 if (intval($id)) {
729 if ($template_uid) {
730 $addC = " AND uid=".$template_uid;
731 }
732 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).$addC.' '.$this->whereClause, '', 'sorting', '1');
733 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
734 $GLOBALS['TYPO3_DB']->sql_free_result($res);
735 return $row; // Returns the template row if found.
736 }
737 }
738
739 /**
740 * [Describe function...]
741 *
742 * @param [type] $id: ...
743 * @return [type] ...
744 */
745 function ext_getAllTemplates($id) {
746 // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
747 if (intval($id)) {
748 $outRes=array();
749 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).' '.$this->whereClause, '', 'sorting');
750 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
751 $outRes[] = $row;
752 }
753 $GLOBALS['TYPO3_DB']->sql_free_result($res);
754 return $outRes; // Returns the template rows in an array.
755 }
756 }
757
758 /**
759 * This function compares the flattened constants (default and all).
760 * Returns an array with the constants from the whole template which may be edited by the module.
761 *
762 * @param [type] $default: ...
763 * @return [type] ...
764 */
765 function ext_compareFlatSetups($default) {
766 $editableComments=array();
767 reset($this->flatSetup);
768 while(list($const,$value)=each($this->flatSetup)) {
769 if (substr($const,-2)!=".." && isset($this->flatSetup[$const.".."])) {
770 $comment = trim($this->flatSetup[$const.".."]);
771 $c_arr = explode(chr(10),$comment);
772 while(list($k,$v)=each($c_arr)) {
773 $line=trim(ereg_replace("^[#\/]*","",$v));
774 if ($line) {
775 $parts = explode(";", $line);
776 while(list(,$par)=each($parts)) {
777 if (strstr($par,"=")) {
778 $keyValPair =explode("=",$par,2);
779 switch(trim(strtolower($keyValPair[0]))) {
780 case "type":
781 // Type:
782 /*
783 int (range; low-high, list: item,item,item = selector),
784 boolean (check),
785 string (default),
786 wrap,
787 html-color ...,
788 file
789 */
790 $editableComments[$const]["type"] = trim($keyValPair[1]);
791 break;
792 case "cat":
793 // list of categories.
794 $catSplit=explode("/",strtolower($keyValPair[1]));
795 $editableComments[$const]["cat"] = trim($catSplit[0]);
796 $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.
797 if ($catSplit[1] && isset($this->subCategories[$catSplit[1]])) {
798 $editableComments[$const]["subcat_name"]=$catSplit[1];
799 $editableComments[$const]["subcat"]=$this->subCategories[$catSplit[1]][1]."/".$catSplit[1]."/".trim($catSplit[2])."z";
800 } else {
801 $editableComments[$const]["subcat"]="x"."/".trim($catSplit[2])."z";
802 }
803 break;
804 case "label":
805 // label
806 $editableComments[$const]["label"] = trim($keyValPair[1]);
807 break;
808 }
809 }
810 }
811 }
812 }
813 }
814 if (isset($editableComments[$const])) {
815 $editableComments[$const]["name"]=$const;
816 $editableComments[$const]["value"]=trim($value);
817 if (isset($default[$const])) {
818 $editableComments[$const]["default_value"]=trim($default[$const]);
819 }
820 }
821 }
822 return $editableComments;
823 }
824
825 /**
826 * [Describe function...]
827 *
828 * @param [type] $editConstArray: ...
829 * @return [type] ...
830 */
831 function ext_categorizeEditableConstants($editConstArray) {
832 // Runs through the available constants and fills the $this->categories array with pointers and priority-info
833 reset($editConstArray);
834 while(list($constName,$constData)=each($editConstArray)) {
835 if (!$constData["type"]) {$constData["type"]="string";}
836 $cats = explode(",",$constData["cat"]);
837 reset($cats);
838 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...
839 $theCat=trim($theCat);
840 if ($theCat) {
841 $this->categories[$theCat][$constName]=$constData["subcat"];
842 // $this->categories["all"][$constName]=$constData["subcat"];
843 }
844 }
845 }
846 // debug($this->categories);
847 }
848
849 /**
850 * [Describe function...]
851 *
852 * @return [type] ...
853 */
854 function ext_getCategoryLabelArray() {
855 // Returns array used for labels in the menu.
856 $retArr = array();
857 while(list($k,$v)=each($this->categories)) {
858 if (count($v)) {
859 $retArr[$k]=strtoupper($k)." (".count($v).")";
860 }
861 }
862 return $retArr;
863 }
864
865 /**
866 * [Describe function...]
867 *
868 * @param [type] $type: ...
869 * @return [type] ...
870 */
871 function ext_getTypeData($type) {
872 $retArr = array();
873 $type=trim($type);
874 if (!$type) {
875 $retArr["type"]="string";
876 } else {
877 $m=strcspn ($type," [");
878 $retArr["type"]=strtolower(substr($type,0,$m));
879 if (t3lib_div::inList("int,options,file,boolean,offset",$retArr["type"])) {
880 $p=trim(substr($type,$m));
881 ereg("\[(.*)\]",$p,$reg);
882 $p=trim($reg[1]);
883 if ($p) {
884 $retArr["paramstr"]=$p;
885 switch($retArr["type"]) {
886 case "int":
887 if (substr($retArr["paramstr"],0,1)=="-") {
888 $retArr["params"]=t3lib_div::intExplode("-",substr($retArr["paramstr"],1));
889 $retArr["params"][0]=intval("-".$retArr["params"][0]);
890 } else {
891 $retArr["params"]=t3lib_div::intExplode("-",$retArr["paramstr"]);
892 }
893 $retArr["paramstr"]=$retArr["params"][0]." - ".$retArr["params"][1];
894 break;
895 case "options":
896 $retArr["params"]=explode(",",$retArr["paramstr"]);
897 break;
898 }
899 }
900 }
901 }
902 // debug($retArr);
903 return $retArr;
904 }
905
906 /**
907 * [Describe function...]
908 *
909 * @param [type] $category: ...
910 * @return [type] ...
911 */
912 function ext_getTSCE_config($category) {
913 $catConf=$this->setup["constants"]["TSConstantEditor."][$category."."];
914 $out=array();
915 if (is_array($catConf)) {
916 reset($catConf);
917 while(list($key,$val)=each($catConf)) {
918 switch($key) {
919 case "image":
920 $out["imagetag"] = $this->ext_getTSCE_config_image($catConf["image"]);
921 break;
922 case "description":
923 case "bulletlist":
924 case "header":
925 $out[$key] = $val;
926 break;
927 default:
928 if (t3lib_div::testInt($key)) {
929 $constRefs = explode(",",$val);
930 reset($constRefs);
931 while(list(,$const)=each($constRefs)) {
932 $const=trim($const);
933 if ($const && $const<=20) {
934 $out["constants"][$const].=$this->ext_getKeyImage($key);
935 }
936 }
937 }
938 break;
939 }
940 }
941 }
942 $this->helpConfig=$out;
943 }
944
945 /**
946 * [Describe function...]
947 *
948 * @param [type] $key: ...
949 * @return [type] ...
950 */
951 function ext_getKeyImage($key) {
952 return '<img src="'.$this->ext_localWebGfxPrefix.'gfx/'.$key.'.gif" align="top" hspace=2>';
953 }
954
955 /**
956 * [Describe function...]
957 *
958 * @param [type] $imgConf: ...
959 * @return [type] ...
960 */
961 function ext_getTSCE_config_image($imgConf) {
962 if (substr($imgConf,0,4)=="gfx/") {
963 $iFile=$this->ext_localGfxPrefix.$imgConf;
964 $tFile=$this->ext_localWebGfxPrefix.$imgConf;
965 } elseif (substr($imgConf,0,4)=='EXT:') {
966 $iFile = t3lib_div::getFileAbsFileName($imgConf);
967 if ($iFile) {
968 $f = substr($iFile,strlen(PATH_site));
969 $tFile=$GLOBALS["BACK_PATH"]."../".$f;
970 }
971 } else {
972 $f = "uploads/tf/".$this->extractFromResources($this->setup["resources"],$imgConf);
973 $iFile=PATH_site.$f;
974 $tFile=$GLOBALS["BACK_PATH"]."../".$f;
975 }
976 $imageInfo=@getImagesize($iFile);
977 return '<img src="'.$tFile.'" '.$imageInfo[3].'>';
978 }
979
980 /**
981 * [Describe function...]
982 *
983 * @return [type] ...
984 */
985 function ext_resourceDims() {
986 if ($this->setup["resources"]) {
987 $rArr=explode(",",$this->setup["resources"]);
988 while(list($c,$val)=each($rArr)) {
989 $val=trim($val);
990 $theFile = PATH_site."uploads/tf/".$val;
991 if ($val && @is_file($theFile)) {
992 $imgInfo = @getimagesize($theFile);
993 }
994 if (is_array($imgInfo)) {
995 $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
996 }
997 }
998 }
999 reset($this->dirResources);
1000 while(list($c,$val)=each($this->dirResources)) {
1001 $val=trim($val);
1002 $imgInfo = @getimagesize(PATH_site.$val);
1003 if (is_array($imgInfo)) {
1004 $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
1005 }
1006 }
1007 }
1008
1009 /**
1010 * [Describe function...]
1011 *
1012 * @param [type] $path: ...
1013 * @return [type] ...
1014 */
1015 function ext_readDirResources($path) {
1016 $path=trim($path);
1017 if ($path && substr($path,0,10)=="fileadmin/") {
1018 $path = ereg_replace("\/$","",$path);
1019 $this->readDirectory(PATH_site.$path);
1020 }
1021 }
1022
1023 /**
1024 * [Describe function...]
1025 *
1026 * @param [type] $path: ...
1027 * @param [type] $type: ...
1028 * @return [type] ...
1029 */
1030 function readDirectory($path,$type="file") {
1031 if(@is_dir($path)) {
1032 $d = @dir($path);
1033 $tempArray=Array();
1034 if (is_object($d)) {
1035 while($entry=$d->read()) {
1036 if ($entry!="." && $entry!="..") {
1037 $wholePath = $path."/".$entry; // Because of odd PHP-error where <BR>-tag is sometimes placed after a filename!!
1038 if (@file_exists($wholePath) && (!$type || filetype($wholePath)==$type)) {
1039 $fI = t3lib_div::split_fileref($wholePath);
1040 $this->dirResources[]=substr($wholePath,strlen(PATH_site));
1041 }
1042 }
1043 }
1044 $d->close();
1045 }
1046 }
1047 }
1048
1049 /**
1050 * [Describe function...]
1051 *
1052 * @param [type] $params: ...
1053 * @return [type] ...
1054 */
1055 function ext_fNandV($params) {
1056 $fN='data['.$params["name"].']';
1057 $fV=$params["value"];
1058 if (ereg("^{[\$][a-zA-Z0-9\.]*}$",trim($fV),$reg)) { // Values entered from the constantsedit cannot be constants! 230502; removed \{ and set {
1059 $fV="";
1060 }
1061 $fV=htmlspecialchars($fV);
1062
1063 return array($fN,$fV,$params);
1064 }
1065
1066 /**
1067 * [Describe function...]
1068 *
1069 * @param [type] $theConstants: ...
1070 * @param [type] $category: ...
1071 * @return [type] ...
1072 */
1073 function ext_printFields($theConstants,$category) {
1074 // This functions returns the HTML-code that creates the editor-layout of the module.
1075 reset($theConstants);
1076 $output="";
1077 $subcat="";
1078 if (is_array($this->categories[$category])) {
1079
1080 $help=$this->helpConfig;
1081 $this->rArr=explode(",",$this->setup["resources"].",".implode($this->dirResources,","));
1082
1083 asort($this->categories[$category]);
1084 while(list($name,$type)=each($this->categories[$category])) {
1085 $params = $theConstants[$name];
1086 if (is_array($params)) {
1087 if ($subcat!=$params["subcat_name"]) {
1088 $subcat=$params["subcat_name"];
1089 $subcat_name = $params["subcat_name"] ? $this->subCategories[$params["subcat_name"]][0] : "Others";
1090 $output.='<tr>';
1091 $output.='<td colspan=2 class="bgColor4"><div align="center"><b>'.$subcat_name.'</b></div></td>';
1092 $output.='</tr>';
1093 }
1094
1095 // if (substr($params["value"],0,2)!='{$') {
1096 $label=$GLOBALS["LANG"]->sL($params["label"]);
1097 $label_parts = explode(":",$label,2);
1098 if (count($label_parts)==2) {
1099 $head=trim($label_parts[0]);
1100 $body=trim($label_parts[1]);
1101 } else {
1102 $head=trim($label_parts[0]);
1103 $body="";
1104 }
1105 if (strlen($head)>35) {
1106 if (!$body) {$body=$head;}
1107 $head=t3lib_div::fixed_lgd($head,35);
1108 }
1109 $typeDat=$this->ext_getTypeData($params["type"]);
1110 $checked="";
1111 $p_field="";
1112 $raname = substr(md5($params["name"]),0,10);
1113 $aname="'".$raname."'";
1114 if ($this->ext_dontCheckIssetValues || isset($this->objReg[$params["name"]])) {
1115 $checked=" checked";
1116 list($fN,$fV,$params)=$this->ext_fNandV($params);
1117
1118 switch($typeDat["type"]) {
1119 case "int":
1120 case "int+":
1121 $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(5).' onChange="uFormUrl('.$aname.')">';
1122 if ($typeDat["paramstr"]) {
1123 $p_field.=' Range: '.$typeDat["paramstr"];
1124 } elseif ($typeDat["type"]=="int+") {
1125 $p_field.=' Range: 0 - ';
1126 } else {
1127 $p_field.=' (Integer)';
1128 }
1129 break;
1130 case "color":
1131 $colorNames=explode(",",",".$this->HTMLcolorList);
1132 $p_field="";
1133 while(list(,$val)=each($colorNames)) {
1134 $sel="";
1135 if ($val==strtolower($params["value"])) {$sel=" selected";}
1136 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.'</option>';
1137 }
1138 $p_field='<select name="C'.$fN.'" onChange="document.'.$this->ext_CEformName.'[\''.$fN.'\'].value=this.options[this.selectedIndex].value; uFormUrl('.$aname.');">'.$p_field.'</select>';
1139
1140 $p_field.='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(7).' onChange="uFormUrl('.$aname.')">';
1141 break;
1142 case "wrap":
1143 $wArr = explode("|",$fV);
1144 $p_field='<input type="text" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(29).' onChange="uFormUrl('.$aname.')">';
1145 $p_field.=' | ';
1146 $p_field.='<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(15).' onChange="uFormUrl('.$aname.')">';
1147 break;
1148 case "offset":
1149 $wArr = explode(",",$fV);
1150 $labels = t3lib_div::trimExplode(",",$typeDat["paramstr"]);
1151 $p_field=($labels[0]?$labels[0]:"x").':<input type="text" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
1152 $p_field.=' , ';
1153 $p_field.=($labels[1]?$labels[1]:"y").':<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
1154 for ($aa=2;$aa<count($labels);$aa++) {
1155 if ($labels[$aa]) {
1156 $p_field.=' , '.$labels[$aa].':<input type="text" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
1157 } else {
1158 $p_field.='<input type="hidden" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'">';
1159 }
1160 }
1161 break;
1162 case "options":
1163 if (is_array($typeDat["params"])) {
1164 $p_field="";
1165 while(list(,$val)=each($typeDat["params"])) {
1166 $vParts = explode("=",$val,2);
1167 $label = $vParts[0];
1168 $val = isset($vParts[1]) ? $vParts[1] : $vParts[0];
1169
1170 // option tag:
1171 $sel="";
1172 if ($val==$params["value"]) {$sel=" selected";}
1173 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$GLOBALS["LANG"]->sL($label).'</option>';
1174 }
1175 $p_field='<select name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
1176 }
1177 break;
1178 case "boolean":
1179 $p_field='<input type="Hidden" name="'.$fN.'" value="0">';
1180 $sel=""; if ($fV) {$sel=" checked";}
1181 $p_field.='<input type="Checkbox" name="'.$fN.'" value="'.($typeDat["paramstr"]?$typeDat["paramstr"]:1).'"'.$sel.' onClick="uFormUrl('.$aname.')">';
1182 break;
1183 case "comment":
1184 $p_field='<input type="Hidden" name="'.$fN.'" value="#">';
1185 $sel=""; if (!$fV) {$sel=" checked";}
1186 $p_field.='<input type="Checkbox" name="'.$fN.'" value=""'.$sel.' onClick="uFormUrl('.$aname.')">';
1187 break;
1188 case "file":
1189 $p_field='<option value=""></option>';
1190 // debug($params["value"]);
1191 $theImage="";
1192 // if ($this->) {
1193 $selectThisFile = $this->extractFromResources($this->setup["resources"],$params["value"]);
1194 if ($params["value"] && !$selectThisFile) {
1195 if (in_array($params["value"],$this->dirResources)) {
1196 $selectThisFile=$params["value"];
1197 }
1198 }
1199 // debug($selectThisFile);
1200 // extensionlist
1201 $extList = $typeDat["paramstr"];
1202 $p_field='<option value="">('.$extList.')</option>';
1203 if ($extList=="IMAGE_EXT") {
1204 $extList = $GLOBALS["TYPO3_CONF_VARS"]["GFX"]["imagefile_ext"];
1205 }
1206 reset($this->rArr);
1207 $onlineResourceFlag=$this->ext_defaultOnlineResourceFlag;
1208
1209 while(list($c,$val)=each($this->rArr)) {
1210 $val=trim($val);
1211 $fI=t3lib_div::split_fileref($val);
1212 // debug($fI);
1213 if ($val && (!$extList || t3lib_div::inList($extList,$fI["fileext"]))) {
1214 if ($onlineResourceFlag<=0 && substr($fI["path"],0,10)=="fileadmin/") {
1215 if ($onlineResourceFlag<0) {
1216 $p_field.='<option value=""></option>';
1217 }
1218 $p_field.='<option value="">__'.$fI["path"].'__:</option>';
1219 $onlineResourceFlag=1;
1220 }
1221 $dims=$this->resourceDimensions[$val];
1222 $sel="";
1223
1224 // Check if $params["value"] is in the list of resources.
1225 if ($selectThisFile && $selectThisFile==$val) {
1226 $sel=" selected";
1227 if ($onlineResourceFlag<=0) {
1228 $theImage=t3lib_BEfunc::thumbCode(array("resources"=>$selectThisFile),"sys_template","resources",$GLOBALS["BACK_PATH"],"");
1229 } else {
1230 $theImage=t3lib_BEfunc::thumbCode(array("resources"=>$fI["file"]),"sys_template","resources",$GLOBALS["BACK_PATH"],"",$fI["path"]);
1231 }
1232 }
1233
1234 if ($onlineResourceFlag<=0) {
1235 $onlineResourceFlag--;
1236 // Value is set with a *
1237 $val = $this->ext_setStar($val);
1238 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.$dims.'</option>';
1239 } else {
1240 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$fI["file"].$dims.'</option>';
1241 }
1242 }
1243 }
1244 if (trim($params["value"]) && !$selectThisFile) {
1245 $val = $params["value"];
1246 $p_field.='<option value=""></option>';
1247 $p_field.='<option value="'.htmlspecialchars($val).'" selected>'.$val.'</option>';
1248 }
1249 // }
1250 $p_field='<select name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
1251 $p_field.=$theImage;
1252
1253 if (!$this->ext_noCEUploadAndCopying) {
1254 // Copy a resource
1255 $copyFile = $this->extractFromResources($this->setup["resources"],$params["value"]);
1256 if (!$copyFile) {
1257 if ($params["value"]) {
1258 $copyFile=PATH_site.$this->ext_detectAndFixExtensionPrefix($params["value"]);
1259 }
1260 } else {
1261 // $copyFile=PATH_site."uploads/tf/".$copyFile;
1262 $copyFile="";
1263 }
1264 #debug($copyFile);
1265 if ($copyFile && @is_file($copyFile)) {
1266 $p_field.='<img src="clear.gif" width="20" height="1" alt="" /><img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/clip_copy.gif','width="12" height="12"').' border="0" alt="" /><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"])).'\'));}">';
1267 }
1268 // Upload?
1269 $p_field.='<BR>';
1270 $p_field.='<input type="file" name="upload_'.$fN.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth().' onChange="uFormUrl('.$aname.')" size="50" />';
1271 }
1272 break;
1273 case 'small':
1274 default:
1275 $fwidth= $typeDat["type"]=="small" ? 10 : 46;
1276 $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth($fwidth).' onChange="uFormUrl('.$aname.')">';
1277 break;
1278 }
1279 }
1280 if (!$this->ext_dontCheckIssetValues) $p_field='<input type="Checkbox" name="check['.$params["name"].']" value="1"'.$checked.' onClick="uFormUrl('.$aname.')">'.$p_field;
1281 if ($typeDat["type"]=="color" && substr($params["value"],0,2)!='{$') {
1282 $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>';
1283 } else {
1284 $p_field='<span class="nobr">'.$p_field.'</span><br />';
1285 }
1286
1287 $p_name = '<span class="typo3-dimmed">['.$params["name"].']</span><BR>';
1288 $p_dlabel='<span class="typo3-dimmed"><b>Default:</b> '.htmlspecialchars($params["default_value"]).'</span><BR>';
1289 $p_label = '<b>'.htmlspecialchars($head).'</b>';
1290 $p_descrip = $body ? htmlspecialchars($body)."<BR>" : "";
1291
1292 $output.='<tr>';
1293 $output.='<td valign=top nowrap><a name="'.$raname.'"></a>'.$help["constants"][$params["name"]].$p_label.'</td>';
1294 $output.='<td valign=top align="right">'.$p_name.'</td>';
1295 $output.='</tr>';
1296 $output.='<tr>';
1297 $output.='<td colspan=2>'.$p_descrip.$p_field.$p_dlabel.'<br></td>';
1298 $output.='</tr>';
1299 // }
1300 } else {
1301 debug("Error. Constant did not exits. Should not happen.");
1302 }
1303 }
1304 $output='<table border=0 cellpadding=0 cellspacing=0>'.$output.'</table>';
1305 }
1306 return $output;
1307 }
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320 /***************************
1321 *
1322 * Processing input values
1323 *
1324 ***************************/
1325
1326 /**
1327 * @param [type] $constants: ...
1328 * @return [type] ...
1329 */
1330 function ext_regObjectPositions($constants) {
1331 // 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
1332 $this->raw = explode(chr(10),$constants);
1333 $this->rawP=0;
1334
1335 $this->objReg=array(); // resetting the objReg if the divider is found!!
1336 $this->ext_regObjects("");
1337 }
1338
1339 /**
1340 * [Describe function...]
1341 *
1342 * @param [type] $pre: ...
1343 * @return [type] ...
1344 */
1345 function ext_regObjects($pre) {
1346 // works with regObjectPositions. "expands" the names of the TypoScript objects
1347 while (isset($this->raw[$this->rawP])) {
1348 $line = ltrim($this->raw[$this->rawP]);
1349 if (strstr($line,$this->edit_divider)) {
1350 $this->objReg=array(); // resetting the objReg if the divider is found!!
1351 }
1352 $this->rawP++;
1353 if ($line) {
1354 if (substr($line,0,1)=="[") {
1355 // return $line;
1356 } elseif (strcspn($line,"}#/")!=0) {
1357 $varL = strcspn($line," {=<");
1358 $var=substr($line,0,$varL);
1359 $line = ltrim(substr($line,$varL));
1360 switch(substr($line,0,1)) {
1361 case "=":
1362 $this->objReg[$pre.$var]=$this->rawP-1;
1363 break;
1364 case "{":
1365 $this->ext_inBrace++;
1366 $this->ext_regObjects($pre.$var.".");
1367 break;
1368 }
1369 $this->lastComment="";
1370 } elseif (substr($line,0,1)=="}") {
1371 $this->lastComment="";
1372 $this->ext_inBrace--;
1373 if ($this->ext_inBrace<0) {
1374 $this->ext_inBrace=0;
1375 } else {
1376 break;
1377 }
1378 }
1379 }
1380 }
1381 }
1382
1383 /**
1384 * [Describe function...]
1385 *
1386 * @param [type] $key: ...
1387 * @param [type] $var: ...
1388 * @return [type] ...
1389 */
1390 function ext_putValueInConf($key, $var) {
1391 // Puts the value $var to the TypoScript value $key in the current lines of the templates.
1392 // If the $key is not found in the template constants field, a new line is inserted in the bottom.
1393 $theValue = " ".trim($var);
1394 if (isset($this->objReg[$key])) {
1395 $lineNum = $this->objReg[$key];
1396 $parts = explode("=",$this->raw[$lineNum],2);
1397 if (count($parts)==2) {
1398 $parts[1]= $theValue;
1399 }
1400 $this->raw[$lineNum]=implode($parts,"=");
1401 } else {
1402 $this->raw[]=$key." =".$theValue;
1403 }
1404 $this->changed=1;
1405 }
1406
1407 /**
1408 * [Describe function...]
1409 *
1410 * @param [type] $key: ...
1411 * @return [type] ...
1412 */
1413 function ext_removeValueInConf($key) {
1414 // Removes the value in the configuration
1415 if (isset($this->objReg[$key])) {
1416 $lineNum = $this->objReg[$key];
1417 unset($this->raw[$lineNum]);
1418 }
1419 $this->changed=1;
1420 }
1421
1422 /**
1423 * [Describe function...]
1424 *
1425 * @param [type] $arr: ...
1426 * @param [type] $settings: ...
1427 * @return [type] ...
1428 */
1429 function ext_depthKeys($arr,$settings) {
1430 reset($arr);
1431 $tsbrArray=array();
1432 while(list($theK,$theV)=each($arr)) {
1433 $theKeyParts = explode(".",$theK);
1434 $depth="";
1435 $c=count($theKeyParts);
1436 $a=0;
1437 while(list(,$p)=each($theKeyParts)) {
1438 $a++;
1439 $depth.=($depth?".":"").$p;
1440 $tsbrArray[$depth]= ($c==$a) ? $theV : 1;
1441 }
1442 }
1443 // Modify settings
1444 reset($tsbrArray);
1445 while(list($theK,$theV)=each($tsbrArray)) {
1446 if ($theV) {
1447 $settings[$theK] = 1;
1448 } else {
1449 unset($settings[$theK]);
1450 }
1451 }
1452 return $settings;
1453 }
1454
1455 /**
1456 * [Describe function...]
1457 *
1458 * @param [type] $http_post_vars: ...
1459 * @param [type] $http_post_files: ...
1460 * @param [type] $theConstants: ...
1461 * @param [type] $tplRow: ...
1462 * @return [type] ...
1463 */
1464 function ext_procesInput($http_post_vars,$http_post_files,$theConstants,$tplRow) {
1465 $data=$http_post_vars["data"];
1466 $check=$http_post_vars["check"];
1467 $copyResource=$http_post_vars["_copyResource"];
1468 $Wdata=$http_post_vars["Wdata"];
1469 $W2data=$http_post_vars["W2data"];
1470 $W3data=$http_post_vars["W3data"];
1471 $W4data=$http_post_vars["W4data"];
1472 $W5data=$http_post_vars["W5data"];
1473
1474 if (is_array($data)) {
1475 reset($data);
1476 while(list($key,$var)=each($data)) {
1477 if (isset($theConstants[$key])) {
1478 if ($this->ext_dontCheckIssetValues || isset($check[$key])) { // If checkbox is set, update the value
1479 list($var) = explode(chr(10),$var); // exploding with linebreak, just to make sure that no multiline input is given!
1480 $typeDat=$this->ext_getTypeData($theConstants[$key]["type"]);
1481 switch($typeDat["type"]) {
1482 case "int":
1483 if ($typeDat["paramstr"]) {
1484 $var=t3lib_div::intInRange($var,$typeDat["params"][0],$typeDat["params"][1]);
1485 } else {
1486 $var=intval($var);
1487 }
1488 break;
1489 case "int+":
1490 $var=t3lib_div::intInRange($var,0,10000);
1491 break;
1492 case "color":
1493 $col=array();
1494 if($var && !t3lib_div::inList($this->HTMLcolorList,strtolower($var))) {
1495 $var = ereg_replace("[^A-Fa-f0-9]*","",$var);
1496 $col[]=HexDec(substr($var,0,2));
1497 $col[]=HexDec(substr($var,2,2));
1498 $col[]=HexDec(substr($var,4,2));
1499 $var="#".strtoupper(substr("0".DecHex($col[0]),-2).substr("0".DecHex($col[1]),-2).substr("0".DecHex($col[2]),-2));
1500 }
1501 break;
1502 case "comment":
1503 if ($val) {
1504 $val="#";
1505 } else {
1506 $val="";
1507 }
1508 break;
1509 case "wrap":
1510 if (isset($Wdata[$key])) {
1511 $var.="|".$Wdata[$key];
1512 }
1513 break;
1514 case "offset":
1515 if (isset($Wdata[$key])) {
1516 $var=intval($var).",".intval($Wdata[$key]);
1517 if (isset($W2data[$key])) {
1518 $var.=",".intval($W2data[$key]);
1519 if (isset($W3data[$key])) {
1520 $var.=",".intval($W3data[$key]);
1521 if (isset($W4data[$key])) {
1522 $var.=",".intval($W4data[$key]);
1523 if (isset($W5data[$key])) {
1524 $var.=",".intval($W5data[$key]);
1525 }
1526 }
1527 }
1528 }
1529 }
1530 break;
1531 case "boolean":
1532 if ($var) {
1533 $var = $typeDat["paramstr"] ? $typeDat["paramstr"] : 1;
1534 }
1535 break;
1536 case "file":
1537 if (!$this->ext_noCEUploadAndCopying) {
1538 if ($http_post_files["upload_data"]["name"][$key] && $http_post_files["upload_data"]["tmp_name"][$key]!="none") {
1539 $var = $this->upload_copy_file(
1540 $typeDat,
1541 $tplRow,
1542 trim($http_post_files["upload_data"]["name"][$key]),
1543 $http_post_files["upload_data"]["tmp_name"][$key]
1544 );
1545 }
1546 if ($copyResource[$key]) {
1547 $var = $this->upload_copy_file(
1548 $typeDat,
1549 $tplRow,
1550 basename($copyResource[$key]),
1551 $copyResource[$key]
1552 );
1553 }
1554 }
1555 break;
1556 }
1557 if ($this->ext_printAll || strcmp($theConstants[$key]["value"],$var)) {
1558 $this->ext_putValueInConf($key, $var); // Put value in, if changed.
1559 }
1560 unset($check[$key]); // Remove the entry because it has been "used"
1561 } else {
1562 $this->ext_removeValueInConf($key);
1563 }
1564 }
1565 }
1566 }
1567 // 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...
1568 if (!$this->ext_dontCheckIssetValues && is_array($check)) {
1569 reset($check);
1570 while(list($key,$var)=each($check)) {
1571 if (isset($theConstants[$key])) {
1572 $dValue = $theConstants[$key]["default_value"];
1573 // debug($dValue);
1574 $this->ext_putValueInConf($key, $dValue);
1575 // debug($key,1);
1576 }
1577 }
1578 }
1579 // debug($this->objReg);
1580 }
1581
1582 /**
1583 * [Describe function...]
1584 *
1585 * @param [type] $typeDat: ...
1586 * @param [type] $tplRow: ...
1587 * @param [type] $theRealFileName: ...
1588 * @param [type] $tmp_name: ...
1589 * @return [type] ...
1590 */
1591 function upload_copy_file($typeDat,&$tplRow,$theRealFileName,$tmp_name) {
1592
1593 // extensions
1594 $extList = $typeDat["paramstr"];
1595 if ($extList=="IMAGE_EXT") {
1596 $extList = $GLOBALS["TYPO3_CONF_VARS"]["GFX"]["imagefile_ext"];
1597 }
1598 $fI=t3lib_div::split_fileref($theRealFileName);
1599 if ($theRealFileName && (!$extList || t3lib_div::inList($extList,$fI["fileext"]))) {
1600 $tmp_upload_name = t3lib_div::upload_to_tempfile($tmp_name); // If there is an uploaded file, move it for the sake of safe_mode.
1601
1602 // Saving resource
1603 $alternativeFileName=array();
1604 $alternativeFileName[$tmp_upload_name] = $theRealFileName;
1605 // Making list of resources
1606 $resList = $tplRow["resources"];
1607 $resList = $tmp_upload_name.",".$resList;
1608 $resList=implode(t3lib_div::trimExplode(",",$resList,1),",");
1609 // Making data-array
1610 $recData=array();
1611 $recData["sys_template"][$tplRow["uid"]]["resources"] = $resList;
1612 // Saving
1613 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
1614 $tce->stripslashes_values=0;
1615 $tce->alternativeFileName = $alternativeFileName;
1616 $tce->start($recData,Array());
1617 $tce->process_datamap();
1618
1619 t3lib_div::unlink_tempfile($tmp_upload_name);
1620
1621 $tmpRow = t3lib_BEfunc::getRecord("sys_template",$tplRow["uid"],"resources");
1622 $tplRow["resources"] = $tmpRow["resources"];
1623
1624 // Setting the value
1625 $var = $this->ext_setStar($theRealFileName);
1626 }
1627 return $var;
1628 }
1629
1630 /**
1631 * [Describe function...]
1632 *
1633 * @param [type] $id: ...
1634 * @param [type] $perms_clause: ...
1635 * @return [type] ...
1636 */
1637 function ext_prevPageWithTemplate($id,$perms_clause) {
1638 $rootLine = t3lib_BEfunc::BEgetRootLine($id,$perms_clause?" AND ".$perms_clause:"");
1639 reset($rootLine);
1640 while(list(,$p)=each($rootLine)) {
1641 if ($this->ext_getFirstTemplate($p["uid"])) {
1642 return $p;
1643 }
1644 }
1645 }
1646
1647 /**
1648 * [Describe function...]
1649 *
1650 * @param [type] $val: ...
1651 * @return [type] ...
1652 */
1653 function ext_setStar($val) {
1654 $fParts = explode(".",strrev($val),2);
1655 $val=ereg_replace("_[0-9][0-9]$","",strrev($fParts[1]))."*.".strrev($fParts[0]);
1656 return $val;
1657 }
1658
1659 /**
1660 * [Describe function...]
1661 *
1662 * @param [type] $value: ...
1663 * @return [type] ...
1664 */
1665 function ext_detectAndFixExtensionPrefix($value) {
1666 if (substr($value,0,4)=="EXT:") {
1667 $parts = explode("/",substr($value,4),2);
1668 #debug($parts);
1669 $extPath = t3lib_extMgm::siteRelPath($parts[0]);
1670 $value = $extPath.$parts[1];
1671 return $value;
1672 } else {
1673 return $value;
1674 }
1675 }
1676 }
1677
1678
1679 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php']) {
1680 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php']);
1681 }
1682 ?>