|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2007-2011 Tobias Liebig <mail_typo3@etobi.de> 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 require_once(t3lib_extMgm::extPath('t3editor', 'classes/class.tx_t3editor.php')); 00029 00030 class tx_t3editor_hooks_tstemplateinfo { 00031 00032 /** 00033 * @var tx_t3editor 00034 */ 00035 protected $t3editor = NULL; 00036 00037 /** 00038 * @var string 00039 */ 00040 protected $ajaxSaveType = 'tx_tstemplateinfo'; 00041 00042 /** 00043 * @return tx_t3editor 00044 */ 00045 protected function getT3editor() { 00046 if ($this->t3editor == NULL) { 00047 $this->t3editor = t3lib_div::makeInstance('tx_t3editor') 00048 ->setMode(tx_t3editor::MODE_TYPOSCRIPT) 00049 ->setAjaxSaveType($this->ajaxSaveType); 00050 } 00051 return $this->t3editor; 00052 } 00053 00054 /** 00055 * Hook-function: inject t3editor JavaScript code before the page is compiled 00056 * called in typo3/template.php:startPage 00057 * 00058 * @param array $parameters 00059 * @param template $pObj 00060 */ 00061 public function preStartPageHook($parameters, $pObj) { 00062 // enable editor in Template-Modul 00063 if (preg_match('/sysext\/tstemplate\/ts\/index\.php/', $_SERVER['SCRIPT_NAME'])) { 00064 00065 $t3editor = $this->getT3editor(); 00066 00067 // insert javascript code in document header 00068 $pObj->JScode .= $t3editor->getJavascriptCode($pObj); 00069 } 00070 } 00071 00072 00073 /** 00074 * Hook-function: 00075 * called in typo3/sysext/tstemplate_info/class.tx_tstemplateinfo.php 00076 * 00077 * @param array $parameters 00078 * @param tx_tstemplateinfo $pObj 00079 */ 00080 public function postOutputProcessingHook($parameters, $pObj) { 00081 $t3editor = $this->getT3editor(); 00082 00083 if (!$t3editor->isEnabled()) { 00084 return; 00085 } 00086 00087 foreach (array('constants', 'config') as $type) { 00088 if ($parameters['e'][$type]) { 00089 $attributes = 'rows="' . $parameters['numberOfRows'] . '" ' . 00090 'wrap="off" ' . 00091 $pObj->pObj->doc->formWidthText(48, 'width:98%;height:60%', 'off'); 00092 00093 $title = $GLOBALS['LANG']->getLL('template') . ' ' . 00094 htmlspecialchars($parameters['tplRow']['title']) . 00095 $GLOBALS['LANG']->getLL('delimiter') . ' ' . 00096 $GLOBALS['LANG']->getLL($type); 00097 00098 $outCode = $t3editor->getCodeEditor( 00099 'data[' . $type . ']', 00100 'fixed-font enable-tab', 00101 '$1', // will be replaced with the actual code later, see preg_replace below 00102 $attributes, 00103 $title, 00104 array( 00105 'pageId' => intval($pObj->pObj->id) 00106 ) 00107 ); 00108 $parameters['theOutput'] = preg_replace( 00109 '/<textarea name="data\[' . $type . '\]".*>([^<]*)<\/textarea>/mi', 00110 $outCode, 00111 $parameters['theOutput'] 00112 ); 00113 } 00114 } 00115 } 00116 00117 00118 /** 00119 * Process saving request like in class.tstemplateinfo.php (TCE processing) 00120 * 00121 * @return boolean true if successful 00122 */ 00123 public function save($parameters, $pObj) { 00124 $savingsuccess = false; 00125 if ($parameters['type'] == $this->ajaxSaveType) { 00126 00127 $pageId = t3lib_div::_GP('pageId'); 00128 if (!is_numeric($pageId) || $pageId < 1) { 00129 return false; 00130 } 00131 00132 // if given use the requested template_uid 00133 // if not, use the first template-record on the page (in this case there should only be one record!) 00134 $set = t3lib_div::_GP('SET'); 00135 $template_uid = $set['templatesOnPage'] ? $set['templatesOnPage'] : 0; 00136 00137 $tmpl = t3lib_div::makeInstance('t3lib_tsparser_ext'); // Defined global here! 00138 $tmpl->tt_track = 0; // Do not log time-performance information 00139 $tmpl->init(); 00140 00141 // Get the row of the first VISIBLE template of the page. whereclause like the frontend. 00142 $tplRow = $tmpl->ext_getFirstTemplate($pageId, $template_uid); 00143 $existTemplate = (is_array($tplRow) ? true : false); 00144 00145 if ($existTemplate) { 00146 $saveId = ($tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid']); 00147 00148 // Update template ? 00149 $POST = t3lib_div::_POST(); 00150 00151 if ($POST['submit']) { 00152 require_once(PATH_t3lib . 'class.t3lib_tcemain.php'); 00153 00154 // Set the data to be saved 00155 $recData = array(); 00156 00157 if (is_array($POST['data'])) { 00158 foreach ($POST['data'] as $field => $val) { 00159 switch ($field) { 00160 case 'constants': 00161 case 'config': 00162 case 'title': 00163 case 'sitetitle': 00164 case 'description': 00165 $recData['sys_template'][$saveId][$field] = $val; 00166 break; 00167 } 00168 } 00169 } 00170 if (count($recData)) { 00171 00172 // process template row before saving 00173 require_once t3lib_extMgm::extPath('tstemplate_info').'class.tx_tstemplateinfo.php'; 00174 $tstemplateinfo = t3lib_div::makeInstance('tx_tstemplateinfo'); /* @var $tstemplateinfo tx_tstemplateinfo */ 00175 // load the MOD_SETTINGS in order to check if the includeTypoScriptFileContent is set 00176 $tstemplateinfo->pObj->MOD_SETTINGS = t3lib_BEfunc::getModuleData( 00177 array('includeTypoScriptFileContent' => true), 00178 array(), 00179 'web_ts' 00180 ); 00181 $recData['sys_template'][$saveId] = $tstemplateinfo->processTemplateRowBeforeSaving($recData['sys_template'][$saveId]); 00182 00183 // Create new tce-object 00184 $tce = t3lib_div::makeInstance('t3lib_TCEmain'); 00185 $tce->stripslashes_values = 0; 00186 00187 // Initialize 00188 $tce->start($recData, array()); 00189 00190 // Saved the stuff 00191 $tce->process_datamap(); 00192 00193 // Clear the cache (note: currently only admin-users can clear the 00194 // cache in tce_main.php) 00195 $tce->clear_cacheCmd('all'); 00196 00197 $savingsuccess = true; 00198 } 00199 } 00200 } 00201 } 00202 return $savingsuccess; 00203 } 00204 } 00205 00206 00207 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/t3editor/classes/class.tx_t3editor_hooks_tstemplateinfo.php'])) { 00208 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/t3editor/classes/class.tx_t3editor_hooks_tstemplateinfo.php']); 00209 } 00210 00211 ?>
1.8.0