Only changes to function indexes, comments and stripping of trailing whitespace in...
[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 $key=ereg_replace("\.$","",$key);
358 if (substr($key,-1)!=".") {
359 if (t3lib_div::testInt($key)) {
360 $keyArr_num[$key]=$arr[$key];
361 } else {
362 $keyArr_alpha[$key]=$arr[$key];
363 }
364 }
365 }
366 ksort($keyArr_num);
367 $keyArr=$keyArr_num+$keyArr_alpha;
368 reset($keyArr);
369 $c=count($keyArr);
370 if ($depth_in) {$depth_in = $depth_in.".";}
371
372 // $validate_info= verify_TSobjects($keyArr,$parentType,$parentValue);
373 // debug($validate_info);
374
375 while (list($key,)=each($keyArr)) {
376 $a++;
377 $depth=$depth_in.$key;
378 if ($this->bType!="const" || substr($depth,0,1)!="_") { // this excludes all constants starting with "_" from being shown.
379 $goto = substr(md5($depth),0,6);
380 // debug($depth);
381 $deeper = (is_array($arr[$key."."]) && ($this->tsbrowser_depthKeys[$depth] || $this->ext_expandAllNotes)) ? 1 : 0;
382 $PM = "join";
383 $LN = ($a==$c)?"blank":"line";
384 $BTM = ($a==$c)?"bottom":"";
385 $PM = is_array($arr[$key."."]) && !$this->ext_noPMicons ? ($deeper ? "minus":"plus") : "join";
386
387 $HTML.=$depthData;
388 $theIcon='<img src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border="0" alt="" />';
389 if ($PM=="join") {
390 $HTML.=$theIcon;
391 } else {
392 $aHref='index.php?id='.$GLOBALS["SOBE"]->id.'&tsbr['.$depth.']='.($deeper?0:1).'#'.$goto;
393 $HTML.='<a name="'.$goto.'" href="'.htmlspecialchars($aHref).'">'.$theIcon.'</a>';
394 }
395
396 $label = $key;
397 if (t3lib_div::inList("types,resources,sitetitle",$depth) && $this->bType=="setup") { // Read only...
398 $label='<font color="#666666">'.$label.'</font>';
399 } else {
400 if ($this->linkObjects) {
401 $aHref = 'index.php?id='.$GLOBALS["SOBE"]->id.'&sObj='.$depth;
402 $label = '<a href="'.htmlspecialchars($aHref).'">'.$label.'</a>';
403 }
404 }
405
406 $HTML.="[".$label."]";
407
408 if (isset($arr[$key])) {
409 $theValue = $arr[$key];
410 if ($this->fixedLgd) {
411 $imgBlocks = ceil(1+strlen($depthData)/77);
412 $lgdChars = 68-ceil(strlen("[".$key."]")*0.8)-$imgBlocks*3;
413 $theValue = $this->ext_fixed_lgd($theValue,$lgdChars);
414 }
415 if ($this->tsbrowser_searchKeys[$depth]) {
416 $HTML.='=<b><font color="red">'.$this->makeHtmlspecialchars($theValue).'</font></b>';
417 } else {
418 $HTML.="=<b>".$this->makeHtmlspecialchars($theValue)."</b>";
419 }
420 }
421 $HTML.="<br />";
422
423 if ($deeper) {
424 $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]);
425 }
426 }
427 }
428 return $HTML;
429 }
430
431 /**
432 * [Describe function...]
433 *
434 * @param [type] $theValue: ...
435 * @return [type] ...
436 */
437 function makeHtmlspecialchars($theValue){
438 return $this->ext_noSpecialCharsOnLabels ? $theValue : htmlspecialchars($theValue);
439 }
440
441 /**
442 * [Describe function...]
443 *
444 * @param [type] $arr: ...
445 * @param [type] $depth_in: ...
446 * @param [type] $searchString: ...
447 * @param [type] $keyArray: ...
448 * @return [type] ...
449 */
450 function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray) {
451 reset($arr);
452 $keyArr=array();
453 while (list($key,)=each($arr)) {
454 $key=ereg_replace("\.$","",$key);
455 if (substr($key,-1)!=".") {
456 $keyArr[$key]=1;
457 }
458 }
459 reset($keyArr);
460 // asort($keyArr);
461 $c=count($keyArr);
462 if ($depth_in) {$depth_in = $depth_in.".";}
463 while (list($key,)=each($keyArr)) {
464 $depth=$depth_in.$key;
465 $deeper = is_array($arr[$key."."]);
466
467 if ($this->regexMode) {
468 if (ereg($searchString,$arr[$key])) { $this->tsbrowser_searchKeys[$depth]=1; }
469 } else {
470 if (stristr($arr[$key],$searchString)) { $this->tsbrowser_searchKeys[$depth]=1; }
471 }
472
473 if ($deeper) {
474 $cS = count($this->tsbrowser_searchKeys);
475 $keyArray = $this->ext_getSearchKeys($arr[$key."."], $depth, $searchString, $keyArray);
476 if ($cS != count($this->tsbrowser_searchKeys)) {
477 $keyArray[$depth]=1;
478 }
479 }
480 }
481 return $keyArray;
482 }
483
484 /**
485 * [Describe function...]
486 *
487 * @param [type] $pid: ...
488 * @return [type] ...
489 */
490 function ext_getRootlineNumber($pid) {
491 if ($pid && is_array($GLOBALS["rootLine"])) {
492 reset($GLOBALS["rootLine"]);
493 while(list($key,$val)=each($GLOBALS["rootLine"])) {
494 if ($val['uid']==$pid) return $key;
495 }
496 }
497 }
498
499 /**
500 * [Describe function...]
501 *
502 * @param [type] $arr: ...
503 * @param [type] $depthData: ...
504 * @param [type] $keyArray: ...
505 * @param [type] $first: ...
506 * @return [type] ...
507 */
508 function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0) {
509 reset($arr);
510 $keyArr=array();
511 while (list($key,)=each($arr)) {
512 $key=ereg_replace("\.$","",$key);
513 if (substr($key,-1)!=".") {
514 $keyArr[$key]=1;
515 }
516 }
517 reset($keyArr);
518 $a=0;
519 $c=count($keyArr);
520 while (list($key,)=each($keyArr)) {
521 $HTML="";
522 $a++;
523 $deeper = is_array($arr[$key."."]);
524 $row=$arr[$key];
525
526 $PM = "join";
527 $LN = ($a==$c)?"blank":"line";
528 $BTM = ($a==$c)?"top":"";
529 $PM = "join";
530
531 $HTML.=$depthData;
532 $icon = substr($row["templateID"],0,3)=="sys" ? t3lib_iconWorks::getIcon("sys_template",array("root"=>$row["root"])) :
533 (substr($row["templateID"],0,6)=="static" ? t3lib_iconWorks::getIcon("static_template",array()) : 'gfx/i/default.gif');
534 $alttext= "[".$row['templateID']."]";
535 $alttext.= $row['pid'] ? " - ".t3lib_BEfunc::getRecordPath($row['pid'],$GLOBALS["SOBE"]->perms_clause,20) : "";
536 if (in_array($row['templateID'],$this->clearList_const) || in_array($row['templateID'],$this->clearList_setup)) {
537 $A_B='<a href="index.php?id='.$GLOBALS["SOBE"]->id.'&template='.$row['templateID'].'">';
538 $A_E="</A>";
539 } else {
540 $A_B="";
541 $A_E="";
542 }
543 $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;";
544 $RL = $this->ext_getRootlineNumber($row['pid']);
545 $keyArray[] = '<tr>
546 <td nowrap>'.$HTML.'</td>
547 <td align=center>'.($row["root"]?"<b>X</b>":"").'&nbsp;&nbsp;</td>
548 <td align=center'.$row["bgcolor_setup"].'>'.fw(($row["clConf"]?"<b>X</b>":"")."&nbsp;&nbsp;").'</td>
549 <td align=center'.$row["bgcolor_const"].'>'.fw(($row["clConst"]?"<b>X</b>":"")."&nbsp;&nbsp;").'</td>
550 <td>'.($row["pid"]?"&nbsp;".$row["pid"].(strcmp($RL,"")?" (".$RL.")":"")."&nbsp;&nbsp;":"").'</td>
551 <td>'.($row["next"]?"&nbsp;".$row["next"]."&nbsp;&nbsp;":"").'</td>
552 </tr>';
553 if ($deeper) {
554 $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);
555 }
556 }
557 return $keyArray;
558 }
559
560 /**
561 * [Describe function...]
562 *
563 * @param [type] $depthDataArr: ...
564 * @param [type] $pointer: ...
565 * @return [type] ...
566 */
567 function ext_process_hierarchyInfo($depthDataArr,&$pointer) {
568 $parent = $this->hierarchyInfo[$pointer-1]['templateParent'];
569 while ($pointer>0 && $this->hierarchyInfo[$pointer-1]['templateParent']==$parent) {
570 $pointer--;
571 $row = $this->hierarchyInfo[$pointer];
572
573 $depthDataArr[$row['templateID']]=$row;
574 $depthDataArr[$row['templateID']]["bgcolor_setup"] = isset($this->clearList_setup_temp[$row['templateID']])?' class="bgColor5"':'';
575 $depthDataArr[$row['templateID']]["bgcolor_const"] = isset($this->clearList_const_temp[$row['templateID']])?' class="bgColor5"':'';
576 unset($this->clearList_setup_temp[$row['templateID']]);
577 unset($this->clearList_const_temp[$row['templateID']]);
578 $this->templateTitles[$row['templateID']]=$row["title"];
579
580 if ($row['templateID']==$this->hierarchyInfo[$pointer-1]['templateParent']) {
581 $depthDataArr[$row['templateID']."."] = $this->ext_process_hierarchyInfo(array(), $pointer);
582 }
583 }
584 return $depthDataArr;
585 }
586
587 /**
588 * [Describe function...]
589 *
590 * @param [type] $config: ...
591 * @param [type] $lineNumbers: ...
592 * @param [type] $comments: ...
593 * @param [type] $crop: ...
594 * @param [type] $syntaxHL: ...
595 * @param [type] $syntaxHLBlockmode: ...
596 * @return [type] ...
597 */
598 function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0) {
599 $all="";
600 reset($config);
601 while (list(,$str)=each($config)) {
602 $all.="\n[GLOBAL]\n".$str;
603 }
604
605 if ($syntaxHL) {
606 $all = ereg_replace("^[^".chr(10)."]*.","",$all);
607 $all = chop($all);
608 $tsparser = t3lib_div::makeInstance("t3lib_TSparser");
609 $tsparser->lineNumberOffset=$this->ext_lineNumberOffset+1;
610 return $tsparser->doSyntaxHighlight($all,$lineNumbers?array($this->ext_lineNumberOffset+1):'',$syntaxHLBlockmode);
611 } else {
612 return $this->ext_formatTS($all,$lineNumbers,$comments,$crop);
613 }
614 }
615
616 /**
617 * Returns a new string of max. $chars lenght
618 * If the string is longer, it will be truncated and prepended with "..."
619 * $chars must be an integer of at least 4
620 *
621 * @param [type] $string: ...
622 * @param [type] $chars: ...
623 * @return [type] ...
624 */
625 function ext_fixed_lgd($string,$chars) {
626 if ($chars >= 4) {
627 if(strlen($string)>$chars) {
628 return substr($string, 0, $chars-3)."...";
629 }
630 }
631 return $string;
632 }
633
634 /**
635 * [Describe function...]
636 *
637 * @param [type] $ln: ...
638 * @param [type] $str: ...
639 * @return [type] ...
640 */
641 function ext_lnBreakPointWrap($ln,$str) {
642 return '<A href="#" onClick="return brPoint('.$ln.','.($this->ext_lineNumberOffset_mode=="setup"?1:0).');">'.$str.'</a>';
643 }
644
645 /**
646 * [Describe function...]
647 *
648 * @param [type] $input: ...
649 * @param [type] $ln: ...
650 * @param [type] $comments: ...
651 * @param [type] $crop: ...
652 * @return [type] ...
653 */
654 function ext_formatTS($input, $ln, $comments=1, $crop=0) {
655 $input = ereg_replace("^[^".chr(10)."]*.","",$input);
656 $input = chop($input);
657 $cArr = explode(chr(10),$input);
658
659 reset($cArr);
660 $n = ceil(log10(count($cArr)+$this->ext_lineNumberOffset));
661 $lineNum="";
662 while(list($k,$v)=each($cArr)) {
663 $lln=$k+$this->ext_lineNumberOffset+1;
664 if ($ln) $lineNum = $this->ext_lnBreakPointWrap($lln,str_replace(" ",'&nbsp;',sprintf("% ".$n."d",$lln))).": ";
665 $v=htmlspecialchars($v);
666 if ($crop) {$v=$this->ext_fixed_lgd($v,($ln?71:77));}
667 $cArr[$k] = $lineNum.str_replace(" ",'&nbsp;',$v);
668
669 $firstChar = substr(trim($v),0,1);
670 if ($firstChar=="[") {
671 $cArr[$k] = '<font color="green"><b>'.$cArr[$k].'</b></font>';
672 } elseif ($firstChar=="/" || $firstChar=="#") {
673 if ($comments) {
674 $cArr[$k] = '<span class="typo3-dimmed">'.$cArr[$k].'</span>';
675 } else {
676 unset($cArr[$k]);
677 }
678 }
679
680
681 }
682 $output = implode($cArr, "<BR>")."<BR>";
683 return $output;
684 }
685
686 /**
687 * [Describe function...]
688 *
689 * @param [type] $id: ...
690 * @param [type] $template_uid: ...
691 * @return [type] ...
692 */
693 function ext_getFirstTemplate($id,$template_uid=0) {
694 // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
695 if (intval($id)) {
696 if ($template_uid) {
697 $addC = " AND uid=".$template_uid;
698 }
699 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).$addC.' '.$this->whereClause, '', 'sorting', '1');
700 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
701 $GLOBALS['TYPO3_DB']->sql_free_result($res);
702 return $row; // Returns the template row if found.
703 }
704 }
705
706 /**
707 * [Describe function...]
708 *
709 * @param [type] $id: ...
710 * @return [type] ...
711 */
712 function ext_getAllTemplates($id) {
713 // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
714 if (intval($id)) {
715 $outRes=array();
716 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).' '.$this->whereClause, '', 'sorting');
717 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
718 $outRes[] = $row;
719 }
720 $GLOBALS['TYPO3_DB']->sql_free_result($res);
721 return $outRes; // Returns the template rows in an array.
722 }
723 }
724
725 /**
726 * This function compares the flattened constants (default and all).
727 * Returns an array with the constants from the whole template which may be edited by the module.
728 *
729 * @param [type] $default: ...
730 * @return [type] ...
731 */
732 function ext_compareFlatSetups($default) {
733 $editableComments=array();
734 reset($this->flatSetup);
735 while(list($const,$value)=each($this->flatSetup)) {
736 if (substr($const,-2)!=".." && isset($this->flatSetup[$const.".."])) {
737 $comment = trim($this->flatSetup[$const.".."]);
738 $c_arr = explode(chr(10),$comment);
739 while(list($k,$v)=each($c_arr)) {
740 $line=trim(ereg_replace("^[#\/]*","",$v));
741 if ($line) {
742 $parts = explode(";", $line);
743 while(list(,$par)=each($parts)) {
744 if (strstr($par,"=")) {
745 $keyValPair =explode("=",$par,2);
746 switch(trim(strtolower($keyValPair[0]))) {
747 case "type":
748 // Type:
749 /*
750 int (range; low-high, list: item,item,item = selector),
751 boolean (check),
752 string (default),
753 wrap,
754 html-color ...,
755 file
756 */
757 $editableComments[$const]["type"] = trim($keyValPair[1]);
758 break;
759 case "cat":
760 // list of categories.
761 $catSplit=explode("/",strtolower($keyValPair[1]));
762 $editableComments[$const]["cat"] = trim($catSplit[0]);
763 $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.
764 if ($catSplit[1] && isset($this->subCategories[$catSplit[1]])) {
765 $editableComments[$const]["subcat_name"]=$catSplit[1];
766 $editableComments[$const]["subcat"]=$this->subCategories[$catSplit[1]][1]."/".$catSplit[1]."/".trim($catSplit[2])."z";
767 } else {
768 $editableComments[$const]["subcat"]="x"."/".trim($catSplit[2])."z";
769 }
770 break;
771 case "label":
772 // label
773 $editableComments[$const]["label"] = trim($keyValPair[1]);
774 break;
775 }
776 }
777 }
778 }
779 }
780 }
781 if (isset($editableComments[$const])) {
782 $editableComments[$const]["name"]=$const;
783 $editableComments[$const]["value"]=trim($value);
784 if (isset($default[$const])) {
785 $editableComments[$const]["default_value"]=trim($default[$const]);
786 }
787 }
788 }
789 return $editableComments;
790 }
791
792 /**
793 * [Describe function...]
794 *
795 * @param [type] $editConstArray: ...
796 * @return [type] ...
797 */
798 function ext_categorizeEditableConstants($editConstArray) {
799 // Runs through the available constants and fills the $this->categories array with pointers and priority-info
800 reset($editConstArray);
801 while(list($constName,$constData)=each($editConstArray)) {
802 if (!$constData["type"]) {$constData["type"]="string";}
803 $cats = explode(",",$constData["cat"]);
804 reset($cats);
805 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...
806 $theCat=trim($theCat);
807 if ($theCat) {
808 $this->categories[$theCat][$constName]=$constData["subcat"];
809 // $this->categories["all"][$constName]=$constData["subcat"];
810 }
811 }
812 }
813 // debug($this->categories);
814 }
815
816 /**
817 * [Describe function...]
818 *
819 * @return [type] ...
820 */
821 function ext_getCategoryLabelArray() {
822 // Returns array used for labels in the menu.
823 $retArr = array();
824 while(list($k,$v)=each($this->categories)) {
825 if (count($v)) {
826 $retArr[$k]=strtoupper($k)." (".count($v).")";
827 }
828 }
829 return $retArr;
830 }
831
832 /**
833 * [Describe function...]
834 *
835 * @param [type] $type: ...
836 * @return [type] ...
837 */
838 function ext_getTypeData($type) {
839 $retArr = array();
840 $type=trim($type);
841 if (!$type) {
842 $retArr["type"]="string";
843 } else {
844 $m=strcspn ($type," [");
845 $retArr["type"]=strtolower(substr($type,0,$m));
846 if (t3lib_div::inList("int,options,file,boolean,offset",$retArr["type"])) {
847 $p=trim(substr($type,$m));
848 ereg("\[(.*)\]",$p,$reg);
849 $p=trim($reg[1]);
850 if ($p) {
851 $retArr["paramstr"]=$p;
852 switch($retArr["type"]) {
853 case "int":
854 if (substr($retArr["paramstr"],0,1)=="-") {
855 $retArr["params"]=t3lib_div::intExplode("-",substr($retArr["paramstr"],1));
856 $retArr["params"][0]=intval("-".$retArr["params"][0]);
857 } else {
858 $retArr["params"]=t3lib_div::intExplode("-",$retArr["paramstr"]);
859 }
860 $retArr["paramstr"]=$retArr["params"][0]." - ".$retArr["params"][1];
861 break;
862 case "options":
863 $retArr["params"]=explode(",",$retArr["paramstr"]);
864 break;
865 }
866 }
867 }
868 }
869 // debug($retArr);
870 return $retArr;
871 }
872
873 /**
874 * [Describe function...]
875 *
876 * @param [type] $category: ...
877 * @return [type] ...
878 */
879 function ext_getTSCE_config($category) {
880 $catConf=$this->setup["constants"]["TSConstantEditor."][$category."."];
881 $out=array();
882 if (is_array($catConf)) {
883 reset($catConf);
884 while(list($key,$val)=each($catConf)) {
885 switch($key) {
886 case "image":
887 $out["imagetag"] = $this->ext_getTSCE_config_image($catConf["image"]);
888 break;
889 case "description":
890 case "bulletlist":
891 case "header":
892 $out[$key] = $val;
893 break;
894 default:
895 if (t3lib_div::testInt($key)) {
896 $constRefs = explode(",",$val);
897 reset($constRefs);
898 while(list(,$const)=each($constRefs)) {
899 $const=trim($const);
900 if ($const && $const<=20) {
901 $out["constants"][$const].=$this->ext_getKeyImage($key);
902 }
903 }
904 }
905 break;
906 }
907 }
908 }
909 $this->helpConfig=$out;
910 }
911
912 /**
913 * [Describe function...]
914 *
915 * @param [type] $key: ...
916 * @return [type] ...
917 */
918 function ext_getKeyImage($key) {
919 return '<img src="'.$this->ext_localWebGfxPrefix.'gfx/'.$key.'.gif" align="top" hspace=2>';
920 }
921
922 /**
923 * [Describe function...]
924 *
925 * @param [type] $imgConf: ...
926 * @return [type] ...
927 */
928 function ext_getTSCE_config_image($imgConf) {
929 if (substr($imgConf,0,4)=="gfx/") {
930 $iFile=$this->ext_localGfxPrefix.$imgConf;
931 $tFile=$this->ext_localWebGfxPrefix.$imgConf;
932 } elseif (substr($imgConf,0,4)=='EXT:') {
933 $iFile = t3lib_div::getFileAbsFileName($imgConf);
934 if ($iFile) {
935 $f = substr($iFile,strlen(PATH_site));
936 $tFile=$GLOBALS["BACK_PATH"]."../".$f;
937 }
938 } else {
939 $f = "uploads/tf/".$this->extractFromResources($this->setup["resources"],$imgConf);
940 $iFile=PATH_site.$f;
941 $tFile=$GLOBALS["BACK_PATH"]."../".$f;
942 }
943 $imageInfo=@getImagesize($iFile);
944 return '<img src="'.$tFile.'" '.$imageInfo[3].'>';
945 }
946
947 /**
948 * [Describe function...]
949 *
950 * @return [type] ...
951 */
952 function ext_resourceDims() {
953 if ($this->setup["resources"]) {
954 $rArr=explode(",",$this->setup["resources"]);
955 while(list($c,$val)=each($rArr)) {
956 $val=trim($val);
957 $theFile = PATH_site."uploads/tf/".$val;
958 if ($val && @is_file($theFile)) {
959 $imgInfo = @getimagesize($theFile);
960 }
961 if (is_array($imgInfo)) {
962 $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
963 }
964 }
965 }
966 reset($this->dirResources);
967 while(list($c,$val)=each($this->dirResources)) {
968 $val=trim($val);
969 $imgInfo = @getimagesize(PATH_site.$val);
970 if (is_array($imgInfo)) {
971 $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
972 }
973 }
974 }
975
976 /**
977 * [Describe function...]
978 *
979 * @param [type] $path: ...
980 * @return [type] ...
981 */
982 function ext_readDirResources($path) {
983 $path=trim($path);
984 if ($path && substr($path,0,10)=="fileadmin/") {
985 $path = ereg_replace("\/$","",$path);
986 $this->readDirectory(PATH_site.$path);
987 }
988 }
989
990 /**
991 * [Describe function...]
992 *
993 * @param [type] $path: ...
994 * @param [type] $type: ...
995 * @return [type] ...
996 */
997 function readDirectory($path,$type="file") {
998 if(@is_dir($path)) {
999 $d = @dir($path);
1000 $tempArray=Array();
1001 if (is_object($d)) {
1002 while($entry=$d->read()) {
1003 if ($entry!="." && $entry!="..") {
1004 $wholePath = $path."/".$entry; // Because of odd PHP-error where <BR>-tag is sometimes placed after a filename!!
1005 if (@file_exists($wholePath) && (!$type || filetype($wholePath)==$type)) {
1006 $fI = t3lib_div::split_fileref($wholePath);
1007 $this->dirResources[]=substr($wholePath,strlen(PATH_site));
1008 }
1009 }
1010 }
1011 $d->close();
1012 }
1013 }
1014 }
1015
1016 /**
1017 * [Describe function...]
1018 *
1019 * @param [type] $params: ...
1020 * @return [type] ...
1021 */
1022 function ext_fNandV($params) {
1023 $fN='data['.$params["name"].']';
1024 $fV=$params["value"];
1025 if (ereg("^{[\$][a-zA-Z0-9\.]*}$",trim($fV),$reg)) { // Values entered from the constantsedit cannot be constants! 230502; removed \{ and set {
1026 $fV="";
1027 }
1028 $fV=htmlspecialchars($fV);
1029
1030 return array($fN,$fV,$params);
1031 }
1032
1033 /**
1034 * [Describe function...]
1035 *
1036 * @param [type] $theConstants: ...
1037 * @param [type] $category: ...
1038 * @return [type] ...
1039 */
1040 function ext_printFields($theConstants,$category) {
1041 // This functions returns the HTML-code that creates the editor-layout of the module.
1042 reset($theConstants);
1043 $output="";
1044 $subcat="";
1045 if (is_array($this->categories[$category])) {
1046
1047 $help=$this->helpConfig;
1048 $this->rArr=explode(",",$this->setup["resources"].",".implode($this->dirResources,","));
1049
1050 asort($this->categories[$category]);
1051 while(list($name,$type)=each($this->categories[$category])) {
1052 $params = $theConstants[$name];
1053 if (is_array($params)) {
1054 if ($subcat!=$params["subcat_name"]) {
1055 $subcat=$params["subcat_name"];
1056 $subcat_name = $params["subcat_name"] ? $this->subCategories[$params["subcat_name"]][0] : "Others";
1057 $output.='<tr>';
1058 $output.='<td colspan=2 class="bgColor4"><div align="center"><b>'.$subcat_name.'</b></div></td>';
1059 $output.='</tr>';
1060 }
1061
1062 // if (substr($params["value"],0,2)!='{$') {
1063 $label=$GLOBALS["LANG"]->sL($params["label"]);
1064 $label_parts = explode(":",$label,2);
1065 if (count($label_parts)==2) {
1066 $head=trim($label_parts[0]);
1067 $body=trim($label_parts[1]);
1068 } else {
1069 $head=trim($label_parts[0]);
1070 $body="";
1071 }
1072 if (strlen($head)>35) {
1073 if (!$body) {$body=$head;}
1074 $head=t3lib_div::fixed_lgd($head,35);
1075 }
1076 $typeDat=$this->ext_getTypeData($params["type"]);
1077 $checked="";
1078 $p_field="";
1079 $raname = substr(md5($params["name"]),0,10);
1080 $aname="'".$raname."'";
1081 if ($this->ext_dontCheckIssetValues || isset($this->objReg[$params["name"]])) {
1082 $checked=" checked";
1083 list($fN,$fV,$params)=$this->ext_fNandV($params);
1084
1085 switch($typeDat["type"]) {
1086 case "int":
1087 case "int+":
1088 $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(5).' onChange="uFormUrl('.$aname.')">';
1089 if ($typeDat["paramstr"]) {
1090 $p_field.=' Range: '.$typeDat["paramstr"];
1091 } elseif ($typeDat["type"]=="int+") {
1092 $p_field.=' Range: 0 - ';
1093 } else {
1094 $p_field.=' (Integer)';
1095 }
1096 break;
1097 case "color":
1098 $colorNames=explode(",",",".$this->HTMLcolorList);
1099 $p_field="";
1100 while(list(,$val)=each($colorNames)) {
1101 $sel="";
1102 if ($val==strtolower($params["value"])) {$sel=" selected";}
1103 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.'</option>';
1104 }
1105 $p_field='<select name="C'.$fN.'" onChange="document.'.$this->ext_CEformName.'[\''.$fN.'\'].value=this.options[this.selectedIndex].value; uFormUrl('.$aname.');">'.$p_field.'</select>';
1106
1107 $p_field.='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(7).' onChange="uFormUrl('.$aname.')">';
1108 break;
1109 case "wrap":
1110 $wArr = explode("|",$fV);
1111 $p_field='<input type="text" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(29).' onChange="uFormUrl('.$aname.')">';
1112 $p_field.=' | ';
1113 $p_field.='<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(15).' onChange="uFormUrl('.$aname.')">';
1114 break;
1115 case "offset":
1116 $wArr = explode(",",$fV);
1117 $labels = t3lib_div::trimExplode(",",$typeDat["paramstr"]);
1118 $p_field=($labels[0]?$labels[0]:"x").':<input type="text" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
1119 $p_field.=' , ';
1120 $p_field.=($labels[1]?$labels[1]:"y").':<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
1121 for ($aa=2;$aa<count($labels);$aa++) {
1122 if ($labels[$aa]) {
1123 $p_field.=' , '.$labels[$aa].':<input type="text" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
1124 } else {
1125 $p_field.='<input type="hidden" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'">';
1126 }
1127 }
1128 break;
1129 case "options":
1130 if (is_array($typeDat["params"])) {
1131 $p_field="";
1132 while(list(,$val)=each($typeDat["params"])) {
1133 $vParts = explode("=",$val,2);
1134 $label = $vParts[0];
1135 $val = isset($vParts[1]) ? $vParts[1] : $vParts[0];
1136
1137 // option tag:
1138 $sel="";
1139 if ($val==$params["value"]) {$sel=" selected";}
1140 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$GLOBALS["LANG"]->sL($label).'</option>';
1141 }
1142 $p_field='<select name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
1143 }
1144 break;
1145 case "boolean":
1146 $p_field='<input type="Hidden" name="'.$fN.'" value="0">';
1147 $sel=""; if ($fV) {$sel=" checked";}
1148 $p_field.='<input type="Checkbox" name="'.$fN.'" value="'.($typeDat["paramstr"]?$typeDat["paramstr"]:1).'"'.$sel.' onClick="uFormUrl('.$aname.')">';
1149 break;
1150 case "comment":
1151 $p_field='<input type="Hidden" name="'.$fN.'" value="#">';
1152 $sel=""; if (!$fV) {$sel=" checked";}
1153 $p_field.='<input type="Checkbox" name="'.$fN.'" value=""'.$sel.' onClick="uFormUrl('.$aname.')">';
1154 break;
1155 case "file":
1156 $p_field='<option value=""></option>';
1157 // debug($params["value"]);
1158 $theImage="";
1159 // if ($this->) {
1160 $selectThisFile = $this->extractFromResources($this->setup["resources"],$params["value"]);
1161 if ($params["value"] && !$selectThisFile) {
1162 if (in_array($params["value"],$this->dirResources)) {
1163 $selectThisFile=$params["value"];
1164 }
1165 }
1166 // debug($selectThisFile);
1167 // extensionlist
1168 $extList = $typeDat["paramstr"];
1169 $p_field='<option value="">('.$extList.')</option>';
1170 if ($extList=="IMAGE_EXT") {
1171 $extList = $GLOBALS["TYPO3_CONF_VARS"]["GFX"]["imagefile_ext"];
1172 }
1173 reset($this->rArr);
1174 $onlineResourceFlag=$this->ext_defaultOnlineResourceFlag;
1175
1176 while(list($c,$val)=each($this->rArr)) {
1177 $val=trim($val);
1178 $fI=t3lib_div::split_fileref($val);
1179 // debug($fI);
1180 if ($val && (!$extList || t3lib_div::inList($extList,$fI["fileext"]))) {
1181 if ($onlineResourceFlag<=0 && substr($fI["path"],0,10)=="fileadmin/") {
1182 if ($onlineResourceFlag<0) {
1183 $p_field.='<option value=""></option>';
1184 }
1185 $p_field.='<option value="">__'.$fI["path"].'__:</option>';
1186 $onlineResourceFlag=1;
1187 }
1188 $dims=$this->resourceDimensions[$val];
1189 $sel="";
1190
1191 // Check if $params["value"] is in the list of resources.
1192 if ($selectThisFile && $selectThisFile==$val) {
1193 $sel=" selected";
1194 if ($onlineResourceFlag<=0) {
1195 $theImage=t3lib_BEfunc::thumbCode(array("resources"=>$selectThisFile),"sys_template","resources",$GLOBALS["BACK_PATH"],"");
1196 } else {
1197 $theImage=t3lib_BEfunc::thumbCode(array("resources"=>$fI["file"]),"sys_template","resources",$GLOBALS["BACK_PATH"],"",$fI["path"]);
1198 }
1199 }
1200
1201 if ($onlineResourceFlag<=0) {
1202 $onlineResourceFlag--;
1203 // Value is set with a *
1204 $val = $this->ext_setStar($val);
1205 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.$dims.'</option>';
1206 } else {
1207 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$fI["file"].$dims.'</option>';
1208 }
1209 }
1210 }
1211 if (trim($params["value"]) && !$selectThisFile) {
1212 $val = $params["value"];
1213 $p_field.='<option value=""></option>';
1214 $p_field.='<option value="'.htmlspecialchars($val).'" selected>'.$val.'</option>';
1215 }
1216 // }
1217 $p_field='<select name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
1218 $p_field.=$theImage;
1219
1220 if (!$this->ext_noCEUploadAndCopying) {
1221 // Copy a resource
1222 $copyFile = $this->extractFromResources($this->setup["resources"],$params["value"]);
1223 if (!$copyFile) {
1224 if ($params["value"]) {
1225 $copyFile=PATH_site.$this->ext_detectAndFixExtensionPrefix($params["value"]);
1226 }
1227 } else {
1228 // $copyFile=PATH_site."uploads/tf/".$copyFile;
1229 $copyFile="";
1230 }
1231 #debug($copyFile);
1232 if ($copyFile && @is_file($copyFile)) {
1233 $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"])).'\'));}">';
1234 }
1235 // Upload?
1236 $p_field.='<BR>';
1237 $p_field.='<input type="file" name="upload_'.$fN.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth().' onChange="uFormUrl('.$aname.')" size="50" />';
1238 }
1239 break;
1240 case 'small':
1241 default:
1242 $fwidth= $typeDat["type"]=="small" ? 10 : 46;
1243 $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth($fwidth).' onChange="uFormUrl('.$aname.')">';
1244 break;
1245 }
1246 }
1247 if (!$this->ext_dontCheckIssetValues) $p_field='<input type="Checkbox" name="check['.$params["name"].']" value="1"'.$checked.' onClick="uFormUrl('.$aname.')">'.$p_field;
1248 if ($typeDat["type"]=="color" && substr($params["value"],0,2)!='{$') {
1249 $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>';
1250 } else {
1251 $p_field='<span class="nobr">'.$p_field.'</span><br />';
1252 }
1253
1254 $p_name = '<span class="typo3-dimmed">['.$params["name"].']</span><BR>';
1255 $p_dlabel='<span class="typo3-dimmed"><b>Default:</b> '.htmlspecialchars($params["default_value"]).'</span><BR>';
1256 $p_label = '<b>'.htmlspecialchars($head).'</b>';
1257 $p_descrip = $body ? htmlspecialchars($body)."<BR>" : "";
1258
1259 $output.='<tr>';
1260 $output.='<td valign=top nowrap><a name="'.$raname.'"></a>'.$help["constants"][$params["name"]].$p_label.'</td>';
1261 $output.='<td valign=top align="right">'.$p_name.'</td>';
1262 $output.='</tr>';
1263 $output.='<tr>';
1264 $output.='<td colspan=2>'.$p_descrip.$p_field.$p_dlabel.'<br></td>';
1265 $output.='</tr>';
1266 // }
1267 } else {
1268 debug("Error. Constant did not exits. Should not happen.");
1269 }
1270 }
1271 $output='<table border=0 cellpadding=0 cellspacing=0>'.$output.'</table>';
1272 }
1273 return $output;
1274 }
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287 /***************************
1288 *
1289 * Processing input values
1290 *
1291 ***************************/
1292
1293 /**
1294 * @param [type] $constants: ...
1295 * @return [type] ...
1296 */
1297 function ext_regObjectPositions($constants) {
1298 // 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
1299 $this->raw = explode(chr(10),$constants);
1300 $this->rawP=0;
1301
1302 $this->objReg=array(); // resetting the objReg if the divider is found!!
1303 $this->ext_regObjects("");
1304 }
1305
1306 /**
1307 * [Describe function...]
1308 *
1309 * @param [type] $pre: ...
1310 * @return [type] ...
1311 */
1312 function ext_regObjects($pre) {
1313 // works with regObjectPositions. "expands" the names of the TypoScript objects
1314 while (isset($this->raw[$this->rawP])) {
1315 $line = ltrim($this->raw[$this->rawP]);
1316 if (strstr($line,$this->edit_divider)) {
1317 $this->objReg=array(); // resetting the objReg if the divider is found!!
1318 }
1319 $this->rawP++;
1320 if ($line) {
1321 if (substr($line,0,1)=="[") {
1322 // return $line;
1323 } elseif (strcspn($line,"}#/")!=0) {
1324 $varL = strcspn($line," {=<");
1325 $var=substr($line,0,$varL);
1326 $line = ltrim(substr($line,$varL));
1327 switch(substr($line,0,1)) {
1328 case "=":
1329 $this->objReg[$pre.$var]=$this->rawP-1;
1330 break;
1331 case "{":
1332 $this->ext_inBrace++;
1333 $this->ext_regObjects($pre.$var.".");
1334 break;
1335 }
1336 $this->lastComment="";
1337 } elseif (substr($line,0,1)=="}") {
1338 $this->lastComment="";
1339 $this->ext_inBrace--;
1340 if ($this->ext_inBrace<0) {
1341 $this->ext_inBrace=0;
1342 } else {
1343 break;
1344 }
1345 }
1346 }
1347 }
1348 }
1349
1350 /**
1351 * [Describe function...]
1352 *
1353 * @param [type] $key: ...
1354 * @param [type] $var: ...
1355 * @return [type] ...
1356 */
1357 function ext_putValueInConf($key, $var) {
1358 // Puts the value $var to the TypoScript value $key in the current lines of the templates.
1359 // If the $key is not found in the template constants field, a new line is inserted in the bottom.
1360 $theValue = " ".trim($var);
1361 if (isset($this->objReg[$key])) {
1362 $lineNum = $this->objReg[$key];
1363 $parts = explode("=",$this->raw[$lineNum],2);
1364 if (count($parts)==2) {
1365 $parts[1]= $theValue;
1366 }
1367 $this->raw[$lineNum]=implode($parts,"=");
1368 } else {
1369 $this->raw[]=$key." =".$theValue;
1370 }
1371 $this->changed=1;
1372 }
1373
1374 /**
1375 * [Describe function...]
1376 *
1377 * @param [type] $key: ...
1378 * @return [type] ...
1379 */
1380 function ext_removeValueInConf($key) {
1381 // Removes the value in the configuration
1382 if (isset($this->objReg[$key])) {
1383 $lineNum = $this->objReg[$key];
1384 unset($this->raw[$lineNum]);
1385 }
1386 $this->changed=1;
1387 }
1388
1389 /**
1390 * [Describe function...]
1391 *
1392 * @param [type] $arr: ...
1393 * @param [type] $settings: ...
1394 * @return [type] ...
1395 */
1396 function ext_depthKeys($arr,$settings) {
1397 reset($arr);
1398 $tsbrArray=array();
1399 while(list($theK,$theV)=each($arr)) {
1400 $theKeyParts = explode(".",$theK);
1401 $depth="";
1402 $c=count($theKeyParts);
1403 $a=0;
1404 while(list(,$p)=each($theKeyParts)) {
1405 $a++;
1406 $depth.=($depth?".":"").$p;
1407 $tsbrArray[$depth]= ($c==$a) ? $theV : 1;
1408 }
1409 }
1410 // Modify settings
1411 reset($tsbrArray);
1412 while(list($theK,$theV)=each($tsbrArray)) {
1413 if ($theV) {
1414 $settings[$theK] = 1;
1415 } else {
1416 unset($settings[$theK]);
1417 }
1418 }
1419 return $settings;
1420 }
1421
1422 /**
1423 * [Describe function...]
1424 *
1425 * @param [type] $http_post_vars: ...
1426 * @param [type] $http_post_files: ...
1427 * @param [type] $theConstants: ...
1428 * @param [type] $tplRow: ...
1429 * @return [type] ...
1430 */
1431 function ext_procesInput($http_post_vars,$http_post_files,$theConstants,$tplRow) {
1432 $data=$http_post_vars["data"];
1433 $check=$http_post_vars["check"];
1434 $copyResource=$http_post_vars["_copyResource"];
1435 $Wdata=$http_post_vars["Wdata"];
1436 $W2data=$http_post_vars["W2data"];
1437 $W3data=$http_post_vars["W3data"];
1438 $W4data=$http_post_vars["W4data"];
1439 $W5data=$http_post_vars["W5data"];
1440
1441 if (is_array($data)) {
1442 reset($data);
1443 while(list($key,$var)=each($data)) {
1444 if (isset($theConstants[$key])) {
1445 if ($this->ext_dontCheckIssetValues || isset($check[$key])) { // If checkbox is set, update the value
1446 list($var) = explode(chr(10),$var); // exploding with linebreak, just to make sure that no multiline input is given!
1447 $typeDat=$this->ext_getTypeData($theConstants[$key]["type"]);
1448 switch($typeDat["type"]) {
1449 case "int":
1450 if ($typeDat["paramstr"]) {
1451 $var=t3lib_div::intInRange($var,$typeDat["params"][0],$typeDat["params"][1]);
1452 } else {
1453 $var=intval($var);
1454 }
1455 break;
1456 case "int+":
1457 $var=t3lib_div::intInRange($var,0,10000);
1458 break;
1459 case "color":
1460 $col=array();
1461 if($var && !t3lib_div::inList($this->HTMLcolorList,strtolower($var))) {
1462 $var = ereg_replace("[^A-Fa-f0-9]*","",$var);
1463 $col[]=HexDec(substr($var,0,2));
1464 $col[]=HexDec(substr($var,2,2));
1465 $col[]=HexDec(substr($var,4,2));
1466 $var="#".strtoupper(substr("0".DecHex($col[0]),-2).substr("0".DecHex($col[1]),-2).substr("0".DecHex($col[2]),-2));
1467 }
1468 break;
1469 case "comment":
1470 if ($val) {
1471 $val="#";
1472 } else {
1473 $val="";
1474 }
1475 break;
1476 case "wrap":
1477 if (isset($Wdata[$key])) {
1478 $var.="|".$Wdata[$key];
1479 }
1480 break;
1481 case "offset":
1482 if (isset($Wdata[$key])) {
1483 $var=intval($var).",".intval($Wdata[$key]);
1484 if (isset($W2data[$key])) {
1485 $var.=",".intval($W2data[$key]);
1486 if (isset($W3data[$key])) {
1487 $var.=",".intval($W3data[$key]);
1488 if (isset($W4data[$key])) {
1489 $var.=",".intval($W4data[$key]);
1490 if (isset($W5data[$key])) {
1491 $var.=",".intval($W5data[$key]);
1492 }
1493 }
1494 }
1495 }
1496 }
1497 break;
1498 case "boolean":
1499 if ($var) {
1500 $var = $typeDat["paramstr"] ? $typeDat["paramstr"] : 1;
1501 }
1502 break;
1503 case "file":
1504 if (!$this->ext_noCEUploadAndCopying) {
1505 if ($http_post_files["upload_data"]["name"][$key] && $http_post_files["upload_data"]["tmp_name"][$key]!="none") {
1506 $var = $this->upload_copy_file(
1507 $typeDat,
1508 $tplRow,
1509 trim($http_post_files["upload_data"]["name"][$key]),
1510 $http_post_files["upload_data"]["tmp_name"][$key]
1511 );
1512 }
1513 if ($copyResource[$key]) {
1514 $var = $this->upload_copy_file(
1515 $typeDat,
1516 $tplRow,
1517 basename($copyResource[$key]),
1518 $copyResource[$key]
1519 );
1520 }
1521 }
1522 break;
1523 }
1524 if ($this->ext_printAll || strcmp($theConstants[$key]["value"],$var)) {
1525 $this->ext_putValueInConf($key, $var); // Put value in, if changed.
1526 }
1527 unset($check[$key]); // Remove the entry because it has been "used"
1528 } else {
1529 $this->ext_removeValueInConf($key);
1530 }
1531 }
1532 }
1533 }
1534 // 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...
1535 if (!$this->ext_dontCheckIssetValues && is_array($check)) {
1536 reset($check);
1537 while(list($key,$var)=each($check)) {
1538 if (isset($theConstants[$key])) {
1539 $dValue = $theConstants[$key]["default_value"];
1540 // debug($dValue);
1541 $this->ext_putValueInConf($key, $dValue);
1542 // debug($key,1);
1543 }
1544 }
1545 }
1546 // debug($this->objReg);
1547 }
1548
1549 /**
1550 * [Describe function...]
1551 *
1552 * @param [type] $typeDat: ...
1553 * @param [type] $tplRow: ...
1554 * @param [type] $theRealFileName: ...
1555 * @param [type] $tmp_name: ...
1556 * @return [type] ...
1557 */
1558 function upload_copy_file($typeDat,&$tplRow,$theRealFileName,$tmp_name) {
1559
1560 // extensions
1561 $extList = $typeDat["paramstr"];
1562 if ($extList=="IMAGE_EXT") {
1563 $extList = $GLOBALS["TYPO3_CONF_VARS"]["GFX"]["imagefile_ext"];
1564 }
1565 $fI=t3lib_div::split_fileref($theRealFileName);
1566 if ($theRealFileName && (!$extList || t3lib_div::inList($extList,$fI["fileext"]))) {
1567 $tmp_upload_name = t3lib_div::upload_to_tempfile($tmp_name); // If there is an uploaded file, move it for the sake of safe_mode.
1568
1569 // Saving resource
1570 $alternativeFileName=array();
1571 $alternativeFileName[$tmp_upload_name] = $theRealFileName;
1572 // Making list of resources
1573 $resList = $tplRow["resources"];
1574 $resList = $tmp_upload_name.",".$resList;
1575 $resList=implode(t3lib_div::trimExplode(",",$resList,1),",");
1576 // Making data-array
1577 $recData=array();
1578 $recData["sys_template"][$tplRow["uid"]]["resources"] = $resList;
1579 // Saving
1580 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
1581 $tce->stripslashes_values=0;
1582 $tce->alternativeFileName = $alternativeFileName;
1583 $tce->start($recData,Array());
1584 $tce->process_datamap();
1585
1586 t3lib_div::unlink_tempfile($tmp_upload_name);
1587
1588 $tmpRow = t3lib_BEfunc::getRecord("sys_template",$tplRow["uid"],"resources");
1589 $tplRow["resources"] = $tmpRow["resources"];
1590
1591 // Setting the value
1592 $var = $this->ext_setStar($theRealFileName);
1593 }
1594 return $var;
1595 }
1596
1597 /**
1598 * [Describe function...]
1599 *
1600 * @param [type] $id: ...
1601 * @param [type] $perms_clause: ...
1602 * @return [type] ...
1603 */
1604 function ext_prevPageWithTemplate($id,$perms_clause) {
1605 $rootLine = t3lib_BEfunc::BEgetRootLine($id,$perms_clause?" AND ".$perms_clause:"");
1606 reset($rootLine);
1607 while(list(,$p)=each($rootLine)) {
1608 if ($this->ext_getFirstTemplate($p["uid"])) {
1609 return $p;
1610 }
1611 }
1612 }
1613
1614 /**
1615 * [Describe function...]
1616 *
1617 * @param [type] $val: ...
1618 * @return [type] ...
1619 */
1620 function ext_setStar($val) {
1621 $fParts = explode(".",strrev($val),2);
1622 $val=ereg_replace("_[0-9][0-9]$","",strrev($fParts[1]))."*.".strrev($fParts[0]);
1623 return $val;
1624 }
1625
1626 /**
1627 * [Describe function...]
1628 *
1629 * @param [type] $value: ...
1630 * @return [type] ...
1631 */
1632 function ext_detectAndFixExtensionPrefix($value) {
1633 if (substr($value,0,4)=="EXT:") {
1634 $parts = explode("/",substr($value,4),2);
1635 #debug($parts);
1636 $extPath = t3lib_extMgm::siteRelPath($parts[0]);
1637 $value = $extPath.$parts[1];
1638 return $value;
1639 } else {
1640 return $value;
1641 }
1642 }
1643 }
1644
1645
1646 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php']) {
1647 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php']);
1648 }
1649 ?>