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