Fixed bug #14662: htmlArea RTE: Should use t3lib_utility_Client::getBrowserInfo
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / extensions / CopyPaste / class.tx_rtehtmlarea_copypaste.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008-2009 Stanislas Rolland <typo3(arobas)sjbr.ca>
6 * All rights reserved
7 *
8 * This script is part of the Typo3 project. The Typo3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24 /**
25 * Copy Paste plugin for htmlArea RTE
26 *
27 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
28 *
29 * TYPO3 SVN ID: $Id$
30 *
31 */
32
33 require_once(t3lib_extMgm::extPath('rtehtmlarea').'class.tx_rtehtmlareaapi.php');
34
35 class tx_rtehtmlarea_copypaste extends tx_rtehtmlareaapi {
36
37 protected $extensionKey = 'rtehtmlarea'; // The key of the extension that is extending htmlArea RTE
38 protected $pluginName = 'CopyPaste'; // The name of the plugin registered by the extension
39 protected $relativePathToLocallangFile = ''; // Path to this main locallang file of the extension relative to the extension dir.
40 protected $relativePathToSkin = 'extensions/CopyPaste/skin/htmlarea.css'; // Path to the skin (css) file relative to the extension dir.
41 protected $htmlAreaRTE; // Reference to the invoking object
42 protected $thisConfig; // Reference to RTE PageTSConfig
43 protected $toolbar; // Reference to RTE toolbar array
44 protected $LOCAL_LANG; // Frontend language array
45 protected $pluginButtons = 'copy, cut, paste';
46 protected $convertToolbarForHtmlAreaArray = array (
47 'copy' => 'Copy',
48 'cut' => 'Cut',
49 'paste' => 'Paste',
50 );
51 // Hide buttons not implemented in client browsers
52 protected $hideButtonsFromClient = array (
53 'webkit' => array('paste'),
54 'opera' => array('copy', 'cut', 'paste'),
55 );
56
57 public function main($parentObject) {
58 $enabled = parent::main($parentObject);
59 // Hiding some buttons
60 if ($enabled && is_array($this->hideButtonsFromClient[$this->htmlAreaRTE->client['browser']])) {
61 $this->pluginButtons = implode(',', array_diff(t3lib_div::trimExplode(',', $this->pluginButtons, 1), $this->hideButtonsFromClient[$this->htmlAreaRTE->client['browser']]));
62 }
63 // Force enabling the plugin even if no button remains in the tool bar, so that hot keys still are enabled
64 $this->pluginAddsButtons = false;
65 return $enabled;
66 }
67
68 /**
69 * Return JS configuration of the htmlArea plugins registered by the extension
70 *
71 * @param integer Relative id of the RTE editing area in the form
72 *
73 * @return string JS configuration for registered plugins
74 *
75 * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
76 * Each of the instructions should be of the form:
77 * RTEarea['.$RTEcounter.'].buttons.button-id.property = "value";
78 */
79 public function buildJavascriptConfiguration($RTEcounter) {
80 $registerRTEinJavascriptString = '';
81 $button = 'paste';
82 if ($this->htmlAreaRTE->client['browser'] == 'gecko') {
83 $mozillaAllowClipboardURL = $this->thisConfig['buttons.'][$button.'.']['mozillaAllowClipboardURL'] ? $this->thisConfig['buttons.'][$button.'.']['mozillaAllowClipboardURL'] : $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extensionKey]['plugins']['CopyPaste']['mozillaAllowClipboardURL'];
84 if ($mozillaAllowClipboardURL) {
85 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][$button.'.'])) {
86 $registerRTEinJavascriptString .= '
87 RTEarea['.$RTEcounter.'].buttons.'. $button .' = new Object();';
88 }
89 $registerRTEinJavascriptString .= '
90 RTEarea['.$RTEcounter.'].buttons.'. $button .'.mozillaAllowClipboardURL = "' . $mozillaAllowClipboardURL . '";';
91 }
92 }
93 return $registerRTEinJavascriptString;
94 }
95
96 /**
97 * Return an updated array of toolbar enabled buttons
98 *
99 * @param array $show: array of toolbar elements that will be enabled, unless modified here
100 *
101 * @return array toolbar button array, possibly updated
102 */
103 public function applyToolbarConstraints($show) {
104 // Remove some buttons
105 if (is_array($this->hideButtonsFromClient[$this->htmlAreaRTE->client['browser']])) {
106 return array_diff($show, $this->hideButtonsFromClient[$this->htmlAreaRTE->client['browser']]);
107 } else {
108 return $show;
109 }
110 }
111 }
112
113 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/CopyPaste/class.tx_rtehtmlarea_copypaste.php']) {
114 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/CopyPaste/class.tx_rtehtmlarea_copypaste.php']);
115 }
116 ?>