TYPO3 API  SVNRelease
class.tx_tstemplateceditor.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 /**
00028  * TypoScript Constant editor
00029  *
00030  * Module Include-file
00031  *
00032  * localconf-variables:
00033  * $TYPO3_CONF_VARS['MODS']['web_ts']['onlineResourceDir'] = 'fileadmin/fonts/';        // This is the path (must be in "fileadmin/" !!) where the web_ts/constant-editor submodule fetches online resources. Put fonts (ttf) and standard images here!
00034  *
00035  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00036  */
00037 
00038 $GLOBALS['LANG']->includeLLFile('EXT:tstemplate_ceditor/locallang.xml');
00039 
00040 class tx_tstemplateceditor extends t3lib_extobjbase {
00041     function initialize_editor($pageId,$template_uid=0) {
00042             // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
00043         global $tmpl,$tplRow,$theConstants;
00044 
00045         $tmpl = t3lib_div::makeInstance("t3lib_tsparser_ext");  // Defined global here!
00046         $tmpl->tt_track = 0;    // Do not log time-performance information
00047         $tmpl->init();
00048 
00049         $tmpl->ext_localGfxPrefix=t3lib_extMgm::extPath("tstemplate_ceditor");
00050         $tmpl->ext_localWebGfxPrefix=$GLOBALS["BACK_PATH"].t3lib_extMgm::extRelPath("tstemplate_ceditor");
00051 
00052         $tplRow = $tmpl->ext_getFirstTemplate($pageId,$template_uid);   // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
00053         if (is_array($tplRow))  {   // IF there was a template...
00054                 // Gets the rootLine
00055             $sys_page = t3lib_div::makeInstance("t3lib_pageSelect");
00056             $rootLine = $sys_page->getRootLine($pageId);
00057             $tmpl->runThroughTemplates($rootLine,$template_uid);    // This generates the constants/config + hierarchy info for the template.
00058             $theConstants = $tmpl->generateConfig_constants();  // The editable constants are returned in an array.
00059             $tmpl->ext_categorizeEditableConstants($theConstants);  // The returned constants are sorted in categories, that goes into the $tmpl->categories array
00060             $tmpl->ext_regObjectPositions($tplRow["constants"]);        // This array will contain key=[expanded constantname], value=linenumber in template. (after edit_divider, if any)
00061             return 1;
00062         }
00063     }
00064     function displayExample($theOutput) {
00065         global $SOBE,$tmpl;
00066         if ($tmpl->helpConfig["imagetag"] || $tmpl->helpConfig["description"] || $tmpl->helpConfig["header"])   {
00067     //      $theOutput.=$this->pObj->doc->divider(20);
00068             $theOutput.=$this->pObj->doc->spacer(30);
00069             $theOutput.=$this->pObj->doc->section($tmpl->helpConfig["header"],
00070                 '<div align="center">'.$tmpl->helpConfig["imagetag"].'</div><BR>'.
00071                 ($tmpl->helpConfig["description"] ? implode(explode("//",$tmpl->helpConfig["description"]),"<BR>")."<BR>" : "").
00072                 ($tmpl->helpConfig["bulletlist"] ? "<ul><li>".implode(explode("//",$tmpl->helpConfig["bulletlist"]),"<li>")."</ul>" : "<BR>")
00073                 );
00074         }
00075         return $theOutput;
00076     }
00077 
00078     function main() {
00079         global $SOBE,$BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
00080         global $tmpl,$tplRow,$theConstants;
00081 
00082 
00083         // **************************
00084         // Create extension template
00085         // **************************
00086         $this->pObj->createTemplate($this->pObj->id);
00087 
00088 
00089 
00090 
00091         // **************************
00092         // Checking for more than one template an if, set a menu...
00093         // **************************
00094         $manyTemplatesMenu = $this->pObj->templateMenu();
00095         $template_uid = 0;
00096         if ($manyTemplatesMenu) {
00097             $template_uid = $this->pObj->MOD_SETTINGS["templatesOnPage"];
00098         }
00099 
00100 
00101 
00102         // **************************
00103         // Main
00104         // **************************
00105 
00106         // BUGBUG: Should we check if the uset may at all read and write template-records???
00107         $existTemplate = $this->initialize_editor($this->pObj->id,$template_uid);       // initialize
00108 
00109         if ($existTemplate) {
00110             $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
00111 
00112                 // Update template ?
00113             if (t3lib_div::_POST('submit') || (t3lib_div::testInt(t3lib_div::_POST('submit_x')) && t3lib_div::testInt(t3lib_div::_POST('submit_y')))) {
00114                 $tmpl->changed=0;
00115                 $tmpl->ext_procesInput(t3lib_div::_POST(),$_FILES,$theConstants,$tplRow);
00116         //      debug($tmpl->changed);
00117         //      debug($tmpl->raw);
00118         //      $tmpl->changed=0;
00119                 if ($tmpl->changed) {
00120                         // Set the data to be saved
00121                     $recData=array();
00122                     $recData["sys_template"][$saveId]["constants"] = implode($tmpl->raw,LF);
00123                         // Create new  tce-object
00124                     $tce = t3lib_div::makeInstance("t3lib_TCEmain");
00125                     $tce->stripslashes_values=0;
00126                         // Initialize
00127                     $tce->start($recData,Array());
00128                         // Saved the stuff
00129                     $tce->process_datamap();
00130                         // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
00131                     $tce->clear_cacheCmd("all");
00132 
00133                         // re-read the template ...
00134                     $this->initialize_editor($this->pObj->id,$template_uid);
00135                 }
00136             }
00137 
00138             // Output edit form
00139             $tmpl->ext_readDirResources($TYPO3_CONF_VARS["MODS"]["web_ts"]["onlineResourceDir"]);
00140             $tmpl->ext_resourceDims();
00141 
00142                 // Resetting the menu (start). I wonder if this in any way is a violation of the menu-system. Haven't checked. But need to do it here, because the menu is dependent on the categories available.
00143             $this->pObj->MOD_MENU["constant_editor_cat"] = $tmpl->ext_getCategoryLabelArray();
00144 
00145             $this->pObj->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->pObj->MOD_MENU, t3lib_div::_GP("SET"), $this->pObj->MCONF["name"]);
00146                 // Resetting the menu (stop)
00147 
00148             $theOutput.=$this->pObj->doc->spacer(5);
00149             $theOutput.=$this->pObj->doc->section($GLOBALS['LANG']->getLL('editConstants', true),t3lib_iconWorks::getSpriteIconForRecord('sys_template', $tplRow).'<strong>'.$this->pObj->linkWrapTemplateTitle($tplRow["title"],"constants").'</strong>'.htmlspecialchars(trim($tplRow["sitetitle"])?' - ('.$tplRow["sitetitle"].')':''),0,1);
00150 
00151             if ($manyTemplatesMenu) {
00152                 $theOutput.=$this->pObj->doc->section("",$manyTemplatesMenu);
00153                 $theOutput.=$this->pObj->doc->divider(5);
00154             }
00155 
00156             $theOutput.=$this->pObj->doc->spacer(5);
00157             if (count($this->pObj->MOD_MENU["constant_editor_cat"]))    {
00158                 $menu = $GLOBALS['LANG']->getLL('category', true)." ".t3lib_BEfunc::getFuncMenu($this->pObj->id,"SET[constant_editor_cat]",$this->pObj->MOD_SETTINGS["constant_editor_cat"],$this->pObj->MOD_MENU["constant_editor_cat"]);
00159                 $theOutput.=$this->pObj->doc->section("",'<NOBR>'.$menu.'</NOBR>');
00160             } else {
00161                 $theOutput.=$this->pObj->doc->section($GLOBALS['LANG']->getLL('noConstants', true),$GLOBALS['LANG']->getLL('noConstantsDescription', true),1,0,1);
00162             }
00163 
00164 
00165                     // Category and constant editor config:
00166             $category = $this->pObj->MOD_SETTINGS["constant_editor_cat"];
00167         /*  $TSCE_tmpl = t3lib_div::makeInstance("t3lib_tsparser_ext"); // Defined global here!
00168             $TSCE_tmpl->tt_track = 0;   // Do not log time-performance information
00169             $TSCE_tmpl->init();
00170             $TSCE_tmpl->constants=array($tplRow["constants"]);
00171             debug($tplRow);
00172             $TSCE_tmpl->generateConfig_constants();
00173             debug($TSCE_tmpl->setup);
00174             */
00175             $tmpl->ext_getTSCE_config($category);
00176 
00177 # NOT WORKING:
00178             if ($BE_USER_modOptions["properties"]["constantEditor."]["example"]=="top") {
00179                 $theOutput=$this->displayExample($theOutput);
00180             }
00181 
00182             $printFields = trim($tmpl->ext_printFields($theConstants,$category));
00183             if ($printFields)   {
00184                 $theOutput.=$this->pObj->doc->spacer(20);
00185                 $theOutput.=$this->pObj->doc->section("",$printFields);
00186             }
00187 
00188             if ($BE_USER_modOptions["properties"]["constantEditor."]["example"]!="top") {
00189                 $theOutput=$this->displayExample($theOutput);
00190             }
00191         } else {
00192             $theOutput.=$this->pObj->noTemplate(1);
00193         }
00194         return $theOutput;
00195     }
00196 }
00197 
00198 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_ceditor/class.tx_tstemplateceditor.php"])   {
00199     include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_ceditor/class.tx_tstemplateceditor.php"]);
00200 }
00201 
00202 ?>