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