TYPO3  7.6
BlockElements.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 = 'BlockElements';
31 
37  protected $pluginButtons = 'formatblock, indent, outdent, blockquote, insertparagraphbefore, insertparagraphafter, left, center, right, justifyfull, orderedlist, unorderedlist, line';
38 
45  'formatblock' => 'FormatBlock',
46  'indent' => 'Indent',
47  'outdent' => 'Outdent',
48  'blockquote' => 'Blockquote',
49  'insertparagraphbefore' => 'InsertParagraphBefore',
50  'insertparagraphafter' => 'InsertParagraphAfter',
51  'left' => 'JustifyLeft',
52  'center' => 'JustifyCenter',
53  'right' => 'JustifyRight',
54  'justifyfull' => 'JustifyFull',
55  'orderedlist' => 'InsertOrderedList',
56  'unorderedlist' => 'InsertUnorderedList',
57  'line' => 'InsertHorizontalRule'
58  );
59 
65  protected $defaultBlockElements = array(
66  'none' => 'No block',
67  'p' => 'Paragraph',
68  'h1' => 'Heading 1',
69  'h2' => 'Heading 2',
70  'h3' => 'Heading 3',
71  'h4' => 'Heading 4',
72  'h5' => 'Heading 5',
73  'h6' => 'Heading 6',
74  'pre' => 'Preformatted',
75  'address' => 'Address',
76  'article' => 'Article',
77  'aside' => 'Aside',
78  'blockquote' => 'Long quotation',
79  'div' => 'Container',
80  'footer' => 'Footer',
81  'header' => 'Header',
82  'nav' => 'Navigation',
83  'section' => 'Section'
84  );
85 
91  protected $defaultBlockElementsOrder = 'none, p, h1, h2, h3, h4, h5, h6, pre, address, article, aside, blockquote, div, footer, header, nav, section';
92 
98  public function buildJavascriptConfiguration()
99  {
100  $jsArray = array();
101  if (in_array('formatblock', $this->toolbar)) {
102  if (!is_array($this->configuration['thisConfig']['buttons.']) || !is_array($this->configuration['thisConfig']['buttons.']['formatblock.'])) {
103  $jsArray[] = 'RTEarea[editornumber].buttons.formatblock = new Object();';
104  }
105  // Default block elements
106  $hideItems = array();
107  $addItems = array();
108  $restrictTo = array('*');
109  $blockElementsOrder = $this->defaultBlockElementsOrder;
110  $prefixLabelWithTag = false;
111  $postfixLabelWithTag = false;
112  // Processing PageTSConfig
113  if (is_array($this->configuration['thisConfig']['buttons.']) && is_array($this->configuration['thisConfig']['buttons.']['formatblock.'])) {
114  // Removing elements
115  if ($this->configuration['thisConfig']['buttons.']['formatblock.']['removeItems']) {
116  $hideItems = GeneralUtility::trimExplode(',', $this->cleanList(GeneralUtility::strtolower($this->configuration['thisConfig']['buttons.']['formatblock.']['removeItems'])), true);
117  }
118  // Adding elements
119  if ($this->configuration['thisConfig']['buttons.']['formatblock.']['addItems']) {
120  $addItems = GeneralUtility::trimExplode(',', $this->cleanList(GeneralUtility::strtolower($this->configuration['thisConfig']['buttons.']['formatblock.']['addItems'])), true);
121  }
122  // Restriction clause
123  if ($this->configuration['thisConfig']['buttons.']['formatblock.']['restrictToItems']) {
124  $restrictTo = GeneralUtility::trimExplode(',', $this->cleanList('none,' . GeneralUtility::strtolower($this->configuration['thisConfig']['buttons.']['formatblock.']['restrictToItems'])), true);
125  }
126  // Elements order
127  if ($this->configuration['thisConfig']['buttons.']['formatblock.']['orderItems']) {
128  $blockElementsOrder = 'none,' . GeneralUtility::strtolower($this->configuration['thisConfig']['buttons.']['formatblock.']['orderItems']);
129  }
130  $prefixLabelWithTag = $this->configuration['thisConfig']['buttons.']['formatblock.']['prefixLabelWithTag'] ? true : $prefixLabelWithTag;
131  $postfixLabelWithTag = $this->configuration['thisConfig']['buttons.']['formatblock.']['postfixLabelWithTag'] ? true : $postfixLabelWithTag;
132  }
133  // Adding custom items
134  $blockElementsOrder = array_merge(GeneralUtility::trimExplode(',', $this->cleanList($blockElementsOrder), true), $addItems);
135  // Add div element if indent is configured in the toolbar
136  if (in_array('indent', $this->toolbar) || in_array('outdent', $this->toolbar)) {
137  $blockElementsOrder = array_merge($blockElementsOrder, array('div'));
138  }
139  // Add blockquote element if blockquote is configured in the toolbar
140  if (in_array('blockquote', $this->toolbar)) {
141  $blockElementsOrder = array_merge($blockElementsOrder, array('blockquote'));
142  }
143  // Remove items
144  $blockElementsOrder = array_diff($blockElementsOrder, $hideItems);
145  // Applying User TSConfig restriction
146  if (!in_array('*', $restrictTo)) {
147  $blockElementsOrder = array_intersect($blockElementsOrder, $restrictTo);
148  }
149  // Localizing the options
150  $blockElementsOptions = array();
151  $labels = array();
152  if (is_array($this->configuration['thisConfig']['buttons.']) && is_array($this->configuration['thisConfig']['buttons.']['formatblock.']) && is_array($this->configuration['thisConfig']['buttons.']['formatblock.']['items.'])) {
153  $labels = $this->configuration['thisConfig']['buttons.']['formatblock.']['items.'];
154  }
155  foreach ($blockElementsOrder as $item) {
156  $blockElementsOptions[$item] = $this->getLanguageService()->sL(
157  'LLL:EXT:rtehtmlarea/Resources/Private/Language/Plugins/BlockElements/locallang.xlf:' . $this->defaultBlockElements[$item]
158  );
159  // Getting custom labels
160  if (is_array($labels[$item . '.']) && $labels[$item . '.']['label']) {
161  $blockElementsOptions[$item] = $this->getPageConfigLabel($labels[$item . '.']['label']);
162  }
163  $blockElementsOptions[$item] = ($prefixLabelWithTag && $item != 'none' ? $item . ' - ' : '') . $blockElementsOptions[$item] . ($postfixLabelWithTag && $item != 'none' ? ' - ' . $item : '');
164  }
165  $first = array_shift($blockElementsOptions);
166  // Sorting the options
167  if (!is_array($this->configuration['thisConfig']['buttons.']) || !is_array($this->configuration['thisConfig']['buttons.']['formatblock.']) || !$this->configuration['thisConfig']['buttons.']['formatblock.']['orderItems']) {
168  asort($blockElementsOptions);
169  }
170  // Generating the javascript options
171  $JSBlockElements = array();
172  $JSBlockElements[] = array($first, 'none');
173  foreach ($blockElementsOptions as $item => $label) {
174  $JSBlockElements[] = array($label, $item);
175  }
176  $jsArray[] = 'RTEarea[editornumber].buttons.formatblock.options = ' . json_encode($JSBlockElements) . ';';
177  }
178  return implode(LF, $jsArray);
179  }
180 }