Updated Copyright notices
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / class.tx_rtehtmlareaapi.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007 Stanislas Rolland <stanislas.rolland(arobas)fructifor.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 <stanislas.rolland(arobas)fructifor.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 $htmlAreaRTE; // Reference to the invoking object
42 protected $rteExtensionKey; // The extension key of the RTE
43 protected $thisConfig; // Reference to RTE PageTSConfig
44 protected $toolbar; // Refrence to RTE toolbar array
45 protected $LOCAL_LANG; // Frontend language array
46 protected $pluginButtons = ''; // The comma-separated list of button names that the registered plugin is adding to the htmlArea RTE toolbar
47 protected $pluginLabels = ''; // The comma-separated list of label names that the registered plugin is adding to the htmlArea RTE toolbar
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
51 /**
52 * Returns true if the plugin is available and correctly initialized
53 *
54 * @param object Reference to parent object, which is an instance of the htmlArea RTE
55 *
56 * @return boolean true if this plugin object should be made available in the current environment and is correctly initialized
57 */
58 public function main($parentObject) {
59 global $TYPO3_CONF_VARS, $LANG, $TSFE;
60
61 $this->htmlAreaRTE =& $parentObject;
62 $this->rteExtensionKey =& $this->htmlAreaRTE->ID;
63 $this->thisConfig =& $this->htmlAreaRTE->thisConfig;
64 $this->toolbar =& $this->htmlAreaRTE->toolbar;
65 $this->LOCAL_LANG =& $this->htmlAreaRTE->LOCAL_LANG;
66
67 // Check if the plugin should be disabled in frontend
68 if ($this->htmlAreaRTE->is_FE() && $TYPO3_CONF_VARS['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['disableInFE']) {
69 return false;
70 }
71 // Localization array must be initialized here
72 if ($this->relativePathToLocallangFile) {
73 if ($this->htmlAreaRTE->is_FE()) {
74 $this->LOCAL_LANG = t3lib_div::array_merge_recursive_overrule($this->LOCAL_LANG, t3lib_div::readLLfile('EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile, $this->htmlAreaRTE->language));
75 } else {
76 $LANG->includeLLFile('EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile);
77 }
78 }
79 return true;
80 }
81
82 /**
83 * Returns a modified toolbar order string
84 *
85 * @return string a modified tollbar order list
86 */
87 public function addButtonsToToolbar() {
88 //Add only buttons not yet in the default toolbar order
89 $addButtons = implode(',', array_diff(t3lib_div::trimExplode(',', $this->pluginButtons, 1), t3lib_div::trimExplode(',', $this->htmlAreaRTE->defaultToolbarOrder, 1)));
90 return (($addButtons ? ('bar,' . $addButtons . ',linebreak,') : '') . $this->htmlAreaRTE->defaultToolbarOrder);
91 }
92
93 /**
94 * Returns the path to the skin component (button icons) that should be added to linked stylesheets
95 *
96 * @return string path to the skin (css) file
97 */
98 public function getPathToSkin() {
99 global $TYPO3_CONF_VARS;
100 if ($TYPO3_CONF_VARS['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['addIconsToSkin']) {
101 return $this->relativePathToSkin;
102 } else {
103 return '';
104 }
105 }
106
107 /**
108 * Return JS configuration of the htmlArea plugins registered by the extension
109 *
110 * @param integer Relative id of the RTE editing area in the form
111 *
112 * @return string JS configuration for registered plugins
113 *
114 * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
115 * Each of the instructions should be of the form:
116 * RTEarea['.$RTEcounter.']["buttons"]["button-id"]["property"] = "value";
117 */
118 public function buildJavascriptConfiguration($RTEcounter) {
119 global $TSFE, $LANG;
120
121 $registerRTEinJavascriptString = '';
122 $pluginButtons = t3lib_div::trimExplode(',', $this->pluginButtons, 1);
123 foreach ($pluginButtons as $button) {
124 if (in_array($button, $this->toolbar)) {
125 if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.'][$button.'.'])) {
126 $registerRTEinJavascriptString .= '
127 RTEarea['.$RTEcounter.']["buttons"]["'. $button .'"] = new Object();';
128 }
129 }
130 }
131 return $registerRTEinJavascriptString;
132 }
133
134 /**
135 * Returns the extension key
136 *
137 * @return string the extension key
138 */
139 public function getExtensionKey() {
140 return $this->extensionKey;
141 }
142
143 /**
144 * Returns the list of buttons implemented by the plugin
145 *
146 * @return string the list of buttons implemented by the plugin
147 */
148 public function getPluginButtons() {
149 return $this->pluginButtons;
150 }
151
152 /**
153 * Returns the list of toolbar labels implemented by the plugin
154 *
155 * @return string the list of labels implemented by the plugin
156 */
157 public function getPluginLabels() {
158 return $this->pluginLabels;
159 }
160
161 /**
162 * Returns the conversion array from TYPO3 button names to htmlArea button names
163 *
164 * @return array the conversion array from TYPO3 button names to htmlArea button names
165 */
166 public function getConvertToolbarForHtmlAreaArray() {
167 return $this->convertToolbarForHtmlAreaArray;
168 }
169
170 /**
171 * Returns true if the extension requires the PageTSConfig Classes configuration
172 *
173 * @return boolean true if the extension requires the PageTSConfig Classes configuration
174 */
175 public function requiresClassesConfiguration() {
176 return $this->requiresClassesConfiguration;
177 }
178
179 } // end of class
180
181 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/class.tx_rtehtmlareaapi.php']) {
182 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/class.tx_rtehtmlareaapi.php']);
183 }
184
185 ?>