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