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