[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / t3editor / Classes / Hook / TypoScriptTemplateInfoHook.php
1 <?php
2 namespace TYPO3\CMS\T3editor\Hook;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Hook for tstemplate info
19 *
20 * @author Tobias Liebig <mail_typo3@etobi.de>
21 */
22 class TypoScriptTemplateInfoHook {
23
24 /**
25 * @var \TYPO3\CMS\T3editor\T3editor
26 */
27 protected $t3editor = NULL;
28
29 /**
30 * @var string
31 */
32 protected $ajaxSaveType = 'TypoScriptTemplateInformationModuleFunctionController';
33
34 /**
35 * @return \TYPO3\CMS\T3editor\T3editor
36 */
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
44 /**
45 * Hook-function: inject t3editor JavaScript code before the page is compiled
46 * called in \TYPO3\CMS\Backend\Template\DocumentTemplate:startPage
47 *
48 * @param array $parameters
49 * @param \TYPO3\CMS\Backend\Template\DocumentTemplate $pObj
50 * @return void
51 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate::startPage
52 */
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
62 /**
63 * Hook-function:
64 * called in typo3/sysext/tstemplate_info/Classes/Controller/TypoScriptTemplateInformationModuleFunctionController.php
65 *
66 * @param array $parameters
67 * @param \TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController $pObj
68 * @return void
69 */
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
87 /**
88 * Process saving request like in class.tstemplateinfo.php (TCE processing)
89 *
90 * @return boolean TRUE if successful
91 */
92 public function save($parameters, $pObj) {
93 $savingsuccess = FALSE;
94 if ($parameters['type'] == $this->ajaxSaveType) {
95 $pageId = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('pageId');
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!)
101 $set = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('SET');
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 ?
114 $POST = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST();
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
123 case 'config':
124
125 case 'title':
126
127 case 'sitetitle':
128
129 case 'description':
130 $recData['sys_template'][$saveId][$field] = $val;
131 break;
132 }
133 }
134 }
135 if (count($recData)) {
136 // process template row before saving
137 $tstemplateinfo = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateInformationModuleFunctionController');
138 /* @var $tstemplateinfo \TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController */
139 // load the MOD_SETTINGS in order to check if the includeTypoScriptFileContent is set
140 $tstemplateinfo->pObj = $pObj;
141 $tstemplateinfo->pObj->MOD_SETTINGS = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleData(array('includeTypoScriptFileContent' => TRUE), array(), 'web_ts');
142 $recData['sys_template'][$saveId] = $tstemplateinfo->processTemplateRowBeforeSaving($recData['sys_template'][$saveId]);
143 // Create new tce-object
144 $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
145 $tce->stripslashes_values = 0;
146 // Initialize
147 $tce->start($recData, array());
148 // Saved the stuff
149 $tce->process_datamap();
150 // Clear the cache (note: currently only admin-users can clear the
151 // cache in tce_main.php)
152 $tce->clear_cacheCmd('all');
153 $savingsuccess = TRUE;
154 }
155 }
156 }
157 }
158 return $savingsuccess;
159 }
160
161 }