[FEATURE][!!!][CONF] Deprecate various RTE configuration properties
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / extensions / BlockElements / class.tx_rtehtmlarea_blockelements.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007-2011 Stanislas Rolland <typo3(arobas)sjbr.ca>
6 * All rights reserved
7 *
8 * This script is part of the Typo3 project. The Typo3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24 /**
25 * BlockElements extension for htmlArea RTE
26 *
27 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
28 *
29 */
30 class tx_rtehtmlarea_blockelements extends tx_rtehtmlarea_api {
31
32 protected $extensionKey = 'rtehtmlarea'; // The key of the extension that is extending htmlArea RTE
33 protected $pluginName = 'BlockElements'; // The name of the plugin registered by the extension
34 protected $relativePathToLocallangFile = 'extensions/BlockElements/locallang.xml'; // Path to this main locallang file of the extension relative to the extension dir.
35 protected $relativePathToSkin = 'extensions/BlockElements/skin/htmlarea.css'; // Path to the skin (css) file relative to the extension dir
36 protected $htmlAreaRTE; // Reference to the invoking object
37 protected $thisConfig; // Reference to RTE PageTSConfig
38 protected $toolbar; // Reference to RTE toolbar array
39 protected $LOCAL_LANG; // Frontend language array
40
41 protected $pluginButtons = 'formatblock, indent, outdent, blockquote, insertparagraphbefore, insertparagraphafter, left, center, right, justifyfull, orderedlist, unorderedlist, line';
42 protected $convertToolbarForHtmlAreaArray = array (
43 'formatblock' => 'FormatBlock',
44 'indent' => 'Indent',
45 'outdent' => 'Outdent',
46 'blockquote' => 'Blockquote',
47 'insertparagraphbefore' => 'InsertParagraphBefore',
48 'insertparagraphafter' => 'InsertParagraphAfter',
49 'left' => 'JustifyLeft',
50 'center' => 'JustifyCenter',
51 'right' => 'JustifyRight',
52 'justifyfull' => 'JustifyFull',
53 'orderedlist' => 'InsertOrderedList',
54 'unorderedlist' => 'InsertUnorderedList',
55 'line' => 'InsertHorizontalRule',
56 );
57
58 protected $defaultBlockElements = array(
59 'none' => 'No block',
60 'p' => 'Paragraph',
61 'h1' => 'Heading 1',
62 'h2' => 'Heading 2',
63 'h3' => 'Heading 3',
64 'h4' => 'Heading 4',
65 'h5' => 'Heading 5',
66 'h6' => 'Heading 6',
67 'pre' => 'Preformatted',
68 'address' => 'Address',
69 'blockquote' => 'Long quotation',
70 'div' => 'Section',
71 );
72
73 protected $defaultBlockElementsOrder = 'none, p, h1, h2, h3, h4, h5, h6, pre, address, blockquote, div';
74
75 /**
76 * Return JS configuration of the htmlArea plugins registered by the extension
77 *
78 * @param integer Relative id of the RTE editing area in the form
79 *
80 * @return string JS configuration for registered plugins, in this case, JS configuration of block elements
81 *
82 * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
83 * Each of the instructions should be of the form:
84 * RTEarea['.$RTEcounter.']["buttons"]["button-id"]["property"] = "value";
85 */
86 public function buildJavascriptConfiguration($RTEcounter) {
87 global $TSFE, $LANG;
88
89 $registerRTEinJavascriptString = '';
90 if (in_array('formatblock', $this->toolbar)) {
91 if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.']['formatblock.'])) {
92 $registerRTEinJavascriptString .= '
93 RTEarea['.$RTEcounter.'].buttons.formatblock = new Object();';
94 }
95 // Default block elements
96 $hideItems = array();
97 $addItems = array();
98 $restrictTo = array('*');
99 $blockElementsOrder = $this->defaultBlockElementsOrder;
100 $prefixLabelWithTag = FALSE;
101 $postfixLabelWithTag = FALSE;
102
103 // Processing PageTSConfig
104 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['formatblock.'])) {
105 // Removing elements
106 if ($this->thisConfig['buttons.']['formatblock.']['removeItems']) {
107 if ($this->htmlAreaRTE->cleanList($this->thisConfig['buttons.']['formatblock.']['removeItems']) == '*') {
108 $hideItems = array_diff(array_keys($defaultBlockElements), array('none'));
109 } else {
110 $hideItems = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList(t3lib_div::strtolower($this->thisConfig['buttons.']['formatblock.']['removeItems'])), 1);
111 }
112 }
113 // Adding elements
114 if ($this->thisConfig['buttons.']['formatblock.']['addItems']) {
115 $addItems = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList(t3lib_div::strtolower($this->thisConfig['buttons.']['formatblock.']['addItems'])), 1);
116 }
117 // Restriction clause
118 if ($this->thisConfig['buttons.']['formatblock.']['restrictToItems']) {
119 $restrictTo = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList('none,'.t3lib_div::strtolower($this->thisConfig['buttons.']['formatblock.']['restrictToItems'])), 1);
120 }
121 // Elements order
122 if ($this->thisConfig['buttons.']['formatblock.']['orderItems']) {
123 $blockElementsOrder = 'none,'.t3lib_div::strtolower($this->thisConfig['buttons.']['formatblock.']['orderItems']);
124 }
125 $prefixLabelWithTag = ($this->thisConfig['buttons.']['formatblock.']['prefixLabelWithTag']) ? TRUE : $prefixLabelWithTag;
126 $postfixLabelWithTag = ($this->thisConfig['buttons.']['formatblock.']['postfixLabelWithTag']) ? TRUE : $postfixLabelWithTag;
127 }
128 // Processing old style configuration for hiding paragraphs
129 // DEPRECATED property will be removed in TYPO3 4.8
130 if (isset($this->thisConfig['hidePStyleItems'])) {
131 $hideItems = array_merge($hideItems, t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList(t3lib_div::strtolower($this->thisConfig['hidePStyleItems'])), 1));
132 $this->htmlAreaRTE->logDeprecatedProperty('hidePStyleItems', 'buttons.formatblock.removeItems', '4.8');
133 }
134 // Adding custom items
135 $blockElementsOrder = array_merge(t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList($blockElementsOrder), 1), $addItems);
136 // Applying User TSConfig restriction
137 $blockElementsOrder = array_diff($blockElementsOrder, $hideItems);
138 if (!in_array('*', $restrictTo)) {
139 $blockElementsOrder = array_intersect($blockElementsOrder, $restrictTo);
140 }
141 // Localizing the options
142 $blockElementsOptions = array();
143 $labels = array();
144 if (is_array($this->thisConfig['buttons.'])
145 && is_array($this->thisConfig['buttons.']['formatblock.'])
146 && is_array($this->thisConfig['buttons.']['formatblock.']['items.'])) {
147 $labels = $this->thisConfig['buttons.']['formatblock.']['items.'];
148 }
149 foreach ($blockElementsOrder as $item) {
150 if ($this->htmlAreaRTE->is_FE()) {
151 $blockElementsOptions[$item] = $TSFE->getLLL($this->defaultBlockElements[$item], $this->LOCAL_LANG);
152 } else {
153 $blockElementsOptions[$item] = $LANG->getLL($this->defaultBlockElements[$item]);
154 }
155 // Getting custom labels
156 if (is_array($labels[$item.'.']) && $labels[$item.'.']['label']) {
157 $blockElementsOptions[$item] = $this->htmlAreaRTE->getPageConfigLabel($labels[$item.'.']['label'], 0);
158 }
159 $blockElementsOptions[$item] = (($prefixLabelWithTag && $item != 'none')?($item . ' - '):'') . $blockElementsOptions[$item] . (($postfixLabelWithTag && $item != 'none')?(' - ' . $item):'');
160 }
161
162 $first = array_shift($blockElementsOptions);
163 // Sorting the options
164 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.']['formatblock.']) || !$this->thisConfig['buttons.']['formatblock.']['orderItems']) {
165 asort($blockElementsOptions);
166 }
167 // Generating the javascript options
168 $JSBlockElements = array();
169 $JSBlockElements[] = array($first, 'none');
170 foreach ($blockElementsOptions as $item => $label) {
171 $JSBlockElements[] = array($label, $item);
172 }
173 if ($this->htmlAreaRTE->is_FE()) {
174 $GLOBALS['TSFE']->csConvObj->convArray($JSBlockElements, $this->htmlAreaRTE->OutputCharset, 'utf-8');
175 } else {
176 $GLOBALS['LANG']->csConvObj->convArray($JSBlockElements, $GLOBALS['LANG']->charSet, 'utf-8');
177 }
178 $registerRTEinJavascriptString .= '
179 RTEarea['.$RTEcounter.'].buttons.formatblock.options = ' . json_encode($JSBlockElements) . ';';
180 }
181 return $registerRTEinJavascriptString;
182 }
183 }
184 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/BlockElements/class.tx_rtehtmlarea_blockelements.php'])) {
185 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/BlockElements/class.tx_rtehtmlarea_blockelements.php']);
186 }
187 ?>