[TASK] Update TYPO3 version in ext_emconf.php and composer.json
[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 ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['addIconsToSkin']) {
199 return $this->relativePathToSkin;
200 } else {
201 return '';
202 }
203 }
204
205 /**
206 * Return JS configuration of the htmlArea plugins registered by the extension
207 *
208 * @param string $rteNumberPlaceholder A dummy string for JS arrays
209 * @return string JS configuration for registered plugins
210 */
211 public function buildJavascriptConfiguration($rteNumberPlaceholder) {
212 $registerRTEinJavascriptString = '';
213 $pluginButtons = GeneralUtility::trimExplode(',', $this->pluginButtons, TRUE);
214 foreach ($pluginButtons as $button) {
215 if (in_array($button, $this->toolbar)) {
216 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][($button . '.')])) {
217 $registerRTEinJavascriptString .= '
218 RTEarea[' . $rteNumberPlaceholder . '].buttons.' . $button . ' = new Object();';
219 }
220 }
221 }
222 return $registerRTEinJavascriptString;
223 }
224
225 /**
226 * Returns the extension key
227 *
228 * @return string the extension key
229 */
230 public function getExtensionKey() {
231 return $this->extensionKey;
232 }
233
234 /**
235 * Returns the path to the plugin directory, if any
236 *
237 * @return string the full path to the plugin directory
238 */
239 public function getPathToPluginDirectory() {
240 return $this->relativePathToPluginDirectory ? $this->htmlAreaRTE->httpTypo3Path . ExtensionManagementUtility::siteRelPath($this->extensionKey) . $this->relativePathToPluginDirectory : '';
241 }
242
243 /**
244 * Returns a boolean indicating whether the plugin adds buttons or not to the toolbar
245 *
246 * @return bool
247 */
248 public function addsButtons() {
249 return $this->pluginAddsButtons;
250 }
251
252 /**
253 * Returns the list of buttons implemented by the plugin
254 *
255 * @return string the list of buttons implemented by the plugin
256 */
257 public function getPluginButtons() {
258 return $this->pluginButtons;
259 }
260
261 /**
262 * Returns the list of toolbar labels implemented by the plugin
263 *
264 * @return string the list of labels implemented by the plugin
265 */
266 public function getPluginLabels() {
267 return $this->pluginLabels;
268 }
269
270 /**
271 * Returns the conversion array from TYPO3 button names to htmlArea button names
272 *
273 * @return array the conversion array from TYPO3 button names to htmlArea button names
274 */
275 public function getConvertToolbarForHtmlAreaArray() {
276 return $this->convertToolbarForHtmlAreaArray;
277 }
278
279 /**
280 * Returns TRUE if the extension requires the PageTSConfig Classes configuration
281 *
282 * @return bool TRUE if the extension requires the PageTSConfig Classes configuration
283 */
284 public function requiresClassesConfiguration() {
285 return $this->requiresClassesConfiguration;
286 }
287
288 /**
289 * Returns TRUE if the plugin requires synchronous load
290 *
291 * @return bool TRUE if the plugin requires synchronous load
292 */
293 public function requiresSynchronousLoad() {
294 return $this->requiresSynchronousLoad;
295 }
296
297 /**
298 * Sets the plugin to require synchronous load or not
299 *
300 * @param bool $value: the boolean value to set
301 * @return void
302 */
303 public function setSynchronousLoad($value = TRUE) {
304 $this->requiresSynchronousLoad = $value;
305 }
306
307 /**
308 * Returns the list of plugins required by the plugin
309 *
310 * @return string the list of plugins required by the plugin
311 */
312 public function getRequiredPlugins() {
313 return $this->requiredPlugins;
314 }
315
316 }