682205b4fa3946b46a1a8c4f5093ed1fab0f949c
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tsparser_ext.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 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 * 713: function ext_getAllTemplates($id)
58 * 734: function ext_compareFlatSetups($default)
59 * 800: function ext_categorizeEditableConstants($editConstArray)
60 * 823: function ext_getCategoryLabelArray()
61 * 840: function ext_getTypeData($type)
62 * 881: function ext_getTSCE_config($category)
63 * 920: function ext_getKeyImage($key)
64 * 930: function ext_getTSCE_config_image($imgConf)
65 * 954: function ext_resourceDims()
66 * 984: function ext_readDirResources($path)
67 * 999: function readDirectory($path,$type="file")
68 * 1024: function ext_fNandV($params)
69 * 1042: function ext_printFields($theConstants,$category)
70 *
71 * SECTION: Processing input values
72 * 1299: function ext_regObjectPositions($constants)
73 * 1314: function ext_regObjects($pre)
74 * 1359: function ext_putValueInConf($key, $var)
75 * 1382: function ext_removeValueInConf($key)
76 * 1398: function ext_depthKeys($arr,$settings)
77 * 1433: function ext_procesInput($http_post_vars,$http_post_files,$theConstants,$tplRow)
78 * 1560: function upload_copy_file($typeDat,&$tplRow,$theRealFileName,$tmp_name)
79 * 1601: function ext_prevPageWithTemplate($id,$perms_clause)
80 * 1617: function ext_setStar($val)
81 * 1629: 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 $query = "SELECT * FROM sys_template WHERE pid = ".intval($id).$addC." ".$this->whereClause." ORDER BY sorting LIMIT 1";
700 $res = mysql(TYPO3_db, $query);
701 echo mysql_error();
702 $row = mysql_fetch_assoc($res);
703 return $row; // Returns the template row if found.
704 }
705 }
706
707 /**
708 * [Describe function...]
709 *
710 * @param [type] $id: ...
711 * @return [type] ...
712 */
713 function ext_getAllTemplates($id) {
714 // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
715 if (intval($id)) {
716 $query = "SELECT * FROM sys_template WHERE pid = ".intval($id)." ".$this->whereClause." ORDER BY sorting";
717 $res = mysql(TYPO3_db, $query);
718 echo mysql_error();
719 $outRes=array();
720 while($row = mysql_fetch_assoc($res)) {
721 $outRes[] = $row;
722 }
723 return $outRes; // Returns the template rows in an array.
724 }
725 }
726
727 /**
728 * This function compares the flattened constants (default and all).
729 * Returns an array with the constants from the whole template which may be edited by the module.
730 *
731 * @param [type] $default: ...
732 * @return [type] ...
733 */
734 function ext_compareFlatSetups($default) {
735 $editableComments=array();
736 reset($this->flatSetup);
737 while(list($const,$value)=each($this->flatSetup)) {
738 if (substr($const,-2)!=".." && isset($this->flatSetup[$const.".."])) {
739 $comment = trim($this->flatSetup[$const.".."]);
740 $c_arr = explode(chr(10),$comment);
741 while(list($k,$v)=each($c_arr)) {
742 $line=trim(ereg_replace("^[#\/]*","",$v));
743 if ($line) {
744 $parts = explode(";", $line);
745 while(list(,$par)=each($parts)) {
746 if (strstr($par,"=")) {
747 $keyValPair =explode("=",$par,2);
748 switch(trim(strtolower($keyValPair[0]))) {
749 case "type":
750 // Type:
751 /*
752 int (range; low-high, list: item,item,item = selector),
753 boolean (check),
754 string (default),
755 wrap,
756 html-color ...,
757 file
758 */
759 $editableComments[$const]["type"] = trim($keyValPair[1]);
760 break;
761 case "cat":
762 // list of categories.
763 $catSplit=explode("/",strtolower($keyValPair[1]));
764 $editableComments[$const]["cat"] = trim($catSplit[0]);
765 $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.
766 if ($catSplit[1] && isset($this->subCategories[$catSplit[1]])) {
767 $editableComments[$const]["subcat_name"]=$catSplit[1];
768 $editableComments[$const]["subcat"]=$this->subCategories[$catSplit[1]][1]."/".$catSplit[1]."/".trim($catSplit[2])."z";
769 } else {
770 $editableComments[$const]["subcat"]="x"."/".trim($catSplit[2])."z";
771 }
772 break;
773 case "label":
774 // label
775 $editableComments[$const]["label"] = trim($keyValPair[1]);
776 break;
777 }
778 }
779 }
780 }
781 }
782 }
783 if (isset($editableComments[$const])) {
784 $editableComments[$const]["name"]=$const;
785 $editableComments[$const]["value"]=trim($value);
786 if (isset($default[$const])) {
787 $editableComments[$const]["default_value"]=trim($default[$const]);
788 }
789 }
790 }
791 return $editableComments;
792 }
793
794 /**
795 * [Describe function...]
796 *
797 * @param [type] $editConstArray: ...
798 * @return [type] ...
799 */
800 function ext_categorizeEditableConstants($editConstArray) {
801 // Runs through the available constants and fills the $this->categories array with pointers and priority-info
802 reset($editConstArray);
803 while(list($constName,$constData)=each($editConstArray)) {
804 if (!$constData["type"]) {$constData["type"]="string";}
805 $cats = explode(",",$constData["cat"]);
806 reset($cats);
807 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...
808 $theCat=trim($theCat);
809 if ($theCat) {
810 $this->categories[$theCat][$constName]=$constData["subcat"];
811 // $this->categories["all"][$constName]=$constData["subcat"];
812 }
813 }
814 }
815 // debug($this->categories);
816 }
817
818 /**
819 * [Describe function...]
820 *
821 * @return [type] ...
822 */
823 function ext_getCategoryLabelArray() {
824 // Returns array used for labels in the menu.
825 $retArr = array();
826 while(list($k,$v)=each($this->categories)) {
827 if (count($v)) {
828 $retArr[$k]=strtoupper($k)." (".count($v).")";
829 }
830 }
831 return $retArr;
832 }
833
834 /**
835 * [Describe function...]
836 *
837 * @param [type] $type: ...
838 * @return [type] ...
839 */
840 function ext_getTypeData($type) {
841 $retArr = array();
842 $type=trim($type);
843 if (!$type) {
844 $retArr["type"]="string";
845 } else {
846 $m=strcspn ($type," [");
847 $retArr["type"]=strtolower(substr($type,0,$m));
848 if (t3lib_div::inList("int,options,file,boolean,offset",$retArr["type"])) {
849 $p=trim(substr($type,$m));
850 ereg("\[(.*)\]",$p,$reg);
851 $p=trim($reg[1]);
852 if ($p) {
853 $retArr["paramstr"]=$p;
854 switch($retArr["type"]) {
855 case "int":
856 if (substr($retArr["paramstr"],0,1)=="-") {
857 $retArr["params"]=t3lib_div::intExplode("-",substr($retArr["paramstr"],1));
858 $retArr["params"][0]=intval("-".$retArr["params"][0]);
859 } else {
860 $retArr["params"]=t3lib_div::intExplode("-",$retArr["paramstr"]);
861 }
862 $retArr["paramstr"]=$retArr["params"][0]." - ".$retArr["params"][1];
863 break;
864 case "options":
865 $retArr["params"]=explode(",",$retArr["paramstr"]);
866 break;
867 }
868 }
869 }
870 }
871 // debug($retArr);
872 return $retArr;
873 }
874
875 /**
876 * [Describe function...]
877 *
878 * @param [type] $category: ...
879 * @return [type] ...
880 */
881 function ext_getTSCE_config($category) {
882 $catConf=$this->setup["constants"]["TSConstantEditor."][$category."."];
883 $out=array();
884 if (is_array($catConf)) {
885 reset($catConf);
886 while(list($key,$val)=each($catConf)) {
887 switch($key) {
888 case "image":
889 $out["imagetag"] = $this->ext_getTSCE_config_image($catConf["image"]);
890 break;
891 case "description":
892 case "bulletlist":
893 case "header":
894 $out[$key] = $val;
895 break;
896 default:
897 if (t3lib_div::testInt($key)) {
898 $constRefs = explode(",",$val);
899 reset($constRefs);
900 while(list(,$const)=each($constRefs)) {
901 $const=trim($const);
902 if ($const && $const<=20) {
903 $out["constants"][$const].=$this->ext_getKeyImage($key);
904 }
905 }
906 }
907 break;
908 }
909 }
910 }
911 $this->helpConfig=$out;
912 }
913
914 /**
915 * [Describe function...]
916 *
917 * @param [type] $key: ...
918 * @return [type] ...
919 */
920 function ext_getKeyImage($key) {
921 return '<img src="'.$this->ext_localWebGfxPrefix.'gfx/'.$key.'.gif" align="top" hspace=2>';
922 }
923
924 /**
925 * [Describe function...]
926 *
927 * @param [type] $imgConf: ...
928 * @return [type] ...
929 */
930 function ext_getTSCE_config_image($imgConf) {
931 if (substr($imgConf,0,4)=="gfx/") {
932 $iFile=$this->ext_localGfxPrefix.$imgConf;
933 $tFile=$this->ext_localWebGfxPrefix.$imgConf;
934 } elseif (substr($imgConf,0,4)=='EXT:') {
935 $iFile = t3lib_div::getFileAbsFileName($imgConf);
936 if ($iFile) {
937 $f = substr($iFile,strlen(PATH_site));
938 $tFile=$GLOBALS["BACK_PATH"]."../".$f;
939 }
940 } else {
941 $f = "uploads/tf/".$this->extractFromResources($this->setup["resources"],$imgConf);
942 $iFile=PATH_site.$f;
943 $tFile=$GLOBALS["BACK_PATH"]."../".$f;
944 }
945 $imageInfo=@getImagesize($iFile);
946 return '<img src="'.$tFile.'" '.$imageInfo[3].'>';
947 }
948
949 /**
950 * [Describe function...]
951 *
952 * @return [type] ...
953 */
954 function ext_resourceDims() {
955 if ($this->setup["resources"]) {
956 $rArr=explode(",",$this->setup["resources"]);
957 while(list($c,$val)=each($rArr)) {
958 $val=trim($val);
959 $theFile = PATH_site."uploads/tf/".$val;
960 if ($val && @is_file($theFile)) {
961 $imgInfo = @getimagesize($theFile);
962 }
963 if (is_array($imgInfo)) {
964 $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
965 }
966 }
967 }
968 reset($this->dirResources);
969 while(list($c,$val)=each($this->dirResources)) {
970 $val=trim($val);
971 $imgInfo = @getimagesize(PATH_site.$val);
972 if (is_array($imgInfo)) {
973 $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
974 }
975 }
976 }
977
978 /**
979 * [Describe function...]
980 *
981 * @param [type] $path: ...
982 * @return [type] ...
983 */
984 function ext_readDirResources($path) {
985 $path=trim($path);
986 if ($path && substr($path,0,10)=="fileadmin/") {
987 $path = ereg_replace("\/$","",$path);
988 $this->readDirectory(PATH_site.$path);
989 }
990 }
991
992 /**
993 * [Describe function...]
994 *
995 * @param [type] $path: ...
996 * @param [type] $type: ...
997 * @return [type] ...
998 */
999 function readDirectory($path,$type="file") {
1000 if(@is_dir($path)) {
1001 $d = @dir($path);
1002 $tempArray=Array();
1003 if (is_object($d)) {
1004 while($entry=$d->read()) {
1005 if ($entry!="." && $entry!="..") {
1006 $wholePath = $path."/".$entry; // Because of odd PHP-error where <BR>-tag is sometimes placed after a filename!!
1007 if (@file_exists($wholePath) && (!$type || filetype($wholePath)==$type)) {
1008 $fI = t3lib_div::split_fileref($wholePath);
1009 $this->dirResources[]=substr($wholePath,strlen(PATH_site));
1010 }
1011 }
1012 }
1013 $d->close();
1014 }
1015 }
1016 }
1017
1018 /**
1019 * [Describe function...]
1020 *
1021 * @param [type] $params: ...
1022 * @return [type] ...
1023 */
1024 function ext_fNandV($params) {
1025 $fN='data['.$params["name"].']';
1026 $fV=$params["value"];
1027 if (ereg("^{[\$][a-zA-Z0-9\.]*}$",trim($fV),$reg)) { // Values entered from the constantsedit cannot be constants! 230502; removed \{ and set {
1028 $fV="";
1029 }
1030 $fV=htmlspecialchars($fV);
1031
1032 return array($fN,$fV,$params);
1033 }
1034
1035 /**
1036 * [Describe function...]
1037 *
1038 * @param [type] $theConstants: ...
1039 * @param [type] $category: ...
1040 * @return [type] ...
1041 */
1042 function ext_printFields($theConstants,$category) {
1043 // This functions returns the HTML-code that creates the editor-layout of the module.
1044 reset($theConstants);
1045 $output="";
1046 $subcat="";
1047 if (is_array($this->categories[$category])) {
1048
1049 $help=$this->helpConfig;
1050 $this->rArr=explode(",",$this->setup["resources"].",".implode($this->dirResources,","));
1051
1052 asort($this->categories[$category]);
1053 while(list($name,$type)=each($this->categories[$category])) {
1054 $params = $theConstants[$name];
1055 if (is_array($params)) {
1056 if ($subcat!=$params["subcat_name"]) {
1057 $subcat=$params["subcat_name"];
1058 $subcat_name = $params["subcat_name"] ? $this->subCategories[$params["subcat_name"]][0] : "Others";
1059 $output.='<tr>';
1060 $output.='<td colspan=2 class="bgColor4"><div align="center"><b>'.$subcat_name.'</b></div></td>';
1061 $output.='</tr>';
1062 }
1063
1064 // if (substr($params["value"],0,2)!='{$') {
1065 $label=$GLOBALS["LANG"]->sL($params["label"]);
1066 $label_parts = explode(":",$label,2);
1067 if (count($label_parts)==2) {
1068 $head=trim($label_parts[0]);
1069 $body=trim($label_parts[1]);
1070 } else {
1071 $head=trim($label_parts[0]);
1072 $body="";
1073 }
1074 if (strlen($head)>35) {
1075 if (!$body) {$body=$head;}
1076 $head=t3lib_div::fixed_lgd($head,35);
1077 }
1078 $typeDat=$this->ext_getTypeData($params["type"]);
1079 $checked="";
1080 $p_field="";
1081 $raname = substr(md5($params["name"]),0,10);
1082 $aname="'".$raname."'";
1083 if ($this->ext_dontCheckIssetValues || isset($this->objReg[$params["name"]])) {
1084 $checked=" checked";
1085 list($fN,$fV,$params)=$this->ext_fNandV($params);
1086
1087 switch($typeDat["type"]) {
1088 case "int":
1089 case "int+":
1090 $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(5).' onChange="uFormUrl('.$aname.')">';
1091 if ($typeDat["paramstr"]) {
1092 $p_field.=' Range: '.$typeDat["paramstr"];
1093 } elseif ($typeDat["type"]=="int+") {
1094 $p_field.=' Range: 0 - ';
1095 } else {
1096 $p_field.=' (Integer)';
1097 }
1098 break;
1099 case "color":
1100 $colorNames=explode(",",",".$this->HTMLcolorList);
1101 $p_field="";
1102 while(list(,$val)=each($colorNames)) {
1103 $sel="";
1104 if ($val==strtolower($params["value"])) {$sel=" selected";}
1105 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.'</option>';
1106 }
1107 $p_field='<select name="C'.$fN.'" onChange="document.'.$this->ext_CEformName.'[\''.$fN.'\'].value=this.options[this.selectedIndex].value; uFormUrl('.$aname.');">'.$p_field.'</select>';
1108
1109 $p_field.='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(7).' onChange="uFormUrl('.$aname.')">';
1110 break;
1111 case "wrap":
1112 $wArr = explode("|",$fV);
1113 $p_field='<input type="text" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(29).' onChange="uFormUrl('.$aname.')">';
1114 $p_field.=' | ';
1115 $p_field.='<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(15).' onChange="uFormUrl('.$aname.')">';
1116 break;
1117 case "offset":
1118 $wArr = explode(",",$fV);
1119 $labels = t3lib_div::trimExplode(",",$typeDat["paramstr"]);
1120 $p_field=($labels[0]?$labels[0]:"x").':<input type="text" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
1121 $p_field.=' , ';
1122 $p_field.=($labels[1]?$labels[1]:"y").':<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
1123 for ($aa=2;$aa<count($labels);$aa++) {
1124 if ($labels[$aa]) {
1125 $p_field.=' , '.$labels[$aa].':<input type="text" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
1126 } else {
1127 $p_field.='<input type="hidden" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'">';
1128 }
1129 }
1130 break;
1131 case "options":
1132 if (is_array($typeDat["params"])) {
1133 $p_field="";
1134 while(list(,$val)=each($typeDat["params"])) {
1135 $vParts = explode("=",$val,2);
1136 $label = $vParts[0];
1137 $val = isset($vParts[1]) ? $vParts[1] : $vParts[0];
1138
1139 // option tag:
1140 $sel="";
1141 if ($val==$params["value"]) {$sel=" selected";}
1142 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$GLOBALS["LANG"]->sL($label).'</option>';
1143 }
1144 $p_field='<select name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
1145 }
1146 break;
1147 case "boolean":
1148 $p_field='<input type="Hidden" name="'.$fN.'" value="0">';
1149 $sel=""; if ($fV) {$sel=" checked";}
1150 $p_field.='<input type="Checkbox" name="'.$fN.'" value="'.($typeDat["paramstr"]?$typeDat["paramstr"]:1).'"'.$sel.' onClick="uFormUrl('.$aname.')">';
1151 break;
1152 case "comment":
1153 $p_field='<input type="Hidden" name="'.$fN.'" value="#">';
1154 $sel=""; if (!$fV) {$sel=" checked";}
1155 $p_field.='<input type="Checkbox" name="'.$fN.'" value=""'.$sel.' onClick="uFormUrl('.$aname.')">';
1156 break;
1157 case "file":
1158 $p_field='<option value=""></option>';
1159 // debug($params["value"]);
1160 $theImage="";
1161 // if ($this->) {
1162 $selectThisFile = $this->extractFromResources($this->setup["resources"],$params["value"]);
1163 if ($params["value"] && !$selectThisFile) {
1164 if (in_array($params["value"],$this->dirResources)) {
1165 $selectThisFile=$params["value"];
1166 }
1167 }
1168 // debug($selectThisFile);
1169 // extensionlist
1170 $extList = $typeDat["paramstr"];
1171 $p_field='<option value="">('.$extList.')</option>';
1172 if ($extList=="IMAGE_EXT") {
1173 $extList = $GLOBALS["TYPO3_CONF_VARS"]["GFX"]["imagefile_ext"];
1174 }
1175 reset($this->rArr);
1176 $onlineResourceFlag=$this->ext_defaultOnlineResourceFlag;
1177
1178 while(list($c,$val)=each($this->rArr)) {
1179 $val=trim($val);
1180 $fI=t3lib_div::split_fileref($val);
1181 // debug($fI);
1182 if ($val && (!$extList || t3lib_div::inList($extList,$fI["fileext"]))) {
1183 if ($onlineResourceFlag<=0 && substr($fI["path"],0,10)=="fileadmin/") {
1184 if ($onlineResourceFlag<0) {
1185 $p_field.='<option value=""></option>';
1186 }
1187 $p_field.='<option value="">__'.$fI["path"].'__:</option>';
1188 $onlineResourceFlag=1;
1189 }
1190 $dims=$this->resourceDimensions[$val];
1191 $sel="";
1192
1193 // Check if $params["value"] is in the list of resources.
1194 if ($selectThisFile && $selectThisFile==$val) {
1195 $sel=" selected";
1196 if ($onlineResourceFlag<=0) {
1197 $theImage=t3lib_BEfunc::thumbCode(array("resources"=>$selectThisFile),"sys_template","resources",$GLOBALS["BACK_PATH"],"");
1198 } else {
1199 $theImage=t3lib_BEfunc::thumbCode(array("resources"=>$fI["file"]),"sys_template","resources",$GLOBALS["BACK_PATH"],"",$fI["path"]);
1200 }
1201 }
1202
1203 if ($onlineResourceFlag<=0) {
1204 $onlineResourceFlag--;
1205 // Value is set with a *
1206 $val = $this->ext_setStar($val);
1207 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.$dims.'</option>';
1208 } else {
1209 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$fI["file"].$dims.'</option>';
1210 }
1211 }
1212 }
1213 if (trim($params["value"]) && !$selectThisFile) {
1214 $val = $params["value"];
1215 $p_field.='<option value=""></option>';
1216 $p_field.='<option value="'.htmlspecialchars($val).'" selected>'.$val.'</option>';
1217 }
1218 // }
1219 $p_field='<select name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
1220 $p_field.=$theImage;
1221
1222 if (!$this->ext_noCEUploadAndCopying) {
1223 // Copy a resource
1224 $copyFile = $this->extractFromResources($this->setup["resources"],$params["value"]);
1225 if (!$copyFile) {
1226 if ($params["value"]) {
1227 $copyFile=PATH_site.$this->ext_detectAndFixExtensionPrefix($params["value"]);
1228 }
1229 } else {
1230 // $copyFile=PATH_site."uploads/tf/".$copyFile;
1231 $copyFile="";
1232 }
1233 #debug($copyFile);
1234 if ($copyFile && @is_file($copyFile)) {
1235 $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"])).'\'));}">';
1236 }
1237 // Upload?
1238 $p_field.='<BR>';
1239 $p_field.='<input type="file" name="upload_'.$fN.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth().' onChange="uFormUrl('.$aname.')" size="50" />';
1240 }
1241 break;
1242 case 'small':
1243 default:
1244 $fwidth= $typeDat["type"]=="small" ? 10 : 46;
1245 $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth($fwidth).' onChange="uFormUrl('.$aname.')">';
1246 break;
1247 }
1248 }
1249 if (!$this->ext_dontCheckIssetValues) $p_field='<input type="Checkbox" name="check['.$params["name"].']" value="1"'.$checked.' onClick="uFormUrl('.$aname.')">'.$p_field;
1250 if ($typeDat["type"]=="color" && substr($params["value"],0,2)!='{$') {
1251 $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>';
1252 } else {
1253 $p_field='<span class="nobr">'.$p_field.'</span><br />';
1254 }
1255
1256 $p_name = '<span class="typo3-dimmed">['.$params["name"].']</span><BR>';
1257 $p_dlabel='<span class="typo3-dimmed"><b>Default:</b> '.htmlspecialchars($params["default_value"]).'</span><BR>';
1258 $p_label = '<b>'.htmlspecialchars($head).'</b>';
1259 $p_descrip = $body ? htmlspecialchars($body)."<BR>" : "";
1260
1261 $output.='<tr>';
1262 $output.='<td valign=top nowrap><a name="'.$raname.'"></a>'.$help["constants"][$params["name"]].$p_label.'</td>';
1263 $output.='<td valign=top align="right">'.$p_name.'</td>';
1264 $output.='</tr>';
1265 $output.='<tr>';
1266 $output.='<td colspan=2>'.$p_descrip.$p_field.$p_dlabel.'<br></td>';
1267 $output.='</tr>';
1268 // }
1269 } else {
1270 debug("Error. Constant did not exits. Should not happen.");
1271 }
1272 }
1273 $output='<table border=0 cellpadding=0 cellspacing=0>'.$output.'</table>';
1274 }
1275 return $output;
1276 }
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289 /***************************
1290 *
1291 * Processing input values
1292 *
1293 ***************************/
1294
1295 /**
1296 * @param [type] $constants: ...
1297 * @return [type] ...
1298 */
1299 function ext_regObjectPositions($constants) {
1300 // 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
1301 $this->raw = explode(chr(10),$constants);
1302 $this->rawP=0;
1303
1304 $this->objReg=array(); // resetting the objReg if the divider is found!!
1305 $this->ext_regObjects("");
1306 }
1307
1308 /**
1309 * [Describe function...]
1310 *
1311 * @param [type] $pre: ...
1312 * @return [type] ...
1313 */
1314 function ext_regObjects($pre) {
1315 // works with regObjectPositions. "expands" the names of the TypoScript objects
1316 while (isset($this->raw[$this->rawP])) {
1317 $line = ltrim($this->raw[$this->rawP]);
1318 if (strstr($line,$this->edit_divider)) {
1319 $this->objReg=array(); // resetting the objReg if the divider is found!!
1320 }
1321 $this->rawP++;
1322 if ($line) {
1323 if (substr($line,0,1)=="[") {
1324 // return $line;
1325 } elseif (strcspn($line,"}#/")!=0) {
1326 $varL = strcspn($line," {=<");
1327 $var=substr($line,0,$varL);
1328 $line = ltrim(substr($line,$varL));
1329 switch(substr($line,0,1)) {
1330 case "=":
1331 $this->objReg[$pre.$var]=$this->rawP-1;
1332 break;
1333 case "{":
1334 $this->ext_inBrace++;
1335 $this->ext_regObjects($pre.$var.".");
1336 break;
1337 }
1338 $this->lastComment="";
1339 } elseif (substr($line,0,1)=="}") {
1340 $this->lastComment="";
1341 $this->ext_inBrace--;
1342 if ($this->ext_inBrace<0) {
1343 $this->ext_inBrace=0;
1344 } else {
1345 break;
1346 }
1347 }
1348 }
1349 }
1350 }
1351
1352 /**
1353 * [Describe function...]
1354 *
1355 * @param [type] $key: ...
1356 * @param [type] $var: ...
1357 * @return [type] ...
1358 */
1359 function ext_putValueInConf($key, $var) {
1360 // Puts the value $var to the TypoScript value $key in the current lines of the templates.
1361 // If the $key is not found in the template constants field, a new line is inserted in the bottom.
1362 $theValue = " ".trim($var);
1363 if (isset($this->objReg[$key])) {
1364 $lineNum = $this->objReg[$key];
1365 $parts = explode("=",$this->raw[$lineNum],2);
1366 if (count($parts)==2) {
1367 $parts[1]= $theValue;
1368 }
1369 $this->raw[$lineNum]=implode($parts,"=");
1370 } else {
1371 $this->raw[]=$key." =".$theValue;
1372 }
1373 $this->changed=1;
1374 }
1375
1376 /**
1377 * [Describe function...]
1378 *
1379 * @param [type] $key: ...
1380 * @return [type] ...
1381 */
1382 function ext_removeValueInConf($key) {
1383 // Removes the value in the configuration
1384 if (isset($this->objReg[$key])) {
1385 $lineNum = $this->objReg[$key];
1386 unset($this->raw[$lineNum]);
1387 }
1388 $this->changed=1;
1389 }
1390
1391 /**
1392 * [Describe function...]
1393 *
1394 * @param [type] $arr: ...
1395 * @param [type] $settings: ...
1396 * @return [type] ...
1397 */
1398 function ext_depthKeys($arr,$settings) {
1399 reset($arr);
1400 $tsbrArray=array();
1401 while(list($theK,$theV)=each($arr)) {
1402 $theKeyParts = explode(".",$theK);
1403 $depth="";
1404 $c=count($theKeyParts);
1405 $a=0;
1406 while(list(,$p)=each($theKeyParts)) {
1407 $a++;
1408 $depth.=($depth?".":"").$p;
1409 $tsbrArray[$depth]= ($c==$a) ? $theV : 1;
1410 }
1411 }
1412 // Modify settings
1413 reset($tsbrArray);
1414 while(list($theK,$theV)=each($tsbrArray)) {
1415 if ($theV) {
1416 $settings[$theK] = 1;
1417 } else {
1418 unset($settings[$theK]);
1419 }
1420 }
1421 return $settings;
1422 }
1423
1424 /**
1425 * [Describe function...]
1426 *
1427 * @param [type] $http_post_vars: ...
1428 * @param [type] $http_post_files: ...
1429 * @param [type] $theConstants: ...
1430 * @param [type] $tplRow: ...
1431 * @return [type] ...
1432 */
1433 function ext_procesInput($http_post_vars,$http_post_files,$theConstants,$tplRow) {
1434 $data=$http_post_vars["data"];
1435 $check=$http_post_vars["check"];
1436 $copyResource=$http_post_vars["_copyResource"];
1437 $Wdata=$http_post_vars["Wdata"];
1438 $W2data=$http_post_vars["W2data"];
1439 $W3data=$http_post_vars["W3data"];
1440 $W4data=$http_post_vars["W4data"];
1441 $W5data=$http_post_vars["W5data"];
1442
1443 if (is_array($data)) {
1444 reset($data);
1445 while(list($key,$var)=each($data)) {
1446 if (isset($theConstants[$key])) {
1447 if ($this->ext_dontCheckIssetValues || isset($check[$key])) { // If checkbox is set, update the value
1448 list($var) = explode(chr(10),stripslashes($var)); // exploding with linebreak, just to make sure that no multiline input is given!
1449 $typeDat=$this->ext_getTypeData($theConstants[$key]["type"]);
1450 switch($typeDat["type"]) {
1451 case "int":
1452 if ($typeDat["paramstr"]) {
1453 $var=t3lib_div::intInRange($var,$typeDat["params"][0],$typeDat["params"][1]);
1454 } else {
1455 $var=intval($var);
1456 }
1457 break;
1458 case "int+":
1459 $var=t3lib_div::intInRange($var,0,10000);
1460 break;
1461 case "color":
1462 $col=array();
1463 if($var && !t3lib_div::inList($this->HTMLcolorList,strtolower($var))) {
1464 $var = ereg_replace("[^A-Fa-f0-9]*","",$var);
1465 $col[]=HexDec(substr($var,0,2));
1466 $col[]=HexDec(substr($var,2,2));
1467 $col[]=HexDec(substr($var,4,2));
1468 $var="#".strtoupper(substr("0".DecHex($col[0]),-2).substr("0".DecHex($col[1]),-2).substr("0".DecHex($col[2]),-2));
1469 }
1470 break;
1471 case "comment":
1472 if ($val) {
1473 $val="#";
1474 } else {
1475 $val="";
1476 }
1477 break;
1478 case "wrap":
1479 if (isset($Wdata[$key])) {
1480 $var.="|".stripslashes($Wdata[$key]);
1481 }
1482 break;
1483 case "offset":
1484 if (isset($Wdata[$key])) {
1485 $var=intval($var).",".intval($Wdata[$key]);
1486 if (isset($W2data[$key])) {
1487 $var.=",".intval($W2data[$key]);
1488 if (isset($W3data[$key])) {
1489 $var.=",".intval($W3data[$key]);
1490 if (isset($W4data[$key])) {
1491 $var.=",".intval($W4data[$key]);
1492 if (isset($W5data[$key])) {
1493 $var.=",".intval($W5data[$key]);
1494 }
1495 }
1496 }
1497 }
1498 }
1499 break;
1500 case "boolean":
1501 if ($var) {
1502 $var = $typeDat["paramstr"] ? $typeDat["paramstr"] : 1;
1503 }
1504 break;
1505 case "file":
1506 if (!$this->ext_noCEUploadAndCopying) {
1507 if ($http_post_files["upload_data"]["name"][$key] && $http_post_files["upload_data"]["tmp_name"][$key]!="none") {
1508 $var = $this->upload_copy_file(
1509 $typeDat,
1510 $tplRow,
1511 trim($http_post_files["upload_data"]["name"][$key]),
1512 $http_post_files["upload_data"]["tmp_name"][$key]
1513 );
1514 }
1515 if ($copyResource[$key]) {
1516 $var = $this->upload_copy_file(
1517 $typeDat,
1518 $tplRow,
1519 basename($copyResource[$key]),
1520 $copyResource[$key]
1521 );
1522 }
1523 }
1524 break;
1525 }
1526 if ($this->ext_printAll || strcmp($theConstants[$key]["value"],$var)) {
1527 $this->ext_putValueInConf($key, $var); // Put value in, if changed.
1528 }
1529 unset($check[$key]); // Remove the entry because it has been "used"
1530 } else {
1531 $this->ext_removeValueInConf($key);
1532 }
1533 }
1534 }
1535 }
1536 // 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...
1537 if (!$this->ext_dontCheckIssetValues && is_array($check)) {
1538 reset($check);
1539 while(list($key,$var)=each($check)) {
1540 if (isset($theConstants[$key])) {
1541 $dValue = $theConstants[$key]["default_value"];
1542 // debug($dValue);
1543 $this->ext_putValueInConf($key, $dValue);
1544 // debug($key,1);
1545 }
1546 }
1547 }
1548 // debug($this->objReg);
1549 }
1550
1551 /**
1552 * [Describe function...]
1553 *
1554 * @param [type] $typeDat: ...
1555 * @param [type] $tplRow: ...
1556 * @param [type] $theRealFileName: ...
1557 * @param [type] $tmp_name: ...
1558 * @return [type] ...
1559 */
1560 function upload_copy_file($typeDat,&$tplRow,$theRealFileName,$tmp_name) {
1561 // extensions
1562 $extList = $typeDat["paramstr"];
1563 if ($extList=="IMAGE_EXT") {
1564 $extList = $GLOBALS["TYPO3_CONF_VARS"]["GFX"]["imagefile_ext"];
1565 }
1566 $fI=t3lib_div::split_fileref($theRealFileName);
1567 if ($theRealFileName && (!$extList || t3lib_div::inList($extList,$fI["fileext"]))) {
1568 // Saving resource
1569 $alternativeFileName=array();
1570 $alternativeFileName[$tmp_name] = $theRealFileName;
1571 // Making list of resources
1572 $resList = $tplRow["resources"];
1573 $resList = $tmp_name.",".$resList;
1574 $resList=implode(t3lib_div::trimExplode(",",$resList,1),",");
1575 // Making data-array
1576 $recData=array();
1577 $recData["sys_template"][$tplRow["uid"]]["resources"] = $resList;
1578 // Saving
1579 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
1580 $tce->stripslashes_values=0;
1581 $tce->alternativeFileName = $alternativeFileName;
1582 $tce->start($recData,Array());
1583 $tce->process_datamap();
1584
1585 $tmpRow = t3lib_BEfunc::getRecord("sys_template",$tplRow["uid"],"resources");
1586 $tplRow["resources"] = $tmpRow["resources"];
1587
1588 // Setting the value
1589 $var = $this->ext_setStar($theRealFileName);
1590 }
1591 return $var;
1592 }
1593
1594 /**
1595 * [Describe function...]
1596 *
1597 * @param [type] $id: ...
1598 * @param [type] $perms_clause: ...
1599 * @return [type] ...
1600 */
1601 function ext_prevPageWithTemplate($id,$perms_clause) {
1602 $rootLine = t3lib_BEfunc::BEgetRootLine($id,$perms_clause?" AND ".$perms_clause:"");
1603 reset($rootLine);
1604 while(list(,$p)=each($rootLine)) {
1605 if ($this->ext_getFirstTemplate($p["uid"])) {
1606 return $p;
1607 }
1608 }
1609 }
1610
1611 /**
1612 * [Describe function...]
1613 *
1614 * @param [type] $val: ...
1615 * @return [type] ...
1616 */
1617 function ext_setStar($val) {
1618 $fParts = explode(".",strrev($val),2);
1619 $val=ereg_replace("_[0-9][0-9]$","",strrev($fParts[1]))."*.".strrev($fParts[0]);
1620 return $val;
1621 }
1622
1623 /**
1624 * [Describe function...]
1625 *
1626 * @param [type] $value: ...
1627 * @return [type] ...
1628 */
1629 function ext_detectAndFixExtensionPrefix($value) {
1630 if (substr($value,0,4)=="EXT:") {
1631 $parts = explode("/",substr($value,4),2);
1632 #debug($parts);
1633 $extPath = t3lib_extMgm::siteRelPath($parts[0]);
1634 $value = $extPath.$parts[1];
1635 return $value;
1636 } else {
1637 return $value;
1638 }
1639 }
1640 }
1641
1642
1643 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php']) {
1644 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php']);
1645 }
1646 ?>