df748fcbf7f6a2f1ddfe06267dbe630a6fe8c17a
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / extensions / BlockElements / class.tx_rtehtmlarea_blockelements.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007-2010 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 * 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, line';
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 'line' => 'InsertHorizontalRule',
61 );
62
63 protected $defaultBlockElements = array(
64 'none' => 'No block',
65 'p' => 'Paragraph',
66 'h1' => 'Heading 1',
67 'h2' => 'Heading 2',
68 'h3' => 'Heading 3',
69 'h4' => 'Heading 4',
70 'h5' => 'Heading 5',
71 'h6' => 'Heading 6',
72 'pre' => 'Preformatted',
73 'address' => 'Address',
74 'blockquote' => 'Long quotation',
75 'div' => 'Section',
76 );
77
78 protected $defaultBlockElementsOrder = 'none, p, h1, h2, h3, h4, h5, h6, pre, address, blockquote, div';
79
80 /**
81 * Return JS configuration of the htmlArea plugins registered by the extension
82 *
83 * @param integer Relative id of the RTE editing area in the form
84 *
85 * @return string JS configuration for registered plugins, in this case, JS configuration of block elements
86 *
87 * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
88 * Each of the instructions should be of the form:
89 * RTEarea['.$RTEcounter.']["buttons"]["button-id"]["property"] = "value";
90 */
91 public function buildJavascriptConfiguration($RTEcounter) {
92 global $TSFE, $LANG;
93
94 $registerRTEinJavascriptString = '';
95 if (in_array('formatblock', $this->toolbar)) {
96 if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.']['formatblock.'])) {
97 $registerRTEinJavascriptString .= '
98 RTEarea['.$RTEcounter.'].buttons.formatblock = new Object();';
99 }
100 // Default block elements
101 $hideItems = array();
102 $addItems = array();
103 $restrictTo = array('*');
104 $blockElementsOrder = $this->defaultBlockElementsOrder;
105 $prefixLabelWithTag = false;
106 $postfixLabelWithTag = false;
107
108 // Processing PageTSConfig
109 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['formatblock.'])) {
110 // Removing elements
111 if ($this->thisConfig['buttons.']['formatblock.']['removeItems']) {
112 $hideItems = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList(t3lib_div::strtolower($this->thisConfig['buttons.']['formatblock.']['removeItems'])), 1);
113 }
114 // Adding elements
115 if ($this->thisConfig['buttons.']['formatblock.']['addItems']) {
116 $addItems = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList(t3lib_div::strtolower($this->thisConfig['buttons.']['formatblock.']['addItems'])), 1);
117 }
118 // Restriction clause
119 if ($this->thisConfig['buttons.']['formatblock.']['restrictToItems']) {
120 $restrictTo = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList('none,'.t3lib_div::strtolower($this->thisConfig['buttons.']['formatblock.']['restrictToItems'])), 1);
121 }
122 // Elements order
123 if ($this->thisConfig['buttons.']['formatblock.']['orderItems']) {
124 $blockElementsOrder = 'none,'.t3lib_div::strtolower($this->thisConfig['buttons.']['formatblock.']['orderItems']);
125 }
126 $prefixLabelWithTag = ($this->thisConfig['buttons.']['formatblock.']['prefixLabelWithTag']) ? true : $prefixLabelWithTag;
127 $postfixLabelWithTag = ($this->thisConfig['buttons.']['formatblock.']['postfixLabelWithTag']) ? true : $postfixLabelWithTag;
128 }
129 // Processing old style configuration for hiding paragraphs
130 if ($this->thisConfig['hidePStyleItems']) {
131 $hideItems = array_merge($hideItems, t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList(t3lib_div::strtolower($this->thisConfig['hidePStyleItems'])), 1));
132 }
133 // Adding custom items
134 $blockElementsOrder = array_merge(t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList($blockElementsOrder), 1), $addItems);
135 // Applying User TSConfig restriction
136 $blockElementsOrder = array_diff($blockElementsOrder, $hideItems);
137 if (!in_array('*', $restrictTo)) {
138 $blockElementsOrder = array_intersect($blockElementsOrder, $restrictTo);
139 }
140 // Localizing the options
141 $blockElementsOptions = array();
142 if ($this->htmlAreaRTE->cleanList($this->thisConfig['hidePStyleItems']) != '*') {
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
163 $first = array_shift($blockElementsOptions);
164 // Sorting the options
165 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.']['formatblock.']) || !$this->thisConfig['buttons.']['formatblock.']['orderItems']) {
166 asort($blockElementsOptions);
167 }
168 // utf8-encode labels if we are responding to an IRRE ajax call
169 if (!$this->htmlAreaRTE->is_FE() && $this->htmlAreaRTE->TCEform->inline->isAjaxCall) {
170 foreach ($blockElementsOptions as $item => $label) {
171 $blockElementsOptions[$item] = $GLOBALS['LANG']->csConvObj->utf8_encode($label, $GLOBALS['LANG']->charSet);
172 }
173 }
174 // Generating the javascript options
175 $JSBlockElements = array();
176 $JSBlockElements[] = array($first, 'none');
177 foreach ($blockElementsOptions as $item => $label) {
178 $JSBlockElements[] = array($label, $item);
179 }
180 $registerRTEinJavascriptString .= '
181 RTEarea['.$RTEcounter.'].buttons.formatblock.data = ' . json_encode($JSBlockElements) . ';';
182 }
183 return $registerRTEinJavascriptString;
184 }
185
186 } // end of class
187
188 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/BlockElements/class.tx_rtehtmlarea_blockelements.php']) {
189 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/BlockElements/class.tx_rtehtmlarea_blockelements.php']);
190 }
191
192 ?>