* Merging all changes from TYPO3_4-0 branch back into HEAD
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / mod4 / 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
37 /**
38 * [CLASS/FUNCTION INDEX of SCRIPT]
39 *
40 *
41 *
42 * 92: class tx_rtehtmlarea_localFolderTree extends t3lib_folderTree
43 * 99: function wrapTitle($title,$v)
44 * 113: function printTree($treeArr="")
45 * 137: function PM_ATagWrap($icon,$cmd,$bMark="")
46 * 151: function ext_getRelFolder($path)
47 * 161: function ext_isLinkable($v)
48 *
49 *
50 * 192: class tx_rtehtmlarea_select_image
51 * 206: function preinit()
52 * 254: function rteImageStorageDir()
53 * 264: function magicProcess()
54 * 333: function init()
55 * 478: function main()
56 * 576: function printContent()
57 *
58 * SECTION: OTHER FUNCTIONS:
59 * 602: function expandFolder($expandFolder=0,$plainFlag=0)
60 * 684: function uploadForm($path)
61 * 708: function barheader($str)
62 * 720: function printCurrentUrl($str)
63 *
64 * TOTAL FUNCTIONS: 15
65 * (This index is automatically created/updated by the extension "extdeveval")
66 *
67 */
68
69 error_reporting (E_ALL ^ E_NOTICE);
70 unset($MCONF);
71 require ('conf.php');
72 require ($BACK_PATH.'init.php');
73 require ($BACK_PATH.'template.php');
74 require_once (PATH_t3lib.'class.t3lib_foldertree.php');
75 require_once (PATH_t3lib.'class.t3lib_stdgraphic.php');
76 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
77 $LANG->includeLLFile('EXT:rtehtmlarea/mod4/locallang.xml');
78
79 /**
80 * Local Folder Tree
81 *
82 * @author Kasper Skaarhoj <kasper@typo3.com>
83 * @package TYPO3
84 * @subpackage tx_rte
85 */
86 class tx_rtehtmlarea_image_localFolderTree extends t3lib_folderTree {
87 var $ext_IconMode=1;
88
89 /**
90 * Wrapping the title in a link, if applicable.
91 *
92 * @param string Title, ready for output.
93 * @param array The "record"
94 * @return string Wrapping title string.
95 */
96 function wrapTitle($title,$v) {
97 if ($this->ext_isLinkable($v)) {
98 $aOnClick = 'return jumpToUrl(\'?expandFolder='.rawurlencode($v['path']).'\');';
99 return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
100 } else {
101 return '<span class="typo3-dimmed">'.$title.'</span>';
102 }
103 }
104
105 /**
106 * Returns true if the input "record" contains a folder which can be linked.
107 *
108 * @param array Array with information about the folder element. Contains keys like title, uid, path, _title
109 * @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
110 */
111 function ext_isLinkable($v) {
112 $webpath=t3lib_BEfunc::getPathType_web_nonweb($v['path']);
113 if ($GLOBALS['SOBE']->act=='magic') return 1; //$webpath='web'; // The web/non-web path does not matter if the mode is 'magic'
114
115 if (strstr($v['path'],'_recycler_') || strstr($v['path'],'_temp_') || $webpath!='web') {
116 return 0;
117 }
118 return 1;
119 }
120
121 /**
122 * Wrap the plus/minus icon in a link
123 *
124 * @param string HTML string to wrap, probably an image tag.
125 * @param string Command for 'PM' get var
126 * @param boolean If set, the link will have a anchor point (=$bMark) and a name attribute (=$bMark)
127 * @return string Link-wrapped input string
128 * @access private
129 */
130 function PM_ATagWrap($icon,$cmd,$bMark='') {
131 if ($bMark) {
132 $anchor = '#'.$bMark;
133 $name=' name="'.$bMark.'"';
134 }
135 $aOnClick = 'return jumpToUrl(\'?PM='.$cmd.'\',\''.$anchor.'\');';
136 return '<a href="#"'.$name.' onclick="'.htmlspecialchars($aOnClick).'">'.$icon.'</a>';
137 }
138
139 /**
140 * Print tree.
141 *
142 * @param mixed Input tree array. If not array, then $this->tree is used.
143 * @return string HTML output of the tree.
144 */
145 function printTree($treeArr='') {
146 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
147
148 if (!is_array($treeArr)) $treeArr=$this->tree;
149
150 $out='';
151 $c=0;
152
153 // Traverse rows for the tree and print them into table rows:
154 foreach($treeArr as $k => $v) {
155 $c++;
156 $bgColor=' class="'.(($c+1)%2 ? 'bgColor' : 'bgColor-10').'"';
157 $out.='<tr'.$bgColor.'><td nowrap="nowrap">'.$v['HTML'].$this->wrapTitle(t3lib_div::fixed_lgd($v['row']['title'],$titleLen),$v['row']).'</td></tr>';
158 }
159
160 $out='<table border="0" cellpadding="0" cellspacing="0">'.$out.'</table>';
161 return $out;
162 }
163 }
164
165
166 /**
167 * Script Class
168 *
169 * @author Kasper Skaarhoj <kasper@typo3.com>
170 * @package TYPO3
171 * @subpackage tx_rte
172 */
173 class tx_rtehtmlarea_select_image {
174 var $content;
175 var $siteUrl;
176 var $act;
177 var $modData;
178 var $thisConfig;
179 var $allowedItems;
180 var $doc;
181 var $imgPath;
182 var $classesImageJSOptions;
183
184 /**
185 * Pre-initialization - the point is to do some processing before the actual init() function; In between we might have some magic-image processing going on...
186 *
187 * @return [type] ...
188 */
189 function preinit() {
190 global $BE_USER;
191
192 // Current site url:
193 $this->siteUrl = t3lib_div::getIndpEnv("TYPO3_SITE_URL");
194
195 // Determine nature of current url:
196 $this->act=t3lib_div::_GP("act");
197
198 $this->modData = $BE_USER->getModuleData("select_image.php","ses");
199 if ($this->act!="image") {
200 if (isset($this->act)) {
201 $this->modData["act"]=$this->act;
202 $BE_USER->pushModuleData("select_image.php",$this->modData);
203 } else {
204 $this->act=$this->modData["act"];
205 }
206 }
207 $expandPage = t3lib_div::_GP("expandFolder");
208 if (isset($expandPage)) {
209 $this->modData["expandFolder"]=$expandPage;
210 $BE_USER->pushModuleData("select_image.php",$this->modData);
211 } else {
212 t3lib_div::_GETset($this->modData["expandFolder"],'expandFolder');
213 }
214
215 if (!$this->act) {
216 $this->act="magic";
217 }
218
219 $RTEtsConfigParts = explode(":",t3lib_div::_GP("RTEtsConfigParams"));
220 // if (count($RTEtsConfigParts)<2) die("Error: The GET parameter 'RTEtsConfigParams' was missing. Close the window.");
221 $RTEsetup = $GLOBALS["BE_USER"]->getTSConfig("RTE",t3lib_BEfunc::getPagesTSconfig($RTEtsConfigParts[5]));
222 $this->thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup["properties"],$RTEtsConfigParts[0],$RTEtsConfigParts[2],$RTEtsConfigParts[4]);
223 $this->imgPath = $RTEtsConfigParts[6];
224
225 $this->allowedItems = array_diff(explode(",","magic,plain,dragdrop,image"),t3lib_div::trimExplode(",",$this->thisConfig["blindImageOptions"],1));
226 reset($this->allowedItems);
227 if (!in_array($this->act,$this->allowedItems)) $this->act = current($this->allowedItems);
228
229 if($this->thisConfig['classesImage']) {
230 $classesImageArray = t3lib_div::trimExplode(',',$this->thisConfig['classesImage'],1);
231 $this->classesImageJSOptions = '<option value=""></option>';
232 reset($classesImageArray);
233 while(list(,$class)=each($classesImageArray)) {
234 $this->classesImageJSOptions .= '<option value="' .$class . '">' . $class . '</option>';
235 }
236 }
237 }
238
239 /**
240 * [Describe function...]
241 *
242 * @return [type] ...
243 */
244 function rteImageStorageDir() {
245 $dir = $this->imgPath ? $this->imgPath : $GLOBALS["TYPO3_CONF_VARS"]["BE"]["RTE_imageStorageDir"];;
246 return $dir;
247 }
248
249 /**
250 * [Describe function...]
251 *
252 * @return [type] ...
253 */
254 function magicProcess() {
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 @copy($imgInfo[3],$destName);
274
275 $cHeight=t3lib_div::intInRange(t3lib_div::_GP("cHeight"),0,500);
276 $cWidth=t3lib_div::intInRange(t3lib_div::_GP("cWidth"),0,500);
277 if (!$cHeight) $cHeight=200;
278 if (!$cWidth) $cWidth=300;
279 // This thing allows 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
280 $cHeight=1000;
281
282 // debug(array($cHeight,$cWidth));
283 //exit;
284 $imgI = $imgObj->imageMagickConvert($filepath,"WEB",$cWidth."m",$cHeight."m"); // ($imagefile,$newExt,$w,$h,$params,$frame,$options,$mustCreate=0)
285 // debug($imgI);
286 if ($imgI[3]) {
287 $fI=pathinfo($imgI[3]);
288 $mainBase="RTEmagicC_".substr(basename($destName),10).".".$fI["extension"];
289 $destName = $fileFunc->getUniqueName($mainBase,$destPath);
290 @copy($imgI[3],$destName);
291
292 $iurl = $this->siteUrl.substr($destName,strlen(PATH_site));
293 echo'
294 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
295 <html>
296 <head>
297 <title>Untitled</title>
298 </head>
299 <script language="javascript" type="text/javascript">
300 /*<![CDATA[*/
301 var editor = parent.editor;
302 var HTMLArea = parent.HTMLArea;
303 function insertImage(file,width,height) {
304 var styleWidth, styleHeight;
305 styleWidth = parseInt(width);
306 if (isNaN(styleWidth) || styleWidth == 0) {
307 styleWidth = "auto";
308 } else {
309 styleWidth += "px";
310 }
311 styleHeight = parseInt(height);
312 if (isNaN(styleHeight) || styleHeight == 0) {
313 styleHeight = "auto";
314 } else {
315 styleHeight += "px";
316 }
317 editor.renderPopup_insertImage(\'<img src="\'+file+\'" style="width: \'+styleWidth+\'; height: \'+styleHeight+\';" />\');
318 }
319 /*]]>*/
320 </script>
321 <body>
322 <script language="javascript" type="text/javascript">
323 /*<![CDATA[*/
324 insertImage(\''.$iurl.'\','.$imgI[0].','.$imgI[1].');
325 /*]]>*/
326 </script>
327 </body>
328 </html>';
329 }
330
331 }
332 }
333 exit;
334 }
335 }
336
337 /**
338 * [Describe function...]
339 *
340 * @return [type] ...
341 */
342 function init() {
343 global $LANG,$BACK_PATH;
344
345 $this->doc = t3lib_div::makeInstance('template');
346 $this->doc->backPath = $BACK_PATH;
347 $this->doc->JScode='
348 <script language="javascript" type="text/javascript">
349 /*<![CDATA[*/
350 var editor = parent.editor;
351 var HTMLArea = parent.HTMLArea;
352 function jumpToUrl(URL,anchor) { //
353 var add_act = URL.indexOf("act=")==-1 ? "&act='.$this->act.'" : "";
354 var RTEtsConfigParams = "&RTEtsConfigParams='.rawurlencode(t3lib_div::_GP('RTEtsConfigParams')).'";
355
356 var cur_width = selectedImageRef ? "&cWidth="+selectedImageRef.style.width : "";
357 var cur_height = selectedImageRef ? "&cHeight="+selectedImageRef.style.height : "";
358
359 var theLocation = URL+add_act+RTEtsConfigParams+cur_width+cur_height+(anchor?anchor:"");
360 window.location.href = theLocation;
361 return false;
362 }
363 function insertImage(file,width,height) {
364 var styleWidth, styleHeight;
365 styleWidth = parseInt(width);
366 if (isNaN(styleWidth) || styleWidth == 0) {
367 styleWidth = "auto";
368 } else {
369 styleWidth += "px";
370 }
371 styleHeight = parseInt(height);
372 if (isNaN(styleHeight) || styleHeight == 0) {
373 styleHeight = "auto";
374 } else {
375 styleHeight += "px";
376 }
377 editor.renderPopup_insertImage(\'<img src="\'+file+\'" style="width: \'+styleWidth+\'; height: \'+styleHeight+\';" />\');
378 }
379 function launchView(url) {
380 var thePreviewWindow="";
381 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");
382 if (thePreviewWindow && thePreviewWindow.focus) {
383 thePreviewWindow.focus();
384 }
385 }
386 function getCurrentImageRef() {
387 if (editor._selectedImage) {
388 return editor._selectedImage;
389 } else {
390 return null;
391 }
392 }
393 function printCurrentImageOptions() {
394 var classesImage = ' . ($this->thisConfig['classesImage']?'true':'false') . ';
395 if(classesImage) var styleSelector=\'<select name="iClass" style="width:140px;">' . $this->classesImageJSOptions . '</select>\';
396 // var alignSelector=\'<select name="iAlign" style="width:60px;"><option value=""></option><option value="left">Left</option><option value="right">Right</option></select>\';
397 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>\';
398 var bgColor=\' class="bgColor4"\';
399 var sz="";
400 sz+=\'<table border=0 cellpadding=1 cellspacing=1><form action="" name="imageData">\';
401 if(classesImage) {
402 sz+=\'<tr><td\'+bgColor+\'>'.$LANG->getLL("class").': \'+styleSelector+\'</td></tr>\';
403 }
404 sz+=\'<tr><td\'+bgColor+\'>'.$LANG->getLL("width").': <input type="text" name="iWidth" value=""'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' />&nbsp;&nbsp;'.$LANG->getLL("height").': <input type="text" name="iHeight" value=""'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' />&nbsp;&nbsp;'.$LANG->getLL("border").': <input type="checkbox" name="iBorder" value="1" /></td></tr>\';
405 sz+=\'<tr><td\'+bgColor+\'>'.$LANG->getLL("float").': \'+floatSelector+\'</td></tr>\';
406 sz+=\'<tr><td\'+bgColor+\'>'.$LANG->getLL("margin_lr").': <input type="text" name="iHspace" value=""'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).'>&nbsp;&nbsp;'.$LANG->getLL("margin_tb").': <input type="text" name="iVspace" value=""'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' /></td></tr>\';
407 // sz+=\'<tr><td\'+bgColor+\'>Textwrapping: \'+alignSelector+\'&nbsp;&nbsp;Style: \'+styleSelector+\'</td></tr>\';
408 sz+=\'<tr><td\'+bgColor+\'>'.$LANG->getLL("title").': <input type="text" name="iTitle"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(20).' /></td></tr>\';
409 sz+=\'<tr><td\'+bgColor+\'>'.$LANG->getLL("alt").': <input type="text" name="iAlt"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(20).' /></td></tr>\';
410 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 /*
468 var iAlign = document.imageData.iAlign.options[document.imageData.iAlign.selectedIndex].value;
469 if (iAlign || selectedImageRef.align) {
470 selectedImageRef.align=iAlign;
471 }
472 selectedImageRef.style.cssText="";
473 */
474 if(classesImage) {
475 var iClass = document.imageData.iClass.options[document.imageData.iClass.selectedIndex].value;
476 if (iClass || (selectedImageRef.attributes["class"] && selectedImageRef.attributes["class"].value)) {
477 selectedImageRef.className = iClass;
478 }
479 }
480 HTMLArea.edHidePopup();
481 }
482 return false;
483 }
484 function insertImagePropertiesInForm() {
485 var classesImage = ' . ($this->thisConfig['classesImage']?'true':'false') . ';
486 if (selectedImageRef) {
487 var styleWidth, styleHeight, paddingTop, paddingRight;
488 styleWidth = selectedImageRef.style.width ? selectedImageRef.style.width : selectedImageRef.width;
489 styleWidth = parseInt(styleWidth);
490 if (isNaN(styleWidth) || styleWidth == 0) { styleWidth = "auto"; }
491 document.imageData.iWidth.value = styleWidth;
492 styleHeight = selectedImageRef.style.height ? selectedImageRef.style.height : selectedImageRef.height;
493 styleHeight = parseInt(styleHeight);
494 if (isNaN(styleHeight) || styleHeight == 0) { styleHeight = "auto"; }
495 document.imageData.iHeight.value = styleHeight;
496
497 paddingTop = selectedImageRef.style.paddingTop ? selectedImageRef.style.paddingTop : selectedImageRef.vspace;
498 paddingTop = parseInt(paddingTop);
499 if (isNaN(paddingTop) || paddingTop < 0) { paddingTop = ""; }
500 document.imageData.iVspace.value = paddingTop;
501 paddingRight = selectedImageRef.style.paddingRight ? selectedImageRef.style.paddingRight : selectedImageRef.hspace;
502 paddingRight = parseInt(paddingRight);
503 if (isNaN(paddingRight) || paddingRight < 0) { paddingRight = ""; }
504 document.imageData.iHspace.value = paddingRight;
505
506 document.imageData.iTitle.value = selectedImageRef.title;
507 document.imageData.iAlt.value = selectedImageRef.alt;
508
509 if((selectedImageRef.style.borderStyle && selectedImageRef.style.borderStyle != "none" && selectedImageRef.style.borderStyle != "none none none none") || selectedImageRef.border) {
510 document.imageData.iBorder.checked = 1;
511 }
512
513 var fObj=document.imageData.iFloat;
514 var value = (selectedImageRef.style.cssFloat ? selectedImageRef.style.cssFloat : selectedImageRef.style.styleFloat);
515 var l=fObj.length;
516 for (a=0;a<l;a++) {
517 if (fObj.options[a].value == value) {
518 fObj.selectedIndex = a;
519 }
520 }
521
522 /*
523 // Update align
524 var fObj=document.imageData.iAlign;
525 var value=selectedImageRef.align;
526 var l=fObj.length;
527 for (a=0;a<l;a++) {
528 if (fObj.options[a].value == value) {
529 fObj.selectedIndex = a;
530 }
531 }
532 */
533
534 if(classesImage) {
535 var fObj=document.imageData.iClass;
536 var value=selectedImageRef.className;
537 var l=fObj.length;
538 for (a=0;a<l;a++) {
539 if (fObj.options[a].value == value) {
540 fObj.selectedIndex = a;
541 }
542 }
543 }
544
545 }
546 return false;
547 }
548
549 function openDragDrop() {
550 var url = "' . $BACK_PATH . t3lib_extMgm::extRelPath('rtehtmlarea') . 'mod3/browse_links.php?mode=filedrag&bparams=|||"+escape("gif,jpg,jpeg,png");
551 parent.opener.browserWin = window.open(url,"Typo3WinBrowser","height=350,width=600,status=0,menubar=0,resizable=1,scrollbars=1");
552 HTMLArea.edHidePopup();
553 }
554
555 var selectedImageRef = getCurrentImageRef(); // Setting this to a reference to the image object.
556
557 '.($this->act=="dragdrop"?"openDragDrop();":"").'
558
559 // alert(selectedImageRef.href);
560 /*]]>*/
561 </script>
562 ';
563
564 // Starting content:
565 $this->content="";
566 $this->content.=$this->doc->startPage("RTE image insert");
567 }
568
569 /**
570 * [Describe function...]
571 *
572 * @return [type] ...
573 */
574 function main() {
575 global $LANG, $TYPO3_CONF_VARS, $FILEMOUNTS, $BE_USER;
576
577 $menu='<table border=0 cellpadding=2 cellspacing=1><tr>';
578 $bgcolor=' class="bgColor4"';
579 $bgcolorA=' class="bgColor5"';
580 if ($this->act=="image" || t3lib_div::_GP("cWidth")) { // If $this->act is specifically set to "image" or if cWidth is passed around...
581 $menu.='<td align=center nowrap="nowrap" width="25%"'.($this->act=="image"?$bgcolorA:$bgcolor).'><a href="#" onClick="jumpToUrl(\'?act=image\');return false;"><strong>'.$LANG->getLL("currentImage").'</strong></a></td>';
582 }
583 if (in_array("magic",$this->allowedItems)) $menu.='<td align=center nowrap="nowrap" width="25%"'.($this->act=="magic"?$bgcolorA:$bgcolor).'><a href="#" onClick="jumpToUrl(\'?act=magic\');return false;"><strong>'.$LANG->getLL("magicImage").'</strong></a></td>';
584 if (in_array("plain",$this->allowedItems)) $menu.='<td align=center nowrap="nowrap" width="25%"'.($this->act=="plain"?$bgcolorA:$bgcolor).'><a href="#" onClick="jumpToUrl(\'?act=plain\');return false;"><strong>'.$LANG->getLL("plainImage").'</strong></a></td>';
585 if (in_array("dragdrop",$this->allowedItems)) $menu.='<td align=center nowrap="nowrap" width="25%"'.$bgcolor.'><a href="#" onClick="openDragDrop();return false;"><strong>'.$LANG->getLL("dragDropImage").'</strong></a></td>';
586 $menu.='</tr></table>';
587
588 $this->content.='<img src=clear.gif width=1 height=2>';
589 $this->content.=$menu;
590 $this->content.='<img src=clear.gif width=1 height=10>';
591
592 if ($this->act!="image") {
593
594 // Getting flag for showing/not showing thumbnails:
595 $noThumbs = $GLOBALS["BE_USER"]->getTSConfigVal("options.noThumbsInRTEimageSelect");
596
597 if (!$noThumbs) {
598 // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
599 $_MOD_MENU = array('displayThumbs' => '');
600 $_MCONF['name']='file_list';
601 $_MOD_SETTINGS = t3lib_BEfunc::getModuleData($_MOD_MENU, t3lib_div::_GP('SET'), $_MCONF['name']);
602 $addParams = '&act='.$this->act.'&expandFolder='.rawurlencode($this->modData["expandFolder"]);
603 $thumbNailCheck = t3lib_BEfunc::getFuncCheck('','SET[displayThumbs]',$_MOD_SETTINGS['displayThumbs'],'select_image.php',$addParams).' '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.php:displayThumbs',1);
604 } else {
605 $thumbNailCheck='';
606 }
607
608 // File-folders:
609 $foldertree = t3lib_div::makeInstance("tx_rtehtmlarea_image_localFolderTree");
610 $tree=$foldertree->getBrowsableTree();
611 list(,,$specUid) = explode("_",t3lib_div::_GP("PM"));
612 $files = $this->expandFolder($foldertree->specUIDmap[$specUid],$this->act=="plain",$noThumbs?$noThumbs:!$_MOD_SETTINGS['displayThumbs']);
613
614 $this->content.= '<table border=0 cellpadding=0 cellspacing=0>
615 <tr>
616 <td valign=top>'.$this->barheader($LANG->getLL("folderTree").':').$tree.'</td>
617 <td>&nbsp;</td>
618 <td valign=top>'.$files.'</td>
619 </tr>
620 </table>
621 <BR>'.$thumbNailCheck;
622
623 /*
624
625 // Target:
626 if ($this->act!="mail") {
627 $ltarget='<table border=0 cellpadding=2 cellspacing=1><form name="ltargetform" id="ltargetform"><tr>';
628 $ltarget.='<td width=90>Target:</td>';
629 $ltarget.='<td><input type="text" name="ltarget" onChange="setTarget(this.value);" value="'.htmlspecialchars($curUrlArray["target"]).'"></td>';
630 $ltarget.='<td><select name="ltarget_type" onChange="setTarget(this.options[this.selectedIndex].value);document.ltargetform.ltarget.value=this.options[this.selectedIndex].value;this.selectedIndex=0;">
631 <option></option>
632 <option value="_top">Top</option>
633 <option value="_blank">New window</option>
634 </select></td>';
635 if (($curUrlInfo["act"]=="page" || $curUrlInfo["act"]=="file") && $curUrlArray["href"]) {
636 $ltarget.='<td><input type="submit" value="Update" onClick="return link_current();"></td>';
637 }
638 $ltarget.='</tr></form></table>';
639
640 $this->content.=$ltarget;
641 }
642 */
643
644 // ***************************
645 // Upload
646 // ***************************
647 // Adding upload forms if applicable:
648 if ($BE_USER->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
649 $fileProcessor = t3lib_div::makeInstance("t3lib_basicFileFunctions");
650 $fileProcessor->init($FILEMOUNTS, $TYPO3_CONF_VARS["BE"]["fileExtensions"]);
651 $path=t3lib_div::_GP("expandFolder");
652
653 if (!$path || $path=="/" || !@is_dir($path)) {
654 $path = $fileProcessor->findTempFolder(); // The closest TEMP-path is found
655 if ($path) $path.="/";
656 }
657 if ($path && @is_dir($path)) {
658 $this->content.=$this->uploadForm($path)."<BR>";
659 }
660 }
661
662 // ***************************
663 // Help
664 // ***************************
665
666 if ($this->act=="magic") {
667 $this->content.='<img src="'.$this->doc->backPath.'gfx/icon_note.gif" width="18" height="16" align=top>'.$LANG->getLL("magicImage_msg").'<BR>';
668 }
669 if ($this->act=="plain") {
670 $resolutionLimit_x = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plainImageMaxWidth'] ? $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plainImageMaxWidth'] : 640;
671 $resolutionLimit_y = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plainImageMaxHeight'] ? $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plainImageMaxHeight'] : 680;
672 $this->content.='<img src="'.$this->doc->backPath.'gfx/icon_note.gif" width="18" height="16" align=top>' . sprintf($LANG->getLL('plainImage_msg'), $resolutionLimit_x, $resolutionLimit_y) . '<br />';
673
674 //$this->content.='<img src="'.$this->doc->backPath.'gfx/icon_note.gif" width="18" height="16" align=top>'.$LANG->getLL("plainImage_msg").'<BR>';
675 }
676 } else {
677 $this->content.='
678 <script language="javascript" type="text/javascript">
679 document.write(printCurrentImageOptions());
680 insertImagePropertiesInForm();
681 </script>
682 ';
683 }
684 }
685
686 /**
687 * Print content of module
688 *
689 * @return void
690 */
691 function printContent() {
692 $this->content.= $this->doc->endPage();
693 echo $this->content;
694 }
695
696 /***************************
697 *
698 * OTHER FUNCTIONS:
699 *
700 ***************************/
701 /**
702 * @param [type] $expandFolder: ...
703 * @param [type] $plainFlag: ...
704 * @return [type] ...
705 */
706 function expandFolder($expandFolder=0,$plainFlag=0,$noThumbs=0) {
707 global $LANG;
708
709 $expandFolder = $expandFolder ? $expandFolder :t3lib_div::_GP("expandFolder");
710 $out="";
711
712 $resolutionLimit_x = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plainImageMaxWidth'] ? $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plainImageMaxWidth'] : 640;
713 $resolutionLimit_y = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plainImageMaxHeight'] ? $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plainImageMaxHeight'] : 680;
714
715 if ($expandFolder) {
716 $files = t3lib_div::getFilesInDir($expandFolder,($plainFlag?"jpg,jpeg,gif,png":$GLOBALS["TYPO3_CONF_VARS"]["GFX"]["imagefile_ext"]),1,1); // $extensionList="",$prependPath=0,$order="")
717 if (is_array($files)) {
718 reset($files);
719
720 $out.=$this->barheader(sprintf($LANG->getLL("images").' (%s):',count($files)));
721
722 $titleLen=intval($GLOBALS["BE_USER"]->uc["titleLen"]);
723 $picon='<img src="'.$this->doc->backPath.'gfx/i/_icon_webfolders.gif" width="18" height="16" align=top>';
724 $picon.=htmlspecialchars(t3lib_div::fixed_lgd(basename($expandFolder),$titleLen));
725 $out.='<span class="nobr">'.$picon.'</span><BR>';
726
727 $imgObj = t3lib_div::makeInstance("t3lib_stdGraphic");
728 $imgObj->init();
729 $imgObj->mayScaleUp=0;
730 $imgObj->tempPath=PATH_site.$imgObj->tempPath;
731
732 $lines=array();
733 while(list(,$filepath)=each($files)) {
734 $fI=pathinfo($filepath);
735
736 $iurl = $this->siteUrl.t3lib_div::rawUrlEncodeFP(substr($filepath,strlen(PATH_site)));
737 $imgInfo = $imgObj->getImageDimensions($filepath);
738
739 $icon = t3lib_BEfunc::getFileIcon(strtolower($fI["extension"]));
740 $pDim = $imgInfo[0]."x".$imgInfo[1]." pixels";
741 $size=" (".t3lib_div::formatSize(filesize($filepath))."bytes, ".$pDim.")";
742 $icon = '<img src="'.$this->doc->backPath.'gfx/fileicons/'.$icon.'" width=18 height=16 border=0 title="'.$fI["basename"].$size.'" class="absmiddle">';
743 if (!$plainFlag) {
744 $ATag = '<a href="#" onclick="return jumpToUrl(\'?insertMagicImage='.rawurlencode($filepath).'\');">';
745 } else {
746 $ATag = '<a href="#" onclick="return insertImage(\''.$iurl.'\','.$imgInfo[0].','.$imgInfo[1].');">';
747 }
748 $ATag_e="</a>";
749 if ($plainFlag && ($imgInfo[0]>$resolutionLimit_x || $imgInfo[1]>$resolutionLimit_y)) {
750 $ATag="";
751 $ATag_e="";
752 $ATag2="";
753 $ATag2_e="";
754 } else {
755 $ATag2='<a href="#" onClick="launchView(\''.rawurlencode($filepath).'\'); return false;">';
756 $ATag2_e="</a>";
757 }
758
759 $filenameAndIcon=$ATag.$icon.htmlspecialchars(t3lib_div::fixed_lgd(basename($filepath),$titleLen)).$ATag_e;
760
761
762 $lines[]='<tr class="bgColor4"><td nowrap="nowrap">'.$filenameAndIcon.'&nbsp;</td><td nowrap="nowrap">'.$pDim.'&nbsp;</td></tr>';
763 $lines[]='<tr><td colspan=2>'.(
764 $noThumbs ?
765 "" :
766 $ATag2.t3lib_BEfunc::getThumbNail($this->doc->backPath.'thumbs.php',$filepath,'hspace="5" vspace="5" border="1"').$ATag2_e).
767 '</td></tr>';
768 $lines[]='<tr><td colspan=2><img src="clear.gif" width=1 height=3></td></tr>';
769 }
770 $out.='<table border=0 cellpadding=0 cellspacing=1>'.implode("",$lines).'</table>';
771 }
772 }
773 return $out;
774 }
775
776 /**
777 * [Describe function...]
778 *
779 * @param [type] $path: ...
780 * @return [type] ...
781 */
782 function uploadForm($path) {
783 global $LANG,$SOBE;
784 // debug($path);
785 $count=1;
786 $header = t3lib_div::isFirstPartOfStr($path,PATH_site)?substr($path,strlen(PATH_site)):$path;
787 $code=$this->barheader($LANG->getLL("uploadImage").":");
788 $code.='<table border=0 cellpadding=0 cellspacing=3><FORM action="'.$this->doc->backPath.'tce_file.php" method="post" name="editform" enctype="'.$GLOBALS["TYPO3_CONF_VARS"]["SYS"]["form_enctype"].'"><tr><td>';
789 $code.="<strong>".$LANG->getLL("path").":</strong> ".$header."</td></tr><tr><td>";
790 for ($a=1;$a<=$count;$a++) {
791 $code.='<input type="File" name="upload_'.$a.'"'.$this->doc->formWidth(35).' size="50">
792 <input type="Hidden" name="file[upload]['.$a.'][target]" value="'.$path.'">
793 <input type="Hidden" name="file[upload]['.$a.'][data]" value="'.$a.'"><BR>';
794 }
795 $code.='
796 <input type="Hidden" name="redirect" value="' . $BACK_PATH . t3lib_extMgm::extRelPath('rtehtmlarea').'mod4/select_image.php?act='.$this->act.'&expandFolder='.rawurlencode($path).'&RTEtsConfigParams='.rawurlencode(t3lib_div::_GP("RTEtsConfigParams")).'">
797 <input type="Submit" name="submit" value="'.$LANG->sL("LLL:EXT:lang/locallang_core.php:file_upload.php.submit").'">
798 <div id="c-override">
799 <input type="checkbox" name="overwriteExistingFiles" value="1" /> '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.php:overwriteExistingFiles',1).'
800 </div>
801
802 </td>
803 </tr>
804 </FORM>
805 </table>';
806
807 return $code;
808 }
809
810 /**
811 * [Describe function...]
812 *
813 * @param [type] $str: ...
814 * @return [type] ...
815 */
816 function barheader($str) {
817 global $LANG,$SOBE;
818
819 return '<table border=0 cellpadding=2 cellspacing=0 width=100% class="bgColor5"><tr><td><strong>'.$str.'</strong></td></tr></table>';
820 }
821
822 /**
823 * [Describe function...]
824 *
825 * @param [type] $str: ...
826 * @return [type] ...
827 */
828 function printCurrentUrl($str) {
829 global $LANG,$SOBE;
830
831 return '<table border=0 cellpadding=0 cellspacing=0 width=100% class="bgColor5"><tr><td><strong>Current Link:</strong> '.$str.'</td></tr></table>';
832 }
833 }
834
835 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod4/select_image.php']) {
836 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod4/select_image.php']);
837 }
838
839
840
841 // Make instance:
842 $SOBE = t3lib_div::makeInstance('tx_rtehtmlarea_select_image');
843 $SOBE->preinit();
844 $SOBE->magicProcess();
845 $SOBE->init();
846 $SOBE->main();
847 $SOBE->printContent();
848
849 ?>