8e4b444a8e7f4192bd53e1addc8ee8824a0db3ea
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / RteHtmlAreaApi.php
1 <?php
2 namespace TYPO3\CMS\Rtehtmlarea;
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 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
19
20 /**
21 * API for extending htmlArea RTE
22 *
23 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
24 */
25 abstract class RteHtmlAreaApi {
26
27 /**
28 * The key of the extension that is extending htmlArea RTE
29 *
30 * @var string
31 */
32 protected $extensionKey = 'rtehtmlarea';
33
34 /**
35 * The name of the plugin registered by the extension
36 *
37 * @var string
38 */
39 protected $pluginName;
40
41 /**
42 * Path to the localization file for this script, relative to the extension dir
43 *
44 * @var string
45 */
46 protected $relativePathToLocallangFile = '';
47
48 /**
49 * 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
50 *
51 * @var string
52 */
53 protected $relativePathToSkin = '';
54
55 /**
56 * Path to the directory containing the plugin, relative to the extension dir (should end with slash /)
57 *
58 * @var string
59 */
60 protected $relativePathToPluginDirectory;
61
62 /**
63 * Reference to the invoking object
64 *
65 * @var RteHtmlAreaBase
66 */
67 protected $htmlAreaRTE;
68
69 /**
70 * The extension key of the RTE
71 *
72 * @var string
73 */
74 protected $rteExtensionKey;
75
76 /**
77 * Reference to RTE PageTSConfig
78 *
79 * @var array
80 */
81 protected $thisConfig;
82
83 /**
84 * Reference to RTE toolbar array
85 *
86 * @var array
87 */
88 protected $toolbar;
89
90 /**
91 * Frontend language array
92 *
93 * @var array
94 */
95 protected $LOCAL_LANG;
96
97 /**
98 * The comma-separated list of button names that the registered plugin is adding to the htmlArea RTE toolbar
99 *
100 * @var string
101 */
102 protected $pluginButtons = '';
103
104 /**
105 * The comma-separated list of label names that the registered plugin is adding to the htmlArea RTE toolbar
106 *
107 * @var string
108 */
109 protected $pluginLabels = '';
110
111 /**
112 * Boolean indicating whether the plugin is adding buttons or not
113 *
114 * @var bool
115 */
116 protected $pluginAddsButtons = TRUE;
117
118 /**
119 * The name-converting array, converting the button names used in the RTE PageTSConfing to the button id's used by the JS scripts
120 *
121 * @var array
122 */
123 protected $convertToolbarForHtmlAreaArray = array();
124
125 /**
126 * TRUE if the registered plugin requires the PageTSConfig Classes configuration
127 *
128 * @var bool
129 */
130 protected $requiresClassesConfiguration = FALSE;
131
132 /**
133 * TRUE if the plugin must be loaded synchronously
134 *
135 * @var bool
136 */
137 protected $requiresSynchronousLoad = FALSE;
138
139 /**
140 * The comma-separated list of names of prerequisite plugins
141 *
142 * @var string
143 */
144 protected $requiredPlugins = '';
145
146 /**
147 * Returns TRUE if the plugin is available and correctly initialized
148 *
149 * @param RteHtmlAreaBase $parentObject parent object
150 * @return bool TRUE if this plugin object should be made available in the current environment and is correctly initialized
151 */
152 public function main($parentObject) {
153 $this->htmlAreaRTE = $parentObject;
154 $this->rteExtensionKey = &$this->htmlAreaRTE->ID;
155 $this->thisConfig = &$this->htmlAreaRTE->thisConfig;
156 $this->toolbar = &$this->htmlAreaRTE->toolbar;
157 $this->LOCAL_LANG = &$this->htmlAreaRTE->LOCAL_LANG;
158 // Set the value of this boolean based on the initial value of $this->pluginButtons
159 $this->pluginAddsButtons = !empty($this->pluginButtons);
160 // Check if the plugin should be disabled in frontend
161 if ($this->htmlAreaRTE->is_FE() && $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['disableInFE']) {
162 return FALSE;
163 }
164 // Localization array must be initialized here
165 if ($this->relativePathToLocallangFile) {
166 if ($this->htmlAreaRTE->is_FE()) {
167 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule(
168 $this->LOCAL_LANG,
169 GeneralUtility::readLLfile(
170 'EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile,
171 $this->htmlAreaRTE->language
172 )
173 );
174 } else {
175 $GLOBALS['LANG']->includeLLFile('EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile);
176 }
177 }
178 return TRUE;
179 }
180
181 /**
182 * Returns a modified toolbar order string
183 *
184 * @return string a modified tollbar order list
185 */
186 public function addButtonsToToolbar() {
187 //Add only buttons not yet in the default toolbar order
188 $addButtons = implode(',', array_diff(GeneralUtility::trimExplode(',', $this->pluginButtons, TRUE), GeneralUtility::trimExplode(',', $this->htmlAreaRTE->defaultToolbarOrder, TRUE)));
189 return ($addButtons ? 'bar,' . $addButtons . ',linebreak,' : '') . $this->htmlAreaRTE->defaultToolbarOrder;
190 }
191
192 /**
193 * Returns the path to the skin component (button icons) that should be added to linked stylesheets
194 *
195 * @return string path to the skin (css) file
196 */
197 public function getPathToSkin() {
198 if (
199 isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['addIconsToSkin'])
200 && $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['addIconsToSkin']
201 ) {
202 return $this->relativePathToSkin;
203 } else {
204 return '';
205 }
206 }
207
208 /**
209 * Return JS configuration of the htmlArea plugins registered by the extension
210 *
211 * @param string $rteNumberPlaceholder A dummy string for JS arrays
212 * @return string JS configuration for registered plugins
213 */
214 public function buildJavascriptConfiguration($rteNumberPlaceholder) {
215 $registerRTEinJavascriptString = '';
216 $pluginButtons = GeneralUtility::trimExplode(',', $this->pluginButtons, TRUE);
217 foreach ($pluginButtons as $button) {
218 if (in_array($button, $this->toolbar)) {
219 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][($button . '.')])) {
220 $registerRTEinJavascriptString .= '
221 RTEarea[' . $rteNumberPlaceholder . '].buttons.' . $button . ' = new Object();';
222 }
223 }
224 }
225 return $registerRTEinJavascriptString;
226 }
227
228 /**
229 * Returns the extension key
230 *
231 * @return string the extension key
232 */
233 public function getExtensionKey() {
234 return $this->extensionKey;
235 }
236
237 /**
238 * Returns the path to the plugin directory, if any
239 *
240 * @return string the full path to the plugin directory
241 */
242 public function getPathToPluginDirectory() {
243 return $this->relativePathToPluginDirectory ? $this->htmlAreaRTE->httpTypo3Path . ExtensionManagementUtility::siteRelPath($this->extensionKey) . $this->relativePathToPluginDirectory : '';
244 }
245
246 /**
247 * Returns a boolean indicating whether the plugin adds buttons or not to the toolbar
248 *
249 * @return bool
250 */
251 public function addsButtons() {
252 return $this->pluginAddsButtons;
253 }
254
255 /**
256 * Returns the list of buttons implemented by the plugin
257 *
258 * @return string the list of buttons implemented by the plugin
259 */
260 public function getPluginButtons() {
261 return $this->pluginButtons;
262 }
263
264 /**
265 * Returns the list of toolbar labels implemented by the plugin
266 *
267 * @return string the list of labels implemented by the plugin
268 */
269 public function getPluginLabels() {
270 return $this->pluginLabels;
271 }
272
273 /**
274 * Returns the conversion array from TYPO3 button names to htmlArea button names
275 *
276 * @return array the conversion array from TYPO3 button names to htmlArea button names
277 */
278 public function getConvertToolbarForHtmlAreaArray() {
279 return $this->convertToolbarForHtmlAreaArray;
280 }
281
282 /**
283 * Returns TRUE if the extension requires the PageTSConfig Classes configuration
284 *
285 * @return bool TRUE if the extension requires the PageTSConfig Classes configuration
286 */
287 public function requiresClassesConfiguration() {
288 return $this->requiresClassesConfiguration;
289 }
290
291 /**
292 * Returns TRUE if the plugin requires synchronous load
293 *
294 * @return bool TRUE if the plugin requires synchronous load
295 */
296 public function requiresSynchronousLoad() {
297 return $this->requiresSynchronousLoad;
298 }
299
300 /**
301 * Sets the plugin to require synchronous load or not
302 *
303 * @param bool $value: the boolean value to set
304 * @return void
305 */
306 public function setSynchronousLoad($value = TRUE) {
307 $this->requiresSynchronousLoad = $value;
308 }
309
310 /**
311 * Returns the list of plugins required by the plugin
312 *
313 * @return string the list of plugins required by the plugin
314 */
315 public function getRequiredPlugins() {
316 return $this->requiredPlugins;
317 }
318
319 }