[!!!][TASK] RTE: Further API cleanups
[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 * Reference to the invoking object
57 *
58 * @var RteHtmlAreaBase
59 */
60 protected $htmlAreaRTE;
61
62 /**
63 * The extension key of the RTE
64 *
65 * @var string
66 */
67 protected $rteExtensionKey;
68
69 /**
70 * Reference to RTE PageTSConfig
71 *
72 * @var array
73 */
74 protected $thisConfig;
75
76 /**
77 * Reference to RTE toolbar array
78 *
79 * @var array
80 */
81 protected $toolbar;
82
83 /**
84 * Frontend language array
85 *
86 * @var array
87 */
88 protected $LOCAL_LANG;
89
90 /**
91 * The comma-separated list of button names that the registered plugin is adding to the htmlArea RTE toolbar
92 *
93 * @var string
94 */
95 protected $pluginButtons = '';
96
97 /**
98 * The comma-separated list of label names that the registered plugin is adding to the htmlArea RTE toolbar
99 *
100 * @var string
101 */
102 protected $pluginLabels = '';
103
104 /**
105 * Boolean indicating whether the plugin is adding buttons or not
106 *
107 * @var bool
108 */
109 protected $pluginAddsButtons = TRUE;
110
111 /**
112 * The name-converting array, converting the button names used in the RTE PageTSConfing to the button id's used by the JS scripts
113 *
114 * @var array
115 */
116 protected $convertToolbarForHtmlAreaArray = array();
117
118 /**
119 * TRUE if the registered plugin requires the PageTSConfig Classes configuration
120 *
121 * @var bool
122 */
123 protected $requiresClassesConfiguration = FALSE;
124
125 /**
126 * The comma-separated list of names of prerequisite plugins
127 *
128 * @var string
129 */
130 protected $requiredPlugins = '';
131
132 /**
133 * Returns TRUE if the plugin is available and correctly initialized
134 *
135 * @param RteHtmlAreaBase $parentObject parent object
136 * @return bool TRUE if this plugin object should be made available in the current environment and is correctly initialized
137 */
138 public function main($parentObject) {
139 $this->htmlAreaRTE = $parentObject;
140 $this->rteExtensionKey = &$this->htmlAreaRTE->ID;
141 $this->thisConfig = &$this->htmlAreaRTE->thisConfig;
142 $this->toolbar = &$this->htmlAreaRTE->toolbar;
143 $this->LOCAL_LANG = &$this->htmlAreaRTE->LOCAL_LANG;
144 // Set the value of this boolean based on the initial value of $this->pluginButtons
145 $this->pluginAddsButtons = !empty($this->pluginButtons);
146 // Check if the plugin should be disabled in frontend
147 if ($this->htmlAreaRTE->is_FE() && $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['disableInFE']) {
148 return FALSE;
149 }
150 // Localization array must be initialized here
151 if ($this->relativePathToLocallangFile) {
152 if ($this->htmlAreaRTE->is_FE()) {
153 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule(
154 $this->LOCAL_LANG,
155 GeneralUtility::readLLfile(
156 'EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile,
157 $this->htmlAreaRTE->language
158 )
159 );
160 } else {
161 $GLOBALS['LANG']->includeLLFile('EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile);
162 }
163 }
164 return TRUE;
165 }
166
167 /**
168 * Returns a modified toolbar order string
169 *
170 * @return string a modified tollbar order list
171 */
172 public function addButtonsToToolbar() {
173 //Add only buttons not yet in the default toolbar order
174 $addButtons = implode(',', array_diff(GeneralUtility::trimExplode(',', $this->pluginButtons, TRUE), GeneralUtility::trimExplode(',', $this->htmlAreaRTE->defaultToolbarOrder, TRUE)));
175 return ($addButtons ? 'bar,' . $addButtons . ',linebreak,' : '') . $this->htmlAreaRTE->defaultToolbarOrder;
176 }
177
178 /**
179 * Returns the path to the skin component (button icons) that should be added to linked stylesheets
180 *
181 * @return string path to the skin (css) file
182 */
183 public function getPathToSkin() {
184 if (
185 isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['addIconsToSkin'])
186 && $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['addIconsToSkin']
187 ) {
188 return $this->relativePathToSkin;
189 } else {
190 return '';
191 }
192 }
193
194 /**
195 * Return JS configuration of the htmlArea plugins registered by the extension
196 *
197 * @param string $rteNumberPlaceholder A dummy string for JS arrays
198 * @return string JS configuration for registered plugins
199 */
200 public function buildJavascriptConfiguration($rteNumberPlaceholder) {
201 $registerRTEinJavascriptString = '';
202 $pluginButtons = GeneralUtility::trimExplode(',', $this->pluginButtons, TRUE);
203 foreach ($pluginButtons as $button) {
204 if (in_array($button, $this->toolbar)) {
205 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][($button . '.')])) {
206 $registerRTEinJavascriptString .= '
207 RTEarea[' . $rteNumberPlaceholder . '].buttons.' . $button . ' = new Object();';
208 }
209 }
210 }
211 return $registerRTEinJavascriptString;
212 }
213
214 /**
215 * Returns the extension key
216 *
217 * @return string the extension key
218 */
219 public function getExtensionKey() {
220 return $this->extensionKey;
221 }
222
223 /**
224 * Returns a boolean indicating whether the plugin adds buttons or not to the toolbar
225 *
226 * @return bool
227 */
228 public function addsButtons() {
229 return $this->pluginAddsButtons;
230 }
231
232 /**
233 * Returns the list of buttons implemented by the plugin
234 *
235 * @return string the list of buttons implemented by the plugin
236 */
237 public function getPluginButtons() {
238 return $this->pluginButtons;
239 }
240
241 /**
242 * Returns the list of toolbar labels implemented by the plugin
243 *
244 * @return string the list of labels implemented by the plugin
245 */
246 public function getPluginLabels() {
247 return $this->pluginLabels;
248 }
249
250 /**
251 * Returns the conversion array from TYPO3 button names to htmlArea button names
252 *
253 * @return array the conversion array from TYPO3 button names to htmlArea button names
254 */
255 public function getConvertToolbarForHtmlAreaArray() {
256 return $this->convertToolbarForHtmlAreaArray;
257 }
258
259 /**
260 * Returns TRUE if the extension requires the PageTSConfig Classes configuration
261 *
262 * @return bool TRUE if the extension requires the PageTSConfig Classes configuration
263 */
264 public function requiresClassesConfiguration() {
265 return $this->requiresClassesConfiguration;
266 }
267
268 /**
269 * Returns the list of plugins required by the plugin
270 *
271 * @return string the list of plugins required by the plugin
272 */
273 public function getRequiredPlugins() {
274 return $this->requiredPlugins;
275 }
276
277 }