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