[TASK] Remove dependency to $this->formEngine->RTEcounter
[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 /**
18 * Copy as Plain Text extension for htmlArea RTE
19 *
20 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
21 */
22 class Plaintext extends \TYPO3\CMS\Rtehtmlarea\RteHtmlAreaApi {
23
24 /**
25 * The key of the extension that is extending htmlArea RTE
26 *
27 * @var string
28 */
29 protected $extensionKey = 'rtehtmlarea';
30
31 /**
32 * The name of the plugin registered by the extension
33 *
34 * @var string
35 */
36 protected $pluginName = 'PlainText';
37
38 /**
39 * Path to this main locallang file of the extension relative to the extension directory
40 *
41 * @var string
42 */
43 protected $relativePathToLocallangFile = '';
44
45 /**
46 * Path to the skin file relative to the extension directory
47 *
48 * @var string
49 */
50 protected $relativePathToSkin = 'Resources/Public/Css/Skin/Plugins/plain-text.css';
51
52 /**
53 * Reference to the invoking object
54 *
55 * @var \TYPO3\CMS\Rtehtmlarea\RteHtmlAreaBase
56 */
57 protected $htmlAreaRTE;
58
59 protected $thisConfig;
60
61 // Reference to RTE PageTSConfig
62 protected $toolbar;
63
64 // Reference to RTE toolbar array
65 protected $LOCAL_LANG;
66
67 // Frontend language array
68 protected $pluginButtons = 'pastetoggle,pastebehaviour';
69
70 protected $convertToolbarForHtmlAreaArray = array(
71 'pastetoggle' => 'PasteToggle',
72 'pastebehaviour' => 'PasteBehaviour'
73 );
74
75 public function main($parentObject) {
76 // Opera has no onPaste event to handle
77 return parent::main($parentObject) && $this->htmlAreaRTE->client['browser'] != 'opera';
78 }
79
80 /**
81 * Return JS configuration of the htmlArea plugins registered by the extension
82 *
83 * @param string $rteNumberPlaceholder A dummy string for JS arrays
84 * @return string JS configuration for registered plugins
85 */
86 public function buildJavascriptConfiguration($rteNumberPlaceholder) {
87 $registerRTEinJavascriptString = '';
88 $button = 'pastebehaviour';
89 // Get current TYPO3 User Setting, if available
90 if (TYPO3_MODE === 'BE' && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('setup') && is_array($GLOBALS['TYPO3_USER_SETTINGS']) && is_object($GLOBALS['BE_USER'])) {
91 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][($button . '.')])) {
92 $registerRTEinJavascriptString .= '
93 RTEarea[' . $rteNumberPlaceholder . '].buttons.' . $button . ' = new Object();';
94 }
95 $registerRTEinJavascriptString .= '
96 RTEarea[' . $rteNumberPlaceholder . '].buttons.' . $button . '.current = "' . (isset($GLOBALS['BE_USER']->uc['rteCleanPasteBehaviour']) ? $GLOBALS['BE_USER']->uc['rteCleanPasteBehaviour'] : 'plainText') . '";';
97 }
98 return $registerRTEinJavascriptString;
99 }
100
101 /**
102 * Return an updated array of toolbar enabled buttons
103 *
104 * @param array $show: array of toolbar elements that will be enabled, unless modified here
105 * @return array toolbar button array, possibly updated
106 */
107 public function applyToolbarConstraints($show) {
108 $removeButtons = array();
109 // Remove pastebehaviour button if pastetoggle is not configured
110 if (!in_array('pastetoggle', $show)) {
111 $removeButtons[] = 'pastebehaviour';
112 }
113 // Remove pastebehaviour button if TYPO3 User Settings are available
114 if (TYPO3_MODE === 'BE' && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('setup') && is_array($GLOBALS['TYPO3_USER_SETTINGS']) && is_object($GLOBALS['BE_USER'])) {
115 $removeButtons[] = 'pastebehaviour';
116 }
117 return array_diff($show, $removeButtons);
118 }
119
120 }