Documentation TYPO3 par Ameos

class.tx_tstemplatestyler_modfunc1.php

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                                                 "100px",
00880                                                 "130px",
00881                                                 "170px",
00882                                                 "200px",
00883                                         );
00884                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"Indent");
00885                                 break;
00886                                 case "line-height":
00887                                         $optValues=array(
00888                                                 "normal",
00889                                                 "70%"=>"0.7",
00890                                                 "80%"=>"0.8",
00891                                                 "90%"=>"0.9",
00892                                                 "110%"=>"1.1",
00893                                                 "120%"=>"1.2",
00894                                                 "130%"=>"1.3",
00895                                                 "140%"=>"1.4",
00896                                                 "150%"=>"1.5",
00897                                                 "160%"=>"1.6",
00898                                                 "170%"=>"1.7",
00899                                                 "180%"=>"1.8",
00900                                                 "200%"=>"2",
00901                                                 "220%"=>"2.2",
00902                                                 "250%"=>"2.5",
00903                                                 "300%"=>"3",
00904                                                 "350%"=>"3.5",
00905                                                 "400%"=>"4",
00906                                         );
00907                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"Line Height");
00908                                 break;
00909                                 case "list-style-type":
00910                                         $optValues=array(
00911                                                 "disc" => "Normal",
00912                                                 "circle",
00913                                                 "square",
00914                                                 "decimal-leading-zero",
00915                                                 "decimal",
00916                                         );
00917                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"List type");
00918                                 break;
00919                                 case "list-style-position":
00920                                         $optValues=array(
00921                                                 "outside" => "Normal",
00922                                                 "inside" => "Inside",
00923                                         );
00924                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"List pos:");
00925                                 break;
00926                                 case "margin+":
00927                                         $el[]='Margin T:<input type="text" name="'.$this->formFieldName($vArray["datObj"],"margin-top").'" value="'.htmlspecialchars($styleAttribs["margin-top"]).'"'.$this->styleCode($styleAttribs["margin-top"],"width:35px;").'>'.
00928                                                         'R:<input type="text" name="'.$this->formFieldName($vArray["datObj"],"margin-right").'" value="'.htmlspecialchars($styleAttribs["margin-right"]).'"'.$this->styleCode($styleAttribs["margin-right"],"width:35px;").'>'.
00929                                                         'B:<input type="text" name="'.$this->formFieldName($vArray["datObj"],"margin-bottom").'" value="'.htmlspecialchars($styleAttribs["margin-bottom"]).'"'.$this->styleCode($styleAttribs["margin-bottom"],"width:35px;").'>'.
00930                                                         'L:<input type="text" name="'.$this->formFieldName($vArray["datObj"],"margin-left").'" value="'.htmlspecialchars($styleAttribs["margin-left"]).'"'.$this->styleCode($styleAttribs["margin-left"],"width:35px;").'>'.
00931                                                         '';
00932                                         unset($styleAttribs["margin-top"]);
00933                                         unset($styleAttribs["margin-right"]);
00934                                         unset($styleAttribs["margin-bottom"]);
00935                                         unset($styleAttribs["margin-left"]);
00936                                 break;
00937                                 case "padding+":
00938                                         $el[]='Padding T:<input type="text" name="'.$this->formFieldName($vArray["datObj"],"padding-top").'" value="'.htmlspecialchars($styleAttribs["padding-top"]).'"'.$this->styleCode($styleAttribs["padding-top"],"width:35px;").'>'.
00939                                                         'R:<input type="text" name="'.$this->formFieldName($vArray["datObj"],"padding-right").'" value="'.htmlspecialchars($styleAttribs["padding-right"]).'"'.$this->styleCode($styleAttribs["padding-right"],"width:35px;").'>'.
00940                                                         'B:<input type="text" name="'.$this->formFieldName($vArray["datObj"],"padding-bottom").'" value="'.htmlspecialchars($styleAttribs["padding-bottom"]).'"'.$this->styleCode($styleAttribs["padding-bottom"],"width:35px;").'>'.
00941                                                         'L:<input type="text" name="'.$this->formFieldName($vArray["datObj"],"padding-left").'" value="'.htmlspecialchars($styleAttribs["padding-left"]).'"'.$this->styleCode($styleAttribs["padding-left"],"width:35px;").'>'.
00942                                                         '';
00943                                         unset($styleAttribs["padding-top"]);
00944                                         unset($styleAttribs["padding-right"]);
00945                                         unset($styleAttribs["padding-bottom"]);
00946                                         unset($styleAttribs["padding-left"]);
00947                                 break;
00948                                 case "padding-top":
00949                                 case "padding-bottom":
00950                                 case "padding-left":
00951                                 case "padding-right":
00952                                 case "margin-top":
00953                                 case "margin-bottom":
00954                                 case "margin-left":
00955                                 case "margin-right":
00956                                         $el[]='<input type="text" name="'.$this->formFieldName($vArray["datObj"],$v).'" value="'.htmlspecialchars($styleAttribs[$v]).'" title="'.$v.'"'.$this->styleCode($styleAttribs[$v],"width:35px;").'>';
00957                                 break;
00958                                 case "border-style":
00959                                         $optValues=array(
00960                                                 "none",
00961                                                 "solid",
00962                                                 "dotted",
00963                                                 "dashed",
00964                                                 "double",
00965                                                 "groove",
00966                                                 "ridge",
00967                                                 "inset",
00968                                                 "outset",
00969                                         );
00970                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"Border style");
00971                                 break;
00972                                 case "border-width":
00973                                         $optValues=array(
00974                                                 "0px" => "None",
00975                                                 "1px",
00976                                                 "2px",
00977                                                 "3px",
00978                                                 "4px",
00979                                                 "5px",
00980                                                 "6px",
00981                                                 "7px",
00982                                                 "8px",
00983                                                 "9px",
00984                                                 "10px",
00985                                         );
00986                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"Width");
00987                                 break;
00988                                 case "vertical-align":
00989                                         $optValues=array(
00990                                                 "top",
00991                                                 "middle",
00992                                                 "bottom",
00993                                         );
00994                                         $el[]=$this->renderSelector($this->formFieldName($vArray["datObj"],$v),$optValues,$styleAttribs[$v],"Vertical Align");
00995                                 break;
00996                                 case "border-color":
00997                                 case "color":
00998                                 case "background-color":
00999                                         $optValues=explode(",",$this->HTMLcolorList);
01000                                         $onChange="document.editForm['".$this->formFieldName($vArray["datObj"],$v)."'].value=this.options[this.selectedIndex].value; this.selectedIndex=0;";
01001                                         $el[]=$this->renderSelector("__".md5($this->formFieldName($vArray["datObj"],$v)),$optValues,"","Color",$onChange).
01002                                                 '<input type="text" name="'.$this->formFieldName($vArray["datObj"],$v).'" value="'.htmlspecialchars($styleAttribs[$v]).'" title="'.$v.'"'.$this->styleCode($styleAttribs[$v],"width:60px;").'>';
01003                                 break;
01004                                 case "width":
01005                                         $el[]='<input type="text" name="'.$this->formFieldName($vArray["datObj"],$v).'" value="'.htmlspecialchars($styleAttribs[$v]).'" title="'.$v.'"'.$this->styleCode($styleAttribs[$v],"width:60px;").'>';
01006                                 break;
01007                                 default:
01008                                         $notProcessed=1;
01009 #debug($v,1);
01010                                 break;
01011                         }
01012                         if (!$notProcessed)     {
01013                                 unset($styleAttribs[$v]);
01014                         }
01015                 }
01016                         // If there are more data left:
01017                 if (count($styleAttribs))       {
01018                         $all="";
01019                         reset($styleAttribs);
01020                         while(list($k,$v)=each($styleAttribs))  {
01021                                 $all.=$k.':'.$v.';';
01022                         }
01023                         $el[]='<input type="text" name="'.$this->formFieldName($vArray["datObj"],"ALL").'" value="'.htmlspecialchars($all).'">';
01024                 }
01025                 return implode("&nbsp;&nbsp;",$el);
01026         }
01027 
01031         function formFieldName($datObj,$attrib) {
01032                 return 'tstemplatestyler[writeObj]['.$datObj.'.style]['.$attrib.']';
01033         }
01034 
01038         function renderSelector($name,$optValues,$value,$title,$onChange="")    {
01039                 $opt=Array();
01040                 $opt[]='<option value="" style="color:#999999;">'.$title.'</option>';
01041                 $notSel=0;
01042                 reset($optValues);
01043                 while(list($k,$v)=each($optValues))     {
01044                         if (t3lib_div::testInt($k))     $k=$v;
01045                         if (!$notSel && !strcmp($value,$k))             $notSel=1;
01046                         $opt[]='<option value="'.htmlspecialchars($k).'"'.(!strcmp($value,$k)?" SELECTED":"").'>'.htmlspecialchars($v).'</option>';
01047                 }
01048                 if (!$notSel && strcmp($value,""))      {
01049                         $opt[]='<option value="">--</option>';
01050                         $opt[]='<option value="'.htmlspecialchars($value).'" SELECTED style="color:red;">'.htmlspecialchars($value).'</option>';
01051                 }
01052                 $out = '<select name="'.$name.'"'.($onChange?' onChange="'.$onChange.'"':'').$this->styleCode($value).'>'.implode("",$opt).'</select>';
01053                 return $out;
01054         }
01055 
01059         function styleCode($v,$style="")        {
01060                 if (!strcmp($v,""))     {
01061                         return ' style="background-color:'.$this->pObj->doc->bgColor.';'.$style.'"';
01062                 } else {
01063                         return ' style="'.$style.'"';
01064                 }
01065         }
01066 
01067 
01068 
01069 
01070 
01071 
01072 
01073 
01074 
01075 
01076 
01077 
01078 
01079         /****************************************************************
01080 
01081                 CSS style sheet parsing + Style collection manipulation
01082 
01083         ****************************************************************/
01084 
01088         function parseStyleSheet($input,$fileref,$matchSel=array())     {
01089 
01090                 $styleItems=array();
01091 
01092                 $parts = explode("}",$input);
01093                 while(list($k,$v)=each($parts)) {
01094                         $tmpItem=array();
01095                         $tmpItem["rawContent"]=$v;
01096                         $tmpItem["changed"]=0;
01097                         if ($k+1<count($parts)) {
01098                                 $subparts = t3lib_div::revExplode("{",$v,2);
01099                                 if (count($subparts)==2)        {       // there is an item here.
01100                                                 // Attributes:
01101 #                                       $attribs = $this->styleAttributes($subparts["1"]);
01102 
01103                                                 // Selector and comments:
01104                                         $selector = strrev($subparts["0"]);
01105                                         $sParts = split(">--|\/\*",$selector,2);
01106                                         $tmpItem["origComment"] = strrev(substr($selector,strlen($sParts[0])));
01107                                         $tmpItem["origSelector"] = strrev($sParts[0]);
01108                                         $tmpItem["origAttributes"] = $subparts["1"];
01109 
01110                                         $tmpItem["selector"] = ereg_replace("[[:space:]]"," ",trim($tmpItem["origSelector"]));
01111                                         $tmpItem["matchSelector"] = strtoupper($tmpItem["selector"]);
01112                                         $tmpItem["matchSelector_md5"] = md5($tmpItem["matchSelector"]);
01113 #                                       $tmpItem["attributes"] = $attribs;
01114 
01115                                         $selStyleAttributes=$tmpItem["origAttributes"];
01116                                         if (isset($matchSel[$tmpItem["matchSelector_md5"]]))    {
01117 #debug(array($tmpItem["matchSelector"],$matchSel[$tmpItem["matchSelector_md5"]][2],$selStyleAttributes));
01118                                                 $selStyleAttributes = $matchSel[$tmpItem["matchSelector_md5"]][2].$selStyleAttributes;
01119                                         }
01120                                         $matchSel[$tmpItem["matchSelector_md5"]]=array(
01121                                                 $fileref,
01122                                                 $k,
01123                                                 $this->printAttributes($this->styleAttributes($selStyleAttributes),1)
01124                                         );
01125                                 }
01126                         }
01127                         $styleItems[$k]=$tmpItem;
01128                 }
01129                 return array($styleItems,$matchSel);
01130         }
01131 
01135         function styleAttributes($data) {
01136                         // Splitting style data into an array:
01137                 $styleAttribs=array();
01138                 $temp_data = t3lib_div::trimExplode(";",$data,1);
01139                 reset($temp_data);
01140                 while(list($k,$v)=each($temp_data))     {
01141                         $p=explode(":",$v,2);
01142                         $styleAttribs[trim($p[0])]=trim($p[1]);
01143                 }
01144                 return $styleAttribs;
01145         }
01146 
01150         function cleanUpSelector($selector)     {
01151                 $parts = t3lib_div::trimExplode(",",$selector,1);
01152                 while(list($k,$v)=each($parts)) {
01153                         $sParts = explode(" ",$v);
01154                         while(list($kk,$vv)=each($sParts))      {
01155                                 $ssParts = split("[^[:alnum:]]",$vv,2);
01156                                 if (strcmp($ssParts[0],""))     {
01157                                         $sParts[$kk]=strtoupper($ssParts[0]).substr($vv,strlen($ssParts[0]));
01158                                 }
01159                         }
01160                         $parts[$k]=trim(implode(" ",$sParts));
01161                 }
01162                 $selector=implode(", ",$parts);
01163                 return $selector;
01164         }
01165 
01169         function parseStyleContent_begin($colParts)     {
01170                         // Set plusStyle
01171                 $plusStyle=$this->ext_plusStyle();
01172                 if ($plusStyle) {
01173                         $thisID="_CSS_DEFAULT_STYLE";
01174                         $this->ext_plusStyleParsed = $styleItems = $this->parseStyleSheet($plusStyle,$thisID,$this->ext_matchSelector);
01175                                 // If these lines are unset, the default style will automatically be included with the otehr CSS stylesheet parts.
01176         #               $this->ext_styleItems[$thisID]=$styleItems[0];
01177         #               $this->ext_matchSelector=$styleItems[1];
01178                 }
01179 
01180                 $this->parseStyleContent($colParts);
01181         }
01182 
01183 
01187         function parseStyleContent($colParts,$path="")  {
01188                 if (is_array($colParts))        {
01189                         reset($colParts);
01190                         while(list($k,$v)=each($colParts))      {
01191                                 $thisID = $path.$k."|".$v["file_id"];
01192                                 if (is_array($v["content"]))    {
01193                                         $this->parseStyleContent($v["content"],$thisID."|");
01194                                 } else {
01195                                         $styleItems = $this->parseStyleSheet($v["content"],$thisID,$this->ext_matchSelector);
01196                                         $this->ext_styleItems[$thisID]=$styleItems[0];
01197                                         $this->ext_matchSelector=$styleItems[1];
01198                                 }
01199                         }
01200                 }
01201         }
01202 
01206         function prepareStyleContent($colParts,$path="")        {
01207                 if (is_array($colParts))        {
01208                         reset($colParts);
01209                         while(list($k)=each($colParts)) {
01210                                 $thisID = $path.$k."|".$colParts[$k]["file_id"];
01211                                 if (is_array($colParts[$k]["content"])) {
01212                                         $colParts[$k]["content"] = $this->prepareStyleContent($colParts[$k]["content"],$thisID."|");
01213                                 } else {
01214                                         $parts=array();
01215                                         reset($this->ext_styleItems[$thisID]);
01216                                         while(list($kk,$vv)=each($this->ext_styleItems[$thisID]))       {
01217                                                 if (trim($vv["rawContent"]) || $vv["changed"])  {
01218                                                         if ($this->ext_allwaysCleanUpWrittenStyles || $vv["changed"])   {
01219                                                                 $parts[]=       chr(10).trim($vv["origComment"]).
01220                                                                                         (trim($vv["origComment"])?chr(10):"").
01221                                                                                         $this->cleanUpSelector($vv["selector"])." {".
01222                                                                                         $this->printAttributes($this->styleAttributes($vv["origAttributes"]));
01223                                                         } else {
01224                                                                 $parts[]=$vv["origComment"].$vv["origSelector"]."{".$vv["origAttributes"];
01225                                                         }
01226                                                 } else $parts[]=$vv["rawContent"];
01227                                         }
01228                                         $colParts[$k]["content2"]=trim(implode("}",$parts));
01229                                         $colParts[$k]["content2_md5"]=md5($colParts[$k]["content2"]);
01230                                 }
01231                         }
01232                 }
01233                 return $colParts;
01234         }
01235 
01239         function writeStyleContent($colParts)   {
01240                 global $tmpl,$tplRow;
01241                 if (is_array($colParts))        {
01242                         reset($colParts);
01243                         while(list($k,$v)=each($colParts))      {
01244                                 if (strcmp($v["file_id"],"INLINE"))     {
01245                                         $fileRef = $this->getFileName($v["file_id"]);
01246                                         if ($fileRef)   {
01247                                                 $fI=pathinfo($fileRef);
01248                                                 $ext=strtolower($fI["extension"]);
01249                                                 if (t3lib_div::inList("html,htm",$ext)) {
01250                                                         $this->writeHTMLdocument(PATH_site.$fileRef, $v["content"]);
01251                                                 } elseif (t3lib_div::inList("css",$ext))        {
01252                                                         $cssFileContent = t3lib_div::getUrl(PATH_site.$fileRef);
01253                                                         $cssFileContent_md5=md5($cssFileContent);
01254                                                         if ($cssFileContent_md5==$v["content_md5"])     {
01255                                                                 $this->writeResourceFile(PATH_site.$fileRef,$v["content2"]);
01256                                                         } else debug("ERROR: The file '".$fileRef."' has changed content...");
01257                                                 } else {
01258                                                         $v["ERROR"]="Not valid fileextension (must be html, htm, css)";
01259                                                 }
01260                                         } else {
01261                                                 $v["ERROR"]="No file found";
01262                                         }
01263                                 } elseif ($v["pageObject"]) {
01264                                         $writeContent=$v["pageObject"]."CSS_inlineStyle ( ".chr(10).$this->prefixLines(trim($v["content2"]),"  ").chr(10).")";
01265 #debug("WRITING TO template record: ".$tplRow["uid"]);
01266                                         $this->writeStyle($tplRow["uid"],$tplRow["config"],$writeContent);
01267                                 } else {
01268 debug("ERROR: Unrecognized section:");
01269 debug($v);
01270                                 }
01271                         }
01272                 }
01273         }
01274 
01278         function writeHTMLdocument($document,$writeArray)       {
01279 #debug($writeArray);
01280                 $content = t3lib_div::getUrl($document);
01281                 $error="";
01282 
01283                 $parser = t3lib_div::makeInstance("t3lib_parsehtml");
01284                 $headerSection = $parser->splitIntoBlock("head",$content);
01285                 if (count($headerSection)>1)    {
01286                         $internalSections = $parser->splitIntoBlock("style",$headerSection[1]);
01287 
01288                         reset($internalSections);
01289                         while(list($k,$v)=each($internalSections))      {
01290                                 if ($k%2)       {
01291                                         $firstTag=$parser->getFirstTag($v);
01292 
01293                                         $currentContent=$parser->removeFirstAndLastTag($v);
01294                                         $currentContent_md5 = md5($currentContent);
01295                                         if ($writeArray[$k]["file_id"]=="INLINE" && $writeArray[$k]["content_md5"]==$currentContent_md5)        {
01296                                                 $internalSections[$k]=$firstTag.chr(10).trim($writeArray[$k]["content2"]).chr(10).'</STYLE>';
01297                                         } else $error="Section ".$k." in HTML template was not INLINE or the content was not as expected.";
01298                                 } else {
01299                                         $nonStyleParts=$parser->getAllParts($parser->splitTags("link",$v));
01300                                         reset($nonStyleParts);
01301                                         while(list($k2,$v2)=each($nonStyleParts))       {
01302                                                 list($attrib) = $parser->get_tag_attributes($v2,1);
01303                                                 $pI = parse_url($attrib["href"]);
01304                                                 if (!$pI["scheme"] && $pI["path"])      {
01305                                                         $file = dirname($document)."/".$pI["path"];
01306                                                         if (@is_file($file))    {
01307                                                                 $currentContent=t3lib_div::getUrl($file);
01308                                                                 $currentContent_md5 = md5($currentContent);
01309 #                                       debug(array(md5($currentContent),md5($writeArray[$k]["content"][$k2]["content"])));
01310 #                                       debug($writeArray[$k]["content"][$k2]);
01311                                                                 if ($writeArray[$k]["content"][$k2]["file_id"]==substr($file,strlen(PATH_site)) && $writeArray[$k]["content"][$k2]["content_md5"]==$currentContent_md5) {
01312                                                                         $theContent = $writeArray[$k]["content"][$k2]["content2"];
01313                                                                         $this->writeResourceFile($file,$theContent);
01314 #debug("WRITING: ".$file);
01315 #debug(array($theContent));
01316                                                                 } else debug("Section ".$k."/".$k2." in HTML template was not INLINE or the content was not as expected.");
01317                                                         }
01318                                                 }
01319                                         }
01320                                 }
01321                         }
01322                         if (!$error)    {
01323                                 $headerSection[1] = implode("",$internalSections);
01324                                 $this->writeResourceFile($document,implode("",$headerSection));
01325 #debug(array(implode("",$headerSection)));
01326                         } else debug("ERROR: ".$error);
01327                 } else debug("ERROR: No header section?");
01328         }
01329 
01333         function writeResourceFile($absFileRef,$content)        {
01334                 if (t3lib_div::isFirstPartOfStr($absFileRef,PATH_site))         {
01335                         if (is_file($absFileRef))       {
01336                                 $relFile = substr($absFileRef,strlen(PATH_site));
01337                                 if (t3lib_div::isFirstPartOfStr($relFile,"uploads/") || t3lib_div::isFirstPartOfStr($relFile,"fileadmin/"))     {
01338                                         t3lib_div::writeFile($absFileRef,$content);
01339 
01340 #                                       debug("Writing: ".$absFileRef);
01341 #                                       debug(array($content));
01342                                 } else debug("File '".$absFileRef."' not found in either uploads/* or fileadmin/* dirs.");
01343                         } else debug("Not a file! ".$absFileRef);
01344                 } else debug("ERROR: The file '".$absFileRef."' was not in the PATH_site path: '".PATH_site."'");
01345         }
01346 
01350         function writeStyle($uid,$currentData,$addData) {
01351                 global $tmpl;
01352 #debug(array($addData));
01353 #debug(md5($addData));
01354                 require_once (PATH_t3lib."class.t3lib_tcemain.php");
01355                         // Set the data to be saved
01356                 $recData=array();
01357                 $recData["sys_template"][$uid]["config"] = trim($this->mergeData($currentData,$addData)).chr(10);
01358 #debug($recData);
01359 
01360                         // Create new  tce-object
01361                 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
01362                 $tce->stripslashes_values=0;
01363 
01364                         // Initialize
01365                 $tce->start($recData,Array());
01366 
01367                         // Saved the stuff
01368                 $tce->process_datamap();
01369 
01370                         // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
01371                 $tce->clear_cacheCmd("all");
01372 
01373                         // re-read the template ...
01374                 $this->initialize_editor($this->pObj->id,$uid);
01375         }
01376 
01380         function prefixLines($str,$indent)      {
01381                 $lines = explode(chr(10),$str);
01382                 while(list($k,$v)=each($lines)) {
01383                         $lines[$k]=$indent.$v;
01384                 }
01385                 return implode(chr(10),$lines);
01386         }
01387 
01391         function mergeData($currentData,$addData)       {
01392                 $lines = explode(chr(10),$currentData);
01393                 $newContent="";
01394 
01395                 $inFlag=0;
01396                 $contentInserted=0;
01397                 reset($lines);
01398                 while(list($k,$v)=each($lines)) {
01399                         if (!$inFlag)   {
01400                                 $newContent.=$v.chr(10);
01401                         }
01402 
01403                         if (!strcmp(substr(trim($v),0,strlen($this->ext_cssMarker)),$this->ext_cssMarker))      {
01404                                 if (!$inFlag)   {
01405 #                                       debug("IN: ".$k);
01406                                         $inFlag=1;
01407                                 } else {
01408 #                                       debug("OUT: ".$k);
01409                                         $newContent.=$addData.chr(10);
01410                                         $contentInserted=1;
01411                                         $newContent.=$v.chr(10);
01412                                         $inFlag=0;
01413                                 }
01414                         }
01415                 }
01416 
01417                 if (!$contentInserted)  {
01418                         $newContent = $currentData.chr(10).
01419                                 $this->ext_cssMarker." - begin. CONTENT BETWEEN THESE MARKERS ARE AUTOMATICALLY UPDATED. ###".chr(10).
01420                                 $addData.chr(10).
01421                                 $this->ext_cssMarker." - end ###".chr(10);
01422                 }
01423                 return $newContent;
01424         }
01425 
01429         function printAttributes($arr,$forceOneLine=0)  {
01430                 $items=array();
01431                 reset($arr);
01432                 while(list($k,$v)=each($arr))   {
01433                         $items[]=$k.":".$v.";";
01434                 }
01435 
01436                 if ($this->ext_oneLineMode || $forceOneLine)    {
01437                         $out = " ".implode(" ",$items)." ";
01438                 } else {
01439                         $out = chr(10).chr(9).implode(chr(10).chr(9),$items).chr(10);
01440                 }
01441 
01442                 return $out;
01443         }
01444 
01448         function makeStyleCollectionSelector()  {
01449                 global $tmpl;
01450 
01451                 $outArray=array();
01452                 reset($tmpl->setup);
01453                 while(list($k)=each($tmpl->setup))      {
01454                         if (is_array($tmpl->setup[$k]) && $tmpl->setup[substr($k,0,-1)]=="PAGE")        {
01455                                 $tArray=array();
01456                                         // Stylesheet:
01457                                 if ($tmpl->setup[$k]["stylesheet"])     {
01458                                         $tArray[]=array(
01459                                                 "title"=>"stylesheet",
01460                                                 "file_id"=>$tmpl->setup[$k]["stylesheet"]
01461                                         );
01462                                 }
01463                                         // Include CSS:
01464                                 if (is_array($tmpl->setup[$k]["includeCSS."]))  {
01465                                         reset($tmpl->setup[$k]["includeCSS."]);
01466                                         while(list($k2,$iCSSfile)=each($tmpl->setup[$k]["includeCSS."]))        {
01467                                                 if (!is_array($iCSSfile))       {
01468                                                         $tArray[]=array(
01469                                                                 "title"=>"includeCSS.".$k2,
01470                                                                 "file_id"=>$iCSSfile
01471                                                         );
01472                                                 }
01473                                         }
01474                                 }
01475 
01476                                         // Inline:
01477                                 if ($tmpl->setup[$k]["CSS_inlineStyle"])        {
01478                                         $tArray[]=array(
01479                                                 "title"=>"CSS_inlineStyle",
01480                                                 "file_id"=>"INLINE",
01481                                                 "pageObject" => $k
01482                                         );
01483                                 }
01484 
01485                                 if (count($tArray))     {
01486                                         $outArray[] = array(
01487                                                 "title"=>"PAGE Obj: '".substr($k,0,-1)."'",
01488                                                 "parts"=>$tArray,
01489                                                 "CSS_editor" => $tmpl->setup_editorcfg[$k]["CSS_editor"],
01490                                                 "CSS_editor." => $tmpl->setup_editorcfg[$k]["CSS_editor."]
01491                                         );
01492                                 }
01493                         }
01494                 }
01495 
01496                 reset($tmpl->setup_editorcfg);
01497                 while(list($k)=each($tmpl->setup_editorcfg))    {
01498                         if (is_array($tmpl->setup_editorcfg[$k]) && is_array($tmpl->setup_editorcfg[$k]["CSS_docs."]))  {
01499                                 reset($tmpl->setup_editorcfg[$k]["CSS_docs."]);
01500                                 while(list($k2,$v2)=each($tmpl->setup_editorcfg[$k]["CSS_docs."]))      {
01501                                         if (is_array($v2) && $tmpl->setup_editorcfg[$k]["CSS_docs."][substr($k2,0,-1)]=="EXTERNAL")     {
01502                                                 $tArray=array();
01503                                                 if (is_array($v2["docs."]))     {
01504                                                         reset($v2["docs."]);
01505                                                         while(list($k3,$v3)=each($v2["docs."])) {
01506                                                                 if (!is_array($v3))     {
01507                                                                         $tArray[]=array(
01508                                                                                 "title"=>$k."CSS_docs.".$k2."docs.".$k3,
01509                                                                                 "file_id"=>$v3,
01510                                                                                 "conf" => $v2["docs."][$k3."."]
01511                                                                         );
01512                                                                 }
01513                                                         }
01514                                                 }
01515 
01516                                                 $ID = "BEC: ".$k."CSS_docs.".$k2;
01517                                                 $outArray[] = array("title"=>$v2["title"]?$v2["title"]:$ID,
01518                                                         "ID"=>$ID,
01519                                                         "parts"=>$tArray,
01520                                                         "CSS_editor" => $v2["CSS_editor"],
01521                                                         "CSS_editor." => $v2["CSS_editor."]
01522                                                 );
01523                                         }
01524                                 }
01525                         }
01526                 }
01527 #debug($outArray);
01528                 return $outArray;
01529         }
01530 
01535         function readStylesheets($collection)   {
01536                 global $tmpl;
01537                 if (is_array($collection["parts"]))     {
01538                         reset($collection["parts"]);
01539                         while(list($k,$v)=each($collection["parts"]))   {
01540                                 if (strcmp($v["file_id"],"INLINE"))     {
01541                                         $fileRef = $this->getFileName($v["file_id"]);
01542                                         if ($fileRef)   {
01543                                                 $fI=pathinfo($fileRef);
01544                                                 $ext=strtolower($fI["extension"]);
01545                                                 if (t3lib_div::inList("html,htm",$ext)) {
01546                                                         $v["content"] = $this->parseHTMLdocument(PATH_site.$fileRef);
01547                                                 } elseif (t3lib_div::inList("css",$ext))        {
01548                                                         $v["content"] = t3lib_div::getUrl(PATH_site.$fileRef);
01549                                                         $v["content_md5"]=md5($v["content"]);
01550                                                 } else {
01551                                                         $v["ERROR"]="Not valid fileextension (must be html, htm, css)";
01552                                                 }
01553                                         } else {
01554                                                 $v["ERROR"]="No file found";
01555                                         }
01556                                 } elseif ($v["pageObject"]) {
01557                                         $v["content"] = $tmpl->setup[$v["pageObject"]]["CSS_inlineStyle"];
01558                                 } else {
01559 debug("ERROR...");
01560                                 }
01561                                 $collection["parts"][$k]=$v;
01562                         }
01563                 }
01564                 return $collection;
01565         }
01566 
01570         function parseHTMLdocument($document)   {
01571                 $content = t3lib_div::getUrl($document);
01572                 $contentArr=array();
01573 
01574                 $parser = t3lib_div::makeInstance("t3lib_parsehtml");
01575                 $headerSection = $parser->getAllParts($parser->splitIntoBlock("head",$content),1,0);
01576                 if (count($headerSection))      {
01577                         $internalSections = $parser->splitIntoBlock("style",$headerSection[0]);
01578 
01579                         reset($internalSections);
01580                         while(list($k,$v)=each($internalSections))      {
01581                                 if ($k%2)       {
01582                                         $contentArr[$k]["file_id"]="INLINE";
01583                                         $contentArr[$k]["content"]=$parser->removeFirstAndLastTag($v);
01584                                         $contentArr[$k]["content_md5"]=md5($contentArr[$k]["content"]);
01585                                 } else {
01586                                         $nonStyleParts=$parser->getAllParts($parser->splitTags("link",$v));
01587                                         reset($nonStyleParts);
01588                                         while(list($k2,$v2)=each($nonStyleParts))       {
01589                                                 list($attrib) = $parser->get_tag_attributes($v2,1);
01590                                                 $pI = parse_url($attrib["href"]);
01591                                                 if (!$pI["scheme"] && $pI["path"])      {
01592                                                         $file = dirname($document)."/".$pI["path"];
01593                                                         if (@is_file($file))    {
01594                                                                 $contentArr[$k]["content"][$k2]["file_id"]=substr($file,strlen(PATH_site));
01595                                                                 $contentArr[$k]["content"][$k2]["content"]=t3lib_div::getUrl($file);
01596                                                                 $contentArr[$k]["content"][$k2]["content_md5"]=md5($contentArr[$k]["content"][$k2]["content"]);
01597                                                         }
01598                                                 }
01599                                         }
01600                                 }
01601                         }
01602                 }
01603                 return $contentArr;
01604         }
01605 
01609         function printCollectionInfo($colParts,$lines=array(),$pre="")  {
01610                 $showContent = $this->pObj->MOD_SETTINGS["tx_tstemplatestyler_modfunc1_showContent"];
01611                 if (is_array($colParts))        {
01612                         reset($colParts);
01613                         while(list($k,$v)=each($colParts))      {
01614                                 if ($v["file_id"])      {
01615                                         $lines[]='<tr class="bgColor4">
01616                                                         <td nowrap valign=top>'.$pre.$v["file_id"].'</td>
01617                                                         <td nowrap valign=top>'.
01618                                                                 ($v["ERROR"]?"<strong>".$GLOBALS["TBE_TEMPLATE"]->rfw("ERROR: ".$v["ERROR"])."</strong>":"").
01619                                                                 (!is_array($v["content"])&&htmlspecialchars($showContent)?nl2br(str_replace(" ","&nbsp;",str_replace(chr(9),"&nbsp;&nbsp;&nbsp;",$v["content"]))):"&nbsp;").'</td>
01620                                                 </tr>';
01621                                 }
01622                                 if (is_array($v["content"]))    {
01623                                         $lines = $this->printCollectionInfo($v["content"],$lines,$pre.($v["file_id"]?"&nbsp; &nbsp; &nbsp; ":""));
01624                                 }
01625                         }
01626                 }
01627 #debug($colParts);
01628 
01629                 return $lines;
01630         }
01631 
01635         function getFileName($resource) {
01636                 global $tmpl;
01637 
01638                 $tmpl->getFileName_backPath=PATH_site;          // Setting absolute prefixed path for relative resources.
01639 
01640                 $fileRef = $tmpl->getFileName($resource);
01641                 if ($tmpl->removeFromGetFilePath && t3lib_div::isFirstPartOfStr($fileRef,$tmpl->removeFromGetFilePath)) {
01642                         $fileRef = substr($fileRef,strlen($tmpl->removeFromGetFilePath));
01643                 }
01644                 return $fileRef;
01645         }
01646 
01647 
01651         function ext_plusStyle()        {
01652                 global $tmpl;
01653 
01654                 if (is_array($tmpl->setup["plugin."])) {
01655                         $temp_styleLines=array();
01656                         reset($tmpl->setup["plugin."]);
01657                         while(list($k2,$iCSScode)=each($tmpl->setup["plugin."]))        {
01658                                 if (is_array($iCSScode) && $iCSScode["_CSS_DEFAULT_STYLE"])     {
01659                                         $temp_styleLines[]='/* default styles for extension "'.substr($k2,0,-1).'" */'.chr(10).$iCSScode["_CSS_DEFAULT_STYLE"];
01660                                 }
01661                         }
01662                         if (count($temp_styleLines))    {
01663                                 $plusStyle=implode(chr(10),$temp_styleLines).chr(10).chr(10).chr(10).chr(10);
01664                         }
01665                 }
01666                 return $plusStyle;
01667         }
01668 }
01669 
01670 
01671 
01672 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_styler/modfunc1/class.tx_tstemplatestyler_modfunc1.php"])   {
01673         include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_styler/modfunc1/class.tx_tstemplatestyler_modfunc1.php"]);
01674 }
01675 
01676 ?>


Généré par Les experts TYPO3 avec  doxygen 1.4.6