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