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