fecb4dbdb70f0281300a90241f18b609164a6724
[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 CVS ID: $Id: class.tx_rtehtmlarea_pi1.php 2449 2007-08-15 08:12:19Z ingorenner $
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 //'label' => 'Label',
88 'q' => 'Quotation',
89 'samp' => 'Sample',
90 'small' => 'Small text',
91 'span' => 'Style container',
92 'strike' => 'Strike-through',
93 'strong' => 'Strong emphasis',
94 'sub' => 'Subscript',
95 'sup' => 'Superscript',
96 'tt' => 'Monospaced text',
97 'u' => 'Underline',
98 'var' => 'Variable',
99 );
100
101 private $defaultInlineElementsOrder = 'none, bidioverride, big, bold, citation, code, definition, deletedtext, emphasis, insertedtext, italic, keyboard,
102 monospaced, quotation, sample, small, span, strikethrough, strong, subscript, superscript, underline, variable';
103
104 private $buttonToInlineElement = array(
105 'none' => 'none',
106 'bidioverride' => 'bdo',
107 'big' => 'big',
108 'bold' => 'b',
109 'citation' => 'cite',
110 'code' => 'code',
111 'definition' => 'dfn',
112 'deletedtext' => 'del',
113 'emphasis' => 'em',
114 'insertedtext' => 'ins',
115 'italic' => 'i',
116 'keyboard' => 'kbd',
117 //'label' => 'label',
118 'monospaced' => 'tt',
119 'quotation' => 'q',
120 'sample' => 'samp',
121 'small' => 'small',
122 'span' => 'span',
123 'strikethrough' => 'strike',
124 'strong' => 'strong',
125 'subscript' => 'sub',
126 'superscript' => 'sup',
127 'underline' => 'u',
128 'variable' => 'var',
129 );
130
131 /**
132 * Return JS configuration of the htmlArea plugins registered by the extension
133 *
134 * @param integer Relative id of the RTE editing area in the form
135 *
136 * @return string JS configuration for registered plugins
137 *
138 * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
139 * Each of the instructions should be of the form:
140 * RTEarea['.$RTEcounter.']["buttons"]["button-id"]["property"] = "value";
141 */
142 public function buildJavascriptConfiguration($RTEcounter) {
143 global $TSFE, $LANG;
144
145 $registerRTEinJavascriptString = '';
146 if (in_array('formattext', $this->toolbar)) {
147 if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.']['formattext.'])) {
148 $registerRTEinJavascriptString .= '
149 RTEarea['.$RTEcounter.']["buttons"]["formattext"] = new Object();';
150 }
151
152 // Default inline elements
153 $hideItems = array();
154 $restrictTo = array('*');
155 $inlineElementsOrder = $this->defaultInlineElementsOrder;
156 $prefixLabelWithTag = false;
157 $postfixLabelWithTag = false;
158
159 // Processing PageTSConfig
160 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['formattext.'])) {
161 // Removing elements
162 if ($this->thisConfig['buttons.']['formattext.']['removeItems']) {
163 $hideItems = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList($this->thisConfig['buttons.']['formattext.']['removeItems']), 1);
164 }
165 // Restriction clause
166 if ($this->thisConfig['buttons.']['formattext.']['restrictToItems']) {
167 $restrictTo = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList('none,'.$this->thisConfig['buttons.']['formattext.']['restrictTo']), 1);
168 }
169 // Elements order
170 if ($this->thisConfig['buttons.']['formattext.']['orderItems']) {
171 $inlineElementsOrder = 'none,'.$this->thisConfig['buttons.']['formattext.']['orderItems'];
172 }
173 $prefixLabelWithTag = ($this->thisConfig['buttons.']['formattext.']['prefixLabelWithTag'])?true:$prefixLabelWithTag;
174 $postfixLabelWithTag = ($this->thisConfig['buttons.']['formattext.']['postfixLabelWithTag'])?true:$postfixLabelWithTag;
175 }
176
177 $inlineElementsOrder = array_diff(t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList($inlineElementsOrder), 1), $hideItems);
178 if (!in_array('*', $restrictTo)) {
179 $inlineElementsOrder = array_intersect($inlineElementsOrder, $restrictTo);
180 }
181
182 // Localizing the options
183 $inlineElementsOptions = array();
184 foreach ($inlineElementsOrder as $item) {
185 if ($this->htmlAreaRTE->is_FE()) {
186 $inlineElementsOptions[$this->buttonToInlineElement[$item]] = $TSFE->csConvObj->conv($TSFE->getLLL($this->defaultInlineElements[$this->buttonToInlineElement[$item]],$this->LOCAL_LANG), $TSFE->labelsCharset, $TSFE->renderCharset);
187 } else {
188 $inlineElementsOptions[$this->buttonToInlineElement[$item]] = $LANG->getLL($this->defaultInlineElements[$this->buttonToInlineElement[$item]]);
189 }
190 $inlineElementsOptions[$this->buttonToInlineElement[$item]] = (($prefixLabelWithTag && $item != 'none')?($this->buttonToInlineElement[$item].' - '):'') . $inlineElementsOptions[$this->buttonToInlineElement[$item]] . (($postfixLabelWithTag && $item != 'none')?(' - '.$this->buttonToInlineElement[$item]):'');
191 }
192
193 $first = array_shift($inlineElementsOptions);
194 // Sorting the options
195 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.']['formattext.']) || !$this->thisConfig['buttons.']['formattext.']['orderItems']) {
196 asort($inlineElementsOptions);
197 }
198 // Generating the javascript options
199 $JSInlineElements = '{
200 "'. $first.'" : "none"';
201 foreach ($inlineElementsOptions as $item => $label) {
202 $JSInlineElements .= ',
203 "' . $label . '" : "' . $item . '"';
204 }
205 $JSInlineElements .= '};';
206
207 $registerRTEinJavascriptString .= '
208 RTEarea['.$RTEcounter.'].buttons.formattext.dropDownOptions = '. $JSInlineElements;
209 }
210 return $registerRTEinJavascriptString;
211 }
212
213
214 } // end of class
215
216 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/InlineElements/class.tx_rtehtmlarea_inlineelements.php']) {
217 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/InlineElements/class.tx_rtehtmlarea_inlineelements.php']);
218 }
219
220 ?>