Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / extensions / SelectFont / class.tx_rtehtmlarea_selectfont.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008-2011 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$
30 *
31 */
32 class tx_rtehtmlarea_selectfont extends tx_rtehtmlarea_api {
33
34 protected $extensionKey = 'rtehtmlarea'; // The key of the extension that is extending htmlArea RTE
35 protected $pluginName = 'SelectFont'; // The name of the plugin registered by the extension
36 protected $relativePathToLocallangFile = 'extensions/SelectFont/locallang.xml'; // Path to this main locallang file of the extension relative to the extension dir.
37 protected $relativePathToSkin = ''; // Path to the skin (css) file relative to the extension dir.
38 protected $htmlAreaRTE; // Reference to the invoking object
39 protected $thisConfig; // Reference to RTE PageTSConfig
40 protected $toolbar; // Reference to RTE toolbar array
41 protected $LOCAL_LANG; // Frontend language array
42
43 protected $pluginButtons = 'fontstyle,fontsize';
44 protected $convertToolbarForHtmlAreaArray = array (
45 'fontstyle' => 'FontName',
46 'fontsize' => 'FontSize',
47 );
48
49 protected $defaultFont = array(
50 'fontstyle' => array(
51 'Arial' => 'Arial,sans-serif',
52 'Arial Black' => '\'Arial Black\',sans-serif',
53 'Verdana' => 'Verdana,Arial,sans-serif',
54 'Times New Roman' => '\'Times New Roman\',Times,serif',
55 'Garamond' => 'Garamond',
56 'Lucida Handwriting' => '\'Lucida Handwriting\'',
57 'Courier' => 'Courier',
58 'Webdings' => 'Webdings',
59 'Wingdings' => 'Wingdings',
60 ),
61 'fontsize' => array(
62 'Extra small' => '8px',
63 'Very small' => '9px',
64 'Small' => '10px',
65 'Medium' => '12px',
66 'Large' => '16px',
67 'Very large' => '24px',
68 'Extra large' => '32px',
69 ),
70 );
71
72 protected $RTEProperties;
73
74 public function main($parentObject) {
75 $enabled = parent::main($parentObject) && $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['allowStyleAttribute'];
76 if ($this->htmlAreaRTE->is_FE()) {
77 $this->RTEProperties = $this->htmlAreaRTE->RTEsetup;
78 } else {
79 $this->RTEProperties = $this->htmlAreaRTE->RTEsetup['properties'];
80 }
81 return $enabled;
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 $registerRTEinJavascriptString = '';
97 $pluginButtonsArray = t3lib_div::trimExplode(",", $this->pluginButtons);
98
99 // Process Page TSConfig configuration for each button
100 foreach ($pluginButtonsArray as $buttonId) {
101 if (in_array($buttonId, $this->toolbar)) {
102 $registerRTEinJavascriptString .= $this->buildJSFontItemsConfig($RTEcounter, $buttonId);
103 }
104 }
105 return $registerRTEinJavascriptString;
106 }
107
108 /**
109 * Return Javascript configuration of font faces
110 *
111 * @param integer $RTEcounter: The index number of the current RTE editing area within the form.
112 * @param string $buttonId: button id
113 *
114 * @return string Javascript configuration of font faces
115 */
116 protected function buildJSFontItemsConfig($RTEcounter, $buttonId) {
117 $configureRTEInJavascriptString = '';
118
119 // Getting removal and addition configuration
120 $hideItems = $this->htmlAreaRTE->cleanList($this->thisConfig['hideFont' . (($buttonId == 'fontstyle') ? 'Faces' : 'Sizes')]);
121 $addItems = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList($this->thisConfig[($buttonId == 'fontstyle') ? 'fontFace' : 'fontSize']), 1);
122 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.'][$buttonId . '.'])) {
123 if ($this->thisConfig['buttons.'][$buttonId . '.']['removeItems']) {
124 $hideItems = $this->thisConfig['buttons.'][$buttonId . '.']['removeItems'];
125 }
126 if ($this->thisConfig['buttons.'][$buttonId . '.']['addItems']) {
127 $addItems = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList($this->thisConfig['buttons.'][$buttonId . '.']['addItems']), 1);
128 }
129 }
130 // Initializing the items array
131 $items = array();
132 if ($this->htmlAreaRTE->is_FE()) {
133 $items['none'] = array($GLOBALS['TSFE']->getLLL((($buttonId == 'fontstyle') ? 'Default font' : 'Default size'), $this->LOCAL_LANG), 'none');
134 } else {
135 $items['none'] = array(($GLOBALS['LANG']->getLL(($buttonId == 'fontstyle') ? 'Default font' : 'Default size')), 'none');
136 }
137 // Inserting and localizing default items
138 if ($hideItems != '*') {
139 $index = 0;
140 foreach ($this->defaultFont[$buttonId] as $name => $value) {
141 if (!t3lib_div::inList($hideItems, strval($index+1))) {
142 if ($this->htmlAreaRTE->is_FE()) {
143 $label = $GLOBALS['TSFE']->getLLL($name,$this->LOCAL_LANG);
144 } else {
145 $label = $GLOBALS['LANG']->getLL($name);
146 if (!$label) {
147 $label = $name;
148 }
149 }
150 $items[$name] = array($label, $this->htmlAreaRTE->cleanList($value));
151 }
152 $index++;
153 }
154 }
155 // Adding configured items
156 if (is_array($this->RTEProperties[($buttonId == 'fontstyle') ? 'fonts.' : 'fontSizes.'])) {
157 foreach ($this->RTEProperties[($buttonId == 'fontstyle') ? 'fonts.' : 'fontSizes.'] as $name => $conf) {
158 $name = substr($name,0,-1);
159 if (in_array($name, $addItems)) {
160 $label = $this->htmlAreaRTE->getPageConfigLabel($conf['name'],0);
161 $items[$name] = array($label, $this->htmlAreaRTE->cleanList($conf['value']));
162 }
163 }
164 }
165 // Seting default item
166 if ($this->thisConfig['buttons.'][$buttonId . '.']['defaultItem'] && $items[$this->thisConfig['buttons.'][$buttonId . '.']['defaultItem']]) {
167 $items['none'] = array($items[$this->thisConfig['buttons.'][$buttonId . '.']['defaultItem']][0], 'none');
168 unset($items[$this->thisConfig['buttons.'][$buttonId . '.']['defaultItem']]);
169 }
170 // Setting the JS list of options
171 $itemsJSArray = array();
172 foreach ($items as $name => $option) {
173 $itemsJSArray[] = array('text' => $option[0], 'value' => $option[1]);
174 }
175 if ($this->htmlAreaRTE->is_FE()) {
176 $GLOBALS['TSFE']->csConvObj->convArray($itemsJSArray, $this->htmlAreaRTE->OutputCharset, 'utf-8');
177 } else {
178 $GLOBALS['LANG']->csConvObj->convArray($itemsJSArray, $GLOBALS['LANG']->charSet, 'utf-8');
179 }
180 $itemsJSArray = json_encode(array('options' => $itemsJSArray));
181 // Adding to button JS configuration
182 if (!is_array( $this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][$buttonId . '.'])) {
183 $configureRTEInJavascriptString .= '
184 RTEarea['.$RTEcounter.'].buttons.'. $buttonId .' = new Object();';
185 }
186 $configureRTEInJavascriptString .= '
187 RTEarea['.$RTEcounter.'].buttons.'. $buttonId . '.dataUrl = \'' . $this->htmlAreaRTE->writeTemporaryFile('', $buttonId . '_'. $this->htmlAreaRTE->contentLanguageUid, 'js', $itemsJSArray) . '\';';
188 return $configureRTEInJavascriptString;
189 }
190 }
191 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/SelectFont/class.tx_rtehtmlarea_selectfont.php'])) {
192 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/SelectFont/class.tx_rtehtmlarea_selectfont.php']);
193 }
194 ?>