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