[TASK] Remove unneeded parenthesis on array-access
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / Extension / Plaintext.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\Rtehtmlarea\RteHtmlAreaApi;
18
19 /**
20 * Copy as Plain Text extension for htmlArea RTE
21 */
22 class Plaintext extends RteHtmlAreaApi
23 {
24 /**
25 * The name of the plugin registered by the extension
26 *
27 * @var string
28 */
29 protected $pluginName = 'PlainText';
30
31 /**
32 * The comma-separated list of button names that the registered plugin is adding to the htmlArea RTE toolbar
33 *
34 * @var string
35 */
36 protected $pluginButtons = 'pastetoggle,pastebehaviour';
37
38 /**
39 * The name-converting array, converting the button names used in the RTE PageTSConfing to the button id's used by the JS scripts
40 *
41 * @var array
42 */
43 protected $convertToolbarForHtmlAreaArray = array(
44 'pastetoggle' => 'PasteToggle',
45 'pastebehaviour' => 'PasteBehaviour'
46 );
47
48 /**
49 * Returns TRUE if the plugin is available and correctly initialized
50 *
51 * @param array $configuration Configuration array given from calling object down to the single plugins
52 * @return bool TRUE if this plugin object should be made available in the current environment and is correctly initialized
53 */
54 public function main(array $configuration)
55 {
56 // Opera has no onPaste event to handle
57 return parent::main($configuration)
58 && $this->configuration['client']['browser'] !== 'opera';
59 }
60
61 /**
62 * Return JS configuration of the htmlArea plugins registered by the extension
63 *
64 * @return string JS configuration for registered plugins
65 */
66 public function buildJavascriptConfiguration()
67 {
68 $jsArray = array();
69 $button = 'pastebehaviour';
70 // Get current TYPO3 User Setting, if available
71 if (TYPO3_MODE === 'BE' && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('setup') && is_array($GLOBALS['TYPO3_USER_SETTINGS']) && is_object($GLOBALS['BE_USER'])) {
72 if (!is_array($this->configuration['thisConfig']['buttons.']) || !is_array($this->configuration['thisConfig']['buttons.'][$button . '.'])) {
73 $jsArray[] = 'RTEarea[editornumber].buttons.' . $button . ' = new Object();';
74 }
75 $jsArray[] = 'RTEarea[editornumber].buttons.' . $button . '.current = "' . (isset($GLOBALS['BE_USER']->uc['rteCleanPasteBehaviour']) ? $GLOBALS['BE_USER']->uc['rteCleanPasteBehaviour'] : 'plainText') . '";';
76 }
77 return implode(LF, $jsArray);
78 }
79
80 /**
81 * Return an updated array of toolbar enabled buttons
82 *
83 * @param array $show: array of toolbar elements that will be enabled, unless modified here
84 * @return array toolbar button array, possibly updated
85 */
86 public function applyToolbarConstraints($show)
87 {
88 $removeButtons = array();
89 // Remove pastebehaviour button if pastetoggle is not configured
90 if (!in_array('pastetoggle', $show)) {
91 $removeButtons[] = 'pastebehaviour';
92 }
93 // Remove pastebehaviour button if TYPO3 User Settings are available
94 if (TYPO3_MODE === 'BE' && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('setup') && is_array($GLOBALS['TYPO3_USER_SETTINGS']) && is_object($GLOBALS['BE_USER'])) {
95 $removeButtons[] = 'pastebehaviour';
96 }
97 return array_diff($show, $removeButtons);
98 }
99 }