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