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