Fixed bug #17438: htmlArea RTE: non-xhtml markup in image dialogue
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / mod4 / class.tx_rtehtmlarea_select_image.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasper@typo3.com)
6 * (c) 2004-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 * Displays image selector for the RTE
30 *
31 * @author Kasper Skårhøj <kasper@typo3.com>
32 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
33 *
34 * $Id$ *
35 */
36 require_once(PATH_typo3.'class.browse_links.php');
37
38 /**
39 * Local Folder Tree
40 *
41 * @author Kasper Skårhøj <kasper@typo3.com>
42 * @package TYPO3
43 * @subpackage tx_rte
44 */
45 class tx_rtehtmlarea_image_folderTree extends t3lib_folderTree {
46 var $ext_IconMode=1;
47
48 /**
49 * Wrapping the title in a link, if applicable.
50 *
51 * @param string Title, ready for output.
52 * @param array The "record"
53 * @return string Wrapping title string.
54 */
55 function wrapTitle($title,$v) {
56 $title = htmlspecialchars($title);
57
58 if ($this->ext_isLinkable($v)) {
59 $aOnClick = 'return jumpToUrl(\'?editorNo='.$GLOBALS['SOBE']->browser->editorNo.'&expandFolder='.rawurlencode($v['path']).'\');';
60 return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
61 } else {
62 return '<span class="typo3-dimmed">'.$title.'</span>';
63 }
64 }
65
66 /**
67 * Returns true if the input "record" contains a folder which can be linked.
68 *
69 * @param array Array with information about the folder element. Contains keys like title, uid, path, _title
70 * @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
71 */
72 function ext_isLinkable($v) {
73 $webpath=t3lib_BEfunc::getPathType_web_nonweb($v['path']);
74 if ($GLOBALS['SOBE']->browser->act=='magic') return 1; //$webpath='web'; // The web/non-web path does not matter if the mode is 'magic'
75
76 if (strstr($v['path'],'_recycler_') || strstr($v['path'],'_temp_') || $webpath!='web') {
77 return 0;
78 }
79 return 1;
80 }
81
82 /**
83 * Wrap the plus/minus icon in a link
84 *
85 * @param string HTML string to wrap, probably an image tag.
86 * @param string Command for 'PM' get var
87 * @param boolean If set, the link will have a anchor point (=$bMark) and a name attribute (=$bMark)
88 * @return string Link-wrapped input string
89 * @access private
90 */
91 function PM_ATagWrap($icon,$cmd,$bMark='') {
92 if ($bMark) {
93 $anchor = '#'.$bMark;
94 $name=' name="'.$bMark.'"';
95 }
96 $aOnClick = 'return jumpToUrl(\'?PM='.$cmd.'\',\''.$anchor.'\');';
97 return '<a href="#"'.$name.' onclick="'.htmlspecialchars($aOnClick).'">'.$icon.'</a>';
98 }
99
100 /**
101 * Print tree.
102 *
103 * @param mixed Input tree array. If not array, then $this->tree is used.
104 * @return string HTML output of the tree.
105 */
106 function printTree($treeArr='') {
107 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
108
109 if (!is_array($treeArr)) $treeArr=$this->tree;
110
111 $out='';
112 $c=0;
113
114 // Traverse rows for the tree and print them into table rows:
115 foreach($treeArr as $k => $v) {
116 $c++;
117 $bgColor=' class="'.(($c+1)%2 ? 'bgColor' : 'bgColor-10').'"';
118 $out.='<tr'.$bgColor.'><td nowrap="nowrap">'.$v['HTML'].$this->wrapTitle(t3lib_div::fixed_lgd_cs($v['row']['title'],$titleLen),$v['row']).'</td></tr>';
119 }
120
121 $out='<table border="0" cellpadding="0" cellspacing="0">'.$out.'</table>';
122 return $out;
123 }
124 }
125
126
127 /**
128 * Script Class
129 *
130 * @author Kasper Skårhøj <kasper@typo3.com>
131 * @package TYPO3
132 * @subpackage tx_rte
133 */
134 class tx_rtehtmlarea_select_image extends browse_links {
135 var $extKey = 'rtehtmlarea';
136 var $content;
137
138 public $allowedItems;
139 public $allowedFileTypes = array();
140 protected $defaultClass;
141 protected $plainMaxWidth;
142 protected $plainMaxHeight;
143 protected $magicMaxWidth;
144 protected $magicMaxHeight;
145 protected $imgPath;
146 protected $RTEImageStorageDir;
147
148 public $editorNo;
149 public $sys_language_content;
150 public $thisConfig;
151 public $buttonConfig;
152
153 protected $imgObj; // Instance object of t3lib_stdGraphic
154
155 /**
156 * Initialisation
157 *
158 * @return void
159 */
160 function init() {
161 global $BACK_PATH;
162
163 $this->initVariables();
164 $this->initConfiguration();
165 $this->initHookObjects();
166
167 // init fileProcessor
168 $this->fileProcessor = t3lib_div::makeInstance('t3lib_basicFileFunctions');
169 $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
170
171 $this->allowedItems = $this->getAllowedItems('magic,plain,image', $this->buttonConfig);
172 reset($this->allowedItems);
173 if (!in_array($this->act,$this->allowedItems)) {
174 $this->act = current($this->allowedItems);
175 }
176
177 $this->insertImage();
178
179 // Creating backend template object:
180 $this->doc = t3lib_div::makeInstance('template');
181 $this->doc->bodyTagAdditions = $this->getBodyTagAdditions();
182 $this->doc->backPath = $BACK_PATH;
183
184 // Load the Prototype library and browse_links.js
185 $this->doc->getPageRenderer()->loadPrototype();
186 $this->doc->loadJavascriptLib('js/browse_links.js');
187
188 $this->doc->getContextMenuCode();
189 }
190
191 /**
192 * Initialize class variables
193 *
194 * @return void
195 */
196 public function initVariables() {
197
198 // Process bparams
199 $this->bparams = t3lib_div::_GP('bparams');
200 $pArr = explode('|', $this->bparams);
201 $pRteArr = explode(':', $pArr[1]);
202 $this->editorNo = $pRteArr[0];
203 $this->sys_language_content = $pRteArr[1];
204 $this->RTEtsConfigParams = $pArr[2];
205 if (!$this->editorNo) {
206 $this->editorNo = t3lib_div::_GP('editorNo');
207 $this->sys_language_content = t3lib_div::_GP('sys_language_content');
208 $this->RTEtsConfigParams = t3lib_div::_GP('RTEtsConfigParams');
209 }
210 $this->expandPage = t3lib_div::_GP('expandPage');
211 $this->expandFolder = t3lib_div::_GP('expandFolder');
212 $pArr[1] = implode(':', array($this->editorNo, $this->sys_language_content));
213 $pArr[2] = $this->RTEtsConfigParams;
214 if ($this->act == 'dragdrop' || $this->act == 'plain') {
215 $this->allowedFileTypes = explode(',','jpg,jpeg,gif,png');
216 }
217 $pArr[3] = implode(',', $this->allowedFileTypes);
218 $this->bparams = implode('|', $pArr);
219
220 // Find "mode"
221 $this->mode = t3lib_div::_GP('mode');
222 if (!$this->mode) {
223 $this->mode = 'rte';
224 }
225 // Site URL
226 $this->siteURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL'); // Current site url
227
228 // the script to link to
229 $this->thisScript = t3lib_div::getIndpEnv('SCRIPT_NAME');
230
231 // Get "act"
232 $this->act = t3lib_div::_GP('act');
233 if (!$this->act) {
234 $this->act = 'magic';
235 }
236 }
237
238 /**
239 * Initialize hook objects implementing interface t3lib_browseLinksHook
240 *
241 * @return void
242 */
243 protected function initHookObjects() {
244 global $TYPO3_CONF_VARS;
245 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']['browseLinksHook'])) {
246 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']['browseLinksHook'] as $classData) {
247 $processObject = t3lib_div::getUserObj($classData);
248 if(!($processObject instanceof t3lib_browseLinksHook)) {
249 throw new UnexpectedValueException('$processObject must implement interface t3lib_browseLinksHook', 1195115652);
250 }
251 $parameters = array();
252 $processObject->init($this, $parameters);
253 $this->hookObjects[] = $processObject;
254 }
255 }
256 }
257
258 /**
259 * Provide the additional parameters to be included in the template body tag
260 *
261 * @return string the body tag additions
262 */
263 public function getBodyTagAdditions() {
264 return 'onload="initEventListeners();"';
265 }
266
267 /**
268 * Get the path to the folder where RTE images are stored
269 *
270 * @return string the path to the folder where RTE images are stored
271 */
272 protected function getRTEImageStorageDir() {
273 return ($this->imgPath ? $this->imgPath : $GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir']);
274 }
275
276 /**
277 * Insert the image in the editing area
278 *
279 * @return void
280 */
281 protected function insertImage() {
282 if (t3lib_div::_GP('insertImage')) {
283 $filepath = t3lib_div::_GP('insertImage');
284 $imgInfo = $this->getImageInfo($filepath);
285 switch ($this->act) {
286 case 'magic':
287 $this->insertMagicImage($filepath, $imgInfo);
288 exit;
289 break;
290 case 'plain':
291 $this->insertPlainImage($imgInfo);
292 exit;
293 break;
294 default:
295 // Call hook
296 foreach ($this->hookObjects as $hookObject) {
297 if (method_exists($hookObject, "insertElement")) {
298 $hookObject->insertElement($this->act);
299 }
300 }
301 break;
302 }
303 }
304 }
305
306 /**
307 * Get the information on the image file identified its path
308 *
309 * @param string $filepath: the path to the image file
310 *
311 * @return array a 4-elements information array about the file
312 */
313 public function getImageInfo($filepath) {
314 $this->imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
315 $this->imgObj->init();
316 $this->imgObj->mayScaleUp = 0;
317 $this->imgObj->tempPath = PATH_site.$this->imgObj->tempPath;
318 return $this->imgObj->getImageDimensions($filepath);
319 }
320
321 /**
322 * Insert a magic image
323 *
324 * @param string $filepath: the path to the image file
325 * @param array $imgInfo: a 4-elements information array about the file
326 * @param string $altText: text for the alt attribute of the image
327 * @param string $titleText: text for the title attribute of the image
328 * @param string $additionalParams: text representing more HTML attributes to be added on the img tag
329 * @return void
330 */
331 public function insertMagicImage($filepath, $imgInfo, $altText='', $titleText='', $additionalParams='') {
332 if (is_array($imgInfo) && count($imgInfo) == 4) {
333 if ($this->RTEImageStorageDir) {
334 $fI = pathinfo($imgInfo[3]);
335 $fileFunc = t3lib_div::makeInstance('t3lib_basicFileFunctions');
336 $basename = $fileFunc->cleanFileName('RTEmagicP_'.$fI['basename']);
337 $destPath =PATH_site.$this->RTEImageStorageDir;
338 if (@is_dir($destPath)) {
339 $destName = $fileFunc->getUniqueName($basename,$destPath);
340 @copy($imgInfo[3],$destName);
341 t3lib_div::fixPermissions($destName);
342 $cWidth = t3lib_div::intInRange(t3lib_div::_GP('cWidth'), 0, $this->magicMaxWidth);
343 $cHeight = t3lib_div::intInRange(t3lib_div::_GP('cHeight'), 0, $this->magicMaxHeight);
344 if (!$cWidth) $cWidth = $this->magicMaxWidth;
345 if (!$cHeight) $cHeight = $this->magicMaxHeight;
346
347 $imgI = $this->imgObj->imageMagickConvert($filepath,'WEB',$cWidth.'m',$cHeight.'m'); // ($imagefile,$newExt,$w,$h,$params,$frame,$options,$mustCreate=0)
348 if ($imgI[3]) {
349 $fI=pathinfo($imgI[3]);
350 $mainBase='RTEmagicC_'.substr(basename($destName),10).'.'.$fI['extension'];
351 $destName = $fileFunc->getUniqueName($mainBase,$destPath);
352 @copy($imgI[3],$destName);
353 t3lib_div::fixPermissions($destName);
354 $destName = dirname($destName).'/'.rawurlencode(basename($destName));
355 $iurl = $this->siteURL.substr($destName,strlen(PATH_site));
356 $this->imageInsertJS($iurl, $imgI[0], $imgI[1], $altText, $titleText, $additionalParams);
357 } else {
358 t3lib_div::sysLog('Attempt at creating a magic image failed due to error converting image: "' . $filepath . '".', $this->extKey . '/tx_rtehtmlarea_select_image', t3lib_div::SYSLOG_SEVERITY_ERROR);
359 }
360 } else {
361 t3lib_div::sysLog('Attempt at creating a magic image failed due to incorrect destination path: "' . $destPath . '".', $this->extKey . '/tx_rtehtmlarea_select_image', t3lib_div::SYSLOG_SEVERITY_ERROR);
362 }
363 } else {
364 t3lib_div::sysLog('Attempt at creating a magic image failed due to absent RTE_imageStorageDir', $this->extKey . '/tx_rtehtmlarea_select_image', t3lib_div::SYSLOG_SEVERITY_ERROR);
365 }
366 } else {
367 t3lib_div::sysLog('Attempt at creating a magic image failed due to missing image file info.', $this->extKey . '/tx_rtehtmlarea_select_image', t3lib_div::SYSLOG_SEVERITY_ERROR);
368 }
369 }
370
371 /**
372 * Insert a plain image
373 *
374 * @param array $imgInfo: a 4-elements information array about the file
375 * @param string $altText: text for the alt attribute of the image
376 * @param string $titleText: text for the title attribute of the image
377 * @param string $additionalParams: text representing more HTML attributes to be added on the img tag
378 * @return void
379 */
380 public function insertPlainImage($imgInfo, $altText='', $titleText='', $additionalParams='') {
381 if (is_array($imgInfo) && count($imgInfo)==4) {
382 $iurl = $this->siteURL.substr($imgInfo[3],strlen(PATH_site));
383 $this->imageInsertJS($iurl, $imgInfo[0], $imgInfo[1], $altText, $titleText, $additionalParams);
384 }
385 }
386
387 /**
388 * Echo the HTML page and JS that will insert the image
389 *
390 * @param string $url: the url of the image
391 * @param integer $width: the width of the image
392 * @param integer $height: the height of the image
393 * @param string $altText: text for the alt attribute of the image
394 * @param string $titleText: text for the title attribute of the image
395 * @param string $additionalParams: text representing more html attributes to be added on the img tag
396 * @return void
397 */
398 protected function imageInsertJS($url, $width, $height, $altText='', $titleText='', $additionalParams='') {
399 echo'
400 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
401 <html>
402 <head>
403 <title>Untitled</title>
404 <script type="text/javascript">
405 /*<![CDATA[*/
406 var plugin = window.parent.RTEarea["' . $this->editorNo . '"].editor.getPlugin("TYPO3Image");
407 function insertImage(file,width,height,alt,title,additionalParams) {
408 plugin.insertImage(\'<img src="\'+file+\'" width="\'+parseInt(width)+\'" height="\'+parseInt(height)+\'"\'' . ($this->defaultClass?('+\' class="'.$this->defaultClass.'"\''):'') .
409 '+(alt?\' alt="\'+alt+\'"\':\'\')+(title?\' title="\'+title+\'"\':\'\')+(additionalParams?\' \'+additionalParams:\'\')+\' />\');
410 }
411 /*]]>*/
412 </script>
413 </head>
414 <body>
415 <script type="text/javascript">
416 /*<![CDATA[*/
417 insertImage('.t3lib_div::quoteJSvalue($url,1).','.$width.','.$height.','.t3lib_div::quoteJSvalue($altText,1).','.t3lib_div::quoteJSvalue($titleText,1).','.t3lib_div::quoteJSvalue($additionalParams, 1).');
418 /*]]>*/
419 </script>
420 </body>
421 </html>';
422 }
423
424 /**
425 * Generate JS code to be used on the image insert/modify dialogue
426 *
427 * @param string $act: the action to be performed
428 * @param string $editorNo: the number of the RTE instance on the page
429 * @param string $sys_language_content: the language of the content element
430 *
431 * @return string the generated JS code
432 */
433 function getJSCode($act, $editorNo, $sys_language_content) {
434 global $LANG, $TYPO3_CONF_VARS;
435
436 $removedProperties = array();
437 if (is_array($this->buttonConfig['properties.'])) {
438 if ($this->buttonConfig['properties.']['removeItems']) {
439 $removedProperties = t3lib_div::trimExplode(',',$this->buttonConfig['properties.']['removeItems'],1);
440 }
441 }
442
443 if ($this->thisConfig['classesImage']) {
444 $classesImageArray = t3lib_div::trimExplode(',', $this->thisConfig['classesImage'], 1);
445 $classesImageJSOptions = '<option value=""></option>';
446 foreach ($classesImageArray as $class) {
447 $classesImageJSOptions .= '<option value="' .$class . '">' . $class . '</option>';
448 }
449 }
450
451 $lockPlainWidth = 'false';
452 $lockPlainHeight = 'false';
453 if (is_array($this->thisConfig['proc.']) && $this->thisConfig['proc.']['plainImageMode']) {
454 $plainImageMode = $this->thisConfig['proc.']['plainImageMode'];
455 $lockPlainWidth = ($plainImageMode == 'lockDimensions')?'true':'false';
456 $lockPlainHeight = ($lockPlainWidth || $plainImageMode == 'lockRatio' || ($plainImageMode == 'lockRatioWhenSmaller'))?'true':'false';
457 }
458
459 $JScode='
460 var plugin = window.parent.RTEarea["' . $editorNo . '"].editor.getPlugin("TYPO3Image");
461 var HTMLArea = window.parent.HTMLArea;
462 function initEventListeners() {
463 if (Ext.isWebKit) {
464 Ext.EventManager.addListener(window.document.body, "dragend", plugin.onDrop, plugin, { single: true });
465 }
466 }
467 function jumpToUrl(URL,anchor) {
468 var add_act = URL.indexOf("act=")==-1 ? "&act='.$act.'" : "";
469 var add_editorNo = URL.indexOf("editorNo=")==-1 ? "&editorNo='.$editorNo.'" : "";
470 var add_sys_language_content = URL.indexOf("sys_language_content=")==-1 ? "&sys_language_content='.$sys_language_content.'" : "";
471 var RTEtsConfigParams = "&RTEtsConfigParams='.rawurlencode($this->RTEtsConfigParams).'";
472
473 var cur_width = selectedImageRef ? "&cWidth="+selectedImageRef.style.width : "";
474 var cur_height = selectedImageRef ? "&cHeight="+selectedImageRef.style.height : "";
475
476 var theLocation = URL+add_act+add_editorNo+add_sys_language_content+RTEtsConfigParams+cur_width+cur_height+(anchor?anchor:"");
477 window.location.href = theLocation;
478 return false;
479 }
480 function insertImage(file,width,height) {
481 plugin.insertImage(\'<img src="\'+file+\'"' . ($this->defaultClass?(' class="'.$this->defaultClass.'"'):'') . ' width="\'+parseInt(width)+\'" height="\'+parseInt(height)+\'" />\');
482 }
483 function launchView(url) {
484 var thePreviewWindow="";
485 thePreviewWindow = window.open("'.t3lib_div::getIndpEnv('TYPO3_SITE_URL').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");
486 if (thePreviewWindow && thePreviewWindow.focus) {
487 thePreviewWindow.focus();
488 }
489 }
490 function getCurrentImageRef() {
491 if (plugin.image) {
492 return plugin.image;
493 } else {
494 return null;
495 }
496 }
497 function printCurrentImageOptions() {
498 var classesImage = ' . ($this->thisConfig['classesImage']?'true':'false') . ';
499 if (classesImage) var styleSelector=\'<select id="iClass" name="iClass" style="width:140px;">' . $classesImageJSOptions . '</select>\';
500 var floatSelector=\'<select id="iFloat" 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>\';
501 if (plugin.getButton("Language")) {
502 var languageSelector = \'<select id="iLang" name="iLang">\';
503 plugin.getButton("Language").getStore().each(function (record) {
504 languageSelector +=\'<option value="\' + record.get("value") + \'">\' + record.get("text") + \'</option>\';
505 });
506 languageSelector += \'</select>\';
507 }
508 var bgColor=\' class="bgColor4"\';
509 var sz="";
510 sz+=\'<table border="0" cellpadding="1" cellspacing="1"><form action="" name="imageData">\';
511 '.(in_array('class', $removedProperties)?'':'
512 if(classesImage) {
513 sz+=\'<tr><td\'+bgColor+\'><label for="iClass">'.$LANG->getLL('class').': </label></td><td>\'+styleSelector+\'</td></tr>\';
514 }')
515 .(in_array('width', $removedProperties)?'':'
516 if (!(selectedImageRef && selectedImageRef.src.indexOf("RTEmagic") == -1 && '. $lockPlainWidth .')) {
517 sz+=\'<tr><td\'+bgColor+\'><label for="iWidth">'.$LANG->getLL('width').': </label></td><td><input type="text" id="iWidth" name="iWidth" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' /></td></tr>\';
518 }')
519 .(in_array('height', $removedProperties)?'':'
520 if (!(selectedImageRef && selectedImageRef.src.indexOf("RTEmagic") == -1 && '. $lockPlainHeight .')) {
521 sz+=\'<tr><td\'+bgColor+\'><label for="iHeight">'.$LANG->getLL('height').': </label></td><td><input type="text" id="iHeight" name="iHeight" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' /></td></tr>\';
522 }')
523 .(in_array('border', $removedProperties)?'':'
524 sz+=\'<tr><td\'+bgColor+\'><label for="iBorder">'.$LANG->getLL('border').': </label></td><td><input type="checkbox" id="iBorder" name="iBorder" value="1" /></td></tr>\';')
525 .(in_array('float', $removedProperties)?'':'
526 sz+=\'<tr><td\'+bgColor+\'><label for="iFloat">'.$LANG->getLL('float').': </label></td><td>\'+floatSelector+\'</td></tr>\';')
527 .(in_array('paddingTop', $removedProperties)?'':'
528 sz+=\'<tr><td\'+bgColor+\'><label for="iPaddingTop">'.$LANG->getLL('padding_top').': </label></td><td><input type="text" id="iPaddingTop" name="iPaddingTop" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).'></td></tr>\';')
529 .(in_array('paddingRight', $removedProperties)?'':'
530 sz+=\'<tr><td\'+bgColor+\'><label for="iPaddingRight">'.$LANG->getLL('padding_right').': </label></td><td><input type="text" id="iPaddingRight" name="iPaddingRight" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' /></td></tr>\';')
531 .(in_array('paddingBottom', $removedProperties)?'':'
532 sz+=\'<tr><td\'+bgColor+\'><label for="iPaddingBottom">'.$LANG->getLL('padding_bottom').': </label></td><td><input type="text" id="iPaddingBottom" name="iPaddingBottom" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' /></td></tr>\';')
533 .(in_array('paddingLeft', $removedProperties)?'':'
534 sz+=\'<tr><td\'+bgColor+\'><label for="iPaddingLeft">'.$LANG->getLL('padding_left').': </label></td><td><input type="text" id="iPaddingLeft" name="iPaddingLeft" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' /></td></tr>\';')
535 .(in_array('title', $removedProperties)?'':'
536 sz+=\'<tr><td\'+bgColor+\'><label for="iTitle">'.$LANG->getLL('title').': </label></td><td><input type="text" id="iTitle" name="iTitle"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' /></td></tr>\';')
537 .(in_array('alt', $removedProperties)?'':'
538 sz+=\'<tr><td\'+bgColor+\'><label for="iAlt">'.$LANG->getLL('alt').': </label></td><td><input type="text" id="iAlt" name="iAlt"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' /></td></tr>\';')
539 .(in_array('lang', $removedProperties)?'':'
540 if (plugin.getButton("Language")) {
541 sz+=\'<tr><td\'+bgColor+\'><label for="iLang">\' + plugin.editor.getPlugin("Language").localize(\'Language-Tooltip\') + \': </label></td><td>\' + languageSelector + \'</td></tr>\';
542 }')
543 .(in_array('clickenlarge', $removedProperties)?'':'
544 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="0" /></td></tr>\';').'
545 sz+=\'<tr><td><input type="submit" value="'.$LANG->getLL('update').'" onClick="return setImageProperties();"></td></tr>\';
546 sz+=\'</form></table>\';
547 return sz;
548 }
549 function setImageProperties() {
550 var classesImage = ' . ($this->thisConfig['classesImage']?'true':'false') . ';
551 if (selectedImageRef) {
552 if (document.imageData.iWidth) {
553 if (document.imageData.iWidth.value && parseInt(document.imageData.iWidth.value)) {
554 selectedImageRef.style.width = "";
555 selectedImageRef.width = parseInt(document.imageData.iWidth.value);
556 }
557 }
558 if (document.imageData.iHeight) {
559 if (document.imageData.iHeight.value && parseInt(document.imageData.iHeight.value)) {
560 selectedImageRef.style.height = "";
561 selectedImageRef.height = parseInt(document.imageData.iHeight.value);
562 }
563 }
564 if (document.imageData.iPaddingTop) {
565 if (document.imageData.iPaddingTop.value != "" && !isNaN(parseInt(document.imageData.iPaddingTop.value))) {
566 selectedImageRef.style.paddingTop = parseInt(document.imageData.iPaddingTop.value) + "px";
567 } else {
568 selectedImageRef.style.paddingTop = "";
569 }
570 }
571 if (document.imageData.iPaddingRight) {
572 if (document.imageData.iPaddingRight.value != "" && !isNaN(parseInt(document.imageData.iPaddingRight.value))) {
573 selectedImageRef.style.paddingRight = parseInt(document.imageData.iPaddingRight.value) + "px";
574 } else {
575 selectedImageRef.style.paddingRight = "";
576 }
577 }
578 if (document.imageData.iPaddingBottom) {
579 if (document.imageData.iPaddingBottom.value != "" && !isNaN(parseInt(document.imageData.iPaddingBottom.value))) {
580 selectedImageRef.style.paddingBottom = parseInt(document.imageData.iPaddingBottom.value) + "px";
581 } else {
582 selectedImageRef.style.paddingBottom = "";
583 }
584 }
585 if (document.imageData.iPaddingLeft) {
586 if (document.imageData.iPaddingLeft.value != "" && !isNaN(parseInt(document.imageData.iPaddingLeft.value))) {
587 selectedImageRef.style.paddingLeft = parseInt(document.imageData.iPaddingLeft.value) + "px";
588 } else {
589 selectedImageRef.style.paddingLeft = "";
590 }
591 }
592 if (document.imageData.iTitle) {
593 selectedImageRef.title=document.imageData.iTitle.value;
594 }
595 if (document.imageData.iAlt) {
596 selectedImageRef.alt=document.imageData.iAlt.value;
597 }
598 if (document.imageData.iBorder) {
599 selectedImageRef.style.borderStyle = "";
600 selectedImageRef.style.borderWidth = "";
601 selectedImageRef.style.border = ""; // this statement ignored by Mozilla 1.3.1
602 selectedImageRef.style.borderTopStyle = "";
603 selectedImageRef.style.borderRightStyle = "";
604 selectedImageRef.style.borderBottomStyle = "";
605 selectedImageRef.style.borderLeftStyle = "";
606 selectedImageRef.style.borderTopWidth = "";
607 selectedImageRef.style.borderRightWidth = "";
608 selectedImageRef.style.borderBottomWidth = "";
609 selectedImageRef.style.borderLeftWidth = "";
610 if(document.imageData.iBorder.checked) {
611 selectedImageRef.style.borderStyle = "solid";
612 selectedImageRef.style.borderWidth = "thin";
613 }
614 selectedImageRef.removeAttribute("border");
615 }
616 if (document.imageData.iFloat) {
617 var iFloat = document.imageData.iFloat.options[document.imageData.iFloat.selectedIndex].value;
618 if (document.all) {
619 selectedImageRef.style.styleFloat = iFloat ? iFloat : "";
620 } else {
621 selectedImageRef.style.cssFloat = iFloat ? iFloat : "";
622 }
623 }
624 if (classesImage && document.imageData.iClass) {
625 var iClass = document.imageData.iClass.options[document.imageData.iClass.selectedIndex].value;
626 if (iClass || (selectedImageRef.attributes["class"] && selectedImageRef.attributes["class"].value)) {
627 selectedImageRef.className = iClass;
628 } else {
629 selectedImageRef.className = "";
630 }
631 }
632 if (document.imageData.iLang) {
633 var iLang = document.imageData.iLang.options[document.imageData.iLang.selectedIndex].value;
634 var languageObject = plugin.editor.getPlugin("Language");
635 if (iLang || languageObject.getLanguageAttribute(selectedImageRef)) {
636 languageObject.setLanguageAttributes(selectedImageRef, iLang);
637 } else {
638 languageObject.setLanguageAttributes(selectedImageRef, "none");
639 }
640 }
641 if (document.imageData.iClickEnlarge) {
642 if (document.imageData.iClickEnlarge.checked) {
643 selectedImageRef.setAttribute("clickenlarge","1");
644 } else {
645 selectedImageRef.removeAttribute("clickenlarge");
646 }
647 }
648 plugin.close();
649 }
650 return false;
651 }
652 function insertImagePropertiesInForm() {
653 var classesImage = ' . ($this->thisConfig['classesImage']?'true':'false') . ';
654 if (selectedImageRef) {
655 var styleWidth, styleHeight, padding;
656 if (document.imageData.iWidth) {
657 styleWidth = selectedImageRef.style.width ? selectedImageRef.style.width : selectedImageRef.width;
658 styleWidth = parseInt(styleWidth);
659 if (!(isNaN(styleWidth) || styleWidth == 0)) {
660 document.imageData.iWidth.value = styleWidth;
661 }
662 }
663 if (document.imageData.iHeight) {
664 styleHeight = selectedImageRef.style.height ? selectedImageRef.style.height : selectedImageRef.height;
665 styleHeight = parseInt(styleHeight);
666 if (!(isNaN(styleHeight) || styleHeight == 0)) {
667 document.imageData.iHeight.value = styleHeight;
668 }
669 }
670 if (document.imageData.iPaddingTop) {
671 var padding = selectedImageRef.style.paddingTop ? selectedImageRef.style.paddingTop : selectedImageRef.vspace;
672 var padding = parseInt(padding);
673 if (isNaN(padding) || padding <= 0) { padding = ""; }
674 document.imageData.iPaddingTop.value = padding;
675 }
676 if (document.imageData.iPaddingRight) {
677 padding = selectedImageRef.style.paddingRight ? selectedImageRef.style.paddingRight : selectedImageRef.hspace;
678 var padding = parseInt(padding);
679 if (isNaN(padding) || padding <= 0) { padding = ""; }
680 document.imageData.iPaddingRight.value = padding;
681 }
682 if (document.imageData.iPaddingBottom) {
683 var padding = selectedImageRef.style.paddingBottom ? selectedImageRef.style.paddingBottom : selectedImageRef.vspace;
684 var padding = parseInt(padding);
685 if (isNaN(padding) || padding <= 0) { padding = ""; }
686 document.imageData.iPaddingBottom.value = padding;
687 }
688 if (document.imageData.iPaddingLeft) {
689 var padding = selectedImageRef.style.paddingLeft ? selectedImageRef.style.paddingLeft : selectedImageRef.hspace;
690 var padding = parseInt(padding);
691 if (isNaN(padding) || padding <= 0) { padding = ""; }
692 document.imageData.iPaddingLeft.value = padding;
693 }
694 if (document.imageData.iTitle) {
695 document.imageData.iTitle.value = selectedImageRef.title;
696 }
697 if (document.imageData.iAlt) {
698 document.imageData.iAlt.value = selectedImageRef.alt;
699 }
700 if (document.imageData.iBorder) {
701 if((selectedImageRef.style.borderStyle && selectedImageRef.style.borderStyle != "none" && selectedImageRef.style.borderStyle != "none none none none") || selectedImageRef.border) {
702 document.imageData.iBorder.checked = 1;
703 }
704 }
705 if (document.imageData.iFloat) {
706 var fObj=document.imageData.iFloat;
707 var value = (selectedImageRef.style.cssFloat ? selectedImageRef.style.cssFloat : selectedImageRef.style.styleFloat);
708 var l=fObj.length;
709 for (var a=0;a<l;a++) {
710 if (fObj.options[a].value == value) {
711 fObj.selectedIndex = a;
712 }
713 }
714 }
715 if (classesImage && document.imageData.iClass) {
716 var fObj=document.imageData.iClass;
717 var value=selectedImageRef.className;
718 var l=fObj.length;
719 for (var a=0;a < l; a++) {
720 if (fObj.options[a].value == value) {
721 fObj.selectedIndex = a;
722 }
723 }
724 }
725 if (document.imageData.iLang) {
726 var fObj=document.imageData.iLang;
727 var value=plugin.editor.getPlugin("Language").getLanguageAttribute(selectedImageRef);
728 for (var i = 0, n = fObj.length; i < n; i++) {
729 if (fObj.options[i].value == value) {
730 fObj.selectedIndex = i;
731 if (i) {
732 fObj.options[0].text = plugin.editor.getPlugin("Language").localize("Remove language mark");
733 }
734 }
735 }
736 }
737 if (document.imageData.iClickEnlarge) {
738 if (selectedImageRef.getAttribute("clickenlarge") == "1") {
739 document.imageData.iClickEnlarge.checked = 1;
740 } else {
741 document.imageData.iClickEnlarge.checked = 0;
742 }
743 }
744 return false;
745 }
746 }
747
748 var selectedImageRef = getCurrentImageRef();'; // Setting this to a reference to the image object.
749 return $JScode;
750 }
751
752 /**
753 * Session data for this class can be set from outside with this method.
754 * Call after init()
755 *
756 * @param array Session data array
757 * @return array Session data and boolean which indicates that data needs to be stored in session because it's changed
758 */
759 function processSessionData($data) {
760 $store = false;
761
762 if ($this->act != 'image') {
763 if (isset($this->act)) {
764 $data['act'] = $this->act;
765 $store = true;
766 } else {
767 $this->act = $data['act'];
768 }
769 }
770
771 if (isset($this->expandFolder)) {
772 $data['expandFolder'] = $this->expandFolder;
773 $store = true;
774 } else {
775 $this->expandFolder = $data['expandFolder'];
776 }
777
778 return array($data, $store);
779 }
780
781 /**
782 * [Describe function...]
783 *
784 * @return [type] ...
785 */
786 function main_rte() {
787 global $LANG, $TYPO3_CONF_VARS, $FILEMOUNTS, $BE_USER;
788
789 // Starting content:
790 $this->content = $this->doc->startPage($LANG->getLL('Insert Image',1));
791
792 // Making menu in top:
793 $menuDef = array();
794 if (in_array('image',$this->allowedItems) && ($this->act=='image' || t3lib_div::_GP('cWidth'))) {
795 $menuDef['page']['isActive'] = $this->act=='image';
796 $menuDef['page']['label'] = $LANG->getLL('currentImage',1);
797 $menuDef['page']['url'] = '#';
798 $menuDef['page']['addParams'] = 'onClick="jumpToUrl(\'?act=image&bparams='.$this->bparams.'\');return false;"';
799 }
800 if (in_array('magic',$this->allowedItems)){
801 $menuDef['file']['isActive'] = $this->act=='magic';
802 $menuDef['file']['label'] = $LANG->getLL('magicImage',1);
803 $menuDef['file']['url'] = '#';
804 $menuDef['file']['addParams'] = 'onClick="jumpToUrl(\'?act=magic&bparams='.$this->bparams.'\');return false;"';
805 }
806 if (in_array('plain',$this->allowedItems)) {
807 $menuDef['url']['isActive'] = $this->act=='plain';
808 $menuDef['url']['label'] = $LANG->getLL('plainImage',1);
809 $menuDef['url']['url'] = '#';
810 $menuDef['url']['addParams'] = 'onClick="jumpToUrl(\'?act=plain&bparams='.$this->bparams.'\');return false;"';
811 }
812 if (in_array('dragdrop',$this->allowedItems)) {
813 $menuDef['mail']['isActive'] = $this->act=='dragdrop';
814 $menuDef['mail']['label'] = $LANG->getLL('dragDropImage',1);
815 $menuDef['mail']['url'] = '#';
816 $menuDef['mail']['addParams'] = 'onClick="jumpToUrl(\'?act=dragdrop&bparams='.$this->bparams.'\');return false;"';
817 }
818
819 // Call hook for extra options
820 foreach ($this->hookObjects as $hookObject) {
821 $menuDef = $hookObject->modifyMenuDefinition($menuDef);
822 }
823
824 $this->content .= $this->doc->getTabMenuRaw($menuDef);
825
826 switch($this->act) {
827 case 'image':
828 $JScode = '
829 document.write(printCurrentImageOptions());
830 insertImagePropertiesInForm();';
831 $this->content.= '<br />'.$this->doc->wrapScriptTags($JScode);
832 break;
833 case 'plain':
834 case 'magic':
835 // Adding upload form, if allowed
836 $this->content .= $this->insertUploadForm($this->expandFolder);
837 // Getting flag for showing/not showing thumbnails:
838 $noThumbs = $BE_USER->getTSConfigVal('options.noThumbsInRTEimageSelect');
839 if (!$noThumbs) {
840 // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
841 $_MOD_MENU = array('displayThumbs' => '');
842 $_MCONF['name']='file_list';
843 $_MOD_SETTINGS = t3lib_BEfunc::getModuleData($_MOD_MENU, t3lib_div::_GP('SET'), $_MCONF['name']);
844 $addParams = '&act='.$this->act.'&editorNo='.$this->editorNo.'&expandFolder='.rawurlencode($this->expandFolder);
845 $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>';
846 } else {
847 $thumbNailCheck='';
848 }
849 // Create folder tree:
850 $foldertree = t3lib_div::makeInstance('tx_rtehtmlarea_image_folderTree');
851 $tree = $foldertree->getBrowsableTree();
852 list(,,$specUid) = explode('_',t3lib_div::_GP('PM'));
853 $files = $this->expandFolder($foldertree->specUIDmap[$specUid],$this->act=='plain',$noThumbs?$noThumbs:!$_MOD_SETTINGS['displayThumbs']);
854 $this->content.= '<table border="0" cellpadding="0" cellspacing="0">
855 <tr>
856 <td style="vertical-align: top;">'.$this->barheader($LANG->getLL('folderTree').':').$tree.'</td>
857 <td>&nbsp;</td>
858 <td style="vertical-align: top;">'.$files.'</td>
859 </tr>
860 </table>
861 <br />'.$thumbNailCheck;
862 // Add help message
863 $helpMessage = $this->getHelpMessage($this->act);
864 if ($helpMessage) {
865 $this->content .= $this->getMsgBox($helpMessage);
866 }
867 break;
868 case 'dragdrop':
869 $foldertree = t3lib_div::makeInstance('TBE_FolderTree');
870 $foldertree->thisScript=$this->thisScript;
871 $foldertree->ext_noTempRecyclerDirs = true;
872 $tree = $foldertree->getBrowsableTree();
873 list(,,$specUid) = explode('_',t3lib_div::_GP('PM'));
874 $files = $this->TBE_dragNDrop($foldertree->specUIDmap[$specUid], implode(',', $this->allowedFileTypes));
875 $this->content.= '<table border="0" cellpadding="0" cellspacing="0">
876 <tr>
877 <td style="vertical-align: top;">'.$this->barheader($LANG->getLL('folderTree').':').$tree.'</td>
878 <td>&nbsp;</td>
879 <td style="vertical-align: top;">'.$files.'</td>
880 </tr>
881 </table>';
882 break;
883 default:
884 // Call hook
885 foreach ($this->hookObjects as $hookObject) {
886 $this->content.= $hookObject->getTab($this->act);
887 }
888 break;
889 }
890 $this->content.= $this->doc->endPage();
891 $this->doc->JScodeArray['rtehtmlarea'] = $this->getJSCode($this->act, $this->editorNo, $this->sys_language_content);
892 $this->content = $this->doc->insertStylesAndJS($this->content);
893 return $this->content;
894 }
895
896 /**
897 * Create upload/create folder forms, if a path is given
898 *
899 * @param string $folderPath: the selected path , if any
900 *
901 * @return string the html content for the upload form
902 */
903 protected function insertUploadForm($folderPath) {
904 $content = '';
905 if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB') && !$this->readOnly && count($GLOBALS['FILEMOUNTS'])) {
906 $path = $folderPath;
907 if (!$path || !@is_dir($path)) {
908 // The closest TEMP-path is found
909 $path = $this->fileProcessor->findTempFolder().'/';
910 }
911 if ($path!='/' && @is_dir($path)) {
912 $uploadForm=$this->uploadForm($path);
913 $createFolder=$this->createFolder($path);
914 } else {
915 $createFolder='';
916 $uploadForm='';
917 }
918 $content .= $uploadForm;
919 if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB')) {
920 $content.=$createFolder;
921 }
922 }
923 return $content;
924 }
925
926 /***************************
927 *
928 * OTHER FUNCTIONS:
929 *
930 ***************************/
931 /**
932 * @param [type] $expandFolder: ...
933 * @param [type] $plainFlag: ...
934 * @return [type] ...
935 */
936 function expandFolder($expandFolder=0,$plainFlag=0,$noThumbs=0) {
937 global $LANG, $BE_USER, $BACK_PATH;
938
939 $expandFolder = $expandFolder ? $expandFolder :t3lib_div::_GP('expandFolder');
940 $out='';
941
942 if ($expandFolder && $this->checkFolder($expandFolder)) {
943 $files = t3lib_div::getFilesInDir($expandFolder,($plainFlag?'jpg,jpeg,gif,png':$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']),1,1); // $extensionList="",$prependPath=0,$order="")
944 if (is_array($files)) {
945 $out.=$this->barheader(sprintf($LANG->getLL('images').' (%s):',count($files)));
946
947 $titleLen = intval($BE_USER->uc['titleLen']);
948 $picon='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/_icon_webfolders.gif','width="18" height="16"').' alt="" />';
949 $picon.=htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($expandFolder),$titleLen));
950 $out.='<span class="nobr">'.$picon.'</span><br />';
951
952 $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
953 $imgObj->init();
954 $imgObj->mayScaleUp=0;
955 $imgObj->tempPath=PATH_site.$imgObj->tempPath;
956
957 $lines=array();
958 foreach ($files as $filepath) {
959 $fI=pathinfo($filepath);
960
961 $origFile = t3lib_div::rawUrlEncodeFP(substr($filepath,strlen(PATH_site)));
962 $iurl = $this->siteURL.$origFile;
963 $imgInfo = $imgObj->getImageDimensions($filepath);
964 // File icon:
965 $icon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
966 $pDim = $imgInfo[0].'x'.$imgInfo[1].' '.$LANG->getLL('pixels',1);
967 $size=' ('.t3lib_div::formatSize(filesize($filepath)).$LANG->getLL('bytes',1).', '.$pDim.')';
968 $icon = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/fileicons/'.$icon.'','width="18" height="16"').' title="'.htmlspecialchars($fI['basename'].$size).'" alt="" />';
969 $ATag = '<a href="#" onclick="return jumpToUrl(\'?editorNo='.$this->editorNo.'&insertImage='.rawurlencode($filepath).'\');">';
970 $ATag_e='</a>';
971 if ($plainFlag && (($imgInfo[0] > $this->plainMaxWidth) || ($imgInfo[1] > $this->plainMaxHeight))) {
972 $ATag='';
973 $ATag_e='';
974 $ATag2='';
975 $ATag2_e='';
976 } else {
977 $ATag2='<a href="#" onClick="launchView(\''.rawurlencode($filepath).'\'); return false;">';
978 $ATag2_e='</a>';
979 }
980
981 $filenameAndIcon=$ATag.$icon.htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($filepath),$titleLen)).$ATag_e;
982
983
984 $lines[]='<tr class="bgColor4"><td nowrap="nowrap">'.$filenameAndIcon.'&nbsp;</td><td nowrap="nowrap">'.$pDim.'&nbsp;</td></tr>';
985 $lines[]='<tr><td colspan="2">'.($noThumbs ? '' : $ATag2.t3lib_BEfunc::getThumbNail($this->doc->backPath.'thumbs.php',$filepath,'hspace="5" vspace="5" border="1"').$ATag2_e).
986 '</td></tr>';
987 $lines[]='<tr><td colspan="2"><img src="clear.gif" width="1" height="3"></td></tr>';
988 }
989 $out.='<table border="0" cellpadding="0" cellspacing="1">'.implode('',$lines).'</table>';
990 }
991 }
992 return $out;
993 }
994
995 /**
996 * For RTE: This displays all IMAGES (gif,png,jpg) (from extensionList) from folder. Thumbnails are shown for images.
997 * This listing is of images located in the web-accessible paths ONLY - the listing is for drag-n-drop use in the RTE
998 *
999 * @param string The folder path to expand
1000 * @param string List of fileextensions to show
1001 * @return string HTML output
1002 */
1003 function TBE_dragNDrop($expandFolder=0,$extensionList='') {
1004 global $BACK_PATH;
1005
1006 $expandFolder = $expandFolder ? $expandFolder : t3lib_div::_GP('expandFolder');
1007 $out='';
1008 if ($expandFolder && $this->checkFolder($expandFolder)) {
1009 if ($this->isWebFolder($expandFolder)) {
1010
1011 // Read files from directory:
1012 $files = t3lib_div::getFilesInDir($expandFolder,$extensionList,1,1); // $extensionList="",$prependPath=0,$order='')
1013 if (is_array($files)) {
1014 $out.=$this->barheader(sprintf($GLOBALS['LANG']->getLL('files').' (%s):',count($files)));
1015
1016 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
1017 $picon='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/_icon_webfolders.gif','width="18" height="16"').' alt="" />';
1018 $picon.=htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($expandFolder),$titleLen));
1019 $out.=$picon.'<br />';
1020
1021 // Init row-array:
1022 $lines=array();
1023
1024 // Add "drag-n-drop" message:
1025 $lines[]='
1026 <tr>
1027 <td colspan="2">'.$this->getMsgBox($GLOBALS['LANG']->getLL('findDragDrop')).'</td>
1028 </tr>';
1029
1030 // Traverse files:
1031 foreach ($files as $filepath) {
1032 $fI = pathinfo($filepath);
1033
1034 // URL of image:
1035 $iurl = $this->siteURL.t3lib_div::rawurlencodeFP(substr($filepath,strlen(PATH_site)));
1036
1037 // Show only web-images
1038 if (t3lib_div::inList('gif,jpeg,jpg,png',strtolower($fI['extension']))) {
1039 $imgInfo = @getimagesize($filepath);
1040 $pDim = $imgInfo[0].'x'.$imgInfo[1].' pixels';
1041
1042 $ficon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
1043 $size=' ('.t3lib_div::formatSize(filesize($filepath)).'bytes'.($pDim?', '.$pDim:'').')';
1044 $icon = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/fileicons/'.$ficon,'width="18" height="16"').' class="absmiddle" title="'.htmlspecialchars($fI['basename'].$size).'" alt="" />';
1045 $filenameAndIcon=$icon.htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($filepath),$titleLen));
1046
1047 if (t3lib_div::_GP('noLimit')) {
1048 $maxW=10000;
1049 $maxH=10000;
1050 } else {
1051 $maxW=380;
1052 $maxH=500;
1053 }
1054 $IW = $imgInfo[0];
1055 $IH = $imgInfo[1];
1056 if ($IW>$maxW) {
1057 $IH=ceil($IH/$IW*$maxW);
1058 $IW=$maxW;
1059 }
1060 if ($IH>$maxH) {
1061 $IW=ceil($IW/$IH*$maxH);
1062 $IH=$maxH;
1063 }
1064
1065 // Make row:
1066 $lines[]='
1067 <tr class="bgColor4">
1068 <td nowrap="nowrap">'.$filenameAndIcon.'&nbsp;</td>
1069 <td nowrap="nowrap">'.
1070 ($imgInfo[0]!=$IW ? '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('noLimit'=>'1'))).'">'.
1071 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/icon_warning2.gif','width="18" height="16"').' title="'.$GLOBALS['LANG']->getLL('clickToRedrawFullSize',1).'" alt="" />'.
1072 '</a>':'').
1073 $pDim.'&nbsp;</td>
1074 </tr>';
1075 // Remove hardcoded border="1"
1076 // Add default class for images
1077 $lines[]='
1078 <tr>
1079 <td colspan="2"><img src="'.$iurl.'" width="'.$IW.'" height="'.$IH.'" alt=""' . ($this->defaultClass?(' class="'.$this->defaultClass.'"'):''). ' style="cursor:move;" /></td>
1080 </tr>';
1081 $lines[]='
1082 <tr>
1083 <td colspan="2"><img src="clear.gif" width="1" height="3" alt="" /></td>
1084 </tr>';
1085 }
1086 }
1087
1088 // Finally, wrap all rows in a table tag:
1089 $out.='
1090
1091
1092 <!--
1093 File listing / Drag-n-drop
1094 -->
1095 <table border="0" cellpadding="0" cellspacing="1" id="typo3-dragBox">
1096 '.implode('',$lines).'
1097 </table>';
1098 }
1099 } else {
1100 // Print this warning if the folder is NOT a web folder:
1101 $out.=$this->barheader($GLOBALS['LANG']->getLL('files'));
1102 $out.=$this->getMsgBox($GLOBALS['LANG']->getLL('noWebFolder'),'icon_warning2');
1103 }
1104 }
1105 return $out;
1106 }
1107
1108 /**
1109 * Initializes the configuration variables
1110 *
1111 * @return void
1112 */
1113 public function initConfiguration() {
1114 $this->thisConfig = $this->getRTEConfig();
1115 $this->buttonConfig = $this->getButtonConfig();
1116 $this->imgPath = $this->getImgPath();
1117 $this->RTEImageStorageDir = $this->getRTEImageStorageDir();
1118 $this->defaultClass = $this->getDefaultClass();
1119 $this->setMaximumImageDimensions();
1120 }
1121
1122 /**
1123 * Get the RTE configuration from Page TSConfig
1124 *
1125 * @return array RTE configuration array
1126 */
1127 protected function getRTEConfig() {
1128 global $BE_USER;
1129
1130 $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
1131 $RTEsetup = $BE_USER->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($RTEtsConfigParts[5]));
1132 return t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$RTEtsConfigParts[0],$RTEtsConfigParts[2],$RTEtsConfigParts[4]);
1133 }
1134
1135 /**
1136 * Get the path of the image to be inserted or modified
1137 *
1138 * @return string path to the image
1139 */
1140 protected function getImgPath() {
1141 $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
1142 return $RTEtsConfigParts[6];
1143 }
1144
1145 /**
1146 * Get the configuration of the image button
1147 *
1148 * @return array the configuration array of the image button
1149 */
1150 protected function getButtonConfig() {
1151 return ((is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['image.'])) ? $this->thisConfig['buttons.']['image.'] : array());
1152 }
1153
1154 /**
1155 * Get the allowed items or tabs
1156 *
1157 * @param string $items: initial list of possible items
1158 * @return array the allowed items
1159 */
1160 public function getAllowedItems($items) {
1161 $allowedItems = explode(',', $items);
1162 $clientInfo = t3lib_div::clientInfo();
1163 if ($clientInfo['BROWSER'] !== 'opera') {
1164 $allowedItems[] = 'dragdrop';
1165 }
1166 // Call hook for extra options
1167 foreach ($this->hookObjects as $hookObject) {
1168 $allowedItems = $hookObject->addAllowedItems($allowedItems);
1169 }
1170 // Remove tab "image" if there is no current image
1171 if ($this->act !== 'image') {
1172 $allowedItems = array_diff($allowedItems, array('image'));
1173 }
1174 // Remove options according to RTE configuration
1175 if (is_array($this->buttonConfig['options.']) && $this->buttonConfig['options.']['removeItems']) {
1176 $allowedItems = array_diff($allowedItems, t3lib_div::trimExplode(',', $this->buttonConfig['options.']['removeItems'], 1));
1177 } else {
1178 $allowedItems = array_diff($allowedItems, t3lib_div::trimExplode(',', $this->thisConfig['blindImageOptions'], 1));
1179 }
1180 return $allowedItems;
1181 }
1182
1183 /**
1184 * Get the default image class
1185 *
1186 * @return string the default class, if any
1187 */
1188 protected function getDefaultClass() {
1189 $defaultClass = '';
1190 if (is_array($this->buttonConfig['properties.'])) {
1191 if (is_array($this->buttonConfig['properties.']['class.']) && trim($this->buttonConfig['properties.']['class.']['default'])) {
1192 $defaultClass = trim($this->buttonConfig['properties.']['class.']['default']);
1193 }
1194 }
1195 return $defaultClass;
1196 }
1197
1198 /**
1199 * Set variables for maximum image dimensions
1200 *
1201 * @return void
1202 */
1203 protected function setMaximumImageDimensions() {
1204 if (is_array($this->buttonConfig['options.']) && is_array($this->buttonConfig['options.']['plain.'])) {
1205 if ($this->buttonConfig['options.']['plain.']['maxWidth']) $this->plainMaxWidth = $this->buttonConfig['options.']['plain.']['maxWidth'];
1206 if ($this->buttonConfig['options.']['plain.']['maxHeight']) $this->plainMaxHeight = $this->buttonConfig['options.']['plain.']['maxHeight'];
1207 }
1208 if (!$this->plainMaxWidth) $this->plainMaxWidth = 640;
1209 if (!$this->plainMaxHeight) $this->plainMaxHeight = 680;
1210 if (is_array($this->buttonConfig['options.']) && is_array($this->buttonConfig['options.']['magic.'])) {
1211 if ($this->buttonConfig['options.']['magic.']['maxWidth']) $this->magicMaxWidth = $this->buttonConfig['options.']['magic.']['maxWidth'];
1212 if ($this->buttonConfig['options.']['magic.']['maxHeight']) $this->magicMaxHeight = $this->buttonConfig['options.']['magic.']['maxHeight'];
1213 }
1214 // 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
1215 if (!$this->magicMaxWidth) $this->magicMaxWidth = 300;
1216 if (!$this->magicMaxHeight) $this->magicMaxHeight = 1000;
1217 }
1218
1219 /**
1220 * Get the help message to be displayed on a given tab
1221 *
1222 * @param string $act: the identifier of the tab
1223 * @return string the text of the message
1224 */
1225 public function getHelpMessage($act) {
1226 global $LANG;
1227 switch ($act) {
1228 case 'plain':
1229 return sprintf($LANG->getLL('plainImage_msg'), $this->plainMaxWidth, $this->plainMaxHeight);
1230 break;
1231 case 'magic':
1232 return sprintf($LANG->getLL('magicImage_msg'));
1233 break;
1234 default:
1235 return '';
1236 }
1237 }
1238 }
1239
1240 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php'])) {
1241 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']);
1242 }
1243
1244 ?>