* Fixed issue 7052: Permission problem of RTE images
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / mod4 / class.tx_rtehtmlarea_select_image.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
6 * (c) 2004-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 * Displays image selector for the RTE
30 *
31 * @author Kasper Skaarhoj <kasper@typo3.com>
32 * @author Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
33 *
34 * $Id$ *
35 */
36 require_once(PATH_typo3.'class.browse_links.php');
37 require_once(PATH_t3lib.'class.t3lib_foldertree.php');
38 require_once(PATH_t3lib.'class.t3lib_stdgraphic.php');
39 require_once(PATH_t3lib.'class.t3lib_basicfilefunc.php');
40
41 /**
42 * Local Folder Tree
43 *
44 * @author Kasper Skaarhoj <kasper@typo3.com>
45 * @package TYPO3
46 * @subpackage tx_rte
47 */
48 class tx_rtehtmlarea_image_folderTree extends t3lib_folderTree {
49 var $ext_IconMode=1;
50
51 /**
52 * Wrapping the title in a link, if applicable.
53 *
54 * @param string Title, ready for output.
55 * @param array The "record"
56 * @return string Wrapping title string.
57 */
58 function wrapTitle($title,$v) {
59 if ($this->ext_isLinkable($v)) {
60 $aOnClick = 'return jumpToUrl(\'?editorNo='.$GLOBALS['SOBE']->browser->editorNo.'&expandFolder='.rawurlencode($v['path']).'\');';
61 return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
62 } else {
63 return '<span class="typo3-dimmed">'.$title.'</span>';
64 }
65 }
66
67 /**
68 * Returns true if the input "record" contains a folder which can be linked.
69 *
70 * @param array Array with information about the folder element. Contains keys like title, uid, path, _title
71 * @return boolean True is returned if the path is found in the web-part of the the server and is NOT a recycler or temp folder
72 */
73 function ext_isLinkable($v) {
74 $webpath=t3lib_BEfunc::getPathType_web_nonweb($v['path']);
75 if ($GLOBALS['SOBE']->browser->act=='magic') return 1; //$webpath='web'; // The web/non-web path does not matter if the mode is 'magic'
76
77 if (strstr($v['path'],'_recycler_') || strstr($v['path'],'_temp_') || $webpath!='web') {
78 return 0;
79 }
80 return 1;
81 }
82
83 /**
84 * Wrap the plus/minus icon in a link
85 *
86 * @param string HTML string to wrap, probably an image tag.
87 * @param string Command for 'PM' get var
88 * @param boolean If set, the link will have a anchor point (=$bMark) and a name attribute (=$bMark)
89 * @return string Link-wrapped input string
90 * @access private
91 */
92 function PM_ATagWrap($icon,$cmd,$bMark='') {
93 if ($bMark) {
94 $anchor = '#'.$bMark;
95 $name=' name="'.$bMark.'"';
96 }
97 $aOnClick = 'return jumpToUrl(\'?PM='.$cmd.'\',\''.$anchor.'\');';
98 return '<a href="#"'.$name.' onclick="'.htmlspecialchars($aOnClick).'">'.$icon.'</a>';
99 }
100
101 /**
102 * Print tree.
103 *
104 * @param mixed Input tree array. If not array, then $this->tree is used.
105 * @return string HTML output of the tree.
106 */
107 function printTree($treeArr='') {
108 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
109
110 if (!is_array($treeArr)) $treeArr=$this->tree;
111
112 $out='';
113 $c=0;
114
115 // Traverse rows for the tree and print them into table rows:
116 foreach($treeArr as $k => $v) {
117 $c++;
118 $bgColor=' class="'.(($c+1)%2 ? 'bgColor' : 'bgColor-10').'"';
119 $out.='<tr'.$bgColor.'><td nowrap="nowrap">'.$v['HTML'].$this->wrapTitle(t3lib_div::fixed_lgd($v['row']['title'],$titleLen),$v['row']).'</td></tr>';
120 }
121
122 $out='<table border="0" cellpadding="0" cellspacing="0">'.$out.'</table>';
123 return $out;
124 }
125 }
126
127
128 /**
129 * Script Class
130 *
131 * @author Kasper Skaarhoj <kasper@typo3.com>
132 * @package TYPO3
133 * @subpackage tx_rte
134 */
135 class tx_rtehtmlarea_select_image extends browse_links {
136 var $extKey = 'rtehtmlarea';
137 var $content;
138 var $act;
139 var $allowedItems;
140 var $plainMaxWidth;
141 var $plainMaxHeight;
142 var $magicMaxWidth;
143 var $magicMaxHeight;
144 var $imgPath;
145 var $classesImageJSOptions;
146 var $editorNo;
147 var $buttonConfig = array();
148
149 /**
150 * Initialisation
151 *
152 * @return [type] ...
153 */
154 function init() {
155 global $BE_USER,$BACK_PATH,$TYPO3_CONF_VARS;
156
157 // Main GPvars:
158 $this->siteUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL');
159 $this->act = t3lib_div::_GP('act');
160 $this->editorNo = t3lib_div::_GP('editorNo');
161 $this->expandPage = t3lib_div::_GP('expandPage');
162 $this->expandFolder = t3lib_div::_GP('expandFolder');
163
164 // Find "mode"
165 $this->mode = t3lib_div::_GP('mode');
166 if (!$this->mode) {
167 $this->mode='rte';
168 }
169
170 // Site URL
171 $this->siteURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL'); // Current site url
172
173 // the script to link to
174 $this->thisScript = t3lib_div::getIndpEnv('SCRIPT_NAME');
175
176 if (!$this->act) {
177 $this->act='magic';
178 }
179
180 $RTEtsConfigParts = explode(':',t3lib_div::_GP('RTEtsConfigParams'));
181 $RTEsetup = $BE_USER->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($RTEtsConfigParts[5]));
182 $this->thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$RTEtsConfigParts[0],$RTEtsConfigParts[2],$RTEtsConfigParts[4]);
183 $this->imgPath = $RTEtsConfigParts[6];
184
185 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['image.'])) {
186 $this->buttonConfig = $this->thisConfig['buttons.']['image.'];
187 }
188
189 $this->allowedItems = explode(',','magic,plain,dragdrop,image');
190 if (is_array($this->buttonConfig['options.']) && $this->buttonConfig['options.']['removeItems']) {
191 $this->allowedItems = array_diff($this->allowedItems,t3lib_div::trimExplode(',',$this->buttonConfig['options.']['removeItems'],1));
192 } else {
193 $this->allowedItems = array_diff($this->allowedItems,t3lib_div::trimExplode(',',$this->thisConfig['blindImageOptions'],1));
194 }
195 reset($this->allowedItems);
196 if (!in_array($this->act,$this->allowedItems)) {
197 $this->act = current($this->allowedItems);
198 }
199
200 if ($this->act == 'plain') {
201 if ($TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['plainImageMaxWidth']) $this->plainMaxWidth = $TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['plainImageMaxWidth'];
202 if ($TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['plainImageMaxHeight']) $this->plainMaxHeight = $TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['plainImageMaxHeight'];
203 if (is_array($this->buttonConfig['options.']) && is_array($this->buttonConfig['options.']['plain.'])) {
204 if ($this->buttonConfig['options.']['plain.']['maxWidth']) $this->plainMaxWidth = $this->buttonConfig['options.']['plain.']['maxWidth'];
205 if ($this->buttonConfig['options.']['plain.']['maxHeight']) $this->plainMaxHeight = $this->buttonConfig['options.']['plain.']['maxHeight'];
206 }
207 if (!$this->plainMaxWidth) $this->plainMaxWidth = 640;
208 if (!$this->plainMaxHeight) $this->plainMaxHeight = 680;
209 } elseif ($this->act == 'magic') {
210 if (is_array($this->buttonConfig['options.']) && is_array($this->buttonConfig['options.']['magic.'])) {
211 if ($this->buttonConfig['options.']['magic.']['maxWidth']) $this->magicMaxWidth = $this->buttonConfig['options.']['magic.']['maxWidth'];
212 if ($this->buttonConfig['options.']['magic.']['maxHeight']) $this->magicMaxHeight = $this->buttonConfig['options.']['magic.']['maxHeight'];
213 }
214 // These defaults allow images to be based on their width - to a certain degree - by setting a high height. Then we're almost certain the image will be based on the width
215 if (!$this->magicMaxWidth) $this->magicMaxWidth = 300;
216 if (!$this->magicMaxHeight) $this->magicMaxHeight = 1000;
217 }
218
219 if($this->thisConfig['classesImage']) {
220 $classesImageArray = t3lib_div::trimExplode(',',$this->thisConfig['classesImage'],1);
221 $this->classesImageJSOptions = '<option value=""></option>';
222 reset($classesImageArray);
223 while(list(,$class)=each($classesImageArray)) {
224 $this->classesImageJSOptions .= '<option value="' .$class . '">' . $class . '</option>';
225 }
226 }
227
228 $this->magicProcess();
229
230 // Creating backend template object:
231 $this->doc = t3lib_div::makeInstance('template');
232 $this->doc->docType= 'xhtml_trans';
233 $this->doc->backPath = $BACK_PATH;
234
235 $this->getJSCode();
236 }
237
238 /**
239 * [Describe function...]
240 *
241 * @return [type] ...
242 */
243 function rteImageStorageDir() {
244 $dir = $this->imgPath ? $this->imgPath : $GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir'];;
245 return $dir;
246 }
247
248 /**
249 * [Describe function...]
250 *
251 * @return [type] ...
252 */
253 function magicProcess() {
254 global $TYPO3_CONF_VARS;
255
256 if ($this->act=='magic' && t3lib_div::_GP('insertMagicImage')) {
257 $filepath = t3lib_div::_GP('insertMagicImage');
258
259 $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
260 $imgObj->init();
261 $imgObj->mayScaleUp=0;
262 $imgObj->tempPath=PATH_site.$imgObj->tempPath;
263
264 $imgInfo = $imgObj->getImageDimensions($filepath);
265
266 if (is_array($imgInfo) && count($imgInfo)==4 && $this->rteImageStorageDir()) {
267 $fI=pathinfo($imgInfo[3]);
268 $fileFunc = t3lib_div::makeInstance('t3lib_basicFileFunctions');
269 $basename = $fileFunc->cleanFileName('RTEmagicP_'.$fI['basename']);
270 $destPath =PATH_site.$this->rteImageStorageDir();
271 if (@is_dir($destPath)) {
272 $destName = $fileFunc->getUniqueName($basename,$destPath);
273 if (isset($TYPO3_CONF_VARS['BE']['fileCreateMask'])) {
274 @chmod($destName, $TYPO3_CONF_VARS['BE']['fileCreateMask']);
275 }
276 @copy($imgInfo[3],$destName);
277
278 $cWidth = t3lib_div::intInRange(t3lib_div::_GP('cWidth'),0,$this->magicMaxWidth);
279 $cHeight = t3lib_div::intInRange(t3lib_div::_GP('cHeight'),0,$this->magicMaxHeight);
280 if (!$cWidth) $cWidth = $this->magicMaxWidth;
281 if (!$cHeight) $cHeight = $this->magicMaxHeight;
282
283 $imgI = $imgObj->imageMagickConvert($filepath,'WEB',$cWidth.'m',$cHeight.'m'); // ($imagefile,$newExt,$w,$h,$params,$frame,$options,$mustCreate=0)
284 if ($imgI[3]) {
285 $fI=pathinfo($imgI[3]);
286 $mainBase='RTEmagicC_'.substr(basename($destName),10).'.'.$fI['extension'];
287 $destName = $fileFunc->getUniqueName($mainBase,$destPath);
288 if (isset($TYPO3_CONF_VARS['BE']['fileCreateMask'])) {
289 @chmod($destName, $TYPO3_CONF_VARS['BE']['fileCreateMask']);
290 }
291 @copy($imgI[3],$destName);
292
293 $destName = dirname($destName).'/'.rawurlencode(basename($destName));
294 $iurl = $this->siteUrl.substr($destName,strlen(PATH_site));
295 echo'
296 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
297 <html>
298 <head>
299 <title>Untitled</title>
300 </head>
301 <script language="javascript" type="text/javascript">
302 /*<![CDATA[*/
303 var editor = window.opener.RTEarea[' . $this->editorNo . ']["editor"];
304 var HTMLArea = window.opener.HTMLArea;
305 function insertImage(file,width,height,origFile) {
306 var styleWidth, styleHeight;
307 styleWidth = parseInt(width);
308 if (isNaN(styleWidth) || styleWidth == 0) {
309 styleWidth = "auto";
310 } else {
311 styleWidth += "px";
312 }
313 styleHeight = parseInt(height);
314 if (isNaN(styleHeight) || styleHeight == 0) {
315 styleHeight = "auto";
316 } else {
317 styleHeight += "px";
318 }
319 editor.renderPopup_insertImage(\'<img src="\'+file+\'" style="width: \'+styleWidth+\'; height: \'+styleHeight+\';"'.(($TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['enableClickEnlarge'] && !(is_array($this->buttonConfig['clickEnlarge.']) && $this->buttonConfig['clickEnlarge.']['disabled']))?' clickenlargesrc="\'+origFile+\'" clickenlarge="0"':'').' />\');
320 }
321 /*]]>*/
322 </script>
323 <body>
324 <script type="text/javascript">
325 /*<![CDATA[*/
326 insertImage(\''.$iurl.'\','.$imgI[0].','.$imgI[1].',\''.substr($imgInfo[3],strlen(PATH_site)).'\');
327 /*]]>*/
328 </script>
329 </body>
330 </html>';
331 }
332
333 }
334 }
335 exit;
336 }
337 }
338
339 /**
340 * [Describe function...]
341 *
342 * @return [type] ...
343 */
344 function getJSCode() {
345 global $LANG,$BACK_PATH,$TYPO3_CONF_VARS;
346
347 $JScode='
348 var editor = window.opener.RTEarea[' . $this->editorNo . ']["editor"];
349 var HTMLArea = window.opener.HTMLArea;
350 function jumpToUrl(URL,anchor) { //
351 var add_act = URL.indexOf("act=")==-1 ? "&act='.$this->act.'" : "";
352 var add_editorNo = URL.indexOf("editorNo=")==-1 ? "&editorNo='.$this->editorNo.'" : "";
353 var RTEtsConfigParams = "&RTEtsConfigParams='.rawurlencode(t3lib_div::_GP('RTEtsConfigParams')).'";
354
355 var cur_width = selectedImageRef ? "&cWidth="+selectedImageRef.style.width : "";
356 var cur_height = selectedImageRef ? "&cHeight="+selectedImageRef.style.height : "";
357
358 var theLocation = URL+add_act+add_editorNo+RTEtsConfigParams+cur_width+cur_height+(anchor?anchor:"");
359 window.location.href = theLocation;
360 return false;
361 }
362 function insertImage(file,width,height,origFile) {
363 var styleWidth, styleHeight;
364 styleWidth = parseInt(width);
365 if (isNaN(styleWidth) || styleWidth == 0) {
366 styleWidth = "auto";
367 } else {
368 styleWidth += "px";
369 }
370 styleHeight = parseInt(height);
371 if (isNaN(styleHeight) || styleHeight == 0) {
372 styleHeight = "auto";
373 } else {
374 styleHeight += "px";
375 }
376 editor.renderPopup_insertImage(\'<img src="\'+file+\'" style="width: \'+styleWidth+\'; height: \'+styleHeight+\';"'.(($TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['enableClickEnlarge'] && !(is_array($this->buttonConfig['clickEnlarge.']) && $this->buttonConfig['clickEnlarge.']['disabled']))?' clickenlargesrc="\'+origFile+\'" clickenlarge="0"':'').' />\');
377 }
378 function launchView(url) {
379 var thePreviewWindow="";
380 thePreviewWindow = window.open("'.$this->siteUrl.TYPO3_mainDir.'show_item.php?table="+url,"ShowItem","height=300,width=410,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
381 if (thePreviewWindow && thePreviewWindow.focus) {
382 thePreviewWindow.focus();
383 }
384 }
385 function getCurrentImageRef() {
386 if (editor._selectedImage) {
387 return editor._selectedImage;
388 } else {
389 return null;
390 }
391 }
392 function printCurrentImageOptions() {
393 var classesImage = ' . ($this->thisConfig['classesImage']?'true':'false') . ';
394 if(classesImage) var styleSelector=\'<select name="iClass" style="width:140px;">' . $this->classesImageJSOptions . '</select>\';
395 var floatSelector=\'<select name="iFloat"><option value="">' . $LANG->getLL('notSet') . '</option><option value="none">' . $LANG->getLL('nonFloating') . '</option><option value="left">' . $LANG->getLL('left') . '</option><option value="right">' . $LANG->getLL('right') . '</option></select>\';
396 var bgColor=\' class="bgColor4"\';
397 var sz="";
398 sz+=\'<table border=0 cellpadding=1 cellspacing=1><form action="" name="imageData">\';
399 if(classesImage) {
400 sz+=\'<tr><td\'+bgColor+\'>'.$LANG->getLL('class').': </td><td>\'+styleSelector+\'</td></tr>\';
401 }
402 sz+=\'<tr><td\'+bgColor+\'>'.$LANG->getLL('width').': </td><td><input type="text" name="iWidth" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' /></td></tr>\';
403 sz+=\'<tr><td\'+bgColor+\'>'.$LANG->getLL('height').': </td><td><input type="text" name="iHeight" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' /></td></tr>\';
404 sz+=\'<tr><td\'+bgColor+\'>'.$LANG->getLL('border').': </td><td><input type="checkbox" name="iBorder" value="1" /></td></tr>\';
405 sz+=\'<tr><td\'+bgColor+\'>'.$LANG->getLL('float').': </td><td>\'+floatSelector+\'</td></tr>\';
406 sz+=\'<tr><td\'+bgColor+\'>'.$LANG->getLL('margin_lr').': </td><td><input type="text" name="iHspace" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).'></td></tr>\';
407 sz+=\'<tr><td\'+bgColor+\'>'.$LANG->getLL('margin_tb').': </td><td><input type="text" name="iVspace" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' /></td></tr>\';
408 sz+=\'<tr><td\'+bgColor+\'>'.$LANG->getLL('title').': </td><td><input type="text" name="iTitle"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' /></td></tr>\';
409 sz+=\'<tr><td\'+bgColor+\'>'.$LANG->getLL('alt').': </td><td><input type="text" name="iAlt"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' /></td></tr>\';
410 '.(($TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['enableClickEnlarge'] && !(is_array($this->buttonConfig['clickEnlarge.']) && $this->buttonConfig['clickEnlarge.']['disabled']))?'if (selectedImageRef && selectedImageRef.getAttribute("clickenlargesrc")) sz+=\'<tr><td\'+bgColor+\'><label for="iClickEnlarge">'.$LANG->sL('LLL:EXT:cms/locallang_ttc.php:image_zoom',1).' </label></td><td><input type="checkbox" name="iClickEnlarge" id="iClickEnlarge" value="1" /></td></tr>\';':'').' sz+=\'<tr><td><input type="submit" value="'.$LANG->getLL('update').'" onClick="return setImageProperties();"></td></tr>\';
411 sz+=\'</form></table>\';
412 return sz;
413 }
414 function setImageProperties() {
415 var classesImage = ' . ($this->thisConfig['classesImage']?'true':'false') . ';
416 if (selectedImageRef) {
417 if(document.imageData.iWidth.value && document.imageData.iWidth.value != "auto") {
418 selectedImageRef.style.width = document.imageData.iWidth.value + "px";
419 } else {
420 selectedImageRef.style.width = "auto";
421 }
422 selectedImageRef.removeAttribute("width");
423 if(document.imageData.iHeight.value && document.imageData.iHeight.value != "auto") {
424 selectedImageRef.style.height=document.imageData.iHeight.value + "px";
425 } else {
426 selectedImageRef.style.height = "auto";
427 }
428 selectedImageRef.removeAttribute("height");
429
430 selectedImageRef.style.paddingTop = "0px";
431 selectedImageRef.style.paddingBottom = "0px";
432 selectedImageRef.style.paddingRight = "0px";
433 selectedImageRef.style.paddingLeft = "0px";
434 selectedImageRef.style.padding = ""; // this statement ignored by Mozilla 1.3.1
435 if(document.imageData.iVspace.value != "" && !isNaN(parseInt(document.imageData.iVspace.value))) {
436 selectedImageRef.style.paddingTop = parseInt(document.imageData.iVspace.value) + "px";
437 selectedImageRef.style.paddingBottom = selectedImageRef.style.paddingTop;
438 }
439 if(document.imageData.iHspace.value != "" && !isNaN(parseInt(document.imageData.iHspace.value))) {
440 selectedImageRef.style.paddingRight = parseInt(document.imageData.iHspace.value) + "px";
441 selectedImageRef.style.paddingLeft = selectedImageRef.style.paddingRight;
442 }
443 selectedImageRef.removeAttribute("vspace");
444 selectedImageRef.removeAttribute("hspace");
445
446 selectedImageRef.title=document.imageData.iTitle.value;
447 selectedImageRef.alt=document.imageData.iAlt.value;
448
449 selectedImageRef.style.borderStyle = "none";
450 selectedImageRef.style.borderWidth = "0px";
451 selectedImageRef.style.border = ""; // this statement ignored by Mozilla 1.3.1
452 if(document.imageData.iBorder.checked) {
453 selectedImageRef.style.borderStyle = "solid";
454 selectedImageRef.style.borderWidth = "thin";
455 }
456 selectedImageRef.removeAttribute("border");
457
458 var iFloat = document.imageData.iFloat.options[document.imageData.iFloat.selectedIndex].value;
459 if (iFloat || selectedImageRef.style.cssFloat || selectedImageRef.style.styleFloat) {
460 if(document.all) {
461 selectedImageRef.style.styleFloat = iFloat;
462 } else {
463 selectedImageRef.style.cssFloat = iFloat;
464 }
465 }
466
467 if(classesImage) {
468 var iClass = document.imageData.iClass.options[document.imageData.iClass.selectedIndex].value;
469 if (iClass || (selectedImageRef.attributes["class"] && selectedImageRef.attributes["class"].value)) {
470 selectedImageRef.className = iClass;
471 }
472 }
473
474 '.(($TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['enableClickEnlarge'] && !(is_array($this->buttonConfig['clickEnlarge.']) && $this->buttonConfig['clickEnlarge.']['disabled']))?'
475 if (document.imageData.iClickEnlarge && document.imageData.iClickEnlarge.checked) selectedImageRef.setAttribute("clickenlarge","1");
476 else selectedImageRef.setAttribute("clickenlarge","0");':'').'
477
478 HTMLArea.edHidePopup();
479 }
480 return false;
481 }
482 function insertImagePropertiesInForm() {
483 var classesImage = ' . ($this->thisConfig['classesImage']?'true':'false') . ';
484 if (selectedImageRef) {
485 var styleWidth, styleHeight, paddingTop, paddingRight;
486 styleWidth = selectedImageRef.style.width ? selectedImageRef.style.width : selectedImageRef.width;
487 styleWidth = parseInt(styleWidth);
488 if (isNaN(styleWidth) || styleWidth == 0) { styleWidth = "auto"; }
489 document.imageData.iWidth.value = styleWidth;
490 styleHeight = selectedImageRef.style.height ? selectedImageRef.style.height : selectedImageRef.height;
491 styleHeight = parseInt(styleHeight);
492 if (isNaN(styleHeight) || styleHeight == 0) { styleHeight = "auto"; }
493 document.imageData.iHeight.value = styleHeight;
494
495 paddingTop = selectedImageRef.style.paddingTop ? selectedImageRef.style.paddingTop : selectedImageRef.vspace;
496 paddingTop = parseInt(paddingTop);
497 if (isNaN(paddingTop) || paddingTop < 0) { paddingTop = ""; }
498 document.imageData.iVspace.value = paddingTop;
499 paddingRight = selectedImageRef.style.paddingRight ? selectedImageRef.style.paddingRight : selectedImageRef.hspace;
500 paddingRight = parseInt(paddingRight);
501 if (isNaN(paddingRight) || paddingRight < 0) { paddingRight = ""; }
502 document.imageData.iHspace.value = paddingRight;
503
504 document.imageData.iTitle.value = selectedImageRef.title;
505 document.imageData.iAlt.value = selectedImageRef.alt;
506
507 if((selectedImageRef.style.borderStyle && selectedImageRef.style.borderStyle != "none" && selectedImageRef.style.borderStyle != "none none none none") || selectedImageRef.border) {
508 document.imageData.iBorder.checked = 1;
509 }
510
511 var fObj=document.imageData.iFloat;
512 var value = (selectedImageRef.style.cssFloat ? selectedImageRef.style.cssFloat : selectedImageRef.style.styleFloat);
513 var l=fObj.length;
514 for (a=0;a<l;a++) {
515 if (fObj.options[a].value == value) {
516 fObj.selectedIndex = a;
517 }
518 }
519
520 if(classesImage) {
521 var fObj=document.imageData.iClass;
522 var value=selectedImageRef.className;
523 var l=fObj.length;
524 for (a=0;a<l;a++) {
525 if (fObj.options[a].value == value) {
526 fObj.selectedIndex = a;
527 }
528 }
529 }
530
531 '.(($TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['enableClickEnlarge'] && !(is_array($this->buttonConfig['clickEnlarge.']) && $this->buttonConfig['clickEnlarge.']['disabled']))?'if (selectedImageRef.getAttribute("clickenlargesrc")) {
532 if (selectedImageRef.getAttribute("clickenlarge") == "1") document.imageData.iClickEnlarge.checked = 1;
533 else document.imageData.iClickEnlarge.removeAttribute("checked");
534 }':'').'
535 }
536 return false;
537 }
538
539 function openDragDrop() {
540 var url = "' . $BACK_PATH . t3lib_extMgm::extRelPath($this->extKey) . 'mod3/browse_links.php?mode=filedrag&editorNo='.$this->editorNo.'&bparams=|||"+escape("gif,jpg,jpeg,png");
541 window.opener.browserWin = window.open(url,"Typo3WinBrowser","height=350,width=600,status=0,menubar=0,resizable=1,scrollbars=1");
542 HTMLArea.edHidePopup();
543 }
544
545 var selectedImageRef = getCurrentImageRef(); // Setting this to a reference to the image object.
546
547 '.($this->act=='dragdrop'?'openDragDrop();':'');
548
549 // Finally, add the accumulated JavaScript to the template object:
550 $this->doc->JScode = $this->doc->wrapScriptTags($JScode);
551 }
552
553 /**
554 * Session data for this class can be set from outside with this method.
555 * Call after init()
556 *
557 * @param array Session data array
558 * @return array Session data and boolean which indicates that data needs to be stored in session because it's changed
559 */
560 function processSessionData($data) {
561 $store = false;
562
563 if ($this->act != 'image') {
564 if (isset($this->act)) {
565 $data['act'] = $this->act;
566 $store = true;
567 } else {
568 $this->act = $data['act'];
569 }
570 }
571
572 if (isset($this->expandFolder)) {
573 $data['expandFolder'] = $this->expandFolder;
574 $store = true;
575 } else {
576 $this->expandFolder = $data['expandFolder'];
577 }
578
579 return array($data, $store);
580 }
581
582 /**
583 * [Describe function...]
584 *
585 * @return [type] ...
586 */
587 function main_rte() {
588 global $LANG, $TYPO3_CONF_VARS, $FILEMOUNTS, $BE_USER;
589
590 // Starting content:
591 $this->content = $this->doc->startPage($LANG->getLL('Insert Image',1));
592
593 // Making menu in top:
594 $menuDef = array();
595 if (in_array('image',$this->allowedItems) && ($this->act=='image' || t3lib_div::_GP('cWidth'))) {
596 $menuDef['page']['isActive'] = $this->act=='image';
597 $menuDef['page']['label'] = $LANG->getLL('currentImage',1);
598 $menuDef['page']['url'] = '#';
599 $menuDef['page']['addParams'] = 'onClick="jumpToUrl(\'?act=image&editorNo='.$this->editorNo.'\');return false;"';
600 }
601 if (in_array('magic',$this->allowedItems)){
602 $menuDef['file']['isActive'] = $this->act=='magic';
603 $menuDef['file']['label'] = $LANG->getLL('magicImage',1);
604 $menuDef['file']['url'] = '#';
605 $menuDef['file']['addParams'] = 'onClick="jumpToUrl(\'?act=magic&editorNo='.$this->editorNo.'\');return false;"';
606 }
607 if (in_array('plain',$this->allowedItems)) {
608 $menuDef['url']['isActive'] = $this->act=='plain';
609 $menuDef['url']['label'] = $LANG->getLL('plainImage',1);
610 $menuDef['url']['url'] = '#';
611 $menuDef['url']['addParams'] = 'onClick="jumpToUrl(\'?act=plain&editorNo='.$this->editorNo.'\');return false;"';
612 }
613 if (in_array('dragdrop',$this->allowedItems)) {
614 $menuDef['mail']['isActive'] = $this->act=='dragdrop';
615 $menuDef['mail']['label'] = $LANG->getLL('dragDropImage',1);
616 $menuDef['mail']['url'] = '#';
617 $menuDef['mail']['addParams'] = 'onClick="openDragDrop();return false;"';
618 }
619 $this->content .= $this->doc->getTabMenuRaw($menuDef);
620
621 if ($this->act!='image') {
622
623 // ***************************
624 // Upload
625 // ***************************
626 // Create upload/create folder forms, if a path is given:
627 if ($BE_USER->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
628 $fileProcessor = t3lib_div::makeInstance('t3lib_basicFileFunctions');
629 $fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
630 $path=$this->expandFolder;
631 if (!$path || !@is_dir($path)) {
632 $path = $fileProcessor->findTempFolder().'/'; // The closest TEMP-path is found
633 }
634 if ($path!='/' && @is_dir($path)) {
635 $uploadForm=$this->uploadForm($path);
636 $createFolder=$this->createFolder($path);
637 } else {
638 $createFolder='';
639 $uploadForm='';
640 }
641 $this->content .= $uploadForm;
642 if ($BE_USER->isAdmin() || $BE_USER->getTSConfigVal('options.createFoldersInEB')) {
643 $this->content.=$createFolder;
644 }
645 }
646
647 // Getting flag for showing/not showing thumbnails:
648 $noThumbs = $BE_USER->getTSConfigVal('options.noThumbsInRTEimageSelect');
649
650 if (!$noThumbs) {
651 // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
652 $_MOD_MENU = array('displayThumbs' => '');
653 $_MCONF['name']='file_list';
654 $_MOD_SETTINGS = t3lib_BEfunc::getModuleData($_MOD_MENU, t3lib_div::_GP('SET'), $_MCONF['name']);
655 $addParams = '&act='.$this->act.'&editorNo='.$this->editorNo.'&expandFolder='.rawurlencode($this->expandFolder);
656 $thumbNailCheck = t3lib_BEfunc::getFuncCheck('','SET[displayThumbs]',$_MOD_SETTINGS['displayThumbs'],'select_image.php',$addParams,'id="checkDisplayThumbs"').' <label for="checkDisplayThumbs">'.$LANG->sL('LLL:EXT:lang/locallang_mod_file_list.php:displayThumbs',1).'</label>';
657 } else {
658 $thumbNailCheck='';
659 }
660
661 // File-folders:
662 $foldertree = t3lib_div::makeInstance('tx_rtehtmlarea_image_folderTree');
663 $tree=$foldertree->getBrowsableTree();
664 list(,,$specUid) = explode('_',t3lib_div::_GP('PM'));
665 $files = $this->expandFolder($foldertree->specUIDmap[$specUid],$this->act=='plain',$noThumbs?$noThumbs:!$_MOD_SETTINGS['displayThumbs']);
666
667 $this->content.= '<table border=0 cellpadding=0 cellspacing=0>
668 <tr>
669 <td valign=top>'.$this->barheader($LANG->getLL('folderTree').':').$tree.'</td>
670 <td>&nbsp;</td>
671 <td valign=top>'.$files.'</td>
672 </tr>
673 </table>
674 <br />'.$thumbNailCheck;
675
676 // ***************************
677 // Help
678 // ***************************
679 if ($this->act=='magic') {
680 $this->content .= $this->getMsgBox($LANG->getLL('magicImage_msg'));
681 }
682 if ($this->act=='plain') {
683 $this->content .= $this->getMsgBox(sprintf($LANG->getLL('plainImage_msg'), $this->plainMaxWidth, $this->plainMaxHeight));
684 }
685 } else {
686 $JScode = '
687 document.write(printCurrentImageOptions());
688 insertImagePropertiesInForm();';
689 $this->content.= '<br />'.$this->doc->wrapScriptTags($JScode);
690 }
691 $this->content.= $this->doc->endPage();
692 return $this->content;
693 }
694
695 /***************************
696 *
697 * OTHER FUNCTIONS:
698 *
699 ***************************/
700 /**
701 * @param [type] $expandFolder: ...
702 * @param [type] $plainFlag: ...
703 * @return [type] ...
704 */
705 function expandFolder($expandFolder=0,$plainFlag=0,$noThumbs=0) {
706 global $LANG, $BE_USER, $BACK_PATH;
707
708 $expandFolder = $expandFolder ? $expandFolder :t3lib_div::_GP('expandFolder');
709 $out='';
710
711 if ($expandFolder && $this->checkFolder($expandFolder)) {
712 $files = t3lib_div::getFilesInDir($expandFolder,($plainFlag?'jpg,jpeg,gif,png':$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']),1,1); // $extensionList="",$prependPath=0,$order="")
713 if (is_array($files)) {
714 reset($files);
715
716 $out.=$this->barheader(sprintf($LANG->getLL('images').' (%s):',count($files)));
717
718 $titleLen = intval($BE_USER->uc['titleLen']);
719 $picon='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/_icon_webfolders.gif','width="18" height="16"').' alt="" />';
720 $picon.=htmlspecialchars(t3lib_div::fixed_lgd(basename($expandFolder),$titleLen));
721 $out.='<span class="nobr">'.$picon.'</span><br />';
722
723 $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
724 $imgObj->init();
725 $imgObj->mayScaleUp=0;
726 $imgObj->tempPath=PATH_site.$imgObj->tempPath;
727
728 $lines=array();
729 while(list(,$filepath)=each($files)) {
730 $fI=pathinfo($filepath);
731
732 $origFile = t3lib_div::rawUrlEncodeFP(substr($filepath,strlen(PATH_site)));
733 $iurl = $this->siteUrl.$origFile;
734 $imgInfo = $imgObj->getImageDimensions($filepath);
735 // File icon:
736 $icon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
737 $pDim = $imgInfo[0].'x'.$imgInfo[1].' '.$LANG->getLL('pixels',1);
738 $size=' ('.t3lib_div::formatSize(filesize($filepath)).$LANG->getLL('bytes',1).', '.$pDim.')';
739 $icon = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/fileicons/'.$icon.'','width="18" height="16"').' title="'.htmlspecialchars($fI['basename'].$size).'" alt="" />';
740 if (!$plainFlag) {
741 $ATag = '<a href="#" onclick="return jumpToUrl(\'?editorNo='.$this->editorNo.'&insertMagicImage='.rawurlencode($filepath).'\');">';
742 } else {
743 $ATag = '<a href="#" onclick="return insertImage(\''.$iurl.'\','.$imgInfo[0].','.$imgInfo[1].',\''.$origFile.'\');">';
744 }
745 $ATag_e='</a>';
746 if ($plainFlag && (($imgInfo[0] > $this->plainMaxWidth) || ($imgInfo[1] > $this->plainMaxHeight))) {
747 $ATag='';
748 $ATag_e='';
749 $ATag2='';
750 $ATag2_e='';
751 } else {
752 $ATag2='<a href="#" onClick="launchView(\''.rawurlencode($filepath).'\'); return false;">';
753 $ATag2_e='</a>';
754 }
755
756 $filenameAndIcon=$ATag.$icon.htmlspecialchars(t3lib_div::fixed_lgd(basename($filepath),$titleLen)).$ATag_e;
757
758
759 $lines[]='<tr class="bgColor4"><td nowrap="nowrap">'.$filenameAndIcon.'&nbsp;</td><td nowrap="nowrap">'.$pDim.'&nbsp;</td></tr>';
760 $lines[]='<tr><td colspan="2">'.($noThumbs ? '' : $ATag2.t3lib_BEfunc::getThumbNail($this->doc->backPath.'thumbs.php',$filepath,'hspace="5" vspace="5" border="1"').$ATag2_e).
761 '</td></tr>';
762 $lines[]='<tr><td colspan="2"><img src="clear.gif" width="1" height="3"></td></tr>';
763 }
764 $out.='<table border="0" cellpadding="0" cellspacing="1">'.implode('',$lines).'</table>';
765 }
766 }
767 return $out;
768 }
769
770 /**
771 * For TBE: Makes an upload form for uploading files to the filemount the user is browsing.
772 * The files are uploaded to the tce_file.php script in the core which will handle the upload.
773 *
774 * @param string Absolute filepath on server to which to upload.
775 * @return string HTML for an upload form.
776 */
777 function uploadForm($path) {
778 global $BACK_PATH;
779 $count=3;
780
781 // Create header, showing upload path:
782 $header = t3lib_div::isFirstPartOfStr($path,PATH_site)?substr($path,strlen(PATH_site)):$path;
783 $code=$this->barheader($GLOBALS['LANG']->getLL('uploadImage').':');
784 $code.='
785
786 <!--
787 Form, for uploading files:
788 -->
789 <form action="'.$BACK_PATH.'tce_file.php" method="post" name="editform" enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'">
790 <table border="0" cellpadding="0" cellspacing="3" id="typo3-uplFiles">
791 <tr>
792 <td><strong>'.$GLOBALS['LANG']->getLL('path',1).':</strong> '.htmlspecialchars($header).'</td>
793 </tr>
794 <tr>
795 <td>';
796
797 // Traverse the number of upload fields (default is 3):
798 for ($a=1;$a<=$count;$a++) {
799 $code.='<input type="file" name="upload_'.$a.'"'.$this->doc->formWidth(35).' size="50" />
800 <input type="hidden" name="file[upload]['.$a.'][target]" value="'.htmlspecialchars($path).'" />
801 <input type="hidden" name="file[upload]['.$a.'][data]" value="'.$a.'" /><br />';
802 }
803
804 // Make footer of upload form, including the submit button:
805 $redirectValue = $this->thisScript.'?act='.$this->act.'&editorNo='.$this->editorNo.'&mode='.$this->mode.'&expandFolder='.rawurlencode($path).'&bparams='.rawurlencode($this->bparams);
806 $code.='<input type="hidden" name="redirect" value="'.htmlspecialchars($redirectValue).'" />'.
807 '<input type="submit" name="submit" value="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit',1).'" />';
808
809 $code.='
810 <div id="c-override">
811 <input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> <label for="overwriteExistingFiles">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xml:overwriteExistingFiles',1).'</label>
812 </div>
813 ';
814
815
816 $code.='</td>
817 </tr>
818 </table>
819 </form>';
820
821 return $code;
822 }
823
824
825 /**
826 * For TBE: Makes a form for creating new folders in the filemount the user is browsing.
827 * The folder creation request is sent to the tce_file.php script in the core which will handle the creation.
828 *
829 * @param string Absolute filepath on server in which to create the new folder.
830 * @return string HTML for the create folder form.
831 */
832 function createFolder($path) {
833 global $BACK_PATH;
834 // Create header, showing upload path:
835 $header = t3lib_div::isFirstPartOfStr($path,PATH_site)?substr($path,strlen(PATH_site)):$path;
836 $code=$this->barheader($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.pagetitle').':');
837 $code.='
838
839 <!--
840 Form, for creating new folders:
841 -->
842 <form action="'.$BACK_PATH.'tce_file.php" method="post" name="editform2">
843 <table border="0" cellpadding="0" cellspacing="3" id="typo3-crFolder">
844 <tr>
845 <td><strong>'.$GLOBALS['LANG']->getLL('path',1).':</strong> '.htmlspecialchars($header).'</td>
846 </tr>
847 <tr>
848 <td>';
849
850 // Create the new-folder name field:
851 $a=1;
852 $code.='<input'.$this->doc->formWidth(20).' type="text" name="file[newfolder]['.$a.'][data]" />'.
853 '<input type="hidden" name="file[newfolder]['.$a.'][target]" value="'.htmlspecialchars($path).'" />';
854
855 // Make footer of upload form, including the submit button:
856 $redirectValue = $this->thisScript.'?act='.$this->act.'&editorNo='.$this->editorNo.'&mode='.$this->mode.'&expandFolder='.rawurlencode($path).'&bparams='.rawurlencode($this->bparams);
857 $code.='<input type="hidden" name="redirect" value="'.htmlspecialchars($redirectValue).'" />'.
858 '<input type="submit" name="submit" value="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.submit',1).'" />';
859
860 $code.='</td>
861 </tr>
862 </table>
863 </form>';
864
865 return $code;
866 }
867
868
869 }
870
871 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']) {
872 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']);
873 }
874
875 ?>