8d0422eb9aad3c3fe3a2d1ebe314db59a251e755
[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 * The comma-separated list of names of prerequisite plugins
134 *
135 * @var string
136 */
137 protected $requiredPlugins = '';
138
139 /**
140 * Returns TRUE if the plugin is available and correctly initialized
141 *
142 * @param RteHtmlAreaBase $parentObject parent object
143 * @return bool TRUE if this plugin object should be made available in the current environment and is correctly initialized
144 */
145 public function main($parentObject) {
146 $this->htmlAreaRTE = $parentObject;
147 $this->rteExtensionKey = &$this->htmlAreaRTE->ID;
148 $this->thisConfig = &$this->htmlAreaRTE->thisConfig;
149 $this->toolbar = &$this->htmlAreaRTE->toolbar;
150 $this->LOCAL_LANG = &$this->htmlAreaRTE->LOCAL_LANG;
151 // Set the value of this boolean based on the initial value of $this->pluginButtons
152 $this->pluginAddsButtons = !empty($this->pluginButtons);
153 // Check if the plugin should be disabled in frontend
154 if ($this->htmlAreaRTE->is_FE() && $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['disableInFE']) {
155 return FALSE;
156 }
157 // Localization array must be initialized here
158 if ($this->relativePathToLocallangFile) {
159 if ($this->htmlAreaRTE->is_FE()) {
160 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule(
161 $this->LOCAL_LANG,
162 GeneralUtility::readLLfile(
163 'EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile,
164 $this->htmlAreaRTE->language
165 )
166 );
167 } else {
168 $GLOBALS['LANG']->includeLLFile('EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile);
169 }
170 }
171 return TRUE;
172 }
173
174 /**
175 * Returns a modified toolbar order string
176 *
177 * @return string a modified tollbar order list
178 */
179 public function addButtonsToToolbar() {
180 //Add only buttons not yet in the default toolbar order
181 $addButtons = implode(',', array_diff(GeneralUtility::trimExplode(',', $this->pluginButtons, TRUE), GeneralUtility::trimExplode(',', $this->htmlAreaRTE->defaultToolbarOrder, TRUE)));
182 return ($addButtons ? 'bar,' . $addButtons . ',linebreak,' : '') . $this->htmlAreaRTE->defaultToolbarOrder;
183 }
184
185 /**
186 * Returns the path to the skin component (button icons) that should be added to linked stylesheets
187 *
188 * @return string path to the skin (css) file
189 */
190 public function getPathToSkin() {
191 if (
192 isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['addIconsToSkin'])
193 && $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['addIconsToSkin']
194 ) {
195 return $this->relativePathToSkin;
196 } else {
197 return '';
198 }
199 }
200
201 /**
202 * Return JS configuration of the htmlArea plugins registered by the extension
203 *
204 * @param string $rteNumberPlaceholder A dummy string for JS arrays
205 * @return string JS configuration for registered plugins
206 */
207 public function buildJavascriptConfiguration($rteNumberPlaceholder) {
208 $registerRTEinJavascriptString = '';
209 $pluginButtons = GeneralUtility::trimExplode(',', $this->pluginButtons, TRUE);
210 foreach ($pluginButtons as $button) {
211 if (in_array($button, $this->toolbar)) {
212 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][($button . '.')])) {
213 $registerRTEinJavascriptString .= '
214 RTEarea[' . $rteNumberPlaceholder . '].buttons.' . $button . ' = new Object();';
215 }
216 }
217 }
218 return $registerRTEinJavascriptString;
219 }
220
221 /**
222 * Returns the extension key
223 *
224 * @return string the extension key
225 */
226 public function getExtensionKey() {
227 return $this->extensionKey;
228 }
229
230 /**
231 * Returns the path to the plugin directory, if any
232 *
233 * @return string the full path to the plugin directory
234 */
235 public function getPathToPluginDirectory() {
236 return $this->relativePathToPluginDirectory ? $this->htmlAreaRTE->httpTypo3Path . ExtensionManagementUtility::siteRelPath($this->extensionKey) . $this->relativePathToPluginDirectory : '';
237 }
238
239 /**
240 * Returns a boolean indicating whether the plugin adds buttons or not to the toolbar
241 *
242 * @return bool
243 */
244 public function addsButtons() {
245 return $this->pluginAddsButtons;
246 }
247
248 /**
249 * Returns the list of buttons implemented by the plugin
250 *
251 * @return string the list of buttons implemented by the plugin
252 */
253 public function getPluginButtons() {
254 return $this->pluginButtons;
255 }
256
257 /**
258 * Returns the list of toolbar labels implemented by the plugin
259 *
260 * @return string the list of labels implemented by the plugin
261 */
262 public function getPluginLabels() {
263 return $this->pluginLabels;
264 }
265
266 /**
267 * Returns the conversion array from TYPO3 button names to htmlArea button names
268 *
269 * @return array the conversion array from TYPO3 button names to htmlArea button names
270 */
271 public function getConvertToolbarForHtmlAreaArray() {
272 return $this->convertToolbarForHtmlAreaArray;
273 }
274
275 /**
276 * Returns TRUE if the extension requires the PageTSConfig Classes configuration
277 *
278 * @return bool TRUE if the extension requires the PageTSConfig Classes configuration
279 */
280 public function requiresClassesConfiguration() {
281 return $this->requiresClassesConfiguration;
282 }
283
284 /**
285 * Returns the list of plugins required by the plugin
286 *
287 * @return string the list of plugins required by the plugin
288 */
289 public function getRequiredPlugins() {
290 return $this->requiredPlugins;
291 }
292
293 }