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