Documentation TYPO3 par Ameos

class.t3lib_tsparser_ext.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
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###";          // 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.
00108         var $HTMLcolorList = "aqua,black,blue,fuchsia,gray,green,lime,maroon,navy,olive,purple,red,silver,teal,yellow,white";
00109 
00110                 // internal
00111         var $categories = array(
00112                 "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.
00113                 "menu" => array(),              // Menu setup. This includes fontfiles, sizes, background images. Depending on the menutype.
00114                 "content" => array(),   // All constants related to the display of pagecontent elements
00115                 "page" => array(),              // General configuration like metatags, link targets
00116                 "advanced" => array(),  // Advanced functions, which are used very seldomly.
00117                 "all" => array()                // All constants are put here also!
00118         );              // This will be filled with the available categories of the current template.
00119         var $subCategories = array(
00120         // Standard categories:
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         // subcategories based on the default content elements
00130                 "cheader" => Array("Content: 'Header'", "ma"),
00131                 "cheader_g" => Array("Content: 'Header', Graphical", "ma"),
00132                 "ctext" => Array("Content: 'Text'", "mb"),
00133 //              "ctextpic" =>
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 //      var $matchAll = 0;              // If set, all conditions are matched!
00153 
00154         var $backend_info=1;
00155 
00156                 // tsconstanteditor
00157         var $ext_inBrace=0;
00158 
00159                 // tsbrowser
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;        // Dont change...
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                 // ts analyzer
00182         var $templateTitles=array();
00183 
00184 
00194         function flattenSetup($setupArray, $prefix, $resourceFlag)      {
00195                 if (is_array($setupArray))      {
00196                         $this->getFileName_backPath=PATH_site;          // Setting absolute prefixed path for relative resources.
00197                         reset($setupArray);
00198                         while(list($key,$val)=each($setupArray))        {
00199                                 if ($prefix || substr($key,0,16)!="TSConstantEditor")   {               // We don't want "TSConstantEditor" in the flattend setup.
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 
00286         function generateConfig_constants()     {
00287                         // Parses the constants in $this->const with respect to the constant-editor in this module.
00288                         // In particular comments in the code are registered and the edit_divider is taken into account.
00289                         // These vars are also set lateron...
00290                 $this->setup["resources"]= $this->resources;
00291                 $this->setup["sitetitle"]= $this->sitetitle;
00292 
00293                         // parse constants
00294                 $constants = t3lib_div::makeInstance("t3lib_TSparser");
00295                 $constants->regComments=1;              // Register comments!
00296                 $constants->setup = $this->const;
00297                 $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup);
00298 
00299                 $matchObj = t3lib_div::makeInstance("t3lib_matchCondition");
00300 //              $matchObj->matchAlternative = array("[globalString =  page | title = *test*]");
00301                 $matchObj->matchAll=1;          // Matches ALL conditions in TypoScript
00302 
00303                 $c=0;
00304                 $cc=count($this->constants);
00305                 reset($this->constants);
00306                 while (list(,$str)=each($this->constants))      {
00307                         $c++;
00308                         if ($c==$cc)    {
00309                                 if (strstr($str,$this->edit_divider))   {
00310                                         $parts = explode($this->edit_divider,$str,2);
00311                                         $str=$parts[1];
00312                                         $constants->parse($parts[0],$matchObj);
00313                                 }
00314                                 $this->flatSetup = Array();
00315                                 $this->flattenSetup($constants->setup,"","");
00316                                 $defaultConstants=$this->flatSetup;
00317                         }
00318                         $constants->parse($str,$matchObj);
00319                 }
00320 
00321                 $this->flatSetup = Array();
00322                 $this->flattenSetup($constants->setup,"","");
00323                 $this->setup["constants"] = $constants->setup;
00324 
00325                 return $this->ext_compareFlatSetups($defaultConstants);
00326         }
00327 
00335         function ext_getSetup($theSetup,$theKey)        {
00336                 $parts = explode(".",$theKey,2);
00337 //              debug("-----------",1);
00338 //              debug($theKey,1);
00339                 if (strcmp($parts[0],"") && is_array($theSetup[$parts[0]."."])) {
00340 //                      debug(trim($parts[1]),1);
00341                         if (strcmp(trim($parts[1]),"")) {
00342 //                      debug(trim($parts[1]),1);
00343                                 return $this->ext_getSetup($theSetup[$parts[0]."."],trim($parts[1]));
00344                         } else {
00345                                 return array($theSetup[$parts[0]."."], $theSetup[$parts[0]]);
00346                         }
00347                 } else {
00348                         if (strcmp(trim($theKey),""))   {
00349                                 return array(array(),$theSetup[$theKey]);
00350                         } else {
00351                                 return array($theSetup,"");
00352                         }
00353                 }
00354         }
00355 
00366         function ext_getObjTree($arr, $depth_in, $depthData, $parentType="",$parentValue="")    {
00367                 $HTML="";
00368                 $a=0;
00369 
00370                 reset($arr);
00371                 $keyArr_num=array();
00372                 $keyArr_alpha=array();
00373                 while (list($key,)=each($arr))  {
00374                         if (substr($key,-2)!="..")      {       // Don't do anything with comments / linenumber registrations...
00375                                 $key=ereg_replace("\.$","",$key);
00376                                 if (substr($key,-1)!=".")       {
00377                                         if (t3lib_div::testInt($key))   {
00378                                                 $keyArr_num[$key]=$arr[$key];
00379                                         } else {
00380                                                 $keyArr_alpha[$key]=$arr[$key];
00381                                         }
00382                                 }
00383                         }
00384                 }
00385                 ksort($keyArr_num);
00386                 $keyArr=$keyArr_num+$keyArr_alpha;
00387                 reset($keyArr);
00388                 $c=count($keyArr);
00389                 if ($depth_in)  {$depth_in = $depth_in.".";}
00390 
00391 //              $validate_info= verify_TSobjects($keyArr,$parentType,$parentValue);
00392 //              debug($validate_info);
00393 
00394                 while (list($key,)=each($keyArr))       {
00395                         $a++;
00396                         $depth=$depth_in.$key;
00397                         if ($this->bType!="const" || substr($depth,0,1)!="_")   {               // this excludes all constants starting with "_" from being shown.
00398                                 $goto = substr(md5($depth),0,6);
00399         //                      debug($depth);
00400                                 $deeper = (is_array($arr[$key."."]) && ($this->tsbrowser_depthKeys[$depth] || $this->ext_expandAllNotes)) ? 1 : 0;
00401                                 $PM = "join";
00402                                 $LN = ($a==$c)?"blank":"line";
00403                                 $BTM = ($a==$c)?"bottom":"";
00404                                 $PM = is_array($arr[$key."."]) && !$this->ext_noPMicons ? ($deeper ? "minus":"plus") : "join";
00405 
00406                                 $HTML.=$depthData;
00407                                 $theIcon='<img src="'.$GLOBALS["BACK_PATH"].'gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border="0" alt="" />';
00408                                 if ($PM=="join")        {
00409                                         $HTML.=$theIcon;
00410                                 } else {
00411                                         $aHref='index.php?id='.$GLOBALS["SOBE"]->id.'&tsbr['.$depth.']='.($deeper?0:1).'#'.$goto;
00412                                         $HTML.='<a name="'.$goto.'" href="'.htmlspecialchars($aHref).'">'.$theIcon.'</a>';
00413                                 }
00414 
00415                                 $label = $key;
00416                                 if (t3lib_div::inList("types,resources,sitetitle",$depth) && $this->bType=="setup")     {               // Read only...
00417                                         $label='<font color="#666666">'.$label.'</font>';
00418                                 } else {
00419                                         if ($this->linkObjects) {
00420                                                 $aHref = 'index.php?id='.$GLOBALS["SOBE"]->id.'&sObj='.$depth;
00421                                                 if ($this->bType!="const")      {
00422                                                         $ln = is_array($arr[$key.'.ln..']) ? 'Defined in: '.$this->lineNumberToScript($arr[$key.'.ln..']) : 'N/A';
00423                                                 } else {
00424                                                         $ln = '';
00425                                                 }
00426 
00427                                                 if ($this->tsbrowser_searchKeys[$depth] & 4)    { $label = '<b><font color="red">'.$label.'</font></b>'; }      // The key has matched the search string
00428                                                 $label = '<a href="'.htmlspecialchars($aHref).'" title="'.htmlspecialchars($ln).'">'.$label.'</a>';
00429                                         }
00430                                 }
00431 
00432                                 $HTML.="[".$label."]";
00433 
00434                                 if (isset($arr[$key]))  {
00435                                         $theValue = $arr[$key];
00436                                         if ($this->fixedLgd)    {
00437                                                 $imgBlocks = ceil(1+strlen($depthData)/77);
00438                                                 $lgdChars = 68-ceil(strlen("[".$key."]")*0.8)-$imgBlocks*3;
00439                                                 $theValue = $this->ext_fixed_lgd($theValue,$lgdChars);
00440                                         }
00441                                         if ($this->tsbrowser_searchKeys[$depth] & 2)    {       // The value has matched the search string
00442                                                 $HTML.='=<b><font color="red">'.$this->makeHtmlspecialchars($theValue).'</font></b>';
00443                                         } else {
00444                                                 $HTML.="=<b>".$this->makeHtmlspecialchars($theValue)."</b>";
00445                                         }
00446                                 }
00447                                 $HTML.="<br />";
00448 
00449                                 if ($deeper)    {
00450                                         $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]);
00451                                 }
00452                         }
00453                 }
00454                 return $HTML;
00455         }
00456 
00463         function lineNumberToScript($lnArr)     {
00464                 if (!is_array($this->lnToScript))       {
00465                         $this->lnToScript = array();
00466                         $c=1;
00467                         $c+=substr_count($GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'],chr(10))+2;
00468                         $this->lnToScript[$c] = '[Default]';
00469 
00470                         foreach($this->hierarchyInfoToRoot as $info)    {
00471                                 $c+=$info['configLines']+1;
00472                                 $this->lnToScript[$c] = $info['title'];
00473                         }
00474                 }
00475 
00476                 foreach($lnArr as $k => $ln)    {
00477                         foreach($this->lnToScript as $endLn => $title)  {
00478                                 if ($endLn >= intval($ln))      {
00479                                         $lnArr[$k] = '"'.$title.'", '.$ln;
00480                                         break;
00481                                 }
00482                         }
00483                 }
00484 
00485                 return implode('; ',$lnArr);
00486         }
00487 
00494         function makeHtmlspecialchars($theValue){
00495                 return $this->ext_noSpecialCharsOnLabels ? $theValue : htmlspecialchars($theValue);
00496         }
00497 
00507         function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray)           {
00508                 reset($arr);
00509                 $keyArr=array();
00510                 while (list($key,)=each($arr))  {
00511                         $key=ereg_replace('\.$','',$key);
00512                         if (substr($key,-1)!='.')       {
00513                                 $keyArr[$key]=1;
00514                         }
00515                 }
00516                 reset($keyArr);
00517 //              asort($keyArr);
00518                 $c=count($keyArr);
00519                 if ($depth_in)  { $depth_in = $depth_in.'.'; }
00520                 while (list($key,)=each($keyArr))       {
00521                         $depth=$depth_in.$key;
00522                         $deeper = is_array($arr[$key."."]);
00523 
00524                         if ($this->regexMode)   {
00525                                 if (ereg($searchString,$arr[$key]))     {       // The value has matched
00526                                         $this->tsbrowser_searchKeys[$depth]+=2;
00527                                 }
00528                                 if (ereg($searchString,$key))   {               // The key has matched
00529                                         $this->tsbrowser_searchKeys[$depth]+=4;
00530                                 }
00531                                 if (ereg($searchString,$depth_in))      {       // Just open this subtree if the parent key has matched the search
00532                                         $this->tsbrowser_searchKeys[$depth]=1;
00533                                 }
00534                         } else {
00535                                 if (stristr($arr[$key],$searchString))  {       // The value has matched
00536                                         $this->tsbrowser_searchKeys[$depth]+=2;
00537                                 }
00538                                 if (stristr($key,$searchString))        {       // The key has matches
00539                                         $this->tsbrowser_searchKeys[$depth]+=4;
00540                                 }
00541                                 if (stristr($depth_in,$searchString))   {       // Just open this subtree if the parent key has matched the search
00542                                         $this->tsbrowser_searchKeys[$depth]=1;
00543                                 }
00544                         }
00545 
00546                         if ($deeper)    {
00547                                 $cS = count($this->tsbrowser_searchKeys);
00548                                 $keyArray = $this->ext_getSearchKeys($arr[$key.'.'], $depth, $searchString, $keyArray);
00549                                 if ($cS != count($this->tsbrowser_searchKeys))  {
00550                                         $keyArray[$depth]=1;
00551                                 }
00552                         }
00553                 }
00554                 return $keyArray;
00555         }
00556 
00563         function ext_getRootlineNumber($pid)    {
00564                 if ($pid && is_array($GLOBALS["rootLine"]))     {
00565                         reset($GLOBALS["rootLine"]);
00566                         while(list($key,$val)=each($GLOBALS["rootLine"]))       {
00567                                 if ($val['uid']==$pid)  return $key;
00568                         }
00569                 }
00570         }
00571 
00581         function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0)       {
00582                 reset($arr);
00583                 $keyArr=array();
00584                 while (list($key,)=each($arr))  {
00585                         $key=ereg_replace("\.$","",$key);
00586                         if (substr($key,-1)!=".")       {
00587                                 $keyArr[$key]=1;
00588                         }
00589                 }
00590                 reset($keyArr);
00591                 $a=0;
00592                 $c=count($keyArr);
00593                 while (list($key,)=each($keyArr))       {
00594                         $HTML="";
00595                         $a++;
00596                         $deeper = is_array($arr[$key."."]);
00597                         $row=$arr[$key];
00598 
00599                         $PM = "join";
00600                         $LN = ($a==$c)?"blank":"line";
00601                         $BTM = ($a==$c)?"top":"";
00602                         $PM = "join";
00603 
00604                         $HTML.=$depthData;
00605                         $icon = substr($row["templateID"],0,3)=="sys" ? t3lib_iconWorks::getIcon("sys_template",array("root"=>$row["root"])) :
00606                                                         (substr($row["templateID"],0,6)=="static" ? t3lib_iconWorks::getIcon("static_template",array()) : 'gfx/i/default.gif');
00607                         $alttext= "[".$row['templateID']."]";
00608                         $alttext.= $row['pid'] ? " - ".t3lib_BEfunc::getRecordPath($row['pid'],$GLOBALS["SOBE"]->perms_clause,20) : "";
00609                         if (in_array($row['templateID'],$this->clearList_const) || in_array($row['templateID'],$this->clearList_setup)) {
00610                                 $A_B='<a href="index.php?id='.$GLOBALS["SOBE"]->id.'&template='.$row['templateID'].'">';
00611                                 $A_E="</A>";
00612                         } else {
00613                                 $A_B="";
00614                                 $A_E="";
00615                         }
00616                         $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."&nbsp;&nbsp;";
00617                         $RL = $this->ext_getRootlineNumber($row['pid']);
00618                         $keyArray[] = '<tr>
00619                                                         <td nowrap>'.$HTML.'</td>
00620                                                         <td align=center>'.($row["root"]?"<b>X</b>":"").'&nbsp;&nbsp;</td>
00621                                                         <td align=center'.$row["bgcolor_setup"].'>'.fw(($row["clConf"]?"<b>X</b>":"")."&nbsp;&nbsp;").'</td>
00622                                                         <td align=center'.$row["bgcolor_const"].'>'.fw(($row["clConst"]?"<b>X</b>":"")."&nbsp;&nbsp;").'</td>
00623                                                         <td>'.($row["pid"]?"&nbsp;".$row["pid"].(strcmp($RL,"")?" (".$RL.")":"")."&nbsp;&nbsp;":"").'</td>
00624                                                         <td>'.($row["next"]?"&nbsp;".$row["next"]."&nbsp;&nbsp;":"").'</td>
00625                                                 </tr>';
00626                         if ($deeper)    {
00627                                 $keyArray = $this->ext_getTemplateHierarchyArr($arr[$key."."], $depthData.($first?'':'<IMG src="'.$GLOBALS["BACK_PATH"].'gfx/ol/'.$LN.'.gif" width="18" height="16" align="top">'), $keyArray);
00628                         }
00629                 }
00630                 return $keyArray;
00631         }
00632 
00640         function ext_process_hierarchyInfo($depthDataArr,&$pointer)     {
00641                 $parent = $this->hierarchyInfo[$pointer-1]['templateParent'];
00642                 while ($pointer>0 && $this->hierarchyInfo[$pointer-1]['templateParent']==$parent)       {
00643                         $pointer--;
00644                         $row = $this->hierarchyInfo[$pointer];
00645 
00646                         $depthDataArr[$row['templateID']]=$row;
00647                         $depthDataArr[$row['templateID']]["bgcolor_setup"] = isset($this->clearList_setup_temp[$row['templateID']])?' class="bgColor5"':'';
00648                         $depthDataArr[$row['templateID']]["bgcolor_const"] = isset($this->clearList_const_temp[$row['templateID']])?' class="bgColor5"':'';
00649                         unset($this->clearList_setup_temp[$row['templateID']]);
00650                         unset($this->clearList_const_temp[$row['templateID']]);
00651                         $this->templateTitles[$row['templateID']]=$row["title"];
00652 
00653                         if ($row['templateID']==$this->hierarchyInfo[$pointer-1]['templateParent'])     {
00654                                 $depthDataArr[$row['templateID']."."] = $this->ext_process_hierarchyInfo(array(), $pointer);
00655                         }
00656                 }
00657                 return $depthDataArr;
00658         }
00659 
00671         function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0) {
00672                 $all="";
00673                 reset($config);
00674                 while (list(,$str)=each($config))       {
00675                         $all.="\n[GLOBAL]\n".$str;
00676                 }
00677 
00678                 if ($syntaxHL)  {
00679                         $all = ereg_replace("^[^".chr(10)."]*.","",$all);
00680                         $all = chop($all);
00681                         $tsparser = t3lib_div::makeInstance("t3lib_TSparser");
00682                         $tsparser->lineNumberOffset=$this->ext_lineNumberOffset+1;
00683                         return $tsparser->doSyntaxHighlight($all,$lineNumbers?array($this->ext_lineNumberOffset+1):'',$syntaxHLBlockmode);
00684                 } else {
00685                         return $this->ext_formatTS($all,$lineNumbers,$comments,$crop);
00686                 }
00687         }
00688 
00698         function ext_fixed_lgd($string,$chars)  {
00699                 if ($chars >= 4)        {
00700                         if(strlen($string)>$chars)  {
00701                                 return substr($string, 0, $chars-3)."...";
00702                         }
00703                 }
00704                 return $string;
00705         }
00706 
00714         function ext_lnBreakPointWrap($ln,$str) {
00715                 return '<A href="#" onClick="return brPoint('.$ln.','.($this->ext_lineNumberOffset_mode=="setup"?1:0).');">'.$str.'</a>';
00716         }
00717 
00727         function ext_formatTS($input, $ln, $comments=1, $crop=0)        {
00728                 $input = ereg_replace("^[^".chr(10)."]*.","",$input);
00729                 $input = chop($input);
00730                 $cArr = explode(chr(10),$input);
00731 
00732                 reset($cArr);
00733                 $n = ceil(log10(count($cArr)+$this->ext_lineNumberOffset));
00734                 $lineNum="";
00735                 while(list($k,$v)=each($cArr))  {
00736                         $lln=$k+$this->ext_lineNumberOffset+1;
00737                         if ($ln)        $lineNum = $this->ext_lnBreakPointWrap($lln,str_replace(" ",'&nbsp;',sprintf("% ".$n."d",$lln))).":   ";
00738                         $v=htmlspecialchars($v);
00739                         if ($crop)      {$v=$this->ext_fixed_lgd($v,($ln?71:77));}
00740                         $cArr[$k] = $lineNum.str_replace(" ",'&nbsp;',$v);
00741 
00742                         $firstChar = substr(trim($v),0,1);
00743                         if ($firstChar=="[")    {
00744                                 $cArr[$k] = '<font color="green"><b>'.$cArr[$k].'</b></font>';
00745                         } elseif ($firstChar=="/" || $firstChar=="#")   {
00746                                 if ($comments)  {
00747                                         $cArr[$k] = '<span class="typo3-dimmed">'.$cArr[$k].'</span>';
00748                                 } else {
00749                                         unset($cArr[$k]);
00750                                 }
00751                         }
00752 
00753 
00754                 }
00755                 $output = implode($cArr, "<BR>")."<BR>";
00756                 return $output;
00757         }
00758 
00766         function ext_getFirstTemplate($id,$template_uid=0)              {
00767                         // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
00768                 if (intval($id))        {
00769                         if ($template_uid)      {
00770                                 $addC = " AND uid=".$template_uid;
00771                         }
00772                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).$addC.' '.$this->whereClause, '', 'sorting', '1');
00773                         $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00774                         t3lib_BEfunc::workspaceOL('sys_template',$row);
00775                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
00776                         return $row;    // Returns the template row if found.
00777                 }
00778         }
00779 
00786         function ext_getAllTemplates($id)               {
00787                         // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
00788                 if (intval($id))        {
00789                         $outRes=array();
00790                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).' '.$this->whereClause, '', 'sorting');
00791                         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00792                                 t3lib_BEfunc::workspaceOL('sys_template',$row);
00793                                 if (is_array($row))             $outRes[] = $row;
00794                         }
00795                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
00796                         return $outRes; // Returns the template rows in an array.
00797                 }
00798         }
00799 
00807         function ext_compareFlatSetups($default)        {
00808                 $editableComments=array();
00809                 reset($this->flatSetup);
00810                 while(list($const,$value)=each($this->flatSetup))       {
00811                         if (substr($const,-2)!=".." && isset($this->flatSetup[$const.".."]))    {
00812                                 $comment = trim($this->flatSetup[$const.".."]);
00813                                 $c_arr = explode(chr(10),$comment);
00814                                 while(list($k,$v)=each($c_arr)) {
00815                                         $line=trim(ereg_replace("^[#\/]*","",$v));
00816                                         if ($line)      {
00817                                                 $parts = explode(";", $line);
00818                                                 while(list(,$par)=each($parts))         {
00819                                                         if (strstr($par,"="))   {
00820                                                                 $keyValPair =explode("=",$par,2);
00821                                                                 switch(trim(strtolower($keyValPair[0])))        {
00822                                                                         case "type":
00823                                                                                         // Type:
00824                                                                                         /*
00825         int (range; low-high, list: item,item,item = selector),
00826         boolean (check),
00827         string (default),
00828         wrap,
00829         html-color ...,
00830         file
00831                                                                                         */
00832                                                                                 $editableComments[$const]["type"] = trim($keyValPair[1]);
00833                                                                         break;
00834                                                                         case "cat":
00835                                                                                         // list of categories.
00836                                                                                 $catSplit=explode("/",strtolower($keyValPair[1]));
00837                                                                                 $editableComments[$const]["cat"] = trim($catSplit[0]);
00838                                                                                 $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.
00839                                                                                 if ($catSplit[1] && isset($this->subCategories[$catSplit[1]]))  {
00840                                                                                         $editableComments[$const]["subcat_name"]=$catSplit[1];
00841                                                                                         $editableComments[$const]["subcat"]=$this->subCategories[$catSplit[1]][1]."/".$catSplit[1]."/".trim($catSplit[2])."z";
00842                                                                                 } else {
00843                                                                                         $editableComments[$const]["subcat"]="x"."/".trim($catSplit[2])."z";
00844                                                                                 }
00845                                                                         break;
00846                                                                         case "label":
00847                                                                                         // label
00848                                                                                 $editableComments[$const]["label"] = trim($keyValPair[1]);
00849                                                                         break;
00850                                                                 }
00851                                                         }
00852                                                 }
00853                                         }
00854                                 }
00855                         }
00856                         if (isset($editableComments[$const]))   {
00857                                 $editableComments[$const]["name"]=$const;
00858                                 $editableComments[$const]["value"]=trim($value);
00859                                 if (isset($default[$const]))    {
00860                                         $editableComments[$const]["default_value"]=trim($default[$const]);
00861                                 }
00862                         }
00863                 }
00864                 return $editableComments;
00865         }
00866 
00873         function ext_categorizeEditableConstants($editConstArray)       {
00874                 // Runs through the available constants and fills the $this->categories array with pointers and priority-info
00875                 reset($editConstArray);
00876                 while(list($constName,$constData)=each($editConstArray))        {
00877                         if (!$constData["type"])        {$constData["type"]="string";}
00878                         $cats = explode(",",$constData["cat"]);
00879                         reset($cats);
00880                         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...
00881                                 $theCat=trim($theCat);
00882                                 if ($theCat)    {
00883                                         $this->categories[$theCat][$constName]=$constData["subcat"];
00884 //                                      $this->categories["all"][$constName]=$constData["subcat"];
00885                                 }
00886                         }
00887                 }
00888 //              debug($this->categories);
00889         }
00890 
00896         function ext_getCategoryLabelArray()    {
00897                 // Returns array used for labels in the menu.
00898                 $retArr = array();
00899                 while(list($k,$v)=each($this->categories))      {
00900                         if (count($v))  {
00901                                 $retArr[$k]=strtoupper($k)." (".count($v).")";
00902                         }
00903                 }
00904                 return $retArr;
00905         }
00906 
00913         function ext_getTypeData($type) {
00914                 $retArr = array();
00915                 $type=trim($type);
00916                 if (!$type)     {
00917                         $retArr["type"]="string";
00918                 } else {
00919                         $m=strcspn ($type," [");
00920                         $retArr["type"]=strtolower(substr($type,0,$m));
00921                         if (t3lib_div::inList("int,options,file,boolean,offset",$retArr["type"]))       {
00922                                 $p=trim(substr($type,$m));
00923                                 $reg = array();
00924                                 ereg("\[(.*)\]",$p,$reg);
00925                                 $p=trim($reg[1]);
00926                                 if ($p) {
00927                                         $retArr["paramstr"]=$p;
00928                                         switch($retArr["type"]) {
00929                                                 case "int":
00930                                                         if (substr($retArr["paramstr"],0,1)=="-")       {
00931                                                                 $retArr["params"]=t3lib_div::intExplode("-",substr($retArr["paramstr"],1));
00932                                                                 $retArr["params"][0]=intval("-".$retArr["params"][0]);
00933                                                         } else {
00934                                                                 $retArr["params"]=t3lib_div::intExplode("-",$retArr["paramstr"]);
00935                                                         }
00936                                                         $retArr["paramstr"]=$retArr["params"][0]." - ".$retArr["params"][1];
00937                                                 break;
00938                                                 case "options":
00939                                                         $retArr["params"]=explode(",",$retArr["paramstr"]);
00940                                                 break;
00941                                         }
00942                                 }
00943                         }
00944                 }
00945 //              debug($retArr);
00946                 return $retArr;
00947         }
00948 
00955         function ext_getTSCE_config($category)  {
00956                 $catConf=$this->setup["constants"]["TSConstantEditor."][$category."."];
00957                 $out=array();
00958                 if (is_array($catConf)) {
00959                         reset($catConf);
00960                         while(list($key,$val)=each($catConf))   {
00961                                 switch($key)    {
00962                                         case "image":
00963                                                 $out["imagetag"] = $this->ext_getTSCE_config_image($catConf["image"]);
00964                                         break;
00965                                         case "description":
00966                                         case "bulletlist":
00967                                         case "header":
00968                                                 $out[$key] = $val;
00969                                         break;
00970                                         default:
00971                                                 if (t3lib_div::testInt($key))   {
00972                                                         $constRefs = explode(",",$val);
00973                                                         reset($constRefs);
00974                                                         while(list(,$const)=each($constRefs))   {
00975                                                                 $const=trim($const);
00976                                                                 if ($const && $const<=20)       {
00977                                                                         $out["constants"][$const].=$this->ext_getKeyImage($key);
00978                                                                 }
00979                                                         }
00980                                                 }
00981                                         break;
00982                                 }
00983                         }
00984                 }
00985                 $this->helpConfig=$out;
00986         }
00987 
00994         function ext_getKeyImage($key)  {
00995                 return '<img src="'.$this->ext_localWebGfxPrefix.'gfx/'.$key.'.gif" align="top" hspace=2>';
00996         }
00997 
01004         function ext_getTSCE_config_image($imgConf)     {
01005                 if (substr($imgConf,0,4)=="gfx/")       {
01006                         $iFile=$this->ext_localGfxPrefix.$imgConf;
01007                         $tFile=$this->ext_localWebGfxPrefix.$imgConf;
01008                 } elseif (substr($imgConf,0,4)=='EXT:') {
01009                         $iFile = t3lib_div::getFileAbsFileName($imgConf);
01010                         if ($iFile)     {
01011                                 $f = substr($iFile,strlen(PATH_site));
01012                                 $tFile=$GLOBALS["BACK_PATH"]."../".$f;
01013                         }
01014                 } else {
01015                         $f = "uploads/tf/".$this->extractFromResources($this->setup["resources"],$imgConf);
01016                         $iFile=PATH_site.$f;
01017                         $tFile=$GLOBALS["BACK_PATH"]."../".$f;
01018                 }
01019                 $imageInfo=@getImagesize($iFile);
01020                 return '<img src="'.$tFile.'" '.$imageInfo[3].'>';
01021         }
01022 
01028         function ext_resourceDims()     {
01029                 if ($this->setup["resources"])  {
01030                         $rArr=explode(",",$this->setup["resources"]);
01031                         while(list($c,$val)=each($rArr))        {
01032                                 $val=trim($val);
01033                                 $theFile = PATH_site."uploads/tf/".$val;
01034                                 if ($val && @is_file($theFile)) {
01035                                         $imgInfo = @getimagesize($theFile);
01036                                 }
01037                                 if (is_array($imgInfo)) {
01038                                         $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
01039                                 }
01040                         }
01041                 }
01042                 reset($this->dirResources);
01043                 while(list($c,$val)=each($this->dirResources))  {
01044                         $val=trim($val);
01045                         $imgInfo = @getimagesize(PATH_site.$val);
01046                         if (is_array($imgInfo)) {
01047                                 $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
01048                         }
01049                 }
01050         }
01051 
01058         function ext_readDirResources($path)    {
01059                 $path=trim($path);
01060                 if ($path && substr($path,0,10)=="fileadmin/")  {
01061                         $path = ereg_replace("\/$","",$path);
01062                         $this->readDirectory(PATH_site.$path);
01063                 }
01064         }
01065 
01073         function readDirectory($path,$type="file")      {
01074                 if(@is_dir($path))      {
01075                         $d = @dir($path);
01076                         $tempArray=Array();
01077                         if (is_object($d))      {
01078                                 while($entry=$d->read()) {
01079                                         if ($entry!="." && $entry!="..")        {
01080                                                 $wholePath = $path."/".$entry;          // Because of odd PHP-error where  <BR>-tag is sometimes placed after a filename!!
01081                                                 if (@file_exists($wholePath) && (!$type || filetype($wholePath)==$type))        {
01082                                                         $fI = t3lib_div::split_fileref($wholePath);
01083                                                         $this->dirResources[]=substr($wholePath,strlen(PATH_site));
01084                                                 }
01085                                         }
01086                                 }
01087                                 $d->close();
01088                         }
01089                 }
01090         }
01091 
01098         function ext_fNandV($params)    {
01099                 $fN='data['.$params["name"].']';
01100                 $fV=$params["value"];
01101                 if (ereg("^{[\$][a-zA-Z0-9\.]*}$",trim($fV),$reg))      {               // Values entered from the constantsedit cannot be constants!   230502; removed \{ and set {
01102                         $fV="";
01103                 }
01104                 $fV=htmlspecialchars($fV);
01105 
01106                 return array($fN,$fV,$params);
01107         }
01108 
01116         function ext_printFields($theConstants,$category)       {
01117                         // This functions returns the HTML-code that creates the editor-layout of the module.
01118                 reset($theConstants);
01119                 $output="";
01120                 $subcat="";
01121                 if (is_array($this->categories[$category]))     {
01122 
01123                         $help=$this->helpConfig;
01124                         $this->rArr=explode(",",$this->setup["resources"].",".implode($this->dirResources,","));
01125 
01126                         if (!$this->doNotSortCategoriesBeforeMakingForm) asort($this->categories[$category]);
01127                         while(list($name,$type)=each($this->categories[$category]))     {
01128                                 $params = $theConstants[$name];
01129                                 if (is_array($params))  {
01130                                         if ($subcat!=$params["subcat_name"])    {
01131                                                 $subcat=$params["subcat_name"];
01132                                                 $subcat_name = $params["subcat_name"] ? $this->subCategories[$params["subcat_name"]][0] : "Others";
01133                                                 $output.='<tr>';
01134                                                 $output.='<td colspan=2 class="bgColor4"><div align="center"><b>'.$subcat_name.'</b></div></td>';
01135                                                 $output.='</tr>';
01136                                         }
01137 
01138                         //              if (substr($params["value"],0,2)!='{$') {
01139                                                 $label=$GLOBALS["LANG"]->sL($params["label"]);
01140                                                 $label_parts = explode(":",$label,2);
01141                                                 if (count($label_parts)==2)     {
01142                                                         $head=trim($label_parts[0]);
01143                                                         $body=trim($label_parts[1]);
01144                                                 } else {
01145                                                         $head=trim($label_parts[0]);
01146                                                         $body="";
01147                                                 }
01148                                                 if (strlen($head)>35)   {
01149                                                         if (!$body) {$body=$head;}
01150                                                         $head=t3lib_div::fixed_lgd_cs($head,35);
01151                                                 }
01152                                                 $typeDat=$this->ext_getTypeData($params["type"]);
01153                                                 $checked="";
01154                                                 $p_field="";
01155                                                 $raname = substr(md5($params["name"]),0,10);
01156                                                 $aname="'".$raname."'";
01157                                                 if ($this->ext_dontCheckIssetValues || isset($this->objReg[$params["name"]]))   {
01158                                                         $checked=" checked";
01159                                                         list($fN,$fV,$params)=$this->ext_fNandV($params);
01160 
01161                                                         switch($typeDat["type"])        {
01162                                                                 case "int":
01163                                                                 case "int+":
01164                                                                         $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(5).' onChange="uFormUrl('.$aname.')">';
01165                                                                         if ($typeDat["paramstr"])       {
01166                                                                                 $p_field.=' Range: '.$typeDat["paramstr"];
01167                                                                         } elseif ($typeDat["type"]=="int+") {
01168                                                                                 $p_field.=' Range: 0 - ';
01169                                                                         } else {
01170                                                                                 $p_field.=' (Integer)';
01171                                                                         }
01172                                                                 break;
01173                                                                 case "color":
01174                                                                         $colorNames=explode(",",",".$this->HTMLcolorList);
01175                                                                         $p_field="";
01176                                                                         while(list(,$val)=each($colorNames))    {
01177                                                                                 $sel="";
01178                                                                                 if ($val==strtolower($params["value"])) {$sel=" selected";}
01179                                                                                 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.'</option>';
01180                                                                         }
01181                                                                         $p_field='<select name=