[TASK] Remove unneeded parenthesis on array-access
[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
20 /**
21 * Table Operations extension for htmlArea RTE
22 */
23 class TableOperations extends RteHtmlAreaApi
24 {
25 /**
26 * The name of the plugin registered by the extension
27 *
28 * @var string
29 */
30 protected $pluginName = 'TableOperations';
31
32 /**
33 * The comma-separated list of names of prerequisite plugins
34 *
35 * @var string
36 */
37 protected $requiredPlugins = 'TYPO3Color,BlockStyle';
38
39 /**
40 * The comma-separated list of button names that the registered plugin is adding to the htmlArea RTE toolbar
41 *
42 * @var string
43 */
44 protected $pluginButtons = 'table, toggleborders, tableproperties, tablerestyle, rowproperties, rowinsertabove, rowinsertunder, rowdelete, rowsplit,
45 columnproperties, columninsertbefore, columninsertafter, columndelete, columnsplit,
46 cellproperties, cellinsertbefore, cellinsertafter, celldelete, cellsplit, cellmerge';
47
48 /**
49 * The name-converting array, converting the button names used in the RTE PageTSConfing to the button id's used by the JS scripts
50 *
51 * @var array
52 */
53 protected $convertToolbarForHtmlAreaArray = array(
54 'table' => 'InsertTable',
55 'toggleborders' => 'TO-toggle-borders',
56 'tableproperties' => 'TO-table-prop',
57 'tablerestyle' => 'TO-table-restyle',
58 'rowproperties' => 'TO-row-prop',
59 'rowinsertabove' => 'TO-row-insert-above',
60 'rowinsertunder' => 'TO-row-insert-under',
61 'rowdelete' => 'TO-row-delete',
62 'rowsplit' => 'TO-row-split',
63 'columnproperties' => 'TO-col-prop',
64 'columninsertbefore' => 'TO-col-insert-before',
65 'columninsertafter' => 'TO-col-insert-after',
66 'columndelete' => 'TO-col-delete',
67 'columnsplit' => 'TO-col-split',
68 'cellproperties' => 'TO-cell-prop',
69 'cellinsertbefore' => 'TO-cell-insert-before',
70 'cellinsertafter' => 'TO-cell-insert-after',
71 'celldelete' => 'TO-cell-delete',
72 'cellsplit' => 'TO-cell-split',
73 'cellmerge' => 'TO-cell-merge'
74 );
75
76 /**
77 * Returns TRUE if the plugin is available and correctly initialized
78 *
79 * @param array $configuration Configuration array given from calling object down to the single plugins
80 * @return bool TRUE if this plugin object should be made available in the current environment and is correctly initialized
81 */
82 public function main(array $configuration)
83 {
84 $available = parent::main($configuration);
85 if ($this->configuration['client']['browser'] === 'opera') {
86 $this->configuration['thisConfig']['hideTableOperationsInToolbar'] = 0;
87 }
88 return $available;
89 }
90
91 /**
92 * Return JS configuration of the htmlArea plugins registered by the extension
93 *
94 * @return string JS configuration for registered plugins, in this case, JS configuration of block elements
95 */
96 public function buildJavascriptConfiguration()
97 {
98 $jsArray = array();
99 if (in_array('table', $this->toolbar)) {
100 // Combining fieldset disablers as a list
101 $disabledFieldsets = array('Alignment', 'Borders', 'Color', 'Description', 'Layout', 'RowGroup', 'Spacing', 'Style');
102 foreach ($disabledFieldsets as $index => $fieldset) {
103 if (!trim($this->configuration['thisConfig']['disable' . $fieldset . 'FieldsetInTableOperations'])) {
104 unset($disabledFieldsets[$index]);
105 }
106 }
107 $disabledFieldsets = strtolower(implode(',', $disabledFieldsets));
108 // Dialogue fieldsets removal configuration
109 if ($disabledFieldsets) {
110 $dialogues = array('table', 'tableproperties', 'rowproperties', 'columnproperties', 'cellproperties');
111 foreach ($dialogues as $dialogue) {
112 if (in_array($dialogue, $this->toolbar)) {
113 if (!is_array($this->configuration['thisConfig']['buttons.']) || !is_array($this->configuration['thisConfig']['buttons.'][$dialogue . '.'])) {
114 $jsArray[] = 'RTEarea[editornumber].buttons.' . $dialogue . ' = new Object();';
115 $jsArray[] = 'RTEarea[editornumber].buttons.' . $dialogue . '.removeFieldsets = "' . $disabledFieldsets . '";';
116 } elseif ($this->configuration['thisConfig']['buttons.'][$dialogue . '.']['removeFieldsets']) {
117 $jsArray[] = 'RTEarea[editornumber].buttons.' . $dialogue . '.removeFieldsets += ",' . $disabledFieldsets . '";';
118 } else {
119 $jsArray[] = 'RTEarea[editornumber].buttons.' . $dialogue . '.removeFieldsets = ",' . $disabledFieldsets . '";';
120 }
121 }
122 }
123 }
124 $jsArray[] = 'RTEarea[editornumber].hideTableOperationsInToolbar = ' . (trim($this->configuration['thisConfig']['hideTableOperationsInToolbar']) ? 'true' : 'false') . ';';
125 }
126 return implode(LF, $jsArray);
127 }
128
129 /**
130 * Return an updated array of toolbar enabled buttons
131 *
132 * @param array $show: array of toolbar elements that will be enabled, unless modified here
133 * @return array toolbar button array, possibly updated
134 */
135 public function applyToolbarConstraints($show)
136 {
137 // We will not allow any table operations button if the table button is not enabled
138 if (!in_array('table', $show)) {
139 return array_diff($show, GeneralUtility::trimExplode(',', $this->pluginButtons));
140 } else {
141 return $show;
142 }
143 }
144 }