Fixed bug #14662: htmlArea RTE: Should use t3lib_utility_Client::getBrowserInfo
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / extensions / TableOperations / class.tx_rtehtmlarea_tableoperations.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008-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 * Table Operations extension for htmlArea RTE
26 *
27 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
28 *
29 * TYPO3 SVN ID: $Id$
30 *
31 */
32
33 require_once(t3lib_extMgm::extPath('rtehtmlarea').'class.tx_rtehtmlareaapi.php');
34
35 class tx_rtehtmlarea_tableoperations extends tx_rtehtmlareaapi {
36
37 protected $extensionKey = 'rtehtmlarea'; // The key of the extension that is extending htmlArea RTE
38 protected $pluginName = 'TableOperations'; // The name of the plugin registered by the extension
39 protected $relativePathToLocallangFile = ''; // Path to this main locallang file of the extension relative to the extension dir.
40 protected $relativePathToSkin = 'extensions/TableOperations/skin/htmlarea.css'; // Path to the skin (css) file relative to the extension dir
41 protected $htmlAreaRTE; // Reference to the invoking object
42 protected $thisConfig; // Reference to RTE PageTSConfig
43 protected $toolbar; // Reference to RTE toolbar array
44 protected $LOCAL_LANG; // Frontend language array
45 protected $requiresClassesConfiguration = true; // True if the registered plugin requires the PageTSConfig Classes configuration
46 protected $requiredPlugins = 'TYPO3Color'; // The comma-separated list of names of prerequisite plugins
47
48 protected $pluginButtons = 'table, toggleborders, tableproperties, tablerestyle, rowproperties, rowinsertabove, rowinsertunder, rowdelete, rowsplit,
49 columnproperties, columninsertbefore, columninsertafter, columndelete, columnsplit,
50 cellproperties, cellinsertbefore, cellinsertafter, celldelete, cellsplit, cellmerge';
51 protected $convertToolbarForHtmlAreaArray = array (
52 'table' => 'InsertTable',
53 'toggleborders' => 'TO-toggle-borders',
54 'tableproperties' => 'TO-table-prop',
55 'tablerestyle' => 'TO-table-restyle',
56 'rowproperties' => 'TO-row-prop',
57 'rowinsertabove' => 'TO-row-insert-above',
58 'rowinsertunder' => 'TO-row-insert-under',
59 'rowdelete' => 'TO-row-delete',
60 'rowsplit' => 'TO-row-split',
61 'columnproperties' => 'TO-col-prop',
62 'columninsertbefore' => 'TO-col-insert-before',
63 'columninsertafter' => 'TO-col-insert-after',
64 'columndelete' => 'TO-col-delete',
65 'columnsplit' => 'TO-col-split',
66 'cellproperties' => 'TO-cell-prop',
67 'cellinsertbefore' => 'TO-cell-insert-before',
68 'cellinsertafter' => 'TO-cell-insert-after',
69 'celldelete' => 'TO-cell-delete',
70 'cellsplit' => 'TO-cell-split',
71 'cellmerge' => 'TO-cell-merge',
72 );
73
74 public function main($parentObject) {
75
76 $available = parent::main($parentObject);
77
78 if ($this->htmlAreaRTE->client['browser'] == 'opera') {
79 $this->thisConfig['hideTableOperationsInToolbar'] = 0;
80 }
81 if ($this->thisConfig['disableSelectColor'] && $this->htmlAreaRTE->client['browser'] != 'gecko') {
82 $this->requiredPlugins = 'DefaultColor';
83 }
84 return $available;
85 }
86
87 /**
88 * Return JS configuration of the htmlArea plugins registered by the extension
89 *
90 * @param integer Relative id of the RTE editing area in the form
91 *
92 * @return string JS configuration for registered plugins, in this case, JS configuration of block elements
93 *
94 * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
95 * Each of the instructions should be of the form:
96 * RTEarea['.$RTEcounter.']["buttons"]["button-id"]["property"] = "value";
97 */
98 public function buildJavascriptConfiguration($RTEcounter) {
99 global $TSFE, $LANG;
100
101 $registerRTEinJavascriptString = '';
102 if (in_array('table', $this->toolbar)) {
103
104 // Combining fieldset disablers as a list
105 $disabledFieldsets = array('Alignment', 'Borders', 'Color', 'Description', 'Layout', 'RowGroup', 'Spacing', 'Style');
106 foreach ($disabledFieldsets as $index => $fieldset) {
107 if (!trim($this->thisConfig['disable'.$fieldset.'FieldsetInTableOperations'])) {
108 unset($disabledFieldsets[$index]);
109 }
110 }
111 $disabledFieldsets = strtolower(implode(',', $disabledFieldsets));
112
113 // Dialogue fieldsets removal configuration
114 if ($disabledFieldsets) {
115 $dialogues = array('table', 'tableproperties', 'rowproperties', 'columnproperties', 'cellproperties');
116 foreach ($dialogues as $dialogue) {
117 if (in_array($dialogue, $this->toolbar)) {
118 if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.'][$dialogue.'.'])) {
119 $registerRTEinJavascriptString .= '
120 RTEarea['.$RTEcounter.'].buttons.'.$dialogue.' = new Object();
121 RTEarea['.$RTEcounter.'].buttons.'.$dialogue.'.removeFieldsets = "' . $disabledFieldsets . '";';
122 } else if ($this->thisConfig['buttons.'][$dialogue.'.']['removeFieldsets']) {
123 $registerRTEinJavascriptString .= '
124 RTEarea['.$RTEcounter.'].buttons.'.$dialogue.'.removeFieldsets += ",' . $disabledFieldsets . '";';
125 } else {
126 $registerRTEinJavascriptString .= '
127 RTEarea['.$RTEcounter.'].buttons.'.$dialogue.'.removeFieldsets = ",' . $disabledFieldsets . '";';
128 }
129 }
130 }
131 }
132
133 $registerRTEinJavascriptString .= '
134 RTEarea['.$RTEcounter.'].hideTableOperationsInToolbar = ' . (trim($this->thisConfig['hideTableOperationsInToolbar']) ? 'true' : 'false') . ';';
135
136 // Deprecated toggleborders button configuration
137 if (in_array('toggleborders',$this->toolbar) && $this->thisConfig['keepToggleBordersInToolbar']) {
138 if (!is_array($this->thisConfig['buttons.']['toggleborders.'])) {
139 $registerRTEinJavascriptString .= '
140 RTEarea['.$RTEcounter.'].buttons.toggleborders = new Object();
141 RTEarea['.$RTEcounter.'].buttons.toggleborders.keepInToolbar = true;';
142 } elseif (!$this->thisConfig['buttons.']['toggleborders.']['keepInToolbar']) {
143 $registerRTEinJavascriptString .= '
144 RTEarea['.$RTEcounter.'].buttons.toggleborders.keepInToolbar = true;';
145 }
146 }
147 }
148 return $registerRTEinJavascriptString;
149 }
150
151
152 /**
153 * Return an updated array of toolbar enabled buttons
154 *
155 * @param array $show: array of toolbar elements that will be enabled, unless modified here
156 *
157 * @return array toolbar button array, possibly updated
158 */
159 public function applyToolbarConstraints($show) {
160 // We will not allow any table operations button if the table button is not enabled
161 if (!in_array('table', $show)) {
162 return array_diff($show, t3lib_div::trimExplode(',', $this->pluginButtons));
163 } else {
164 return $show;
165 }
166 }
167
168 } // end of class
169
170 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/TableOperations/class.tx_rtehtmlarea_tableoperations.php']) {
171 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/TableOperations/class.tx_rtehtmlarea_tableoperations.php']);
172 }
173
174 ?>