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