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