2 /***************************************************************
5 * (c) 1999-2003 Kasper Skårhøj (kasper@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 <kasper@typo3.com>
37 require_once(PATH_t3lib
."class.t3lib_tstemplate.php");
39 class t3lib_tsparser_ext
extends t3lib_TStemplate
{
41 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.
42 var $HTMLcolorList = "aqua,black,blue,fuchsia,gray,green,lime,maroon,navy,olive,purple,red,silver,teal,yellow,white";
45 var $categories = array(
46 "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.
47 "menu" => array(), // Menu setup. This includes fontfiles, sizes, background images. Depending on the menutype.
48 "content" => array(), // All constants related to the display of pagecontent elements
49 "page" => array(), // General configuration like metatags, link targets
50 "advanced" => array(), // Advanced functions, which are used very seldomly.
51 "all" => array() // All constants are put here also!
52 ); // This will be filled with the available categories of the current template.
53 var $subCategories = array(
54 // Standard categories:
55 "enable" => Array("Enable features", "a"),
56 "dims" => Array("Dimensions, widths, heights, pixels", "b"),
57 "file" => Array("Files", "c"),
58 "typo" => Array("Typography", "d"),
59 "color" => Array("Colors", "e"),
60 "links" => Array("Links and targets", "f"),
61 "language" => Array("Language specific constants", "g"),
63 // subcategories based on the default content elements
64 "cheader" => Array("Content: 'Header'", "ma"),
65 "cheader_g" => Array("Content: 'Header', Graphical", "ma"),
66 "ctext" => Array("Content: 'Text'", "mb"),
68 "cimage" => Array("Content: 'Image'", "md"),
69 "cbullets" => Array("Content: 'Bullet list'", "me"),
70 "ctable" => Array("Content: 'Table'", "mf"),
71 "cuploads" => Array("Content: 'Filelinks'", "mg"),
72 "cmultimedia" => Array("Content: 'Multimedia'", "mh"),
73 "cmailform" => Array("Content: 'Form'", "mi"),
74 "csearch" => Array("Content: 'Search'", "mj"),
75 "clogin" => Array("Content: 'Login'", "mk"),
76 "csplash" => Array("Content: 'Textbox'", "ml"),
77 "cmenu" => Array("Content: 'Menu/Sitemap'", "mm"),
78 "cshortcut" => Array("Content: 'Insert records'", "mn"),
79 "clist" => Array("Content: 'List of records'", "mo"),
80 "cscript" => Array("Content: 'Script'", "mp"),
81 "chtml" => Array("Content: 'HTML'", "mq")
83 var $resourceDimensions = array();
84 var $dirResources = array();
86 // var $matchAll = 0; // If set, all conditions are matched!
94 var $tsbrowser_searchKeys = array();
95 var $tsbrowser_depthKeys = array();
100 var $ext_lineNumberOffset=0;
101 var $ext_localGfxPrefix="";
102 var $ext_localWebGfxPrefix="";
103 var $ext_expandAllNotes=0;
104 var $ext_noPMicons=0;
105 var $ext_noSpecialCharsOnLabels=0;
106 var $ext_listOfTemplatesArr=array();
107 var $ext_lineNumberOffset_mode="";
108 var $ext_dontCheckIssetValues=0; // Dont change...
109 var $ext_noCEUploadAndCopying=0;
111 var $ext_CEformName="forms[0]";
112 var $ext_defaultOnlineResourceFlag=0;
115 var $templateTitles=array();
117 function flattenSetup($setupArray, $prefix, $resourceFlag) {
118 // This flattens a hierarchical setuparray to $this->flatSetup
119 // The original function fetched the resource-file if any ("file."). This functions doesn't.
121 if (is_array($setupArray)) {
122 $this->getFileName_backPath
=PATH_site
; // Setting absolute prefixed path for relative resources.
124 while(list($key,$val)=each($setupArray)) {
125 if ($prefix ||
substr($key,0,16)!="TSConstantEditor") { // We don't want "TSConstantEditor" in the flattend setup.
126 if (is_array($val)) {
127 $this->flattenSetup($val,$prefix.$key, ($key=="file."));
128 } elseif ($resourceFlag && $this->resourceCheck
) {
129 // debug($prefix.$key."-".$val);
130 // debug($this->getFileName($val),1);
131 $this->flatSetup
[$prefix.$key] = $this->getFileName($val);
132 #debug(array($prefix.$key,$this->flatSetup[$prefix.$key],$val,$this->getFileName($val)));
133 if ($this->removeFromGetFilePath
&& substr($this->flatSetup
[$prefix.$key],0,strlen($this->removeFromGetFilePath
))==$this->removeFromGetFilePath
) {
134 $this->flatSetup
[$prefix.$key] = substr($this->flatSetup
[$prefix.$key],strlen($this->removeFromGetFilePath
));
135 // debug($this->flatSetup[$prefix.$key],1);
138 $this->flatSetup
[$prefix.$key] = $val;
144 function substituteConstants($all) {
145 $this->Cmarker
=substr(md5(uniqid("")),0,6);
146 reset($this->flatSetup
);
147 while (list($const,$val)=each($this->flatSetup
)) {
148 if (!is_array($val)) {
149 switch($this->constantMode
) {
151 $all = str_replace('{$'.$const.'}','##'.$this->Cmarker
.'_B##{$'.$const.'}##'.$this->Cmarker
.'_E##',$all);
154 $all = str_replace('{$'.$const.'}','##'.$this->Cmarker
.'_B##'.$val.'##'.$this->Cmarker
.'_E##',$all);
159 $all = str_replace('{$'.$const.'}',$val,$all);
166 function substituteCMarkers($all) {
167 switch($this->constantMode
) {
169 $all = str_replace('##'.$this->Cmarker
.'_B##', '<font color="green"><B>', $all);
170 $all = str_replace('##'.$this->Cmarker
.'_E##', '</b></font>', $all);
173 $all = str_replace('##'.$this->Cmarker
.'_B##', '<font color="green"><B>', $all);
174 $all = str_replace('##'.$this->Cmarker
.'_E##', '</b></font>', $all);
182 function generateConfig_constants() {
183 // Parses the constants in $this->const with respect to the constant-editor in this module.
184 // In particular comments in the code are registered and the edit_divider is taken into account.
185 // These vars are also set lateron...
186 $this->setup
["resources"]= $this->resources
;
187 $this->setup
["sitetitle"]= $this->sitetitle
;
190 $constants = t3lib_div
::makeInstance("t3lib_TSparser");
191 $constants->regComments
=1; // Register comments!
192 $constants->setup
= $this->const;
194 $matchObj = t3lib_div
::makeInstance("t3lib_matchCondition");
195 // $matchObj->matchAlternative = array("[globalString = page | title = *test*]");
196 $matchObj->matchAll
=1; // Matches ALL conditions in TypoScript
199 $cc=count($this->constants
);
200 reset($this->constants
);
201 while (list(,$str)=each($this->constants
)) {
204 if (strstr($str,$this->edit_divider
)) {
205 $parts = explode($this->edit_divider
,$str,2);
207 $constants->parse($parts[0],$matchObj);
209 $this->flatSetup
= Array();
210 $this->flattenSetup($constants->setup
,"","");
211 $defaultConstants=$this->flatSetup
;
213 $constants->parse($str,$matchObj);
216 $this->flatSetup
= Array();
217 $this->flattenSetup($constants->setup
,"","");
218 $this->setup
["constants"] = $constants->setup
;
220 return $this->ext_compareFlatSetups($defaultConstants);
222 function ext_getSetup($theSetup,$theKey) {
223 $parts = explode(".",$theKey,2);
224 // debug("-----------",1);
226 if (strcmp($parts[0],"") && is_array($theSetup[$parts[0]."."])) {
227 // debug(trim($parts[1]),1);
228 if (strcmp(trim($parts[1]),"")) {
229 // debug(trim($parts[1]),1);
230 return $this->ext_getSetup($theSetup[$parts[0]."."],trim($parts[1]));
232 return array($theSetup[$parts[0]."."], $theSetup[$parts[0]]);
235 if (strcmp(trim($theKey),"")) {
236 return array(array(),$theSetup[$theKey]);
238 return array($theSetup,"");
242 function ext_getObjTree($arr, $depth_in, $depthData, $parentType="",$parentValue="") {
248 $keyArr_alpha=array();
249 while (list($key,)=each($arr)) {
250 $key=ereg_replace("\.$","",$key);
251 if (substr($key,-1)!=".") {
252 if (t3lib_div
::testInt($key)) {
253 $keyArr_num[$key]=$arr[$key];
255 $keyArr_alpha[$key]=$arr[$key];
260 $keyArr=$keyArr_num+
$keyArr_alpha;
263 if ($depth_in) {$depth_in = $depth_in.".";}
265 // $validate_info= verify_TSobjects($keyArr,$parentType,$parentValue);
266 // debug($validate_info);
268 while (list($key,)=each($keyArr)) {
270 $depth=$depth_in.$key;
271 if ($this->bType
!="const" ||
substr($depth,0,1)!="_") { // this excludes all constants starting with "_" from being shown.
272 $goto = substr(md5($depth),0,6);
274 $deeper = (is_array($arr[$key."."]) && ($this->tsbrowser_depthKeys
[$depth] ||
$this->ext_expandAllNotes
)) ?
1 : 0;
276 $LN = ($a==$c)?
"blank":"line";
277 $BTM = ($a==$c)?
"bottom":"";
278 $PM = is_array($arr[$key."."]) && !$this->ext_noPMicons ?
($deeper ?
"minus":"plus") : "join";
281 $theIcon='<IMG src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border=0>';
285 $HTML.='<a name="'.$goto.'" href="index.php?id='.$GLOBALS["SOBE"]->id
.'&tsbr['.$depth.']='.($deeper?
0:1).'#'.$goto.'">'.$theIcon.'</a>';
289 if (t3lib_div
::inList("types,resources,sitetitle",$depth) && $this->bType
=="setup") { // Read only...
290 $label='<font color="#666666">'.$label.'</font>';
292 if ($this->linkObjects
) {
293 $label = '<a href="index.php?id='.$GLOBALS["SOBE"]->id
.'&sObj='.$depth.'">'.$label.'</a>';
296 // if (!isset($validate_info[$key])) {
297 // $HTML.='<font color="red">['.$label.']</font>';
299 $HTML.="[".$label."]";
301 if (isset($arr[$key])) {
302 $theValue = $arr[$key];
303 if ($this->fixedLgd
) {
304 $imgBlocks = ceil(1+
strlen($depthData)/77);
305 // debug($imgBlocks);
306 $lgdChars = 68-ceil(strlen("[".$key."]")*0.8)-$imgBlocks*3;
307 $theValue = $this->ext_fixed_lgd($theValue,$lgdChars);
309 if ($this->tsbrowser_searchKeys
[$depth]) {
310 $HTML.='=<b><font color="red">'.$this->makeHtmlspecialchars($theValue).'</font></b>';
312 $HTML.="=<b>".$this->makeHtmlspecialchars($theValue)."</b>";
318 $HTML.=$this->ext_getObjTree($arr[$key."."], $depth, $depthData.'<IMG src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$LN.'.gif" width="18" height="16" align="top">', $validate_info[$key], $arr[$key]);
324 function makeHtmlspecialchars($theValue){
325 return $this->ext_noSpecialCharsOnLabels ?
$theValue : htmlspecialchars($theValue);
327 function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray) {
330 while (list($key,)=each($arr)) {
331 $key=ereg_replace("\.$","",$key);
332 if (substr($key,-1)!=".") {
339 if ($depth_in) {$depth_in = $depth_in.".";}
340 while (list($key,)=each($keyArr)) {
341 $depth=$depth_in.$key;
342 $deeper = is_array($arr[$key."."]);
344 if ($this->regexMode
) {
345 if (ereg($searchString,$arr[$key])) { $this->tsbrowser_searchKeys
[$depth]=1; }
347 if (stristr($arr[$key],$searchString)) { $this->tsbrowser_searchKeys
[$depth]=1; }
351 $cS = count($this->tsbrowser_searchKeys
);
352 $keyArray = $this->ext_getSearchKeys($arr[$key."."], $depth, $searchString, $keyArray);
353 if ($cS != count($this->tsbrowser_searchKeys
)) {
360 function ext_getRootlineNumber($pid) {
361 if ($pid && is_array($GLOBALS["rootLine"])) {
362 reset($GLOBALS["rootLine"]);
363 while(list($key,$val)=each($GLOBALS["rootLine"])) {
364 if ($val['uid']==$pid) return $key;
368 function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0) {
371 while (list($key,)=each($arr)) {
372 $key=ereg_replace("\.$","",$key);
373 if (substr($key,-1)!=".") {
380 while (list($key,)=each($keyArr)) {
383 $deeper = is_array($arr[$key."."]);
387 $LN = ($a==$c)?
"blank":"line";
388 $BTM = ($a==$c)?
"top":"";
392 $icon = substr($row["templateID"],0,3)=="sys" ? t3lib_iconWorks
::getIcon("sys_template",array("root"=>$row["root"])) :
393 (substr($row["templateID"],0,6)=="static" ? t3lib_iconWorks
::getIcon("static_template",array()) : 'gfx/i/default.gif');
394 $alttext= "[".$row['templateID']."]";
395 $alttext.= $row['pid'] ?
" - ".t3lib_BEfunc
::getRecordPath($row['pid'],$GLOBALS["SOBE"]->perms_clause
,20) : "";
396 if (in_array($row['templateID'],$this->clearList_const
) ||
in_array($row['templateID'],$this->clearList_setup
)) {
397 $A_B='<a href="index.php?id='.$GLOBALS["SOBE"]->id
.'&template='.$row['templateID'].'">';
403 $HTML.=($first?
'':'<IMG src="'.$GLOBALS["BACK_PATH"].'t3lib/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($row['title'],$GLOBALS["BE_USER"]->uc
["titleLen"]).$A_E." ";
404 $RL = $this->ext_getRootlineNumber($row['pid']);
406 <td nowrap>'.$HTML.'</td>
407 <td align=center>'.($row["root"]?
"<b>X</b>":"").' </td>
408 <td align=center'.$row["bgcolor_setup"].'>'.fw(($row["clConf"]?
"<b>X</b>":"")." ").'</td>
409 <td align=center'.$row["bgcolor_const"].'>'.fw(($row["clConst"]?
"<b>X</b>":"")." ").'</td>
410 <td>'.($row["pid"]?
" ".$row["pid"].(strcmp($RL,"")?
" (".$RL.")":"")." ":"").'</td>
411 <td>'.($row["next"]?
" ".$row["next"]." ":"").'</td>
414 $keyArray = $this->ext_getTemplateHierarchyArr($arr[$key."."], $depthData.($first?
'':'<IMG src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$LN.'.gif" width="18" height="16" align="top">'), $keyArray);
419 function ext_process_hierarchyInfo($depthDataArr,&$pointer) {
420 $parent = $this->hierarchyInfo
[$pointer-1]['templateParent'];
421 while ($pointer>0 && $this->hierarchyInfo
[$pointer-1]['templateParent']==$parent) {
423 $row = $this->hierarchyInfo
[$pointer];
425 $depthDataArr[$row['templateID']]=$row;
426 $depthDataArr[$row['templateID']]["bgcolor_setup"] = isset($this->clearList_setup_temp
[$row['templateID']])?
' bgColor="'.$GLOBALS["SOBE"]->doc
->bgColor5
.'"':'';
427 $depthDataArr[$row['templateID']]["bgcolor_const"] = isset($this->clearList_const_temp
[$row['templateID']])?
' bgColor="'.$GLOBALS["SOBE"]->doc
->bgColor5
.'"':'';
428 unset($this->clearList_setup_temp
[$row['templateID']]);
429 unset($this->clearList_const_temp
[$row['templateID']]);
430 $this->templateTitles
[$row['templateID']]=$row["title"];
432 if ($row['templateID']==$this->hierarchyInfo
[$pointer-1]['templateParent']) {
433 $depthDataArr[$row['templateID']."."] = $this->ext_process_hierarchyInfo(array(), $pointer);
436 return $depthDataArr;
438 function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0) {
441 while (list(,$str)=each($config)) {
442 $all.="\n[GLOBAL]\n".$str;
446 $all = ereg_replace("^[^".chr(10)."]*.","",$all);
448 $tsparser = t3lib_div
::makeInstance("t3lib_TSparser");
449 $tsparser->lineNumberOffset
=$this->ext_lineNumberOffset+
1;
450 return $tsparser->doSyntaxHighlight($all,$lineNumbers?
array($this->ext_lineNumberOffset+
1):'',$syntaxHLBlockmode);
452 return $this->ext_formatTS($all,$lineNumbers,$comments,$crop);
455 function ext_fixed_lgd($string,$chars) {
456 // Returns a new string of max. $chars lenght
457 // If the string is longer, it will be truncated and prepended with "..."
458 // $chars must be an integer of at least 4
460 if(strlen($string)>$chars) {
461 return substr($string, 0, $chars-3)."...";
466 function ext_lnBreakPointWrap($ln,$str) {
467 return '<A href="#" onClick="return brPoint('.$ln.','.($this->ext_lineNumberOffset_mode
=="setup"?
1:0).');">'.$str.'</a>';
469 function ext_formatTS($input, $ln, $comments=1, $crop=0) {
470 $input = ereg_replace("^[^".chr(10)."]*.","",$input);
471 $input = chop($input);
472 $cArr = explode(chr(10),$input);
475 $n = ceil(log10(count($cArr)+
$this->ext_lineNumberOffset
));
477 while(list($k,$v)=each($cArr)) {
478 $lln=$k+
$this->ext_lineNumberOffset+
1;
479 if ($ln) $lineNum = $this->ext_lnBreakPointWrap($lln,str_replace(" ",' ',sprintf("% ".$n."d",$lln))).": ";
480 $v=htmlspecialchars($v);
481 if ($crop) {$v=$this->ext_fixed_lgd($v,($ln?
71:77));}
482 $cArr[$k] = $lineNum.str_replace(" ",' ',$v);
484 $firstChar = substr(trim($v),0,1);
485 if ($firstChar=="[") {
486 $cArr[$k] = '<font color="green"><b>'.$cArr[$k].'</b></font>';
487 } elseif ($firstChar=="/" ||
$firstChar=="#") {
489 $cArr[$k] = '<font color="#666666">'.$cArr[$k].'</font>';
495 /* if (ereg('\{\$[^\}]*\}',$v,$reg)) {
496 while(list(,$f)=each($reg)) {
499 $cArr[$k] = str_replace(htmlspecialchars($f),'<font color="green"><b>'.htmlspecialchars($f).'</b></font>',$cArr[$k]);
505 $output = implode($cArr, "<BR>")."<BR>";
506 // $output = '<font face=verdana size=1 color=maroon>'.$output.'</font>';
509 function ext_getFirstTemplate($id,$template_uid=0) {
510 // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
513 $addC = " AND uid=".$template_uid;
515 $query = "SELECT * FROM sys_template WHERE pid = ".intval($id).$addC." ".$this->whereClause
." ORDER BY sorting LIMIT 1";
516 $res = mysql(TYPO3_db
, $query);
518 $row = mysql_fetch_assoc($res);
519 return $row; // Returns the template row if found.
522 function ext_getAllTemplates($id) {
523 // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
525 $query = "SELECT * FROM sys_template WHERE pid = ".intval($id)." ".$this->whereClause
." ORDER BY sorting";
526 $res = mysql(TYPO3_db
, $query);
529 while($row = mysql_fetch_assoc($res)) {
532 return $outRes; // Returns the template rows in an array.
535 function ext_compareFlatSetups($default) {
536 // This function compares the flattened constants (default and all).
537 // Returns an array with the constants from the whole template which may be edited by the module.
539 $editableComments=array();
540 reset($this->flatSetup
);
541 while(list($const,$value)=each($this->flatSetup
)) {
542 if (substr($const,-2)!=".." && isset($this->flatSetup
[$const.".."])) {
543 $comment = trim($this->flatSetup
[$const.".."]);
544 $c_arr = explode(chr(10),$comment);
545 while(list($k,$v)=each($c_arr)) {
546 $line=trim(ereg_replace("^[#\/]*","",$v));
548 $parts = explode(";", $line);
549 while(list(,$par)=each($parts)) {
550 if (strstr($par,"=")) {
551 $keyValPair =explode("=",$par,2);
552 switch(trim(strtolower($keyValPair[0]))) {
556 int (range; low-high, list: item,item,item = selector),
563 $editableComments[$const]["type"] = trim($keyValPair[1]);
566 // list of categories.
567 $catSplit=explode("/",strtolower($keyValPair[1]));
568 $editableComments[$const]["cat"] = trim($catSplit[0]);
569 $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.
570 if ($catSplit[1] && isset($this->subCategories
[$catSplit[1]])) {
571 $editableComments[$const]["subcat_name"]=$catSplit[1];
572 $editableComments[$const]["subcat"]=$this->subCategories
[$catSplit[1]][1]."/".$catSplit[1]."/".trim($catSplit[2])."z";
574 $editableComments[$const]["subcat"]="x"."/".trim($catSplit[2])."z";
579 $editableComments[$const]["label"] = trim($keyValPair[1]);
587 if (isset($editableComments[$const])) {
588 $editableComments[$const]["name"]=$const;
589 $editableComments[$const]["value"]=trim($value);
590 if (isset($default[$const])) {
591 $editableComments[$const]["default_value"]=trim($default[$const]);
595 return $editableComments;
597 function ext_categorizeEditableConstants($editConstArray) {
598 // Runs through the available constants and fills the $this->categories array with pointers and priority-info
599 reset($editConstArray);
600 while(list($constName,$constData)=each($editConstArray)) {
601 if (!$constData["type"]) {$constData["type"]="string";}
602 $cats = explode(",",$constData["cat"]);
604 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...
605 $theCat=trim($theCat);
607 $this->categories
[$theCat][$constName]=$constData["subcat"];
608 // $this->categories["all"][$constName]=$constData["subcat"];
612 // debug($this->categories);
614 function ext_getCategoryLabelArray() {
615 // Returns array used for labels in the menu.
617 while(list($k,$v)=each($this->categories
)) {
619 $retArr[$k]=strtoupper($k)." (".count($v).")";
624 function ext_getTypeData($type) {
628 $retArr["type"]="string";
630 $m=strcspn ($type," [");
631 $retArr["type"]=strtolower(substr($type,0,$m));
632 if (t3lib_div
::inList("int,options,file,boolean,offset",$retArr["type"])) {
633 $p=trim(substr($type,$m));
634 ereg("\[(.*)\]",$p,$reg);
637 $retArr["paramstr"]=$p;
638 switch($retArr["type"]) {
640 if (substr($retArr["paramstr"],0,1)=="-") {
641 $retArr["params"]=t3lib_div
::intExplode("-",substr($retArr["paramstr"],1));
642 $retArr["params"][0]=intval("-".$retArr["params"][0]);
644 $retArr["params"]=t3lib_div
::intExplode("-",$retArr["paramstr"]);
646 $retArr["paramstr"]=$retArr["params"][0]." - ".$retArr["params"][1];
649 $retArr["params"]=explode(",",$retArr["paramstr"]);
658 function ext_getTSCE_config($category) {
659 $catConf=$this->setup
["constants"]["TSConstantEditor."][$category."."];
661 if (is_array($catConf)) {
663 while(list($key,$val)=each($catConf)) {
666 $out["imagetag"] = $this->ext_getTSCE_config_image($catConf["image"]);
674 if (t3lib_div
::testInt($key)) {
675 $constRefs = explode(",",$val);
677 while(list(,$const)=each($constRefs)) {
679 if ($const && $const<=20) {
680 $out["constants"][$const].=$this->ext_getKeyImage($key);
688 $this->helpConfig
=$out;
690 function ext_getKeyImage($key) {
691 return '<img src="'.$this->ext_localWebGfxPrefix
.'gfx/'.$key.'.gif" align="top" hspace=2>';
693 function ext_getTSCE_config_image($imgConf) {
694 if (substr($imgConf,0,4)=="gfx/") {
695 $iFile=$this->ext_localGfxPrefix
.$imgConf;
696 $tFile=$this->ext_localWebGfxPrefix
.$imgConf;
697 } elseif (substr($imgConf,0,4)=='EXT:') {
698 $iFile = t3lib_div
::getFileAbsFileName($imgConf);
700 $f = substr($iFile,strlen(PATH_site
));
701 $tFile="../".$GLOBALS["BACK_PATH"].$f;
704 $f = "uploads/tf/".$this->extractFromResources($this->setup
["resources"],$imgConf);
706 $tFile="../".$GLOBALS["BACK_PATH"].$f;
708 $imageInfo=@getImagesize
($iFile);
709 return '<img src="'.$tFile.'" '.$imageInfo[3].'>';
711 function ext_resourceDims() {
712 if ($this->setup
["resources"]) {
713 $rArr=explode(",",$this->setup
["resources"]);
714 while(list($c,$val)=each($rArr)) {
716 $theFile = PATH_site
."uploads/tf/".$val;
717 if ($val && @is_file
($theFile)) {
718 $imgInfo = @getimagesize
($theFile);
720 if (is_array($imgInfo)) {
721 $this->resourceDimensions
[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
725 reset($this->dirResources
);
726 while(list($c,$val)=each($this->dirResources
)) {
728 $imgInfo = @getimagesize
(PATH_site
.$val);
729 if (is_array($imgInfo)) {
730 $this->resourceDimensions
[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
734 function ext_readDirResources($path) {
736 if ($path && substr($path,0,10)=="fileadmin/") {
737 $path = ereg_replace("\/$","",$path);
738 $this->readDirectory(PATH_site
.$path);
741 function readDirectory($path,$type="file") {
746 while($entry=$d->read()) {
747 if ($entry!="." && $entry!="..") {
748 $wholePath = $path."/".$entry; // Because of odd PHP-error where <BR>-tag is sometimes placed after a filename!!
749 if (@file_exists
($wholePath) && (!$type ||
filetype($wholePath)==$type)) {
750 $fI = t3lib_div
::split_fileref($wholePath);
751 $this->dirResources
[]=substr($wholePath,strlen(PATH_site
));
759 function ext_fNandV($params) {
760 $fN='data['.$params["name"].']';
761 $fV=$params["value"];
762 if (ereg("^{[\$][a-zA-Z0-9\.]*}$",trim($fV),$reg)) { // Values entered from the constantsedit cannot be constants! 230502; removed \{ and set {
765 $fV=htmlspecialchars($fV);
767 return array($fN,$fV,$params);
769 function ext_printFields($theConstants,$category) {
770 // This functions returns the HTML-code that creates the editor-layout of the module.
771 reset($theConstants);
774 if (is_array($this->categories
[$category])) {
776 $help=$this->helpConfig
;
777 $this->rArr
=explode(",",$this->setup
["resources"].",".implode($this->dirResources
,","));
779 asort($this->categories
[$category]);
780 while(list($name,$type)=each($this->categories
[$category])) {
781 $params = $theConstants[$name];
782 if (is_array($params)) {
783 if ($subcat!=$params["subcat_name"]) {
784 $subcat=$params["subcat_name"];
785 $subcat_name = $params["subcat_name"] ?
$this->subCategories
[$params["subcat_name"]][0] : "Others";
787 $output.='<td colspan=2 bgColor="'.$GLOBALS["SOBE"]->doc
->bgColor4
.'"><div align="center"><b>'.$subcat_name.'</b></div></td>';
791 // if (substr($params["value"],0,2)!='{$') {
792 $label=$GLOBALS["LANG"]->sL($params["label"]);
793 $label_parts = explode(":",$label,2);
794 if (count($label_parts)==2) {
795 $head=trim($label_parts[0]);
796 $body=trim($label_parts[1]);
798 $head=trim($label_parts[0]);
801 if (strlen($head)>35) {
802 if (!$body) {$body=$head;}
803 $head=t3lib_div
::fixed_lgd($head,35);
805 $typeDat=$this->ext_getTypeData($params["type"]);
808 $raname = substr(md5($params["name"]),0,10);
809 $aname="'".$raname."'";
810 if ($this->ext_dontCheckIssetValues ||
isset($this->objReg
[$params["name"]])) {
812 list($fN,$fV,$params)=$this->ext_fNandV($params);
814 switch($typeDat["type"]) {
817 $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(5).' onChange="uFormUrl('.$aname.')">';
818 if ($typeDat["paramstr"]) {
819 $p_field.=' Range: '.$typeDat["paramstr"];
820 } elseif ($typeDat["type"]=="int+") {
821 $p_field.=' Range: 0 - ';
823 $p_field.=' (Integer)';
827 $colorNames=explode(",",",".$this->HTMLcolorList
);
829 while(list(,$val)=each($colorNames)) {
831 if ($val==strtolower($params["value"])) {$sel=" selected";}
832 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.'</option>';
834 $p_field='<select name="C'.$fN.'" onChange="document.'.$this->ext_CEformName
.'[\''.$fN.'\'].value=this.options[this.selectedIndex].value; uFormUrl('.$aname.');">'.$p_field.'</select>';
836 $p_field.='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(7).' onChange="uFormUrl('.$aname.')">';
839 $wArr = explode("|",$fV);
840 $p_field='<input type="text" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(29).' onChange="uFormUrl('.$aname.')">';
842 $p_field.='<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(15).' onChange="uFormUrl('.$aname.')">';
845 $wArr = explode(",",$fV);
846 $labels = t3lib_div
::trimExplode(",",$typeDat["paramstr"]);
847 $p_field=($labels[0]?
$labels[0]:"x").':<input type="text" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
849 $p_field.=($labels[1]?
$labels[1]:"y").':<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
850 for ($aa=2;$aa<count($labels);$aa++
) {
852 $p_field.=' , '.$labels[$aa].':<input type="text" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
854 $p_field.='<input type="hidden" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'">';
859 if (is_array($typeDat["params"])) {
861 while(list(,$val)=each($typeDat["params"])) {
862 $vParts = explode("=",$val,2);
864 $val = isset($vParts[1]) ?
$vParts[1] : $vParts[0];
868 if ($val==$params["value"]) {$sel=" selected";}
869 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$GLOBALS["LANG"]->sL($label).'</option>';
871 $p_field='<select name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
875 $p_field='<input type="Hidden" name="'.$fN.'" value="0">';
876 $sel=""; if ($fV) {$sel=" checked";}
877 $p_field.='<input type="Checkbox" name="'.$fN.'" value="'.($typeDat["paramstr"]?
$typeDat["paramstr"]:1).'"'.$sel.' onClick="uFormUrl('.$aname.')">';
880 $p_field='<input type="Hidden" name="'.$fN.'" value="#">';
881 $sel=""; if (!$fV) {$sel=" checked";}
882 $p_field.='<input type="Checkbox" name="'.$fN.'" value=""'.$sel.' onClick="uFormUrl('.$aname.')">';
885 $p_field='<option value=""></option>';
886 // debug($params["value"]);
889 $selectThisFile = $this->extractFromResources($this->setup
["resources"],$params["value"]);
890 if ($params["value"] && !$selectThisFile) {
891 if (in_array($params["value"],$this->dirResources
)) {
892 $selectThisFile=$params["value"];
895 // debug($selectThisFile);
897 $extList = $typeDat["paramstr"];
898 $p_field='<option value="">('.$extList.')</option>';
899 if ($extList=="IMAGE_EXT") {
900 $extList = $GLOBALS["TYPO3_CONF_VARS"]["GFX"]["imagefile_ext"];
903 $onlineResourceFlag=$this->ext_defaultOnlineResourceFlag
;
905 while(list($c,$val)=each($this->rArr
)) {
907 $fI=t3lib_div
::split_fileref($val);
909 if ($val && (!$extList || t3lib_div
::inList($extList,$fI["fileext"]))) {
910 if ($onlineResourceFlag<=0 && substr($fI["path"],0,10)=="fileadmin/") {
911 if ($onlineResourceFlag<0) {
912 $p_field.='<option value=""></option>';
914 $p_field.='<option value="">__'.$fI["path"].'__:</option>';
915 $onlineResourceFlag=1;
917 $dims=$this->resourceDimensions
[$val];
920 // Check if $params["value"] is in the list of resources.
921 if ($selectThisFile && $selectThisFile==$val) {
923 if ($onlineResourceFlag<=0) {
924 $theImage=t3lib_BEfunc
::thumbCode(array("resources"=>$selectThisFile),"sys_template","resources",$GLOBALS["BACK_PATH"],"");
926 $theImage=t3lib_BEfunc
::thumbCode(array("resources"=>$fI["file"]),"sys_template","resources",$GLOBALS["BACK_PATH"],"",$fI["path"]);
930 if ($onlineResourceFlag<=0) {
931 $onlineResourceFlag--;
932 // Value is set with a *
933 $val = $this->ext_setStar($val);
934 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.$dims.'</option>';
936 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$fI["file"].$dims.'</option>';
940 if (trim($params["value"]) && !$selectThisFile) {
941 $val = $params["value"];
942 $p_field.='<option value=""></option>';
943 $p_field.='<option value="'.htmlspecialchars($val).'" selected>'.$val.'</option>';
946 $p_field='<select name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
949 if (!$this->ext_noCEUploadAndCopying
) {
951 $copyFile = $this->extractFromResources($this->setup
["resources"],$params["value"]);
953 if ($params["value"]) {
954 $copyFile=PATH_site
.$this->ext_detectAndFixExtensionPrefix($params["value"]);
957 // $copyFile=PATH_site."uploads/tf/".$copyFile;
961 if ($copyFile && @is_file
($copyFile)) {
962 $p_field.='<img src=clear.gif width=20 height=1><img src="'.$GLOBALS["BACK_PATH"].'gfx/clip_copy.gif" width="12" height="12" border="0"><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"])).'\'));}">';
966 $p_field.='<input type="file" name="upload_'.$fN.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth().' onChange="uFormUrl('.$aname.')">';
971 $fwidth= $typeDat["type"]=="small" ?
10 : 46;
972 $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth($fwidth).' onChange="uFormUrl('.$aname.')">';
976 if (!$this->ext_dontCheckIssetValues
) $p_field='<input type="Checkbox" name="check['.$params["name"].']" value="1"'.$checked.' onClick="uFormUrl('.$aname.')">'.$p_field;
977 if ($typeDat["type"]=="color" && substr($params["value"],0,2)!='{$') {
978 $p_field='<table border=0 cellpadding=0 cellspacing=0><tr><td nowrap>'.$p_field.'</td><td> </td><td bgcolor="'.$params["value"].'"><img src="clear.gif" width=50 height=10></td></tr></table>';
980 $p_field='<nobr>'.$p_field.'</nobr><br>';
983 $p_name = '<font color="#666666">['.$params["name"].']</font><BR>';
984 $p_dlabel='<font color="#666666"><b>Default:</b> '.htmlspecialchars($params["default_value"]).'</font><BR>';
985 $p_label = '<b>'.htmlspecialchars($head).'</b>';
986 $p_descrip = $body ?
htmlspecialchars($body)."<BR>" : "";
989 $output.='<td valign=top nowrap><a name="'.$raname.'"></a>'.$help["constants"][$params["name"]].$p_label.'</td>';
990 $output.='<td valign=top align="right">'.$p_name.'</td>';
993 $output.='<td colspan=2>'.$p_descrip.$p_field.$p_dlabel.'<br></td>';
997 debug("Error. Constant did not exits. Should not happen.");
1000 $output='<table border=0 cellpadding=0 cellspacing=0>'.$output.'</table>';
1005 // ***************************
1006 // Processing input values
1007 // ***************************
1008 function ext_regObjectPositions($constants) {
1009 // 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
1010 $this->raw
= explode(chr(10),$constants);
1013 $this->objReg
=array(); // resetting the objReg if the divider is found!!
1014 $this->ext_regObjects("");
1016 function ext_regObjects($pre) {
1017 // works with regObjectPositions. "expands" the names of the TypoScript objects
1018 while (isset($this->raw
[$this->rawP
])) {
1019 $line = ltrim($this->raw
[$this->rawP
]);
1020 if (strstr($line,$this->edit_divider
)) {
1021 $this->objReg
=array(); // resetting the objReg if the divider is found!!
1025 if (substr($line,0,1)=="[") {
1027 } elseif (strcspn($line,"}#/")!=0) {
1028 $varL = strcspn($line," {=<");
1029 $var=substr($line,0,$varL);
1030 $line = ltrim(substr($line,$varL));
1031 switch(substr($line,0,1)) {
1033 $this->objReg
[$pre.$var]=$this->rawP
-1;
1036 $this->ext_inBrace++
;
1037 $this->ext_regObjects($pre.$var.".");
1040 $this->lastComment
="";
1041 } elseif (substr($line,0,1)=="}") {
1042 $this->lastComment
="";
1043 $this->ext_inBrace
--;
1044 if ($this->ext_inBrace
<0) {
1045 $this->ext_inBrace
=0;
1053 function ext_putValueInConf($key, $var) {
1054 // Puts the value $var to the TypoScript value $key in the current lines of the templates.
1055 // If the $key is not found in the template constants field, a new line is inserted in the bottom.
1056 $theValue = " ".trim($var);
1057 if (isset($this->objReg
[$key])) {
1058 $lineNum = $this->objReg
[$key];
1059 $parts = explode("=",$this->raw
[$lineNum],2);
1060 if (count($parts)==2) {
1061 $parts[1]= $theValue;
1063 $this->raw
[$lineNum]=implode($parts,"=");
1065 $this->raw
[]=$key." =".$theValue;
1069 function ext_removeValueInConf($key) {
1070 // Removes the value in the configuration
1071 if (isset($this->objReg
[$key])) {
1072 $lineNum = $this->objReg
[$key];
1073 unset($this->raw
[$lineNum]);
1077 function ext_depthKeys($arr,$settings) {
1080 while(list($theK,$theV)=each($arr)) {
1081 $theKeyParts = explode(".",$theK);
1083 $c=count($theKeyParts);
1085 while(list(,$p)=each($theKeyParts)) {
1087 $depth.=($depth?
".":"").$p;
1088 $tsbrArray[$depth]= ($c==$a) ?
$theV : 1;
1093 while(list($theK,$theV)=each($tsbrArray)) {
1095 $settings[$theK] = 1;
1097 unset($settings[$theK]);
1102 function ext_procesInput($http_post_vars,$http_post_files,$theConstants,$tplRow) {
1103 $data=$http_post_vars["data"];
1104 $check=$http_post_vars["check"];
1105 $copyResource=$http_post_vars["_copyResource"];
1106 $Wdata=$http_post_vars["Wdata"];
1107 $W2data=$http_post_vars["W2data"];
1108 $W3data=$http_post_vars["W3data"];
1109 $W4data=$http_post_vars["W4data"];
1110 $W5data=$http_post_vars["W5data"];
1112 if (is_array($data)) {
1114 while(list($key,$var)=each($data)) {
1115 if (isset($theConstants[$key])) {
1116 if ($this->ext_dontCheckIssetValues ||
isset($check[$key])) { // If checkbox is set, update the value
1117 list($var) = explode(chr(10),stripslashes($var)); // exploding with linebreak, just to make sure that no multiline input is given!
1118 $typeDat=$this->ext_getTypeData($theConstants[$key]["type"]);
1119 switch($typeDat["type"]) {
1121 if ($typeDat["paramstr"]) {
1122 $var=t3lib_div
::intInRange($var,$typeDat["params"][0],$typeDat["params"][1]);
1128 $var=t3lib_div
::intInRange($var,0,10000);
1132 if($var && !t3lib_div
::inList($this->HTMLcolorList
,strtolower($var))) {
1133 $var = ereg_replace("[^A-Fa-f0-9]*","",$var);
1134 $col[]=HexDec(substr($var,0,2));
1135 $col[]=HexDec(substr($var,2,2));
1136 $col[]=HexDec(substr($var,4,2));
1137 $var="#".strtoupper(substr("0".DecHex($col[0]),-2).substr("0".DecHex($col[1]),-2).substr("0".DecHex($col[2]),-2));
1148 if (isset($Wdata[$key])) {
1149 $var.="|".stripslashes($Wdata[$key]);
1153 if (isset($Wdata[$key])) {
1154 $var=intval($var).",".intval($Wdata[$key]);
1155 if (isset($W2data[$key])) {
1156 $var.=",".intval($W2data[$key]);
1157 if (isset($W3data[$key])) {
1158 $var.=",".intval($W3data[$key]);
1159 if (isset($W4data[$key])) {
1160 $var.=",".intval($W4data[$key]);
1161 if (isset($W5data[$key])) {
1162 $var.=",".intval($W5data[$key]);
1171 $var = $typeDat["paramstr"] ?
$typeDat["paramstr"] : 1;
1175 if (!$this->ext_noCEUploadAndCopying
) {
1176 if ($http_post_files["upload_data"]["name"][$key] && $http_post_files["upload_data"]["tmp_name"][$key]!="none") {
1177 $var = $this->upload_copy_file(
1180 trim($http_post_files["upload_data"]["name"][$key]),
1181 $http_post_files["upload_data"]["tmp_name"][$key]
1184 if ($copyResource[$key]) {
1185 $var = $this->upload_copy_file(
1188 basename($copyResource[$key]),
1195 if ($this->ext_printAll ||
strcmp($theConstants[$key]["value"],$var)) {
1196 $this->ext_putValueInConf($key, $var); // Put value in, if changed.
1198 unset($check[$key]); // Remove the entry because it has been "used"
1200 $this->ext_removeValueInConf($key);
1205 // 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...
1206 if (!$this->ext_dontCheckIssetValues
&& is_array($check)) {
1208 while(list($key,$var)=each($check)) {
1209 if (isset($theConstants[$key])) {
1210 $dValue = $theConstants[$key]["default_value"];
1212 $this->ext_putValueInConf($key, $dValue);
1217 // debug($this->objReg);
1219 function upload_copy_file($typeDat,&$tplRow,$theRealFileName,$tmp_name) {
1221 $extList = $typeDat["paramstr"];
1222 if ($extList=="IMAGE_EXT") {
1223 $extList = $GLOBALS["TYPO3_CONF_VARS"]["GFX"]["imagefile_ext"];
1225 $fI=t3lib_div
::split_fileref($theRealFileName);
1226 if ($theRealFileName && (!$extList || t3lib_div
::inList($extList,$fI["fileext"]))) {
1228 $alternativeFileName=array();
1229 $alternativeFileName[$tmp_name] = $theRealFileName;
1230 // Making list of resources
1231 $resList = $tplRow["resources"];
1232 $resList = $tmp_name.",".$resList;
1233 $resList=implode(t3lib_div
::trimExplode(",",$resList,1),",");
1234 // Making data-array
1236 $recData["sys_template"][$tplRow["uid"]]["resources"] = $resList;
1238 $tce = t3lib_div
::makeInstance("t3lib_TCEmain");
1239 $tce->stripslashes_values
=0;
1240 $tce->alternativeFileName
= $alternativeFileName;
1241 $tce->start($recData,Array());
1242 $tce->process_datamap();
1244 $tmpRow = t3lib_BEfunc
::getRecord("sys_template",$tplRow["uid"],"resources");
1245 $tplRow["resources"] = $tmpRow["resources"];
1247 // Setting the value
1248 $var = $this->ext_setStar($theRealFileName);
1252 function ext_prevPageWithTemplate($id,$perms_clause) {
1253 $rootLine = t3lib_BEfunc
::BEgetRootLine($id,$perms_clause?
" AND ".$perms_clause:"");
1255 while(list(,$p)=each($rootLine)) {
1256 if ($this->ext_getFirstTemplate($p["uid"])) {
1261 function ext_setStar($val) {
1262 $fParts = explode(".",strrev($val),2);
1263 $val=ereg_replace("_[0-9][0-9]$","",strrev($fParts[1]))."*.".strrev($fParts[0]);
1266 function ext_detectAndFixExtensionPrefix($value) {
1267 if (substr($value,0,4)=="EXT:") {
1268 $parts = explode("/",substr($value,4),2);
1270 $extPath = t3lib_extMgm
::siteRelPath($parts[0]);
1271 $value = $extPath.$parts[1];
1280 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE
]["XCLASS"]["t3lib/class.t3lib_tsparser_ext.php"]) {
1281 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]["XCLASS"]["t3lib/class.t3lib_tsparser_ext.php"]);