[TASK] CGL violations "AssignmentArithmeticAndComparisonSpace"
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / RteHtmlAreaApi.php
1 <?php
2 namespace TYPO3\CMS\Rtehtmlarea;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2007-2011 Stanislas Rolland <typo3(arobas)sjbr.ca>
8 * All rights reserved
9 *
10 * This script is part of the Typo3 project. The Typo3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * API for extending htmlArea RTE
28 *
29 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
30 */
31 abstract class RteHtmlAreaApi {
32
33 protected $extensionKey;
34
35 // The key of the extension that is extending htmlArea RTE
36 protected $pluginName;
37
38 // The name of the plugin registered by the extension
39 protected $relativePathToLocallangFile;
40
41 // Path to the localization file for this script, relative to the extension dir
42 protected $relativePathToSkin;
43
44 // 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
45 protected $relativePathToPluginDirectory;
46
47 // Path to the directory containing the plugin, relative to the extension dir (should end with slash /)
48 protected $htmlAreaRTE;
49
50 // Reference to the invoking object
51 protected $rteExtensionKey;
52
53 // The extension key of the RTE
54 protected $thisConfig;
55
56 // Reference to RTE PageTSConfig
57 protected $toolbar;
58
59 // Refrence to RTE toolbar array
60 protected $LOCAL_LANG;
61
62 // Frontend language array
63 protected $pluginButtons = '';
64
65 // The comma-separated list of button names that the registered plugin is adding to the htmlArea RTE toolbar
66 protected $pluginLabels = '';
67
68 // The comma-separated list of label names that the registered plugin is adding to the htmlArea RTE toolbar
69 protected $pluginAddsButtons = TRUE;
70
71 // Boolean indicating whether the plugin is adding buttons or not
72 protected $convertToolbarForHtmlAreaArray = array();
73
74 // The name-converting array, converting the button names used in the RTE PageTSConfing to the button id's used by the JS scripts
75 protected $requiresClassesConfiguration = FALSE;
76
77 // TRUE if the registered plugin requires the PageTSConfig Classes configuration
78 protected $requiresSynchronousLoad = FALSE;
79
80 // TRUE if the plugin must be loaded synchronously
81 protected $requiredPlugins = '';
82
83 // The comma-separated list of names of prerequisite plugins
84 /**
85 * Returns TRUE if the plugin is available and correctly initialized
86 *
87 * @param object Reference to parent object, which is an instance of the htmlArea RTE
88 * @return boolean TRUE if this plugin object should be made available in the current environment and is correctly initialized
89 */
90 public function main($parentObject) {
91 global $TYPO3_CONF_VARS, $LANG, $TSFE;
92 $this->htmlAreaRTE = $parentObject;
93 $this->rteExtensionKey = &$this->htmlAreaRTE->ID;
94 $this->thisConfig = &$this->htmlAreaRTE->thisConfig;
95 $this->toolbar = &$this->htmlAreaRTE->toolbar;
96 $this->LOCAL_LANG = &$this->htmlAreaRTE->LOCAL_LANG;
97 // Set the value of this boolean based on the initial value of $this->pluginButtons
98 $this->pluginAddsButtons = !empty($this->pluginButtons);
99 // Check if the plugin should be disabled in frontend
100 if ($this->htmlAreaRTE->is_FE() && $TYPO3_CONF_VARS['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['disableInFE']) {
101 return FALSE;
102 }
103 // Localization array must be initialized here
104 if ($this->relativePathToLocallangFile) {
105 if ($this->htmlAreaRTE->is_FE()) {
106 $this->LOCAL_LANG = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($this->LOCAL_LANG, \TYPO3\CMS\Core\Utility\GeneralUtility::readLLfile('EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile, $this->htmlAreaRTE->language));
107 } else {
108 $LANG->includeLLFile('EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile);
109 }
110 }
111 return TRUE;
112 }
113
114 /**
115 * Returns a modified toolbar order string
116 *
117 * @return string a modified tollbar order list
118 */
119 public function addButtonsToToolbar() {
120 //Add only buttons not yet in the default toolbar order
121 $addButtons = implode(',', array_diff(\TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->pluginButtons, 1), \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->htmlAreaRTE->defaultToolbarOrder, 1)));
122 return ($addButtons ? 'bar,' . $addButtons . ',linebreak,' : '') . $this->htmlAreaRTE->defaultToolbarOrder;
123 }
124
125 /**
126 * Returns the path to the skin component (button icons) that should be added to linked stylesheets
127 *
128 * @return string path to the skin (css) file
129 */
130 public function getPathToSkin() {
131 global $TYPO3_CONF_VARS;
132 if ($TYPO3_CONF_VARS['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['addIconsToSkin']) {
133 return $this->relativePathToSkin;
134 } else {
135 return '';
136 }
137 }
138
139 /**
140 * Return JS configuration of the htmlArea plugins registered by the extension
141 *
142 * @param integer Relative id of the RTE editing area in the form
143 * @return string JS configuration for registered plugins
144 */
145 public function buildJavascriptConfiguration($RTEcounter) {
146 global $TSFE, $LANG;
147 $registerRTEinJavascriptString = '';
148 $pluginButtons = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->pluginButtons, 1);
149 foreach ($pluginButtons as $button) {
150 if (in_array($button, $this->toolbar)) {
151 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][($button . '.')])) {
152 $registerRTEinJavascriptString .= '
153 RTEarea[' . $RTEcounter . '].buttons.' . $button . ' = new Object();';
154 }
155 }
156 }
157 return $registerRTEinJavascriptString;
158 }
159
160 /**
161 * Returns the extension key
162 *
163 * @return string the extension key
164 */
165 public function getExtensionKey() {
166 return $this->extensionKey;
167 }
168
169 /**
170 * Returns the path to the plugin directory, if any
171 *
172 * @return string the full path to the plugin directory
173 */
174 public function getPathToPluginDirectory() {
175 return $this->relativePathToPluginDirectory ? $this->htmlAreaRTE->httpTypo3Path . \TYPO3\CMS\Core\Extension\ExtensionManager::siteRelPath($this->extensionKey) . $this->relativePathToPluginDirectory : '';
176 }
177
178 /**
179 * Returns a boolean indicating whether the plugin adds buttons or not to the toolbar
180 *
181 * @return boolean
182 */
183 public function addsButtons() {
184 return $this->pluginAddsButtons;
185 }
186
187 /**
188 * Returns the list of buttons implemented by the plugin
189 *
190 * @return string the list of buttons implemented by the plugin
191 */
192 public function getPluginButtons() {
193 return $this->pluginButtons;
194 }
195
196 /**
197 * Returns the list of toolbar labels implemented by the plugin
198 *
199 * @return string the list of labels implemented by the plugin
200 */
201 public function getPluginLabels() {
202 return $this->pluginLabels;
203 }
204
205 /**
206 * Returns the conversion array from TYPO3 button names to htmlArea button names
207 *
208 * @return array the conversion array from TYPO3 button names to htmlArea button names
209 */
210 public function getConvertToolbarForHtmlAreaArray() {
211 return $this->convertToolbarForHtmlAreaArray;
212 }
213
214 /**
215 * Returns TRUE if the extension requires the PageTSConfig Classes configuration
216 *
217 * @return boolean TRUE if the extension requires the PageTSConfig Classes configuration
218 */
219 public function requiresClassesConfiguration() {
220 return $this->requiresClassesConfiguration;
221 }
222
223 /**
224 * Returns TRUE if the plugin requires synchronous load
225 *
226 * @return boolean TRUE if the plugin requires synchronous load
227 */
228 public function requiresSynchronousLoad() {
229 return $this->requiresSynchronousLoad;
230 }
231
232 /**
233 * Sets the plugin to require synchronous load or not
234 *
235 * @param boolean $value: the boolean value to set
236 * @return void
237 */
238 public function setSynchronousLoad($value = TRUE) {
239 $this->requiresSynchronousLoad = $value;
240 }
241
242 /**
243 * Returns the list of plugins required by the plugin
244 *
245 * @return string the list of plugins required by the plugin
246 */
247 public function getRequiredPlugins() {
248 return $this->requiredPlugins;
249 }
250
251 }
252
253
254 ?>