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 
00367         function ext_getObjTree($arr, $depth_in, $depthData, $parentType='',$parentValue='', $alphaSort='0')    {
00368                 $HTML="";
00369                 $a=0;
00370 
00371                 reset($arr);
00372                 if($alphaSort == '1')   {
00373                         ksort($arr);
00374                 }
00375                 $keyArr_num=array();
00376                 $keyArr_alpha=array();
00377                 while (list($key,)=each($arr))  {
00378                         if (substr($key,-2)!="..")      {       // Don't do anything with comments / linenumber registrations...
00379                                 $key=ereg_replace("\.$","",$key);
00380                                 if (substr($key,-1)!=".")       {
00381                                         if (t3lib_div::testInt($key))   {
00382                                                 $keyArr_num[$key]=$arr[$key];
00383                                         } else {
00384                                                 $keyArr_alpha[$key]=$arr[$key];
00385                                         }
00386                                 }
00387                         }
00388                 }
00389                 ksort($keyArr_num);
00390                 $keyArr=$keyArr_num+$keyArr_alpha;
00391                 reset($keyArr);
00392                 $c=count($keyArr);
00393                 if ($depth_in)  {$depth_in = $depth_in.".";}
00394 
00395 //              $validate_info= verify_TSobjects($keyArr,$parentType,$parentValue);
00396 //              debug($validate_info);
00397 
00398                 while (list($key,)=each($keyArr))       {
00399                         $a++;
00400                         $depth=$depth_in.$key;
00401                         if ($this->bType!="const" || substr($depth,0,1)!="_")   {               // this excludes all constants starting with "_" from being shown.
00402                                 $goto = substr(md5($depth),0,6);
00403         //                      debug($depth);
00404                                 $deeper = (is_array($arr[$key."."]) && ($this->tsbrowser_depthKeys[$depth] || $this->ext_expandAllNotes)) ? 1 : 0;
00405                                 $PM = "join";
00406                                 $LN = ($a==$c)?"blank":"line";
00407                                 $BTM = ($a==$c)?"bottom":"";
00408                                 $PM = is_array($arr[$key."."]) && !$this->ext_noPMicons ? ($deeper ? "minus":"plus") : "join";
00409 
00410                                 $HTML.=$depthData;
00411                                 $theIcon='<img src="'.$GLOBALS["BACK_PATH"].'gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border="0" alt="" />';
00412                                 if ($PM=="join")        {
00413                                         $HTML.=$theIcon;
00414                                 } else {
00415                                         $aHref='index.php?id='.$GLOBALS["SOBE"]->id.'&tsbr['.$depth.']='.($deeper?0:1).'#'.$goto;
00416                                         $HTML.='<a name="'.$goto.'" href="'.htmlspecialchars($aHref).'">'.$theIcon.'</a>';
00417                                 }
00418 
00419                                 $label = $key;
00420                                 if (t3lib_div::inList("types,resources,sitetitle",$depth) && $this->bType=="setup")     {               // Read only...
00421                                         $label='<font color="#666666">'.$label.'</font>';
00422                                 } else {
00423                                         if ($this->linkObjects) {
00424                                                 $aHref = 'index.php?id='.$GLOBALS["SOBE"]->id.'&sObj='.$depth;
00425                                                 if ($this->bType!="const")      {
00426                                                         $ln = is_array($arr[$key.'.ln..']) ? 'Defined in: '.$this->lineNumberToScript($arr[$key.'.ln..']) : 'N/A';
00427                                                 } else {
00428                                                         $ln = '';
00429                                                 }
00430 
00431                                                 if ($this->tsbrowser_searchKeys[$depth] & 4)    { $label = '<b><font color="red">'.$label.'</font></b>'; }      // The key has matched the search string
00432                                                 $label = '<a href="'.htmlspecialchars($aHref).'" title="'.htmlspecialchars($ln).'">'.$label.'</a>';
00433                                         }
00434                                 }
00435 
00436                                 $HTML.="[".$label."]";
00437 
00438                                 if (isset($arr[$key]))  {
00439                                         $theValue = $arr[$key];
00440                                         if ($this->fixedLgd)    {
00441                                                 $imgBlocks = ceil(1+strlen($depthData)/77);
00442                                                 $lgdChars = 68-ceil(strlen("[".$key."]")*0.8)-$imgBlocks*3;
00443                                                 $theValue = $this->ext_fixed_lgd($theValue,$lgdChars);
00444                                         }
00445                                         if ($this->tsbrowser_searchKeys[$depth] & 2)    {       // The value has matched the search string
00446                                                 $HTML.='=<b><font color="red">'.$this->makeHtmlspecialchars($theValue).'</font></b>';
00447                                         } else {
00448                                                 $HTML.="=<b>".$this->makeHtmlspecialchars($theValue)."</b>";
00449                                         }
00450                                 }
00451                                 $HTML.="<br />";
00452 
00453                                 if ($deeper)    {
00454                                         $HTML.=$this->ext_getObjTree($arr[$key."."], $depth, $depthData.'<img src="'.$GLOBALS["BACK_PATH"].'gfx/ol/'.$LN.'.gif" width="18" height="16" align="top" alt="" />', '' /* not used: $validate_info[$key] */, $arr[$key], $alphaSort);
00455                                 }
00456                         }
00457                 }
00458                 return $HTML;
00459         }
00460 
00467         function lineNumberToScript($lnArr)     {
00468                 if (!is_array($this->lnToScript))       {
00469                         $this->lnToScript = array();
00470                         $c=1;
00471                         $c+=substr_count($GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'],chr(10))+2;
00472                         $this->lnToScript[$c] = '[Default]';
00473 
00474                         foreach($this->hierarchyInfoToRoot as $info)    {
00475                                 $c+=$info['configLines']+1;
00476                                 $this->lnToScript[$c] = $info['title'];
00477                         }
00478                 }
00479 
00480                 foreach($lnArr as $k => $ln)    {
00481                         foreach($this->lnToScript as $endLn => $title)  {
00482                                 if ($endLn >= intval($ln))      {
00483                                         $lnArr[$k] = '"'.$title.'", '.$ln;
00484                                         break;
00485                                 }
00486                         }
00487                 }
00488 
00489                 return implode('; ',$lnArr);
00490         }
00491 
00498         function makeHtmlspecialchars($theValue){
00499                 return $this->ext_noSpecialCharsOnLabels ? $theValue : htmlspecialchars($theValue);
00500         }
00501 
00511         function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray)           {
00512                 reset($arr);
00513                 $keyArr=array();
00514                 while (list($key,)=each($arr))  {
00515                         $key=ereg_replace('\.$','',$key);
00516                         if (substr($key,-1)!='.')       {
00517                                 $keyArr[$key]=1;
00518                         }
00519                 }
00520                 reset($keyArr);
00521 //              asort($keyArr);
00522                 $c=count($keyArr);
00523                 if ($depth_in)  { $depth_in = $depth_in.'.'; }
00524                 while (list($key,)=each($keyArr))       {
00525                         $depth=$depth_in.$key;
00526                         $deeper = is_array($arr[$key."."]);
00527 
00528                         if ($this->regexMode)   {
00529                                 if (ereg($searchString,$arr[$key]))     {       // The value has matched
00530                                         $this->tsbrowser_searchKeys[$depth]+=2;
00531                                 }
00532                                 if (ereg($searchString,$key))   {               // The key has matched
00533                                         $this->tsbrowser_searchKeys[$depth]+=4;
00534                                 }
00535                                 if (ereg($searchString,$depth_in))      {       // Just open this subtree if the parent key has matched the search
00536                                         $this->tsbrowser_searchKeys[$depth]=1;
00537                                 }
00538                         } else {
00539                                 if (stristr($arr[$key],$searchString))  {       // The value has matched
00540                                         $this->tsbrowser_searchKeys[$depth]+=2;
00541                                 }
00542                                 if (stristr($key,$searchString))        {       // The key has matches
00543                                         $this->tsbrowser_searchKeys[$depth]+=4;
00544                                 }
00545                                 if (stristr($depth_in,$searchString))   {       // Just open this subtree if the parent key has matched the search
00546                                         $this->tsbrowser_searchKeys[$depth]=1;
00547                                 }
00548                         }
00549 
00550                         if ($deeper)    {
00551                                 $cS = count($this->tsbrowser_searchKeys);
00552                                 $keyArray = $this->ext_getSearchKeys($arr[$key.'.'], $depth, $searchString, $keyArray);
00553                                 if ($cS != count($this->tsbrowser_searchKeys))  {
00554                                         $keyArray[$depth]=1;
00555                                 }
00556                         }
00557                 }
00558                 return $keyArray;
00559         }
00560 
00567         function ext_getRootlineNumber($pid)    {
00568                 if ($pid && is_array($GLOBALS["rootLine"]))     {
00569                         reset($GLOBALS["rootLine"]);
00570                         while(list($key,$val)=each($GLOBALS["rootLine"]))       {
00571                                 if ($val['uid']==$pid)  return $key;
00572                         }
00573                 }
00574         }
00575 
00585         function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0)       {
00586                 reset($arr);
00587                 $keyArr=array();
00588                 while (list($key,)=each($arr))  {
00589                         $key=ereg_replace("\.$","",$key);
00590                         if (substr($key,-1)!=".")       {
00591                                 $keyArr[$key]=1;
00592                         }
00593                 }
00594                 reset($keyArr);
00595                 $a=0;
00596                 $c=count($keyArr);
00597                 while (list($key,)=each($keyArr))       {
00598                         $HTML="";
00599                         $a++;
00600                         $deeper = is_array($arr[$key."."]);
00601                         $row=$arr[$key];
00602 
00603                         $PM = "join";
00604                         $LN = ($a==$c)?"blank":"line";
00605                         $BTM = ($a==$c)?"top":"";
00606                         $PM = "join";
00607 
00608                         $HTML.=$depthData;
00609                         $icon = substr($row["templateID"],0,3)=="sys" ? t3lib_iconWorks::getIcon("sys_template",array("root"=>$row["root"])) :
00610                                                         (substr($row["templateID"],0,6)=="static" ? t3lib_iconWorks::getIcon("static_template",array()) : 'gfx/i/default.gif');
00611                         $alttext= "[".$row['templateID']."]";
00612                         $alttext.= $row['pid'] ? " - ".t3lib_BEfunc::getRecordPath($row['pid'],$GLOBALS["SOBE"]->perms_clause,20) : "";
00613                         if (in_array($row['templateID'],$this->clearList_const) || in_array($row['templateID'],$this->clearList_setup)) {
00614                                 $A_B='<a href="index.php?id='.$GLOBALS["SOBE"]->id.'&template='.$row['templateID'].'">';
00615                                 $A_E="</A>";
00616                         } else {
00617                                 $A_B="";
00618                                 $A_E="";
00619                         }
00620                         $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;";
00621                         $RL = $this->ext_getRootlineNumber($row['pid']);
00622                         $keyArray[] = '<tr>
00623                                                         <td nowrap>'.$HTML.'</td>
00624                                                         <td align=center>'.($row["root"]?"<b>X</b>":"").'&nbsp;&nbsp;</td>
00625                                                         <td align=center'.$row["bgcolor_setup"].'>'.fw(($row["clConf"]?"<b>X</b>":"")."&nbsp;&nbsp;").'</td>
00626                                                         <td align=center'.$row["bgcolor_const"].'>'.fw(($row["clConst"]?"<b>X</b>":"")."&nbsp;&nbsp;").'</td>
00627                                                         <td>'.($row["pid"]?"&nbsp;".$row["pid"].(strcmp($RL,"")?" (".$RL.")":"")."&nbsp;&nbsp;":"").'</td>
00628                                                         <td>'.($row["next"]?"&nbsp;".$row["next"]."&nbsp;&nbsp;":"").'</td>
00629                                                 </tr>';
00630                         if ($deeper)    {
00631                                 $keyArray = $this->ext_getTemplateHierarchyArr($arr[$key."."], $depthData.($first?'':'<IMG src="'.$GLOBALS["BACK_PATH"].'gfx/ol/'.$LN.'.gif" width="18" height="16" align="top">'), $keyArray);
00632                         }
00633                 }
00634                 return $keyArray;
00635         }
00636 
00644         function ext_process_hierarchyInfo($depthDataArr,&$pointer)     {
00645                 $parent = $this->hierarchyInfo[$pointer-1]['templateParent'];
00646                 while ($pointer>0 && $this->hierarchyInfo[$pointer-1]['templateParent']==$parent)       {
00647                         $pointer--;
00648                         $row = $this->hierarchyInfo[$pointer];
00649 
00650                         $depthDataArr[$row['templateID']]=$row;
00651                         $depthDataArr[$row['templateID']]["bgcolor_setup"] = isset($this->clearList_setup_temp[$row['templateID']])?' class="bgColor5"':'';
00652                         $depthDataArr[$row['templateID']]["bgcolor_const"] = isset($this->clearList_const_temp[$row['templateID']])?' class="bgColor5"':'';
00653                         unset($this->clearList_setup_temp[$row['templateID']]);
00654                         unset($this->clearList_const_temp[$row['templateID']]);
00655                         $this->templateTitles[$row['templateID']]=$row["title"];
00656 
00657                         if ($row['templateID']==$this->hierarchyInfo[$pointer-1]['templateParent'])     {
00658                                 $depthDataArr[$row['templateID']."."] = $this->ext_process_hierarchyInfo(array(), $pointer);
00659                         }
00660                 }
00661                 return $depthDataArr;
00662         }
00663 
00675         function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0) {
00676                 $all="";
00677                 reset($config);
00678                 while (list(,$str)=each($config))       {
00679                         $all.="\n[GLOBAL]\n".$str;
00680                 }
00681 
00682                 if ($syntaxHL)  {
00683                         $all = ereg_replace("^[^".chr(10)."]*.","",$all);
00684                         $all = chop($all);
00685                         $tsparser = t3lib_div::makeInstance("t3lib_TSparser");
00686                         $tsparser->lineNumberOffset=$this->ext_lineNumberOffset+1;
00687                         return $tsparser->doSyntaxHighlight($all,$lineNumbers?array($this->ext_lineNumberOffset+1):'',$syntaxHLBlockmode);
00688                 } else {
00689                         return $this->ext_formatTS($all,$lineNumbers,$comments,$crop);
00690                 }
00691         }
00692 
00702         function ext_fixed_lgd($string,$chars)  {
00703                 if ($chars >= 4)        {
00704                         if(strlen($string)>$chars)  {
00705                                 return substr($string, 0, $chars-3)."...";
00706                         }
00707                 }
00708                 return $string;
00709         }
00710 
00718         function ext_lnBreakPointWrap($ln,$str) {
00719                 return '<A href="#" onClick="return brPoint('.$ln.','.($this->ext_lineNumberOffset_mode=="setup"?1:0).');">'.$str.'</a>';
00720         }
00721 
00731         function ext_formatTS($input, $ln, $comments=1, $crop=0)        {
00732                 $input = ereg_replace("^[^".chr(10)."]*.","",$input);
00733                 $input = chop($input);
00734                 $cArr = explode(chr(10),$input);
00735 
00736                 reset($cArr);
00737                 $n = ceil(log10(count($cArr)+$this->ext_lineNumberOffset));
00738                 $lineNum="";
00739                 while(list($k,$v)=each($cArr))  {
00740                         $lln=$k+$this->ext_lineNumberOffset+1;
00741                         if ($ln)        $lineNum = $this->ext_lnBreakPointWrap($lln,str_replace(" ",'&nbsp;',sprintf("% ".$n."d",$lln))).":   ";
00742                         $v=htmlspecialchars($v);
00743                         if ($crop)      {$v=$this->ext_fixed_lgd($v,($ln?71:77));}
00744                         $cArr[$k] = $lineNum.str_replace(" ",'&nbsp;',$v);
00745 
00746                         $firstChar = substr(trim($v),0,1);
00747                         if ($firstChar=="[")    {
00748                                 $cArr[$k] = '<font color="green"><b>'.$cArr[$k].'</b></font>';
00749                         } elseif ($firstChar=="/" || $firstChar=="#")   {
00750                                 if ($comments)  {
00751                                         $cArr[$k] = '<span class="typo3-dimmed">'.$cArr[$k].'</span>';
00752                                 } else {
00753                                         unset($cArr[$k]);
00754                                 }
00755                         }
00756 
00757 
00758                 }
00759                 $output = implode($cArr, "<BR>")."<BR>";
00760                 return $output;
00761         }
00762 
00770         function ext_getFirstTemplate($id,$template_uid=0)              {
00771                         // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
00772                 if (intval($id))        {
00773                         if ($template_uid)      {
00774                                 $addC = " AND uid=".$template_uid;
00775                         }
00776                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).$addC.' '.$this->whereClause, '', 'sorting', '1');
00777                         $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00778                         t3lib_BEfunc::workspaceOL('sys_template',$row);
00779                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
00780                         return $row;    // Returns the template row if found.
00781                 }
00782         }
00783 
00790         function ext_getAllTemplates($id)               {
00791                         // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
00792                 if (intval($id))        {
00793                         $outRes=array();
00794                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).' '.$this->whereClause, '', 'sorting');
00795                         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00796                                 t3lib_BEfunc::workspaceOL('sys_template',$row);
00797                                 if (is_array($row))             $outRes[] = $row;
00798                         }
00799                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
00800                         return $outRes; // Returns the template rows in an array.
00801                 }
00802         }
00803 
00811         function ext_compareFlatSetups($default)        {
00812                 $editableComments=array();
00813                 reset($this->flatSetup);
00814                 while(list($const,$value)=each($this->flatSetup))       {
00815                         if (substr($const,-2)!=".." && isset($this->flatSetup[$const.".."]))    {
00816                                 $comment = trim($this->flatSetup[$const.".."]);
00817                                 $c_arr = explode(chr(10),$comment);
00818                                 while(list($k,$v)=each($c_arr)) {
00819                                         $line=trim(ereg_replace("^[#\/]*","",$v));
00820                                         if ($line)      {
00821                                                 $parts = explode(";", $line);
00822                                                 while(list(,$par)=each($parts))         {
00823                                                         if (strstr($par,"="))   {
00824                                                                 $keyValPair =explode("=",$par,2);
00825                                                                 switch(trim(strtolower($keyValPair[0])))        {
00826                                                                         case "type":
00827                                                                                         // Type:
00828                                                                                         /*
00829         int (range; low-high, list: item,item,item = selector),
00830         boolean (check),
00831         string (default),
00832         wrap,
00833         html-color ...,
00834         file
00835                                                                                         */
00836                                                                                 $editableComments[$const]["type"] = trim($keyValPair[1]);
00837                                                                         break;
00838                                                                         case "cat":
00839                                                                                         // list of categories.
00840                                                                                 $catSplit=explode("/",strtolower($keyValPair[1]));
00841                                                                                 $editableComments[$const]["cat"] = trim($catSplit[0]);
00842                                                                                 $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.
00843                                                                                 if ($catSplit[1] && isset($this->subCategories[$catSplit[1]]))  {
00844                                                                                         $editableComments[$const]["subcat_name"]=$catSplit[1];
00845                                                                                         $editableComments[$const]["subcat"]=$this->subCategories[$catSplit[1]][1]."/".$catSplit[1]."/".trim($catSplit[2])."z";
00846                                                                                 } else {
00847                                                                                         $editableComments[$const]["subcat"]="x"."/".trim($catSplit[2])."z";
00848                                                                                 }
00849                                                                         break;
00850                                                                         case "label":
00851                                                                                         // label
00852                                                                                 $editableComments[$const]["label"] = trim($keyValPair[1]);
00853                                                                         break;
00854                                                                 }
00855                                                         }
00856                                                 }
00857                                         }
00858                                 }
00859                         }
00860                         if (isset($editableComments[$const]))   {
00861                                 $editableComments[$const]["name"]=$const;
00862                                 $editableComments[$const]["value"]=trim($value);
00863                                 if (isset($default[$const]))    {
00864                                         $editableComments[$const]["default_value"]=trim($default[$const]);
00865                                 }
00866                         }
00867                 }
00868                 return $editableComments;
00869         }
00870 
00877         function ext_categorizeEditableConstants($editConstArray)       {
00878                 // Runs through the available constants and fills the $this->categories array with pointers and priority-info
00879                 reset($editConstArray);
00880                 while(list($constName,$constData)=each($editConstArray))        {
00881                         if (!$constData["type"])        {$constData["type"]="string";}
00882                         $cats = explode(",",$constData["cat"]);
00883                         reset($cats);
00884                         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...
00885                                 $theCat=trim($theCat);
00886                                 if ($theCat)    {
00887                                         $this->categories[$theCat][$constName]=$constData["subcat"];
00888 //                                      $this->categories["all"][$constName]=$constData["subcat"];
00889                                 }
00890                         }
00891                 }
00892 //              debug($this->categories);
00893         }
00894 
00900         function ext_getCategoryLabelArray()    {
00901                 // Returns array used for labels in the menu.
00902                 $retArr = array();
00903                 while(list($k,$v)=each($this->categories))      {
00904                         if (count($v))  {
00905                                 $retArr[$k]=strtoupper($k)." (".count($v).")";
00906                         }
00907                 }
00908                 return $retArr;
00909         }
00910 
00917         function ext_getTypeData($type) {
00918                 $retArr = array();
00919                 $type=trim($type);
00920                 if (!$type)     {
00921                         $retArr["type"]="string";
00922                 } else {
00923                         $m=strcspn ($type," [");
00924                         $retArr["type"]=strtolower(substr($type,0,$m));
00925                         if (t3lib_div::inList("int,options,file,boolean,offset",$retArr["type"]))       {
00926                                 $p=trim(substr($type,$m));
00927                                 $reg = array();
00928                                 ereg("\[(.*)\]",$p,$reg);
00929                                 $p=trim($reg[1]);
00930                                 if ($p) {
00931                                         $retArr["paramstr"]=$p;
00932                                         switch($retArr["type"]) {
00933                                                 case "int":
00934                                                         if (substr($retArr["paramstr"],0,1)=="-")       {
00935                                                                 $retArr["params"]=t3lib_div::intExplode("-",substr($retArr["paramstr"],1));
00936                                                                 $retArr["params"][0]=intval("-".$retArr["params"][0]);
00937                                                         } else {
00938                                                                 $retArr["params"]=t3lib_div::intExplode("-",$retArr["paramstr"]);
00939                                                         }
00940                                                         $retArr["paramstr"]=$retArr["params"][0]." - ".$retArr["params"][1];
00941                                                 break;
00942                                                 case "options":
00943                                                         $retArr["params"]=explode(",",$retArr["paramstr"]);
00944                                                 break;
00945                                         }
00946                                 }
00947                         }
00948                 }
00949 //              debug($retArr);
00950                 return $retArr;
00951         }
00952 
00959         function ext_getTSCE_config($category)  {
00960                 $catConf=$this->setup["constants"]["TSConstantEditor."][$category."."];
00961                 $out=array();
00962                 if (is_array($catConf)) {
00963                         reset($catConf);
00964                         while(list($key,$val)=each($catConf))   {
00965                                 switch($key)    {
00966                                         case "image":
00967                                                 $out["imagetag"] = $this->ext_getTSCE_config_image($catConf["image"]);
00968                                         break;
00969                                         case "description":
00970                                         case "bulletlist":
00971                                         case "header":
00972                                                 $out[$key] = $val;
00973                                         break;
00974                                         default:
00975                                                 if (t3lib_div::testInt($key))   {
00976                                                         $constRefs = explode(",",$val);
00977                                                         reset($constRefs);
00978                                                         while(list(,$const)=each($constRefs))   {
00979                                                                 $const=trim($const);
00980                                                                 if ($const && $const<=20)       {
00981                                                                         $out["constants"][$const].=$this->ext_getKeyImage($key);
00982                                                                 }
00983                                                         }
00984                                                 }
00985                                         break;
00986                                 }
00987                         }
00988                 }
00989                 $this->helpConfig=$out;
00990         }
00991 
00998         function ext_getKeyImage($key)  {
00999                 return '<img src="'.$this->ext_localWebGfxPrefix.'gfx/'.$key.'.gif" align="top" hspace=2>';
01000         }
01001 
01008         function ext_getTSCE_config_image($imgConf)     {
01009                 if (substr($imgConf,0,4)=="gfx/")       {
01010                         $iFile=$this->ext_localGfxPrefix.$imgConf;
01011                         $tFile=$this->ext_localWebGfxPrefix.$imgConf;
01012                 } elseif (substr($imgConf,0,4)=='EXT:') {
01013                         $iFile = t3lib_div::getFileAbsFileName($imgConf);
01014                         if ($iFile)     {
01015                                 $f = substr($iFile,strlen(PATH_site));
01016                                 $tFile=$GLOBALS["BACK_PATH"]."../".$f;
01017                         }
01018                 } else {
01019                         $f = "uploads/tf/".$this->extractFromResources($this->setup["resources"],$imgConf);
01020                         $iFile=PATH_site.$f;
01021                         $tFile=$GLOBALS["BACK_PATH"]."../".$f;
01022                 }
01023                 $imageInfo=@getImagesize($iFile);
01024                 return '<img src="'.$tFile.'" '.$imageInfo[3].'>';
01025         }
01026 
01032         function ext_resourceDims()     {
01033                 if ($this->setup["resources"])  {
01034                         $rArr=explode(",",$this->setup["resources"]);
01035                         while(list($c,$val)=each($rArr))        {
01036                                 $val=trim($val);
01037                                 $theFile = PATH_site."uploads/tf/".$val;
01038                                 if ($val && @is_file($theFile)) {
01039                                         $imgInfo = @getimagesize($theFile);
01040                                 }
01041                                 if (is_array($imgInfo)) {
01042                                         $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
01043                                 }
01044                         }
01045                 }
01046                 reset($this->dirResources);
01047                 while(list($c,$val)=each($this->dirResources))  {
01048                         $val=trim($val);
01049                         $imgInfo = @getimagesize(PATH_site.$val);
01050                         if (is_array($imgInfo)) {
01051                                 $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
01052                         }
01053                 }
01054         }
01055 
01062         function ext_readDirResources($path)    {
01063                 $path=trim($path);
01064                 if ($path && substr($path,0,10)=="fileadmin/")  {
01065                         $path = ereg_replace("\/$","",$path);
01066                         $this->readDirectory(PATH_site.$path);
01067                 }
01068         }
01069 
01077         function readDirectory($path,$type="file")      {
01078                 if(@is_dir($path))      {
01079                         $d = @dir($path);
01080                         $tempArray=Array();
01081                         if (is_object($d))      {
01082                                 while($entry=$d->read()) {
01083                                         if ($entry!="." && $entry!="..")        {
01084                                                 $wholePath = $path."/".$entry;          // Because of odd PHP-error where  <BR>-tag is sometimes placed after a filename!!
01085                                                 if (@file_exists($wholePath) && (!$type || filetype($wholePath)==$type))        {
01086                                                         $fI = t3lib_div::split_fileref($wholePath);
01087                                                         $this->dirResources[]=substr($wholePath,strlen(PATH_site));
01088                                                 }
01089                                         }
01090                                 }
01091                                 $d->close();
01092                         }
01093                 }
01094         }
01095 
01102         function ext_fNandV($params)    {
01103                 $fN='data['.$params["name"].']';
01104                 $fV=$params["value"];
01105                 if (ereg("^{[\$][a-zA-Z0-9\.]*}$",trim($fV),$reg))      {               // Values entered from the constantsedit cannot be constants!   230502; removed \{ and set {
01106                         $fV="";
01107                 }
01108                 $fV=htmlspecialchars($fV);
01109 
01110                 return array($fN,$fV,$params);
01111         }
01112 
01120         function ext_printFields($theConstants,$category)       {
01121                         // This functions returns the HTML-code that creates the editor-layout of the module.
01122                 reset($theConstants);
01123                 $output="";
01124                 $subcat="";
01125                 if (is_array($this->categories[$category]))     {
01126 
01127                         $help=$this->helpConfig;
01128                         $this->rArr=explode(",",$this->setup["resources"].",".implode($this->dirResources,","));
01129 
01130                         if (!$this->doNotSortCategoriesBeforeMakingForm) asort($this->categories[$category]);
01131                         while(list($name,$type)=each($this->categories[$category]))     {
01132                                 $params = $theConstants[$name];
01133                                 if (is_array($params))  {
01134                                         if ($subcat!=$params["subcat_name"])    {
01135                                                 $subcat=$params["subcat_name"];
01136                                                 $subcat_name = $params["subcat_name"] ? $this->subCategories[$params["subcat_name"]][0] : "Others";
01137                                                 $output.='<tr>';
01138                                                 $output.='<td colspan=2 class="bgColor4"><div align="center"><b>'.$subcat_name.'</b></div></td>';
01139                                                 $output.='</tr>';
01140                                         }
01141 
01142                         //              if (substr($params["value"],0,2)!='{$') {
01143                                                 $label=$GLOBALS["LANG"]->sL($params["label"]);
01144                                                 $label_parts = explode(":",$label,2);
01145                                                 if (count($label_parts)==2)     {
01146                                                         $head=trim($label_parts[0]);
01147                                                         $body=trim($label_parts[1]);
01148                                                 } else {
01149                                                         $head=trim($label_parts[0]);
01150                                                         $body="";
01151                                                 }
01152                                                 if (strlen($head)>35)   {
01153                                                         if (!$body) {$body=$head;}
01154                                                         $head=t3lib_div::fixed_lgd_cs($head,35);
01155                                                 }
01156                                                 $typeDat=$this->ext_getTypeData($params["type"]);
01157                                                 $checked="";
01158                                                 $p_field="";
01159                                                 $raname = substr(md5($params["name"]),0,10);
01160                                                 $aname="'".$raname."'";
01161                                                 if ($this->ext_dontCheckIssetValues || isset($this->objReg[$params["name"]]))   {
01162                                                         $checked=" checked";
01163                                                         list($fN,$fV,$params)=$this->ext_fNandV($params);
01164 
01165                                                         switch($typeDat["type"])        {
01166                                                                 case "int":
01167                                                                 case "int+":
01168                                                                         $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(5).' onChange="uFormUrl('.$aname.')">';
01169                                                                         if ($typeDat["paramstr"])       {
01170                                                                                 $p_field.=' Range: '.$typeDat["paramstr"];
01171                                                                         } elseif ($typeDat["type"]=="int+") {
01172                                                                                 $p_field.=' Range: 0 - ';
01173                                                                         } else {
01174                                                                                 $p_field.=' (Integer)';
01175                                                                         }
01176                                                                 break;
01177                                                                 case "color":
01178                                                                         $colorNames=explode(",",",".$this->HTMLcolorList);
01179                                                                         $p_field="";
01180                                                                         while(list(,$val)=each($colorNames))    {
01181                                                                                 $sel="";
01182                                                                                 if ($val==strtolower($params["value"])) {$sel=" selected";}
01183                                                                                 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.'</option>';
01184                                                                         }
01185                                                                         $p_field='<select name="C'.$fN.'" onChange="document.'.$this->ext_CEformName.'[\''.$fN.'\'].value=this.options[this.selectedIndex].value; uFormUrl('.$aname.');">'.$p_field.'</select>';
01186 
01187                                                                         $p_field.='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(7).' onChange="uFormUrl('.$aname.')">';
01188                                                                 break;
01189                                                                 case "wrap":
01190                                                                         $wArr = explode("|",$fV);
01191                                                                         $p_field='<input type="text" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(29).' onChange="uFormUrl('.$aname.')">';
01192                                                                         $p_field.=' | ';
01193                                                                         $p_field.='<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(15).' onChange="uFormUrl('.$aname.')">';
01194                                                                 break;
01195                                                                 case "offset":
01196                                                                         $wArr = explode(",",$fV);
01197                                                                         $labels = t3lib_div::trimExplode(",",$typeDat["paramstr"]);
01198                                                                         $p_field=($labels[0]?$labels[0]:"x").':<input type="text" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
01199                                                                         $p_field.=' , ';
01200                                                                         $p_field.=($labels[1]?$labels[1]:"y").':<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
01201                                                                         for ($aa=2;$aa<count($labels);$aa++)    {
01202                                                                                 if ($labels[$aa])       {
01203                                                                                         $p_field.=' , '.$labels[$aa].':<input type="text" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
01204                                                                                 } else {
01205                                                                                         $p_field.='<input type="hidden" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'">';
01206                                                                                 }
01207                                                                         }
01208                                                                 break;
01209                                                                 case "options":
01210                                                                         if (is_array($typeDat["params"]))       {
01211                                                                                 $p_field="";
01212                                                                                 while(list(,$val)=each($typeDat["params"]))     {
01213                                                                                         $vParts = explode("=",$val,2);
01214                                                                                         $label = $vParts[0];
01215                                                                                         $val = isset($vParts[1]) ? $vParts[1] : $vParts[0];
01216 
01217                                                                                                 // option tag:
01218                                                                                         $sel="";
01219                                                                                         if ($val==$params["value"])     {$sel=" selected";}
01220                                                                                         $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$GLOBALS["LANG"]->sL($label).'</option>';
01221                                                                                 }
01222                                                                                 $p_field='<select name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
01223                                                                         }
01224                                                                 break;
01225                                                                 case "boolean":
01226                                                                         $p_field='<input type="Hidden" name="'.$fN.'" value="0">';
01227                                                                         $sel=""; if ($fV)       {$sel=" checked";}
01228                                                                         $p_field.='<input type="Checkbox" name="'.$fN.'" value="'.($typeDat["paramstr"]?$typeDat["paramstr"]:1).'"'.$sel.' onClick="uFormUrl('.$aname.')">';
01229                                                                 break;
01230                                                                 case "comment":
01231                                                                         $p_field='<input type="Hidden" name="'.$fN.'" value="#">';
01232                                                                         $sel=""; if (!$fV)      {$sel=" checked";}
01233                                                                         $p_field.='<input type="Checkbox" name="'.$fN.'" value=""'.$sel.' onClick="uFormUrl('.$aname.')">';
01234                                                                 break;
01235                                                                 case "file":
01236                                                                         $p_field='<option value=""></option>';
01237 //                                                                      debug($params["value"]);
01238                                                                         $theImage="";
01239 //                                                                      if ($this->)    {
01240                                                                                 $selectThisFile = $this->extractFromResources($this->setup["resources"],$params["value"]);
01241                                                                                 if ($params["value"] && !$selectThisFile)       {
01242                                                                                         if (in_array($params["value"],$this->dirResources))     {
01243                                                                                                 $selectThisFile=$params["value"];
01244                                                                                         }
01245                                                                                 }
01246 //                                                                              debug($selectThisFile);
01247                                                                                         // extensionlist
01248                                                                                 $extList = $typeDat["paramstr"];
01249                                                                                 $p_field='<option value="">('.$extList.')</option>';
01250                                                                                 if ($extList=="IMAGE_EXT")      {
01251                                                                                         $extList = $GLOBALS["TYPO3_CONF_VARS"]["GFX"]["imagefile_ext"];
01252                                                                                 }
01253                                                                                 reset($this->rArr);
01254                                                                                 $onlineResourceFlag=$this->ext_defaultOnlineResourceFlag;
01255 
01256                                                                                 while(list($c,$val)=each($this->rArr))  {
01257                                                                                         $val=trim($val);
01258                                                                                         $fI=t3lib_div::split_fileref($val);
01259 //                                                                                      debug($fI);
01260                                                                                         if ($val && (!$extList || t3lib_div::inList($extList,$fI["fileext"])))  {
01261                                                                                                 if ($onlineResourceFlag<=0 && substr($fI["path"],0,10)=="fileadmin/")   {
01262                                                                                                         if ($onlineResourceFlag<0)      {
01263                                                                                                                 $p_field.='<option value=""></option>';
01264                                                                                                         }
01265                                                                                                         $p_field.='<option value="">__'.$fI["path"].'__:</option>';
01266                                                                                                         $onlineResourceFlag=1;
01267                                                                                                 }
01268                                                                                                 $dims=$this->resourceDimensions[$val];
01269                                                                                                 $sel="";
01270 
01271                                                                                                         // Check if $params["value"] is in the list of resources.
01272                                                                                                 if ($selectThisFile && $selectThisFile==$val)   {
01273                                                                                                         $sel=" selected";
01274                                                                                                         if ($onlineResourceFlag<=0)     {
01275                                                                                                                 $theImage=t3lib_BEfunc::thumbCode(array("resources"=>$selectThisFile),"sys_template","resources",$GLOBALS["BACK_PATH"],"");
01276                                                                                                         } else {
01277                                                                                                                 $theImage=t3lib_BEfunc::thumbCode(array("resources"=>$fI["file"]),"sys_template","resources",$GLOBALS["BACK_PATH"],"",$fI["path"]);
01278                                                                                                         }
01279                                                                                                 }
01280 
01281                                                                                                 if ($onlineResourceFlag<=0)     {
01282                                                                                                         $onlineResourceFlag--;
01283                                                                                                                 // Value is set with a *
01284                                                                                                         $val = $this->ext_setStar($val);
01285                                                                                                         $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.$dims.'</option>';
01286                                                                                                 } else {
01287                                                                                                         $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$fI["file"].$dims.'</option>';
01288                                                                                                 }
01289                                                                                         }
01290                                                                                 }
01291                                                                                 if (trim($params["value"]) && !$selectThisFile) {
01292                                                                                         $val = $params["value"];
01293                                                                                         $p_field.='<option value=""></option>';
01294                                                                                         $p_field.='<option value="'.htmlspecialchars($val).'" selected>'.$val.'</option>';
01295                                                                                 }
01296         //                                                              }
01297                                                                         $p_field='<select name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
01298                                                                         $p_field.=$theImage;
01299 
01300                                                                         if (!$this->ext_noCEUploadAndCopying)   {
01301                                                                                         // Copy a resource
01302                                                                                 $copyFile = $this->extractFromResources($this->setup["resources"],$params["value"]);
01303                                                                                 if (!$copyFile) {
01304                                                                                         if ($params["value"])   {
01305                                                                                                 $copyFile=PATH_site.$this->ext_detectAndFixExtensionPrefix($params["value"]);
01306                                                                                         }
01307                                                                                 } else {
01308         //                                                                              $copyFile=PATH_site."uploads/tf/".$copyFile;
01309                                                                                         $copyFile="";
01310                                                                                 }
01311 #debug($copyFile);
01312                                                                                 if ($copyFile && @is_file($copyFile))   {
01313                                                                                         $p_field.='<img src="clear.gif" width="20" height="1" alt="" /><img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/clip_copy.gif','width="12" height="12"').' border="0" alt="" /><input type="Checkbox" name="_copyResource['.$params["name"].']" value="'.htmlspecialchars($copyFile).'" onClick="uFormUrl('.$aname.');if (this.checked) {alert(unescape(\''.rawurlencode(sprintf("This will make a copy of the current file, '%s'. Do you really want that?",$params["value"])).'\'));}">';
01314                                                                                 }
01315                                                                                         // Upload?
01316                                                                                 $p_field.='<BR>';
01317                                                                                 $p_field.='<input type="file" name="upload_'.$fN.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth().' onChange="uFormUrl('.$aname.')" size="50" />';
01318                                                                         }
01319                                                                 break;
01320                                                                 case 'small':
01321                                                                 default:
01322                                                                         $fwidth= $typeDat["type"]=="small" ? 10 : 46;
01323                                                                         $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth($fwidth).' onChange="uFormUrl('.$aname.')">';
01324                                                                 break;
01325                                                         }
01326                                                 }
01327                                                 if (!$this->ext_dontCheckIssetValues)   $p_field='<input type="Checkbox" name="check['.$params["name"].']" value="1"'.$checked.' onClick="uFormUrl('.$aname.')">'.$p_field;
01328                                                 if ($typeDat["type"]=="color" && substr($params["value"],0,2)!='{$')    {
01329                                                         $p_field='<table border=0 cellpadding=0 cellspacing=0><tr><td nowrap>'.$p_field.'</td><td>&nbsp;</td><td bgcolor="'.$params["value"].'"><img src="clear.gif" width=50 height=10></td></tr></table>';
01330                                                 } else {
01331                                                         $p_field='<span class="nobr">'.$p_field.'</span><br />';
01332                                                 }
01333 
01334                                                 $p_name = '<span class="typo3-dimmed">['.$params["name"].']</span><BR>';
01335                                                 $p_dlabel='<span class="typo3-dimmed"><b>Default:</b> '.htmlspecialchars($params["default_value"]).'</span><BR>';
01336                                                 $p_label = '<b>'.htmlspecialchars($head).'</b>';
01337                                                 $p_descrip = $body ? htmlspecialchars($body)."<BR>" : "";
01338 
01339                                                 $output.='<tr>';
01340                                                 $output.='<td valign=top nowrap><a name="'.$raname.'"></a>'.$help["constants"][$params["name"]].$p_label.'</td>';
01341                                                 $output.='<td valign=top align="right">'.$p_name.'</td>';
01342                                                 $output.='</tr>';
01343                                                 $output.='<tr>';
01344                                                 $output.='<td colspan=2>'.$p_descrip.$p_field.$p_dlabel.'<br></td>';
01345                                                 $output.='</tr>';
01346                         //              }
01347                                 } else {
01348                                         debug("Error. Constant did not exits. Should not happen.");
01349                                 }
01350                         }
01351                         $output='<table border=0 cellpadding=0 cellspacing=0>'.$output.'</table>';
01352                 }
01353                 return $output;
01354         }
01355 
01356 
01357 
01358 
01359 
01360 
01361 
01362 
01363 
01364 
01365 
01366 
01367         /***************************
01368          *
01369          * Processing input values
01370          *
01371          ***************************/
01372 
01377         function ext_regObjectPositions($constants)     {
01378                         // 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
01379                 $this->raw = explode(chr(10),$constants);
01380                 $this->rawP=0;
01381 
01382                 $this->objReg=array();          // resetting the objReg if the divider is found!!
01383                 $this->ext_regObjects("");
01384         }
01385 
01392         function ext_regObjects($pre)   {
01393                         // works with regObjectPositions. "expands" the names of the TypoScript objects
01394                 while (isset($this->raw[$this->rawP]))  {
01395                         $line = ltrim($this->raw[$this->rawP]);
01396                         if (strstr($line,$this->edit_divider))  {
01397                                 $this->objReg=array();          // resetting the objReg if the divider is found!!
01398                         }
01399                         $this->rawP++;
01400                         if ($line)      {
01401                                 if (substr($line,0,1)=="[")     {
01402 //                                      return $line;
01403                                 } elseif (strcspn($line,"}#/")!=0)      {
01404                                         $varL = strcspn($line," {=<");
01405                                         $var=substr($line,0,$varL);
01406                                         $line = ltrim(substr($line,$varL));
01407                                         switch(substr($line,0,1))       {
01408                                                 case "=":
01409                                                         $this->objReg[$pre.$var]=$this->rawP-1;
01410                                                 break;
01411                                                 case "{":
01412                                                         $this->ext_inBrace++;
01413                                                         $this->ext_regObjects($pre.$var.".");
01414                                                 break;
01415                                         }
01416                                         $this->lastComment="";
01417                                 } elseif (substr($line,0,1)=="}")       {
01418                                         $this->lastComment="";
01419                                         $this->ext_inBrace--;
01420                                         if ($this->ext_inBrace<0)       {
01421                                                 $this->ext_inBrace=0;
01422                                         } else {
01423                                                 break;
01424                                         }
01425                                 }
01426                         }
01427                 }
01428         }
01429 
01437         function ext_putValueInConf($key, $var) {
01438                         // Puts the value $var to the TypoScript value $key in the current lines of the templates.
01439                         // If the $key is not found in the template constants field, a new line is inserted in the bottom.
01440                 $theValue = " ".trim($var);
01441                 if (isset($this->objReg[$key])) {
01442                         $lineNum = $this->objReg[$key];
01443                         $parts = explode("=",$this->raw[$lineNum],2);
01444                         if (count($parts)==2)   {
01445                                 $parts[1]= $theValue;
01446                         }
01447                         $this->raw[$lineNum]=implode($parts,"=");
01448                 } else {
01449                         $this->raw[]=$key." =".$theValue;
01450                 }
01451                 $this->changed=1;
01452         }
01453 
01460         function ext_removeValueInConf($key)    {
01461                         // Removes the value in the configuration
01462                 if (isset($this->objReg[$key])) {
01463                         $lineNum = $this->objReg[$key];
01464                         unset($this->raw[$lineNum]);
01465                 }
01466                 $this->changed=1;
01467         }
01468 
01476         function ext_depthKeys($arr,$settings)  {
01477                 reset($arr);
01478                 $tsbrArray=array();
01479                 while(list($theK,$theV)=each($arr))     {
01480                         $theKeyParts = explode(".",$theK);
01481                         $depth="";
01482                         $c=count($theKeyParts);
01483                         $a=0;
01484                         while(list(,$p)=each($theKeyParts))     {
01485                                 $a++;
01486                                 $depth.=($depth?".":"").$p;
01487                                 $tsbrArray[$depth]= ($c==$a) ? $theV : 1;
01488                         }
01489                 }
01490                         // Modify settings
01491                 reset($tsbrArray);
01492                 while(list($theK,$theV)=each($tsbrArray))       {
01493                         if ($theV)      {
01494                                 $settings[$theK] = 1;
01495                         } else {
01496                                 unset($settings[$theK]);
01497                         }
01498                 }
01499                 return $settings;
01500         }
01501 
01511         function ext_procesInput($http_post_vars,$http_post_files,$theConstants,$tplRow)        {
01512                 $data=$http_post_vars["data"];
01513                 $check=$http_post_vars["check"];
01514                 $copyResource=$http_post_vars["_copyResource"];
01515                 $Wdata=$http_post_vars["Wdata"];
01516                 $W2data=$http_post_vars["W2data"];
01517                 $W3data=$http_post_vars["W3data"];
01518                 $W4data=$http_post_vars["W4data"];
01519                 $W5data=$http_post_vars["W5data"];
01520 
01521                 if (is_array($data))    {
01522                         reset($data);
01523                         while(list($key,$var)=each($data))      {
01524                                 if (isset($theConstants[$key])) {
01525                                         if ($this->ext_dontCheckIssetValues || isset($check[$key]))     {               // If checkbox is set, update the value
01526                                                 list($var) = explode(chr(10),$var);     // exploding with linebreak, just to make sure that no multiline input is given!
01527                                                 $typeDat=$this->ext_getTypeData($theConstants[$key]["type"]);
01528                                                 switch($typeDat["type"])        {
01529                                                         case "int":
01530                                                                 if ($typeDat["paramstr"])       {
01531                                                                         $var=t3lib_div::intInRange($var,$typeDat["params"][0],$typeDat["params"][1]);
01532                                                                 } else {
01533                                                                         $var=intval($var);
01534                                                                 }
01535                                                         break;
01536                                                         case "int+":
01537                                                                 $var=t3lib_div::intInRange($var,0,10000);
01538                                                         break;
01539                                                         case "color":
01540                                                                 $col=array();
01541                                                                 if($var && !t3lib_div::inList($this->HTMLcolorList,strtolower($var)))   {
01542                                                                         $var = ereg_replace("[^A-Fa-f0-9]*","",$var);
01543                                                                         $col[]=HexDec(substr($var,0,2));
01544                                                                         $col[]=HexDec(substr($var,2,2));
01545                                                                         $col[]=HexDec(substr($var,4,2));
01546                                                                         $var="#".strtoupper(substr("0".DecHex($col[0]),-2).substr("0".DecHex($col[1]),-2).substr("0".DecHex($col[2]),-2));
01547                                                                 }
01548                                                         break;
01549                                                         case "comment":
01550                                                                 if ($var)       {
01551                                                                         $var="#";
01552                                                                 } else {
01553                                                                         $var="";
01554                                                                 }
01555                                                         break;
01556                                                         case "wrap":
01557                                                                 if (isset($Wdata[$key]))        {
01558                                                                         $var.="|".$Wdata[$key];
01559                                                                 }
01560                                                         break;
01561                                                         case "offset":
01562                                                                 if (isset($Wdata[$key]))        {
01563                                                                         $var=intval($var).",".intval($Wdata[$key]);
01564                                                                         if (isset($W2data[$key]))       {
01565                                                                                 $var.=",".intval($W2data[$key]);
01566                                                                                 if (isset($W3data[$key]))       {
01567                                                                                         $var.=",".intval($W3data[$key]);
01568                                                                                         if (isset($W4data[$key]))       {
01569                                                                                                 $var.=",".intval($W4data[$key]);
01570                                                                                                 if (isset($W5data[$key]))       {
01571                                                                                                         $var.=",".intval($W5data[$key]);
01572                                                                                                 }
01573                                                                                         }
01574                                                                                 }
01575                                                                         }
01576                                                                 }
01577                                                         break;
01578                                                         case "boolean":
01579                                                                 if ($var)       {
01580                                                                         $var = $typeDat["paramstr"] ? $typeDat["paramstr"] : 1;
01581                                                                 }
01582                                                         break;
01583                                                         case "file":
01584                                                                 if (!$this->ext_noCEUploadAndCopying)   {
01585                                                                         if ($http_post_files["upload_data"]["name"][$key] && $http_post_files["upload_data"]["tmp_name"][$key]!="none") {
01586                                                                                 $var = $this->upload_copy_file(
01587                                                                                         $typeDat,
01588                                                                                         $tplRow,
01589                                                                                         trim($http_post_files["upload_data"]["name"][$key]),
01590                                                                                         $http_post_files["upload_data"]["tmp_name"][$key]
01591                                                                                 );
01592                                                                         }
01593                                                                         if ($copyResource[$key])        {
01594                                                                                 $var = $this->upload_copy_file(
01595                                                                                         $typeDat,
01596                                                                                         $tplRow,
01597                                                                                         basename($copyResource[$key]),
01598                                                                                         $copyResource[$key]
01599                                                                                 );
01600                                                                         }
01601                                                                 }
01602                                                         break;
01603                                                 }
01604                                                 if ($this->ext_printAll || strcmp($theConstants[$key]["value"],$var))   {
01605                                                         $this->ext_putValueInConf($key, $var);          // Put value in, if changed.
01606                                                 }
01607                                                 unset($check[$key]);            // Remove the entry because it has been "used"
01608                                         } else {
01609                                                 $this->ext_removeValueInConf($key);
01610                                         }
01611                                 }
01612                         }
01613                 }
01614                         // 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...
01615                 if (!$this->ext_dontCheckIssetValues && is_array($check))       {
01616                         reset($check);
01617                         while(list($key,$var)=each($check))     {
01618                                 if (isset($theConstants[$key])) {
01619                                         $dValue = $theConstants[$key]["default_value"];
01620 //                                      debug($dValue);
01621                                         $this->ext_putValueInConf($key, $dValue);
01622 //                                      debug($key,1);
01623                                 }
01624                         }
01625                 }
01626 //              debug($this->objReg);
01627         }
01628 
01638         function upload_copy_file($typeDat,&$tplRow,$theRealFileName,$tmp_name) {
01639 
01640                         // extensions
01641                 $extList = $typeDat["paramstr"];
01642                 if ($extList=="IMAGE_EXT")      {
01643                         $extList = $GLOBALS["TYPO3_CONF_VARS"]["GFX"]["imagefile_ext"];
01644                 }
01645                 $fI=t3lib_div::split_fileref($theRealFileName);
01646                 if ($theRealFileName && (!$extList || t3lib_div::inList($extList,$fI["fileext"])))      {
01647                         $tmp_upload_name = t3lib_div::upload_to_tempfile($tmp_name);    // If there is an uploaded file, move it for the sake of safe_mode.
01648 
01649                                 // Saving resource
01650                         $alternativeFileName=array();
01651                         $alternativeFileName[$tmp_upload_name] = $theRealFileName;
01652                                 // Making list of resources
01653                         $resList = $tplRow["resources"];
01654                         $resList = $tmp_upload_name.",".$resList;
01655                         $resList=implode(t3lib_div::trimExplode(",",$resList,1),",");
01656                                 // Making data-array
01657                         $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
01658 // debug($saveId);
01659                         $recData=array();
01660                         $recData["sys_template"][$saveId]["resources"] = $resList;
01661                                 // Saving
01662                         $tce = t3lib_div::makeInstance("t3lib_TCEmain");
01663                         $tce->stripslashes_values=0;
01664                         $tce->alternativeFileName = $alternativeFileName;
01665                         $tce->start($recData,Array());
01666                         $tce->process_datamap();
01667 
01668                         t3lib_div::unlink_tempfile($tmp_upload_name);
01669 
01670                         $tmpRow = t3lib_BEfunc::getRecordWSOL("sys_template",$saveId,"resources");
01671 
01672                         $tplRow["resources"] = $tmpRow["resources"];
01673 
01674                                 // Setting the value
01675                         $var = $this->ext_setStar($theRealFileName);
01676                 }
01677                 return $var;
01678         }
01679 
01687         function ext_prevPageWithTemplate($id,$perms_clause)    {
01688                 $rootLine = t3lib_BEfunc::BEgetRootLine($id,$perms_clause?" AND ".$perms_clause:"");
01689                 reset($rootLine);
01690                 while(list(,$p)=each($rootLine))        {
01691                         if ($this->ext_getFirstTemplate($p["uid"]))     {
01692                                 return $p;
01693                         }
01694                 }
01695         }
01696 
01703         function ext_setStar($val)      {
01704                 $fParts = explode(".",strrev($val),2);
01705                 $val=ereg_replace("_[0-9][0-9]$","",strrev($fParts[1]))."*.".strrev($fParts[0]);
01706                 return $val;
01707         }
01708 
01715         function ext_detectAndFixExtensionPrefix($value)        {
01716                 if (substr($value,0,4)=="EXT:") {
01717                         $parts = explode("/",substr($value,4),2);
01718 #debug($parts);
01719                         $extPath = t3lib_extMgm::siteRelPath($parts[0]);
01720                         $value = $extPath.$parts[1];
01721                         return $value;
01722                 } else {
01723                         return $value;
01724                 }
01725         }
01726 }
01727 
01728 
01729 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php'])      {
01730         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php']);
01731 }
01732 ?>


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6