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