typo3/ext/tstemplate_styler/modfunc1/class.tx_tstemplatestyler_modfunc1.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2002-2005 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 *
00017 *  This script is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00034 require_once(PATH_t3lib."class.t3lib_extobjbase.php");
00035 require_once(PATH_t3lib."class.t3lib_parsehtml.php");
00036 
00037 class tx_tstemplatestyler_modfunc1 extends t3lib_extobjbase {
00038         var $ext_cssMarker = "###CSS_EDITOR STYLE INFORMATION MARKER";
00039         var $HTMLcolorList = "aqua,black,blue,fuchsia,gray,green,lime,maroon,navy,olive,purple,red,silver,teal,yellow,white";
00040 
00041         var $ext_makeStyleDialogFlag=0;
00042         var $ext_compiledExamples =array();
00043         var $ext_compiledStylesheet =array();
00044 
00045         var $ext_depthKeysValues=array();
00046 
00047 
00048         var $ext_plusStyleParsed=array();
00049         var $ext_styleItems = array();
00050         var $ext_matchSelector = array();
00051         var $ext_collectionWithContent = array();
00052 
00053         var $ext_allwaysCleanUpWrittenStyles=0; // If set, then the stylesheets written will be reformatted in a nice style.
00054         var $ext_oneLineMode=1;
00055         var $ext_addComments=0;
00056 
00057 
00058         function modMenu()      {
00059                 global $LANG;
00060 
00061                 return Array (
00062                         "tx_tstemplatestyler_modfunc1_menu" => Array(
00063                                 "editor" => "Editor",
00064                                 "overview" => "Technical overview"
00065                         ),
00066                         "tx_tstemplatestyler_modfunc1_expAll"=>"",
00067                         "tx_tstemplatestyler_modfunc1_showContent"=>"",
00068                         "tx_tstemplatestyler_modfunc1_multipleLines" => "",
00069                         "tx_tstemplatestyler_modfunc1_addComments" => "",
00070                         "tx_tstemplatestyler_modfunc1_keepitLight" => "",
00071 
00072                         "tx_tstemplatestyler_styleCollection" => ""             // Set to blank - then the value is not forced to any other value...
00073                 );
00074         }
00075 
00076         function initialize_editor($pageId,$template_uid=0)     {
00077                         // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
00078                 global $tmpl,$tplRow,$theConstants;
00079 
00080                 $tmpl = t3lib_div::makeInstance("t3lib_tsparser_ext");  // Defined global here!
00081                 $tmpl->parseEditorCfgField=1;   // This makes sure that editorcfg fields are read as well!
00082                 $tmpl->tt_track = 0;    // Do not log time-performance information
00083                 $tmpl->resourceCheck=1;
00084                 $tmpl->uplPath = PATH_site.$tmpl->uplPath;
00085                 $tmpl->removeFromGetFilePath = PATH_site;
00086                 $tmpl->init();
00087 
00088                                 // Gets the rootLine
00089                 $sys_page = t3lib_div::makeInstance("t3lib_pageSelect");
00090                 $rootLine = $sys_page->getRootLine($pageId);
00091                 $tmpl->runThroughTemplates($rootLine,$template_uid);    // This generates the constants/config + hierarchy info for the template.
00092 
00093                 $tplRow = $tmpl->ext_getFirstTemplate($pageId,$template_uid);   // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
00094                 if (is_array($tplRow))  {       // IF there was a template...
00095                         return 1;
00096                 }
00097         }
00098         function main() {
00099                 global $SOBE,$BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
00100                 global $tmpl,$tplRow,$theConstants;
00101 
00102                 // **************************
00103                 // Checking for more than one template an if, set a menu...
00104                 // **************************
00105                 $manyTemplatesMenu = $this->pObj->templateMenu();
00106                 $template_uid = 0;
00107                 if ($manyTemplatesMenu) {
00108                         $template_uid = $this->pObj->MOD_SETTINGS["templatesOnPage"];
00109                 }
00110 
00111                 $this->ext_oneLineMode = !$this->pObj->MOD_SETTINGS["tx_tstemplatestyler_modfunc1_multipleLines"];
00112                 $this->ext_addComments = $this->pObj->MOD_SETTINGS["tx_tstemplatestyler_modfunc1_addComments"];
00113 
00114 
00115                 // **************************
00116                 // Main
00117                 // **************************
00118 
00119                 // BUGBUG: Should we check if the user may at all read and write template-records???
00120                 $existTemplate = $this->initialize_editor($this->pObj->id,$template_uid);               // initialize
00121                 if ($existTemplate)     {
00122                         $theOutput.=$this->pObj->doc->divider(5);
00123                         $theOutput.=$this->pObj->doc->section("Current template:",'<img src="'.$BACK_PATH.t3lib_iconWorks::getIcon("sys_template",$tplRow).'" width=18 height=16 align=top><b>'.$this->pObj->linkWrapTemplateTitle($tplRow["title"], "config").'</b>'.htmlspecialchars(trim($tplRow["sitetitle"])?' - ('.$tplRow["sitetitle"].')':''),0,0);
00124                         if ($manyTemplatesMenu) {
00125                                 $theOutput.=$this->pObj->doc->section($manyTemplatesMenu,"");
00126                                 $theOutput.=$this->pObj->doc->divider(5);
00127                         }
00128                 }
00129 
00130 
00131 
00132                 // If any plus-signs were clicked, it's registred:
00133                 $updateSettings=0;
00134                 $tsbr = t3lib_div::_GET('tsbr');
00135                 if (is_array($tsbr))    {
00136                         $this->pObj->MOD_SETTINGS["cssbrowser_depthKeys"] = $tmpl->ext_depthKeys($tsbr, $this->pObj->MOD_SETTINGS["cssbrowser_depthKeys"]);
00137                         $updateSettings=1;
00138                 }
00139                 $this->ext_depthKeysValues=$this->pObj->MOD_SETTINGS["cssbrowser_depthKeys"];
00140                 if ($updateSettings){   $GLOBALS["BE_USER"]->pushModuleData($this->pObj->MCONF["name"],$this->pObj->MOD_SETTINGS);}
00141 
00142 
00143 
00144 
00145                         // Main function:
00146                 $tmpl->generateConfig();        // This parses the TypoScript into the arrays needed. "editorcfg" is parsed as well
00147 
00148 #debug($tmpl->editorcfg);
00149 #debug($tmpl->setup_editorcfg);
00150 
00151                         // Style collection menu
00152                 $styleCollections = $this->makeStyleCollectionSelector();
00153                 if (count($styleCollections))   {
00154                         $this->pObj->MOD_MENU["tx_tstemplatestyler_styleCollection"]=array();
00155                         reset($styleCollections);
00156                         while(list($sk,$sv)=each($styleCollections))    {
00157                                 $this->pObj->MOD_MENU["tx_tstemplatestyler_styleCollection"][$sk]=$sv["title"];
00158                         }
00159                         $this->pObj->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->pObj->MOD_MENU, t3lib_div::_GP("SET"), $this->pObj->MCONF["name"]);
00160 
00161 
00162 
00163 
00164                                 // *****************
00165                                 // Go main:
00166                                 // *****************
00167 
00168                                 // Based on the RAW current style-collection, the resources content are now read:
00169                                 // Most likely this array should reflect something to base a hash-value upon, after having parsed the content as well in the next section:
00170                         $this->ext_collectionWithContent = $this->readStylesheets($styleCollections[$this->pObj->MOD_SETTINGS["tx_tstemplatestyler_styleCollection"]]);
00171                                 // parsing the style-content which was read.
00172 
00173                         $this->parseStyleContent_begin($this->ext_collectionWithContent["parts"]);
00174 
00175                                 // OK, now $this->ext_styleItems and $this->ext_matchSelector are filled (or fetched from cache) and this means that we can actually write the new information to the right positions if we like
00176 
00177         #                               debug($this->ext_styleItems);
00178         #                               debug($this->ext_matchSelector);
00179 
00180                                 // If write-buttons are pressed:
00181                         $inData = t3lib_div::_GP("tstemplatestyler");
00182                         if ($inData["write1"] || $inData["write2"])     {
00183                                         $this->ext_doWrite=1;
00184                                         $this->makeCSSTree();
00185                                         $this->ext_doWrite=0;
00186 
00187                                 // preparing for writing back the style-content from $this->ext_styleItems
00188                                         $newParts = $this->prepareStyleContent($this->ext_collectionWithContent["parts"]);
00189         #                               debug($newParts);
00190                                         $this->writeStyleContent($newParts);
00191         #debug($GLOBALS["tplRow"]);
00192                                                 // Re-read template and stylesheets
00193                                         $this->ext_styleItems = array();
00194                                         $this->ext_matchSelector = array();
00195                                         $this->ext_collectionWithContent = array();
00196 
00197                                         $tmpl->generateConfig();
00198         #debug($tmpl->setup);
00199 
00200                                         $this->ext_collectionWithContent = $this->readStylesheets($styleCollections[$this->pObj->MOD_SETTINGS["tx_tstemplatestyler_styleCollection"]]);
00201         #debug($this->ext_collectionWithContent);
00202                                         $this->parseStyleContent_begin($this->ext_collectionWithContent["parts"]);
00203                         }
00204 
00205                                 // Editor:
00206                         $this->ext_makeStyleDialogFlag = $this->pObj->MOD_SETTINGS["tx_tstemplatestyler_modfunc1_menu"]=="editor";
00207                         $tree = $this->makeCSSTree($existTemplate);
00208 
00209 
00210         #debug($this->ext_compiledExamples);
00211         #debug($this->ext_compiledStylesheet);
00212 
00213 
00214 
00215 
00216 
00217                         if (t3lib_div::_GP("displayStyle"))     {               // This is display of the examples etc.
00218                                 $examplesCode = implode(chr(10),$this->ext_compiledExamples);
00219 
00220                                 $eCArr=explode('src="EXT:',$examplesCode);
00221                                 next($eCArr);
00222                                 while(list($k,$part)=each($eCArr))      {
00223                                         list($extKey)=explode("/",$part,2);
00224                                         if (t3lib_extMgm::isLoaded($extKey))    {
00225                                                 $p=t3lib_extMgm::extRelPath($extKey);
00226                                                 $eCArr[$k] = $BACK_PATH.(substr($p,0,3)=="../"?"../typo3conf/ext/":"ext/").
00227                                                                                 $eCArr[$k];
00228                                         }
00229                                 }
00230                                 $examplesCode=implode('src="', $eCArr);
00231 
00232 #
00233 
00234                                 $output = '
00235                                         <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
00236 
00237                                         <html>
00238                                         <head>
00239                                                 <title>Untitled</title>
00240 
00241                                                 <style>
00242                                                 '.$this->ext_plusStyle().
00243                                                 implode(chr(10),$this->ext_compiledStylesheet).'
00244                                                 </style>
00245 
00246                                         </head>
00247 
00248                                         <body>
00249                                                 <table border=0 cellpadding=0><tr><td>
00250                                                         '.$examplesCode.'
00251                                                 </td></tr></table>
00252                                         </body>
00253                                         </html>
00254                                 ';
00255                                 echo $output;
00256                                 exit;
00257                         }
00258 
00259 
00260 
00261 
00262                                 // Output:
00263                         $styleColMenu = t3lib_BEfunc::getFuncMenu($this->pObj->id,"SET[tx_tstemplatestyler_styleCollection]",$this->pObj->MOD_SETTINGS["tx_tstemplatestyler_styleCollection"],$this->pObj->MOD_MENU["tx_tstemplatestyler_styleCollection"]);
00264                         $modeMenu = t3lib_BEfunc::getFuncMenu($this->pObj->id,"SET[tx_tstemplatestyler_modfunc1_menu]",$this->pObj->MOD_SETTINGS["tx_tstemplatestyler_modfunc1_menu"],$this->pObj->MOD_MENU["tx_tstemplatestyler_modfunc1_menu"]);
00265 
00266                         if (strcmp($tree,""))   {
00267                                 $theOutput.=$this->pObj->doc->spacer(5);
00268                                 $theOutput.=$this->pObj->doc->section("TypoScript CSS Style tree:",$styleColMenu.$modeMenu,0,1);
00269                                 $theOutput.=$this->pObj->doc->spacer(10);
00270 
00271                                 $theOutput.=$this->pObj->doc->sectionEnd();
00272 
00273                                 $theOutput.='<table border=0 cellpadding=1 cellspacing=0>';
00274                                 if ($this->ext_editBranch)      {
00275                                         $theOutput.='
00276                                                         <tr>
00277                                                                 <td></td>
00278                                                                 <td><strong>Style preview:</strong><BR>
00279                                                                         <IFRAME src="index.php?id='.$this->pObj->id.'&displayStyle=1&editBranch='.$this->ext_editBranch.'" width=500 height=250 style="border: 1px solid;"></iframe>
00280                                                                         </td>
00281                                                         </tr>';
00282                                 }
00283                                 $theOutput.='
00284                                                 <tr>
00285                                                         <td><img src=clear.gif width=4 height=1></td>
00286                                                         <td class="bgColor2">
00287                                                                 <table border=0 cellpadding=0 cellspacing=0 bgcolor="#D9D5C9" width="100%"><tr><td nowrap>'.$tree.'</td></tr></table><img src=clear.gif width=465 height=1></td>
00288                                                 </tr>
00289                                         </table>
00290                                 ';
00291 
00292                                 $theOutput.= t3lib_BEfunc::getFuncCheck($this->pObj->id,"SET[tx_tstemplatestyler_modfunc1_expAll]",$this->pObj->MOD_SETTINGS["tx_tstemplatestyler_modfunc1_expAll"])."Expand ALL branches (takes time)<BR>";
00293                                 $theOutput.= t3lib_BEfunc::getFuncCheck($this->pObj->id,"SET[tx_tstemplatestyler_modfunc1_keepitLight]",$this->pObj->MOD_SETTINGS["tx_tstemplatestyler_modfunc1_keepitLight"])."KISS mode<BR>";
00294                                 $theOutput.= t3lib_BEfunc::getFuncCheck($this->pObj->id,"SET[tx_tstemplatestyler_modfunc1_multipleLines]",$this->pObj->MOD_SETTINGS["tx_tstemplatestyler_modfunc1_multipleLines"])."Write CSS attributes in multiple lines<BR>";
00295                                 $theOutput.= t3lib_BEfunc::getFuncCheck($this->pObj->id,"SET[tx_tstemplatestyler_modfunc1_addComments]",$this->pObj->MOD_SETTINGS["tx_tstemplatestyler_modfunc1_addComments"])."Write comments before selectors<BR>";
00296                         } else {
00297                                 $theOutput.=$this->pObj->doc->section("TypoScript CSS Style tree:","
00298                                 The Stylesheet Editor is based on configuration which tells it about available CSS selectors and attributes for them. No such configuration was found in the 'editorcfg' object tree.<BR>Either there are no static templates which adds configuration or you have not added any valid configuration yourself.
00299                                 ",0,2,2);
00300                         }
00301 
00302                                 // Collection info:
00303                         if (is_array($this->ext_collectionWithContent)) {
00304                                 $cInfo = $this->printCollectionInfo($this->ext_collectionWithContent["parts"]);
00305                                 $cInfoStr = '<table border=0 cellpadding=2 cellspacing=2>'.implode(chr(10),$cInfo).'</table>';
00306                                 $cInfoStr.= t3lib_BEfunc::getFuncCheck($this->pObj->id,"SET[tx_tstemplatestyler_modfunc1_showContent]",$this->pObj->MOD_SETTINGS["tx_tstemplatestyler_modfunc1_showContent"])."Show content";
00307 
00308                                 $theOutput.=$this->pObj->doc->section("Style collection info",$cInfoStr,0,1);
00309                                 $theOutput.=$this->pObj->doc->spacer(10);
00310                         }
00311                 } else {
00312                         $theOutput.=$this->pObj->doc->section("No stylecollections","
00313                                 The stylesheet editor needs to know about one or more stylesheet(s) to edit. None is found at this point.<BR>
00314                                 You can...<BR>
00315                                 1) either manually set up stylesheets by configuring this in the 'Backend Editor Configuration' field (advanced, see documentation) or <BR>
00316                                 2) set stylesheet filenames for your PAGE objects in the TypoScript templates and they will automatically be detected and editable (recommended!)
00317                         ",0,1,1);
00318                         $theOutput.=$this->pObj->doc->spacer(10);
00319                 }
00320 
00321 
00322                         // Cache:
00323                 $theOutput.=$this->pObj->doc->spacer(10);
00324                 $theOutput.=$this->pObj->doc->section("Cache",'Click here to <a href="index.php?id='.$this->pObj->id.'&clear_all_cache=1"><strong>clear all cache</strong></a>',0,1);
00325 
00326                         // Ending section:
00327                 $theOutput.=$this->pObj->doc->sectionEnd();
00328 #debug(strlen($theOutput));
00329                 return $theOutput;
00330         }
00331 
00332 
00336         function makeCSSTree($existTemplate=0,$editBranch="")   {
00337                 global $tmpl;
00338 
00339                         // Init
00340                 $tstemplatestyler = t3lib_div::_GP("tstemplatestyler");
00341                 $editBranch = t3lib_div::_GP("editBranch");
00342                 $this->ext_editBranch = $editBranch = $editBranch ? $editBranch : $tstemplatestyler["editBranch"];
00343 #               if ($this->ext_editBranch)      $this->pObj->MOD_SETTINGS["tx_tstemplatestyler_modfunc1_expAll"]=1;
00344                 $outlines=array();
00345 
00346                 if (is_array($this->ext_collectionWithContent)) {
00347                         if (is_array($this->ext_collectionWithContent["CSS_editor."]))  {
00348                                 $editorObj = $this->ext_collectionWithContent["CSS_editor."]["ch."];
00349                                 $editorTitle = $this->ext_collectionWithContent["CSS_editor"];
00350                         } else {
00351                                 $editorObj = $tmpl->setup_editorcfg["CSS_editor."]["ch."];
00352                                 $editorTitle = $tmpl->setup_editorcfg["CSS_editor"];
00353                         }
00354 #debug($tmpl->setup_editorcfg);
00355 #debug($tmpl->editorcfg);
00356                                 // Starting to make the rows:
00357                         $lines=array();
00358                         if (is_array($editorObj))       {
00359                                 $lines[]=array(
00360                                                 "html" => '<img src="'.$GLOBALS["BACK_PATH"].'gfx/ol/arrowbullet.gif" width="18" height="16" border="0" class="absmiddle" alt="">'.$editorTitle,
00361                                         );
00362 
00363                                 $lines=$this->makeCSSTree_recursive (
00364                                         $editorObj,
00365                                         $lines,
00366                                         '<img src="'.$GLOBALS["BACK_PATH"].'gfx/ol/blank.gif" width="18" height="16" border="0" class="absmiddle">'
00367                                 );
00368                         } else return "";
00369 
00370                                 // Outputting rows:
00371                         reset($lines);
00372                         while(list($k,$v)=each($lines)) {
00373                                 $editFieldsRow=0;
00374                                 if (strcmp($v["html"],""))      {
00375                                         if ($this->pObj->MOD_SETTINGS["tx_tstemplatestyler_modfunc1_menu"]=="editor")   {
00376                                                 $datContent="";
00377                                                 $editIcon="";
00378                                                 if ($v["datObj"] && !$v["exampleStop"]) $editIcon='<a href="'.t3lib_div::linkThisScript(array("editBranch"=>$v["datObj"])).'"><img src="'.$GLOBALS["BACK_PATH"].'gfx/edit2.gif" width="11" hspace=2 height="12" border="0" align="top" alt="Edit branch"></a>';
00379                                                 if ($v["itemSel"])      {       // There must be a selector.
00380                                                         $datContent.='<input type="hidden" name="tstemplatestyler[writeObj]['.$v["datObj"].'.selector]" value="'.htmlspecialchars($v["itemSel"]).'">';
00381                                                         if ($v["attribs"] && $this->ext_makeStyleDialogFlag)    {
00382                                                                 if ($this->matchEB($editBranch,$v["datObj"]))   {       // $v["datObj"]==$editBranch || substr($v["datObj"],0,strlen($editBranch)+1)==$editBranch."."
00383                                                                         if ($this->pObj->MOD_SETTINGS["tx_tstemplatestyler_modfunc1_keepitLight"])      {
00384                                                                                 $datContent.='<input type="text" name="'.$this->formFieldName($v["datObj"],"ALL").'" value="'.htmlspecialchars(trim($v["CSS_data"])).'"
00385                                                                                         title="'.htmlspecialchars(trim($v["CSS_data_default"])?"DEFAULT: ".trim($v["CSS_data_default"]):"").'"
00386                                                                                         style="width:300px;'.(trim($v["CSS_data_default"])?"background-color:#f0f0f0;":"").'"
00387                                                                                         '.(trim($v["CSS_data_default"])&&!$v["CSS_data"]?' onfocus="if (!this.value) {this.value=unescape(\''.rawurlencode(trim($v["CSS_data_default"])).'\');}"':'').'
00388                                                                                         > '.$v["selector"];
00389                                                                         } else $datContent.=$this->makeStyleDialog($v);
00390                                                                         $editFieldsRow=1;
00391                                                                 } else {
00392                                                                         $datContent.=$v["CSS_data"] ? $v["selector"]." { ".$v["CSS_data"]." }" : "";
00393                                                                 }
00394                                                         } else {
00395                                                                 $datContent.='<input type="hidden" name="tstemplatestyler[writeObj]['.$v["datObj"].'.style][ALL]" value="'.htmlspecialchars($v["CSS_data"]).'">';
00396                                                                 if ($this->matchEB($editBranch,$v["datObj"]))   {
00397                                                                         $editFieldsRow=1;
00398                                                                 }
00399                                                         }
00400                                                 }
00401 
00402                                                 if (!$editBranch || $editFieldsRow)     {
00403                                                         $outlines[]='<tr class="bgColor">
00404                                                                 <td nowrap>'.$v["html"].'&nbsp;&nbsp;</td>
00405                                                                 <td>'.$editIcon.'</td>
00406                                                                 <td nowrap>'.$datContent.'</td>
00407                                                         </tr>';
00408                                                 }
00409                                         } else {
00410                                                 $datContent="";
00411                                                 if ($v["itemSel"])      {       // There must be a selector.
00412                                                         $datContent='<input type="hidden" name="tstemplatestyler[writeObj]['.$v["datObj"].'.selector]" value="'.htmlspecialchars($v["itemSel"]).'">';
00413                                                         $datContent.='<input type="text" name="tstemplatestyler[writeObj]['.$v["datObj"].'.style][ALL]" value="'.htmlspecialchars(trim(ereg_replace("[[:space:]]+"," ",$v["CSS_data"]))).'">';
00414                                                 }
00415                                                 $outlines[]='<tr class="bgColor">
00416                                                         <td nowrap>'.$v["html"].'&nbsp;&nbsp;</td>
00417                                                         <td nowrap>'.$v["selector"].'&nbsp;&nbsp;</td>
00418                                                         <td nowrap>'.$datContent.'</td>
00419                                                         <td nowrap>'.$v["resourcePath"].'</td>
00420                                                         <td nowrap>'.$v["attribs"].'&nbsp;&nbsp;</td>
00421                                                         <td nowrap>'.$v["itemSel"].'&nbsp;&nbsp;</td>
00422                                                         <td nowrap>'.$v["datObj"].'&nbsp;&nbsp;</td>
00423                                                 </tr>';
00424                                         }
00425                                 }
00426                         }
00427                 }
00428 
00429 
00430 
00431                         // OUTPUT the stuff:
00432                 $eBCancel='';
00433                 if ($editBranch)        {
00434                         $eBCancel=' <input type="submit" name="_" value="Cancel" onClick="document.location=\''.t3lib_div::linkThisScript(array("editBranch"=>"")).'\';return false;">';
00435                 }
00436                 if ($existTemplate)     {
00437                         $out = '<input type="submit" name="tstemplatestyler[write1]" value="Write changes">'.$eBCancel.'
00438                                 <table border=0 cellpadding=0 cellspacing=1>'.implode("",$outlines).'</table>
00439                                 <input type="hidden" name="tstemplatestyler[editBranch]" value="'.$editBranch.'">
00440                                 <input type="submit" name="tstemplatestyler[write2]" value="Write changes">'.$eBCancel.'
00441                         ';
00442                 } else {
00443                         $out = $GLOBALS["TBE_TEMPLATE"]->rfw("You cannot write changes to the stylesheet unless you are on a page with a template record to write to.").'
00444                         <table border=0 cellpadding=0 cellspacing=1>'.implode("",$outlines).'</table>';
00445                 }
00446 
00447                 return $out;
00448         }
00449 
00453         function makeCSSTree_recursive($eArr,$lines,$preHTML="",$accSel="",$datObj="",$cc=0,$openBranch=1,$exampleStop=0,$titlePath="") {
00454                 $oArr=$this->getEarr($eArr);
00455                 $prevPointer="";
00456 
00457                 reset($oArr);
00458                 while(list($count,$itms)=each($oArr))   {
00459                         list($title,$dat,$k)=$itms;
00460                         if (is_array($dat) && $cc<12)   {
00461                                         // Current selector for this branch
00462                                 $thisSel = trim(substr($dat["selector"],0,1)=="+" ? $accSel.trim(substr($dat["selector"],1)) : $accSel." ".$dat["selector"]);
00463 
00464                                         // references to this position in the hierarchy
00465                                 $datObjRef = $datObj ? $datObj.".".$k : $k;
00466                                 $thisPath = ($titlePath?$titlePath." -> ":"").$title;
00467 
00468                                         // Code for making the graphics
00469                                 $join = ($this->pObj->MOD_SETTINGS["tx_tstemplatestyler_modfunc1_expAll"] || $this->ext_editBranch) || !is_array($dat["ch."]);
00470                                 $iconN = $join?"join":($this->ext_depthKeysValues[$datObjRef]?"minus":"plus");
00471                                 if (($count+1)==count($oArr))   {
00472                                         $iconN.="bottom";
00473                                 }
00474 
00475                                         // Getting the current value of the selector from the parsed CSS files:
00476 #                               $styleInfo="";
00477                                 $styleValue="";
00478                                 $matchKey = md5(strtoupper($thisSel));
00479                                 $pointer = $this->ext_matchSelector[$matchKey];
00480                                 $rPath = $pointer[0];
00481                                 if (is_array($pointer)) {
00482                                         $this->ext_matchSelector[$matchKey]["configFound"]=1;
00483 #                                       $styleInfo=$this->ext_styleItems[$pointer[0]][$pointer[1]];
00484 #                                       $styleValue = $styleInfo["origAttributes"];
00485                                         $styleValue = $pointer[2];
00486                                 }
00487 
00488                                 if ($this->ext_plusStyleParsed[1][$matchKey][2])        {
00489                                         $styleValue_default=$this->ext_plusStyleParsed[1][$matchKey][2];
00490                                 } else $styleValue_default="";
00491 
00492 
00493                                         // Incoming data.
00494                                 if ($this->ext_doWrite) {
00495                                         $inValueArr = $this->getInputValue($datObjRef);
00496                                         if (is_array($inValueArr))      {       // This data WAS incoming, so write it:
00497                                                 $inValue = $inValueArr[0];
00498 
00499                                                 $com = $this->ext_addComments ? chr(10).'/* '.$thisPath.' */' : "";
00500 
00501                                                 if (is_array($pointer)) {       // AND this selector was present already
00502                                                         $this->ext_styleItems[$pointer[0]][$pointer[1]]["changed"]=1;
00503                                                         $this->ext_styleItems[$pointer[0]][$pointer[1]]["origAttributes"]=$inValue;
00504                                                         $this->ext_styleItems[$pointer[0]][$pointer[1]]["origComment"] = $com;
00505                                                         $prevPointer=$pointer[0];
00506                                                 } elseif (strcmp(trim($inValue),"")) {  // ... but in this case NO such selector existed...
00507                                                         $this->insertNewSelector($thisSel,$inValue,$prevPointer,$com);
00508                                                 }
00509 #                                               debug($thisSel,1);
00510                                         }
00511                                 }
00512 
00513                                         // Row info passed back, used to layout:
00514                                 $lines[]=array(
00515                                                 "html" => $openBranch ? $preHTML.($join?'':'<a name="'.substr(md5($datObjRef),0,10).'" href="'.t3lib_div::linkThisScript(array("editBranch"=>$this->ext_editBranch,"tsbr"=>array($datObjRef=>$this->ext_depthKeysValues[$datObjRef]?0:1))).'#'.substr(md5($datObjRef),0,10).'">').'<img src="'.$GLOBALS["BACK_PATH"].'gfx/ol/'.$iconN.'.gif" width="18" height="16" border="0" class="absmiddle" alt="">'.($join?'':'</a>').(!$exampleStop?'<strong>'.$title.'</strong>':$title) : '',
00516                                                 "selector" => $thisSel,
00517                                                 "attribs" => $dat["attribs"],
00518                                                 "CSS_data" => $styleValue,
00519                                                 "CSS_data_default" => $styleValue_default,
00520                                                 "itemSel" => $dat["selector"],
00521                                                 "resourcePath" => $rPath,
00522                                                 "exampleStop" => $exampleStop,
00523                                                 "datObj" => $datObjRef
00524                                         );
00525 
00526                                 if ($styleValue && $thisSel)    {
00527                                         $this->ext_compiledStylesheet[]=$thisSel.' {'.$styleValue.'}';
00528                                 }
00529                                 if ($dat["example"] && !$exampleStop && (!$this->ext_editBranch || ($this->matchEB($this->ext_editBranch,$datObjRef)&&$openBranch)))    {
00530                                         $this->ext_compiledExamples[]=$this->wrapExample($dat["example"],$title);
00531                                 }
00532 
00533                                         // Children are processed here:
00534                                 if (is_array($dat["ch."]))      {
00535                                         $exampleWrap = explode("|",$dat["exampleWrap"]);
00536 
00537                                         if      ($dat["exampleWrap"])   {
00538                                                 $this->ext_compiledExamples[]=$exampleWrap[0];
00539                                                 $extCE_count = count($this->ext_compiledExamples);
00540                                         }
00541 
00542                                         $thisExampleStop = isset($dat["exampleStop"]) ? $dat["exampleStop"] : $exampleStop;
00543                                         $lines = $this->makeCSSTree_recursive(
00544                                                 $dat["ch."],
00545                                                 $lines,
00546                                                 $preHTML.'<img src="'.$GLOBALS["BACK_PATH"].'gfx/ol/'.(($count+1)==count($oArr)?"blank":"line").'.gif" width="18" height="16" border="0" class="absmiddle">',
00547                                                 $thisSel,
00548                                                 $datObjRef.".ch",
00549                                                 $cc+1,
00550                                                 $openBranch && ($this->ext_depthKeysValues[$datObjRef] || ($this->pObj->MOD_SETTINGS["tx_tstemplatestyler_modfunc1_expAll"] || $this->ext_editBranch)) ? 1 : 0,
00551                                                 $thisExampleStop,
00552                                                 $thisPath
00553                                         );
00554 
00555                                         if      ($dat["exampleWrap"])   {
00556                                                 if (count($this->ext_compiledExamples)==$extCE_count)   {
00557                                                         array_pop($this->ext_compiledExamples);
00558                                                 } else {
00559                                                         $this->ext_compiledExamples[]=$exampleWrap[1];
00560                                                 }
00561                                         }
00562                                 }
00563                         }
00564                 }
00565                 return $lines;
00566         }
00567 
00571         function getEarr($eArr) {
00572                 global $tmpl;
00573                 $oArr=array();
00574 
00575                 reset($eArr);
00576                 while(list($k,$v)=each($eArr))  {
00577                         $title="";
00578                         $dat="";
00579                         if (is_string($v) && substr($v,0,1)=="<")       {
00580                                 $cF = t3lib_div::makeInstance("t3lib_TSparser");
00581                                 list($title,$dat)=$cF->getVal(trim(substr($v,1)),$tmpl->setup_editorcfg);
00582 
00583                                 if (is_array($eArr[$k."."]) && count($eArr[$k."."]))    {
00584                                         $dat = $this->joinTSarrays($dat,$eArr[$k."."]);
00585                                 }
00586                                 $title = $dat["title"]?$dat["title"]:$title;
00587                         } elseif (is_array($v) && substr($eArr[substr($k,0,-1)],0,1)!="<")      {
00588                                 $k=substr($k,0,-1);
00589                                 $title = $v["title"]?$v["title"]:$eArr[$k];
00590                                 $dat = $v;
00591                         }
00592                         if (is_array($dat))             $oArr[]=array($title,$dat,$k);
00593                 }
00594                 return $oArr;
00595         }
00596 
00600         function joinTSarrays($conf,$old_conf)  {
00601                 if (is_array($old_conf))        {
00602                         reset($old_conf);
00603                         while(list($key,$val)=each($old_conf))  {
00604                                 if (is_array($val))     {
00605                                         $conf[$key] = $this->joinTSarrays($conf[$key],$val);
00606                                 } else {
00607                                         $conf[$key] = $val;
00608                                 }
00609                         }
00610                 }
00611                 return $conf;
00612         }
00613 
00617         function getInputValue($objRef) {
00618                 $value="";
00619                 $POST = t3lib_div::_POST();
00620                 if (is_array($POST["tstemplatestyler"]["writeObj"][$objRef.".style"]))  {
00621                         reset($POST["tstemplatestyler"]["writeObj"][$objRef.".style"]);
00622                         while(list($k,$v)=each($POST["tstemplatestyler"]["writeObj"][$objRef.".style"]))        {
00623                                 if ($k!="ALL" && strcmp("",trim($v)))   {
00624                                         if (substr($k,0,7)=="margin-" && t3lib_div::testInt(trim($v)))  {
00625                                                 $v=trim($v)."px";
00626                                         }
00627                                         if (substr($k,0,8)=="padding-" && t3lib_div::testInt(trim($v))) {
00628                                                 $v=trim($v)."px";
00629                                         }
00630                                         if ($k=="width" && t3lib_div::testInt(trim($v)))        {
00631                                                 $v=trim($v)."px";
00632                                         }
00633                                         $value.=$k.":".trim($v)."; ";
00634 #debug($value,1);
00635                                 }
00636                         }
00637                         $value.= $POST["tstemplatestyler"]["writeObj"][$objRef.".style"]["ALL"];
00638                         $value = trim($value);
00639                         return array($value);
00640                 }
00641         }
00642 
00646         function insertNewSelector($inSelector,$inValue,$prevPointer,$comment="")       {
00647                 if (!$prevPointer || !isset($this->ext_styleItems[$prevPointer]))       {
00648                         end($this->ext_styleItems);
00649                         $prevPointer=key($this->ext_styleItems);
00650 
00651                                 // Here we might also find another stylesheet based on object-string or if a preferred flag was set (which is not specified yet...)
00652                 }
00653 
00654                 $newEl=array(
00655                         "changed"=>1,
00656                         "origSelector" => $inSelector,
00657                         "selector" => $inSelector,
00658                         "origAttributes" => $inValue,
00659                         "origComment" => $comment
00660                 );
00661                 array_splice ($this->ext_styleItems[$prevPointer], -1, 0, array($newEl));       // MUST be inserted as the second last item, because the last item is always a dummy and all the other items must have proper key-relations with the $this->ext_matchSelector
00662         }
00663 
00667         function wrapExample($str,$title)       {
00668                 $str = $title.'<br><div style="border: dotted #666666 1px; margin-bottom:10px;">'.$str.'</div>';
00669                 return $str;
00670         }
00671 
00675         function matchEB($editBranch,$datObjRef)        {
00676                 return $datObjRef==$editBranch || substr($datObjRef,0,strlen($editBranch)+1)==$editBranch.".";
00677         }
00678 
00679 
00680 
00681 
00682 
00683 
00684 
00685 
00686 
00687 
00688 
00689 
00690 
00691 
00692 
00693 
00694 
00695         /********************************
00696 
00697                 Style editor functions
00698 
00699          ********************************/
00700 
00701 
00702 
00706         function makeStyleDialog($vArray)       {
00707                 $el=array();
00708                         // Splitting style data into an array:
00709                 $styleAttribs=$this->styleAttributes($vArray["CSS_data"]);
00710 
00711                         // Make form elements:
00712                 $vArray["attribs"] = str_replace("ALL","TEXT,TEXT+,BULLET,BORDER,background-color,margin+,padding+",$vArray["attribs"]);
00713                 $vArray["attribs"] = str_replace("HEADER","TEXT,margin-top,margin-bottom",$vArray["attribs"]);
00714                 $vArray["attribs"] = str_replace("TABLE","BORDER,margin+,background-color",$vArray["attribs"]);
00715                 $vArray["attribs"] = str_replace("TD","BORDER,vertical-align,padding+,background-color",$vArray["attribs"]);
00716                 $vArray["attribs"] = str_replace("BORDER","border-color,border-style,border-width",$vArray["attribs"]);
00717                 $vArray["attribs"] = str_replace("BODYTEXT","TEXT,line-height,margin-top,margin-bottom",$vArray["attribs"]);
00718                 $vArray["attribs"] = str_replace("TEXT+","white-space,letter-spacing,word-spacing,text-decoration,text-align,text-transform,text-indent,line-height",$vArray["attribs"]);
00719                 $vArray["attribs"] = str_replace("TEXT","font-family,font-size,color,font-weight,font-style,font-variant",$vArray["attribs"]);
00720                 $vArray["attribs"] = str_replace("LINKS","color,text-decoration",$vArray["attribs"]);
00721                 $vArray["attribs"] = str_replace("BULLETS","list-style-type,list-style-position,margin-left,margin-right,margin-top,margin-bottom",$vArray["attribs"]);
00722 #debug(array($vArray["attribs"]));
00723                 $editorItems = array_unique(t3lib_div::trimExplode(",",$vArray["attribs"],1));
00724                 reset($editorItems);
00725                 while(list(,$v)=each($editorItems))     {
00726                         $notProcessed=0;
00727                         switch((string)$v)      {
00728                                 case "font-size":
00729                                         $optValues=array(
00730                                                 "8px"=>"8",
00731                                                 "9px"=>"9",
00732                                                 "10px"=>"10",
00733                                                 "11px"=>"11",
00734                                                 "12px"=>"12",
00735                                                 "13px"=>"13",
00736                                                 "14px"=>"14",
00737                                                 "15px"=>"15",
00738                                                 "16px"=>"16",
00739                                                 "17px"=>"17",
00740                                                 "18px"=>"18",
00741                                                 "20px"=>"20",
00742                                                 "22px"=>"22",
00743                                                 "24px"=>"24",
00744                                                 "26px"=>"26",
00745                                                 "28px"=>"28",
00746                                                 "30px"=>"30",
00747                                                 "33px"=>"33",
00748                                                 "36px"=>"36",
00749                                                 "40px"=>"40",
00750                                                 "44px"=>"44",
00751                                                 "48px"=>"48"
00752                                         );
00753                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"Size");
00754                                 break;
00755                                 case "font-family":
00756                                         $optValues=array(
00757                                                 'Verdana, Geneva, Arial, Helvetica, sans-serif' => "Verdana+",
00758                                                 'Arial, Helvetica, sans-serif' => "Arial+",
00759                                                 'Times, "Times New Roman", serif;' => "Times+",
00760                                                 '"Courier New", Courier, monospace;' => "Courier+",
00761                                                 "Verdana",
00762                                                 "Arial",
00763                                                 "Times",
00764                                                 "Comic Sans MS",
00765                                                 'Georgia, serif',
00766                                                 "serif",
00767                                                 "sans-serif",
00768                                                 "monospace",
00769                                         );
00770                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"Font");
00771                                 break;
00772                                 case "font-weight":
00773                                         $optValues=array(
00774                                                 "normal",
00775                                                 "bold",
00776                                                 "bolder",
00777                                                 "lighter",
00778                                         );
00779                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"Weight");
00780                                 break;
00781                                 case "font-style":
00782                                         $optValues=array(
00783                                                 "normal",
00784                                                 "italic",
00785                                                 "oblique",
00786                                         );
00787                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"Style");
00788                                 break;
00789                                 case "font-variant":
00790                                         $optValues=array(
00791                                                 "normal",
00792                                                 "small-caps",
00793                                         );
00794                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"Variant");
00795                                 break;
00796                                 case "white-space":
00797                                         $optValues=array(
00798                                                 "normal",
00799                                                 "pre",
00800                                                 "nowrap",
00801                                         );
00802                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"WhiteSpc");
00803                                 break;
00804                                 case "letter-spacing":
00805                                         $optValues=array(
00806                                                 "normal",
00807                                                 "-2px",
00808                                                 "-1px",
00809                                                 "1px",
00810                                                 "2px",
00811                                                 "3px",
00812                                                 "4px",
00813                                                 "5px",
00814                                                 "6px",
00815                                                 "7px",
00816                                                 "8px",
00817                                                 "9px",
00818                                                 "10px",
00819                                         );
00820                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"Char Spacing");
00821                                 break;
00822                                 case "word-spacing":
00823                                         $optValues=array(
00824                                                 "normal",
00825                                                 "-2px",
00826                                                 "-1px",
00827                                                 "1px",
00828                                                 "2px",
00829                                                 "3px",
00830                                                 "4px",
00831                                                 "5px",
00832                                                 "6px",
00833                                                 "7px",
00834                                                 "8px",
00835                                                 "9px",
00836                                                 "10px",
00837                                         );
00838                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"Word Spacing");
00839                                 break;
00840                                 case "text-decoration":
00841                                         $optValues=array(
00842                                                 "none",
00843                                                 "underline",
00844                                                 "overline",
00845                                                 "line-through",
00846                                         );
00847                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"Decoration");
00848                                 break;
00849                                 case "text-align":
00850                                         $optValues=array(
00851                                                 "left",
00852                                                 "right",
00853                                                 "center",
00854                                                 "justify",
00855                                         );
00856                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"Align");
00857                                 break;
00858                                 case "text-transform":
00859                                         $optValues=array(
00860                                                 "capitalize",
00861                                                 "uppercase",
00862                                                 "lowercase",
00863                                                 "none",
00864                                         );
00865                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"Transform");
00866                                 break;
00867                                 case "text-indent":
00868                                         $optValues=array(
00869                                                 "-30px",
00870                                                 "-20px",
00871                                                 "-10px",
00872                                                 "0px" => "Normal",
00873                                                 "10px",
00874                                                 "20px",
00875                                                 "30px",
00876                                                 "40px",
00877                                                 "50px",
00878                                                 "70px",
00879                                                 "