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