653816e505079fe032001d5c7c25d1bcec591476
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / extensions / DefaultFont / class.tx_rtehtmlarea_defaultfont.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008 Stanislas Rolland <stanislas.rolland(arobas)fructifor.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 <stanislas.rolland(arobas)fructifor.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 private $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 private $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 private $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 private 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 $HTMLAreaFontname = array();
132 $HTMLAreaFontname['nofont'] = '
133 "' . $fontName . '" : "' . $this->htmlAreaRTE->cleanList($fontValue) . '"';
134 $defaultFontFacesList = 'nofont,';
135 if ($this->htmlAreaRTE->is_FE()) {
136 $HTMLAreaFontname['nofont'] = '
137 "' . $TSFE->csConvObj->conv($TSFE->getLLL('No font',$this->LOCAL_LANG), $TSFE->labelsCharset, $TSFE->renderCharset) . '" : ""';
138 } else {
139 $HTMLAreaFontname['nofont'] = '
140 "' . $LANG->getLL('No font') . '" : ""';
141 }
142
143 $hideFontFaces = $this->htmlAreaRTE->cleanList($this->thisConfig['hideFontFaces']);
144 if ($hideFontFaces != '*') {
145 $index = 0;
146 foreach ($this->defaultFontFaces as $fontName => $fontValue) {
147 if (!t3lib_div::inList($hideFontFaces, $index+1)) {
148 $HTMLAreaFontname[$fontName] = '
149 "' . $fontName . '" : "' . $this->htmlAreaRTE->cleanList($fontValue) . '"';
150 $defaultFontFacesList .= $fontName . ',';
151 }
152 $index++;
153 }
154 }
155
156 // Adding configured font faces
157 if (is_array($RTEProperties['fonts.'])) {
158 foreach ($RTEProperties['fonts.'] as $fontName => $conf) {
159 $fontName = substr($fontName,0,-1);
160 $fontLabel = $this->htmlAreaRTE->getPageConfigLabel($conf['name'],0);
161 $HTMLAreaFontname[$fontName] = '
162 "' . $fontLabel . '" : "' . $this->htmlAreaRTE->cleanList($conf['value']) . '"';
163 }
164 }
165
166 // Setting the list of font faces
167 $HTMLAreaJSFontface = '{';
168 $HTMLAreaFontface = t3lib_div::trimExplode(',' , $this->htmlAreaRTE->cleanList($defaultFontFacesList . ',' . $this->thisConfig['fontFace']));
169 $HTMLAreaFontfaceIndex = 0;
170 foreach ($HTMLAreaFontface as $fontName) {
171 if ($HTMLAreaFontfaceIndex) {
172 $HTMLAreaJSFontface .= ',';
173 }
174 $HTMLAreaJSFontface .= $HTMLAreaFontname[$fontName];
175 $HTMLAreaFontfaceIndex++;
176 }
177 $HTMLAreaJSFontface .= '};';
178
179 $button = 'fontstyle';
180 if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.'][$button.'.'])) {
181 $configureRTEInJavascriptString .= '
182 RTEarea['.$RTEcounter.'].buttons.'. $button .' = new Object();';
183 }
184 $configureRTEInJavascriptString .= '
185 RTEarea['.$RTEcounter.'].buttons.'. $button .'.options = '. $HTMLAreaJSFontface;
186
187 return $configureRTEInJavascriptString;
188 }
189
190 /**
191 * Return Javascript configuration of font sizes
192 *
193 * @param integer $RTEcounter: The index number of the current RTE editing area within the form.
194 *
195 * @return string Javascript font sizes configuration
196 */
197 private function buildJSFontSizesConfig($RTEcounter) {
198 global $LANG, $TSFE;
199 $configureRTEInJavascriptString = '';
200
201 // Builing JS array of default font sizes
202 $HTMLAreaFontSizes = array();
203 if ($this->htmlAreaRTE->is_FE()) {
204 $HTMLAreaFontSizes[0] = $TSFE->csConvObj->conv($TSFE->getLLL('No size',$this->LOCAL_LANG), $TSFE->labelsCharset, $TSFE->renderCharset);
205 } else {
206 $HTMLAreaFontSizes[0] = $LANG->getLL('No size');
207 }
208
209 foreach ($this->defaultFontSizes as $FontSizeItem => $FontSizeLabel) {
210 if ($this->htmlAreaRTE->client['BROWSER'] == 'safari') {
211 $HTMLAreaFontSizes[$FontSizeItem] = $this->defaultFontSizes_safari[$FontSizeItem];
212 } else {
213 $HTMLAreaFontSizes[$FontSizeItem] = $FontSizeLabel;
214 }
215 }
216 if ($this->thisConfig['hideFontSizes'] ) {
217 $hideFontSizes = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList($this->thisConfig['hideFontSizes']), 1);
218 foreach ($hideFontSizes as $item) {
219 if ($HTMLAreaFontSizes[strtolower($item)]) {
220 unset($HTMLAreaFontSizes[strtolower($item)]);
221 }
222 }
223 }
224
225 $HTMLAreaJSFontSize = '{';
226 if ($this->htmlAreaRTE->cleanList($this->thisConfig['hideFontSizes']) != '*') {
227 $HTMLAreaFontSizeIndex = 0;
228 foreach ($HTMLAreaFontSizes as $FontSizeItem => $FontSizeLabel) {
229 if($HTMLAreaFontSizeIndex) {
230 $HTMLAreaJSFontSize .= ',';
231 }
232 $HTMLAreaJSFontSize .= '
233 "' . $FontSizeLabel . '" : "' . ($FontSizeItem?$FontSizeItem:'') . '"';
234 $HTMLAreaFontSizeIndex++;
235 }
236 }
237 $HTMLAreaJSFontSize .= '};';
238
239 $button = 'fontsize';
240 if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.'][$button.'.'])) {
241 $configureRTEInJavascriptString .= '
242 RTEarea['.$RTEcounter.'].buttons.'. $button .' = new Object();';
243 }
244 $configureRTEInJavascriptString .= '
245 RTEarea['.$RTEcounter.'].buttons.'. $button .'.options = '. $HTMLAreaJSFontSize;
246
247 return $configureRTEInJavascriptString;
248 }
249
250 } // end of class
251
252 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/DefaultFont/class.tx_rtehtmlarea_defaultfont.php']) {
253 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/DefaultFont/class.tx_rtehtmlarea_defaultfont.php']);
254 }
255
256 ?>