2 /***************************************************************
5 * (c) 2008 Stanislas Rolland <typo3(arobas)sjbr.ca>
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.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
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.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
25 * SelectFont extension for htmlArea RTE
27 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
29 * TYPO3 SVN ID: $Id: class.tx_rtehtmlarea_selectfont.php $
33 require_once(t3lib_extMgm
::extPath('rtehtmlarea').'class.tx_rtehtmlareaapi.php');
35 class tx_rtehtmlarea_selectfont
extends tx_rtehtmlareaapi
{
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
46 protected $pluginButtons = 'fontstyle,fontsize';
47 protected $convertToolbarForHtmlAreaArray = array (
48 'fontstyle' => 'FontName',
49 'fontsize' => 'FontSize',
52 protected $defaultFont = 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',
65 'Extra small' => 'xx-small',
66 'Very small' => 'x-small',
70 'Very large' => 'x-large',
71 'Extra large' => 'xx-large',
75 protected $RTEProperties;
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
;
82 $this->RTEProperties
= $this->htmlAreaRTE
->RTEsetup
['properties'];
88 * Return JS configuration of the htmlArea plugins registered by the extension
90 * @param integer Relative id of the RTE editing area in the form
92 * @return string JS configuration for registered plugins
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";
98 public function buildJavascriptConfiguration($RTEcounter) {
99 $registerRTEinJavascriptString = '';
100 $pluginButtonsArray = t3lib_div
::trimExplode(",", $this->pluginButtons
);
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);
108 return $registerRTEinJavascriptString;
112 * Return Javascript configuration of font faces
114 * @param integer $RTEcounter: The index number of the current RTE editing area within the form.
115 * @param string $buttonId: button id
117 * @return string Javascript configuration of font faces
119 protected function buildJSFontItemsConfig($RTEcounter, $buttonId) {
120 $configureRTEInJavascriptString = '';
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'];
129 if ($this->thisConfig
['buttons.'][$buttonId]['addItems']) {
130 $addItems = $this->thisConfig
['buttons.'][$buttonId]['addItems'];
133 // Initializing the items array
135 if ($this->htmlAreaRTE
->is_FE()) {
137 "' . $GLOBALS['TSFE']->getLLL((($buttonId == 'fontstyle') ?
'No font' : 'No size'), $this->LOCAL_LANG
) . '" : ""';
140 "' . $GLOBALS['LANG']->getLL(($buttonId == 'fontstyle') ?
'No font' : 'No size') . '" : ""';
142 $defaultItems = 'none,';
144 // Inserting and localizing default items
145 if ($hideItems != '*') {
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
);
152 $label = $GLOBALS['LANG']->getLL($name);
155 "' . $name . '" : "' . $this->htmlAreaRTE
->cleanList($value) . '"';
156 $defaultItems .= $name . ',';
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);
167 "' . $label . '" : "' . $this->htmlAreaRTE
->cleanList($conf['value']) . '"';
170 // Setting the JS list of options
172 $configuredItems = t3lib_div
::trimExplode(',' , $this->htmlAreaRTE
->cleanList($defaultItems . ',' . $addItems));
174 foreach ($configuredItems as $name) {
175 $JSOptions .= ($index ?
',' : '') . $items[$name];
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();';
187 $configureRTEInJavascriptString .= '
188 RTEarea['.$RTEcounter.'].buttons.'. $buttonId .'.options = '. $JSOptions;
190 return $configureRTEInJavascriptString;
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']);