2 /***************************************************************
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * TSParser extension class to t3lib_TStemplate
30 * Contains functions for the TS module in TYPO3 backend
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
37 * TSParser extension class to t3lib_TStemplate
39 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
43 class t3lib_tsparser_ext
extends t3lib_TStemplate
{
45 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.
46 var $HTMLcolorList = 'aqua,beige,black,blue,brown,fuchsia,gold,gray,green,lime,maroon,navy,olive,orange,purple,red,silver,tan,teal,turquoise,yellow,white';
49 var $categories = array(
50 '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.
51 'menu' => array(), // Menu setup. This includes fontfiles, sizes, background images. Depending on the menutype.
52 'content' => array(), // All constants related to the display of pagecontent elements
53 'page' => array(), // General configuration like metatags, link targets
54 'advanced' => array(), // Advanced functions, which are used very seldomly.
55 'all' => array() // All constants are put here also!
56 ); // This will be filled with the available categories of the current template.
57 var $subCategories = array(
58 // Standard categories:
59 'enable' => Array('Enable features', 'a'),
60 'dims' => Array('Dimensions, widths, heights, pixels', 'b'),
61 'file' => Array('Files', 'c'),
62 'typo' => Array('Typography', 'd'),
63 'color' => Array('Colors', 'e'),
64 'links' => Array('Links and targets', 'f'),
65 'language' => Array('Language specific constants', 'g'),
67 // subcategories based on the default content elements
68 'cheader' => Array('Content: \'Header\'', 'ma'),
69 'cheader_g' => Array('Content: \'Header\', Graphical', 'ma'),
70 'ctext' => Array('Content: \'Text\'', 'mb'),
71 'cimage' => Array('Content: \'Image\'', 'md'),
72 'cbullets' => Array('Content: \'Bullet list\'', 'me'),
73 'ctable' => Array('Content: \'Table\'', 'mf'),
74 'cuploads' => Array('Content: \'Filelinks\'', 'mg'),
75 'cmultimedia' => Array('Content: \'Multimedia\'', 'mh'),
76 'cmedia' => Array('Content: \'Media\'', 'mr'),
77 'cmailform' => Array('Content: \'Form\'', 'mi'),
78 'csearch' => Array('Content: \'Search\'', 'mj'),
79 'clogin' => Array('Content: \'Login\'', 'mk'),
80 'csplash' => Array('Content: \'Textbox\'', 'ml'),
81 'cmenu' => Array('Content: \'Menu/Sitemap\'', 'mm'),
82 'cshortcut' => Array('Content: \'Insert records\'', 'mn'),
83 'clist' => Array('Content: \'List of records\'', 'mo'),
84 'cscript' => Array('Content: \'Script\'', 'mp'),
85 'chtml' => Array('Content: \'HTML\'', 'mq')
87 var $resourceDimensions = array();
88 var $dirResources = array();
90 var $backend_info = 1;
96 var $tsbrowser_searchKeys = array();
97 var $tsbrowser_depthKeys = array();
98 var $constantMode = '';
101 var $resourceCheck = 0;
102 var $ext_lineNumberOffset = 0;
103 var $ext_localGfxPrefix = '';
104 var $ext_localWebGfxPrefix = '';
105 var $ext_expandAllNotes = 0;
106 var $ext_noPMicons = 0;
107 var $ext_noSpecialCharsOnLabels = 0;
108 var $ext_listOfTemplatesArr = array();
109 var $ext_lineNumberOffset_mode = '';
110 var $ext_dontCheckIssetValues = 0; // Dont change...
111 var $ext_noCEUploadAndCopying = 0;
112 var $ext_printAll = 0;
113 var $ext_CEformName = 'forms[0]';
114 var $ext_defaultOnlineResourceFlag = 0;
115 var $doNotSortCategoriesBeforeMakingForm = FALSE;
118 var $templateTitles = array();
122 * This flattens a hierarchical setuparray to $this->flatSetup
123 * The original function fetched the resource-file if any ('file.'). This functions doesn't.
125 * @param [type] $setupArray: ...
126 * @param [type] $prefix: ...
127 * @param [type] $resourceFlag: ...
130 function flattenSetup($setupArray, $prefix, $resourceFlag) {
131 if (is_array($setupArray)) {
132 $this->getFileName_backPath
= PATH_site
; // Setting absolute prefixed path for relative resources.
133 foreach ($setupArray as $key => $val) {
134 if ($prefix ||
substr($key, 0, 16) != 'TSConstantEditor') { // We don't want 'TSConstantEditor' in the flattend setup.
135 if (is_array($val)) {
136 $this->flattenSetup($val, $prefix . $key, ($key == 'file.'));
137 } elseif ($resourceFlag && $this->resourceCheck
) {
138 $this->flatSetup
[$prefix . $key] = $this->getFileName($val);
139 if ($this->removeFromGetFilePath
&&
140 substr($this->flatSetup
[$prefix . $key], 0, strlen($this->removeFromGetFilePath
)) == $this->removeFromGetFilePath
) {
141 $this->flatSetup
[$prefix . $key] = substr($this->flatSetup
[$prefix . $key], strlen($this->removeFromGetFilePath
));
144 $this->flatSetup
[$prefix . $key] = $val;
152 * [Describe function...]
154 * @param [type] $all: ...
157 function substituteConstants($all) {
158 $this->Cmarker
= substr(md5(uniqid('')), 0, 6);
160 return preg_replace_callback('/\{\$(.[^}]+)\}/', array($this, 'substituteConstantsCallBack'), $all);
164 * Call back method for preg_replace_callback in substituteConstants
166 * @param array Regular expression matches
167 * @return string Replacement
168 * @see substituteConstants()
170 function substituteConstantsCallBack($matches) {
171 switch ($this->constantMode
) {
173 $ret_val = isset($this->flatSetup
[$matches[1]]) && !is_array($this->flatSetup
[$matches[1]]) ?
174 '##' . $this->Cmarker
. '_B##' . $matches[0] . '##' . $this->Cmarker
. '_E##' :
178 $ret_val = isset($this->flatSetup
[$matches[1]]) && !is_array($this->flatSetup
[$matches[1]]) ?
179 '##' . $this->Cmarker
. '_B##' . $this->flatSetup
[$matches[1]] . '##' . $this->Cmarker
. '_E##' :
183 $ret_val = $matches[0];
186 $ret_val = isset($this->flatSetup
[$matches[1]]) && !is_array($this->flatSetup
[$matches[1]]) ?
187 $this->flatSetup
[$matches[1]] :
195 * [Describe function...]
197 * @param [type] $all: ...
200 function substituteCMarkers($all) {
201 switch ($this->constantMode
) {
203 $all = str_replace('##' . $this->Cmarker
. '_B##', '<font color="green"><strong>', $all);
204 $all = str_replace('##' . $this->Cmarker
. '_E##', '</strong></font>', $all);
207 $all = str_replace('##' . $this->Cmarker
. '_B##', '<font color="green"><strong>', $all);
208 $all = str_replace('##' . $this->Cmarker
. '_E##', '</strong></font>', $all);
218 * Parses the constants in $this->const with respect to the constant-editor in this module.
219 * In particular comments in the code are registered and the edit_divider is taken into account.
223 function generateConfig_constants() {
224 // These vars are also set lateron...
225 $this->setup
['resources'] = $this->resources
;
226 $this->setup
['sitetitle'] = $this->sitetitle
;
229 $constants = t3lib_div
::makeInstance('t3lib_TSparser');
230 $constants->regComments
= 1; // Register comments!
231 $constants->setup
= $this->const;
232 $constants->setup
= $this->mergeConstantsFromPageTSconfig($constants->setup
);
234 /* @var $matchObj t3lib_matchCondition_frontend */
235 $matchObj = t3lib_div
::makeInstance('t3lib_matchCondition_frontend');
236 $matchObj->setSimulateMatchResult(TRUE); // Matches ALL conditions in TypoScript
239 $cc = count($this->constants
);
240 foreach ($this->constants
as $str) {
243 if (strstr($str, $this->edit_divider
)) {
244 $parts = explode($this->edit_divider
, $str, 2);
246 $constants->parse($parts[0], $matchObj);
248 $this->flatSetup
= Array();
249 $this->flattenSetup($constants->setup
, '', '');
250 $defaultConstants = $this->flatSetup
;
252 $constants->parse($str, $matchObj);
255 $this->flatSetup
= Array();
256 $this->flattenSetup($constants->setup
, '', '');
257 $this->setup
['constants'] = $constants->setup
;
259 return $this->ext_compareFlatSetups($defaultConstants);
263 * [Describe function...]
265 * @param [type] $theSetup: ...
266 * @param [type] $theKey: ...
269 function ext_getSetup($theSetup, $theKey) {
270 $parts = explode('.', $theKey, 2);
271 if (strcmp($parts[0], '') && is_array($theSetup[$parts[0] . '.'])) {
272 if (strcmp(trim($parts[1]), '')) {
273 return $this->ext_getSetup($theSetup[$parts[0] . '.'], trim($parts[1]));
275 return array($theSetup[$parts[0] . '.'], $theSetup[$parts[0]]);
278 if (strcmp(trim($theKey), '')) {
279 return array(array(), $theSetup[$theKey]);
281 return array($theSetup, '');
287 * [Describe function...]
289 * @param [type] $arr: ...
290 * @param [type] $depth_in: ...
291 * @param [type] $depthData: ...
292 * @param [type] $parentType: ...
293 * @param [type] $parentValue: ...
294 * @param boolean $alphaSort sorts the array keys / tree by alphabet when set to 1
297 function ext_getObjTree($arr, $depth_in, $depthData, $parentType = '', $parentValue = '', $alphaSort = '0') {
301 if ($alphaSort == '1') {
304 $keyArr_num = array();
305 $keyArr_alpha = array();
306 foreach ($arr as $key => $value) {
307 if (substr($key, -2) != '..') { // Don't do anything with comments / linenumber registrations...
308 $key = preg_replace('/\.$/', '', $key);
309 if (substr($key, -1) != '.') {
310 if (t3lib_utility_Math
::canBeInterpretedAsInteger($key)) {
311 $keyArr_num[$key] = $arr[$key];
313 $keyArr_alpha[$key] = $arr[$key];
319 $keyArr = $keyArr_num +
$keyArr_alpha;
322 $depth_in = $depth_in . '.';
325 foreach ($keyArr as $key => $value) {
327 $depth = $depth_in . $key;
328 if ($this->bType
!= 'const' ||
substr($depth, 0, 1) != '_') { // this excludes all constants starting with '_' from being shown.
329 $goto = substr(md5($depth), 0, 6);
330 $deeper = (is_array($arr[$key . '.']) && ($this->tsbrowser_depthKeys
[$depth] ||
$this->ext_expandAllNotes
)) ?
1 : 0;
332 $LN = ($a == $c) ?
'blank' : 'line';
333 $BTM = ($a == $c) ?
'bottom' : '';
334 $PM = is_array($arr[$key . '.']) && !$this->ext_noPMicons ?
($deeper ?
'minus' : 'plus') : 'join';
337 $theIcon = '<img src="' . $GLOBALS['BACK_PATH'] . 'gfx/ol/' . $PM . $BTM . '.gif" width="18" height="16" align="top" border="0" alt="" />';
341 $aHref = 'index.php?id=' . $GLOBALS['SOBE']->id
.
342 '&tsbr[' . $depth . ']=' . ($deeper ?
0 : 1) .
343 (t3lib_div
::_GP("breakPointLN") ?
'&breakPointLN=' . t3lib_div
::_GP("breakPointLN") : '') .
345 $HTML .= '<a name="' . $goto . '" href="' . htmlspecialchars($aHref) . '">' . $theIcon . '</a>';
349 if (t3lib_div
::inList('types,resources,sitetitle', $depth) && $this->bType
== 'setup') { // Read only...
350 $label = '<font color="#666666">' . $label . '</font>';
352 if ($this->linkObjects
) {
353 $aHref = 'index.php?id=' . $GLOBALS['SOBE']->id
.
355 (t3lib_div
::_GP("breakPointLN") ?
'&breakPointLN=' . t3lib_div
::_GP("breakPointLN") : '');
356 if ($this->bType
!= 'const') {
357 $ln = is_array($arr[$key . '.ln..']) ?
'Defined in: ' . $this->lineNumberToScript($arr[$key . '.ln..']) : 'N/A';
362 if ($this->tsbrowser_searchKeys
[$depth] & 4) {
363 $label = '<strong><font color="red">' . $label . '</font></strong>';
364 } // The key has matched the search string
365 $label = '<a href="' . htmlspecialchars($aHref) . '" title="' . htmlspecialchars($ln) . '">' . $label . '</a>';
369 $HTML .= '[' . $label . ']';
371 if (isset($arr[$key])) {
372 $theValue = $arr[$key];
373 if ($this->fixedLgd
) {
374 $imgBlocks = ceil(1 +
strlen($depthData) / 77);
375 $lgdChars = 68 - ceil(strlen('[' . $key . ']') * 0.8) - $imgBlocks * 3;
376 $theValue = $this->ext_fixed_lgd($theValue, $lgdChars);
378 if ($this->tsbrowser_searchKeys
[$depth] & 2) { // The value has matched the search string
379 $HTML .= ' = <strong><font color="red">' . $this->makeHtmlspecialchars($theValue) . '</font></strong>';
381 $HTML .= ' = <strong>' . $this->makeHtmlspecialchars($theValue) . '</strong>';
383 if ($this->ext_regComments
&& isset($arr[$key . '..'])) {
384 $comment = $arr[$key . '..'];
385 if (!preg_match('/### <INCLUDE_TYPOSCRIPT:.*/', $comment)) { // Skip INCLUDE_TYPOSCRIPT comments, they are almost useless
386 $comment = preg_replace('/[\r\n]/', ' ', $comment); // Remove linebreaks, replace with ' '
387 $comment = preg_replace('/[#\*]{2,}/', '', $comment); // Remove # and * if more than twice in a row
388 $comment = preg_replace('/^[#\*\s]+/', '# ', $comment); // Replace leading # (just if it exists) and add it again. Result: Every comment should be prefixed by a '#'.
389 $comment = $this->makeHtmlspecialchars($comment); // Masking HTML Tags: Replace < with < and > with >
390 $HTML .= ' <span class="comment">' . trim($comment) . '</span>';
397 $HTML .= $this->ext_getObjTree(
400 $depthData . '<img src="' . $GLOBALS['BACK_PATH'] . 'gfx/ol/' . $LN . '.gif" width="18" height="16" align="top" alt="" />',
401 '' /* not used: $validate_info[$key] */,
412 * [Describe function...]
414 * @param [type] $lnArr: ...
417 function lineNumberToScript($lnArr) {
418 if (!is_array($this->lnToScript
)) {
419 $this->lnToScript
= array();
421 $c +
= substr_count($GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'], LF
) +
2;
422 $this->lnToScript
[$c] = '[Default]';
424 foreach ($this->hierarchyInfoToRoot
as $info) {
425 $c +
= $info['configLines'] +
1;
426 $this->lnToScript
[$c] = $info['title'];
430 foreach ($lnArr as $k => $ln) {
431 foreach ($this->lnToScript
as $endLn => $title) {
432 if ($endLn >= intval($ln)) {
433 $lnArr[$k] = '"' . $title . '", ' . $ln;
439 return implode('; ', $lnArr);
443 * [Describe function...]
445 * @param [type] $theValue: ...
448 function makeHtmlspecialchars($theValue) {
449 return $this->ext_noSpecialCharsOnLabels ?
$theValue : htmlspecialchars($theValue);
453 * [Describe function...]
455 * @param [type] $arr: ...
456 * @param [type] $depth_in: ...
457 * @param [type] $searchString: ...
458 * @param [type] $keyArray: ...
461 function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray) {
463 foreach ($arr as $key => $value) {
464 $key = preg_replace('/\.$/', '', $key);
465 if (substr($key, -1) != '.') {
471 $depth_in = $depth_in . '.';
473 foreach ($keyArr as $key => $value) {
474 $depth = $depth_in . $key;
475 $deeper = is_array($arr[$key . '.']);
477 if ($this->regexMode
) {
478 if (preg_match('/' . $searchString . '/', $arr[$key])) { // The value has matched
479 $this->tsbrowser_searchKeys
[$depth] +
= 2;
481 if (preg_match('/' . $searchString . '/', $key)) { // The key has matched
482 $this->tsbrowser_searchKeys
[$depth] +
= 4;
484 if (preg_match('/' . $searchString . '/', $depth_in)) { // Just open this subtree if the parent key has matched the search
485 $this->tsbrowser_searchKeys
[$depth] = 1;
488 if (stristr($arr[$key], $searchString)) { // The value has matched
489 $this->tsbrowser_searchKeys
[$depth] +
= 2;
491 if (stristr($key, $searchString)) { // The key has matches
492 $this->tsbrowser_searchKeys
[$depth] +
= 4;
494 if (stristr($depth_in, $searchString)) { // Just open this subtree if the parent key has matched the search
495 $this->tsbrowser_searchKeys
[$depth] = 1;
500 $cS = count($this->tsbrowser_searchKeys
);
501 $keyArray = $this->ext_getSearchKeys($arr[$key . '.'], $depth, $searchString, $keyArray);
502 if ($cS != count($this->tsbrowser_searchKeys
)) {
503 $keyArray[$depth] = 1;
511 * [Describe function...]
513 * @param [type] $pid: ...
516 function ext_getRootlineNumber($pid) {
517 if ($pid && is_array($GLOBALS['rootLine'])) {
518 foreach ($GLOBALS['rootLine'] as $key => $val) {
519 if ($val['uid'] == $pid) {
527 * [Describe function...]
529 * @param [type] $arr: ...
530 * @param [type] $depthData: ...
531 * @param [type] $keyArray: ...
532 * @param [type] $first: ...
535 function ext_getTemplateHierarchyArr($arr, $depthData, $keyArray, $first = 0) {
537 foreach ($arr as $key => $value) {
538 $key = preg_replace('/\.$/', '', $key);
539 if (substr($key, -1) != '.') {
546 foreach ($keyArr as $key => $value) {
549 $deeper = is_array($arr[$key . '.']);
553 $LN = ($a == $c) ?
'blank' : 'line';
554 $BTM = ($a == $c) ?
'top' : '';
559 $alttext = '[' . $row['templateID'] . ']';
560 $alttext .= $row['pid'] ?
' - ' . t3lib_BEfunc
::getRecordPath($row['pid'], $GLOBALS['SOBE']->perms_clause
, 20) : '';
562 $icon = (substr($row['templateID'], 0, 3) == 'sys' ?
563 t3lib_iconWorks
::getSpriteIconForRecord('sys_template', $row, array('title' => $alttext))
564 : t3lib_iconWorks
::getSpriteIcon('mimetypes-x-content-template-static', array('title' => $alttext))
566 if (in_array($row['templateID'], $this->clearList_const
) ||
in_array($row['templateID'], $this->clearList_setup
)) {
567 $A_B = '<a href="index.php?id=' . htmlspecialchars($GLOBALS['SOBE']->id
. '&template=' . $row['templateID']) . '">';
569 if (t3lib_div
::_GP('template') == $row['templateID']) {
570 $A_B = '<strong>' . $A_B;
577 $HTML .= ($first ?
'' : '<img src="' . $GLOBALS['BACK_PATH'] . 'gfx/ol/' . $PM . $BTM . '.gif" width="18" height="16" align="top" border="0" alt="" />') .
579 $A_B . htmlspecialchars(t3lib_div
::fixed_lgd_cs($row['title'], $GLOBALS['BE_USER']->uc
['titleLen'])) . $A_E . ' ';
580 $RL = $this->ext_getRootlineNumber($row['pid']);
581 $keyArray[] = '<tr class="' . ($i++ %
2 == 0 ?
'bgColor4' : 'bgColor6') . '">
582 <td nowrap="nowrap">' . $HTML . '</td>
583 <td align="center">' . ($row['root'] ? t3lib_iconWorks
::getSpriteIcon('status-status-checked') : '') . ' </td>
584 <td align="center">' . ($row['clConf'] ? t3lib_iconWorks
::getSpriteIcon('status-status-checked') : '') . ' ' . '</td>
585 <td align="center">' . ($row['clConst'] ? t3lib_iconWorks
::getSpriteIcon('status-status-checked') : '') . ' ' . '</td>
586 <td align="center">' . ($row['pid'] ?
$row['pid'] : '') . '</td>
587 <td align="center">' . (strcmp($RL, '') ?
$RL : '') . '</td>
588 <td>' . ($row['next'] ?
' ' . $row['next'] . ' ' : '') . '</td>
591 $keyArray = $this->ext_getTemplateHierarchyArr(
593 $depthData . ($first ?
'' : '<img src="' . $GLOBALS['BACK_PATH'] . 'gfx/ol/' . $LN . '.gif" width="18" height="16" align="top" />'),
602 * [Describe function...]
604 * @param [type] $depthDataArr: ...
605 * @param [type] $pointer: ...
608 function ext_process_hierarchyInfo($depthDataArr, &$pointer) {
609 $parent = $this->hierarchyInfo
[$pointer - 1]['templateParent'];
610 while ($pointer > 0 && $this->hierarchyInfo
[$pointer - 1]['templateParent'] == $parent) {
612 $row = $this->hierarchyInfo
[$pointer];
614 $depthDataArr[$row['templateID']] = $row;
615 $depthDataArr[$row['templateID']]['bgcolor_setup'] = isset($this->clearList_setup_temp
[$row['templateID']]) ?
' class="bgColor5"' : '';
616 $depthDataArr[$row['templateID']]['bgcolor_const'] = isset($this->clearList_const_temp
[$row['templateID']]) ?
' class="bgColor5"' : '';
617 unset($this->clearList_setup_temp
[$row['templateID']]);
618 unset($this->clearList_const_temp
[$row['templateID']]);
619 $this->templateTitles
[$row['templateID']] = $row['title'];
621 if ($row['templateID'] == $this->hierarchyInfo
[$pointer - 1]['templateParent']) {
622 $depthDataArr[$row['templateID'] . '.'] = $this->ext_process_hierarchyInfo(array(), $pointer);
625 return $depthDataArr;
629 * [Describe function...]
631 * @param [type] $config: ...
632 * @param [type] $lineNumbers: ...
633 * @param [type] $comments: ...
634 * @param [type] $crop: ...
635 * @param [type] $syntaxHL: ...
636 * @param [type] $syntaxHLBlockmode: ...
639 function ext_outputTS($config, $lineNumbers = 0, $comments = 0, $crop = 0, $syntaxHL = 0, $syntaxHLBlockmode = 0) {
641 foreach ($config as $str) {
642 $all .= LF
. '[GLOBAL]' . LF
. $str;
646 $all = preg_replace('/^[^' . LF
. ']*./', '', $all);
648 $tsparser = t3lib_div
::makeInstance('t3lib_TSparser');
649 $tsparser->lineNumberOffset
= $this->ext_lineNumberOffset +
1;
650 $tsparser->parentObject
= $this;
651 return $tsparser->doSyntaxHighlight($all, $lineNumbers ?
array($this->ext_lineNumberOffset +
1) : '', $syntaxHLBlockmode);
653 return $this->ext_formatTS($all, $lineNumbers, $comments, $crop);
658 * Returns a new string of max. $chars lenght
659 * If the string is longer, it will be truncated and prepended with '...'
660 * $chars must be an integer of at least 4
662 * @param [type] $string: ...
663 * @param [type] $chars: ...
666 function ext_fixed_lgd($string, $chars) {
668 if (strlen($string) > $chars) {
669 if (strlen($string) > 24 && substr($string, 0, 12) == '##' . $this->Cmarker
. '_B##') {
670 return '##' . $this->Cmarker
. '_B##' . t3lib_div
::fixed_lgd_cs(substr($string, 12, -12), $chars - 3) . '##' . $this->Cmarker
. '_E##';
672 return t3lib_div
::fixed_lgd_cs($string, $chars - 3);
680 * [Describe function...]
682 * @param integer $lineNumber Line Number
683 * @param [type] $str: ...
686 function ext_lnBreakPointWrap($lineNumber, $str) {
687 return '<a href="#" id="line-' . $lineNumber . '" onClick="return brPoint(' . $lineNumber . ',' . ($this->ext_lineNumberOffset_mode
== "setup" ?
1 : 0) . ');">' . $str . '</a>';
691 * [Describe function...]
693 * @param [type] $input: ...
694 * @param [type] $ln: ...
695 * @param [type] $comments: ...
696 * @param [type] $crop: ...
699 function ext_formatTS($input, $ln, $comments = 1, $crop = 0) {
700 $input = preg_replace('/^[^' . LF
. ']*./', '', $input);
701 $input = chop($input);
702 $cArr = explode(LF
, $input);
704 $n = ceil(log10(count($cArr) +
$this->ext_lineNumberOffset
));
706 foreach ($cArr as $k => $v) {
707 $lln = $k +
$this->ext_lineNumberOffset +
1;
709 $lineNum = $this->ext_lnBreakPointWrap($lln, str_replace(' ', ' ', sprintf('% ' . $n . 'd', $lln))) . ': ';
711 $v = htmlspecialchars($v);
713 $v = $this->ext_fixed_lgd($v, ($ln ?
71 : 77));
715 $cArr[$k] = $lineNum . str_replace(' ', ' ', $v);
717 $firstChar = substr(trim($v), 0, 1);
718 if ($firstChar == '[') {
719 $cArr[$k] = '<font color="green"><strong>' . $cArr[$k] . '</strong></font>';
720 } elseif ($firstChar == '/' ||
$firstChar == '#') {
722 $cArr[$k] = '<span class="typo3-dimmed">' . $cArr[$k] . '</span>';
730 $output = implode($cArr, '<br />') . '<br />';
735 * [Describe function...]
737 * @param [type] $id: ...
738 * @param [type] $template_uid: ...
741 function ext_getFirstTemplate($id, $template_uid = 0) {
742 // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
745 $addC = ' AND uid=' . $template_uid;
747 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid=' . intval($id) . $addC . ' ' . $this->whereClause
, '', 'sorting', '1');
748 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
749 t3lib_BEfunc
::workspaceOL('sys_template', $row);
750 $GLOBALS['TYPO3_DB']->sql_free_result($res);
751 return $row; // Returns the template row if found.
756 * [Describe function...]
758 * @param [type] $id: ...
761 function ext_getAllTemplates($id) {
762 // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
765 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid=' . intval($id) . ' ' . $this->whereClause
, '', 'sorting');
766 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
767 t3lib_BEfunc
::workspaceOL('sys_template', $row);
768 if (is_array($row)) {
772 $GLOBALS['TYPO3_DB']->sql_free_result($res);
773 return $outRes; // Returns the template rows in an array.
778 * This function compares the flattened constants (default and all).
779 * Returns an array with the constants from the whole template which may be edited by the module.
781 * @param [type] $default: ...
784 function ext_compareFlatSetups($default) {
785 $editableComments = array();
786 foreach ($this->flatSetup
as $const => $value) {
787 if (substr($const, -2) != '..' && isset($this->flatSetup
[$const . '..'])) {
788 $comment = trim($this->flatSetup
[$const . '..']);
789 $c_arr = explode(LF
, $comment);
790 foreach ($c_arr as $k => $v) {
791 $line = trim(preg_replace('/^[#\/]*/', '', $v));
793 $parts = explode(';', $line);
794 foreach ($parts as $par) {
795 if (strstr($par, '=')) {
796 $keyValPair = explode('=', $par, 2);
797 switch (trim(strtolower($keyValPair[0]))) {
800 $editableComments[$const]['type'] = trim($keyValPair[1]);
803 // list of categories.
804 $catSplit = explode('/', strtolower($keyValPair[1]));
805 $editableComments[$const]['cat'] = trim($catSplit[0]);
806 $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.
807 if ($catSplit[1] && isset($this->subCategories
[$catSplit[1]])) {
808 $editableComments[$const]['subcat_name'] = $catSplit[1];
809 $editableComments[$const]['subcat'] = $this->subCategories
[$catSplit[1]][1] . '/' .
810 $catSplit[1] . '/' . trim($catSplit[2]) . 'z';
812 $editableComments[$const]['subcat'] = 'x' . '/' . trim($catSplit[2]) . 'z';
817 $editableComments[$const]['label'] = trim($keyValPair[1]);
819 case 'customsubcategory':
820 // custom subCategory label
821 $customSubcategory = explode('=', $keyValPair[1], 2);
822 if (trim($customSubcategory[0])) {
823 $subCategoryKey = strtolower($customSubcategory[0]);
824 $this->subCategories
[$subCategoryKey][0] = $GLOBALS['LANG']->sL($customSubcategory[1]);
833 if (isset($editableComments[$const])) {
834 $editableComments[$const]['name'] = $const;
835 $editableComments[$const]['value'] = trim($value);
836 if (isset($default[$const])) {
837 $editableComments[$const]['default_value'] = trim($default[$const]);
841 return $editableComments;
845 * [Describe function...]
847 * @param [type] $editConstArray: ...
850 function ext_categorizeEditableConstants($editConstArray) {
851 // Runs through the available constants and fills the $this->categories array with pointers and priority-info
852 foreach ($editConstArray as $constName => $constData) {
853 if (!$constData['type']) {
854 $constData['type'] = 'string';
856 $cats = explode(',', $constData['cat']);
857 foreach ($cats as $theCat) { // if = only one category, while allows for many. We have agreed on only one category is the most basic way...
858 $theCat = trim($theCat);
860 $this->categories
[$theCat][$constName] = $constData['subcat'];
867 * [Describe function...]
871 function ext_getCategoryLabelArray() {
872 // Returns array used for labels in the menu.
874 foreach ($this->categories
as $k => $v) {
876 $retArr[$k] = strtoupper($k) . ' (' . count($v) . ')';
883 * [Describe function...]
885 * @param [type] $type: ...
888 function ext_getTypeData($type) {
892 $retArr['type'] = 'string';
894 $m = strcspn($type, ' [');
895 $retArr['type'] = strtolower(substr($type, 0, $m));
896 if (t3lib_div
::inList('int,options,file,boolean,offset,user', $retArr['type'])) {
897 $p = trim(substr($type, $m));
899 preg_match('/\[(.*)\]/', $p, $reg);
902 $retArr['paramstr'] = $p;
903 switch ($retArr['type']) {
905 if (substr($retArr['paramstr'], 0, 1) == '-') {
906 $retArr['params'] = t3lib_div
::intExplode('-', substr($retArr['paramstr'], 1));
907 $retArr['params'][0] = intval('-' . $retArr['params'][0]);
909 $retArr['params'] = t3lib_div
::intExplode('-', $retArr['paramstr']);
911 $retArr['paramstr'] = $retArr['params'][0] . ' - ' . $retArr['params'][1];
914 $retArr['params'] = explode(',', $retArr['paramstr']);
924 * [Describe function...]
926 * @param [type] $category: ...
929 function ext_getTSCE_config($category) {
930 $catConf = $this->setup
['constants']['TSConstantEditor.'][$category . '.'];
932 if (is_array($catConf)) {
933 foreach ($catConf as $key => $val) {
936 $out['imagetag'] = $this->ext_getTSCE_config_image($catConf['image']);
944 if (t3lib_utility_Math
::canBeInterpretedAsInteger($key)) {
945 $constRefs = explode(',', $val);
946 foreach ($constRefs as $const) {
947 $const = trim($const);
948 if ($const && $const <= 20) {
949 $out['constants'][$const] .= $this->ext_getKeyImage($key);
957 $this->helpConfig
= $out;
961 * [Describe function...]
963 * @param [type] $key: ...
966 function ext_getKeyImage($key) {
967 return '<img src="' . $this->ext_localWebGfxPrefix
. 'gfx/' . $key . '.gif" align="top" hspace=2>';
971 * [Describe function...]
973 * @param [type] $imgConf: ...
976 function ext_getTSCE_config_image($imgConf) {
977 if (substr($imgConf, 0, 4) == 'gfx/') {
978 $iFile = $this->ext_localGfxPrefix
. $imgConf;
979 $tFile = $this->ext_localWebGfxPrefix
. $imgConf;
980 } elseif (substr($imgConf, 0, 4) == 'EXT:') {
981 $iFile = t3lib_div
::getFileAbsFileName($imgConf);
983 $f = substr($iFile, strlen(PATH_site
));
984 $tFile = $GLOBALS['BACK_PATH'] . '../' . $f;
987 $f = 'uploads/tf/' . $this->extractFromResources($this->setup
['resources'], $imgConf);
988 $iFile = PATH_site
. $f;
989 $tFile = $GLOBALS['BACK_PATH'] . '../' . $f;
991 $imageInfo = @getImagesize
($iFile);
992 return '<img src="' . $tFile . '" ' . $imageInfo[3] . '>';
996 * [Describe function...]
1000 function ext_resourceDims() {
1001 if ($this->setup
['resources']) {
1002 $rArr = explode(',', $this->setup
['resources']);
1003 foreach ($rArr as $c => $val) {
1005 $theFile = PATH_site
. 'uploads/tf/' . $val;
1006 if ($val && @is_file
($theFile)) {
1007 $imgInfo = @getimagesize
($theFile);
1009 if (is_array($imgInfo)) {
1010 $this->resourceDimensions
[$val] = ' (' . $imgInfo[0] . 'x' . $imgInfo[1] . ')';
1014 foreach ($this->dirResources
as $c => $val) {
1016 $imgInfo = @getimagesize
(PATH_site
. $val);
1017 if (is_array($imgInfo)) {
1018 $this->resourceDimensions
[$val] = ' (' . $imgInfo[0] . 'x' . $imgInfo[1] . ')';
1024 * [Describe function...]
1026 * @param [type] $path: ...
1027 * @return [type] ...
1029 function ext_readDirResources($path) {
1030 $path = trim($path);
1031 if ($path && strstr($path, $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'])) {
1032 $path = rtrim($path, '/');
1033 $this->readDirectory(PATH_site
. $path);
1038 * [Describe function...]
1040 * @param [type] $path: ...
1041 * @param [type] $type: ...
1042 * @return [type] ...
1044 function readDirectory($path, $type = 'file') {
1045 if (@is_dir
($path)) {
1047 $tempArray = Array();
1048 if (is_object($d)) {
1049 while ($entry = $d->read()) {
1050 if ($entry != '.' && $entry != '..') {
1051 $wholePath = $path . '/' . $entry; // Because of odd PHP-error where <BR>-tag is sometimes placed after a filename!!
1052 if (file_exists($wholePath) && (!$type ||
filetype($wholePath) == $type)) {
1053 $fI = t3lib_div
::split_fileref($wholePath);
1054 $this->dirResources
[] = substr($wholePath, strlen(PATH_site
));
1064 * [Describe function...]
1066 * @param [type] $params: ...
1067 * @return [type] ...
1069 function ext_fNandV($params) {
1070 $fN = 'data[' . $params['name'] . ']';
1071 $fV = $params['value'];
1072 if (preg_match('/^{[\$][a-zA-Z0-9\.]*}$/', trim($fV), $reg)) { // Values entered from the constantsedit cannot be constants! 230502; removed \{ and set {
1075 $fV = htmlspecialchars($fV);
1077 return array($fN, $fV, $params);
1081 * This functions returns the HTML-code that creates the editor-layout of the module.
1083 * @param [type] $theConstants: ...
1084 * @param [type] $category: ...
1085 * @return [type] ...
1087 function ext_printFields($theConstants, $category) {
1088 reset($theConstants);
1089 $output = '<script type="text/javascript" src="' . $GLOBALS['BACK_PATH'] . 'js/constantEditor.js"></script>
1092 if (is_array($this->categories
[$category])) {
1094 $help = $this->helpConfig
;
1095 $this->rArr
= explode(',', $this->setup
['resources'] . ',' . implode($this->dirResources
, ','));
1097 if (!$this->doNotSortCategoriesBeforeMakingForm
) {
1098 asort($this->categories
[$category]);
1100 foreach ($this->categories
[$category] as $name => $type) {
1101 $params = $theConstants[$name];
1102 if (is_array($params)) {
1103 if ($subcat != $params['subcat_name']) {
1104 $subcat = $params['subcat_name'];
1105 $subcat_name = $params['subcat_name'] ?
$this->subCategories
[$params['subcat_name']][0] : 'Others';
1107 $output .= '<h3 class="typo3-tstemplate-ceditor-subcat">' . $subcat_name . '</h3>';
1110 $label = $GLOBALS['LANG']->sL($params['label']);
1111 $label_parts = explode(':', $label, 2);
1112 if (count($label_parts) == 2) {
1113 $head = trim($label_parts[0]);
1114 $body = trim($label_parts[1]);
1116 $head = trim($label_parts[0]);
1119 if (strlen($head) > 35) {
1123 $head = t3lib_div
::fixed_lgd_cs($head, 35);
1125 $typeDat = $this->ext_getTypeData($params['type']);
1128 $raname = substr(md5($params['name']), 0, 10);
1129 $aname = '\'' . $raname . '\'';
1131 list($fN, $fV, $params) = $this->ext_fNandV($params);
1133 switch ($typeDat['type']) {
1136 $p_field = '<input id="' . $fN . '" type="text" name="' . $fN . '" value="' . $fV . '"' .
1137 $GLOBALS['TBE_TEMPLATE']->formWidth(5) . ' onChange="uFormUrl(' . $aname . ')" />';
1138 if ($typeDat['paramstr']) {
1139 $p_field .= ' Range: ' . $typeDat['paramstr'];
1140 } elseif ($typeDat['type'] == 'int+') {
1141 $p_field .= ' Range: 0 - ';
1143 $p_field .= ' (Integer)';
1147 $colorNames = explode(',', ',' . $this->HTMLcolorList
);
1149 foreach ($colorNames as $val) {
1151 if ($val == strtolower($params['value'])) {
1154 $p_field .= '<option value="' . htmlspecialchars($val) . '"' . $sel . '>' . $val . '</option>';
1156 $p_field = '<select id="select-' . $fN . '" rel="' . $fN . '" name="C' . $fN .
1157 '" class="typo3-tstemplate-ceditor-color-select" onChange="uFormUrl(' .
1158 $aname . ');">' . $p_field . '</select>';
1160 $p_field .= '<input type="text" id="input-' . $fN . '" rel="' . $fN . '" name="' . $fN .
1161 '" class="typo3-tstemplate-ceditor-color-input" value="' . $fV . '"' .
1162 $GLOBALS['TBE_TEMPLATE']->formWidth(7) . ' onChange="uFormUrl(' . $aname . ')" />';
1165 $wArr = explode('|', $fV);
1166 $p_field = '<input type="text" id="' . $fN . '" name="' . $fN . '" value="' . $wArr[0] . '"' .
1167 $GLOBALS['TBE_TEMPLATE']->formWidth(29) . ' onChange="uFormUrl(' . $aname . ')" />';
1169 $p_field .= '<input type="text" name="W' . $fN . '" value="' . $wArr[1] . '"' .
1170 $GLOBALS['TBE_TEMPLATE']->formWidth(15) . ' onChange="uFormUrl(' . $aname . ')" />';
1173 $wArr = explode(',', $fV);
1174 $labels = t3lib_div
::trimExplode(',', $typeDat['paramstr']);
1175 $p_field = ($labels[0] ?
$labels[0] : 'x') . ':<input type="text" name="' . $fN . '" value="' . $wArr[0] . '"' .
1176 $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' onChange="uFormUrl(' . $aname . ')" />';
1178 $p_field .= ($labels[1] ?
$labels[1] : 'y') . ':<input type="text" name="W' . $fN . '" value="' . $wArr[1] . '"' .
1179 $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' onChange="uFormUrl(' . $aname . ')" />';
1180 for ($aa = 2; $aa < count($labels); $aa++
) {
1182 $p_field .= ' , ' . $labels[$aa] . ':<input type="text" name="W' . $aa . $fN . '" value="' . $wArr[$aa] . '"' .
1183 $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' onChange="uFormUrl(' . $aname . ')" />';
1185 $p_field .= '<input type="hidden" name="W' . $aa . $fN . '" value="' . $wArr[$aa] . '" />';
1190 if (is_array($typeDat['params'])) {
1192 foreach ($typeDat['params'] as $val) {
1193 $vParts = explode('=', $val, 2);
1194 $label = $vParts[0];
1195 $val = isset($vParts[1]) ?
$vParts[1] : $vParts[0];
1199 if ($val == $params['value']) {
1202 $p_field .= '<option value="' . htmlspecialchars($val) . '"' . $sel . '>' . $GLOBALS['LANG']->sL($label) . '</option>';
1204 $p_field = '<select id="' . $fN . '" name="' . $fN . '" onChange="uFormUrl(' . $aname . ')">' . $p_field . '</select>';
1208 $p_field = '<input type="hidden" name="' . $fN . '" value="0" />';
1213 $p_field .= '<input id="' . $fN . '" type="checkbox" name="' . $fN . '" value="' . ($typeDat['paramstr'] ?
$typeDat['paramstr'] : 1) .
1214 '"' . $sel . ' onClick="uFormUrl(' . $aname . ')" />';
1217 $p_field = '<input type="hidden" name="' . $fN . '" value="#" />';
1222 $p_field .= '<input id="' . $fN . '" type="checkbox" name="' . $fN . '" value=""' . $sel . ' onClick="uFormUrl(' . $aname . ')" />';
1225 $p_field = '<option value=""></option>';
1227 $selectThisFile = $this->extractFromResources($this->setup
['resources'], $params['value']);
1228 if ($params['value'] && !$selectThisFile) {
1229 if (in_array($params['value'], $this->dirResources
)) {
1230 $selectThisFile = $params['value'];
1234 $extList = $typeDat['paramstr'];
1235 $p_field = '<option value="">(' . $extList . ')</option>';
1236 if ($extList == 'IMAGE_EXT') {
1237 $extList = $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'];
1239 $onlineResourceFlag = $this->ext_defaultOnlineResourceFlag
;
1241 foreach ($this->rArr
as $c => $val) {
1243 $fI = t3lib_div
::split_fileref($val);
1244 if ($val && (!$extList || t3lib_div
::inList($extList, $fI['fileext']))) {
1245 if ($onlineResourceFlag <= 0 && strstr($fI['path'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'])) {
1246 if ($onlineResourceFlag < 0) {
1247 $p_field .= '<option value=""></option>';
1249 $p_field .= '<option value="">__' . $fI['path'] . '__:</option>';
1250 $onlineResourceFlag = 1;
1252 $dims = $this->resourceDimensions
[$val];
1255 // Check if $params['value'] is in the list of resources.
1256 if ($selectThisFile && $selectThisFile == $val) {
1258 if ($onlineResourceFlag <= 0) {
1259 $theImage = t3lib_BEfunc
::thumbCode(
1261 'resources' => $selectThisFile
1265 $GLOBALS['BACK_PATH'],
1269 $theImage = t3lib_BEfunc
::thumbCode(
1271 'resources' => $fI['file']
1275 $GLOBALS['BACK_PATH'],
1282 if ($onlineResourceFlag <= 0) {
1283 $onlineResourceFlag--;
1284 // Value is set with a *
1285 $val = $this->ext_setStar($val);
1286 $p_field .= '<option value="' . htmlspecialchars($val) . '"' . $sel . '>' . $val . $dims . '</option>';
1288 $p_field .= '<option value="' . htmlspecialchars($val) . '"' . $sel . '>' . $fI['file'] . $dims . '</option>';
1293 if (trim($params['value']) && !$selectThisFile) {
1294 $val = $params['value'];
1295 $p_field .= '<option value=""></option>';
1296 $p_field .= '<option value="' . htmlspecialchars($val) . '" selected>' . $val . '</option>';
1299 $p_field = '<select id="' . $fN . '" name="' . $fN . '" onChange="uFormUrl(' . $aname . ')">' . $p_field . '</select>';
1300 $p_field .= $theImage;
1302 if (!$this->ext_noCEUploadAndCopying
) {
1304 $copyFile = $this->extractFromResources($this->setup
['resources'], $params['value']);
1306 if ($params['value']) {
1307 $copyFile = PATH_site
. $this->ext_detectAndFixExtensionPrefix($params['value']);
1313 if ($copyFile && @is_file
($copyFile)) {
1314 $p_field .= '<img src="clear.gif" width="20" ' . 'height="1" alt="" />' .
1315 t3lib_iconWorks
::getSpriteIcon('actions-edit-copy') . '<input type="checkbox" ' .
1316 'name="_copyResource[' . $params['name'] . ']" value="' . htmlspecialchars($copyFile) .
1317 '" onclick="uFormUrl(' . $aname . ');if (this.checked && !confirm(\'' .
1318 t3lib_div
::slashJS(htmlspecialchars(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_tsparser.xml:tsparser_ext.make_copy'), $params['value']))) .
1319 '\')) this.checked=false;" />';
1323 $p_field .= '<br />';
1324 $p_field .= '<input id="' . $fN . '" type="file" name="upload_' . $fN . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth() .
1325 ' onChange="uFormUrl(' . $aname . ')" size="50" />';
1329 $userFunction = $typeDat['paramstr'];
1330 $userFunctionParams = array('fieldName' => $fN, 'fieldValue' => $fV);
1331 $p_field = t3lib_div
::callUserFunction($userFunction, $userFunctionParams, $this, '');
1335 $fwidth = $typeDat['type'] == 'small' ?
10 : 46;
1336 $p_field = '<input id="' . $fN . '" type="text" name="' . $fN . '" value="' . $fV . '"' .
1337 $GLOBALS['TBE_TEMPLATE']->formWidth($fwidth) . ' onChange="uFormUrl(' . $aname . ')" />';
1341 // Define default names and IDs
1342 $userTyposcriptID = 'userTS-' . $params['name'];
1343 $defaultTyposcriptID = 'defaultTS-' . $params['name'];
1344 $checkboxName = 'check[' . $params['name'] . ']';
1345 $checkboxID = $checkboxName;
1347 // Handle type=color specially
1348 if ($typeDat['type'] == 'color' && substr($params['value'], 0, 2) != '{$') {
1349 $color = '<div id="colorbox-' . $fN . '" class="typo3-tstemplate-ceditor-colorblock" style="background-color:' .
1350 $params['value'] . ';"> </div>';
1355 if (!$this->ext_dontCheckIssetValues
) {
1357 /* Set the default styling options */
1358 if (isset($this->objReg
[$params['name']])) {
1359 $checkboxValue = 'checked';
1360 $userTyposcriptStyle = '';
1361 $defaultTyposcriptStyle = 'style="display:none;"';
1363 $checkboxValue = '';
1364 $userTyposcriptStyle = 'style="display:none;"';
1365 $defaultTyposcriptStyle = '';
1369 $deleteIconHTML = t3lib_iconWorks
::getSpriteIcon(
1370 'actions-edit-undo',
1372 'class' => "typo3-tstemplate-ceditor-control undoIcon",
1373 'alt' => "Revert to default Constant",
1374 'title' => "Revert to default Constant",
1375 'rel' => $params['name']
1378 $editIconHTML = t3lib_iconWorks
::getSpriteIcon(
1379 'actions-document-open',
1381 'class' => "typo3-tstemplate-ceditor-control editIcon",
1382 'alt' => "Edit this Constant",
1383 'title' => "Edit this Constant",
1384 'rel' => $params['name']
1387 $constantCheckbox = '<input type="hidden" name="' . $checkboxName . '" id="' . $checkboxID . '" value="' . $checkboxValue . '"/>';
1389 // If there's no default value for the field, use a static label.
1390 if (!$params['default_value']) {
1391 $params['default_value'] = '[Empty]';
1394 $constantDefaultRow = '<div class="typo3-tstemplate-ceditor-row" id="' . $defaultTyposcriptID . '" ' .
1395 $defaultTyposcriptStyle . '>' . $editIconHTML .
1396 htmlspecialchars($params['default_value']) . $color . '</div>';
1399 $constantEditRow = '<div class="typo3-tstemplate-ceditor-row" id="' . $userTyposcriptID . '" ' .
1400 $userTyposcriptStyle . '>' . $deleteIconHTML . $p_field . $color . '</div>';
1402 $constantLabel = '<dt class="typo3-tstemplate-ceditor-label">' . htmlspecialchars($head) . '</dt>';
1403 $constantName = '<dt class="typo3-dimmed">[' . $params['name'] . ']</dt>';
1404 $constantDescription = $body ?
'<dd>' . htmlspecialchars($body) . '</dd>' : '';
1405 $constantData = '<dd>' . $constantCheckbox . $constantEditRow . $constantDefaultRow . '</dd>';
1407 $output .= '<a name="' . $raname . '"></a>' . $help['constants'][$params['name']];
1408 $output .= '<dl class="typo3-tstemplate-ceditor-constant">' . $constantLabel . $constantName .
1409 $constantDescription . $constantData . '</dl>';
1411 debug('Error. Constant did not exist. Should not happen.');
1419 /***************************
1421 * Processing input values
1423 ***************************/
1426 * @param [type] $constants: ...
1427 * @return [type] ...
1429 function ext_regObjectPositions($constants) {
1430 // This runs through the lines of the constants-field of the active template and registers the constants-names
1431 // and linepositions in an array, $this->objReg
1432 $this->raw
= explode(LF
, $constants);
1435 $this->objReg
= array(); // resetting the objReg if the divider is found!!
1436 $this->ext_regObjects('');
1440 * [Describe function...]
1442 * @param [type] $pre: ...
1443 * @return [type] ...
1445 function ext_regObjects($pre) {
1446 // works with regObjectPositions. "expands" the names of the TypoScript objects
1447 while (isset($this->raw
[$this->rawP
])) {
1448 $line = ltrim($this->raw
[$this->rawP
]);
1449 if (strstr($line, $this->edit_divider
)) {
1450 $this->objReg
= array(); // resetting the objReg if the divider is found!!
1454 if (substr($line, 0, 1) == '[') {
1456 } elseif (strcspn($line, '}#/') != 0) {
1457 $varL = strcspn($line, ' {=<');
1458 $var = substr($line, 0, $varL);
1459 $line = ltrim(substr($line, $varL));
1460 switch (substr($line, 0, 1)) {
1462 $this->objReg
[$pre . $var] = $this->rawP
- 1;
1465 $this->ext_inBrace++
;
1466 $this->ext_regObjects($pre . $var . '.');
1469 $this->lastComment
= '';
1470 } elseif (substr($line, 0, 1) == '}') {
1471 $this->lastComment
= '';
1472 $this->ext_inBrace
--;
1473 if ($this->ext_inBrace
< 0) {
1474 $this->ext_inBrace
= 0;
1484 * [Describe function...]
1486 * @param [type] $key: ...
1487 * @param [type] $var: ...
1488 * @return [type] ...
1490 function ext_putValueInConf($key, $var) {
1491 // Puts the value $var to the TypoScript value $key in the current lines of the templates.
1492 // If the $key is not found in the template constants field, a new line is inserted in the bottom.
1493 $theValue = ' ' . trim($var);
1494 if (isset($this->objReg
[$key])) {
1495 $lineNum = $this->objReg
[$key];
1496 $parts = explode('=', $this->raw
[$lineNum], 2);
1497 if (count($parts) == 2) {
1498 $parts[1] = $theValue;
1500 $this->raw
[$lineNum] = implode($parts, '=');
1502 $this->raw
[] = $key . ' =' . $theValue;
1508 * [Describe function...]
1510 * @param [type] $key: ...
1511 * @return [type] ...
1513 function ext_removeValueInConf($key) {
1514 // Removes the value in the configuration
1515 if (isset($this->objReg
[$key])) {
1516 $lineNum = $this->objReg
[$key];
1517 unset($this->raw
[$lineNum]);
1523 * [Describe function...]
1525 * @param [type] $arr: ...
1526 * @param [type] $settings: ...
1527 * @return [type] ...
1529 function ext_depthKeys($arr, $settings) {
1530 $tsbrArray = array();
1531 foreach ($arr as $theK => $theV) {
1532 $theKeyParts = explode('.', $theK);
1534 $c = count($theKeyParts);
1536 foreach ($theKeyParts as $p) {
1538 $depth .= ($depth ?
'.' : '') . $p;
1539 $tsbrArray[$depth] = ($c == $a) ?
$theV : 1;
1543 foreach ($tsbrArray as $theK => $theV) {
1545 $settings[$theK] = 1;
1547 unset($settings[$theK]);
1554 * [Describe function...]
1556 * @param [type] $http_post_vars: ...
1557 * @param [type] $http_post_files: ...
1558 * @param [type] $theConstants: ...
1559 * @param [type] $tplRow: ...
1560 * @return [type] ...
1562 function ext_procesInput($http_post_vars, $http_post_files, $theConstants, $tplRow) {
1563 $data = $http_post_vars['data'];
1564 $check = $http_post_vars['check'];
1565 $copyResource = $http_post_vars['_copyResource'];
1566 $Wdata = $http_post_vars['Wdata'];
1567 $W2data = $http_post_vars['W2data'];
1568 $W3data = $http_post_vars['W3data'];
1569 $W4data = $http_post_vars['W4data'];
1570 $W5data = $http_post_vars['W5data'];
1572 if (is_array($data)) {
1573 foreach ($data as $key => $var) {
1574 if (isset($theConstants[$key])) {
1575 if ($this->ext_dontCheckIssetValues ||
isset($check[$key])) { // If checkbox is set, update the value
1576 list($var) = explode(LF
, $var); // exploding with linebreak, just to make sure that no multiline input is given!
1577 $typeDat = $this->ext_getTypeData($theConstants[$key]['type']);
1578 switch ($typeDat['type']) {
1580 if ($typeDat['paramstr']) {
1581 $var = t3lib_utility_Math
::forceIntegerInRange($var, $typeDat['params'][0], $typeDat['params'][1]);
1583 $var = intval($var);
1587 $var = max(0, intval($var));
1591 if ($var && !t3lib_div
::inList($this->HTMLcolorList
, strtolower($var))) {
1592 $var = preg_replace('/[^A-Fa-f0-9]*/', '', $var);
1593 $useFullHex = strlen($var) > 3;
1595 $col[] = HexDec(substr($var, 0, 1));
1596 $col[] = HexDec(substr($var, 1, 1));
1597 $col[] = HexDec(substr($var, 2, 1));
1600 $col[] = HexDec(substr($var, 3, 1));
1601 $col[] = HexDec(substr($var, 4, 1));
1602 $col[] = HexDec(substr($var, 5, 1));
1605 $var = substr('0' . DecHex($col[0]), -1) . substr('0' . DecHex($col[1]), -1) . substr('0' . DecHex($col[2]), -1);
1607 $var .= substr('0' . DecHex($col[3]), -1) . substr('0' . DecHex($col[4]), -1) . substr('0' . DecHex($col[5]), -1);
1610 $var = '#' . strtoupper($var);
1621 if (isset($Wdata[$key])) {
1622 $var .= '|' . $Wdata[$key];
1626 if (isset($Wdata[$key])) {
1627 $var = intval($var) . ',' . intval($Wdata[$key]);
1628 if (isset($W2data[$key])) {
1629 $var .= ',' . intval($W2data[$key]);
1630 if (isset($W3data[$key])) {
1631 $var .= ',' . intval($W3data[$key]);
1632 if (isset($W4data[$key])) {
1633 $var .= ',' . intval($W4data[$key]);
1634 if (isset($W5data[$key])) {
1635 $var .= ',' . intval($W5data[$key]);
1644 $var = $typeDat['paramstr'] ?
$typeDat['paramstr'] : 1;
1648 if (!$this->ext_noCEUploadAndCopying
) {
1649 if ($http_post_files['upload_data']['name'][$key] && $http_post_files['upload_data']['tmp_name'][$key] != 'none') {
1650 $var = $this->upload_copy_file(
1653 trim($http_post_files['upload_data']['name'][$key]),
1654 $http_post_files['upload_data']['tmp_name'][$key]
1657 if ($copyResource[$key]) {
1658 $var = $this->upload_copy_file(
1661 basename($copyResource[$key]),
1668 if ($this->ext_printAll ||
strcmp($theConstants[$key]['value'], $var)) {
1669 $this->ext_putValueInConf($key, $var); // Put value in, if changed.
1671 unset($check[$key]); // Remove the entry because it has been "used"
1673 $this->ext_removeValueInConf($key);
1678 // 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...
1679 if (!$this->ext_dontCheckIssetValues
&& is_array($check)) {
1680 foreach ($check as $key => $var) {
1681 if (isset($theConstants[$key])) {
1682 $dValue = $theConstants[$key]['default_value'];
1683 $this->ext_putValueInConf($key, $dValue);
1690 * [Describe function...]
1692 * @param [type] $typeDat: ...
1693 * @param [type] $tplRow: ...
1694 * @param [type] $theRealFileName: ...
1695 * @param [type] $tmp_name: ...
1696 * @return [type] ...
1698 function upload_copy_file($typeDat, &$tplRow, $theRealFileName, $tmp_name) {
1701 $extList = $typeDat['paramstr'];
1702 if ($extList == 'IMAGE_EXT') {
1703 $extList = $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'];
1705 $fI = t3lib_div
::split_fileref($theRealFileName);
1706 if ($theRealFileName && (!$extList || t3lib_div
::inList($extList, $fI['fileext']))) {
1707 $tmp_upload_name = t3lib_div
::upload_to_tempfile($tmp_name); // If there is an uploaded file, move it.
1710 $alternativeFileName = array();
1711 $alternativeFileName[$tmp_upload_name] = $theRealFileName;
1712 // Making list of resources
1713 $resList = $tplRow['resources'];
1714 $resList = $tmp_upload_name . ',' . $resList;
1715 $resList = implode(t3lib_div
::trimExplode(',', $resList, 1), ',');
1716 // Making data-array
1717 $saveId = $tplRow['_ORIG_uid'] ?
$tplRow['_ORIG_uid'] : $tplRow['uid'];
1720 $recData['sys_template'][$saveId]['resources'] = $resList;
1722 $tce = t3lib_div
::makeInstance('t3lib_TCEmain');
1723 $tce->stripslashes_values
= 0;
1724 $tce->alternativeFileName
= $alternativeFileName;
1725 $tce->start($recData, Array());
1726 $tce->process_datamap();
1728 t3lib_div
::unlink_tempfile($tmp_upload_name);
1730 $tmpRow = t3lib_BEfunc
::getRecordWSOL('sys_template', $saveId, 'resources');
1732 $tplRow['resources'] = $tmpRow['resources'];
1734 // Setting the value
1735 $var = $this->ext_setStar($theRealFileName);
1741 * [Describe function...]
1743 * @param [type] $id: ...
1744 * @param [type] $perms_clause: ...
1745 * @return [type] ...
1747 function ext_prevPageWithTemplate($id, $perms_clause) {
1748 $rootLine = t3lib_BEfunc
::BEgetRootLine($id, $perms_clause ?
' AND ' . $perms_clause : '');
1749 foreach ($rootLine as $p) {
1750 if ($this->ext_getFirstTemplate($p['uid'])) {
1757 * [Describe function...]
1759 * @param [type] $val: ...
1760 * @return [type] ...
1762 function ext_setStar($val) {
1763 $fParts = explode('.', strrev($val), 2);
1764 $val = preg_replace('/_[0-9][0-9]$/', '', strrev($fParts[1])) . '*.' . strrev($fParts[0]);
1769 * [Describe function...]
1771 * @param [type] $value: ...
1772 * @return [type] ...
1774 function ext_detectAndFixExtensionPrefix($value) {
1775 if (substr($value, 0, 4) == 'EXT:') {
1776 $parts = explode('/', substr($value, 4), 2);
1778 $extPath = t3lib_extMgm
::siteRelPath($parts[0]);
1779 $value = $extPath . $parts[1];
1788 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php'])) {
1789 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php']);