TYPO3 CMS  TYPO3_6-2
TypoScriptTemplateInfoHook.php
Go to the documentation of this file.
1 <?php
3 
23 
27  protected $t3editor = NULL;
28 
32  protected $ajaxSaveType = 'TypoScriptTemplateInformationModuleFunctionController';
33 
37  protected function getT3editor() {
38  if ($this->t3editor == NULL) {
39  $this->t3editor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\T3editor\\T3editor')->setMode(\TYPO3\CMS\T3editor\T3editor::MODE_TYPOSCRIPT)->setAjaxSaveType($this->ajaxSaveType);
40  }
41  return $this->t3editor;
42  }
43 
53  public function preStartPageHook($parameters, $pObj) {
54  // Enable editor in Template-Modul
55  if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('M') === 'web_ts') {
56  $t3editor = $this->getT3editor();
57  // Insert javascript code in document header
58  $pObj->JScode .= $t3editor->getJavascriptCode($pObj);
59  }
60  }
61 
70  public function postOutputProcessingHook($parameters, $pObj) {
71  $t3editor = $this->getT3editor();
72  if (!$t3editor->isEnabled()) {
73  return;
74  }
75  foreach (array('constants', 'config') as $type) {
76  if ($parameters['e'][$type]) {
77  $attributes = 'rows="' . $parameters['numberOfRows'] . '" ' . 'wrap="off" ' . $pObj->pObj->doc->formWidth(48, TRUE, 'width:98%;height:60%');
78  $title = $GLOBALS['LANG']->getLL('template') . ' ' . htmlspecialchars($parameters['tplRow']['title']) . $GLOBALS['LANG']->getLL('delimiter') . ' ' . $GLOBALS['LANG']->getLL($type);
79  $outCode = $t3editor->getCodeEditor('data[' . $type . ']', 'fixed-font enable-tab', '$1', $attributes, $title, array(
80  'pageId' => (int)$pObj->pObj->id
81  ));
82  $parameters['theOutput'] = preg_replace('/\\<textarea name="data\\[' . $type . '\\]".*\\>([^\\<]*)\\<\\/textarea\\>/mi', $outCode, $parameters['theOutput']);
83  }
84  }
85  }
86 
92  public function save($parameters, $pObj) {
93  $savingsuccess = FALSE;
94  if ($parameters['type'] == $this->ajaxSaveType) {
96  if (!is_numeric($pageId) || $pageId < 1) {
97  return FALSE;
98  }
99  // If given use the requested template_uid
100  // if not, use the first template-record on the page (in this case there should only be one record!)
102  $template_uid = $set['templatesOnPage'] ?: 0;
103  // Defined global here!
104  $tmpl = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\ExtendedTemplateService');
105  // Do not log time-performance information
106  $tmpl->tt_track = 0;
107  $tmpl->init();
108  // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
109  $tplRow = $tmpl->ext_getFirstTemplate($pageId, $template_uid);
110  $existTemplate = is_array($tplRow) ? TRUE : FALSE;
111  if ($existTemplate) {
112  $saveId = $tplRow['_ORIG_uid'] ?: $tplRow['uid'];
113  // Update template ?
115  if ($POST['submit']) {
116  // Set the data to be saved
117  $recData = array();
118  if (is_array($POST['data'])) {
119  foreach ($POST['data'] as $field => $val) {
120  switch ($field) {
121  case 'constants':
122  case 'config':
123  // Replace Windows- and Mac linebreaks
124  $val = str_replace(array(CRLF, CR), LF, $val);
125  // intended fallthrough
126  case 'title':
127  case 'sitetitle':
128  case 'description':
129  $recData['sys_template'][$saveId][$field] = $val;
130  break;
131  }
132  }
133  }
134  if (count($recData)) {
135  // process template row before saving
136  $tstemplateinfo = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateInformationModuleFunctionController');
137  /* @var $tstemplateinfo \TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController */
138  // load the MOD_SETTINGS in order to check if the includeTypoScriptFileContent is set
139  $tstemplateinfo->pObj = $pObj;
140  $tstemplateinfo->pObj->MOD_SETTINGS = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleData(array('includeTypoScriptFileContent' => TRUE), array(), 'web_ts');
141  $recData['sys_template'][$saveId] = $tstemplateinfo->processTemplateRowBeforeSaving($recData['sys_template'][$saveId]);
142  // Create new tce-object
143  $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
144  $tce->stripslashes_values = 0;
145  // Initialize
146  $tce->start($recData, array());
147  // Saved the stuff
148  $tce->process_datamap();
149  // Clear the cache (note: currently only admin-users can clear the
150  // cache in tce_main.php)
151  $tce->clear_cacheCmd('all');
152  $savingsuccess = TRUE;
153  }
154  }
155  }
156  }
157  return $savingsuccess;
158  }
159 
160 }
$parameters
Definition: FileDumpEID.php:15
static getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]