Fixed bug #5945: Missing right parenthesis in RTEhtmlarea user element module (thanks...
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / mod5 / class.tx_rtehtmlarea_user.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
6 * (c) 2005-2006 Stanislas Rolland <stanislas.rolland(arobas)fructifor.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 Skaarhoj <kasper@typo3.com>
32 * @author Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
33 *
34 * $Id$ *
35 */
36
37 class tx_rtehtmlarea_user {
38 var $content;
39 var $modData;
40 var $siteUrl;
41 var $doc;
42 var $editorNo;
43
44 /**
45 * @return [type] ...
46 */
47 function init() {
48 global $BE_USER, $LANG, $BACK_PATH;
49
50 $this->editorNo = t3lib_div::_GP('editorNo');
51
52 $this->siteUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL');
53 $this->doc = t3lib_div::makeInstance('template');
54 $this->doc->backPath = $BACK_PATH;
55
56 $this->doc->bodyTagAdditions = 'onload="init();"';
57 $this->doc->form = '
58 <form action="" id="process" name="process" method="POST">
59 <input type="hidden" name="processContent" value="" />
60 <input type="hidden" name="returnUrl" value="'.htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')).'" />
61 ';
62
63 $this->doc->JScode = '<script type="text/javascript" src="'. $BACK_PATH . t3lib_extMgm::extRelPath('rtehtmlarea') . 'htmlarea/popups/popup.js"></script>';
64
65 $JScode = '
66 var editor = window.opener.RTEarea[' . $this->editorNo . ']["editor"];
67 var HTMLArea = window.opener.HTMLArea;
68
69 function init() {
70 document.body.onkeypress = __dlg_close_on_esc;
71 };
72 function insertHTML(content,noHide) {
73 editor.insertHTML(content);
74 if(!noHide) HTMLArea.edHidePopup();
75 };
76 function wrapHTML(wrap1,wrap2,noHide) {
77 if(editor.hasSelectedText()) {
78 editor.surroundHTML(wrap1,wrap2);
79 } else {
80 alert('.$LANG->JScharCode($LANG->getLL('noTextSelection')).');
81 }
82 if(!noHide) HTMLArea.edHidePopup();
83 };
84 function processSelection(script) {
85 document.process.action = script;
86 document.process.processContent.value = editor.getSelectedHTML();
87 document.process.submit();
88 };
89 ';
90
91 $this->doc->JScode .= $this->doc->wrapScriptTags($JScode);
92
93 $this->modData = $BE_USER->getModuleData('user.php','ses');
94 if (t3lib_div::_GP('OC_key')) {
95 $parts = explode('|',t3lib_div::_GP('OC_key'));
96 $this->modData['openKeys'][$parts[1]] = $parts[0]=='O' ? 1 : 0;
97 $BE_USER->pushModuleData('user.php',$this->modData);
98 }
99 }
100
101 /**
102 * [Describe function...]
103 *
104 * @return [type] ...
105 */
106 function main() {
107
108 $this->content='';
109 $this->content.=$this->main_user($this->modData['openKeys']);
110 }
111
112 /**
113 * [Describe function...]
114 *
115 * @return [type] ...
116 */
117 function printContent() {
118 echo $this->content;
119 }
120
121
122
123 /********************************
124 *
125 * Other functions
126 *
127 *********************************/
128
129 /**
130 * @param [type] $imgInfo: ...
131 * @param [type] $maxW: ...
132 * @param [type] $maxH: ...
133 * @return [type] ...
134 */
135 function calcWH($imgInfo,$maxW=380,$maxH=500) {
136 $IW = $imgInfo[0];
137 $IH = $imgInfo[1];
138 if ($IW>$maxW) {
139 $IH=ceil($IH/$IW*$maxW);
140 $IW=$maxW;
141 }
142 if ($IH>$maxH) {
143 $IW=ceil($IW/$IH*$maxH);
144 $IH=$maxH;
145 }
146
147 $imgInfo[3]='width="'.$IW.'" height="'.$IH.'"';
148 return $imgInfo;
149 }
150
151 /**
152 * Rich Text Editor (RTE) user element selector
153 *
154 * @param [type] $openKeys: ...
155 * @return [type] ...
156 */
157 function main_user($openKeys) {
158 global $LANG, $BACK_PATH, $BE_USER;
159 // Starting content:
160 $content.=$this->doc->startPage($LANG->getLL('Insert Custom Element',1));
161
162 $RTEtsConfigParts = explode(':',t3lib_div::_GP('RTEtsConfigParams'));
163 $RTEsetup = $BE_USER->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($RTEtsConfigParts[5]));
164 $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$RTEtsConfigParts[0],$RTEtsConfigParts[2],$RTEtsConfigParts[4]);
165
166 if (is_array($thisConfig['userElements.'])) {
167
168 $categories=array();
169 reset($thisConfig['userElements.']);
170 while(list($k)=each($thisConfig['userElements.'])) {
171 $ki=intval($k);
172 $v = $thisConfig['userElements.'][$ki.'.'];
173 if (substr($k,-1)=="." && is_array($v)) {
174 $subcats=array();
175 $openK = $ki;
176 if ($openKeys[$openK]) {
177
178 $mArray = '';
179 switch ((string)$v['load']) {
180 case 'images_from_folder':
181 $mArray=array();
182 if ($v['path'] && @is_dir(PATH_site.$v['path'])) {
183 $files = t3lib_div::getFilesInDir(PATH_site.$v['path'],'gif,jpg,jpeg,png',0,'');
184 if (is_array($files)) {
185 reset($files);
186 $c=0;
187 while(list(,$filename)=each($files)) {
188 $iInfo = @getimagesize(PATH_site.$v['path'].$filename);
189 $iInfo = $this->calcWH($iInfo,50,100);
190
191 $ks=(string)(100+$c);
192 $mArray[$ks]=$filename;
193 $mArray[$ks."."]=array(
194 'content' => '<img src="'.$this->siteUrl.$v['path'].$filename.'" />',
195 '_icon' => '<img src="'.$this->siteUrl.$v['path'].$filename.'" '.$iInfo[3].' />',
196 'description' => $LANG->getLL('filesize').': '.str_replace('&nbsp;',' ',t3lib_div::formatSize(@filesize(PATH_site.$v['path'].$filename))).', '.$LANG->getLL('pixels',1).': '.$iInfo[0].'x'.$iInfo[1]
197 );
198 $c++;
199 }
200 }
201 }
202 break;
203 }
204 if (is_array($mArray)) {
205 if ($v['merge']) {
206 $v=t3lib_div::array_merge_recursive_overrule($mArray,$v);
207 } else {
208 $v=$mArray;
209 }
210 }
211 reset($v);
212 while(list($k2)=each($v)) {
213 $k2i = intval($k2);
214 if (substr($k2,-1)=='.' && is_array($v[$k2i.'.'])) {
215 $title = trim($v[$k2i]);
216 if (!$title) {
217 $title='['.$LANG->getLL('noTitle',1).']';
218 } else {
219 $title=$LANG->sL($title,1);
220 }
221 $description = $LANG->sL($v[$k2i.'.']['description'],1).'<br />';
222 if (!$v[$k2i.'.']['dontInsertSiteUrl']) $v[$k2i.'.']['content'] = str_replace('###_URL###',$this->siteUrl,$v[$k2i.'.']['content']);
223
224 $logo = $v[$k2i.'.']['_icon'] ? $v[$k2i.'.']['_icon'] : '';
225
226 $onClickEvent='';
227 switch((string)$v[$k2i.'.']['mode']) {
228 case 'wrap':
229 $wrap = explode('|',$v[$k2i.'.']['content']);
230 $onClickEvent='wrapHTML(' . $LANG->JScharCode($wrap[0]) . ',' . $LANG->JScharCode($wrap[1]) . ',false);';
231 break;
232 case 'processor':
233 $script = trim($v[$k2i.'.']['submitToScript']);
234 if (substr($script,0,4)!='http') $script = $this->siteUrl.$script;
235 if ($script) {
236 $onClickEvent='processSelection(' . $LANG->JScharCode($script) . ');';
237 }
238 break;
239 case 'insert':
240 default:
241 $onClickEvent='insertHTML(' . $LANG->JScharCode($v[$k2i . '.']['content']) . ');';
242 break;
243 }
244 $A=array('<a href="#" onClick="'.$onClickEvent.'return false;">','</a>');
245 $subcats[$k2i]='<tr>
246 <td><img src="clear.gif" width="18" height="1" /></td>
247 <td class="bgColor4" valign="top">'.$A[0].$logo.$A[1].'</td>
248 <td class="bgColor4" valign="top">'.$A[0].'<strong>'.$title.'</strong><br />'.$description.$A[1].'</td>
249 </tr>';
250 }
251 }
252 ksort($subcats);
253 }
254 $categories[$ki]=implode('',$subcats);
255 }
256 }
257 ksort($categories);
258
259 # Render menu of the items:
260 $lines=array();
261 reset($categories);
262 while(list($k,$v)=each($categories)) {
263 $title = trim($thisConfig['userElements.'][$k]);
264 $openK = $k;
265 if (!$title) {
266 $title='['.$LANG->getLL('noTitle',1).']';
267 } else {
268 $title=$LANG->sL($title,1);
269 }
270 $lines[]='<tr><td colspan="3" class="bgColor5"><a href="'.t3lib_div::linkThisScript(array('OC_key' => ($openKeys[$openK]?'C|':'O|').$openK, 'editorNo' => $this->editorNo)).'" title="'.$LANG->getLL('expand',1).'"><img' . t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/'.($openKeys[$openK]?'minus':'plus').'bullet.gif','width="18" height="16"').' title="'.$LANG->getLL('expand',1).'" /><strong>'.$title.'</strong></a></td></tr>';
271 $lines[]=$v;
272 }
273
274 $content.='<table border="0" cellpadding="1" cellspacing="1">'.implode('',$lines).'</table>';
275 }
276
277 $content.= $this->doc->endPage();
278 return $content;
279 }
280 }
281
282 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod5/class.tx_rtehtmlarea_user.php']) {
283 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod5/class.tx_rtehtmlarea_user.php']);
284 }
285
286 ?>