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