Fixed bug #14737: htmlArea RTE: Missing labels for SelectFont extension
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / extensions / DefaultFont / class.tx_rtehtmlarea_defaultfont.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008-2010 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 * Default Font 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_defaultfont extends tx_rtehtmlareaapi {
36
37 protected $extensionKey = 'rtehtmlarea'; // The key of the extension that is extending htmlArea RTE
38 protected $pluginName = 'DefaultFont'; // The name of the plugin registered by the extension
39 protected $relativePathToLocallangFile = 'extensions/DefaultFont/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 $defaultFontFaces = array(
53 'Arial' => 'Arial,sans-serif',
54 'Arial Black' => 'Arial Black,sans-serif',
55 'Verdana' => 'Verdana,Arial,sans-serif',
56 'Times New Roman' => 'Times New Roman,Times,serif',
57 'Garamond' => 'Garamond',
58 'Lucida Handwriting' => 'Lucida Handwriting',
59 'Courier' => 'Courier',
60 'Webdings' => 'Webdings',
61 'Wingdings' => 'Wingdings',
62 );
63
64 protected $defaultFontSizes = array(
65 '1' => '1 (8 pt)',
66 '2' => '2 (10 pt)',
67 '3' => '3 (12 pt)',
68 '4' => '4 (14 pt)',
69 '5' => '5 (18 pt)',
70 '6' => '6 (24 pt)',
71 '7' => '7 (36 pt)',
72 );
73
74 protected $defaultFontSizes_safari = array(
75 '1' => 'x-small (10px)',
76 '2' => 'small (13px)',
77 '3' => 'medium (16px)',
78 '4' => 'large (18px)',
79 '5' => 'x-large (24px)',
80 '6' => 'xx-large (32px)',
81 '7' => 'xxx-large (48px)',
82 );
83
84 /**
85 * Return JS configuration of the htmlArea plugins registered by the extension
86 *
87 * @param integer Relative id of the RTE editing area in the form
88 *
89 * @return string JS configuration for registered plugins
90 *
91 * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
92 * Each of the instructions should be of the form:
93 * RTEarea['.$RTEcounter.']["buttons"]["button-id"]["property"] = "value";
94 */
95 public function buildJavascriptConfiguration($RTEcounter) {
96
97 $registerRTEinJavascriptString = '';
98
99 // Process font faces configuration
100 if (in_array('fontstyle',$this->toolbar)) {
101 $registerRTEinJavascriptString .= $this->buildJSFontFacesConfig($RTEcounter);
102 }
103
104 // Process font sizes configuration
105 if (in_array('fontsize',$this->toolbar)) {
106 $registerRTEinJavascriptString .= $this->buildJSFontSizesConfig($RTEcounter);
107 }
108
109 return $registerRTEinJavascriptString;
110 }
111
112 /**
113 * Return Javascript configuration of font faces
114 *
115 * @param integer $RTEcounter: The index number of the current RTE editing area within the form.
116 *
117 * @return string Javascript configuration of font faces
118 */
119 protected function buildJSFontfacesConfig($RTEcounter) {
120 global $TSFE, $LANG;
121
122 if ($this->htmlAreaRTE->is_FE()) {
123 $RTEProperties = $this->htmlAreaRTE->RTEsetup;
124 } else {
125 $RTEProperties = $this->htmlAreaRTE->RTEsetup['properties'];
126 }
127
128 $configureRTEInJavascriptString = '';
129
130 // Builing JS array of default font faces
131 // utf8-encode labels if we are responding to an IRRE ajax call
132 $HTMLAreaFontname = array();
133 $HTMLAreaFontname['nofont'] = '
134 "' . $fontName . '" : "' . $this->htmlAreaRTE->cleanList($fontValue) . '"';
135 $defaultFontFacesList = 'nofont,';
136 if ($this->htmlAreaRTE->is_FE()) {
137 $HTMLAreaFontname['nofont'] = '
138 "' . $GLOBALS['TSFE']->getLLL('No font', $this->LOCAL_LANG) . '" : ""';
139 } else {
140 $HTMLAreaFontname['nofont'] = '
141 "' . ($this->htmlAreaRTE->TCEform->inline->isAjaxCall ? $GLOBALS['LANG']->csConvObj->utf8_encode($GLOBALS['LANG']->getLL('No font'), $GLOBALS['LANG']->charSet) : $GLOBALS['LANG']->getLL('No font')) . '" : ""';
142 }
143
144 $hideFontFaces = $this->htmlAreaRTE->cleanList($this->thisConfig['hideFontFaces']);
145 if ($hideFontFaces != '*') {
146 $index = 0;
147 foreach ($this->defaultFontFaces as $fontName => $fontValue) {
148 if (!t3lib_div::inList($hideFontFaces, $index+1)) {
149 $HTMLAreaFontname[$fontName] = '
150 "' . ((!$this->htmlAreaRTE->is_FE() && $this->htmlAreaRTE->TCEform->inline->isAjaxCall) ? $GLOBALS['LANG']->csConvObj->utf8_encode($fontName, $GLOBALS['LANG']->charSet) : $fontName) . '" : "' . $this->htmlAreaRTE->cleanList($fontValue) . '"';
151 $defaultFontFacesList .= $fontName . ',';
152 }
153 $index++;
154 }
155 }
156
157 // Adding configured font faces
158 if (is_array($RTEProperties['fonts.'])) {
159 foreach ($RTEProperties['fonts.'] as $fontName => $conf) {
160 $fontName = substr($fontName,0,-1);
161 $fontLabel = $this->htmlAreaRTE->getPageConfigLabel($conf['name'],0);
162 $HTMLAreaFontname[$fontName] = '
163 "' . ((!$this->htmlAreaRTE->is_FE() && $this->htmlAreaRTE->TCEform->inline->isAjaxCall) ? $GLOBALS['LANG']->csConvObj->utf8_encode($fontLabel, $GLOBALS['LANG']->charSet) : $fontLabel) . '" : "' . $this->htmlAreaRTE->cleanList($conf['value']) . '"';
164 }
165 }
166
167 // Setting the list of font faces
168 $HTMLAreaJSFontface = '{';
169 $HTMLAreaFontface = t3lib_div::trimExplode(',' , $this->htmlAreaRTE->cleanList($defaultFontFacesList . ',' . $this->thisConfig['fontFace']));
170 $HTMLAreaFontfaceIndex = 0;
171 foreach ($HTMLAreaFontface as $fontName) {
172 if ($HTMLAreaFontfaceIndex) {
173 $HTMLAreaJSFontface .= ',';
174 }
175 $HTMLAreaJSFontface .= $HTMLAreaFontname[$fontName];
176 $HTMLAreaFontfaceIndex++;
177 }
178 $HTMLAreaJSFontface .= '};';
179
180 $button = 'fontstyle';
181 if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.'][$button.'.'])) {
182 $configureRTEInJavascriptString .= '
183 RTEarea['.$RTEcounter.'].buttons.'. $button .' = new Object();';
184 }
185 $configureRTEInJavascriptString .= '
186 RTEarea['.$RTEcounter.'].buttons.'. $button .'.options = '. $HTMLAreaJSFontface;
187
188 return $configureRTEInJavascriptString;
189 }
190
191 /**
192 * Return Javascript configuration of font sizes
193 *
194 * @param integer $RTEcounter: The index number of the current RTE editing area within the form.
195 *
196 * @return string Javascript font sizes configuration
197 */
198 protected function buildJSFontSizesConfig($RTEcounter) {
199 global $LANG, $TSFE;
200 $configureRTEInJavascriptString = '';
201
202 // Builing JS array of default font sizes
203 $HTMLAreaFontSizes = array();
204 if ($this->htmlAreaRTE->is_FE()) {
205 $HTMLAreaFontSizes[0] = $TSFE->getLLL('No size', $this->LOCAL_LANG);
206 } else {
207 $HTMLAreaFontSizes[0] = $LANG->getLL('No size');
208 }
209
210 foreach ($this->defaultFontSizes as $FontSizeItem => $FontSizeLabel) {
211 if ($this->htmlAreaRTE->client['BROWSER'] == 'safari') {
212 $HTMLAreaFontSizes[$FontSizeItem] = $this->defaultFontSizes_safari[$FontSizeItem];
213 } else {
214 $HTMLAreaFontSizes[$FontSizeItem] = $FontSizeLabel;
215 }
216 }
217 if ($this->thisConfig['hideFontSizes'] ) {
218 $hideFontSizes = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList($this->thisConfig['hideFontSizes']), 1);
219 foreach ($hideFontSizes as $item) {
220 if ($HTMLAreaFontSizes[strtolower($item)]) {
221 unset($HTMLAreaFontSizes[strtolower($item)]);
222 }
223 }
224 }
225
226 $HTMLAreaJSFontSize = '{';
227 if ($this->htmlAreaRTE->cleanList($this->thisConfig['hideFontSizes']) != '*') {
228 // utf8-encode labels if we are responding to an IRRE ajax call
229 if (!$this->htmlAreaRTE->is_FE() && $this->htmlAreaRTE->TCEform->inline->isAjaxCall) {
230 foreach ($HTMLAreaFontSizes as $FontSizeItem => $FontSizeLabel) {
231 $HTMLAreaFontSizes[$FontSizeItem] = $GLOBALS['LANG']->csConvObj->utf8_encode($FontSizeLabel, $GLOBALS['LANG']->charSet);
232 }
233 }
234 $HTMLAreaFontSizeIndex = 0;
235 foreach ($HTMLAreaFontSizes as $FontSizeItem => $FontSizeLabel) {
236 if($HTMLAreaFontSizeIndex) {
237 $HTMLAreaJSFontSize .= ',';
238 }
239 $HTMLAreaJSFontSize .= '
240 "' . $FontSizeLabel . '" : "' . ($FontSizeItem?$FontSizeItem:'') . '"';
241 $HTMLAreaFontSizeIndex++;
242 }
243 }
244 $HTMLAreaJSFontSize .= '};';
245
246 $button = 'fontsize';
247 if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.'][$button.'.'])) {
248 $configureRTEInJavascriptString .= '
249 RTEarea['.$RTEcounter.'].buttons.'. $button .' = new Object();';
250 }
251 $configureRTEInJavascriptString .= '
252 RTEarea['.$RTEcounter.'].buttons.'. $button .'.options = '. $HTMLAreaJSFontSize;
253
254 return $configureRTEInJavascriptString;
255 }
256
257 } // end of class
258
259 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/DefaultFont/class.tx_rtehtmlarea_defaultfont.php']) {
260 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/DefaultFont/class.tx_rtehtmlarea_defaultfont.php']);
261 }
262
263 ?>