[TASK] Fix CGL violations against InlineControlStructure
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / mod5 / class.tx_rtehtmlarea_user.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasper@typo3.com)
6 * (c) 2005-2012 Stanislas Rolland <typo3(arobas)sjbr.ca>
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
19 *
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28 /**
29 * User defined content for htmlArea RTE
30 *
31 * @author Kasper Skårhøj <kasper@typo3.com>
32 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
33 */
34
35 class tx_rtehtmlarea_user {
36 var $content;
37 var $modData;
38 var $siteUrl;
39
40 /**
41 * document template object
42 *
43 * @var template
44 */
45 var $doc;
46 var $editorNo;
47
48 /**
49 * @return [type] ...
50 */
51 function init() {
52 $this->editorNo = t3lib_div::_GP('editorNo');
53
54 $this->siteUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL');
55 $this->doc = t3lib_div::makeInstance('template');
56 $this->doc->backPath = $GLOBALS['BACK_PATH'];
57
58 $this->doc->bodyTagAdditions = 'onload="Init();"';
59 $this->doc->form = '
60 <form action="" id="process" name="process" method="post">
61 <input type="hidden" name="processContent" value="" />
62 <input type="hidden" name="returnUrl" value="' . htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')) . '" />
63 ';
64
65 $JScode = '
66 var plugin = window.parent.RTEarea["' . $this->editorNo . '"].editor.getPlugin("UserElements");
67 var HTMLArea = window.parent.HTMLArea;
68 var editor = plugin.editor;
69
70 function Init() {
71 };
72 function insertHTML(content,noHide) {
73 plugin.restoreSelection();
74 editor.getSelection().insertHtml(content);
75 if(!noHide) plugin.close();
76 };
77 function wrapHTML(wrap1,wrap2,noHide) {
78 plugin.restoreSelection();
79 if(!editor.getSelection().isEmpty()) {
80 editor.getSelection().surroundHtml(wrap1,wrap2);
81 } else {
82 alert(' . $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->getLL('noTextSelection')) . ');
83 }
84 if(!noHide) plugin.close();
85 };
86 function processSelection(script) {
87 plugin.restoreSelection();
88 document.process.action = script;
89 document.process.processContent.value = editor.getSelection().getHtml();
90 document.process.submit();
91 };
92 function jumpToUrl(URL) {
93 var RTEtsConfigParams = "&RTEtsConfigParams=' . rawurlencode(t3lib_div::_GP('RTEtsConfigParams')) . '";
94 var editorNo = "&editorNo=' . rawurlencode($this->editorNo) . '";
95 theLocation = "' . t3lib_div::getIndpEnv('SCRIPT_NAME') . '"+URL+RTEtsConfigParams+editorNo;
96 window.location.href = theLocation;
97 }
98 ';
99
100 $this->doc->JScode = $this->doc->wrapScriptTags($JScode);
101
102 $this->modData = $GLOBALS['BE_USER']->getModuleData('user.php', 'ses');
103 if (t3lib_div::_GP('OC_key')) {
104 $parts = explode('|', t3lib_div::_GP('OC_key'));
105 $this->modData['openKeys'][$parts[1]] = $parts[0]=='O' ? 1 : 0;
106 $GLOBALS['BE_USER']->pushModuleData('user.php', $this->modData);
107 }
108 }
109
110 /**
111 * [Describe function...]
112 *
113 * @return [type] ...
114 */
115 function main() {
116
117 $this->content = '';
118 $this->content .= $this->main_user($this->modData['openKeys']);
119 }
120
121 /**
122 * [Describe function...]
123 *
124 * @return [type] ...
125 */
126 function printContent() {
127 echo $this->content;
128 }
129
130
131
132 /********************************
133 *
134 * Other functions
135 *
136 *********************************/
137
138 /**
139 * @param [type] $imgInfo: ...
140 * @param [type] $maxW: ...
141 * @param [type] $maxH: ...
142 * @return [type] ...
143 */
144 function calcWH($imgInfo, $maxW = 380, $maxH = 500) {
145 $IW = $imgInfo[0];
146 $IH = $imgInfo[1];
147 if ($IW > $maxW) {
148 $IH = ceil($IH / $IW * $maxW);
149 $IW = $maxW;
150 }
151 if ($IH > $maxH) {
152 $IW = ceil($IW / $IH * $maxH);
153 $IH = $maxH;
154 }
155
156 $imgInfo[3] = 'width="' . $IW.'" height="' . $IH.'"';
157 return $imgInfo;
158 }
159
160 /**
161 * Rich Text Editor (RTE) user element selector
162 *
163 * @param [type] $openKeys: ...
164 * @return [type] ...
165 */
166 function main_user($openKeys) {
167 // Starting content:
168 $content = $this->doc->startPage($GLOBALS['LANG']->getLL('Insert Custom Element', 1));
169
170 $RTEtsConfigParts = explode(':', t3lib_div::_GP('RTEtsConfigParams'));
171 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', t3lib_BEfunc::getPagesTSconfig($RTEtsConfigParts[5]));
172 $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
173
174 if (is_array($thisConfig['userElements.'])) {
175
176 $categories=array();
177 foreach ($thisConfig['userElements.'] as $k => $value) {
178 $ki = intval($k);
179 $v = $thisConfig['userElements.'][$ki . '.'];
180 if (substr($k, -1) == '.' && is_array($v)) {
181 $subcats = array();
182 $openK = $ki;
183 if ($openKeys[$openK]) {
184
185 $mArray = '';
186 switch ((string)$v['load']) {
187 case 'images_from_folder':
188 $mArray = array();
189 if ($v['path'] && @is_dir(PATH_site.$v['path'])) {
190 $files = t3lib_div::getFilesInDir(PATH_site . $v['path'], 'gif,jpg,jpeg,png', 0, '');
191 if (is_array($files)) {
192 $c = 0;
193 foreach ($files as $filename) {
194 $iInfo = @getimagesize(PATH_site . $v['path'] . $filename);
195 $iInfo = $this->calcWH($iInfo, 50, 100);
196
197 $ks = (string)(100 + $c);
198 $mArray[$ks] = $filename;
199 $mArray[$ks . '.'] = array(
200 'content' => '<img src="' . $this->siteUrl . $v['path'] . $filename . '" />',
201 '_icon' => '<img src="' . $this->siteUrl . $v['path'] . $filename . '" ' . $iInfo[3] . ' />',
202 'description' => $GLOBALS['LANG']->getLL('filesize') . ': ' . str_replace('&nbsp;', ' ', t3lib_div::formatSize(@filesize(PATH_site . $v['path'] . $filename))) . ', ' . $GLOBALS['LANG']->getLL('pixels', 1) . ': ' . $iInfo[0] . 'x' . $iInfo[1]
203 );
204 $c++;
205 }
206 }
207 }
208 break;
209 }
210 if (is_array($mArray)) {
211 if ($v['merge']) {
212 $v = t3lib_div::array_merge_recursive_overrule($mArray, $v);
213 } else {
214 $v = $mArray;
215 }
216 }
217 foreach ($v as $k2 => $dummyValue) {
218 $k2i = intval($k2);
219 if (substr($k2, -1) == '.' && is_array($v[$k2i . '.'])) {
220 $title = trim($v[$k2i]);
221 if (!$title) {
222 $title = '[' . $GLOBALS['LANG']->getLL('noTitle', 1) . ']';
223 } else {
224 $title = $GLOBALS['LANG']->sL($title, 1);
225 }
226 $description = $GLOBALS['LANG']->sL($v[$k2i . '.']['description'], 1) . '<br />';
227 if (!$v[$k2i.'.']['dontInsertSiteUrl']) {
228 $v[$k2i . '.']['content'] = str_replace('###_URL###', $this->siteUrl, $v[$k2i . '.']['content']);
229 }
230
231 $logo = $v[$k2i.'.']['_icon'] ? $v[$k2i.'.']['_icon'] : '';
232
233 $onClickEvent = '';
234 switch((string)$v[$k2i . '.']['mode']) {
235 case 'wrap':
236 $wrap = explode('|', $v[$k2i.'.']['content']);
237 $onClickEvent = 'wrapHTML(' . $GLOBALS['LANG']->JScharCode($wrap[0]) . ',' . $GLOBALS['LANG']->JScharCode($wrap[1]) . ',false);';
238 break;
239 case 'processor':
240 $script = trim($v[$k2i.'.']['submitToScript']);
241 if (substr($script, 0, 4)!='http') {
242 $script = $this->siteUrl.$script;
243 }
244 if ($script) {
245 $onClickEvent='processSelection(' . $GLOBALS['LANG']->JScharCode($script) . ');';
246 }
247 break;
248 case 'insert':
249 default:
250 $onClickEvent='insertHTML(' . $GLOBALS['LANG']->JScharCode($v[$k2i . '.']['content']) . ');';
251 break;
252 }
253 $A = array('<a href="#" onClick="' . $onClickEvent . 'return false;">', '</a>');
254 $subcats[$k2i] = '<tr>
255 <td><img src="clear.gif" width="18" height="1" /></td>
256 <td class="bgColor4" valign="top">' . $A[0] . $logo . $A[1] . '</td>
257 <td class="bgColor4" valign="top">' . $A[0] . '<strong>' . $title . '</strong><br />' . $description . $A[1] . '</td>
258 </tr>';
259 }
260 }
261 ksort($subcats);
262 }
263 $categories[$ki] = implode('', $subcats);
264 }
265 }
266 ksort($categories);
267
268 // Render menu of the items:
269 $lines = array();
270 foreach ($categories as $k => $v) {
271 $title = trim($thisConfig['userElements.'][$k]);
272 $openK = $k;
273 if (!$title) {
274 $title = '[' . $GLOBALS['LANG']->getLL('noTitle', 1) . ']';
275 } else {
276 $title = $GLOBALS['LANG']->sL($title, 1);
277 }
278 $lines[] = '<tr><td colspan="3" class="bgColor5"><a href="#" title="' . $GLOBALS['LANG']->getLL('expand', 1) . '" onClick="jumpToUrl(\'?OC_key=' . ($openKeys[$openK] ? 'C|' : 'O|') . $openK . '\');return false;"><img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/ol/' . ($openKeys[$openK] ? 'minus' : 'plus') . 'bullet.gif', 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('expand', 1) . '" /><strong>' . $title . '</strong></a></td></tr>';
279 $lines[] = $v;
280 }
281
282 $content .= '<table border="0" cellpadding="1" cellspacing="1">' . implode('', $lines) . '</table>';
283 }
284
285 $content .= $this->doc->endPage();
286 return $content;
287 }
288 }
289 ?>