TYPO3  7.6
InlineElements.php
Go to the documentation of this file.
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 
19 
24 {
30  protected $pluginName = 'InlineElements';
31 
37  protected $pluginButtons = 'formattext, bidioverride, big, bold, citation, code, definition, deletedtext, emphasis, insertedtext, italic, keyboard, quotation, sample, small, span, strikethrough, strong, subscript, superscript, underline, variable';
38 
45  'formattext' => 'FormatText',
46  'bidioverride' => 'BiDiOverride',
47  'big' => 'Big',
48  'bold' => 'Bold',
49  'citation' => 'Citation',
50  'code' => 'Code',
51  'definition' => 'Definition',
52  'deletedtext' => 'DeletedText',
53  'emphasis' => 'Emphasis',
54  'insertedtext' => 'InsertedText',
55  'italic' => 'Italic',
56  'keyboard' => 'Keyboard',
57  'monospaced' => 'MonoSpaced',
58  'quotation' => 'Quotation',
59  'sample' => 'Sample',
60  'small' => 'Small',
61  'span' => 'Span',
62  'strikethrough' => 'StrikeThrough',
63  'strong' => 'Strong',
64  'subscript' => 'Subscript',
65  'superscript' => 'Superscript',
66  'underline' => 'Underline',
67  'variable' => 'Variable'
68  );
69 
75  protected $defaultInlineElements = array(
76  'none' => 'No markup',
77  'b' => 'Bold',
78  'bdo' => 'BiDi override',
79  'big' => 'Large text',
80  'cite' => 'Citation',
81  'code' => 'Code',
82  'del' => 'Deleted text',
83  'dfn' => 'Definition',
84  'em' => 'Emphasis',
85  'i' => 'Italic',
86  'ins' => 'Inserted text',
87  'kbd' => 'Keyboard',
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 
106  protected $defaultInlineElementsOrder = 'none, bidioverride, big, bold, citation, code, definition, deletedtext, emphasis, insertedtext, italic, keyboard,
107  monospaced, quotation, sample, small, span, strikethrough, strong, subscript, superscript, underline, variable';
108 
114  protected $buttonToInlineElement = array(
115  'none' => 'none',
116  'bidioverride' => 'bdo',
117  'big' => 'big',
118  'bold' => 'b',
119  'citation' => 'cite',
120  'code' => 'code',
121  'definition' => 'dfn',
122  'deletedtext' => 'del',
123  'emphasis' => 'em',
124  'insertedtext' => 'ins',
125  'italic' => 'i',
126  'keyboard' => 'kbd',
127  'monospaced' => 'tt',
128  'quotation' => 'q',
129  'sample' => 'samp',
130  'small' => 'small',
131  'span' => 'span',
132  'strikethrough' => 'strike',
133  'strong' => 'strong',
134  'subscript' => 'sub',
135  'superscript' => 'sup',
136  'underline' => 'u',
137  'variable' => 'var'
138  );
139 
146  {
147  $jsArray = array();
148  if (in_array('formattext', $this->toolbar)) {
149  if (!is_array($this->configuration['thisConfig']['buttons.']) || !is_array($this->configuration['thisConfig']['buttons.']['formattext.'])) {
150  $jsArray[] = 'RTEarea[editornumber].buttons.formattext = new Object();';
151  }
152  // Default inline elements
153  $hideItems = array();
154  $restrictTo = array('*');
155  $inlineElementsOrder = $this->defaultInlineElementsOrder;
156  $prefixLabelWithTag = false;
157  $postfixLabelWithTag = false;
158  // Processing PageTSConfig
159  if (is_array($this->configuration['thisConfig']['buttons.']) && is_array($this->configuration['thisConfig']['buttons.']['formattext.'])) {
160  // Removing elements
161  if ($this->configuration['thisConfig']['buttons.']['formattext.']['removeItems']) {
162  $hideItems = GeneralUtility::trimExplode(',', $this->cleanList($this->configuration['thisConfig']['buttons.']['formattext.']['removeItems']), true);
163  }
164  // Restriction clause
165  if ($this->configuration['thisConfig']['buttons.']['formattext.']['restrictTo']) {
166  $restrictTo = GeneralUtility::trimExplode(',', $this->cleanList('none,' . $this->configuration['thisConfig']['buttons.']['formattext.']['restrictTo']), true);
167  } elseif ($this->configuration['thisConfig']['buttons.']['formattext.']['restrictToItems']) {
168  $restrictTo = GeneralUtility::trimExplode(',', $this->cleanList('none,' . $this->configuration['thisConfig']['buttons.']['formattext.']['restrictToItems']), true);
169  }
170  // Elements order
171  if ($this->configuration['thisConfig']['buttons.']['formattext.']['orderItems']) {
172  $inlineElementsOrder = 'none,' . $this->configuration['thisConfig']['buttons.']['formattext.']['orderItems'];
173  }
174  $prefixLabelWithTag = $this->configuration['thisConfig']['buttons.']['formattext.']['prefixLabelWithTag'] ? true : $prefixLabelWithTag;
175  $postfixLabelWithTag = $this->configuration['thisConfig']['buttons.']['formattext.']['postfixLabelWithTag'] ? true : $postfixLabelWithTag;
176  }
177  $inlineElementsOrder = array_diff(GeneralUtility::trimExplode(',', $this->cleanList($inlineElementsOrder), true), $hideItems);
178  if (!in_array('*', $restrictTo)) {
179  $inlineElementsOrder = array_intersect($inlineElementsOrder, $restrictTo);
180  }
181  // Localizing the options
182  $inlineElementsOptions = array();
183  foreach ($inlineElementsOrder as $item) {
184  $inlineElementsOptions[$this->buttonToInlineElement[$item]] = $this->getLanguageService()->sL(
185  'LLL:EXT:rtehtmlarea/Resources/Private/Language/Plugins/InlineElements/locallang.xlf:' . $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  $first = array_shift($inlineElementsOptions);
190  // Sorting the options
191  if (!is_array($this->configuration['thisConfig']['buttons.']) || !is_array($this->configuration['thisConfig']['buttons.']['formattext.']) || !$this->configuration['thisConfig']['buttons.']['formattext.']['orderItems']) {
192  asort($inlineElementsOptions);
193  }
194  // Generating the javascript options
195  $JSInlineElements = array();
196  $JSInlineElements[] = array($first, 'none');
197  foreach ($inlineElementsOptions as $item => $label) {
198  $JSInlineElements[] = array($label, $item);
199  }
200  $jsArray[] = 'RTEarea[editornumber].buttons.formattext.options = ' . json_encode($JSInlineElements) . ';';
201  }
202  return implode(LF, $jsArray);
203  }
204 }