[TASK] RTE: Remove unused css files
[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 * Path to this main locallang file of the extension relative to the extension directory
36 *
37 * @var string
38 */
39 protected $relativePathToLocallangFile = 'extensions/InlineElements/locallang.xlf';
40
41 /**
42 * The comma-separated list of button names that the registered plugin is adding to the htmlArea RTE toolbar
43 *
44 * @var string
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 /**
49 * The name-converting array, converting the button names used in the RTE PageTSConfing to the button id's used by the JS scripts
50 *
51 * @var array
52 */
53 protected $convertToolbarForHtmlAreaArray = array(
54 'formattext' => 'FormatText',
55 'bidioverride' => 'BiDiOverride',
56 'big' => 'Big',
57 'bold' => 'Bold',
58 'citation' => 'Citation',
59 'code' => 'Code',
60 'definition' => 'Definition',
61 'deletedtext' => 'DeletedText',
62 'emphasis' => 'Emphasis',
63 'insertedtext' => 'InsertedText',
64 'italic' => 'Italic',
65 'keyboard' => 'Keyboard',
66 'monospaced' => 'MonoSpaced',
67 'quotation' => 'Quotation',
68 'sample' => 'Sample',
69 'small' => 'Small',
70 'span' => 'Span',
71 'strikethrough' => 'StrikeThrough',
72 'strong' => 'Strong',
73 'subscript' => 'Subscript',
74 'superscript' => 'Superscript',
75 'underline' => 'Underline',
76 'variable' => 'Variable'
77 );
78
79 /**
80 * Default list of inline elements
81 *
82 * @var array
83 */
84 protected $defaultInlineElements = array(
85 'none' => 'No markup',
86 'b' => 'Bold',
87 'bdo' => 'BiDi override',
88 'big' => 'Large text',
89 'cite' => 'Citation',
90 'code' => 'Code',
91 'del' => 'Deleted text',
92 'dfn' => 'Definition',
93 'em' => 'Emphasis',
94 'i' => 'Italic',
95 'ins' => 'Inserted text',
96 'kbd' => 'Keyboard',
97 'q' => 'Quotation',
98 'samp' => 'Sample',
99 'small' => 'Small text',
100 'span' => 'Style container',
101 'strike' => 'Strike-through',
102 'strong' => 'Strong emphasis',
103 'sub' => 'Subscript',
104 'sup' => 'Superscript',
105 'tt' => 'Monospaced text',
106 'u' => 'Underline',
107 'var' => 'Variable'
108 );
109
110 /**
111 * Default order of inline elements
112 *
113 * @var string
114 */
115 protected $defaultInlineElementsOrder = 'none, bidioverride, big, bold, citation, code, definition, deletedtext, emphasis, insertedtext, italic, keyboard,
116 monospaced, quotation, sample, small, span, strikethrough, strong, subscript, superscript, underline, variable';
117
118 /**
119 * Button names to inline elements
120 *
121 * @var array
122 */
123 protected $buttonToInlineElement = array(
124 'none' => 'none',
125 'bidioverride' => 'bdo',
126 'big' => 'big',
127 'bold' => 'b',
128 'citation' => 'cite',
129 'code' => 'code',
130 'definition' => 'dfn',
131 'deletedtext' => 'del',
132 'emphasis' => 'em',
133 'insertedtext' => 'ins',
134 'italic' => 'i',
135 'keyboard' => 'kbd',
136 'monospaced' => 'tt',
137 'quotation' => 'q',
138 'sample' => 'samp',
139 'small' => 'small',
140 'span' => 'span',
141 'strikethrough' => 'strike',
142 'strong' => 'strong',
143 'subscript' => 'sub',
144 'superscript' => 'sup',
145 'underline' => 'u',
146 'variable' => 'var'
147 );
148
149 /**
150 * Return JS configuration of the htmlArea plugins registered by the extension
151 *
152 * @param string $rteNumberPlaceholder A dummy string for JS arrays
153 * @return string JS configuration for registered plugins
154 */
155 public function buildJavascriptConfiguration($rteNumberPlaceholder) {
156 $registerRTEinJavascriptString = '';
157 if (in_array('formattext', $this->toolbar)) {
158 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.']['formattext.'])) {
159 $registerRTEinJavascriptString .= '
160 RTEarea[' . $rteNumberPlaceholder . '].buttons.formattext = new Object();';
161 }
162 // Default inline elements
163 $hideItems = array();
164 $restrictTo = array('*');
165 $inlineElementsOrder = $this->defaultInlineElementsOrder;
166 $prefixLabelWithTag = FALSE;
167 $postfixLabelWithTag = FALSE;
168 // Processing PageTSConfig
169 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['formattext.'])) {
170 // Removing elements
171 if ($this->thisConfig['buttons.']['formattext.']['removeItems']) {
172 $hideItems = GeneralUtility::trimExplode(',', $this->htmlAreaRTE->cleanList($this->thisConfig['buttons.']['formattext.']['removeItems']), TRUE);
173 }
174 // Restriction clause
175 if ($this->thisConfig['buttons.']['formattext.']['restrictTo']) {
176 $restrictTo = GeneralUtility::trimExplode(',', $this->htmlAreaRTE->cleanList('none,' . $this->thisConfig['buttons.']['formattext.']['restrictTo']), TRUE);
177 } elseif ($this->thisConfig['buttons.']['formattext.']['restrictToItems']) {
178 $restrictTo = GeneralUtility::trimExplode(',', $this->htmlAreaRTE->cleanList('none,' . $this->thisConfig['buttons.']['formattext.']['restrictToItems']), TRUE);
179 }
180 // Elements order
181 if ($this->thisConfig['buttons.']['formattext.']['orderItems']) {
182 $inlineElementsOrder = 'none,' . $this->thisConfig['buttons.']['formattext.']['orderItems'];
183 }
184 $prefixLabelWithTag = $this->thisConfig['buttons.']['formattext.']['prefixLabelWithTag'] ? TRUE : $prefixLabelWithTag;
185 $postfixLabelWithTag = $this->thisConfig['buttons.']['formattext.']['postfixLabelWithTag'] ? TRUE : $postfixLabelWithTag;
186 }
187 $inlineElementsOrder = array_diff(GeneralUtility::trimExplode(',', $this->htmlAreaRTE->cleanList($inlineElementsOrder), TRUE), $hideItems);
188 if (!in_array('*', $restrictTo)) {
189 $inlineElementsOrder = array_intersect($inlineElementsOrder, $restrictTo);
190 }
191 // Localizing the options
192 $inlineElementsOptions = array();
193 foreach ($inlineElementsOrder as $item) {
194 if ($this->htmlAreaRTE->is_FE()) {
195 $inlineElementsOptions[$this->buttonToInlineElement[$item]] = $GLOBALS['TSFE']->getLLL($this->defaultInlineElements[$this->buttonToInlineElement[$item]], $this->LOCAL_LANG);
196 } else {
197 $inlineElementsOptions[$this->buttonToInlineElement[$item]] = $GLOBALS['LANG']->getLL($this->defaultInlineElements[$this->buttonToInlineElement[$item]]);
198 }
199 $inlineElementsOptions[$this->buttonToInlineElement[$item]] = ($prefixLabelWithTag && $item != 'none' ? $this->buttonToInlineElement[$item] . ' - ' : '') . $inlineElementsOptions[$this->buttonToInlineElement[$item]] . ($postfixLabelWithTag && $item != 'none' ? ' - ' . $this->buttonToInlineElement[$item] : '');
200 }
201 $first = array_shift($inlineElementsOptions);
202 // Sorting the options
203 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.']['formattext.']) || !$this->thisConfig['buttons.']['formattext.']['orderItems']) {
204 asort($inlineElementsOptions);
205 }
206 // Generating the javascript options
207 $JSInlineElements = array();
208 $JSInlineElements[] = array($first, 'none');
209 foreach ($inlineElementsOptions as $item => $label) {
210 $JSInlineElements[] = array($label, $item);
211 }
212 if ($this->htmlAreaRTE->is_FE()) {
213 $GLOBALS['TSFE']->csConvObj->convArray($JSInlineElements, $this->htmlAreaRTE->OutputCharset, 'utf-8');
214 }
215 $registerRTEinJavascriptString .= '
216 RTEarea[' . $rteNumberPlaceholder . '].buttons.formattext.options = ' . json_encode($JSInlineElements) . ';';
217 }
218 return $registerRTEinJavascriptString;
219 }
220
221 }