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