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