[TASK] RTE: Remove unused css files
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / Extension / TableOperations.php
1 <?php
2 namespace TYPO3\CMS\Rtehtmlarea\Extension;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Rtehtmlarea\RteHtmlAreaApi;
19 use TYPO3\CMS\Rtehtmlarea\RteHtmlAreaBase;
20
21 /**
22 * Table Operations extension for htmlArea RTE
23 *
24 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
25 */
26 class TableOperations extends RteHtmlAreaApi {
27
28 /**
29 * The name of the plugin registered by the extension
30 *
31 * @var string
32 */
33 protected $pluginName = 'TableOperations';
34
35 /**
36 * TRUE if the registered plugin requires the PageTSConfig Classes configuration
37 *
38 * @var bool
39 */
40 protected $requiresClassesConfiguration = TRUE;
41
42 /**
43 * The comma-separated list of names of prerequisite plugins
44 *
45 * @var string
46 */
47 protected $requiredPlugins = 'TYPO3Color,BlockStyle';
48
49 /**
50 * The comma-separated list of button names that the registered plugin is adding to the htmlArea RTE toolbar
51 *
52 * @var string
53 */
54 protected $pluginButtons = 'table, toggleborders, tableproperties, tablerestyle, rowproperties, rowinsertabove, rowinsertunder, rowdelete, rowsplit,
55 columnproperties, columninsertbefore, columninsertafter, columndelete, columnsplit,
56 cellproperties, cellinsertbefore, cellinsertafter, celldelete, cellsplit, cellmerge';
57
58 /**
59 * The name-converting array, converting the button names used in the RTE PageTSConfing to the button id's used by the JS scripts
60 *
61 * @var array
62 */
63 protected $convertToolbarForHtmlAreaArray = array(
64 'table' => 'InsertTable',
65 'toggleborders' => 'TO-toggle-borders',
66 'tableproperties' => 'TO-table-prop',
67 'tablerestyle' => 'TO-table-restyle',
68 'rowproperties' => 'TO-row-prop',
69 'rowinsertabove' => 'TO-row-insert-above',
70 'rowinsertunder' => 'TO-row-insert-under',
71 'rowdelete' => 'TO-row-delete',
72 'rowsplit' => 'TO-row-split',
73 'columnproperties' => 'TO-col-prop',
74 'columninsertbefore' => 'TO-col-insert-before',
75 'columninsertafter' => 'TO-col-insert-after',
76 'columndelete' => 'TO-col-delete',
77 'columnsplit' => 'TO-col-split',
78 'cellproperties' => 'TO-cell-prop',
79 'cellinsertbefore' => 'TO-cell-insert-before',
80 'cellinsertafter' => 'TO-cell-insert-after',
81 'celldelete' => 'TO-cell-delete',
82 'cellsplit' => 'TO-cell-split',
83 'cellmerge' => 'TO-cell-merge'
84 );
85
86 /**
87 * Returns TRUE if the plugin is available and correctly initialized
88 *
89 * @param RteHtmlAreaBase $parentObject parent object
90 * @return bool TRUE if this plugin object should be made available in the current environment and is correctly initialized
91 */
92 public function main($parentObject) {
93 $available = parent::main($parentObject);
94 if ($this->htmlAreaRTE->client['browser'] == 'opera') {
95 $this->thisConfig['hideTableOperationsInToolbar'] = 0;
96 }
97 return $available;
98 }
99
100 /**
101 * Return JS configuration of the htmlArea plugins registered by the extension
102 *
103 * @param string $rteNumberPlaceholder A dummy string for JS arrays
104 * @return string JS configuration for registered plugins, in this case, JS configuration of block elements
105 */
106 public function buildJavascriptConfiguration($rteNumberPlaceholder) {
107 $registerRTEinJavascriptString = '';
108 if (in_array('table', $this->toolbar)) {
109 // Combining fieldset disablers as a list
110 $disabledFieldsets = array('Alignment', 'Borders', 'Color', 'Description', 'Layout', 'RowGroup', 'Spacing', 'Style');
111 foreach ($disabledFieldsets as $index => $fieldset) {
112 if (!trim($this->thisConfig[('disable' . $fieldset . 'FieldsetInTableOperations')])) {
113 unset($disabledFieldsets[$index]);
114 }
115 }
116 $disabledFieldsets = strtolower(implode(',', $disabledFieldsets));
117 // Dialogue fieldsets removal configuration
118 if ($disabledFieldsets) {
119 $dialogues = array('table', 'tableproperties', 'rowproperties', 'columnproperties', 'cellproperties');
120 foreach ($dialogues as $dialogue) {
121 if (in_array($dialogue, $this->toolbar)) {
122 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][($dialogue . '.')])) {
123 $registerRTEinJavascriptString .= '
124 RTEarea[' . $rteNumberPlaceholder . '].buttons.' . $dialogue . ' = new Object();
125 RTEarea[' . $rteNumberPlaceholder . '].buttons.' . $dialogue . '.removeFieldsets = "' . $disabledFieldsets . '";';
126 } elseif ($this->thisConfig['buttons.'][$dialogue . '.']['removeFieldsets']) {
127 $registerRTEinJavascriptString .= '
128 RTEarea[' . $rteNumberPlaceholder . '].buttons.' . $dialogue . '.removeFieldsets += ",' . $disabledFieldsets . '";';
129 } else {
130 $registerRTEinJavascriptString .= '
131 RTEarea[' . $rteNumberPlaceholder . '].buttons.' . $dialogue . '.removeFieldsets = ",' . $disabledFieldsets . '";';
132 }
133 }
134 }
135 }
136 $registerRTEinJavascriptString .= '
137 RTEarea[' . $rteNumberPlaceholder . '].hideTableOperationsInToolbar = ' . (trim($this->thisConfig['hideTableOperationsInToolbar']) ? 'true' : 'false') . ';';
138 }
139 return $registerRTEinJavascriptString;
140 }
141
142 /**
143 * Return an updated array of toolbar enabled buttons
144 *
145 * @param array $show: array of toolbar elements that will be enabled, unless modified here
146 * @return array toolbar button array, possibly updated
147 */
148 public function applyToolbarConstraints($show) {
149 // We will not allow any table operations button if the table button is not enabled
150 if (!in_array('table', $show)) {
151 return array_diff($show, GeneralUtility::trimExplode(',', $this->pluginButtons));
152 } else {
153 return $show;
154 }
155 }
156
157 }