2 /***************************************************************
5 * (c) 1999-2008 Kasper Skaarhoj (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
31 * Contains functions for the TS module in TYPO3 backend
33 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
36 * [CLASS/FUNCTION INDEX of SCRIPT]
40 * 105: class t3lib_tsparser_ext extends t3lib_TStemplate
41 * 191: function flattenSetup($setupArray, $prefix, $resourceFlag)
42 * 218: function substituteConstants($all)
43 * 231: function substituteConstantsCallBack($matches)
44 * 261: function substituteCMarkers($all)
45 * 284: function generateConfig_constants()
46 * 330: function ext_getSetup($theSetup,$theKey)
47 * 358: function ext_getObjTree($arr, $depth_in, $depthData, $parentType='',$parentValue='', $alphaSort='0')
48 * 463: function lineNumberToScript($lnArr)
49 * 494: function makeHtmlspecialchars($theValue)
50 * 507: function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray)
51 * 562: function ext_getRootlineNumber($pid)
52 * 580: function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0)
53 * 639: function ext_process_hierarchyInfo($depthDataArr,&$pointer)
54 * 670: function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0)
55 * 697: function ext_fixed_lgd($string,$chars)
56 * 713: function ext_lnBreakPointWrap($ln,$str)
57 * 726: function ext_formatTS($input, $ln, $comments=1, $crop=0)
58 * 765: function ext_getFirstTemplate($id,$template_uid=0)
59 * 785: function ext_getAllTemplates($id)
60 * 806: function ext_compareFlatSetups($default)
61 * 872: function ext_categorizeEditableConstants($editConstArray)
62 * 895: function ext_getCategoryLabelArray()
63 * 912: function ext_getTypeData($type)
64 * 953: function ext_getTSCE_config($category)
65 * 992: function ext_getKeyImage($key)
66 * 1002: function ext_getTSCE_config_image($imgConf)
67 * 1026: function ext_resourceDims()
68 * 1056: function ext_readDirResources($path)
69 * 1071: function readDirectory($path,$type='file')
70 * 1096: function ext_fNandV($params)
71 * 1114: function ext_printFields($theConstants,$category)
73 * SECTION: Processing input values
74 * 1408: function ext_regObjectPositions($constants)
75 * 1423: function ext_regObjects($pre)
76 * 1468: function ext_putValueInConf($key, $var)
77 * 1491: function ext_removeValueInConf($key)
78 * 1507: function ext_depthKeys($arr,$settings)
79 * 1542: function ext_procesInput($http_post_vars,$http_post_files,$theConstants,$tplRow)
80 * 1666: function upload_copy_file($typeDat,&$tplRow,$theRealFileName,$tmp_name)
81 * 1715: function ext_prevPageWithTemplate($id,$perms_clause)
82 * 1731: function ext_setStar($val)
83 * 1743: function ext_detectAndFixExtensionPrefix($value)
86 * (This index is automatically created/updated by the extension "extdeveval")
90 require_once(PATH_t3lib
.'class.t3lib_tstemplate.php');
99 * TSParser extension class to t3lib_TStemplate
101 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
105 class t3lib_tsparser_ext
extends t3lib_TStemplate
{
107 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.
108 var $HTMLcolorList = 'aqua,beige,black,blue,brown,fuchsia,gold,gray,green,lime,maroon,navy,olive,orange,purple,red,silver,tan,teal,turquoise,yellow,white';
111 var $categories = array(
112 '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.
113 'menu' => array(), // Menu setup. This includes fontfiles, sizes, background images. Depending on the menutype.
114 'content' => array(), // All constants related to the display of pagecontent elements
115 'page' => array(), // General configuration like metatags, link targets
116 'advanced' => array(), // Advanced functions, which are used very seldomly.
117 'all' => array() // All constants are put here also!
118 ); // This will be filled with the available categories of the current template.
119 var $subCategories = array(
120 // Standard categories:
121 'enable' => Array('Enable features', 'a'),
122 'dims' => Array('Dimensions, widths, heights, pixels', 'b'),
123 'file' => Array('Files', 'c'),
124 'typo' => Array('Typography', 'd'),
125 'color' => Array('Colors', 'e'),
126 'links' => Array('Links and targets', 'f'),
127 'language' => Array('Language specific constants', 'g'),
129 // subcategories based on the default content elements
130 'cheader' => Array('Content: \'Header\'', 'ma'),
131 'cheader_g' => Array('Content: \'Header\', Graphical', 'ma'),
132 'ctext' => Array('Content: \'Text\'', 'mb'),
133 'cimage' => Array('Content: \'Image\'', 'md'),
134 'cbullets' => Array('Content: \'Bullet list\'', 'me'),
135 'ctable' => Array('Content: \'Table\'', 'mf'),
136 'cuploads' => Array('Content: \'Filelinks\'', 'mg'),
137 'cmultimedia' => Array('Content: \'Multimedia\'', 'mh'),
138 'cmailform' => Array('Content: \'Form\'', 'mi'),
139 'csearch' => Array('Content: \'Search\'', 'mj'),
140 'clogin' => Array('Content: \'Login\'', 'mk'),
141 'csplash' => Array('Content: \'Textbox\'', 'ml'),
142 'cmenu' => Array('Content: \'Menu/Sitemap\'', 'mm'),
143 'cshortcut' => Array('Content: \'Insert records\'', 'mn'),
144 'clist' => Array('Content: \'List of records\'', 'mo'),
145 'cscript' => Array('Content: \'Script\'', 'mp'),
146 'chtml' => Array('Content: \'HTML\'', 'mq')
148 var $resourceDimensions = array();
149 var $dirResources = array();
157 var $tsbrowser_searchKeys = array();
158 var $tsbrowser_depthKeys = array();
159 var $constantMode='';
162 var $resourceCheck=0;
163 var $ext_lineNumberOffset=0;
164 var $ext_localGfxPrefix='';
165 var $ext_localWebGfxPrefix='';
166 var $ext_expandAllNotes=0;
167 var $ext_noPMicons=0;
168 var $ext_noSpecialCharsOnLabels=0;
169 var $ext_listOfTemplatesArr=array();
170 var $ext_lineNumberOffset_mode='';
171 var $ext_dontCheckIssetValues=0; // Dont change...
172 var $ext_noCEUploadAndCopying=0;
174 var $ext_CEformName='forms[0]';
175 var $ext_defaultOnlineResourceFlag=0;
176 var $doNotSortCategoriesBeforeMakingForm = FALSE;
179 var $templateTitles=array();
183 * This flattens a hierarchical setuparray to $this->flatSetup
184 * The original function fetched the resource-file if any ('file.'). This functions doesn't.
186 * @param [type] $setupArray: ...
187 * @param [type] $prefix: ...
188 * @param [type] $resourceFlag: ...
191 function flattenSetup($setupArray, $prefix, $resourceFlag) {
192 if (is_array($setupArray)) {
193 $this->getFileName_backPath
=PATH_site
; // Setting absolute prefixed path for relative resources.
195 while(list($key,$val)=each($setupArray)) {
196 if ($prefix ||
substr($key,0,16)!='TSConstantEditor') { // We don't want 'TSConstantEditor' in the flattend setup.
197 if (is_array($val)) {
198 $this->flattenSetup($val,$prefix.$key, ($key=='file.'));
199 } elseif ($resourceFlag && $this->resourceCheck
) {
200 $this->flatSetup
[$prefix.$key] = $this->getFileName($val);
201 if ($this->removeFromGetFilePath
&& substr($this->flatSetup
[$prefix.$key],0,strlen($this->removeFromGetFilePath
))==$this->removeFromGetFilePath
) {
202 $this->flatSetup
[$prefix.$key] = substr($this->flatSetup
[$prefix.$key],strlen($this->removeFromGetFilePath
));
205 $this->flatSetup
[$prefix.$key] = $val;
213 * [Describe function...]
215 * @param [type] $all: ...
218 function substituteConstants($all) {
219 $this->Cmarker
= substr(md5(uniqid('')),0,6);
221 return preg_replace_callback('/\{\$(.[^}]+)\}/', array($this, 'substituteConstantsCallBack'), $all);
225 * Call back method for preg_replace_callback in substituteConstants
227 * @param array Regular expression matches
228 * @return string Replacement
229 * @see substituteConstants()
231 function substituteConstantsCallBack($matches) {
232 switch($this->constantMode
) {
234 $ret_val = isset($this->flatSetup
[$matches[1]]) && !is_array($this->flatSetup
[$matches[1]]) ?
235 '##'.$this->Cmarker
.'_B##'.$matches[0].'##'.$this->Cmarker
.'_E##' :
239 $ret_val = isset($this->flatSetup
[$matches[1]]) && !is_array($this->flatSetup
[$matches[1]]) ?
240 '##'.$this->Cmarker
.'_B##'.$this->flatSetup
[$matches[1]].'##'.$this->Cmarker
.'_E##' :
244 $ret_val = $matches[0];
247 $ret_val = isset($this->flatSetup
[$matches[1]]) && !is_array($this->flatSetup
[$matches[1]]) ?
248 $this->flatSetup
[$matches[1]] :
256 * [Describe function...]
258 * @param [type] $all: ...
261 function substituteCMarkers($all) {
262 switch($this->constantMode
) {
264 $all = str_replace('##'.$this->Cmarker
.'_B##', '<font color="green"><B>', $all);
265 $all = str_replace('##'.$this->Cmarker
.'_E##', '</b></font>', $all);
268 $all = str_replace('##'.$this->Cmarker
.'_B##', '<font color="green"><B>', $all);
269 $all = str_replace('##'.$this->Cmarker
.'_E##', '</b></font>', $all);
279 * Parses the constants in $this->const with respect to the constant-editor in this module.
280 * In particular comments in the code are registered and the edit_divider is taken into account.
284 function generateConfig_constants() {
285 // These vars are also set lateron...
286 $this->setup
['resources'] = $this->resources
;
287 $this->setup
['sitetitle'] = $this->sitetitle
;
290 $constants = t3lib_div
::makeInstance('t3lib_TSparser');
291 $constants->regComments
=1; // Register comments!
292 $constants->setup
= $this->const;
293 $constants->setup
= $this->mergeConstantsFromPageTSconfig($constants->setup
);
295 $matchObj = t3lib_div
::makeInstance('t3lib_matchCondition');
296 $matchObj->matchAll
=1; // Matches ALL conditions in TypoScript
299 $cc=count($this->constants
);
300 reset($this->constants
);
301 while (list(,$str)=each($this->constants
)) {
304 if (strstr($str,$this->edit_divider
)) {
305 $parts = explode($this->edit_divider
,$str,2);
307 $constants->parse($parts[0],$matchObj);
309 $this->flatSetup
= Array();
310 $this->flattenSetup($constants->setup
,'','');
311 $defaultConstants=$this->flatSetup
;
313 $constants->parse($str,$matchObj);
316 $this->flatSetup
= Array();
317 $this->flattenSetup($constants->setup
,'','');
318 $this->setup
['constants'] = $constants->setup
;
320 return $this->ext_compareFlatSetups($defaultConstants);
324 * [Describe function...]
326 * @param [type] $theSetup: ...
327 * @param [type] $theKey: ...
330 function ext_getSetup($theSetup,$theKey) {
331 $parts = explode('.',$theKey,2);
332 if (strcmp($parts[0],'') && is_array($theSetup[$parts[0].'.'])) {
333 if (strcmp(trim($parts[1]),'')) {
334 return $this->ext_getSetup($theSetup[$parts[0].'.'],trim($parts[1]));
336 return array($theSetup[$parts[0].'.'], $theSetup[$parts[0]]);
339 if (strcmp(trim($theKey),'')) {
340 return array(array(),$theSetup[$theKey]);
342 return array($theSetup,'');
348 * [Describe function...]
350 * @param [type] $arr: ...
351 * @param [type] $depth_in: ...
352 * @param [type] $depthData: ...
353 * @param [type] $parentType: ...
354 * @param [type] $parentValue: ...
355 * @param boolean $alphaSort sorts the array keys / tree by alphabet when set to 1
358 function ext_getObjTree($arr, $depth_in, $depthData, $parentType='',$parentValue='', $alphaSort='0') {
363 if($alphaSort == '1') {
367 $keyArr_alpha=array();
368 while (list($key,)=each($arr)) {
369 if (substr($key,-2)!='..') { // Don't do anything with comments / linenumber registrations...
370 $key=ereg_replace('\.$','',$key);
371 if (substr($key,-1)!='.') {
372 if (t3lib_div
::testInt($key)) {
373 $keyArr_num[$key]=$arr[$key];
375 $keyArr_alpha[$key]=$arr[$key];
381 $keyArr=$keyArr_num+
$keyArr_alpha;
384 if ($depth_in) {$depth_in = $depth_in.'.';}
386 while (list($key,)=each($keyArr)) {
388 $depth=$depth_in.$key;
389 if ($this->bType
!='const' ||
substr($depth,0,1)!='_') { // this excludes all constants starting with '_' from being shown.
390 $goto = substr(md5($depth),0,6);
391 $deeper = (is_array($arr[$key.'.']) && ($this->tsbrowser_depthKeys
[$depth] ||
$this->ext_expandAllNotes
)) ?
1 : 0;
393 $LN = ($a==$c)?
'blank':'line';
394 $BTM = ($a==$c)?
'bottom':'';
395 $PM = is_array($arr[$key.'.']) && !$this->ext_noPMicons ?
($deeper ?
'minus':'plus') : 'join';
398 $theIcon='<img src="'.$GLOBALS['BACK_PATH'].'gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border="0" alt="" />';
402 $aHref='index.php?id='.$GLOBALS['SOBE']->id
.'&tsbr['.$depth.']='.($deeper?
0:1).'#'.$goto;
403 $HTML.='<a name="'.$goto.'" href="'.htmlspecialchars($aHref).'">'.$theIcon.'</a>';
407 if (t3lib_div
::inList('types,resources,sitetitle',$depth) && $this->bType
=='setup') { // Read only...
408 $label='<font color="#666666">'.$label.'</font>';
410 if ($this->linkObjects
) {
411 $aHref = 'index.php?id='.$GLOBALS['SOBE']->id
.'&sObj='.$depth;
412 if ($this->bType
!='const') {
413 $ln = is_array($arr[$key.'.ln..']) ?
'Defined in: '.$this->lineNumberToScript($arr[$key.'.ln..']) : 'N/A';
418 if ($this->tsbrowser_searchKeys
[$depth] & 4) { $label = '<b><font color="red">'.$label.'</font></b>'; } // The key has matched the search string
419 $label = '<a href="'.htmlspecialchars($aHref).'" title="'.htmlspecialchars($ln).'">'.$label.'</a>';
423 $HTML.='['.$label.']';
425 if (isset($arr[$key])) {
426 $theValue = $arr[$key];
427 if ($this->fixedLgd
) {
428 $imgBlocks = ceil(1+
strlen($depthData)/77);
429 $lgdChars = 68-ceil(strlen('['.$key.']')*0.8)-$imgBlocks*3;
430 $theValue = $this->ext_fixed_lgd($theValue,$lgdChars);
432 if ($this->tsbrowser_searchKeys
[$depth] & 2) { // The value has matched the search string
433 $HTML.=' = <b><font color="red">'.$this->makeHtmlspecialchars($theValue).'</font></b>';
435 $HTML.=' = <b>'.$this->makeHtmlspecialchars($theValue).'</b>';
437 if ($this->ext_regComments
&& isset($arr[$key.'..'])) {
438 $comment = $arr[$key.'..'];
439 if (!preg_match('/### <INCLUDE_TYPOSCRIPT:.*/', $comment)) { // Skip INCLUDE_TYPOSCRIPT comments, they are almost useless
440 $comment = preg_replace('/[\r\n]/', ' ', $comment); // Remove linebreaks, replace with ' '
441 $comment = preg_replace('/[#\*]{2,}/', '', $comment); // Remove # and * if more than twice in a row
442 $comment = preg_replace('/^[#\*\s]+/', '# ', $comment); // Replace leading # (just if it exists) and add it again. Result: Every comment should be prefixed by a '#'.
443 $HTML.= ' <span class="comment">'.trim($comment).'</span>';
450 $HTML.=$this->ext_getObjTree($arr[$key.'.'], $depth, $depthData.'<img src="'.$GLOBALS['BACK_PATH'].'gfx/ol/'.$LN.'.gif" width="18" height="16" align="top" alt="" />', '' /* not used: $validate_info[$key] */, $arr[$key], $alphaSort);
458 * [Describe function...]
460 * @param [type] $lnArr: ...
463 function lineNumberToScript($lnArr) {
464 if (!is_array($this->lnToScript
)) {
465 $this->lnToScript
= array();
467 $c+
=substr_count($GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'],chr(10))+
2;
468 $this->lnToScript
[$c] = '[Default]';
470 foreach($this->hierarchyInfoToRoot
as $info) {
471 $c+
=$info['configLines']+
1;
472 $this->lnToScript
[$c] = $info['title'];
476 foreach($lnArr as $k => $ln) {
477 foreach($this->lnToScript
as $endLn => $title) {
478 if ($endLn >= intval($ln)) {
479 $lnArr[$k] = '"'.$title.'", '.$ln;
485 return implode('; ',$lnArr);
489 * [Describe function...]
491 * @param [type] $theValue: ...
494 function makeHtmlspecialchars($theValue){
495 return $this->ext_noSpecialCharsOnLabels ?
$theValue : htmlspecialchars($theValue);
499 * [Describe function...]
501 * @param [type] $arr: ...
502 * @param [type] $depth_in: ...
503 * @param [type] $searchString: ...
504 * @param [type] $keyArray: ...
507 function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray) {
510 while (list($key,)=each($arr)) {
511 $key=ereg_replace('\.$','',$key);
512 if (substr($key,-1)!='.') {
518 if ($depth_in) { $depth_in = $depth_in.'.'; }
519 while (list($key,)=each($keyArr)) {
520 $depth=$depth_in.$key;
521 $deeper = is_array($arr[$key.'.']);
523 if ($this->regexMode
) {
524 if (ereg($searchString,$arr[$key])) { // The value has matched
525 $this->tsbrowser_searchKeys
[$depth]+
=2;
527 if (ereg($searchString,$key)) { // The key has matched
528 $this->tsbrowser_searchKeys
[$depth]+
=4;
530 if (ereg($searchString,$depth_in)) { // Just open this subtree if the parent key has matched the search
531 $this->tsbrowser_searchKeys
[$depth]=1;
534 if (stristr($arr[$key],$searchString)) { // The value has matched
535 $this->tsbrowser_searchKeys
[$depth]+
=2;
537 if (stristr($key,$searchString)) { // The key has matches
538 $this->tsbrowser_searchKeys
[$depth]+
=4;
540 if (stristr($depth_in,$searchString)) { // Just open this subtree if the parent key has matched the search
541 $this->tsbrowser_searchKeys
[$depth]=1;
546 $cS = count($this->tsbrowser_searchKeys
);
547 $keyArray = $this->ext_getSearchKeys($arr[$key.'.'], $depth, $searchString, $keyArray);
548 if ($cS != count($this->tsbrowser_searchKeys
)) {
557 * [Describe function...]
559 * @param [type] $pid: ...
562 function ext_getRootlineNumber($pid) {
563 if ($pid && is_array($GLOBALS['rootLine'])) {
564 reset($GLOBALS['rootLine']);
565 while(list($key,$val)=each($GLOBALS['rootLine'])) {
566 if ($val['uid']==$pid) return $key;
572 * [Describe function...]
574 * @param [type] $arr: ...
575 * @param [type] $depthData: ...
576 * @param [type] $keyArray: ...
577 * @param [type] $first: ...
580 function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0) {
583 while (list($key,)=each($arr)) {
584 $key=ereg_replace('\.$','',$key);
585 if (substr($key,-1)!='.') {
592 while (list($key,)=each($keyArr)) {
595 $deeper = is_array($arr[$key.'.']);
599 $LN = ($a==$c)?
'blank':'line';
600 $BTM = ($a==$c)?
'top':'';
604 $icon = substr($row['templateID'],0,3)=='sys' ? t3lib_iconWorks
::getIcon('sys_template',array('root'=>$row['root'])) :
605 (substr($row['templateID'],0,6)=='static' ? t3lib_iconWorks
::getIcon('static_template',array()) : 'gfx/i/default.gif');
606 $alttext= '['.$row['templateID'].']';
607 $alttext.= $row['pid'] ?
' - '.t3lib_BEfunc
::getRecordPath($row['pid'],$GLOBALS['SOBE']->perms_clause
,20) : '';
608 if (in_array($row['templateID'],$this->clearList_const
) ||
in_array($row['templateID'],$this->clearList_setup
)) {
609 $A_B='<a href="index.php?id='.$GLOBALS['SOBE']->id
.'&template='.$row['templateID'].'">';
615 $HTML.=($first?
'':'<IMG src="'.$GLOBALS['BACK_PATH'].'gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border=0>').'<IMG src="'.$GLOBALS['BACK_PATH'].$icon.'" width="18" height="16" align="top" title="'.$alttext.'">'.$A_B.t3lib_div
::fixed_lgd_cs($row['title'],$GLOBALS['BE_USER']->uc
['titleLen']).$A_E.' ';
616 $RL = $this->ext_getRootlineNumber($row['pid']);
618 <td nowrap>'.$HTML.'</td>
619 <td align=center>'.($row['root']?
'<b>X</b>':'').' </td>
620 <td align=center'.$row['bgcolor_setup'].'>'.fw(($row['clConf']?
'<b>X</b>':'').' ').'</td>
621 <td align=center'.$row['bgcolor_const'].'>'.fw(($row['clConst']?
'<b>X</b>':'').' ').'</td>
622 <td>'.($row['pid']?
' '.$row['pid'].(strcmp($RL,'')?
' ('.$RL.')':'').' ':'').'</td>
623 <td>'.($row['next']?
' '.$row['next'].' ':'').'</td>
626 $keyArray = $this->ext_getTemplateHierarchyArr($arr[$key.'.'], $depthData.($first?
'':'<IMG src="'.$GLOBALS['BACK_PATH'].'gfx/ol/'.$LN.'.gif" width="18" height="16" align="top">'), $keyArray);
633 * [Describe function...]
635 * @param [type] $depthDataArr: ...
636 * @param [type] $pointer: ...
639 function ext_process_hierarchyInfo($depthDataArr,&$pointer) {
640 $parent = $this->hierarchyInfo
[$pointer-1]['templateParent'];
641 while ($pointer>0 && $this->hierarchyInfo
[$pointer-1]['templateParent']==$parent) {
643 $row = $this->hierarchyInfo
[$pointer];
645 $depthDataArr[$row['templateID']]=$row;
646 $depthDataArr[$row['templateID']]['bgcolor_setup'] = isset($this->clearList_setup_temp
[$row['templateID']])?
' class="bgColor5"':'';
647 $depthDataArr[$row['templateID']]['bgcolor_const'] = isset($this->clearList_const_temp
[$row['templateID']])?
' class="bgColor5"':'';
648 unset($this->clearList_setup_temp
[$row['templateID']]);
649 unset($this->clearList_const_temp
[$row['templateID']]);
650 $this->templateTitles
[$row['templateID']]=$row['title'];
652 if ($row['templateID']==$this->hierarchyInfo
[$pointer-1]['templateParent']) {
653 $depthDataArr[$row['templateID'].'.'] = $this->ext_process_hierarchyInfo(array(), $pointer);
656 return $depthDataArr;
660 * [Describe function...]
662 * @param [type] $config: ...
663 * @param [type] $lineNumbers: ...
664 * @param [type] $comments: ...
665 * @param [type] $crop: ...
666 * @param [type] $syntaxHL: ...
667 * @param [type] $syntaxHLBlockmode: ...
670 function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0) {
673 while (list(,$str)=each($config)) {
674 $all .= chr(10) .'[GLOBAL]' . chr(10) . $str;
678 $all = ereg_replace('^[^'.chr(10).']*.','',$all);
680 $tsparser = t3lib_div
::makeInstance('t3lib_TSparser');
681 $tsparser->lineNumberOffset
=$this->ext_lineNumberOffset+
1;
682 return $tsparser->doSyntaxHighlight($all,$lineNumbers?
array($this->ext_lineNumberOffset+
1):'',$syntaxHLBlockmode);
684 return $this->ext_formatTS($all,$lineNumbers,$comments,$crop);
689 * Returns a new string of max. $chars lenght
690 * If the string is longer, it will be truncated and prepended with '...'
691 * $chars must be an integer of at least 4
693 * @param [type] $string: ...
694 * @param [type] $chars: ...
697 function ext_fixed_lgd($string,$chars) {
699 if(strlen($string)>$chars) {
700 return substr($string, 0, $chars-3).'...';
707 * [Describe function...]
709 * @param [type] $ln: ...
710 * @param [type] $str: ...
713 function ext_lnBreakPointWrap($ln,$str) {
714 return '<a href="#" onClick="return brPoint('.$ln.','.($this->ext_lineNumberOffset_mode
=="setup"?
1:0).');">'.$str.'</a>';
718 * [Describe function...]
720 * @param [type] $input: ...
721 * @param [type] $ln: ...
722 * @param [type] $comments: ...
723 * @param [type] $crop: ...
726 function ext_formatTS($input, $ln, $comments=1, $crop=0) {
727 $input = ereg_replace('^[^'.chr(10).']*.','',$input);
728 $input = chop($input);
729 $cArr = explode(chr(10),$input);
732 $n = ceil(log10(count($cArr)+
$this->ext_lineNumberOffset
));
734 while(list($k,$v)=each($cArr)) {
735 $lln=$k+
$this->ext_lineNumberOffset+
1;
736 if ($ln) $lineNum = $this->ext_lnBreakPointWrap($lln,str_replace(' ',' ',sprintf('% '.$n.'d',$lln))).': ';
737 $v=htmlspecialchars($v);
738 if ($crop) {$v=$this->ext_fixed_lgd($v,($ln?
71:77));}
739 $cArr[$k] = $lineNum.str_replace(' ',' ',$v);
741 $firstChar = substr(trim($v),0,1);
742 if ($firstChar=='[') {
743 $cArr[$k] = '<font color="green"><b>'.$cArr[$k].'</b></font>';
744 } elseif ($firstChar=='/' ||
$firstChar=='#') {
746 $cArr[$k] = '<span class="typo3-dimmed">'.$cArr[$k].'</span>';
754 $output = implode($cArr, '<br />').'<br />';
759 * [Describe function...]
761 * @param [type] $id: ...
762 * @param [type] $template_uid: ...
765 function ext_getFirstTemplate($id,$template_uid=0) {
766 // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
769 $addC = ' AND uid='.$template_uid;
771 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).$addC.' '.$this->whereClause
, '', 'sorting', '1');
772 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
773 t3lib_BEfunc
::workspaceOL('sys_template',$row);
774 $GLOBALS['TYPO3_DB']->sql_free_result($res);
775 return $row; // Returns the template row if found.
780 * [Describe function...]
782 * @param [type] $id: ...
785 function ext_getAllTemplates($id) {
786 // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
789 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).' '.$this->whereClause
, '', 'sorting');
790 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
791 t3lib_BEfunc
::workspaceOL('sys_template',$row);
792 if (is_array($row)) $outRes[] = $row;
794 $GLOBALS['TYPO3_DB']->sql_free_result($res);
795 return $outRes; // Returns the template rows in an array.
800 * This function compares the flattened constants (default and all).
801 * Returns an array with the constants from the whole template which may be edited by the module.
803 * @param [type] $default: ...
806 function ext_compareFlatSetups($default) {
807 $editableComments=array();
808 reset($this->flatSetup
);
809 while(list($const,$value)=each($this->flatSetup
)) {
810 if (substr($const,-2)!='..' && isset($this->flatSetup
[$const.'..'])) {
811 $comment = trim($this->flatSetup
[$const.'..']);
812 $c_arr = explode(chr(10),$comment);
813 while(list($k,$v)=each($c_arr)) {
814 $line=trim(ereg_replace('^[#\/]*','',$v));
816 $parts = explode(';', $line);
817 while(list(,$par)=each($parts)) {
818 if (strstr($par,'=')) {
819 $keyValPair =explode('=',$par,2);
820 switch(trim(strtolower($keyValPair[0]))) {
824 int (range; low-high, list: item,item,item = selector),
831 $editableComments[$const]['type'] = trim($keyValPair[1]);
834 // list of categories.
835 $catSplit=explode('/',strtolower($keyValPair[1]));
836 $editableComments[$const]['cat'] = trim($catSplit[0]);
837 $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.
838 if ($catSplit[1] && isset($this->subCategories
[$catSplit[1]])) {
839 $editableComments[$const]['subcat_name']=$catSplit[1];
840 $editableComments[$const]['subcat']=$this->subCategories
[$catSplit[1]][1].'/'.$catSplit[1].'/'.trim($catSplit[2]).'z';
842 $editableComments[$const]['subcat']='x'.'/'.trim($catSplit[2]).'z';
847 $editableComments[$const]['label'] = trim($keyValPair[1]);
855 if (isset($editableComments[$const])) {
856 $editableComments[$const]['name']=$const;
857 $editableComments[$const]['value']=trim($value);
858 if (isset($default[$const])) {
859 $editableComments[$const]['default_value']=trim($default[$const]);
863 return $editableComments;
867 * [Describe function...]
869 * @param [type] $editConstArray: ...
872 function ext_categorizeEditableConstants($editConstArray) {
873 // Runs through the available constants and fills the $this->categories array with pointers and priority-info
874 reset($editConstArray);
875 while(list($constName,$constData)=each($editConstArray)) {
876 if (!$constData['type']) {
877 $constData['type']='string';
879 $cats = explode(',',$constData['cat']);
881 while (list(,$theCat)=each($cats)) { // if = only one category, while allows for many. We have agreed on only one category is the most basic way...
882 $theCat=trim($theCat);
884 $this->categories
[$theCat][$constName]=$constData['subcat'];
891 * [Describe function...]
895 function ext_getCategoryLabelArray() {
896 // Returns array used for labels in the menu.
898 while(list($k,$v)=each($this->categories
)) {
900 $retArr[$k]=strtoupper($k).' ('.count($v).')';
907 * [Describe function...]
909 * @param [type] $type: ...
912 function ext_getTypeData($type) {
916 $retArr['type']='string';
918 $m=strcspn ($type,' [');
919 $retArr['type']=strtolower(substr($type,0,$m));
920 if (t3lib_div
::inList('int,options,file,boolean,offset,user', $retArr['type'])) {
921 $p=trim(substr($type,$m));
923 ereg('\[(.*)\]',$p,$reg);
926 $retArr['paramstr']=$p;
927 switch($retArr['type']) {
929 if (substr($retArr['paramstr'],0,1)=='-') {
930 $retArr['params']=t3lib_div
::intExplode('-',substr($retArr['paramstr'],1));
931 $retArr['params'][0]=intval('-'.$retArr['params'][0]);
933 $retArr['params']=t3lib_div
::intExplode('-',$retArr['paramstr']);
935 $retArr['paramstr']=$retArr['params'][0].' - '.$retArr['params'][1];
938 $retArr['params']=explode(',',$retArr['paramstr']);
948 * [Describe function...]
950 * @param [type] $category: ...
953 function ext_getTSCE_config($category) {
954 $catConf=$this->setup
['constants']['TSConstantEditor.'][$category.'.'];
956 if (is_array($catConf)) {
958 while(list($key,$val)=each($catConf)) {
961 $out['imagetag'] = $this->ext_getTSCE_config_image($catConf['image']);
969 if (t3lib_div
::testInt($key)) {
970 $constRefs = explode(',',$val);
972 while(list(,$const)=each($constRefs)) {
974 if ($const && $const<=20) {
975 $out['constants'][$const].=$this->ext_getKeyImage($key);
983 $this->helpConfig
=$out;
987 * [Describe function...]
989 * @param [type] $key: ...
992 function ext_getKeyImage($key) {
993 return '<img src="'.$this->ext_localWebGfxPrefix
.'gfx/'.$key.'.gif" align="top" hspace=2>';
997 * [Describe function...]
999 * @param [type] $imgConf: ...
1000 * @return [type] ...
1002 function ext_getTSCE_config_image($imgConf) {
1003 if (substr($imgConf,0,4)=='gfx/') {
1004 $iFile=$this->ext_localGfxPrefix
.$imgConf;
1005 $tFile=$this->ext_localWebGfxPrefix
.$imgConf;
1006 } elseif (substr($imgConf,0,4)=='EXT:') {
1007 $iFile = t3lib_div
::getFileAbsFileName($imgConf);
1009 $f = substr($iFile,strlen(PATH_site
));
1010 $tFile=$GLOBALS['BACK_PATH'].'../'.$f;
1013 $f = 'uploads/tf/'.$this->extractFromResources($this->setup
['resources'],$imgConf);
1014 $iFile=PATH_site
.$f;
1015 $tFile=$GLOBALS['BACK_PATH'].'../'.$f;
1017 $imageInfo=@getImagesize
($iFile);
1018 return '<img src="'.$tFile.'" '.$imageInfo[3].'>';
1022 * [Describe function...]
1024 * @return [type] ...
1026 function ext_resourceDims() {
1027 if ($this->setup
['resources']) {
1028 $rArr=explode(',',$this->setup
['resources']);
1029 while(list($c,$val)=each($rArr)) {
1031 $theFile = PATH_site
.'uploads/tf/'.$val;
1032 if ($val && @is_file
($theFile)) {
1033 $imgInfo = @getimagesize
($theFile);
1035 if (is_array($imgInfo)) {
1036 $this->resourceDimensions
[$val]=' ('.$imgInfo[0].'x'.$imgInfo[1].')';
1040 reset($this->dirResources
);
1041 while(list($c,$val)=each($this->dirResources
)) {
1043 $imgInfo = @getimagesize
(PATH_site
.$val);
1044 if (is_array($imgInfo)) {
1045 $this->resourceDimensions
[$val]=' ('.$imgInfo[0].'x'.$imgInfo[1].')';
1051 * [Describe function...]
1053 * @param [type] $path: ...
1054 * @return [type] ...
1056 function ext_readDirResources($path) {
1058 if ($path && substr($path,0,10)=='fileadmin/') {
1059 $path = ereg_replace('\/$','',$path);
1060 $this->readDirectory(PATH_site
.$path);
1065 * [Describe function...]
1067 * @param [type] $path: ...
1068 * @param [type] $type: ...
1069 * @return [type] ...
1071 function readDirectory($path,$type='file') {
1072 if(@is_dir
($path)) {
1075 if (is_object($d)) {
1076 while($entry=$d->read()) {
1077 if ($entry!='.' && $entry!='..') {
1078 $wholePath = $path.'/'.$entry; // Because of odd PHP-error where <BR>-tag is sometimes placed after a filename!!
1079 if (@file_exists
($wholePath) && (!$type ||
filetype($wholePath)==$type)) {
1080 $fI = t3lib_div
::split_fileref($wholePath);
1081 $this->dirResources
[]=substr($wholePath,strlen(PATH_site
));
1091 * [Describe function...]
1093 * @param [type] $params: ...
1094 * @return [type] ...
1096 function ext_fNandV($params) {
1097 $fN='data['.$params['name'].']';
1098 $fV=$params['value'];
1099 if (ereg('^{[\$][a-zA-Z0-9\.]*}$',trim($fV),$reg)) { // Values entered from the constantsedit cannot be constants! 230502; removed \{ and set {
1102 $fV=htmlspecialchars($fV);
1104 return array($fN,$fV,$params);
1108 * This functions returns the HTML-code that creates the editor-layout of the module.
1110 * @param [type] $theConstants: ...
1111 * @param [type] $category: ...
1112 * @return [type] ...
1114 function ext_printFields($theConstants,$category) {
1115 reset($theConstants);
1116 $output='<script type="text/javascript" src="'.$GLOBALS['BACK_PATH'].'js/constantEditor.js"></script>
1119 if (is_array($this->categories
[$category])) {
1121 $help=$this->helpConfig
;
1122 $this->rArr
=explode(',',$this->setup
['resources'].','.implode($this->dirResources
,','));
1124 if (!$this->doNotSortCategoriesBeforeMakingForm
) asort($this->categories
[$category]);
1125 while(list($name,$type)=each($this->categories
[$category])) {
1126 $params = $theConstants[$name];
1127 if (is_array($params)) {
1128 if ($subcat!=$params['subcat_name']) {
1129 $subcat=$params['subcat_name'];
1130 $subcat_name = $params['subcat_name'] ?
$this->subCategories
[$params['subcat_name']][0] : 'Others';
1132 $output.='<h2 class="typo3-tstemplate-ceditor-subcat">'.$subcat_name.'</h2>';
1135 $label=$GLOBALS['LANG']->sL($params['label']);
1136 $label_parts = explode(':',$label,2);
1137 if (count($label_parts)==2) {
1138 $head=trim($label_parts[0]);
1139 $body=trim($label_parts[1]);
1141 $head=trim($label_parts[0]);
1144 if (strlen($head)>35) {
1145 if (!$body) {$body=$head;}
1146 $head=t3lib_div
::fixed_lgd_cs($head,35);
1148 $typeDat=$this->ext_getTypeData($params['type']);
1151 $raname = substr(md5($params['name']),0,10);
1152 $aname='\''.$raname.'\'';
1154 list($fN,$fV,$params)=$this->ext_fNandV($params);
1156 switch($typeDat['type']) {
1159 $p_field='<input id="'.$fN.'" type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(5).' onChange="uFormUrl('.$aname.')" />';
1160 if ($typeDat['paramstr']) {
1161 $p_field.=' Range: '.$typeDat['paramstr'];
1162 } elseif ($typeDat['type']=='int+') {
1163 $p_field.=' Range: 0 - ';
1165 $p_field.=' (Integer)';
1169 $colorNames=explode(',',','.$this->HTMLcolorList
);
1171 while(list(,$val)=each($colorNames)) {
1173 if ($val==strtolower($params['value'])) {
1176 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.'</option>';
1178 $p_field='<select id="select-'.$fN.'" rel="'.$fN.'" name="C'.$fN.'" class="typo3-tstemplate-ceditor-color-select" onChange="uFormUrl('.$aname.');">'.$p_field.'</select>';
1180 $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.')" />';
1183 $wArr = explode('|',$fV);
1184 $p_field='<input type="text" id="'.$fN.'" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(29).' onChange="uFormUrl('.$aname.')" />';
1186 $p_field.='<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(15).' onChange="uFormUrl('.$aname.')" />';
1189 $wArr = explode(',',$fV);
1190 $labels = t3lib_div
::trimExplode(',',$typeDat['paramstr']);
1191 $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.=($labels[1]?
$labels[1]:'y').':<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' onChange="uFormUrl('.$aname.')" />';
1194 for ($aa=2;$aa<count($labels);$aa++
) {
1196 $p_field.=' , '.$labels[$aa].':<input type="text" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' onChange="uFormUrl('.$aname.')" />';
1198 $p_field.='<input type="hidden" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'" />';
1203 if (is_array($typeDat['params'])) {
1205 while(list(,$val)=each($typeDat['params'])) {
1206 $vParts = explode('=',$val,2);
1207 $label = $vParts[0];
1208 $val = isset($vParts[1]) ?
$vParts[1] : $vParts[0];
1212 if ($val==$params['value']) {
1215 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$GLOBALS['LANG']->sL($label).'</option>';
1217 $p_field='<select id="'.$fN.'" name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
1221 $p_field='<input type="hidden" name="'.$fN.'" value="0" />';
1226 $p_field.='<input id="'.$fN.'" type="checkbox" name="'.$fN.'" value="'.($typeDat['paramstr']?
$typeDat['paramstr']:1).'"'.$sel.' onClick="uFormUrl('.$aname.')" />';
1229 $p_field='<input type="hidden" name="'.$fN.'" value="#" />';
1234 $p_field.='<input id="'.$fN.'" type="checkbox" name="'.$fN.'" value=""'.$sel.' onClick="uFormUrl('.$aname.')" />';
1237 $p_field='<option value=""></option>';
1239 $selectThisFile = $this->extractFromResources($this->setup
['resources'],$params['value']);
1240 if ($params['value'] && !$selectThisFile) {
1241 if (in_array($params['value'],$this->dirResources
)) {
1242 $selectThisFile=$params['value'];
1246 $extList = $typeDat['paramstr'];
1247 $p_field='<option value="">('.$extList.')</option>';
1248 if ($extList=='IMAGE_EXT') {
1249 $extList = $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'];
1252 $onlineResourceFlag=$this->ext_defaultOnlineResourceFlag
;
1254 while(list($c,$val)=each($this->rArr
)) {
1256 $fI=t3lib_div
::split_fileref($val);
1257 if ($val && (!$extList || t3lib_div
::inList($extList,$fI['fileext']))) {
1258 if ($onlineResourceFlag<=0 && substr($fI['path'],0,10)=='fileadmin/') {
1259 if ($onlineResourceFlag<0) {
1260 $p_field.='<option value=""></option>';
1262 $p_field.='<option value="">__'.$fI['path'].'__:</option>';
1263 $onlineResourceFlag=1;
1265 $dims=$this->resourceDimensions
[$val];
1268 // Check if $params['value'] is in the list of resources.
1269 if ($selectThisFile && $selectThisFile==$val) {
1271 if ($onlineResourceFlag<=0) {
1272 $theImage=t3lib_BEfunc
::thumbCode(array('resources'=>$selectThisFile),'sys_template','resources',$GLOBALS['BACK_PATH'],'');
1274 $theImage=t3lib_BEfunc
::thumbCode(array('resources'=>$fI['file']),'sys_template','resources',$GLOBALS['BACK_PATH'],'',$fI['path']);
1278 if ($onlineResourceFlag<=0) {
1279 $onlineResourceFlag--;
1280 // Value is set with a *
1281 $val = $this->ext_setStar($val);
1282 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.$dims.'</option>';
1284 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$fI['file'].$dims.'</option>';
1289 if (trim($params['value']) && !$selectThisFile) {
1290 $val = $params['value'];
1291 $p_field.='<option value=""></option>';
1292 $p_field.='<option value="'.htmlspecialchars($val).'" selected>'.$val.'</option>';
1295 $p_field='<select id="'.$fN.'" name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
1296 $p_field.=$theImage;
1298 if (!$this->ext_noCEUploadAndCopying
) {
1300 $copyFile = $this->extractFromResources($this->setup
['resources'],$params['value']);
1302 if ($params['value']) {
1303 $copyFile=PATH_site
.$this->ext_detectAndFixExtensionPrefix($params['value']);
1309 if ($copyFile && @is_file
($copyFile)) {
1310 $p_field.='<img src="clear.gif" width="20" height="1" alt="" /><img'.t3lib_iconWorks
::skinImg($GLOBALS['BACK_PATH'],'gfx/clip_copy.gif','width="12" height="12"').' border="0" alt="" /><input type="checkbox" name="_copyResource['.$params['name'].']" value="'.htmlspecialchars($copyFile).'" onClick="uFormUrl('.$aname.');if (this.checked) {alert(unescape(\''.rawurlencode(sprintf("This will make a copy of the current file, '%s'. Do you really want that?",$params['value'])).'\'));}" />';
1315 $p_field.='<input id="'.$fN.'" type="file" name="upload_'.$fN.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth().' onChange="uFormUrl('.$aname.')" size="50" />';
1319 $userFunction = $typeDat['paramstr'];
1320 $userFunctionParams = array('fieldName' => $fN, 'fieldValue' => $fV);
1321 $p_field = t3lib_div
::callUserFunction($userFunction, $userFunctionParams, $this, '');
1325 $fwidth= $typeDat['type']=='small' ?
10 : 46;
1326 $p_field='<input id="'.$fN.'" type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth($fwidth).' onChange="uFormUrl('.$aname.')" />';
1330 // Define default names and IDs
1331 $userTyposcriptID = 'userTS-'.$params['name'];
1332 $defaultTyposcriptID = 'defaultTS-'.$params['name'];
1333 $checkboxName = 'check['.$params['name'].']';
1334 $checkboxID = $checkboxName;
1336 // Handle type=color specially
1337 if ($typeDat['type']=='color' && substr($params['value'],0,2)!='{$') {
1338 $color = '<div id="colorbox-'.$fN.'" class="typo3-tstemplate-ceditor-colorblock" style="background-color:'.$params['value'].';"> </div>';
1343 if (!$this->ext_dontCheckIssetValues
) {
1345 /* Set the default styling options */
1346 if(isset($this->objReg
[$params['name']])) {
1347 $checkboxValue = 'checked';
1348 $userTyposcriptStyle = '';
1349 $defaultTyposcriptStyle = 'style="display:none;"';
1351 $checkboxValue = '';
1352 $userTyposcriptStyle = 'style="display:none;"';
1353 $defaultTyposcriptStyle = '';
1357 $deleteIconHTML = '<img class="typo3-tstemplate-ceditor-control undoIcon" '.t3lib_iconWorks
::skinImg($GLOBALS['BACK_PATH'], 'gfx/undo.gif').' alt="Revert to default Constant" title="Revert to default Constant" rel="'.$params['name'].'" />';
1358 $editIconHTML = '<img class="typo3-tstemplate-ceditor-control editIcon" '.t3lib_iconWorks
::skinImg($GLOBALS['BACK_PATH'], 'gfx/edit2.gif').' alt="Edit this Constant" title="Edit this Constant" rel="'.$params['name'].'" />';
1359 $constantCheckbox = '<input type="hidden" name="'.$checkboxName.'" id="'.$checkboxID.'" value="'.$checkboxValue.'"/>';
1361 // If there's no default value for the field, use a static label.
1362 if(!$params['default_value']) {
1363 $params['default_value'] = '[Empty]';
1366 $constantDefaultRow='<div class="typo3-tstemplate-ceditor-row" id="'.$defaultTyposcriptID.'" '.$defaultTyposcriptStyle.'>'.$editIconHTML.htmlspecialchars($params['default_value']).$color.'</div>';
1369 $constantEditRow = '<div class="typo3-tstemplate-ceditor-row" id="'.$userTyposcriptID.'" '.$userTyposcriptStyle.'>'.$deleteIconHTML.$p_field.$color.'</div>';
1371 $constantLabel = '<dt class="typo3-tstemplate-ceditor-label">'.htmlspecialchars($head).'</dt>';
1372 $constantName = '<dt class="typo3-dimmed">['.$params['name'].']</dt>';
1373 $constantDescription = $body ?
'<dd>'.htmlspecialchars($body).'</dd>' : '';
1374 $constantData = '<dd>'.$constantCheckbox.$constantEditRow.$constantDefaultRow.'</dd>';
1376 $output.='<a name="'.$raname.'"></a>'.$help['constants'][$params['name']];
1377 $output.='<dl class="typo3-tstemplate-ceditor-constant">'.$constantLabel.$constantName.$constantDescription.$constantData.'</dl>';
1379 debug('Error. Constant did not exist. Should not happen.');
1397 /***************************
1399 * Processing input values
1401 ***************************/
1404 * @param [type] $constants: ...
1405 * @return [type] ...
1407 function ext_regObjectPositions($constants) {
1408 // This runs through the lines of the constants-field of the active template and registers the constants-names and linepositions in an array, $this->objReg
1409 $this->raw
= explode(chr(10),$constants);
1412 $this->objReg
=array(); // resetting the objReg if the divider is found!!
1413 $this->ext_regObjects('');
1417 * [Describe function...]
1419 * @param [type] $pre: ...
1420 * @return [type] ...
1422 function ext_regObjects($pre) {
1423 // works with regObjectPositions. "expands" the names of the TypoScript objects
1424 while (isset($this->raw
[$this->rawP
])) {
1425 $line = ltrim($this->raw
[$this->rawP
]);
1426 if (strstr($line,$this->edit_divider
)) {
1427 $this->objReg
=array(); // resetting the objReg if the divider is found!!
1431 if (substr($line,0,1)=='[') {
1433 } elseif (strcspn($line,'}#/')!=0) {
1434 $varL = strcspn($line,' {=<');
1435 $var=substr($line,0,$varL);
1436 $line = ltrim(substr($line,$varL));
1437 switch(substr($line,0,1)) {
1439 $this->objReg
[$pre.$var]=$this->rawP
-1;
1442 $this->ext_inBrace++
;
1443 $this->ext_regObjects($pre.$var.'.');
1446 $this->lastComment
='';
1447 } elseif (substr($line,0,1)=='}') {
1448 $this->lastComment
='';
1449 $this->ext_inBrace
--;
1450 if ($this->ext_inBrace
<0) {
1451 $this->ext_inBrace
=0;
1461 * [Describe function...]
1463 * @param [type] $key: ...
1464 * @param [type] $var: ...
1465 * @return [type] ...
1467 function ext_putValueInConf($key, $var) {
1468 // Puts the value $var to the TypoScript value $key in the current lines of the templates.
1469 // If the $key is not found in the template constants field, a new line is inserted in the bottom.
1470 $theValue = ' '.trim($var);
1471 if (isset($this->objReg
[$key])) {
1472 $lineNum = $this->objReg
[$key];
1473 $parts = explode('=',$this->raw
[$lineNum],2);
1474 if (count($parts)==2) {
1475 $parts[1]= $theValue;
1477 $this->raw
[$lineNum]=implode($parts,'=');
1479 $this->raw
[]=$key.' ='.$theValue;
1485 * [Describe function...]
1487 * @param [type] $key: ...
1488 * @return [type] ...
1490 function ext_removeValueInConf($key) {
1491 // Removes the value in the configuration
1492 if (isset($this->objReg
[$key])) {
1493 $lineNum = $this->objReg
[$key];
1494 unset($this->raw
[$lineNum]);
1500 * [Describe function...]
1502 * @param [type] $arr: ...
1503 * @param [type] $settings: ...
1504 * @return [type] ...
1506 function ext_depthKeys($arr,$settings) {
1509 while(list($theK,$theV)=each($arr)) {
1510 $theKeyParts = explode('.',$theK);
1512 $c=count($theKeyParts);
1514 while(list(,$p)=each($theKeyParts)) {
1516 $depth.=($depth?
'.':'').$p;
1517 $tsbrArray[$depth]= ($c==$a) ?
$theV : 1;
1522 while(list($theK,$theV)=each($tsbrArray)) {
1524 $settings[$theK] = 1;
1526 unset($settings[$theK]);
1533 * [Describe function...]
1535 * @param [type] $http_post_vars: ...
1536 * @param [type] $http_post_files: ...
1537 * @param [type] $theConstants: ...
1538 * @param [type] $tplRow: ...
1539 * @return [type] ...
1541 function ext_procesInput($http_post_vars,$http_post_files,$theConstants,$tplRow) {
1542 $data=$http_post_vars['data'];
1543 $check=$http_post_vars['check'];
1544 $copyResource=$http_post_vars['_copyResource'];
1545 $Wdata=$http_post_vars['Wdata'];
1546 $W2data=$http_post_vars['W2data'];
1547 $W3data=$http_post_vars['W3data'];
1548 $W4data=$http_post_vars['W4data'];
1549 $W5data=$http_post_vars['W5data'];
1551 if (is_array($data)) {
1553 while(list($key,$var)=each($data)) {
1554 if (isset($theConstants[$key])) {
1555 if ($this->ext_dontCheckIssetValues ||
isset($check[$key])) { // If checkbox is set, update the value
1556 list($var) = explode(chr(10),$var); // exploding with linebreak, just to make sure that no multiline input is given!
1557 $typeDat=$this->ext_getTypeData($theConstants[$key]['type']);
1558 switch($typeDat['type']) {
1560 if ($typeDat['paramstr']) {
1561 $var=t3lib_div
::intInRange($var,$typeDat['params'][0],$typeDat['params'][1]);
1567 $var=t3lib_div
::intInRange($var,0,10000);
1571 if($var && !t3lib_div
::inList($this->HTMLcolorList
,strtolower($var))) {
1572 $var = ereg_replace('[^A-Fa-f0-9]*','',$var);
1573 $useFullHex = strlen($var) > 3;
1575 $col[]=HexDec(substr($var,0,1));
1576 $col[]=HexDec(substr($var,1,1));
1577 $col[]=HexDec(substr($var,2,1));
1580 $col[]=HexDec(substr($var,3,1));
1581 $col[]=HexDec(substr($var,4,1));
1582 $col[]=HexDec(substr($var,5,1));
1585 $var = substr('0'.DecHex($col[0]),-1).substr('0'.DecHex($col[1]),-1).substr('0'.DecHex($col[2]),-1);
1587 $var .= substr('0'.DecHex($col[3]),-1).substr('0'.DecHex($col[4]),-1).substr('0'.DecHex($col[5]),-1);
1590 $var = '#'.strtoupper($var);
1601 if (isset($Wdata[$key])) {
1602 $var.='|'.$Wdata[$key];
1606 if (isset($Wdata[$key])) {
1607 $var=intval($var).','.intval($Wdata[$key]);
1608 if (isset($W2data[$key])) {
1609 $var.=','.intval($W2data[$key]);
1610 if (isset($W3data[$key])) {
1611 $var.=','.intval($W3data[$key]);
1612 if (isset($W4data[$key])) {
1613 $var.=','.intval($W4data[$key]);
1614 if (isset($W5data[$key])) {
1615 $var.=','.intval($W5data[$key]);
1624 $var = $typeDat['paramstr'] ?
$typeDat['paramstr'] : 1;
1628 if (!$this->ext_noCEUploadAndCopying
) {
1629 if ($http_post_files['upload_data']['name'][$key] && $http_post_files['upload_data']['tmp_name'][$key]!='none') {
1630 $var = $this->upload_copy_file(
1633 trim($http_post_files['upload_data']['name'][$key]),
1634 $http_post_files['upload_data']['tmp_name'][$key]
1637 if ($copyResource[$key]) {
1638 $var = $this->upload_copy_file(
1641 basename($copyResource[$key]),
1648 if ($this->ext_printAll ||
strcmp($theConstants[$key]['value'],$var)) {
1649 $this->ext_putValueInConf($key, $var); // Put value in, if changed.
1651 unset($check[$key]); // Remove the entry because it has been "used"
1653 $this->ext_removeValueInConf($key);
1658 // 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...
1659 if (!$this->ext_dontCheckIssetValues
&& is_array($check)) {
1661 while(list($key,$var)=each($check)) {
1662 if (isset($theConstants[$key])) {
1663 $dValue = $theConstants[$key]['default_value'];
1664 $this->ext_putValueInConf($key, $dValue);
1671 * [Describe function...]
1673 * @param [type] $typeDat: ...
1674 * @param [type] $tplRow: ...
1675 * @param [type] $theRealFileName: ...
1676 * @param [type] $tmp_name: ...
1677 * @return [type] ...
1679 function upload_copy_file($typeDat,&$tplRow,$theRealFileName,$tmp_name) {
1682 $extList = $typeDat['paramstr'];
1683 if ($extList=='IMAGE_EXT') {
1684 $extList = $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'];
1686 $fI=t3lib_div
::split_fileref($theRealFileName);
1687 if ($theRealFileName && (!$extList || t3lib_div
::inList($extList,$fI['fileext']))) {
1688 $tmp_upload_name = t3lib_div
::upload_to_tempfile($tmp_name); // If there is an uploaded file, move it for the sake of safe_mode.
1691 $alternativeFileName=array();
1692 $alternativeFileName[$tmp_upload_name] = $theRealFileName;
1693 // Making list of resources
1694 $resList = $tplRow['resources'];
1695 $resList = $tmp_upload_name.','.$resList;
1696 $resList=implode(t3lib_div
::trimExplode(',',$resList,1),',');
1697 // Making data-array
1698 $saveId = $tplRow['_ORIG_uid'] ?
$tplRow['_ORIG_uid'] : $tplRow['uid'];
1701 $recData['sys_template'][$saveId]['resources'] = $resList;
1703 $tce = t3lib_div
::makeInstance('t3lib_TCEmain');
1704 $tce->stripslashes_values
=0;
1705 $tce->alternativeFileName
= $alternativeFileName;
1706 $tce->start($recData,Array());
1707 $tce->process_datamap();
1709 t3lib_div
::unlink_tempfile($tmp_upload_name);
1711 $tmpRow = t3lib_BEfunc
::getRecordWSOL('sys_template',$saveId,'resources');
1713 $tplRow['resources'] = $tmpRow['resources'];
1715 // Setting the value
1716 $var = $this->ext_setStar($theRealFileName);
1722 * [Describe function...]
1724 * @param [type] $id: ...
1725 * @param [type] $perms_clause: ...
1726 * @return [type] ...
1728 function ext_prevPageWithTemplate($id,$perms_clause) {
1729 $rootLine = t3lib_BEfunc
::BEgetRootLine($id,$perms_clause?
' AND '.$perms_clause:'');
1731 while(list(,$p)=each($rootLine)) {
1732 if ($this->ext_getFirstTemplate($p['uid'])) {
1739 * [Describe function...]
1741 * @param [type] $val: ...
1742 * @return [type] ...
1744 function ext_setStar($val) {
1745 $fParts = explode('.',strrev($val),2);
1746 $val=ereg_replace('_[0-9][0-9]$','',strrev($fParts[1])).'*.'.strrev($fParts[0]);
1751 * [Describe function...]
1753 * @param [type] $value: ...
1754 * @return [type] ...
1756 function ext_detectAndFixExtensionPrefix($value) {
1757 if (substr($value,0,4)=='EXT:') {
1758 $parts = explode('/',substr($value,4),2);
1760 $extPath = t3lib_extMgm
::siteRelPath($parts[0]);
1761 $value = $extPath.$parts[1];
1770 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php']) {
1771 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php']);