[TASK] Remove SVN auto properties $Id$
[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 reset($this->flatSetup);
841 foreach ($this->flatSetup as $const => $value) {
842 if (substr($const, -2) != '..' && isset($this->flatSetup[$const . '..'])) {
843 $comment = trim($this->flatSetup[$const . '..']);
844 $c_arr = explode(LF, $comment);
845 foreach ($c_arr as $k => $v) {
846 $line = trim(preg_replace('/^[#\/]*/', '', $v));
847 if ($line) {
848 $parts = explode(';', $line);
849 foreach ($parts as $par) {
850 if (strstr($par, '=')) {
851 $keyValPair = explode('=', $par, 2);
852 switch (trim(strtolower($keyValPair[0]))) {
853 case 'type':
854 // Type:
855 $editableComments[$const]['type'] = trim($keyValPair[1]);
856 break;
857 case 'cat':
858 // list of categories.
859 $catSplit = explode('/', strtolower($keyValPair[1]));
860 $editableComments[$const]['cat'] = trim($catSplit[0]);
861 $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.
862 if ($catSplit[1] && isset($this->subCategories[$catSplit[1]])) {
863 $editableComments[$const]['subcat_name'] = $catSplit[1];
864 $editableComments[$const]['subcat'] = $this->subCategories[$catSplit[1]][1] . '/' .
865 $catSplit[1] . '/' . trim($catSplit[2]) . 'z';
866 } else {
867 $editableComments[$const]['subcat'] = 'x' . '/' . trim($catSplit[2]) . 'z';
868 }
869 break;
870 case 'label':
871 // label
872 $editableComments[$const]['label'] = trim($keyValPair[1]);
873 break;
874 case 'customsubcategory':
875 // custom subCategory label
876 $customSubcategory = explode('=', $keyValPair[1], 2);
877 if (trim($customSubcategory[0])) {
878 $subCategoryKey = strtolower($customSubcategory[0]);
879 $this->subCategories[$subCategoryKey][0] = $GLOBALS['LANG']->sL($customSubcategory[1]);
880 }
881 break;
882 }
883 }
884 }
885 }
886 }
887 }
888 if (isset($editableComments[$const])) {
889 $editableComments[$const]['name'] = $const;
890 $editableComments[$const]['value'] = trim($value);
891 if (isset($default[$const])) {
892 $editableComments[$const]['default_value'] = trim($default[$const]);
893 }
894 }
895 }
896 return $editableComments;
897 }
898
899 /**
900 * [Describe function...]
901 *
902 * @param [type] $editConstArray: ...
903 * @return [type] ...
904 */
905 function ext_categorizeEditableConstants($editConstArray) {
906 // Runs through the available constants and fills the $this->categories array with pointers and priority-info
907 foreach ($editConstArray as $constName => $constData) {
908 if (!$constData['type']) {
909 $constData['type'] = 'string';
910 }
911 $cats = explode(',', $constData['cat']);
912 foreach ($cats as $theCat) { // if = only one category, while allows for many. We have agreed on only one category is the most basic way...
913 $theCat = trim($theCat);
914 if ($theCat) {
915 $this->categories[$theCat][$constName] = $constData['subcat'];
916 }
917 }
918 }
919 }
920
921 /**
922 * [Describe function...]
923 *
924 * @return [type] ...
925 */
926 function ext_getCategoryLabelArray() {
927 // Returns array used for labels in the menu.
928 $retArr = array();
929 foreach ($this->categories as $k => $v) {
930 if (count($v)) {
931 $retArr[$k] = strtoupper($k) . ' (' . count($v) . ')';
932 }
933 }
934 return $retArr;
935 }
936
937 /**
938 * [Describe function...]
939 *
940 * @param [type] $type: ...
941 * @return [type] ...
942 */
943 function ext_getTypeData($type) {
944 $retArr = array();
945 $type = trim($type);
946 if (!$type) {
947 $retArr['type'] = 'string';
948 } else {
949 $m = strcspn($type, ' [');
950 $retArr['type'] = strtolower(substr($type, 0, $m));
951 if (t3lib_div::inList('int,options,file,boolean,offset,user', $retArr['type'])) {
952 $p = trim(substr($type, $m));
953 $reg = array();
954 preg_match('/\[(.*)\]/', $p, $reg);
955 $p = trim($reg[1]);
956 if ($p) {
957 $retArr['paramstr'] = $p;
958 switch ($retArr['type']) {
959 case 'int':
960 if (substr($retArr['paramstr'], 0, 1) == '-') {
961 $retArr['params'] = t3lib_div::intExplode('-', substr($retArr['paramstr'], 1));
962 $retArr['params'][0] = intval('-' . $retArr['params'][0]);
963 } else {
964 $retArr['params'] = t3lib_div::intExplode('-', $retArr['paramstr']);
965 }
966 $retArr['paramstr'] = $retArr['params'][0] . ' - ' . $retArr['params'][1];
967 break;
968 case 'options':
969 $retArr['params'] = explode(',', $retArr['paramstr']);
970 break;
971 }
972 }
973 }
974 }
975 return $retArr;
976 }
977
978 /**
979 * [Describe function...]
980 *
981 * @param [type] $category: ...
982 * @return [type] ...
983 */
984 function ext_getTSCE_config($category) {
985 $catConf = $this->setup['constants']['TSConstantEditor.'][$category . '.'];
986 $out = array();
987 if (is_array($catConf)) {
988 foreach ($catConf as $key => $val) {
989 switch ($key) {
990 case 'image':
991 $out['imagetag'] = $this->ext_getTSCE_config_image($catConf['image']);
992 break;
993 case 'description':
994 case 'bulletlist':
995 case 'header':
996 $out[$key] = $val;
997 break;
998 default:
999 if (t3lib_div::testInt($key)) {
1000 $constRefs = explode(',', $val);
1001 foreach ($constRefs as $const) {
1002 $const = trim($const);
1003 if ($const && $const <= 20) {
1004 $out['constants'][$const] .= $this->ext_getKeyImage($key);
1005 }
1006 }
1007 }
1008 break;
1009 }
1010 }
1011 }
1012 $this->helpConfig = $out;
1013 }
1014
1015 /**
1016 * [Describe function...]
1017 *
1018 * @param [type] $key: ...
1019 * @return [type] ...
1020 */
1021 function ext_getKeyImage($key) {
1022 return '<img src="' . $this->ext_localWebGfxPrefix . 'gfx/' . $key . '.gif" align="top" hspace=2>';
1023 }
1024
1025 /**
1026 * [Describe function...]
1027 *
1028 * @param [type] $imgConf: ...
1029 * @return [type] ...
1030 */
1031 function ext_getTSCE_config_image($imgConf) {
1032 if (substr($imgConf, 0, 4) == 'gfx/') {
1033 $iFile = $this->ext_localGfxPrefix . $imgConf;
1034 $tFile = $this->ext_localWebGfxPrefix . $imgConf;
1035 } elseif (substr($imgConf, 0, 4) == 'EXT:') {
1036 $iFile = t3lib_div::getFileAbsFileName($imgConf);
1037 if ($iFile) {
1038 $f = substr($iFile, strlen(PATH_site));
1039 $tFile = $GLOBALS['BACK_PATH'] . '../' . $f;
1040 }
1041 } else {
1042 $f = 'uploads/tf/' . $this->extractFromResources($this->setup['resources'], $imgConf);
1043 $iFile = PATH_site . $f;
1044 $tFile = $GLOBALS['BACK_PATH'] . '../' . $f;
1045 }
1046 $imageInfo = @getImagesize($iFile);
1047 return '<img src="' . $tFile . '" ' . $imageInfo[3] . '>';
1048 }
1049
1050 /**
1051 * [Describe function...]
1052 *
1053 * @return [type] ...
1054 */
1055 function ext_resourceDims() {
1056 if ($this->setup['resources']) {
1057 $rArr = explode(',', $this->setup['resources']);
1058 foreach ($rArr as $c => $val) {
1059 $val = trim($val);
1060 $theFile = PATH_site . 'uploads/tf/' . $val;
1061 if ($val && @is_file($theFile)) {
1062 $imgInfo = @getimagesize($theFile);
1063 }
1064 if (is_array($imgInfo)) {
1065 $this->resourceDimensions[$val] = ' (' . $imgInfo[0] . 'x' . $imgInfo[1] . ')';
1066 }
1067 }
1068 }
1069 foreach ($this->dirResources as $c => $val) {
1070 $val = trim($val);
1071 $imgInfo = @getimagesize(PATH_site . $val);
1072 if (is_array($imgInfo)) {
1073 $this->resourceDimensions[$val] = ' (' . $imgInfo[0] . 'x' . $imgInfo[1] . ')';
1074 }
1075 }
1076 }
1077
1078 /**
1079 * [Describe function...]
1080 *
1081 * @param [type] $path: ...
1082 * @return [type] ...
1083 */
1084 function ext_readDirResources($path) {
1085 $path = trim($path);
1086 if ($path && strstr($path, $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'])) {
1087 $path = rtrim($path, '/');
1088 $this->readDirectory(PATH_site . $path);
1089 }
1090 }
1091
1092 /**
1093 * [Describe function...]
1094 *
1095 * @param [type] $path: ...
1096 * @param [type] $type: ...
1097 * @return [type] ...
1098 */
1099 function readDirectory($path, $type = 'file') {
1100 if (@is_dir($path)) {
1101 $d = @dir($path);
1102 $tempArray = Array();
1103 if (is_object($d)) {
1104 while ($entry = $d->read()) {
1105 if ($entry != '.' && $entry != '..') {
1106 $wholePath = $path . '/' . $entry; // Because of odd PHP-error where <BR>-tag is sometimes placed after a filename!!
1107 if (file_exists($wholePath) && (!$type || filetype($wholePath) == $type)) {
1108 $fI = t3lib_div::split_fileref($wholePath);
1109 $this->dirResources[] = substr($wholePath, strlen(PATH_site));
1110 }
1111 }
1112 }
1113 $d->close();
1114 }
1115 }
1116 }
1117
1118 /**
1119 * [Describe function...]
1120 *
1121 * @param [type] $params: ...
1122 * @return [type] ...
1123 */
1124 function ext_fNandV($params) {
1125 $fN = 'data[' . $params['name'] . ']';
1126 $fV = $params['value'];
1127 if (preg_match('/^{[\$][a-zA-Z0-9\.]*}$/', trim($fV), $reg)) { // Values entered from the constantsedit cannot be constants! 230502; removed \{ and set {
1128 $fV = '';
1129 }
1130 $fV = htmlspecialchars($fV);
1131
1132 return array($fN, $fV, $params);
1133 }
1134
1135 /**
1136 * This functions returns the HTML-code that creates the editor-layout of the module.
1137 *
1138 * @param [type] $theConstants: ...
1139 * @param [type] $category: ...
1140 * @return [type] ...
1141 */
1142 function ext_printFields($theConstants, $category) {
1143 reset($theConstants);
1144 $output = '<script type="text/javascript" src="' . $GLOBALS['BACK_PATH'] . 'js/constantEditor.js"></script>
1145 ';
1146 $subcat = '';
1147 if (is_array($this->categories[$category])) {
1148
1149 $help = $this->helpConfig;
1150 $this->rArr = explode(',', $this->setup['resources'] . ',' . implode($this->dirResources, ','));
1151
1152 if (!$this->doNotSortCategoriesBeforeMakingForm) {
1153 asort($this->categories[$category]);
1154 }
1155 foreach ($this->categories[$category] as $name => $type) {
1156 $params = $theConstants[$name];
1157 if (is_array($params)) {
1158 if ($subcat != $params['subcat_name']) {
1159 $subcat = $params['subcat_name'];
1160 $subcat_name = $params['subcat_name'] ? $this->subCategories[$params['subcat_name']][0] : 'Others';
1161
1162 $output .= '<h2 class="typo3-tstemplate-ceditor-subcat">' . $subcat_name . '</h2>';
1163 }
1164
1165 $label = $GLOBALS['LANG']->sL($params['label']);
1166 $label_parts = explode(':', $label, 2);
1167 if (count($label_parts) == 2) {
1168 $head = trim($label_parts[0]);
1169 $body = trim($label_parts[1]);
1170 } else {
1171 $head = trim($label_parts[0]);
1172 $body = '';
1173 }
1174 if (strlen($head) > 35) {
1175 if (!$body) {
1176 $body = $head;
1177 }
1178 $head = t3lib_div::fixed_lgd_cs($head, 35);
1179 }
1180 $typeDat = $this->ext_getTypeData($params['type']);
1181 $checked = '';
1182 $p_field = '';
1183 $raname = substr(md5($params['name']), 0, 10);
1184 $aname = '\'' . $raname . '\'';
1185
1186 list($fN, $fV, $params) = $this->ext_fNandV($params);
1187
1188 switch ($typeDat['type']) {
1189 case 'int':
1190 case 'int+':
1191 $p_field = '<input id="' . $fN . '" type="text" name="' . $fN . '" value="' . $fV . '"' .
1192 $GLOBALS['TBE_TEMPLATE']->formWidth(5) . ' onChange="uFormUrl(' . $aname . ')" />';
1193 if ($typeDat['paramstr']) {
1194 $p_field .= ' Range: ' . $typeDat['paramstr'];
1195 } elseif ($typeDat['type'] == 'int+') {
1196 $p_field .= ' Range: 0 - ';
1197 } else {
1198 $p_field .= ' (Integer)';
1199 }
1200 break;
1201 case 'color':
1202 $colorNames = explode(',', ',' . $this->HTMLcolorList);
1203 $p_field = '';
1204 foreach ($colorNames as $val) {
1205 $sel = '';
1206 if ($val == strtolower($params['value'])) {
1207 $sel = ' selected';
1208 }
1209 $p_field .= '<option value="' . htmlspecialchars($val) . '"' . $sel . '>' . $val . '</option>';
1210 }
1211 $p_field = '<select id="select-' . $fN . '" rel="' . $fN . '" name="C' . $fN .
1212 '" class="typo3-tstemplate-ceditor-color-select" onChange="uFormUrl(' .
1213 $aname . ');">' . $p_field . '</select>';
1214
1215 $p_field .= '<input type="text" id="input-' . $fN . '" rel="' . $fN . '" name="' . $fN .
1216 '" class="typo3-tstemplate-ceditor-color-input" value="' . $fV . '"' .
1217 $GLOBALS['TBE_TEMPLATE']->formWidth(7) . ' onChange="uFormUrl(' . $aname . ')" />';
1218 break;
1219 case 'wrap':
1220 $wArr = explode('|', $fV);
1221 $p_field = '<input type="text" id="' . $fN . '" name="' . $fN . '" value="' . $wArr[0] . '"' .
1222 $GLOBALS['TBE_TEMPLATE']->formWidth(29) . ' onChange="uFormUrl(' . $aname . ')" />';
1223 $p_field .= ' | ';
1224 $p_field .= '<input type="text" name="W' . $fN . '" value="' . $wArr[1] . '"' .
1225 $GLOBALS['TBE_TEMPLATE']->formWidth(15) . ' onChange="uFormUrl(' . $aname . ')" />';
1226 break;
1227 case 'offset':
1228 $wArr = explode(',', $fV);
1229 $labels = t3lib_div::trimExplode(',', $typeDat['paramstr']);
1230 $p_field = ($labels[0] ? $labels[0] : 'x') . ':<input type="text" name="' . $fN . '" value="' . $wArr[0] . '"' .
1231 $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' onChange="uFormUrl(' . $aname . ')" />';
1232 $p_field .= ' , ';
1233 $p_field .= ($labels[1] ? $labels[1] : 'y') . ':<input type="text" name="W' . $fN . '" value="' . $wArr[1] . '"' .
1234 $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' onChange="uFormUrl(' . $aname . ')" />';
1235 for ($aa = 2; $aa < count($labels); $aa++) {
1236 if ($labels[$aa]) {
1237 $p_field .= ' , ' . $labels[$aa] . ':<input type="text" name="W' . $aa . $fN . '" value="' . $wArr[$aa] . '"' .
1238 $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' onChange="uFormUrl(' . $aname . ')" />';
1239 } else {
1240 $p_field .= '<input type="hidden" name="W' . $aa . $fN . '" value="' . $wArr[$aa] . '" />';
1241 }
1242 }
1243 break;
1244 case 'options':
1245 if (is_array($typeDat['params'])) {
1246 $p_field = '';
1247 foreach ($typeDat['params'] as $val) {
1248 $vParts = explode('=', $val, 2);
1249 $label = $vParts[0];
1250 $val = isset($vParts[1]) ? $vParts[1] : $vParts[0];
1251
1252 // option tag:
1253 $sel = '';
1254 if ($val == $params['value']) {
1255 $sel = ' selected';
1256 }
1257 $p_field .= '<option value="' . htmlspecialchars($val) . '"' . $sel . '>' . $GLOBALS['LANG']->sL($label) . '</option>';
1258 }
1259 $p_field = '<select id="' . $fN . '" name="' . $fN . '" onChange="uFormUrl(' . $aname . ')">' . $p_field . '</select>';
1260 }
1261 break;
1262 case 'boolean':
1263 $p_field = '<input type="hidden" name="' . $fN . '" value="0" />';
1264 $sel = '';
1265 if ($fV) {
1266 $sel = ' checked';
1267 }
1268 $p_field .= '<input id="' . $fN . '" type="checkbox" name="' . $fN . '" value="' . ($typeDat['paramstr'] ? $typeDat['paramstr'] : 1) .
1269 '"' . $sel . ' onClick="uFormUrl(' . $aname . ')" />';
1270 break;
1271 case 'comment':
1272 $p_field = '<input type="hidden" name="' . $fN . '" value="#" />';
1273 $sel = '';
1274 if (!$fV) {
1275 $sel = ' checked';
1276 }
1277 $p_field .= '<input id="' . $fN . '" type="checkbox" name="' . $fN . '" value=""' . $sel . ' onClick="uFormUrl(' . $aname . ')" />';
1278 break;
1279 case 'file':
1280 $p_field = '<option value=""></option>';
1281 $theImage = '';
1282 $selectThisFile = $this->extractFromResources($this->setup['resources'], $params['value']);
1283 if ($params['value'] && !$selectThisFile) {
1284 if (in_array($params['value'], $this->dirResources)) {
1285 $selectThisFile = $params['value'];
1286 }
1287 }
1288 // extensionlist
1289 $extList = $typeDat['paramstr'];
1290 $p_field = '<option value="">(' . $extList . ')</option>';
1291 if ($extList == 'IMAGE_EXT') {
1292 $extList = $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'];
1293 }
1294 reset($this->rArr);
1295 $onlineResourceFlag = $this->ext_defaultOnlineResourceFlag;
1296
1297 foreach ($this->rArr as $c => $val) {
1298 $val = trim($val);
1299 $fI = t3lib_div::split_fileref($val);
1300 if ($val && (!$extList || t3lib_div::inList($extList, $fI['fileext']))) {
1301 if ($onlineResourceFlag <= 0 && strstr($fI['path'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'])) {
1302 if ($onlineResourceFlag < 0) {
1303 $p_field .= '<option value=""></option>';
1304 }
1305 $p_field .= '<option value="">__' . $fI['path'] . '__:</option>';
1306 $onlineResourceFlag = 1;
1307 }
1308 $dims = $this->resourceDimensions[$val];
1309 $sel = '';
1310
1311 // Check if $params['value'] is in the list of resources.
1312 if ($selectThisFile && $selectThisFile == $val) {
1313 $sel = ' selected';
1314 if ($onlineResourceFlag <= 0) {
1315 $theImage = t3lib_BEfunc::thumbCode(
1316 array(
1317 'resources' => $selectThisFile
1318 ),
1319 'sys_template',
1320 'resources',
1321 $GLOBALS['BACK_PATH'],
1322 ''
1323 );
1324 } else {
1325 $theImage = t3lib_BEfunc::thumbCode(
1326 array(
1327 'resources' => $fI['file']
1328 ),
1329 'sys_template',
1330 'resources',
1331 $GLOBALS['BACK_PATH'],
1332 '',
1333 $fI['path']
1334 );
1335 }
1336 }
1337
1338 if ($onlineResourceFlag <= 0) {
1339 $onlineResourceFlag--;
1340 // Value is set with a *
1341 $val = $this->ext_setStar($val);
1342 $p_field .= '<option value="' . htmlspecialchars($val) . '"' . $sel . '>' . $val . $dims . '</option>';
1343 } else {
1344 $p_field .= '<option value="' . htmlspecialchars($val) . '"' . $sel . '>' . $fI['file'] . $dims . '</option>';
1345 }
1346 }
1347 }
1348
1349 if (trim($params['value']) && !$selectThisFile) {
1350 $val = $params['value'];
1351 $p_field .= '<option value=""></option>';
1352 $p_field .= '<option value="' . htmlspecialchars($val) . '" selected>' . $val . '</option>';
1353 }
1354
1355 $p_field = '<select id="' . $fN . '" name="' . $fN . '" onChange="uFormUrl(' . $aname . ')">' . $p_field . '</select>';
1356 $p_field .= $theImage;
1357
1358 if (!$this->ext_noCEUploadAndCopying) {
1359 // Copy a resource
1360 $copyFile = $this->extractFromResources($this->setup['resources'], $params['value']);
1361 if (!$copyFile) {
1362 if ($params['value']) {
1363 $copyFile = PATH_site . $this->ext_detectAndFixExtensionPrefix($params['value']);
1364 }
1365 } else {
1366 $copyFile = '';
1367 }
1368
1369 if ($copyFile && @is_file($copyFile)) {
1370 $p_field .= '<img src="clear.gif" width="20" ' . 'height="1" alt="" />' .
1371 t3lib_iconWorks::getSpriteIcon('actions-edit-copy') . '<input type="checkbox" ' .
1372 'name="_copyResource[' . $params['name'] . ']" value="' . htmlspecialchars($copyFile) .
1373 '" onclick="uFormUrl(' . $aname . ');if (this.checked && !confirm(\'' .
1374 t3lib_div::slashJS(htmlspecialchars(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_tsparser.xml:tsparser_ext.make_copy'), $params['value']))) .
1375 '\')) this.checked=false;" />';
1376 }
1377
1378 // Upload?
1379 $p_field .= '<br />';
1380 $p_field .= '<input id="' . $fN . '" type="file" name="upload_' . $fN . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth() .
1381 ' onChange="uFormUrl(' . $aname . ')" size="50" />';
1382 }
1383 break;
1384 case 'user':
1385 $userFunction = $typeDat['paramstr'];
1386 $userFunctionParams = array('fieldName' => $fN, 'fieldValue' => $fV);
1387 $p_field = t3lib_div::callUserFunction($userFunction, $userFunctionParams, $this, '');
1388 break;
1389 case 'small':
1390 default:
1391 $fwidth = $typeDat['type'] == 'small' ? 10 : 46;
1392 $p_field = '<input id="' . $fN . '" type="text" name="' . $fN . '" value="' . $fV . '"' .
1393 $GLOBALS['TBE_TEMPLATE']->formWidth($fwidth) . ' onChange="uFormUrl(' . $aname . ')" />';
1394 break;
1395 }
1396
1397 // Define default names and IDs
1398 $userTyposcriptID = 'userTS-' . $params['name'];
1399 $defaultTyposcriptID = 'defaultTS-' . $params['name'];
1400 $checkboxName = 'check[' . $params['name'] . ']';
1401 $checkboxID = $checkboxName;
1402
1403 // Handle type=color specially
1404 if ($typeDat['type'] == 'color' && substr($params['value'], 0, 2) != '{$') {
1405 $color = '<div id="colorbox-' . $fN . '" class="typo3-tstemplate-ceditor-colorblock" style="background-color:' .
1406 $params['value'] . ';">&nbsp;</div>';
1407 } else {
1408 $color = '';
1409 }
1410
1411 if (!$this->ext_dontCheckIssetValues) {
1412
1413 /* Set the default styling options */
1414 if (isset($this->objReg[$params['name']])) {
1415 $checkboxValue = 'checked';
1416 $userTyposcriptStyle = '';
1417 $defaultTyposcriptStyle = 'style="display:none;"';
1418 } else {
1419 $checkboxValue = '';
1420 $userTyposcriptStyle = 'style="display:none;"';
1421 $defaultTyposcriptStyle = '';
1422 }
1423
1424
1425 $deleteIconHTML = t3lib_iconWorks::getSpriteIcon(
1426 'actions-edit-undo',
1427 array(
1428 'class' => "typo3-tstemplate-ceditor-control undoIcon",
1429 'alt' => "Revert to default Constant",
1430 'title' => "Revert to default Constant",
1431 'rel' => $params['name']
1432 )
1433 );
1434 $editIconHTML = t3lib_iconWorks::getSpriteIcon(
1435 'actions-document-open',
1436 array(
1437 'class' => "typo3-tstemplate-ceditor-control editIcon",
1438 'alt' => "Edit this Constant",
1439 'title' => "Edit this Constant",
1440 'rel' => $params['name']
1441 )
1442 );
1443 $constantCheckbox = '<input type="hidden" name="' . $checkboxName . '" id="' . $checkboxID . '" value="' . $checkboxValue . '"/>';
1444
1445 // If there's no default value for the field, use a static label.
1446 if (!$params['default_value']) {
1447 $params['default_value'] = '[Empty]';
1448 }
1449
1450 $constantDefaultRow = '<div class="typo3-tstemplate-ceditor-row" id="' . $defaultTyposcriptID . '" ' .
1451 $defaultTyposcriptStyle . '>' . $editIconHTML .
1452 htmlspecialchars($params['default_value']) . $color . '</div>';
1453 }
1454
1455 $constantEditRow = '<div class="typo3-tstemplate-ceditor-row" id="' . $userTyposcriptID . '" ' .
1456 $userTyposcriptStyle . '>' . $deleteIconHTML . $p_field . $color . '</div>';
1457
1458 $constantLabel = '<dt class="typo3-tstemplate-ceditor-label">' . htmlspecialchars($head) . '</dt>';
1459 $constantName = '<dt class="typo3-dimmed">[' . $params['name'] . ']</dt>';
1460 $constantDescription = $body ? '<dd>' . htmlspecialchars($body) . '</dd>' : '';
1461 $constantData = '<dd>' . $constantCheckbox . $constantEditRow . $constantDefaultRow . '</dd>';
1462
1463 $output .= '<a name="' . $raname . '"></a>' . $help['constants'][$params['name']];
1464 $output .= '<dl class="typo3-tstemplate-ceditor-constant">' . $constantLabel . $constantName .
1465 $constantDescription . $constantData . '</dl>';
1466 } else {
1467 debug('Error. Constant did not exist. Should not happen.');
1468 }
1469 }
1470 }
1471 return $output;
1472 }
1473
1474
1475 /***************************
1476 *
1477 * Processing input values
1478 *
1479 ***************************/
1480
1481 /**
1482 * @param [type] $constants: ...
1483 * @return [type] ...
1484 */
1485 function ext_regObjectPositions($constants) {
1486 // This runs through the lines of the constants-field of the active template and registers the constants-names
1487 // and linepositions in an array, $this->objReg
1488 $this->raw = explode(LF, $constants);
1489 $this->rawP = 0;
1490
1491 $this->objReg = array(); // resetting the objReg if the divider is found!!
1492 $this->ext_regObjects('');
1493 }
1494
1495 /**
1496 * [Describe function...]
1497 *
1498 * @param [type] $pre: ...
1499 * @return [type] ...
1500 */
1501 function ext_regObjects($pre) {
1502 // works with regObjectPositions. "expands" the names of the TypoScript objects
1503 while (isset($this->raw[$this->rawP])) {
1504 $line = ltrim($this->raw[$this->rawP]);
1505 if (strstr($line, $this->edit_divider)) {
1506 $this->objReg = array(); // resetting the objReg if the divider is found!!
1507 }
1508 $this->rawP++;
1509 if ($line) {
1510 if (substr($line, 0, 1) == '[') {
1511 // return $line;
1512 } elseif (strcspn($line, '}#/') != 0) {
1513 $varL = strcspn($line, ' {=<');
1514 $var = substr($line, 0, $varL);
1515 $line = ltrim(substr($line, $varL));
1516 switch (substr($line, 0, 1)) {
1517 case '=':
1518 $this->objReg[$pre . $var] = $this->rawP - 1;
1519 break;
1520 case '{':
1521 $this->ext_inBrace++;
1522 $this->ext_regObjects($pre . $var . '.');
1523 break;
1524 }
1525 $this->lastComment = '';
1526 } elseif (substr($line, 0, 1) == '}') {
1527 $this->lastComment = '';
1528 $this->ext_inBrace--;
1529 if ($this->ext_inBrace < 0) {
1530 $this->ext_inBrace = 0;
1531 } else {
1532 break;
1533 }
1534 }
1535 }
1536 }
1537 }
1538
1539 /**
1540 * [Describe function...]
1541 *
1542 * @param [type] $key: ...
1543 * @param [type] $var: ...
1544 * @return [type] ...
1545 */
1546 function ext_putValueInConf($key, $var) {
1547 // Puts the value $var to the TypoScript value $key in the current lines of the templates.
1548 // If the $key is not found in the template constants field, a new line is inserted in the bottom.
1549 $theValue = ' ' . trim($var);
1550 if (isset($this->objReg[$key])) {
1551 $lineNum = $this->objReg[$key];
1552 $parts = explode('=', $this->raw[$lineNum], 2);
1553 if (count($parts) == 2) {
1554 $parts[1] = $theValue;
1555 }
1556 $this->raw[$lineNum] = implode($parts, '=');
1557 } else {
1558 $this->raw[] = $key . ' =' . $theValue;
1559 }
1560 $this->changed = 1;
1561 }
1562
1563 /**
1564 * [Describe function...]
1565 *
1566 * @param [type] $key: ...
1567 * @return [type] ...
1568 */
1569 function ext_removeValueInConf($key) {
1570 // Removes the value in the configuration
1571 if (isset($this->objReg[$key])) {
1572 $lineNum = $this->objReg[$key];
1573 unset($this->raw[$lineNum]);
1574 }
1575 $this->changed = 1;
1576 }
1577
1578 /**
1579 * [Describe function...]
1580 *
1581 * @param [type] $arr: ...
1582 * @param [type] $settings: ...
1583 * @return [type] ...
1584 */
1585 function ext_depthKeys($arr, $settings) {
1586 $tsbrArray = array();
1587 foreach ($arr as $theK => $theV) {
1588 $theKeyParts = explode('.', $theK);
1589 $depth = '';
1590 $c = count($theKeyParts);
1591 $a = 0;
1592 foreach ($theKeyParts as $p) {
1593 $a++;
1594 $depth .= ($depth ? '.' : '') . $p;
1595 $tsbrArray[$depth] = ($c == $a) ? $theV : 1;
1596 }
1597 }
1598 // Modify settings
1599 foreach ($tsbrArray as $theK => $theV) {
1600 if ($theV) {
1601 $settings[$theK] = 1;
1602 } else {
1603 unset($settings[$theK]);
1604 }
1605 }
1606 return $settings;
1607 }
1608
1609 /**
1610 * [Describe function...]
1611 *
1612 * @param [type] $http_post_vars: ...
1613 * @param [type] $http_post_files: ...
1614 * @param [type] $theConstants: ...
1615 * @param [type] $tplRow: ...
1616 * @return [type] ...
1617 */
1618 function ext_procesInput($http_post_vars, $http_post_files, $theConstants, $tplRow) {
1619 $data = $http_post_vars['data'];
1620 $check = $http_post_vars['check'];
1621 $copyResource = $http_post_vars['_copyResource'];
1622 $Wdata = $http_post_vars['Wdata'];
1623 $W2data = $http_post_vars['W2data'];
1624 $W3data = $http_post_vars['W3data'];
1625 $W4data = $http_post_vars['W4data'];
1626 $W5data = $http_post_vars['W5data'];
1627
1628 if (is_array($data)) {
1629 foreach ($data as $key => $var) {
1630 if (isset($theConstants[$key])) {
1631 if ($this->ext_dontCheckIssetValues || isset($check[$key])) { // If checkbox is set, update the value
1632 list($var) = explode(LF, $var); // exploding with linebreak, just to make sure that no multiline input is given!
1633 $typeDat = $this->ext_getTypeData($theConstants[$key]['type']);
1634 switch ($typeDat['type']) {
1635 case 'int':
1636 if ($typeDat['paramstr']) {
1637 $var = t3lib_div::intInRange($var, $typeDat['params'][0], $typeDat['params'][1]);
1638 } else {
1639 $var = intval($var);
1640 }
1641 break;
1642 case 'int+':
1643 $var = max(0, intval($var));
1644 break;
1645 case 'color':
1646 $col = array();
1647 if ($var && !t3lib_div::inList($this->HTMLcolorList, strtolower($var))) {
1648 $var = preg_replace('/[^A-Fa-f0-9]*/', '', $var);
1649 $useFullHex = strlen($var) > 3;
1650
1651 $col[] = HexDec(substr($var, 0, 1));
1652 $col[] = HexDec(substr($var, 1, 1));
1653 $col[] = HexDec(substr($var, 2, 1));
1654
1655 if ($useFullHex) {
1656 $col[] = HexDec(substr($var, 3, 1));
1657 $col[] = HexDec(substr($var, 4, 1));
1658 $col[] = HexDec(substr($var, 5, 1));
1659 }
1660
1661 $var = substr('0' . DecHex($col[0]), -1) . substr('0' . DecHex($col[1]), -1) . substr('0' . DecHex($col[2]), -1);
1662 if ($useFullHex) {
1663 $var .= substr('0' . DecHex($col[3]), -1) . substr('0' . DecHex($col[4]), -1) . substr('0' . DecHex($col[5]), -1);
1664 }
1665
1666 $var = '#' . strtoupper($var);
1667 }
1668 break;
1669 case 'comment':
1670 if ($var) {
1671 $var = '#';
1672 } else {
1673 $var = '';
1674 }
1675 break;
1676 case 'wrap':
1677 if (isset($Wdata[$key])) {
1678 $var .= '|' . $Wdata[$key];
1679 }
1680 break;
1681 case 'offset':
1682 if (isset($Wdata[$key])) {
1683 $var = intval($var) . ',' . intval($Wdata[$key]);
1684 if (isset($W2data[$key])) {
1685 $var .= ',' . intval($W2data[$key]);
1686 if (isset($W3data[$key])) {
1687 $var .= ',' . intval($W3data[$key]);
1688 if (isset($W4data[$key])) {
1689 $var .= ',' . intval($W4data[$key]);
1690 if (isset($W5data[$key])) {
1691 $var .= ',' . intval($W5data[$key]);
1692 }
1693 }
1694 }
1695 }
1696 }
1697 break;
1698 case 'boolean':
1699 if ($var) {
1700 $var = $typeDat['paramstr'] ? $typeDat['paramstr'] : 1;
1701 }
1702 break;
1703 case 'file':
1704 if (!$this->ext_noCEUploadAndCopying) {
1705 if ($http_post_files['upload_data']['name'][$key] && $http_post_files['upload_data']['tmp_name'][$key] != 'none') {
1706 $var = $this->upload_copy_file(
1707 $typeDat,
1708 $tplRow,
1709 trim($http_post_files['upload_data']['name'][$key]),
1710 $http_post_files['upload_data']['tmp_name'][$key]
1711 );
1712 }
1713 if ($copyResource[$key]) {
1714 $var = $this->upload_copy_file(
1715 $typeDat,
1716 $tplRow,
1717 basename($copyResource[$key]),
1718 $copyResource[$key]
1719 );
1720 }
1721 }
1722 break;
1723 }
1724 if ($this->ext_printAll || strcmp($theConstants[$key]['value'], $var)) {
1725 $this->ext_putValueInConf($key, $var); // Put value in, if changed.
1726 }
1727 unset($check[$key]); // Remove the entry because it has been "used"
1728 } else {
1729 $this->ext_removeValueInConf($key);
1730 }
1731 }
1732 }
1733 }
1734 // 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...
1735 if (!$this->ext_dontCheckIssetValues && is_array($check)) {
1736 foreach ($check as $key => $var) {
1737 if (isset($theConstants[$key])) {
1738 $dValue = $theConstants[$key]['default_value'];
1739 $this->ext_putValueInConf($key, $dValue);
1740 }
1741 }
1742 }
1743 }
1744
1745 /**
1746 * [Describe function...]
1747 *
1748 * @param [type] $typeDat: ...
1749 * @param [type] $tplRow: ...
1750 * @param [type] $theRealFileName: ...
1751 * @param [type] $tmp_name: ...
1752 * @return [type] ...
1753 */
1754 function upload_copy_file($typeDat, &$tplRow, $theRealFileName, $tmp_name) {
1755
1756 // extensions
1757 $extList = $typeDat['paramstr'];
1758 if ($extList == 'IMAGE_EXT') {
1759 $extList = $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'];
1760 }
1761 $fI = t3lib_div::split_fileref($theRealFileName);
1762 if ($theRealFileName && (!$extList || t3lib_div::inList($extList, $fI['fileext']))) {
1763 $tmp_upload_name = t3lib_div::upload_to_tempfile($tmp_name); // If there is an uploaded file, move it for the sake of safe_mode.
1764
1765 // Saving resource
1766 $alternativeFileName = array();
1767 $alternativeFileName[$tmp_upload_name] = $theRealFileName;
1768 // Making list of resources
1769 $resList = $tplRow['resources'];
1770 $resList = $tmp_upload_name . ',' . $resList;
1771 $resList = implode(t3lib_div::trimExplode(',', $resList, 1), ',');
1772 // Making data-array
1773 $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
1774
1775 $recData = array();
1776 $recData['sys_template'][$saveId]['resources'] = $resList;
1777 // Saving
1778 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
1779 $tce->stripslashes_values = 0;
1780 $tce->alternativeFileName = $alternativeFileName;
1781 $tce->start($recData, Array());
1782 $tce->process_datamap();
1783
1784 t3lib_div::unlink_tempfile($tmp_upload_name);
1785
1786 $tmpRow = t3lib_BEfunc::getRecordWSOL('sys_template', $saveId, 'resources');
1787
1788 $tplRow['resources'] = $tmpRow['resources'];
1789
1790 // Setting the value
1791 $var = $this->ext_setStar($theRealFileName);
1792 }
1793 return $var;
1794 }
1795
1796 /**
1797 * [Describe function...]
1798 *
1799 * @param [type] $id: ...
1800 * @param [type] $perms_clause: ...
1801 * @return [type] ...
1802 */
1803 function ext_prevPageWithTemplate($id, $perms_clause) {
1804 $rootLine = t3lib_BEfunc::BEgetRootLine($id, $perms_clause ? ' AND ' . $perms_clause : '');
1805 foreach ($rootLine as $p) {
1806 if ($this->ext_getFirstTemplate($p['uid'])) {
1807 return $p;
1808 }
1809 }
1810 }
1811
1812 /**
1813 * [Describe function...]
1814 *
1815 * @param [type] $val: ...
1816 * @return [type] ...
1817 */
1818 function ext_setStar($val) {
1819 $fParts = explode('.', strrev($val), 2);
1820 $val = preg_replace('/_[0-9][0-9]$/', '', strrev($fParts[1])) . '*.' . strrev($fParts[0]);
1821 return $val;
1822 }
1823
1824 /**
1825 * [Describe function...]
1826 *
1827 * @param [type] $value: ...
1828 * @return [type] ...
1829 */
1830 function ext_detectAndFixExtensionPrefix($value) {
1831 if (substr($value, 0, 4) == 'EXT:') {
1832 $parts = explode('/', substr($value, 4), 2);
1833
1834 $extPath = t3lib_extMgm::siteRelPath($parts[0]);
1835 $value = $extPath . $parts[1];
1836 return $value;
1837 } else {
1838 return $value;
1839 }
1840 }
1841 }
1842
1843
1844 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php'])) {
1845 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php']);
1846 }
1847
1848 ?>