[BUGFIX] Fix wrong JS function name in RTE
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / RteHtmlAreaApi.php
1 <?php
2 namespace TYPO3\CMS\Rtehtmlarea;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2007-2013 Stanislas Rolland <typo3(arobas)sjbr.ca>
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 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * API for extending htmlArea RTE
28 *
29 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
30 */
31 abstract class RteHtmlAreaApi {
32
33 protected $extensionKey;
34
35 // The key of the extension that is extending htmlArea RTE
36 protected $pluginName;
37
38 // The name of the plugin registered by the extension
39 protected $relativePathToLocallangFile;
40
41 // Path to the localization file for this script, relative to the extension dir
42 protected $relativePathToSkin;
43
44 // Path to the skin (css) file that should be added to the RTE skin when the registered plugin is enabled, relative to the extension dir
45 protected $relativePathToPluginDirectory;
46
47 // Path to the directory containing the plugin, relative to the extension dir (should end with slash /)
48 protected $htmlAreaRTE;
49
50 // Reference to the invoking object
51 protected $rteExtensionKey;
52
53 // The extension key of the RTE
54 protected $thisConfig;
55
56 // Reference to RTE PageTSConfig
57 protected $toolbar;
58
59 // Refrence to RTE toolbar array
60 protected $LOCAL_LANG;
61
62 // Frontend language array
63 protected $pluginButtons = '';
64
65 // The comma-separated list of button names that the registered plugin is adding to the htmlArea RTE toolbar
66 protected $pluginLabels = '';
67
68 // The comma-separated list of label names that the registered plugin is adding to the htmlArea RTE toolbar
69 protected $pluginAddsButtons = TRUE;
70
71 // Boolean indicating whether the plugin is adding buttons or not
72 protected $convertToolbarForHtmlAreaArray = array();
73
74 // The name-converting array, converting the button names used in the RTE PageTSConfing to the button id's used by the JS scripts
75 protected $requiresClassesConfiguration = FALSE;
76
77 // TRUE if the registered plugin requires the PageTSConfig Classes configuration
78 protected $requiresSynchronousLoad = FALSE;
79
80 // TRUE if the plugin must be loaded synchronously
81 protected $requiredPlugins = '';
82
83 // The comma-separated list of names of prerequisite plugins
84 /**
85 * Returns TRUE if the plugin is available and correctly initialized
86 *
87 * @param object Reference to parent object, which is an instance of the htmlArea RTE
88 * @return boolean TRUE if this plugin object should be made available in the current environment and is correctly initialized
89 */
90 public function main($parentObject) {
91 global $TYPO3_CONF_VARS, $LANG, $TSFE;
92 $this->htmlAreaRTE = $parentObject;
93 $this->rteExtensionKey = &$this->htmlAreaRTE->ID;
94 $this->thisConfig = &$this->htmlAreaRTE->thisConfig;
95 $this->toolbar = &$this->htmlAreaRTE->toolbar;
96 $this->LOCAL_LANG = &$this->htmlAreaRTE->LOCAL_LANG;
97 // Set the value of this boolean based on the initial value of $this->pluginButtons
98 $this->pluginAddsButtons = !empty($this->pluginButtons);
99 // Check if the plugin should be disabled in frontend
100 if ($this->htmlAreaRTE->is_FE() && $TYPO3_CONF_VARS['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['disableInFE']) {
101 return FALSE;
102 }
103 // Localization array must be initialized here
104 if ($this->relativePathToLocallangFile) {
105 if ($this->htmlAreaRTE->is_FE()) {
106 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule(
107 $this->LOCAL_LANG,
108 \TYPO3\CMS\Core\Utility\GeneralUtility::readLLfile(
109 'EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile,
110 $this->htmlAreaRTE->language
111 )
112 );
113 } else {
114 $LANG->includeLLFile('EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile);
115 }
116 }
117 return TRUE;
118 }
119
120 /**
121 * Returns a modified toolbar order string
122 *
123 * @return string a modified tollbar order list
124 */
125 public function addButtonsToToolbar() {
126 //Add only buttons not yet in the default toolbar order
127 $addButtons = implode(',', array_diff(\TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->pluginButtons, TRUE), \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->htmlAreaRTE->defaultToolbarOrder, TRUE)));
128 return ($addButtons ? 'bar,' . $addButtons . ',linebreak,' : '') . $this->htmlAreaRTE->defaultToolbarOrder;
129 }
130
131 /**
132 * Returns the path to the skin component (button icons) that should be added to linked stylesheets
133 *
134 * @return string path to the skin (css) file
135 */
136 public function getPathToSkin() {
137 global $TYPO3_CONF_VARS;
138 if ($TYPO3_CONF_VARS['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['addIconsToSkin']) {
139 return $this->relativePathToSkin;
140 } else {
141 return '';
142 }
143 }
144
145 /**
146 * Return JS configuration of the htmlArea plugins registered by the extension
147 *
148 * @param integer Relative id of the RTE editing area in the form
149 * @return string JS configuration for registered plugins
150 */
151 public function buildJavascriptConfiguration($RTEcounter) {
152 global $TSFE, $LANG;
153 $registerRTEinJavascriptString = '';
154 $pluginButtons = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->pluginButtons, TRUE);
155 foreach ($pluginButtons as $button) {
156 if (in_array($button, $this->toolbar)) {
157 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][($button . '.')])) {
158 $registerRTEinJavascriptString .= '
159 RTEarea[' . $RTEcounter . '].buttons.' . $button . ' = new Object();';
160 }
161 }
162 }
163 return $registerRTEinJavascriptString;
164 }
165
166 /**
167 * Returns the extension key
168 *
169 * @return string the extension key
170 */
171 public function getExtensionKey() {
172 return $this->extensionKey;
173 }
174
175 /**
176 * Returns the path to the plugin directory, if any
177 *
178 * @return string the full path to the plugin directory
179 */
180 public function getPathToPluginDirectory() {
181 return $this->relativePathToPluginDirectory ? $this->htmlAreaRTE->httpTypo3Path . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extensionKey) . $this->relativePathToPluginDirectory : '';
182 }
183
184 /**
185 * Returns a boolean indicating whether the plugin adds buttons or not to the toolbar
186 *
187 * @return boolean
188 */
189 public function addsButtons() {
190 return $this->pluginAddsButtons;
191 }
192
193 /**
194 * Returns the list of buttons implemented by the plugin
195 *
196 * @return string the list of buttons implemented by the plugin
197 */
198 public function getPluginButtons() {
199 return $this->pluginButtons;
200 }
201
202 /**
203 * Returns the list of toolbar labels implemented by the plugin
204 *
205 * @return string the list of labels implemented by the plugin
206 */
207 public function getPluginLabels() {
208 return $this->pluginLabels;
209 }
210
211 /**
212 * Returns the conversion array from TYPO3 button names to htmlArea button names
213 *
214 * @return array the conversion array from TYPO3 button names to htmlArea button names
215 */
216 public function getConvertToolbarForHtmlAreaArray() {
217 return $this->convertToolbarForHtmlAreaArray;
218 }
219
220 /**
221 * Returns TRUE if the extension requires the PageTSConfig Classes configuration
222 *
223 * @return boolean TRUE if the extension requires the PageTSConfig Classes configuration
224 */
225 public function requiresClassesConfiguration() {
226 return $this->requiresClassesConfiguration;
227 }
228
229 /**
230 * Returns TRUE if the plugin requires synchronous load
231 *
232 * @return boolean TRUE if the plugin requires synchronous load
233 */
234 public function requiresSynchronousLoad() {
235 return $this->requiresSynchronousLoad;
236 }
237
238 /**
239 * Sets the plugin to require synchronous load or not
240 *
241 * @param boolean $value: the boolean value to set
242 * @return void
243 */
244 public function setSynchronousLoad($value = TRUE) {
245 $this->requiresSynchronousLoad = $value;
246 }
247
248 /**
249 * Returns the list of plugins required by the plugin
250 *
251 * @return string the list of plugins required by the plugin
252 */
253 public function getRequiredPlugins() {
254 return $this->requiredPlugins;
255 }
256
257 }