Added feature #7970: htmlARea RTE: fontstyle and fontsize should not use deprecated...
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / extensions / SelectFont / class.tx_rtehtmlarea_selectfont.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008 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 * SelectFont extension for htmlArea RTE
26 *
27 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
28 *
29 * TYPO3 SVN ID: $Id: class.tx_rtehtmlarea_selectfont.php $
30 *
31 */
32
33 require_once(t3lib_extMgm::extPath('rtehtmlarea').'class.tx_rtehtmlareaapi.php');
34
35 class tx_rtehtmlarea_selectfont extends tx_rtehtmlareaapi {
36
37 protected $extensionKey = 'rtehtmlarea'; // The key of the extension that is extending htmlArea RTE
38 protected $pluginName = 'SelectFont'; // The name of the plugin registered by the extension
39 protected $relativePathToLocallangFile = 'extensions/SelectFont/locallang.xml'; // Path to this main locallang file of the extension relative to the extension dir.
40 protected $relativePathToSkin = ''; // 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
46 protected $pluginButtons = 'fontstyle,fontsize';
47 protected $convertToolbarForHtmlAreaArray = array (
48 'fontstyle' => 'FontName',
49 'fontsize' => 'FontSize',
50 );
51
52 protected $defaultFont = array(
53 'fontstyle' => array(
54 'Arial' => 'Arial,sans-serif',
55 'Arial Black' => '\'Arial Black\',sans-serif',
56 'Verdana' => 'Verdana,Arial,sans-serif',
57 'Times New Roman' => '\'Times New Roman\',Times,serif',
58 'Garamond' => 'Garamond',
59 'Lucida Handwriting' => '\'Lucida Handwriting\'',
60 'Courier' => 'Courier',
61 'Webdings' => 'Webdings',
62 'Wingdings' => 'Wingdings',
63 ),
64 'fontsize' => array(
65 'Extra small' => 'xx-small',
66 'Very small' => 'x-small',
67 'Small' => 'small',
68 'Medium' => 'medium',
69 'Large' => 'large',
70 'Very large' => 'x-large',
71 'Extra large' => 'xx-large',
72 ),
73 );
74
75 protected $RTEProperties;
76
77 public function main($parentObject) {
78 $enabled = parent::main($parentObject) && $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['allowStyleAttribute'];
79 if ($this->htmlAreaRTE->is_FE()) {
80 $this->RTEProperties = $this->htmlAreaRTE->RTEsetup;
81 } else {
82 $this->RTEProperties = $this->htmlAreaRTE->RTEsetup['properties'];
83 }
84 return $enabled;
85 }
86
87 /**
88 * Return JS configuration of the htmlArea plugins registered by the extension
89 *
90 * @param integer Relative id of the RTE editing area in the form
91 *
92 * @return string JS configuration for registered plugins
93 *
94 * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
95 * Each of the instructions should be of the form:
96 * RTEarea['.$RTEcounter.']["buttons"]["button-id"]["property"] = "value";
97 */
98 public function buildJavascriptConfiguration($RTEcounter) {
99 $registerRTEinJavascriptString = '';
100 $pluginButtonsArray = t3lib_div::trimExplode(",", $this->pluginButtons);
101
102 // Process Page TSConfig configuration for each button
103 foreach ($pluginButtonsArray as $buttonId) {
104 if (in_array($buttonId, $this->toolbar)) {
105 $registerRTEinJavascriptString .= $this->buildJSFontItemsConfig($RTEcounter, $buttonId);
106 }
107 }
108 return $registerRTEinJavascriptString;
109 }
110
111 /**
112 * Return Javascript configuration of font faces
113 *
114 * @param integer $RTEcounter: The index number of the current RTE editing area within the form.
115 * @param string $buttonId: button id
116 *
117 * @return string Javascript configuration of font faces
118 */
119 protected function buildJSFontItemsConfig($RTEcounter, $buttonId) {
120 $configureRTEInJavascriptString = '';
121
122 // Getting removal and addition configuration
123 $hideItems = $this->htmlAreaRTE->cleanList($this->thisConfig['hideFont' . (($buttonId == 'fontstyle') ? 'Faces' : 'Sizes')]);
124 $addItems = $this->htmlAreaRTE->cleanList($this->thisConfig[($buttonId == 'fontstyle') ? 'fontFace' : 'fontSize']);
125 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.'][$buttonId])) {
126 if ($this->thisConfig['buttons.'][$buttonId]['removeItems']) {
127 $hideItems = $this->thisConfig['buttons.'][$buttonId]['removeItems'];
128 }
129 if ($this->thisConfig['buttons.'][$buttonId]['addItems']) {
130 $addItems = $this->thisConfig['buttons.'][$buttonId]['addItems'];
131 }
132 }
133 // Initializing the items array
134 $items = array();
135 if ($this->htmlAreaRTE->is_FE()) {
136 $items['none'] = '
137 "' . $GLOBALS['TSFE']->getLLL((($buttonId == 'fontstyle') ? 'No font' : 'No size'), $this->LOCAL_LANG) . '" : ""';
138 } else {
139 $items['none'] = '
140 "' . $GLOBALS['LANG']->getLL(($buttonId == 'fontstyle') ? 'No font' : 'No size') . '" : ""';
141 }
142 $defaultItems = 'none,';
143
144 // Inserting and localizing default items
145 if ($hideItems != '*') {
146 $index = 0;
147 foreach ($this->defaultFont[$buttonId] as $name => $value) {
148 if (!t3lib_div::inList($hideItems, $index+1)) {
149 if ($this->htmlAreaRTE->is_FE()) {
150 $label = $GLOBALS['TSFE']->getLLL($name,$this->LOCAL_LANG);
151 } else {
152 $label = $GLOBALS['LANG']->getLL($name);
153 }
154 $items[$name] = '
155 "' . $name . '" : "' . $this->htmlAreaRTE->cleanList($value) . '"';
156 $defaultItems .= $name . ',';
157 }
158 $index++;
159 }
160 }
161 // Adding configured items
162 if (is_array($this->RTEProperties[($buttonId == 'fontstyle') ? 'fonts.' : 'fontSizes.'])) {
163 foreach ($this->RTEProperties[($buttonId == 'fontstyle') ? 'fonts.' : 'fontSizes.'] as $name => $conf) {
164 $name = substr($name,0,-1);
165 $label = $this->htmlAreaRTE->getPageConfigLabel($conf['name'],0);
166 $items[$name] = '
167 "' . $label . '" : "' . $this->htmlAreaRTE->cleanList($conf['value']) . '"';
168 }
169 }
170 // Setting the JS list of options
171 $JSOptions = '';
172 $configuredItems = t3lib_div::trimExplode(',' , $this->htmlAreaRTE->cleanList($defaultItems . ',' . $addItems));
173 $index = 0;
174 foreach ($configuredItems as $name) {
175 $JSOptions .= ($index ? ',' : '') . $items[$name];
176 $index++;
177 }
178 $JSOptions = '{'
179 . $JSOptions . '
180 };';
181
182 // Adding to button JS configuration
183 if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.'][$buttonId.'.'])) {
184 $configureRTEInJavascriptString .= '
185 RTEarea['.$RTEcounter.'].buttons.'. $buttonId .' = new Object();';
186 }
187 $configureRTEInJavascriptString .= '
188 RTEarea['.$RTEcounter.'].buttons.'. $buttonId .'.options = '. $JSOptions;
189
190 return $configureRTEInJavascriptString;
191 }
192 } // end of class
193
194 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/SelectFont/class.tx_rtehtmlarea_selectfont.php']) {
195 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/SelectFont/class.tx_rtehtmlarea_selectfont.php']);
196 }
197 ?>