TYPO3 CMS  TYPO3_6-2
BlockElements.php
Go to the documentation of this file.
1 <?php
3 
22 
23  protected $extensionKey = 'rtehtmlarea';
24 
25  // The key of the extension that is extending htmlArea RTE
26  protected $pluginName = 'BlockElements';
27 
28  // The name of the plugin registered by the extension
29  protected $relativePathToLocallangFile = 'extensions/BlockElements/locallang.xlf';
30 
31  // Path to this main locallang file of the extension relative to the extension dir.
32  protected $relativePathToSkin = 'extensions/BlockElements/skin/htmlarea.css';
33 
34  // Path to the skin (css) file relative to the extension dir
35  protected $htmlAreaRTE;
36 
37  // Reference to the invoking object
38  protected $thisConfig;
39 
40  // Reference to RTE PageTSConfig
41  protected $toolbar;
42 
43  // Reference to RTE toolbar array
44  protected $LOCAL_LANG;
45 
46  // Frontend language array
47  protected $pluginButtons = 'formatblock, indent, outdent, blockquote, insertparagraphbefore, insertparagraphafter, left, center, right, justifyfull, orderedlist, unorderedlist, line';
48 
50  'formatblock' => 'FormatBlock',
51  'indent' => 'Indent',
52  'outdent' => 'Outdent',
53  'blockquote' => 'Blockquote',
54  'insertparagraphbefore' => 'InsertParagraphBefore',
55  'insertparagraphafter' => 'InsertParagraphAfter',
56  'left' => 'JustifyLeft',
57  'center' => 'JustifyCenter',
58  'right' => 'JustifyRight',
59  'justifyfull' => 'JustifyFull',
60  'orderedlist' => 'InsertOrderedList',
61  'unorderedlist' => 'InsertUnorderedList',
62  'line' => 'InsertHorizontalRule'
63  );
64 
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 
86  protected $defaultBlockElementsOrder = 'none, p, h1, h2, h3, h4, h5, h6, pre, address, article, aside, blockquote, div, footer, header, nav, section';
87 
94  public function buildJavascriptConfiguration($RTEcounter) {
95  global $TSFE, $LANG;
96  $registerRTEinJavascriptString = '';
97  if (in_array('formatblock', $this->toolbar)) {
98  if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.']['formatblock.'])) {
99  $registerRTEinJavascriptString .= '
100  RTEarea[' . $RTEcounter . '].buttons.formatblock = new Object();';
101  }
102  // Default block elements
103  $hideItems = array();
104  $addItems = array();
105  $restrictTo = array('*');
106  $blockElementsOrder = $this->defaultBlockElementsOrder;
107  $prefixLabelWithTag = FALSE;
108  $postfixLabelWithTag = FALSE;
109  // Processing PageTSConfig
110  if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['formatblock.'])) {
111  // Removing elements
112  if ($this->thisConfig['buttons.']['formatblock.']['removeItems']) {
113  if ($this->htmlAreaRTE->cleanList($this->thisConfig['buttons.']['formatblock.']['removeItems']) == '*') {
114  $hideItems = array_diff(array_keys($defaultBlockElements), array('none'));
115  } else {
116  $hideItems = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->htmlAreaRTE->cleanList(\TYPO3\CMS\Core\Utility\GeneralUtility::strtolower($this->thisConfig['buttons.']['formatblock.']['removeItems'])), TRUE);
117  }
118  }
119  // Adding elements
120  if ($this->thisConfig['buttons.']['formatblock.']['addItems']) {
121  $addItems = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->htmlAreaRTE->cleanList(\TYPO3\CMS\Core\Utility\GeneralUtility::strtolower($this->thisConfig['buttons.']['formatblock.']['addItems'])), TRUE);
122  }
123  // Restriction clause
124  if ($this->thisConfig['buttons.']['formatblock.']['restrictToItems']) {
125  $restrictTo = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->htmlAreaRTE->cleanList('none,' . \TYPO3\CMS\Core\Utility\GeneralUtility::strtolower($this->thisConfig['buttons.']['formatblock.']['restrictToItems'])), TRUE);
126  }
127  // Elements order
128  if ($this->thisConfig['buttons.']['formatblock.']['orderItems']) {
129  $blockElementsOrder = 'none,' . \TYPO3\CMS\Core\Utility\GeneralUtility::strtolower($this->thisConfig['buttons.']['formatblock.']['orderItems']);
130  }
131  $prefixLabelWithTag = $this->thisConfig['buttons.']['formatblock.']['prefixLabelWithTag'] ? TRUE : $prefixLabelWithTag;
132  $postfixLabelWithTag = $this->thisConfig['buttons.']['formatblock.']['postfixLabelWithTag'] ? TRUE : $postfixLabelWithTag;
133  }
134  // Adding custom items
135  $blockElementsOrder = array_merge(\TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->htmlAreaRTE->cleanList($blockElementsOrder), TRUE), $addItems);
136  // Add div element if indent is configured in the toolbar
137  if (in_array('indent', $this->toolbar) || in_array('outdent', $this->toolbar)) {
138  $blockElementsOrder = array_merge($blockElementsOrder, array('div'));
139  }
140  // Add blockquote element if blockquote is configured in the toolbar
141  if (in_array('blockquote', $this->toolbar)) {
142  $blockElementsOrder = array_merge($blockElementsOrder, array('blockquote'));
143  }
144  // Remove items
145  $blockElementsOrder = array_diff($blockElementsOrder, $hideItems);
146  // Applying User TSConfig restriction
147  if (!in_array('*', $restrictTo)) {
148  $blockElementsOrder = array_intersect($blockElementsOrder, $restrictTo);
149  }
150  // Localizing the options
151  $blockElementsOptions = array();
152  $labels = array();
153  if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['formatblock.']) && is_array($this->thisConfig['buttons.']['formatblock.']['items.'])) {
154  $labels = $this->thisConfig['buttons.']['formatblock.']['items.'];
155  }
156  foreach ($blockElementsOrder as $item) {
157  if ($this->htmlAreaRTE->is_FE()) {
158  $blockElementsOptions[$item] = $TSFE->getLLL($this->defaultBlockElements[$item], $this->LOCAL_LANG);
159  } else {
160  $blockElementsOptions[$item] = $LANG->getLL($this->defaultBlockElements[$item]);
161  }
162  // Getting custom labels
163  if (is_array($labels[$item . '.']) && $labels[$item . '.']['label']) {
164  $blockElementsOptions[$item] = $this->htmlAreaRTE->getPageConfigLabel($labels[$item . '.']['label'], 0);
165  }
166  $blockElementsOptions[$item] = ($prefixLabelWithTag && $item != 'none' ? $item . ' - ' : '') . $blockElementsOptions[$item] . ($postfixLabelWithTag && $item != 'none' ? ' - ' . $item : '');
167  }
168  $first = array_shift($blockElementsOptions);
169  // Sorting the options
170  if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.']['formatblock.']) || !$this->thisConfig['buttons.']['formatblock.']['orderItems']) {
171  asort($blockElementsOptions);
172  }
173  // Generating the javascript options
174  $JSBlockElements = array();
175  $JSBlockElements[] = array($first, 'none');
176  foreach ($blockElementsOptions as $item => $label) {
177  $JSBlockElements[] = array($label, $item);
178  }
179  if ($this->htmlAreaRTE->is_FE()) {
180  $GLOBALS['TSFE']->csConvObj->convArray($JSBlockElements, $this->htmlAreaRTE->OutputCharset, 'utf-8');
181  }
182  $registerRTEinJavascriptString .= '
183  RTEarea[' . $RTEcounter . '].buttons.formatblock.options = ' . json_encode($JSBlockElements) . ';';
184  }
185  return $registerRTEinJavascriptString;
186  }
187 
188 }
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
$TSFE
Definition: index_ts.php:72
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]