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