[TASK] Migrate eID scripts to use PSR-7
[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 // Opera has no onPaste event to handle
56 return parent::main($configuration)
57 && $this->configuration['client']['browser'] !== 'opera';
58 }
59
60 /**
61 * Return JS configuration of the htmlArea plugins registered by the extension
62 *
63 * @return string JS configuration for registered plugins
64 */
65 public function buildJavascriptConfiguration() {
66 $jsArray = array();
67 $button = 'pastebehaviour';
68 // Get current TYPO3 User Setting, if available
69 if (TYPO3_MODE === 'BE' && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('setup') && is_array($GLOBALS['TYPO3_USER_SETTINGS']) && is_object($GLOBALS['BE_USER'])) {
70 if (!is_array($this->configuration['thisConfig']['buttons.']) || !is_array($this->configuration['thisConfig']['buttons.'][($button . '.')])) {
71 $jsArray[] = 'RTEarea[editornumber].buttons.' . $button . ' = new Object();';
72 }
73 $jsArray[] = 'RTEarea[editornumber].buttons.' . $button . '.current = "' . (isset($GLOBALS['BE_USER']->uc['rteCleanPasteBehaviour']) ? $GLOBALS['BE_USER']->uc['rteCleanPasteBehaviour'] : 'plainText') . '";';
74 }
75 return implode(LF, $jsArray);
76 }
77
78 /**
79 * Return an updated array of toolbar enabled buttons
80 *
81 * @param array $show: array of toolbar elements that will be enabled, unless modified here
82 * @return array toolbar button array, possibly updated
83 */
84 public function applyToolbarConstraints($show) {
85 $removeButtons = array();
86 // Remove pastebehaviour button if pastetoggle is not configured
87 if (!in_array('pastetoggle', $show)) {
88 $removeButtons[] = 'pastebehaviour';
89 }
90 // Remove pastebehaviour button if TYPO3 User Settings are available
91 if (TYPO3_MODE === 'BE' && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('setup') && is_array($GLOBALS['TYPO3_USER_SETTINGS']) && is_object($GLOBALS['BE_USER'])) {
92 $removeButtons[] = 'pastebehaviour';
93 }
94 return array_diff($show, $removeButtons);
95 }
96
97 }