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