[TASK] Remove dummy files from ext:tstemplate_* extensions
[Packages/TYPO3.CMS.git] / typo3 / sysext / t3editor / Classes / Hook / FileEditHook.php
1 <?php
2 namespace TYPO3\CMS\T3Editor\Hook;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Tobias Liebig <mail_typo3@etobi.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * File edit hook for t3editor
32 *
33 * @author Tobias Liebig <mail_typo3@etobi.de>
34 */
35 class FileEditHook {
36
37 /**
38 * @var \TYPO3\CMS\T3Editor\T3Editor
39 */
40 protected $t3editor = NULL;
41
42 /**
43 * @var string
44 */
45 protected $ajaxSaveType = 'TypoScriptTemplateInformationModuleFunctionController';
46
47 /**
48 * @return \TYPO3\CMS\T3Editor\T3Editor
49 */
50 protected function getT3editor() {
51 if ($this->t3editor == NULL) {
52 $this->t3editor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\T3Editor\\T3Editor')->setAjaxSaveType($this->ajaxSaveType);
53 }
54 return $this->t3editor;
55 }
56
57 /**
58 * Hook-function: inject t3editor JavaScript code before the page is compiled
59 * called in file_edit.php:SC_file_edit->main
60 *
61 * @param array $parameters
62 * @param \TYPO3\CMS\Backend\Controller\File\EditFileController $pObj
63 */
64 public function preOutputProcessingHook($parameters, $pObj) {
65 $t3editor = $this->getT3editor();
66 $t3editor->setModeByFile($parameters['target']);
67 if (!$t3editor->isEnabled() || !$t3editor->getMode()) {
68 return;
69 }
70 $parameters['content'] = str_replace('<!--###POSTJSMARKER###-->', '<!--###POSTJSMARKER###-->' . $t3editor->getModeSpecificJavascriptCode(), $parameters['content']);
71 }
72
73 /**
74 * Hook-function: inject t3editor JavaScript code before the page is compiled
75 * called in \TYPO3\CMS\Backend\Template\DocumentTemplate:startPage
76 *
77 * @param array $parameters
78 * @param \TYPO3\CMS\Backend\Template\DocumentTemplate $pObj
79 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate::startPage
80 */
81 public function preStartPageHook($parameters, $pObj) {
82 if (preg_match('/typo3\\/file_edit\\.php/', $_SERVER['SCRIPT_NAME'])) {
83 $t3editor = $this->getT3editor();
84 if (!$t3editor->isEnabled()) {
85 return;
86 }
87 $pObj->JScode .= $t3editor->getJavascriptCode($pObj);
88 $pObj->loadJavascriptLib(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('t3editor') . 'res/jslib/fileedit.js');
89 }
90 }
91
92 /**
93 * Hook-function:
94 * called in file_edit.php:SC_file_edit->main
95 *
96 * @param array $parameters
97 * @param \TYPO3\CMS\Backend\Controller\File\EditFileController $pObj
98 */
99 public function postOutputProcessingHook($parameters, $pObj) {
100 $t3editor = $this->getT3editor();
101 if (!$t3editor->isEnabled() || !$t3editor->getMode()) {
102 return;
103 }
104 $attributes = 'rows="30" ' . 'wrap="off" ' . $pObj->doc->formWidthText(48, 'width:98%;height:60%', 'off');
105 $title = $GLOBALS['LANG']->getLL('file') . ' ' . htmlspecialchars($pObj->target);
106 $outCode = $t3editor->getCodeEditor('file[editfile][0][data]', 'fixed-font enable-tab', '$1', $attributes, $title, array(
107 'target' => intval($pObj->target)
108 ));
109 $parameters['pageContent'] = preg_replace('/\\<textarea .*name="file\\[editfile\\]\\[0\\]\\[data\\]".*\\>([^\\<]*)\\<\\/textarea\\>/mi', $outCode, $parameters['pageContent']);
110 }
111
112 /**
113 * @return boolean TRUE if successful
114 */
115 public function save($parameters, $pObj) {
116 $savingsuccess = FALSE;
117 if ($parameters['type'] == $this->ajaxSaveType) {
118 require_once 'init.php';
119 $tceFile = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Controller\\File\\FileController');
120 $tceFile->processAjaxRequest(array(), $parameters['ajaxObj']);
121 $result = $parameters['ajaxObj']->getContent('result');
122 $savingsuccess = is_array($result) && $result['editfile'][0];
123 }
124 return $savingsuccess;
125 }
126
127 }
128
129
130 ?>