Code cleanup: replaced CVS with SVN
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / extensions / InlineElements / class.tx_rtehtmlarea_inlineelements.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007-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 * InlineElements 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_inlineelements extends tx_rtehtmlareaapi {
36
37 protected $extensionKey = 'rtehtmlarea'; // The key of the extension that is extending htmlArea RTE
38 protected $pluginName = 'InlineElements'; // The name of the plugin registered by the extension
39 protected $relativePathToLocallangFile = 'extensions/InlineElements/locallang.xml'; // Path to this main locallang file of the extension relative to the extension dir.
40 protected $relativePathToSkin = 'extensions/InlineElements/skin/htmlarea.css'; // 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 = 'formattext, bidioverride, big, bold, citation, code, definition, deletedtext, emphasis, insertedtext, italic, keyboard, quotation, sample, small, span, strikethrough, strong, subscript, superscript, underline, variable';
47
48 protected $convertToolbarForHtmlAreaArray = array (
49 'formattext' => 'FormatText',
50 'bidioverride' => 'BiDiOverride',
51 'big' => 'Big',
52 'bold' => 'Bold',
53 'citation' => 'Citation',
54 'code' => 'Code',
55 'definition' => 'Definition',
56 'deletedtext' => 'DeletedText',
57 'emphasis' => 'Emphasis',
58 'insertedtext' => 'InsertedText',
59 'italic' => 'Italic',
60 'keyboard' => 'Keyboard',
61 'monospaced' => 'MonoSpaced',
62 'quotation' => 'Quotation',
63 'sample' => 'Sample',
64 'small' => 'Small',
65 'span' => 'Span',
66 'strikethrough' => 'StrikeThrough',
67 'strong' => 'Strong',
68 'subscript' => 'Subscript',
69 'superscript' => 'Superscript',
70 'underline' => 'Underline',
71 'variable' => 'Variable',
72 );
73
74 private $defaultInlineElements = array(
75 'none' => 'No markup',
76 'b' => 'Bold',
77 'bdo' => 'BiDi override',
78 'big' => 'Large text',
79 'cite' => 'Citation',
80 'code' => 'Code',
81 'del' => 'Deleted text',
82 'dfn' => 'Definition',
83 'em' => 'Emphasis',
84 'i' => 'Italic',
85 'ins' => 'Inserted text',
86 'kbd' => 'Keyboard',
87 'q' => 'Quotation',
88 'samp' => 'Sample',
89 'small' => 'Small text',
90 'span' => 'Style container',
91 'strike' => 'Strike-through',
92 'strong' => 'Strong emphasis',
93 'sub' => 'Subscript',
94 'sup' => 'Superscript',
95 'tt' => 'Monospaced text',
96 'u' => 'Underline',
97 'var' => 'Variable',
98 );
99
100 private $defaultInlineElementsOrder = 'none, bidioverride, big, bold, citation, code, definition, deletedtext, emphasis, insertedtext, italic, keyboard,
101 monospaced, quotation, sample, small, span, strikethrough, strong, subscript, superscript, underline, variable';
102
103 private $buttonToInlineElement = array(
104 'none' => 'none',
105 'bidioverride' => 'bdo',
106 'big' => 'big',
107 'bold' => 'b',
108 'citation' => 'cite',
109 'code' => 'code',
110 'definition' => 'dfn',
111 'deletedtext' => 'del',
112 'emphasis' => 'em',
113 'insertedtext' => 'ins',
114 'italic' => 'i',
115 'keyboard' => 'kbd',
116 'monospaced' => 'tt',
117 'quotation' => 'q',
118 'sample' => 'samp',
119 'small' => 'small',
120 'span' => 'span',
121 'strikethrough' => 'strike',
122 'strong' => 'strong',
123 'subscript' => 'sub',
124 'superscript' => 'sup',
125 'underline' => 'u',
126 'variable' => 'var',
127 );
128
129 /**
130 * Return JS configuration of the htmlArea plugins registered by the extension
131 *
132 * @param integer Relative id of the RTE editing area in the form
133 *
134 * @return string JS configuration for registered plugins
135 *
136 * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
137 * Each of the instructions should be of the form:
138 * RTEarea['.$RTEcounter.']["buttons"]["button-id"]["property"] = "value";
139 */
140 public function buildJavascriptConfiguration($RTEcounter) {
141 global $TSFE, $LANG;
142
143 $registerRTEinJavascriptString = '';
144 if (in_array('formattext', $this->toolbar)) {
145 if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.']['formattext.'])) {
146 $registerRTEinJavascriptString .= '
147 RTEarea['.$RTEcounter.'].buttons.formattext = new Object();';
148 }
149
150 // Default inline elements
151 $hideItems = array();
152 $restrictTo = array('*');
153 $inlineElementsOrder = $this->defaultInlineElementsOrder;
154 $prefixLabelWithTag = false;
155 $postfixLabelWithTag = false;
156
157 // Processing PageTSConfig
158 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['formattext.'])) {
159 // Removing elements
160 if ($this->thisConfig['buttons.']['formattext.']['removeItems']) {
161 $hideItems = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList($this->thisConfig['buttons.']['formattext.']['removeItems']), 1);
162 }
163 // Restriction clause
164 if ($this->thisConfig['buttons.']['formattext.']['restrictToItems']) {
165 $restrictTo = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList('none,'.$this->thisConfig['buttons.']['formattext.']['restrictTo']), 1);
166 }
167 // Elements order
168 if ($this->thisConfig['buttons.']['formattext.']['orderItems']) {
169 $inlineElementsOrder = 'none,'.$this->thisConfig['buttons.']['formattext.']['orderItems'];
170 }
171 $prefixLabelWithTag = ($this->thisConfig['buttons.']['formattext.']['prefixLabelWithTag'])?true:$prefixLabelWithTag;
172 $postfixLabelWithTag = ($this->thisConfig['buttons.']['formattext.']['postfixLabelWithTag'])?true:$postfixLabelWithTag;
173 }
174
175 $inlineElementsOrder = array_diff(t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList($inlineElementsOrder), 1), $hideItems);
176 if (!in_array('*', $restrictTo)) {
177 $inlineElementsOrder = array_intersect($inlineElementsOrder, $restrictTo);
178 }
179
180 // Localizing the options
181 $inlineElementsOptions = array();
182 foreach ($inlineElementsOrder as $item) {
183 if ($this->htmlAreaRTE->is_FE()) {
184 $inlineElementsOptions[$this->buttonToInlineElement[$item]] = $TSFE->getLLL($this->defaultInlineElements[$this->buttonToInlineElement[$item]], $this->LOCAL_LANG);
185 } else {
186 $inlineElementsOptions[$this->buttonToInlineElement[$item]] = $LANG->getLL($this->defaultInlineElements[$this->buttonToInlineElement[$item]]);
187 }
188 $inlineElementsOptions[$this->buttonToInlineElement[$item]] = (($prefixLabelWithTag && $item != 'none')?($this->buttonToInlineElement[$item].' - '):'') . $inlineElementsOptions[$this->buttonToInlineElement[$item]] . (($postfixLabelWithTag && $item != 'none')?(' - '.$this->buttonToInlineElement[$item]):'');
189 }
190
191 $first = array_shift($inlineElementsOptions);
192 // Sorting the options
193 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.']['formattext.']) || !$this->thisConfig['buttons.']['formattext.']['orderItems']) {
194 asort($inlineElementsOptions);
195 }
196 // Generating the javascript options
197 $JSInlineElements = '{
198 "'. $first.'" : "none"';
199 foreach ($inlineElementsOptions as $item => $label) {
200 $JSInlineElements .= ',
201 "' . $label . '" : "' . $item . '"';
202 }
203 $JSInlineElements .= '};';
204
205 $registerRTEinJavascriptString .= '
206 RTEarea['.$RTEcounter.'].buttons.formattext.dropDownOptions = '. $JSInlineElements;
207 }
208 return $registerRTEinJavascriptString;
209 }
210
211
212 } // end of class
213
214 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/InlineElements/class.tx_rtehtmlarea_inlineelements.php']) {
215 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/InlineElements/class.tx_rtehtmlarea_inlineelements.php']);
216 }
217
218 ?>