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