00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00090 require_once(PATH_t3lib."class.t3lib_tstemplate.php");
00091
00092
00093
00094
00095
00096
00097
00105 class t3lib_tsparser_ext extends t3lib_TStemplate {
00106
00107 var $edit_divider = "###MOD_TS:EDITABLE_CONSTANTS###";
00108 var $HTMLcolorList = "aqua,black,blue,fuchsia,gray,green,lime,maroon,navy,olive,purple,red,silver,teal,yellow,white";
00109
00110
00111 var $categories = array(
00112 "basic" => array(),
00113 "menu" => array(),
00114 "content" => array(),
00115 "page" => array(),
00116 "advanced" => array(),
00117 "all" => array()
00118 );
00119 var $subCategories = array(
00120
00121 "enable" => Array("Enable features", "a"),
00122 "dims" => Array("Dimensions, widths, heights, pixels", "b"),
00123 "file" => Array("Files", "c"),
00124 "typo" => Array("Typography", "d"),
00125 "color" => Array("Colors", "e"),
00126 "links" => Array("Links and targets", "f"),
00127 "language" => Array("Language specific constants", "g"),
00128
00129
00130 "cheader" => Array("Content: 'Header'", "ma"),
00131 "cheader_g" => Array("Content: 'Header', Graphical", "ma"),
00132 "ctext" => Array("Content: 'Text'", "mb"),
00133
00134 "cimage" => Array("Content: 'Image'", "md"),
00135 "cbullets" => Array("Content: 'Bullet list'", "me"),
00136 "ctable" => Array("Content: 'Table'", "mf"),
00137 "cuploads" => Array("Content: 'Filelinks'", "mg"),
00138 "cmultimedia" => Array("Content: 'Multimedia'", "mh"),
00139 "cmailform" => Array("Content: 'Form'", "mi"),
00140 "csearch" => Array("Content: 'Search'", "mj"),
00141 "clogin" => Array("Content: 'Login'", "mk"),
00142 "csplash" => Array("Content: 'Textbox'", "ml"),
00143 "cmenu" => Array("Content: 'Menu/Sitemap'", "mm"),
00144 "cshortcut" => Array("Content: 'Insert records'", "mn"),
00145 "clist" => Array("Content: 'List of records'", "mo"),
00146 "cscript" => Array("Content: 'Script'", "mp"),
00147 "chtml" => Array("Content: 'HTML'", "mq")
00148 );
00149 var $resourceDimensions = array();
00150 var $dirResources = array();
00151
00152
00153
00154 var $backend_info=1;
00155
00156
00157 var $ext_inBrace=0;
00158
00159
00160 var $tsbrowser_searchKeys = array();
00161 var $tsbrowser_depthKeys = array();
00162 var $constantMode="";
00163 var $regexMode="";
00164 var $fixedLgd="";
00165 var $resourceCheck=0;
00166 var $ext_lineNumberOffset=0;
00167 var $ext_localGfxPrefix="";
00168 var $ext_localWebGfxPrefix="";
00169 var $ext_expandAllNotes=0;
00170 var $ext_noPMicons=0;
00171 var $ext_noSpecialCharsOnLabels=0;
00172 var $ext_listOfTemplatesArr=array();
00173 var $ext_lineNumberOffset_mode="";
00174 var $ext_dontCheckIssetValues=0;
00175 var $ext_noCEUploadAndCopying=0;
00176 var $ext_printAll=0;
00177 var $ext_CEformName="forms[0]";
00178 var $ext_defaultOnlineResourceFlag=0;
00179 var $doNotSortCategoriesBeforeMakingForm = FALSE;
00180
00181
00182 var $templateTitles=array();
00183
00184
00194 function flattenSetup($setupArray, $prefix, $resourceFlag) {
00195 if (is_array($setupArray)) {
00196 $this->getFileName_backPath=PATH_site;
00197 reset($setupArray);
00198 while(list($key,$val)=each($setupArray)) {
00199 if ($prefix || substr($key,0,16)!="TSConstantEditor") {
00200 if (is_array($val)) {
00201 $this->flattenSetup($val,$prefix.$key, ($key=="file."));
00202 } elseif ($resourceFlag && $this->resourceCheck) {
00203 $this->flatSetup[$prefix.$key] = $this->getFileName($val);
00204 if ($this->removeFromGetFilePath && substr($this->flatSetup[$prefix.$key],0,strlen($this->removeFromGetFilePath))==$this->removeFromGetFilePath) {
00205 $this->flatSetup[$prefix.$key] = substr($this->flatSetup[$prefix.$key],strlen($this->removeFromGetFilePath));
00206 }
00207 } else {
00208 $this->flatSetup[$prefix.$key] = $val;
00209 }
00210 }
00211 }
00212 }
00213 }
00214
00221 function substituteConstants($all) {
00222 $this->Cmarker = substr(md5(uniqid("")),0,6);
00223
00224 return preg_replace_callback('/\{\$(.[^}]+)\}/', array($this, 'substituteConstantsCallBack'), $all);
00225 }
00226
00234 function substituteConstantsCallBack($matches) {
00235 switch($this->constantMode) {
00236 case 'const':
00237 $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ?
00238 '##'.$this->Cmarker.'_B##'.$matches[0].'##'.$this->Cmarker.'_E##' :
00239 $matches[0];
00240 break;
00241 case 'subst':
00242 $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ?
00243 '##'.$this->Cmarker.'_B##'.$this->flatSetup[$matches[1]].'##'.$this->Cmarker.'_E##' :
00244 $matches[0];
00245 break;
00246 case 'untouched':
00247 $ret_val = $matches[0];
00248 break;
00249 default:
00250 $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ?
00251 $this->flatSetup[$matches[1]] :
00252 $matches[0];
00253 }
00254
00255 return $ret_val;
00256 }
00257
00264 function substituteCMarkers($all) {
00265 switch($this->constantMode) {
00266 case "const":
00267 $all = str_replace('##'.$this->Cmarker.'_B##', '<font color="green"><B>', $all);
00268 $all = str_replace('##'.$this->Cmarker.'_E##', '</b></font>', $all);
00269 break;
00270 case "subst":
00271 $all = str_replace('##'.$this->Cmarker.'_B##', '<font color="green"><B>', $all);
00272 $all = str_replace('##'.$this->Cmarker.'_E##', '</b></font>', $all);
00273 break;
00274 default:
00275 $all = $all;
00276 break;
00277 }
00278 return $all;
00279 }
00280
00287 function generateConfig_constants() {
00288
00289 $this->setup['resources'] = $this->resources;
00290 $this->setup['sitetitle'] = $this->sitetitle;
00291
00292
00293 $constants = t3lib_div::makeInstance("t3lib_TSparser");
00294 $constants->regComments=1;
00295 $constants->setup = $this->const;
00296 $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup);
00297
00298 $matchObj = t3lib_div::makeInstance("t3lib_matchCondition");
00299
00300 $matchObj->matchAll=1;
00301
00302 $c=0;
00303 $cc=count($this->constants);
00304 reset($this->constants);
00305 while (list(,$str)=each($this->constants)) {
00306 $c++;
00307 if ($c==$cc) {
00308 if (strstr($str,$this->edit_divider)) {
00309 $parts = explode($this->edit_divider,$str,2);
00310 $str=$parts[1];
00311 $constants->parse($parts[0],$matchObj);
00312 }
00313 $this->flatSetup = Array();
00314 $this->flattenSetup($constants->setup,"","");
00315 $defaultConstants=$this->flatSetup;
00316 }
00317 $constants->parse($str,$matchObj);
00318 }
00319
00320 $this->flatSetup = Array();
00321 $this->flattenSetup($constants->setup,"","");
00322 $this->setup["constants"] = $constants->setup;
00323
00324 return $this->ext_compareFlatSetups($defaultConstants);
00325 }
00326
00334 function ext_getSetup($theSetup,$theKey) {
00335 $parts = explode(".",$theKey,2);
00336
00337
00338 if (strcmp($parts[0],"") && is_array($theSetup[$parts[0]."."])) {
00339
00340 if (strcmp(trim($parts[1]),"")) {
00341
00342 return $this->ext_getSetup($theSetup[$parts[0]."."],trim($parts[1]));
00343 } else {
00344 return array($theSetup[$parts[0]."."], $theSetup[$parts[0]]);
00345 }
00346 } else {
00347 if (strcmp(trim($theKey),"")) {
00348 return array(array(),$theSetup[$theKey]);
00349 } else {
00350 return array($theSetup,"");
00351 }
00352 }
00353 }
00354
00366 function ext_getObjTree($arr, $depth_in, $depthData, $parentType='',$parentValue='', $alphaSort='0') {
00367 $HTML="";
00368 $a=0;
00369
00370 reset($arr);
00371 if($alphaSort == '1') {
00372 ksort($arr);
00373 }
00374 $keyArr_num=array();
00375 $keyArr_alpha=array();
00376 while (list($key,)=each($arr)) {
00377 if (substr($key,-2)!="..") {
00378 $key=ereg_replace("\.$","",$key);
00379 if (substr($key,-1)!=".") {
00380 if (t3lib_div::testInt($key)) {
00381 $keyArr_num[$key]=$arr[$key];
00382 } else {
00383 $keyArr_alpha[$key]=$arr[$key];
00384 }
00385 }
00386 }
00387 }
00388 ksort($keyArr_num);
00389 $keyArr=$keyArr_num+$keyArr_alpha;
00390 reset($keyArr);
00391 $c=count($keyArr);
00392 if ($depth_in) {$depth_in = $depth_in.".";}
00393
00394
00395
00396
00397 while (list($key,)=each($keyArr)) {
00398 $a++;
00399 $depth=$depth_in.$key;
00400 if ($this->bType!="const" || substr($depth,0,1)!="_") {
00401 $goto = substr(md5($depth),0,6);
00402
00403 $deeper = (is_array($arr[$key."."]) && ($this->tsbrowser_depthKeys[$depth] || $this->ext_expandAllNotes)) ? 1 : 0;
00404 $PM = "join";
00405 $LN = ($a==$c)?"blank":"line";
00406 $BTM = ($a==$c)?"bottom":"";
00407 $PM = is_array($arr[$key."."]) && !$this->ext_noPMicons ? ($deeper ? "minus":"plus") : "join";
00408
00409 $HTML.=$depthData;
00410 $theIcon='<img src="'.$GLOBALS["BACK_PATH"].'gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border="0" alt="" />';
00411 if ($PM=="join") {
00412 $HTML.=$theIcon;
00413 } else {
00414 $aHref='index.php?id='.$GLOBALS["SOBE"]->id.'&tsbr['.$depth.']='.($deeper?0:1).'#'.$goto;
00415 $HTML.='<a name="'.$goto.'" href="'.htmlspecialchars($aHref).'">'.$theIcon.'</a>';
00416 }
00417
00418 $label = $key;
00419 if (t3lib_div::inList("types,resources,sitetitle",$depth) && $this->bType=="setup") {
00420 $label='<font color="#666666">'.$label.'</font>';
00421 } else {
00422 if ($this->linkObjects) {
00423 $aHref = 'index.php?id='.$GLOBALS["SOBE"]->id.'&sObj='.$depth;
00424 if ($this->bType!="const") {
00425 $ln = is_array($arr[$key.'.ln..']) ? 'Defined in: '.$this->lineNumberToScript($arr[$key.'.ln..']) : 'N/A';
00426 } else {
00427 $ln = '';
00428 }
00429
00430 if ($this->tsbrowser_searchKeys[$depth] & 4) { $label = '<b><font color="red">'.$label.'</font></b>'; }
00431 $label = '<a href="'.htmlspecialchars($aHref).'" title="'.htmlspecialchars($ln).'">'.$label.'</a>';
00432 }
00433 }
00434
00435 $HTML.="[".$label."]";
00436
00437 if (isset($arr[$key])) {
00438 $theValue = $arr[$key];
00439 if ($this->fixedLgd) {
00440 $imgBlocks = ceil(1+strlen($depthData)/77);
00441 $lgdChars = 68-ceil(strlen("[".$key."]")*0.8)-$imgBlocks*3;
00442 $theValue = $this->ext_fixed_lgd($theValue,$lgdChars);
00443 }
00444 if ($this->tsbrowser_searchKeys[$depth] & 2) {
00445 $HTML.=' = <b><font color="red">'.$this->makeHtmlspecialchars($theValue).'</font></b>';
00446 } else {
00447 $HTML.=" = <b>".$this->makeHtmlspecialchars($theValue)."</b>";
00448 }
00449 if ($this->ext_regComments && isset($arr[$key.'..'])) {
00450 $comment = $arr[$key.'..'];
00451 $comment = preg_replace('/[\r\n]/', ' ', $comment);
00452 $comment = preg_replace('/[#\*]{2,}/', '', $comment);
00453 $comment = preg_replace('/^[#\*\s]+/', '# ', $comment);
00454 $HTML.= ' <span class="comment">'.trim($comment).'</span>';
00455 }
00456 }
00457 $HTML.="<br />";
00458
00459 if ($deeper) {
00460 $HTML.=$this->ext_getObjTree($arr[$key."."], $depth, $depthData.'<img src="'.$GLOBALS["BACK_PATH"].'gfx/ol/'.$LN.'.gif" width="18" height="16" align="top" alt="" />', '' , $arr[$key], $alphaSort);
00461 }
00462 }
00463 }
00464 return $HTML;
00465 }
00466
00473 function lineNumberToScript($lnArr) {
00474 if (!is_array($this->lnToScript)) {
00475 $this->lnToScript = array();
00476 $c=1;
00477 $c+=substr_count($GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'],chr(10))+2;
00478 $this->lnToScript[$c] = '[Default]';
00479
00480 foreach($this->hierarchyInfoToRoot as $info) {
00481 $c+=$info['configLines']+1;
00482 $this->lnToScript[$c] = $info['title'];
00483 }
00484 }
00485
00486 foreach($lnArr as $k => $ln) {
00487 foreach($this->lnToScript as $endLn => $title) {
00488 if ($endLn >= intval($ln)) {
00489 $lnArr[$k] = '"'.$title.'", '.$ln;
00490 break;
00491 }
00492 }
00493 }
00494
00495 return implode('; ',$lnArr);
00496 }
00497
00504 function makeHtmlspecialchars($theValue){
00505 return $this->ext_noSpecialCharsOnLabels ? $theValue : htmlspecialchars($theValue);
00506 }
00507
00517 function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray) {
00518 reset($arr);
00519 $keyArr=array();
00520 while (list($key,)=each($arr)) {
00521 $key=ereg_replace('\.$','',$key);
00522 if (substr($key,-1)!='.') {
00523 $keyArr[$key]=1;
00524 }
00525 }
00526 reset($keyArr);
00527 // asort($keyArr);
00528 $c=count($keyArr);
00529 if ($depth_in) { $depth_in = $depth_in.'.'; }
00530 while (list($key,)=each($keyArr)) {
00531 $depth=$depth_in.$key;
00532 $deeper = is_array($arr[$key."."]);
00533
00534 if ($this->regexMode) {
00535 if (ereg($searchString,$arr[$key])) { // The value has matched
00536 $this->tsbrowser_searchKeys[$depth]+=2;
00537 }
00538 if (ereg($searchString,$key)) { // The key has matched
00539 $this->tsbrowser_searchKeys[$depth]+=4;
00540 }
00541 if (ereg($searchString,$depth_in)) { // Just open this subtree if the parent key has matched the search
00542 $this->tsbrowser_searchKeys[$depth]=1;
00543 }
00544 } else {
00545 if (stristr($arr[$key],$searchString)) { // The value has matched
00546 $this->tsbrowser_searchKeys[$depth]+=2;
00547 }
00548 if (stristr($key,$searchString)) { // The key has matches
00549 $this->tsbrowser_searchKeys[$depth]+=4;
00550 }
00551 if (stristr($depth_in,$searchString)) { // Just open this subtree if the parent key has matched the search
00552 $this->tsbrowser_searchKeys[$depth]=1;
00553 }
00554 }
00555
00556 if ($deeper) {
00557 $cS = count($this->tsbrowser_searchKeys);
00558 $keyArray = $this->ext_getSearchKeys($arr[$key.'.'], $depth, $searchString, $keyArray);
00559 if ($cS != count($this->tsbrowser_searchKeys)) {
00560 $keyArray[$depth]=1;
00561 }
00562 }
00563 }
00564 return $keyArray;
00565 }
00566
00573 function ext_getRootlineNumber($pid) {
00574 if ($pid && is_array($GLOBALS["rootLine"])) {
00575 reset($GLOBALS["rootLine"]);
00576 while(list($key,$val)=each($GLOBALS["rootLine"])) {
00577 if ($val['uid']==$pid) return $key;
00578 }
00579 }
00580 }
00581
00591 function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0) {
00592 reset($arr);
00593 $keyArr=array();
00594 while (list($key,)=each($arr)) {
00595 $key=ereg_replace("\.$","",$key);
00596 if (substr($key,-1)!=".") {
00597 $keyArr[$key]=1;
00598 }
00599 }
00600 reset($keyArr);
00601 $a=0;
00602 $c=count($keyArr);
00603 while (list($key,)=each($keyArr)) {
00604 $HTML="";
00605 $a++;
00606 $deeper = is_array($arr[$key."."]);
00607 $row=$arr[$key];
00608
00609 $PM = "join";
00610 $LN = ($a==$c)?"blank":"line";
00611 $BTM = ($a==$c)?"top":"";
00612 $PM = "join";
00613
00614 $HTML.=$depthData;
00615 $icon = substr($row["templateID"],0,3)=="sys" ? t3lib_iconWorks::getIcon("sys_template",array("root"=>$row["root"])) :
00616 (substr($row["templateID"],0,6)=="static" ? t3lib_iconWorks::getIcon("static_template",array()) : 'gfx/i/default.gif');
00617 $alttext= "[".$row['templateID']."]";
00618 $alttext.= $row['pid'] ? " - ".t3lib_BEfunc::getRecordPath($row['pid'],$GLOBALS["SOBE"]->perms_clause,20) : "";
00619 if (in_array($row['templateID'],$this->clearList_const) || in_array($row['templateID'],$this->clearList_setup)) {
00620 $A_B='<a href="index.php?id='.$GLOBALS["SOBE"]->id.'&template='.$row['templateID'].'">';
00621 $A_E="</A>";
00622 } else {
00623 $A_B="";
00624 $A_E="";
00625 }
00626 $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." ";
00627 $RL = $this->ext_getRootlineNumber($row['pid']);
00628 $keyArray[] = '<tr>
00629 <td nowrap>'.$HTML.'</td>
00630 <td align=center>'.($row["root"]?"<b>X</b>":"").' </td>
00631 <td align=center'.$row["bgcolor_setup"].'>'.fw(($row["clConf"]?"<b>X</b>":"")." ").'</td>
00632 <td align=center'.$row["bgcolor_const"].'>'.fw(($row["clConst"]?"<b>X</b>":"")." ").'</td>
00633 <td>'.($row["pid"]?" ".$row["pid"].(strcmp($RL,"")?" (".$RL.")":"")." ":"").'</td>
00634 <td>'.($row["next"]?" ".$row["next"]." ":"").'</td>
00635 </tr>';
00636 if ($deeper) {
00637 $keyArray = $this->ext_getTemplateHierarchyArr($arr[$key."."], $depthData.($first?'':'<IMG src="'.$GLOBALS["BACK_PATH"].'gfx/ol/'.$LN.'.gif" width="18" height="16" align="top">'), $keyArray);
00638 }
00639 }
00640 return $keyArray;
00641 }
00642
00650 function ext_process_hierarchyInfo($depthDataArr,&$pointer) {
00651 $parent = $this->hierarchyInfo[$pointer-1]['templateParent'];
00652 while ($pointer>0 && $this->hierarchyInfo[$pointer-1]['templateParent']==$parent) {
00653 $pointer--;
00654 $row = $this->hierarchyInfo[$pointer];
00655
00656 $depthDataArr[$row['templateID']]=$row;
00657 $depthDataArr[$row['templateID']]["bgcolor_setup"] = isset($this->clearList_setup_temp[$row['templateID']])?' class="bgColor5"':'';
00658 $depthDataArr[$row['templateID']]["bgcolor_const"] = isset($this->clearList_const_temp[$row['templateID']])?' class="bgColor5"':'';
00659 unset($this->clearList_setup_temp[$row['templateID']]);
00660 unset($this->clearList_const_temp[$row['templateID']]);
00661 $this->templateTitles[$row['templateID']]=$row["title"];
00662
00663 if ($row['templateID']==$this->hierarchyInfo[$pointer-1]['templateParent']) {
00664 $depthDataArr[$row['templateID']."."] = $this->ext_process_hierarchyInfo(array(), $pointer);
00665 }
00666 }
00667 return $depthDataArr;
00668 }
00669
00681 function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0) {
00682 $all="";
00683 reset($config);
00684 while (list(,$str)=each($config)) {
00685 $all.="\n[GLOBAL]\n".$str;
00686 }
00687
00688 if ($syntaxHL) {
00689 $all = ereg_replace("^[^".chr(10)."]*.","",$all);
00690 $all = chop($all);
00691 $tsparser = t3lib_div::makeInstance("t3lib_TSparser");
00692 $tsparser->lineNumberOffset=$this->ext_lineNumberOffset+1;
00693 return $tsparser->doSyntaxHighlight($all,$lineNumbers?array($this->ext_lineNumberOffset+1):'',$syntaxHLBlockmode);
00694 } else {
00695 return $this->ext_formatTS($all,$lineNumbers,$comments,$crop);
00696 }
00697 }
00698
00708 function ext_fixed_lgd($string,$chars) {
00709 if ($chars >= 4) {
00710 if(strlen($string)>$chars) {
00711 return substr($string, 0, $chars-3)."...";
00712 }
00713 }
00714 return $string;
00715 }
00716
00724 function ext_lnBreakPointWrap($ln,$str) {
00725 return '<A href="#" onClick="return brPoint('.$ln.','.($this->ext_lineNumberOffset_mode=="setup"?1:0).');">'.$str.'</a>';
00726 }
00727
00737 function ext_formatTS($input, $ln, $comments=1, $crop=0) {
00738 $input = ereg_replace("^[^".chr(10)."]*.","",$input);
00739 $input = chop($input);
00740 $cArr = explode(chr(10),$input);
00741
00742 reset($cArr);
00743 $n = ceil(log10(count($cArr)+$this->ext_lineNumberOffset));
00744 $lineNum="";
00745 while(list($k,$v)=each($cArr)) {
00746 $lln=$k+$this->ext_lineNumberOffset+1;
00747 if ($ln) $lineNum = $this->ext_lnBreakPointWrap($lln,str_replace(" ",' ',sprintf("% ".$n."d",$lln))).": ";
00748 $v=htmlspecialchars($v);
00749 if ($crop) {$v=$this->ext_fixed_lgd($v,($ln?71:77));}
00750 $cArr[$k] = $lineNum.str_replace(" ",' ',$v);
00751
00752 $firstChar = substr(trim($v),0,1);
00753 if ($firstChar=="[") {
00754 $cArr[$k] = '<font color="green"><b>'.$cArr[$k].'</b></font>';
00755 } elseif ($firstChar=="/" || $firstChar=="#") {
00756 if ($comments) {
00757 $cArr[$k] = '<span class="typo3-dimmed">'.$cArr[$k].'</span>';
00758 } else {
00759 unset($cArr[$k]);
00760 }
00761 }
00762
00763
00764 }
00765 $output = implode($cArr, "<BR>")."<BR>";
00766 return $output;
00767 }
00768
00776 function ext_getFirstTemplate($id,$template_uid=0) {
00777 // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
00778 if (intval($id)) {
00779 if ($template_uid) {
00780 $addC = " AND uid=".$template_uid;
00781 }
00782 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).$addC.' '.$this->whereClause, '', 'sorting', '1');
00783 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00784 t3lib_BEfunc::workspaceOL('sys_template',$row);
00785 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00786 return $row; // Returns the template row if found.
00787 }
00788 }
00789
00796 function ext_getAllTemplates($id) {
00797 // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
00798 if (intval($id)) {
00799 $outRes=array();
00800 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).' '.$this->whereClause, '', 'sorting');
00801 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00802 t3lib_BEfunc::workspaceOL('sys_template',$row);
00803 if (is_array($row)) $outRes[] = $row;
00804 }
00805 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00806 return $outRes; // Returns the template rows in an array.
00807 }
00808 }
00809
00817 function ext_compareFlatSetups($default) {
00818 $editableComments=array();
00819 reset($this->flatSetup);
00820 while(list($const,$value)=each($this->flatSetup)) {
00821 if (substr($const,-2)!=".." && isset($this->flatSetup[$const.".."])) {
00822 $comment = trim($this->flatSetup[$const.".."]);
00823 $c_arr = explode(chr(10),$comment);
00824 while(list($k,$v)=each($c_arr)) {
00825 $line=trim(ereg_replace("^[#\/]*","",$v));
00826 if ($line) {
00827 $parts = explode(";", $line);
00828 while(list(,$par)=each($parts)) {
00829 if (strstr($par,"=")) {
00830 $keyValPair =explode("=",$par,2);
00831 switch(trim(strtolower($keyValPair[0]))) {
00832 case "type":
00833 // Type:
00834 /*
00835 int (range; low-high, list: item,item,item = selector),
00836 boolean (check),
00837 string (default),
00838 wrap,
00839 html-color ...,
00840 file
00841 */
00842 $editableComments[$const]["type"] = trim($keyValPair[1]);
00843 break;
00844 case "cat":
00845 // list of categories.
00846 $catSplit=explode("/",strtolower($keyValPair[1]));
00847 $editableComments[$const]["cat"] = trim($catSplit[0]);
00848 $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.
00849 if ($catSplit[1] && isset($this->subCategories[$catSplit[1]])) {
00850 $editableComments[$const]["subcat_name"]=$catSplit[1];
00851 $editableComments[$const]["subcat"]=$this->subCategories[$catSplit[1]][1]."/".$catSplit[1]."/".trim($catSplit[2])."z";
00852 } else {
00853 $editableComments[$const]["subcat"]="x"."/".trim($catSplit[2])."z";
00854 }
00855 break;
00856 case "label":
00857 // label
00858 $editableComments[$const]["label"] = trim($keyValPair[1]);
00859 break;
00860 }
00861 }
00862 }
00863 }
00864 }
00865 }
00866 if (isset($editableComments[$const])) {
00867 $editableComments[$const]["name"]=$const;
00868 $editableComments[$const]["value"]=trim($value);
00869 if (isset($default[$const])) {
00870 $editableComments[$const]["default_value"]=trim($default[$const]);
00871 }
00872 }
00873 }
00874 return $editableComments;
00875 }
00876
00883 function ext_categorizeEditableConstants($editConstArray) {
00884 // Runs through the available constants and fills the $this->categories array with pointers and priority-info
00885 reset($editConstArray);
00886 while(list($constName,$constData)=each($editConstArray)) {
00887 if (!$constData["type"]) {$constData["type"]="string";}
00888 $cats = explode(",",$constData["cat"]);
00889 reset($cats);
00890 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...
00891 $theCat=trim($theCat);
00892 if ($theCat) {
00893 $this->categories[$theCat][$constName]=$constData["subcat"];
00894 // $this->categories["all"][$constName]=$constData["subcat"];
00895 }
00896 }
00897 }
00898 // debug($this->categories);
00899 }
00900
00906 function ext_getCategoryLabelArray() {
00907 // Returns array used for labels in the menu.
00908 $retArr = array();
00909 while(list($k,$v)=each($this->categories)) {
00910 if (count($v)) {
00911 $retArr[$k]=strtoupper($k)." (".count($v).")";
00912 }
00913 }
00914 return $retArr;
00915 }
00916
00923 function ext_getTypeData($type) {
00924 $retArr = array();
00925 $type=trim($type);
00926 if (!$type) {
00927 $retArr["type"]="string";
00928 } else {
00929 $m=strcspn ($type," [");
00930 $retArr["type"]=strtolower(substr($type,0,$m));
00931 if (t3lib_div::inList("int,options,file,boolean,offset",$retArr["type"])) {
00932 $p=trim(substr($type,$m));
00933 $reg = array();
00934 ereg("\[(.*)\]",$p,$reg);
00935 $p=trim($reg[1]);
00936 if ($p) {
00937 $retArr["paramstr"]=$p;
00938 switch($retArr["type"]) {
00939 case "int":
00940 if (substr($retArr["paramstr"],0,1)=="-") {
00941 $retArr["params"]=t3lib_div::intExplode("-",substr($retArr["paramstr"],1));
00942 $retArr["params"][0]=intval("-".$retArr["params"][0]);
00943 } else {
00944 $retArr["params"]=t3lib_div::intExplode("-",$retArr["paramstr"]);
00945 }
00946 $retArr["paramstr"]=$retArr["params"][0]." - ".$retArr["params"][1];
00947 break;
00948 case "options":
00949 $retArr["params"]=explode(",",$retArr["paramstr"]);
00950 break;
00951 }
00952 }
00953 }
00954 }
00955 // debug($retArr);
00956 return $retArr;
00957 }
00958
00965 function ext_getTSCE_config($category) {
00966 $catConf=$this->setup["constants"]["TSConstantEditor."][$category."."];
00967 $out=array();
00968 if (is_array($catConf)) {
00969 reset($catConf);
00970 while(list($key,$val)=each($catConf)) {
00971 switch($key) {
00972 case "image":
00973 $out["imagetag"] = $this->ext_getTSCE_config_image($catConf["image"]);
00974 break;
00975 case "description":
00976 case "bulletlist":
00977 case "header":
00978 $out[$key] = $val;
00979 break;
00980 default:
00981 if (t3lib_div::testInt($key)) {
00982 $constRefs = explode(",",$val);
00983 reset($constRefs);
00984 while(list(,$const)=each($constRefs)) {
00985 $const=trim($const);
00986 if ($const && $const<=20) {
00987 $out["constants"][$const].=$this->ext_getKeyImage($key);
00988 }
00989 }
00990 }
00991 break;
00992 }
00993 }
00994 }
00995 $this->helpConfig=$out;
00996 }
00997
01004 function ext_getKeyImage($key) {
01005 return '<img src="'.$this->ext_localWebGfxPrefix.'gfx/'.$key.'.gif" align="top" hspace=2>';
01006 }
01007
01014 function ext_getTSCE_config_image($imgConf) {
01015 if (substr($imgConf,0,4)=="gfx/") {
01016 $iFile=$this->ext_localGfxPrefix.$imgConf;
01017 $tFile=$this->ext_localWebGfxPrefix.$imgConf;
01018 } elseif (substr($imgConf,0,4)=='EXT:') {
01019 $iFile = t3lib_div::getFileAbsFileName($imgConf);
01020 if ($iFile) {
01021 $f = substr($iFile,strlen(PATH_site));
01022 $tFile=$GLOBALS["BACK_PATH"]."../".$f;
01023 }
01024 } else {
01025 $f = "uploads/tf/".$this->extractFromResources($this->setup["resources"],$imgConf);
01026 $iFile=PATH_site.$f;
01027 $tFile=$GLOBALS["BACK_PATH"]."../".$f;
01028 }
01029 $imageInfo=@getImagesize($iFile);
01030 return '<img src="'.$tFile.'" '.$imageInfo[3].'>';
01031 }
01032
01038 function ext_resourceDims() {
01039 if ($this->setup["resources"]) {
01040 $rArr=explode(",",$this->setup["resources"]);
01041 while(list($c,$val)=each($rArr)) {
01042 $val=trim($val);
01043 $theFile = PATH_site."uploads/tf/".$val;
01044 if ($val && @is_file($theFile)) {
01045 $imgInfo = @getimagesize($theFile);
01046 }
01047 if (is_array($imgInfo)) {
01048 $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
01049 }
01050 }
01051 }
01052 reset($this->dirResources);
01053 while(list($c,$val)=each($this->dirResources)) {
01054 $val=trim($val);
01055 $imgInfo = @getimagesize(PATH_site.$val);
01056 if (is_array($imgInfo)) {
01057 $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
01058 }
01059 }
01060 }
01061
01068 function ext_readDirResources($path) {
01069 $path=trim($path);
01070 if ($path && substr($path,0,10)=="fileadmin/") {
01071 $path = ereg_replace("\/$","",$path);
01072 $this->readDirectory(PATH_site.$path);
01073 }
01074 }
01075
01083 function readDirectory($path,$type="file") {
01084 if(@is_dir($path)) {
01085 $d = @dir($path);
01086 $tempArray=Array();
01087 if (is_object($d)) {
01088 while($entry=$d->read()) {
01089 if ($entry!="." && $entry!="..") {
01090 $wholePath = $path."/".$entry; // Because of odd PHP-error where <BR>-tag is sometimes placed after a filename!!
01091 if (@file_exists($wholePath) && (!$type || filetype($wholePath)==$type)) {
01092 $fI = t3lib_div::split_fileref($wholePath);
01093 $this->dirResources[]=substr($wholePath,strlen(PATH_site));
01094 }
01095 }
01096 }
01097 $d->close();
01098 }
01099 }
01100 }
01101
01108 function ext_fNandV($params) {
01109 $fN='data['.$params["name"].']';
01110 $fV=$params["value"];
01111 if (ereg("^{[\$][a-zA-Z0-9\.]*}$",trim($fV),$reg)) { // Values entered from the constantsedit cannot be constants! 230502; removed \{ and set {
01112 $fV="";
01113 }
01114 $fV=htmlspecialchars($fV);
01115
01116 return array($fN,$fV,$params);
01117 }
01118
01126 function ext_printFields($theConstants,$category) {
01127 // This functions returns the HTML-code that creates the editor-layout of the module.
01128 reset($theConstants);
01129 $output="";
01130 $subcat="";
01131 if (is_array($this->categories[$category])) {
01132
01133 $help=$this->helpConfig;
01134 $this->rArr=explode(",",$this->setup["resources"].",".implode($this->dirResources,","));
01135
01136 if (!$this->doNotSortCategoriesBeforeMakingForm) asort($this->categories[$category]);
01137 while(list($name,$type)=each($this->categories[$category])) {
01138 $params = $theConstants[$name];
01139 if (is_array($params)) {
01140 if ($subcat!=$params["subcat_name"]) {
01141 $subcat=$params["subcat_name"];
01142 $subcat_name = $params["subcat_name"] ? $this->subCategories[$params["subcat_name"]][0] : "Others";
01143 $output.='<tr>';
01144 $output.='<td colspan=2 class="bgColor4"><div align="center"><b>'.$subcat_name.'</b></div></td>';
01145 $output.='</tr>';
01146 }
01147
01148 // if (substr($params["value"],0,2)!='{$') {
01149 $label=$GLOBALS["LANG"]->sL($params["label"]);
01150 $label_parts = explode(":",$label,2);
01151 if (count($label_parts)==2) {
01152 $head=trim($label_parts[0]);
01153 $body=trim($label_parts[1]);
01154 } else {
01155 $head=trim($label_parts[0]);
01156 $body="";
01157 }
01158 if (strlen($head)>35) {
01159 if (!$body) {$body=$head;}
01160 $head=t3lib_div::fixed_lgd_cs($head,35);
01161 }
01162 $typeDat=$this->ext_getTypeData($params["type"]);
01163 $checked="";
01164 $p_field="";
01165 $raname = substr(md5($params["name"]),0,10);
01166 $aname="'".$raname."'";
01167 if ($this->ext_dontCheckIssetValues || isset($this->objReg[$params["name"]])) {
01168 $checked=" checked";
01169 list($fN,$fV,$params)=$this->ext_fNandV($params);
01170
01171 switch($typeDat["type"]) {
01172 case "int":
01173 case "int+":
01174 $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(5).' onChange="uFormUrl('.$aname.')">';
01175 if ($typeDat["paramstr"]) {
01176 $p_field.=' Range: '.$typeDat["paramstr"];
01177 } elseif ($typeDat["type"]=="int+") {
01178 $p_field.=' Range: 0 - ';
01179 } else {
01180 $p_field.=' (Integer)';
01181 }
01182 break;
01183 case "color":
01184 $colorNames=explode(",",",".$this->HTMLcolorList);
01185 $p_field="";
01186 while(list(,$val)=each($colorNames)) {
01187 $sel="";
01188 if ($val==strtolower($params["value"])) {$sel=