[!!!][TASK] RTE: locallang inferno
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / Extension / InlineElements.php
1 <?php
2 namespace TYPO3\CMS\Rtehtmlarea\Extension;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Rtehtmlarea\RteHtmlAreaApi;
19
20 /**
21 * InlineElements plugin for htmlArea RTE
22 *
23 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
24 */
25 class InlineElements extends RteHtmlAreaApi {
26
27 /**
28 * The name of the plugin registered by the extension
29 *
30 * @var string
31 */
32 protected $pluginName = 'InlineElements';
33
34 /**
35 * The comma-separated list of button names that the registered plugin is adding to the htmlArea RTE toolbar
36 *
37 * @var string
38 */
39 protected $pluginButtons = 'formattext, bidioverride, big, bold, citation, code, definition, deletedtext, emphasis, insertedtext, italic, keyboard, quotation, sample, small, span, strikethrough, strong, subscript, superscript, underline, variable';
40
41 /**
42 * The name-converting array, converting the button names used in the RTE PageTSConfing to the button id's used by the JS scripts
43 *
44 * @var array
45 */
46 protected $convertToolbarForHtmlAreaArray = array(
47 'formattext' => 'FormatText',
48 'bidioverride' => 'BiDiOverride',
49 'big' => 'Big',
50 'bold' => 'Bold',
51 'citation' => 'Citation',
52 'code' => 'Code',
53 'definition' => 'Definition',
54 'deletedtext' => 'DeletedText',
55 'emphasis' => 'Emphasis',
56 'insertedtext' => 'InsertedText',
57 'italic' => 'Italic',
58 'keyboard' => 'Keyboard',
59 'monospaced' => 'MonoSpaced',
60 'quotation' => 'Quotation',
61 'sample' => 'Sample',
62 'small' => 'Small',
63 'span' => 'Span',
64 'strikethrough' => 'StrikeThrough',
65 'strong' => 'Strong',
66 'subscript' => 'Subscript',
67 'superscript' => 'Superscript',
68 'underline' => 'Underline',
69 'variable' => 'Variable'
70 );
71
72 /**
73 * Default list of inline elements
74 *
75 * @var array
76 */
77 protected $defaultInlineElements = array(
78 'none' => 'No markup',
79 'b' => 'Bold',
80 'bdo' => 'BiDi override',
81 'big' => 'Large text',
82 'cite' => 'Citation',
83 'code' => 'Code',
84 'del' => 'Deleted text',
85 'dfn' => 'Definition',
86 'em' => 'Emphasis',
87 'i' => 'Italic',
88 'ins' => 'Inserted text',
89 'kbd' => 'Keyboard',
90 'q' => 'Quotation',
91 'samp' => 'Sample',
92 'small' => 'Small text',
93 'span' => 'Style container',
94 'strike' => 'Strike-through',
95 'strong' => 'Strong emphasis',
96 'sub' => 'Subscript',
97 'sup' => 'Superscript',
98 'tt' => 'Monospaced text',
99 'u' => 'Underline',
100 'var' => 'Variable'
101 );
102
103 /**
104 * Default order of inline elements
105 *
106 * @var string
107 */
108 protected $defaultInlineElementsOrder = 'none, bidioverride, big, bold, citation, code, definition, deletedtext, emphasis, insertedtext, italic, keyboard,
109 monospaced, quotation, sample, small, span, strikethrough, strong, subscript, superscript, underline, variable';
110
111 /**
112 * Button names to inline elements
113 *
114 * @var array
115 */
116 protected $buttonToInlineElement = array(
117 'none' => 'none',
118 'bidioverride' => 'bdo',
119 'big' => 'big',
120 'bold' => 'b',
121 'citation' => 'cite',
122 'code' => 'code',
123 'definition' => 'dfn',
124 'deletedtext' => 'del',
125 'emphasis' => 'em',
126 'insertedtext' => 'ins',
127 'italic' => 'i',
128 'keyboard' => 'kbd',
129 'monospaced' => 'tt',
130 'quotation' => 'q',
131 'sample' => 'samp',
132 'small' => 'small',
133 'span' => 'span',
134 'strikethrough' => 'strike',
135 'strong' => 'strong',
136 'subscript' => 'sub',
137 'superscript' => 'sup',
138 'underline' => 'u',
139 'variable' => 'var'
140 );
141
142 /**
143 * Return JS configuration of the htmlArea plugins registered by the extension
144 *
145 * @param string $rteNumberPlaceholder A dummy string for JS arrays
146 * @return string JS configuration for registered plugins
147 */
148 public function buildJavascriptConfiguration($rteNumberPlaceholder) {
149 $registerRTEinJavascriptString = '';
150 if (in_array('formattext', $this->toolbar)) {
151 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.']['formattext.'])) {
152 $registerRTEinJavascriptString .= '
153 RTEarea[' . $rteNumberPlaceholder . '].buttons.formattext = new Object();';
154 }
155 // Default inline elements
156 $hideItems = array();
157 $restrictTo = array('*');
158 $inlineElementsOrder = $this->defaultInlineElementsOrder;
159 $prefixLabelWithTag = FALSE;
160 $postfixLabelWithTag = FALSE;
161 // Processing PageTSConfig
162 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['formattext.'])) {
163 // Removing elements
164 if ($this->thisConfig['buttons.']['formattext.']['removeItems']) {
165 $hideItems = GeneralUtility::trimExplode(',', $this->htmlAreaRTE->cleanList($this->thisConfig['buttons.']['formattext.']['removeItems']), TRUE);
166 }
167 // Restriction clause
168 if ($this->thisConfig['buttons.']['formattext.']['restrictTo']) {
169 $restrictTo = GeneralUtility::trimExplode(',', $this->htmlAreaRTE->cleanList('none,' . $this->thisConfig['buttons.']['formattext.']['restrictTo']), TRUE);
170 } elseif ($this->thisConfig['buttons.']['formattext.']['restrictToItems']) {
171 $restrictTo = GeneralUtility::trimExplode(',', $this->htmlAreaRTE->cleanList('none,' . $this->thisConfig['buttons.']['formattext.']['restrictToItems']), TRUE);
172 }
173 // Elements order
174 if ($this->thisConfig['buttons.']['formattext.']['orderItems']) {
175 $inlineElementsOrder = 'none,' . $this->thisConfig['buttons.']['formattext.']['orderItems'];
176 }
177 $prefixLabelWithTag = $this->thisConfig['buttons.']['formattext.']['prefixLabelWithTag'] ? TRUE : $prefixLabelWithTag;
178 $postfixLabelWithTag = $this->thisConfig['buttons.']['formattext.']['postfixLabelWithTag'] ? TRUE : $postfixLabelWithTag;
179 }
180 $inlineElementsOrder = array_diff(GeneralUtility::trimExplode(',', $this->htmlAreaRTE->cleanList($inlineElementsOrder), TRUE), $hideItems);
181 if (!in_array('*', $restrictTo)) {
182 $inlineElementsOrder = array_intersect($inlineElementsOrder, $restrictTo);
183 }
184 // Localizing the options
185 $inlineElementsOptions = array();
186 foreach ($inlineElementsOrder as $item) {
187 $inlineElementsOptions[$this->buttonToInlineElement[$item]] = $this->getLanguageService()->sL(
188 'LLL:EXT:rtehtmlarea/Resources/Private/Language/Plugins/InlineElements/locallang.xlf:' . $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 $first = array_shift($inlineElementsOptions);
193 // Sorting the options
194 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.']['formattext.']) || !$this->thisConfig['buttons.']['formattext.']['orderItems']) {
195 asort($inlineElementsOptions);
196 }
197 // Generating the javascript options
198 $JSInlineElements = array();
199 $JSInlineElements[] = array($first, 'none');
200 foreach ($inlineElementsOptions as $item => $label) {
201 $JSInlineElements[] = array($label, $item);
202 }
203 if ($this->htmlAreaRTE->is_FE()) {
204 $GLOBALS['TSFE']->csConvObj->convArray($JSInlineElements, $this->htmlAreaRTE->OutputCharset, 'utf-8');
205 }
206 $registerRTEinJavascriptString .= '
207 RTEarea[' . $rteNumberPlaceholder . '].buttons.formattext.options = ' . json_encode($JSInlineElements) . ';';
208 }
209 return $registerRTEinJavascriptString;
210 }
211
212 }