[TASK] Remove closing PHP tags
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / Extension / Plaintext.php
1 <?php
2 namespace TYPO3\CMS\Rtehtmlarea\Extension;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Stanislas Rolland <typo3(arobas)sjbr.ca>
8 * All rights reserved
9 *
10 * This script is part of the Typo3 project. The Typo3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Copy as Plain Text extension for htmlArea RTE
28 *
29 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
30 */
31 class Plaintext extends \TYPO3\CMS\Rtehtmlarea\RteHtmlAreaApi {
32
33 protected $extensionKey = 'rtehtmlarea';
34
35 // The key of the extension that is extending htmlArea RTE
36 protected $pluginName = 'PlainText';
37
38 // The name of the plugin registered by the extension
39 protected $relativePathToLocallangFile = '';
40
41 // Path to this main locallang file of the extension relative to the extension dir.
42 protected $relativePathToSkin = 'extensions/PlainText/skin/htmlarea.css';
43
44 // Path to the skin (css) file relative to the extension dir
45 protected $htmlAreaRTE;
46
47 // Reference to the invoking object
48 protected $thisConfig;
49
50 // Reference to RTE PageTSConfig
51 protected $toolbar;
52
53 // Reference to RTE toolbar array
54 protected $LOCAL_LANG;
55
56 // Frontend language array
57 protected $pluginButtons = 'pastetoggle,pastebehaviour';
58
59 protected $convertToolbarForHtmlAreaArray = array(
60 'pastetoggle' => 'PasteToggle',
61 'pastebehaviour' => 'PasteBehaviour'
62 );
63
64 public function main($parentObject) {
65 // Opera has no onPaste event to handle
66 return parent::main($parentObject) && $this->htmlAreaRTE->client['browser'] != 'opera';
67 }
68
69 /**
70 * Return JS configuration of the htmlArea plugins registered by the extension
71 *
72 * @param integer Relative id of the RTE editing area in the form
73 * @return string JS configuration for registered plugins
74 */
75 public function buildJavascriptConfiguration($RTEcounter) {
76 $registerRTEinJavascriptString = '';
77 $button = 'pastebehaviour';
78 // Get current TYPO3 User Setting, if available
79 if (TYPO3_MODE === 'BE' && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('setup') && is_array($GLOBALS['TYPO3_USER_SETTINGS']) && is_object($GLOBALS['BE_USER'])) {
80 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][($button . '.')])) {
81 $registerRTEinJavascriptString .= '
82 RTEarea[' . $RTEcounter . '].buttons.' . $button . ' = new Object();';
83 }
84 $registerRTEinJavascriptString .= '
85 RTEarea[' . $RTEcounter . '].buttons.' . $button . '.current = "' . (isset($GLOBALS['BE_USER']->uc['rteCleanPasteBehaviour']) ? $GLOBALS['BE_USER']->uc['rteCleanPasteBehaviour'] : 'plainText') . '";';
86 }
87 return $registerRTEinJavascriptString;
88 }
89
90 /**
91 * Return an updated array of toolbar enabled buttons
92 *
93 * @param array $show: array of toolbar elements that will be enabled, unless modified here
94 * @return array toolbar button array, possibly updated
95 */
96 public function applyToolbarConstraints($show) {
97 $removeButtons = array();
98 // Remove pastebehaviour button if pastetoggle is not configured
99 if (!in_array('pastetoggle', $show)) {
100 $removeButtons[] = 'pastebehaviour';
101 }
102 // Remove pastebehaviour button if TYPO3 User Settings are available
103 if (TYPO3_MODE === 'BE' && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('setup') && is_array($GLOBALS['TYPO3_USER_SETTINGS']) && is_object($GLOBALS['BE_USER'])) {
104 $removeButtons[] = 'pastebehaviour';
105 }
106 return array_diff($show, $removeButtons);
107 }
108
109 }