[TASK] RTE: Remove unused css files
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / Extension / BlockElements.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 * BlockElements extension for htmlArea RTE
22 *
23 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
24 */
25 class BlockElements extends RteHtmlAreaApi {
26
27 /**
28 * The name of the plugin registered by the extension
29 *
30 * @var string
31 */
32 protected $pluginName = 'BlockElements';
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/BlockElements/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 = 'formatblock, indent, outdent, blockquote, insertparagraphbefore, insertparagraphafter, left, center, right, justifyfull, orderedlist, unorderedlist, line';
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 'formatblock' => 'FormatBlock',
55 'indent' => 'Indent',
56 'outdent' => 'Outdent',
57 'blockquote' => 'Blockquote',
58 'insertparagraphbefore' => 'InsertParagraphBefore',
59 'insertparagraphafter' => 'InsertParagraphAfter',
60 'left' => 'JustifyLeft',
61 'center' => 'JustifyCenter',
62 'right' => 'JustifyRight',
63 'justifyfull' => 'JustifyFull',
64 'orderedlist' => 'InsertOrderedList',
65 'unorderedlist' => 'InsertUnorderedList',
66 'line' => 'InsertHorizontalRule'
67 );
68
69 /**
70 * List of default block elements
71 *
72 * @var array
73 */
74 protected $defaultBlockElements = array(
75 'none' => 'No block',
76 'p' => 'Paragraph',
77 'h1' => 'Heading 1',
78 'h2' => 'Heading 2',
79 'h3' => 'Heading 3',
80 'h4' => 'Heading 4',
81 'h5' => 'Heading 5',
82 'h6' => 'Heading 6',
83 'pre' => 'Preformatted',
84 'address' => 'Address',
85 'article' => 'Article',
86 'aside' => 'Aside',
87 'blockquote' => 'Long quotation',
88 'div' => 'Container',
89 'footer' => 'Footer',
90 'header' => 'Header',
91 'nav' => 'Navigation',
92 'section' => 'Section'
93 );
94
95 /**
96 * Default order of block elements
97 *
98 * @var string
99 */
100 protected $defaultBlockElementsOrder = 'none, p, h1, h2, h3, h4, h5, h6, pre, address, article, aside, blockquote, div, footer, header, nav, section';
101
102 /**
103 * Return JS configuration of the htmlArea plugins registered by the extension
104 *
105 * @param string $rteNumberPlaceholder A dummy string for JS arrays
106 * @return string JS configuration for registered plugins, in this case, JS configuration of block elements
107 */
108 public function buildJavascriptConfiguration($rteNumberPlaceholder) {
109 $registerRTEinJavascriptString = '';
110 if (in_array('formatblock', $this->toolbar)) {
111 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.']['formatblock.'])) {
112 $registerRTEinJavascriptString .= '
113 RTEarea[' . $rteNumberPlaceholder . '].buttons.formatblock = new Object();';
114 }
115 // Default block elements
116 $hideItems = array();
117 $addItems = array();
118 $restrictTo = array('*');
119 $blockElementsOrder = $this->defaultBlockElementsOrder;
120 $prefixLabelWithTag = FALSE;
121 $postfixLabelWithTag = FALSE;
122 // Processing PageTSConfig
123 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['formatblock.'])) {
124 // Removing elements
125 if ($this->thisConfig['buttons.']['formatblock.']['removeItems']) {
126 if ($this->htmlAreaRTE->cleanList($this->thisConfig['buttons.']['formatblock.']['removeItems']) == '*') {
127 $hideItems = array_diff(array_keys($defaultBlockElements), array('none'));
128 } else {
129 $hideItems = GeneralUtility::trimExplode(',', $this->htmlAreaRTE->cleanList(GeneralUtility::strtolower($this->thisConfig['buttons.']['formatblock.']['removeItems'])), TRUE);
130 }
131 }
132 // Adding elements
133 if ($this->thisConfig['buttons.']['formatblock.']['addItems']) {
134 $addItems = GeneralUtility::trimExplode(',', $this->htmlAreaRTE->cleanList(GeneralUtility::strtolower($this->thisConfig['buttons.']['formatblock.']['addItems'])), TRUE);
135 }
136 // Restriction clause
137 if ($this->thisConfig['buttons.']['formatblock.']['restrictToItems']) {
138 $restrictTo = GeneralUtility::trimExplode(',', $this->htmlAreaRTE->cleanList('none,' . GeneralUtility::strtolower($this->thisConfig['buttons.']['formatblock.']['restrictToItems'])), TRUE);
139 }
140 // Elements order
141 if ($this->thisConfig['buttons.']['formatblock.']['orderItems']) {
142 $blockElementsOrder = 'none,' . GeneralUtility::strtolower($this->thisConfig['buttons.']['formatblock.']['orderItems']);
143 }
144 $prefixLabelWithTag = $this->thisConfig['buttons.']['formatblock.']['prefixLabelWithTag'] ? TRUE : $prefixLabelWithTag;
145 $postfixLabelWithTag = $this->thisConfig['buttons.']['formatblock.']['postfixLabelWithTag'] ? TRUE : $postfixLabelWithTag;
146 }
147 // Adding custom items
148 $blockElementsOrder = array_merge(GeneralUtility::trimExplode(',', $this->htmlAreaRTE->cleanList($blockElementsOrder), TRUE), $addItems);
149 // Add div element if indent is configured in the toolbar
150 if (in_array('indent', $this->toolbar) || in_array('outdent', $this->toolbar)) {
151 $blockElementsOrder = array_merge($blockElementsOrder, array('div'));
152 }
153 // Add blockquote element if blockquote is configured in the toolbar
154 if (in_array('blockquote', $this->toolbar)) {
155 $blockElementsOrder = array_merge($blockElementsOrder, array('blockquote'));
156 }
157 // Remove items
158 $blockElementsOrder = array_diff($blockElementsOrder, $hideItems);
159 // Applying User TSConfig restriction
160 if (!in_array('*', $restrictTo)) {
161 $blockElementsOrder = array_intersect($blockElementsOrder, $restrictTo);
162 }
163 // Localizing the options
164 $blockElementsOptions = array();
165 $labels = array();
166 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['formatblock.']) && is_array($this->thisConfig['buttons.']['formatblock.']['items.'])) {
167 $labels = $this->thisConfig['buttons.']['formatblock.']['items.'];
168 }
169 foreach ($blockElementsOrder as $item) {
170 if ($this->htmlAreaRTE->is_FE()) {
171 $blockElementsOptions[$item] = $GLOBALS['TSFE']->getLLL($this->defaultBlockElements[$item], $this->LOCAL_LANG);
172 } else {
173 $blockElementsOptions[$item] = $GLOBALS['LANG']->getLL($this->defaultBlockElements[$item]);
174 }
175 // Getting custom labels
176 if (is_array($labels[$item . '.']) && $labels[$item . '.']['label']) {
177 $blockElementsOptions[$item] = $this->htmlAreaRTE->getPageConfigLabel($labels[$item . '.']['label'], 0);
178 }
179 $blockElementsOptions[$item] = ($prefixLabelWithTag && $item != 'none' ? $item . ' - ' : '') . $blockElementsOptions[$item] . ($postfixLabelWithTag && $item != 'none' ? ' - ' . $item : '');
180 }
181 $first = array_shift($blockElementsOptions);
182 // Sorting the options
183 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.']['formatblock.']) || !$this->thisConfig['buttons.']['formatblock.']['orderItems']) {
184 asort($blockElementsOptions);
185 }
186 // Generating the javascript options
187 $JSBlockElements = array();
188 $JSBlockElements[] = array($first, 'none');
189 foreach ($blockElementsOptions as $item => $label) {
190 $JSBlockElements[] = array($label, $item);
191 }
192 if ($this->htmlAreaRTE->is_FE()) {
193 $GLOBALS['TSFE']->csConvObj->convArray($JSBlockElements, $this->htmlAreaRTE->OutputCharset, 'utf-8');
194 }
195 $registerRTEinJavascriptString .= '
196 RTEarea[' . $rteNumberPlaceholder . '].buttons.formatblock.options = ' . json_encode($JSBlockElements) . ';';
197 }
198 return $registerRTEinJavascriptString;
199 }
200
201 }