* Fixed bug #7857: htmlArea RTE: hidePStyleItems does not work anymore
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / extensions / BlockElements / class.tx_rtehtmlarea_blockelements.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007-2208 Stanislas Rolland <stanislas.rolland(arobas)fructifor.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 <stanislas.rolland(arobas)fructifor.ca>
28 *
29 * TYPO3 SVN ID: $Id$
30 *
31 */
32
33 require_once(t3lib_extMgm::extPath('rtehtmlarea').'class.tx_rtehtmlareaapi.php');
34
35 class tx_rtehtmlarea_blockelements extends tx_rtehtmlareaapi {
36
37 protected $extensionKey = 'rtehtmlarea'; // The key of the extension that is extending htmlArea RTE
38 protected $pluginName = 'BlockElements'; // The name of the plugin registered by the extension
39 protected $relativePathToLocallangFile = 'extensions/BlockElements/locallang.xml'; // Path to this main locallang file of the extension relative to the extension dir.
40 protected $relativePathToSkin = 'extensions/BlockElements/skin/htmlarea.css'; // Path to the skin (css) file relative to the extension dir
41 protected $htmlAreaRTE; // Reference to the invoking object
42 protected $thisConfig; // Reference to RTE PageTSConfig
43 protected $toolbar; // Reference to RTE toolbar array
44 protected $LOCAL_LANG; // Frontend language array
45
46 protected $pluginButtons = 'formatblock, indent, outdent, blockquote, insertparagraphbefore, insertparagraphafter, left, center, right, justifyfull, orderedlist, unorderedlist';
47 protected $convertToolbarForHtmlAreaArray = array (
48 'formatblock' => 'FormatBlock',
49 'indent' => 'Indent',
50 'outdent' => 'Outdent',
51 'blockquote' => 'Blockquote',
52 'insertparagraphbefore' => 'InsertParagraphBefore',
53 'insertparagraphafter' => 'InsertParagraphAfter',
54 'left' => 'JustifyLeft',
55 'center' => 'JustifyCenter',
56 'right' => 'JustifyRight',
57 'justifyfull' => 'JustifyFull',
58 'orderedlist' => 'InsertOrderedList',
59 'unorderedlist' => 'InsertUnorderedList',
60 );
61
62 private $defaultBlockElements = array(
63 'none' => 'No block',
64 'p' => 'Paragraph',
65 'h1' => 'Heading 1',
66 'h2' => 'Heading 2',
67 'h3' => 'Heading 3',
68 'h4' => 'Heading 4',
69 'h5' => 'Heading 5',
70 'h6' => 'Heading 6',
71 'pre' => 'Preformatted',
72 'address' => 'Address',
73 'blockquote' => 'Long quotation',
74 'div' => 'Section',
75 );
76
77 private $defaultBlockElementsOrder = 'none, p, h1, h2, h3, h4, h5, h6, pre, address, blockquote, div';
78
79 /**
80 * Return JS configuration of the htmlArea plugins registered by the extension
81 *
82 * @param integer Relative id of the RTE editing area in the form
83 *
84 * @return string JS configuration for registered plugins, in this case, JS configuration of block elements
85 *
86 * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
87 * Each of the instructions should be of the form:
88 * RTEarea['.$RTEcounter.']["buttons"]["button-id"]["property"] = "value";
89 */
90 public function buildJavascriptConfiguration($RTEcounter) {
91 global $TSFE, $LANG;
92
93 $registerRTEinJavascriptString = '';
94 if (in_array('formatblock', $this->toolbar)) {
95 if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.']['formatblock.'])) {
96 $registerRTEinJavascriptString .= '
97 RTEarea['.$RTEcounter.'].buttons.formatblock = new Object();';
98 }
99 // Default block elements
100 $hideItems = array();
101 $restrictTo = array('*');
102 $blockElementsOrder = $this->defaultBlockElementsOrder;
103 $prefixLabelWithTag = false;
104 $postfixLabelWithTag = false;
105
106 // Processing PageTSConfig
107 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['formatblock.'])) {
108 // Removing elements
109 if ($this->thisConfig['buttons.']['formatblock.']['removeItems']) {
110 $hideItems = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList(strtolower($this->thisConfig['buttons.']['formatblock.']['removeItems'])), 1);
111 }
112 // Restriction clause
113 if ($this->thisConfig['buttons.']['formatblock.']['restrictToItems']) {
114 $restrictTo = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList('none,'.strtolower($this->thisConfig['buttons.']['formatblock.']['restrictTo'])), 1);
115 }
116 // Elements order
117 if ($this->thisConfig['buttons.']['formatblock.']['orderItems']) {
118 $blockElementsOrder = 'none,'.strtolower($this->thisConfig['buttons.']['formatblock.']['orderItems']);
119 }
120 $prefixLabelWithTag = ($this->thisConfig['buttons.']['formatblock.']['prefixLabelWithTag']) ? true : $prefixLabelWithTag;
121 $postfixLabelWithTag = ($this->thisConfig['buttons.']['formatblock.']['postfixLabelWithTag']) ? true : $postfixLabelWithTag;
122 }
123 // Processing old style configuration for hiding paragraphs
124 if ($this->thisConfig['hidePStyleItems']) {
125 $hideItems = array_merge($hideItems, t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList(strtolower($this->thisConfig['hidePStyleItems'])), 1));
126 }
127 // Applying User TSConfig restriction
128 $blockElementsOrder = array_diff(t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList($blockElementsOrder), 1), $hideItems);
129 if (!in_array('*', $restrictTo)) {
130 $blockElementsOrder = array_intersect($blockElementsOrder, $restrictTo);
131 }
132 // Localizing the options
133 $blockElementsOptions = array();
134 if ($this->htmlAreaRTE->cleanList($this->thisConfig['hidePStyleItems']) != '*') {
135 foreach ($blockElementsOrder as $item) {
136 if ($this->htmlAreaRTE->is_FE()) {
137 $blockElementsOptions[$item] = $TSFE->getLLL($this->defaultBlockElements[$item],$this->LOCAL_LANG);
138 } else {
139 $blockElementsOptions[$item] = $LANG->getLL($this->defaultBlockElements[$item]);
140 }
141 $blockElementsOptions[$item] = (($prefixLabelWithTag && $item != 'none')?($item . ' - '):'') . $blockElementsOptions[$item] . (($postfixLabelWithTag && $item != 'none')?(' - ' . $item):'');
142 }
143 }
144
145 $first = array_shift($blockElementsOptions);
146 // Sorting the options
147 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.']['formatblock.']) || !$this->thisConfig['buttons.']['formatblock.']['orderItems']) {
148 asort($blockElementsOptions);
149 }
150 // Generating the javascript options
151 $JSBlockElements = '{
152 "'. $first.'" : "none"';
153 foreach ($blockElementsOptions as $item => $label) {
154 $JSBlockElements .= ',
155 "' . $label . '" : "' . $item . '"';
156 }
157 $JSBlockElements .= '};';
158
159 $registerRTEinJavascriptString .= '
160 RTEarea['.$RTEcounter.'].buttons.formatblock.dropDownOptions = '. $JSBlockElements;
161 }
162 return $registerRTEinJavascriptString;
163 }
164
165 } // end of class
166
167 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/BlockElements/class.tx_rtehtmlarea_blockelements.php']) {
168 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/BlockElements/class.tx_rtehtmlarea_blockelements.php']);
169 }
170
171 ?>