* Added feature #7667: htmlArea RTE: Usability improvements in table operations
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / extensions / TableOperations / class.tx_rtehtmlarea_tableoperations.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008 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 * Table Operations extension for htmlArea RTE
26 *
27 * @author Stanislas Rolland <stanislas.rolland(arobas)fructifor.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
47 protected $pluginButtons = 'table, toggleborders, tableproperties, tablerestyle, rowproperties, rowinsertabove, rowinsertunder, rowdelete, rowsplit,
48 columnproperties, columninsertbefore, columninsertafter, columndelete, columnsplit,
49 cellproperties, cellinsertbefore, cellinsertafter, celldelete, cellsplit, cellmerge';
50 protected $convertToolbarForHtmlAreaArray = array (
51 'table' => 'InsertTable',
52 'toggleborders' => 'TO-toggle-borders',
53 'tableproperties' => 'TO-table-prop',
54 'tablerestyle' => 'TO-table-restyle',
55 'rowproperties' => 'TO-row-prop',
56 'rowinsertabove' => 'TO-row-insert-above',
57 'rowinsertunder' => 'TO-row-insert-under',
58 'rowdelete' => 'TO-row-delete',
59 'rowsplit' => 'TO-row-split',
60 'columnproperties' => 'TO-col-prop',
61 'columninsertbefore' => 'TO-col-insert-before',
62 'columninsertafter' => 'TO-col-insert-after',
63 'columndelete' => 'TO-col-delete',
64 'columnsplit' => 'TO-col-split',
65 'cellproperties' => 'TO-cell-prop',
66 'cellinsertbefore' => 'TO-cell-insert-before',
67 'cellinsertafter' => 'TO-cell-insert-after',
68 'celldelete' => 'TO-cell-delete',
69 'cellsplit' => 'TO-cell-split',
70 'cellmerge' => 'TO-cell-merge',
71 );
72
73 public function main($parentObject) {
74 global $TYPO3_CONF_VARS;
75
76 $available = parent::main($parentObject);
77
78 if ($this->htmlAreaRTE->client['BROWSER'] == 'opera') {
79 $this->thisConfig['hideTableOperationsInToolbar'] = 0;
80 }
81
82 return $available;
83 }
84
85 /**
86 * Return JS configuration of the htmlArea plugins registered by the extension
87 *
88 * @param integer Relative id of the RTE editing area in the form
89 *
90 * @return string JS configuration for registered plugins, in this case, JS configuration of block elements
91 *
92 * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
93 * Each of the instructions should be of the form:
94 * RTEarea['.$RTEcounter.']["buttons"]["button-id"]["property"] = "value";
95 */
96 public function buildJavascriptConfiguration($RTEcounter) {
97 global $TSFE, $LANG;
98
99 $registerRTEinJavascriptString = '';
100 if (in_array('table', $this->toolbar)) {
101
102 // Combining fieldset disablers as a list
103 $disabledFieldsets = array('Alignment', 'Borders', 'Color', 'Description', 'Layout', 'RowGroup', 'Spacing', 'Style');
104 foreach ($disabledFieldsets as $index => $fieldset) {
105 if (!trim($this->thisConfig['disable'.$fieldset.'FieldsetInTableOperations'])) {
106 unset($disabledFieldsets[$index]);
107 }
108 }
109 $disabledFieldsets = strtolower(implode(',', $disabledFieldsets));
110
111 // Dialogue fieldsets removal configuration
112 $dialogues = array('table', 'tableproperties', 'rowproperties', 'columnproperties', 'cellproperties');
113 foreach ($dialogues as $dialogue) {
114 if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.'][$dialogue.'.'])) {
115 $registerRTEinJavascriptString .= '
116 RTEarea['.$RTEcounter.'].buttons.'.$dialogue.' = new Object();
117 RTEarea['.$RTEcounter.'].buttons.'.$dialogue.'.removeFieldsets = "' . $disabledFieldsets . '";';
118 } else if ($this->thisConfig['buttons.'][$dialogue.'.']['removeFieldsets']) {
119 $registerRTEinJavascriptString .= '
120 RTEarea['.$RTEcounter.'].buttons.'.$dialogue.'.removeFieldsets += ",' . $disabledFieldsets . '";';
121 } else {
122 $registerRTEinJavascriptString .= '
123 RTEarea['.$RTEcounter.'].buttons.'.$dialogue.'.removeFieldsets = ",' . $disabledFieldsets . '";';
124 }
125 }
126
127 $registerRTEinJavascriptString .= '
128 RTEarea['.$RTEcounter.'].hideTableOperationsInToolbar = ' . (trim($this->thisConfig['hideTableOperationsInToolbar']) ? 'true' : 'false') . ';';
129
130 // Deprecated toggleborders button configuration
131 if (in_array('toggleborders',$this->toolbar) && $this->thisConfig['keepToggleBordersInToolbar']) {
132 if (!is_array($this->thisConfig['buttons.']['toggleborders.'])) {
133 $registerRTEinJavascriptString .= '
134 RTEarea['.$RTEcounter.'].buttons.toggleborders = new Object();
135 RTEarea['.$RTEcounter.'].buttons.toggleborders.keepInToolbar = true;';
136 } elseif (!$this->thisConfig['buttons.']['toggleborders.']['keepInToolbar']) {
137 $registerRTEinJavascriptString .= '
138 RTEarea['.$RTEcounter.'].buttons.toggleborders.keepInToolbar = true;';
139 }
140 }
141 }
142 return $registerRTEinJavascriptString;
143 }
144
145 } // end of class
146
147 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/TableOperations/class.tx_rtehtmlarea_tableoperations.php']) {
148 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/TableOperations/class.tx_rtehtmlarea_tableoperations.php']);
149 }
150
151 ?>