Added feature #10196: htmlArea RTE: Remove extension configuration variable enableCli...
[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 // init fileProcessor
169 $this->fileProcessor = t3lib_div::makeInstance('t3lib_basicFileFunctions');
170 $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
171
172 $this->allowedItems = $this->getAllowedItems('dragdrop,magic,plain,image', $this->buttonConfig);
173 reset($this->allowedItems);
174 if (!in_array($this->act,$this->allowedItems)) {
175 $this->act = current($this->allowedItems);
176 }
177
178 $this->insertImage();
179
180 // Creating backend template object:
181 $this->doc = t3lib_div::makeInstance('template');
182 $this->doc->bodyTagAdditions = $this->getBodyTagAdditions();
183 $this->doc->backPath = $BACK_PATH;
184
185 // Load the Prototype library and browse_links.js
186 $this->doc->loadJavascriptLib('contrib/prototype/prototype.js');
187 $this->doc->loadJavascriptLib('js/browse_links.js');
188
189 $this->doc->getContextMenuCode();
190 }
191
192 /**
193 * Initialize class variables
194 *
195 * @return void
196 */
197 public function initVariables() {
198
199 // Process bparams
200 $this->bparams = t3lib_div::_GP('bparams');
201 $pArr = explode('|', $this->bparams);
202 $pRteArr = explode(':', $pArr[1]);
203 $this->editorNo = $pRteArr[0];
204 $this->sys_language_content = $pRteArr[1];
205 $this->RTEtsConfigParams = $pArr[2];
206 if (!$this->editorNo) {
207 $this->editorNo = t3lib_div::_GP('editorNo');
208 $this->sys_language_content = t3lib_div::_GP('sys_language_content');
209 $this->RTEtsConfigParams = t3lib_div::_GP('RTEtsConfigParams');
210 }
211 $this->expandPage = t3lib_div::_GP('expandPage');
212 $this->expandFolder = t3lib_div::_GP('expandFolder');
213 $pArr[1] = implode(':', array($this->editorNo, $this->sys_language_content));
214 $pArr[2] = $this->RTEtsConfigParams;
215 if ($this->act == 'dragdrop' || $this->act == 'plain') {
216 $this->allowedFileTypes = explode(',','jpg,jpeg,gif,png');
217 }
218 $pArr[3] = implode(',', $this->allowedFileTypes);
219 $this->bparams = implode('|', $pArr);
220
221 // Find "mode"
222 $this->mode = t3lib_div::_GP('mode');
223 if (!$this->mode) {
224 $this->mode = 'rte';
225 }
226 // Site URL
227 $this->siteURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL'); // Current site url
228
229 // the script to link to
230 $this->thisScript = t3lib_div::getIndpEnv('SCRIPT_NAME');
231
232 // Get "act"
233 $this->act = t3lib_div::_GP('act');
234 if (!$this->act) {
235 $this->act = 'magic';
236 }
237 }
238
239 /**
240 * Initialize hook objects implementing interface t3lib_browseLinksHook
241 *
242 * @return void
243 */
244 protected function initHookObjects() {
245 global $TYPO3_CONF_VARS;
246 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']['browseLinksHook'])) {
247 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']['browseLinksHook'] as $classData) {
248 $processObject = &t3lib_div::getUserObj($classData);
249 if(!($processObject instanceof t3lib_browseLinksHook)) {
250 throw new UnexpectedValueException('$processObject must implement interface t3lib_browseLinksHook', 1195115652);
251 }
252 $parameters = array();
253 $processObject->init($this, $parameters);
254 $this->hookObjects[] = $processObject;
255 }
256 }
257 }
258
259 /**
260 * Provide the additional parameters to be included in the template body tag
261 *
262 * @return string the body tag additions
263 */
264 public function getBodyTagAdditions() {
265 return 'onLoad="initDialog();"';
266 }
267
268 /**
269 * Get the path to the folder where RTE images are stored
270 *
271 * @return string the path to the folder where RTE images are stored
272 */
273 protected function getRTEImageStorageDir() {
274 return ($this->imgPath ? $this->imgPath : $GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir']);
275 }
276
277 /**
278 * Insert the image in the editing area
279 *
280 * @return void
281 */
282 protected function insertImage() {
283 if (t3lib_div::_GP('insertImage')) {
284 $filepath = t3lib_div::_GP('insertImage');
285 $imgInfo = $this->getImageInfo($filepath);
286 switch ($this->act) {
287 case 'magic':
288 $this->insertMagicImage($filepath, $imgInfo);
289 exit;
290 break;
291 case 'plain':
292 $this->insertPlainImage($imgInfo);
293 exit;
294 break;
295 default:
296 // Call hook
297 foreach ($this->hookObjects as $hookObject) {
298 if (method_exists($hookObject, "insertElement")) {
299 $hookObject->insertElement($this->act);
300 }
301 }
302 break;
303 }
304 }
305 }
306
307 /**
308 * Get the information on the image file identified its path
309 *
310 * @param string $filepath: the path to the image file
311 *
312 * @return array a 4-elements information array about the file
313 */
314 public function getImageInfo($filepath) {
315 $this->imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
316 $this->imgObj->init();
317 $this->imgObj->mayScaleUp = 0;
318 $this->imgObj->tempPath = PATH_site.$this->imgObj->tempPath;
319 return $this->imgObj->getImageDimensions($filepath);
320 }
321
322 /**
323 * Insert a magic image
324 *
325 * @param string $filepath: the path to the image file
326 * @param array $imgInfo: a 4-elements information array about the file
327 * @param string $altText: text for the alt attribute of the image
328 * @param string $titleText: text for the title attribute of the image
329 * @param string $additionalParams: text representing more HTML attributes to be added on the img tag
330 * @return void
331 */
332 public function insertMagicImage($filepath, $imgInfo, $altText='', $titleText='', $additionalParams='') {
333 if (is_array($imgInfo) && count($imgInfo)==4 && $this->RTEImageStorageDir) {
334 $fI = pathinfo($imgInfo[3]);
335 $fileFunc = t3lib_div::makeInstance('t3lib_basicFileFunctions');
336 $basename = $fileFunc->cleanFileName('RTEmagicP_'.$fI['basename']);
337 $destPath =PATH_site.$this->RTEImageStorageDir;
338 if (@is_dir($destPath)) {
339 $destName = $fileFunc->getUniqueName($basename,$destPath);
340 @copy($imgInfo[3],$destName);
341 t3lib_div::fixPermissions($destName);
342 $cWidth = t3lib_div::intInRange(t3lib_div::_GP('cWidth'), 0, $this->magicMaxWidth);
343 $cHeight = t3lib_div::intInRange(t3lib_div::_GP('cHeight'), 0, $this->magicMaxHeight);
344 if (!$cWidth) $cWidth = $this->magicMaxWidth;
345 if (!$cHeight) $cHeight = $this->magicMaxHeight;
346
347 $imgI = $this->imgObj->imageMagickConvert($filepath,'WEB',$cWidth.'m',$cHeight.'m'); // ($imagefile,$newExt,$w,$h,$params,$frame,$options,$mustCreate=0)
348 if ($imgI[3]) {
349 $fI=pathinfo($imgI[3]);
350 $mainBase='RTEmagicC_'.substr(basename($destName),10).'.'.$fI['extension'];
351 $destName = $fileFunc->getUniqueName($mainBase,$destPath);
352 @copy($imgI[3],$destName);
353 t3lib_div::fixPermissions($destName);
354 $destName = dirname($destName).'/'.rawurlencode(basename($destName));
355 $iurl = $this->siteURL.substr($destName,strlen(PATH_site));
356 $this->imageInsertJS($iurl, $imgI[0], $imgI[1], $altText, $titleText, $additionalParams);
357 }
358 }
359 }
360 }
361
362 /**
363 * Insert a plain image
364 *
365 * @param array $imgInfo: a 4-elements information array about the file
366 * @param string $altText: text for the alt attribute of the image
367 * @param string $titleText: text for the title attribute of the image
368 * @param string $additionalParams: text representing more HTML attributes to be added on the img tag
369 * @return void
370 */
371 public function insertPlainImage($imgInfo, $altText='', $titleText='', $additionalParams='') {
372 if (is_array($imgInfo) && count($imgInfo)==4) {
373 $iurl = $this->siteURL.substr($imgInfo[3],strlen(PATH_site));
374 $this->imageInsertJS($iurl, $imgInfo[0], $imgInfo[1], $altText, $titleText, $additionalParams);
375 }
376 }
377
378 /**
379 * Echo the HTML page and JS that will insert the image
380 *
381 * @param string $url: the url of the image
382 * @param integer $width: the width of the image
383 * @param integer $height: the height of the image
384 * @param string $altText: text for the alt attribute of the image
385 * @param string $titleText: text for the title attribute of the image
386 * @param string $additionalParams: text representing more html attributes to be added on the img tag
387 * @return void
388 */
389 protected function imageInsertJS($url, $width, $height, $altText='', $titleText='', $additionalParams='') {
390 echo'
391 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
392 <html>
393 <head>
394 <title>Untitled</title>
395 </head>
396 <script type="text/javascript">
397 /*<![CDATA[*/
398 var dialog = window.opener.HTMLArea.Dialog.TYPO3Image;
399 var plugin = dialog.plugin;
400 function insertImage(file,width,height,alt,title,additionalParams) {
401 plugin.insertImage(\'<img src="\'+file+\'" width="\'+parseInt(width)+\'" height="\'+parseInt(height)+\'"\'' . ($this->defaultClass?('+\' class="'.$this->defaultClass.'"\''):'') .
402 '+(alt?\' alt="\'+alt+\'"\':\'\')+(title?\' title="\'+title+\'"\':\'\')+(additionalParams?\' \'+additionalParams:\'\')+\' />\');
403 }
404 /*]]>*/
405 </script>
406 <body>
407 <script type="text/javascript">
408 /*<![CDATA[*/
409 insertImage('.t3lib_div::quoteJSvalue($url,1).','.$width.','.$height.','.t3lib_div::quoteJSvalue($altText,1).','.t3lib_div::quoteJSvalue($titleText,1).','.t3lib_div::quoteJSvalue($additionalParams, 1).');
410 /*]]>*/
411 </script>
412 </body>
413 </html>';
414 }
415
416 /**
417 * Generate JS code to be used on the image insert/modify dialogue
418 *
419 * @param string $act: the action to be performed
420 * @param string $editorNo: the number of the RTE instance on the page
421 * @param string $sys_language_content: the language of the content element
422 *
423 * @return string the generated JS code
424 */
425 function getJSCode($act, $editorNo, $sys_language_content) {
426 global $LANG, $TYPO3_CONF_VARS;
427
428 $removedProperties = array();
429 if (is_array($this->buttonConfig['properties.'])) {
430 if ($this->buttonConfig['properties.']['removeItems']) {
431 $removedProperties = t3lib_div::trimExplode(',',$this->buttonConfig['properties.']['removeItems'],1);
432 }
433 }
434
435 if ($this->thisConfig['classesImage']) {
436 $classesImageArray = t3lib_div::trimExplode(',', $this->thisConfig['classesImage'], 1);
437 $classesImageJSOptions = '<option value=""></option>';
438 foreach ($classesImageArray as $class) {
439 $classesImageJSOptions .= '<option value="' .$class . '">' . $class . '</option>';
440 }
441 }
442
443 $lockPlainWidth = 'false';
444 $lockPlainHeight = 'false';
445 if (is_array($this->thisConfig['proc.']) && $this->thisConfig['proc.']['plainImageMode']) {
446 $plainImageMode = $this->thisConfig['proc.']['plainImageMode'];
447 $lockPlainWidth = ($plainImageMode == 'lockDimensions')?'true':'false';
448 $lockPlainHeight = ($lockPlainWidth || $plainImageMode == 'lockRatio' || ($plainImageMode == 'lockRatioWhenSmaller'))?'true':'false';
449 }
450
451 $JScode='
452 var dialog = window.opener.HTMLArea.Dialog.TYPO3Image;
453 var plugin = dialog.plugin;
454 var HTMLArea = window.opener.HTMLArea;
455
456 function initDialog() {
457 window.dialog = window.opener.HTMLArea.Dialog.TYPO3Image;
458 window.plugin = dialog.plugin;
459 window.HTMLArea = window.opener.HTMLArea;
460 dialog.captureEvents("skipUnload");
461 }
462
463 function jumpToUrl(URL,anchor) {
464 var add_act = URL.indexOf("act=")==-1 ? "&act='.$act.'" : "";
465 var add_editorNo = URL.indexOf("editorNo=")==-1 ? "&editorNo='.$editorNo.'" : "";
466 var add_sys_language_content = URL.indexOf("sys_language_content=")==-1 ? "&sys_language_content='.$sys_language_content.'" : "";
467 var RTEtsConfigParams = "&RTEtsConfigParams='.rawurlencode($this->RTEtsConfigParams).'";
468
469 var cur_width = selectedImageRef ? "&cWidth="+selectedImageRef.style.width : "";
470 var cur_height = selectedImageRef ? "&cHeight="+selectedImageRef.style.height : "";
471
472 var theLocation = URL+add_act+add_editorNo+add_sys_language_content+RTEtsConfigParams+cur_width+cur_height+(anchor?anchor:"");
473 window.location.href = theLocation;
474 return false;
475 }
476 function insertImage(file,width,height) {
477 plugin.insertImage(\'<img src="\'+file+\'"' . ($this->defaultClass?(' class="'.$this->defaultClass.'"'):'') . ' width="\'+parseInt(width)+\'" height="\'+parseInt(height)+\'" />\');
478 }
479 function launchView(url) {
480 var thePreviewWindow="";
481 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");
482 if (thePreviewWindow && thePreviewWindow.focus) {
483 thePreviewWindow.focus();
484 }
485 }
486 function getCurrentImageRef() {
487 if (plugin.image) {
488 return plugin.image;
489 } else {
490 return null;
491 }
492 }
493 function printCurrentImageOptions() {
494 var classesImage = ' . ($this->thisConfig['classesImage']?'true':'false') . ';
495 if (classesImage) var styleSelector=\'<select id="iClass" name="iClass" style="width:140px;">' . $classesImageJSOptions . '</select>\';
496 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>\';
497 var bgColor=\' class="bgColor4"\';
498 var sz="";
499 sz+=\'<table border=0 cellpadding=1 cellspacing=1><form action="" name="imageData">\';
500 '.(in_array('class', $removedProperties)?'':'
501 if(classesImage) {
502 sz+=\'<tr><td\'+bgColor+\'><label for="iClass">'.$LANG->getLL('class').': </label></td><td>\'+styleSelector+\'</td></tr>\';
503 }')
504 .(in_array('width', $removedProperties)?'':'
505 if (!(selectedImageRef && selectedImageRef.src.indexOf("RTEmagic") == -1 && '. $lockPlainWidth .')) {
506 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>\';
507 }')
508 .(in_array('height', $removedProperties)?'':'
509 if (!(selectedImageRef && selectedImageRef.src.indexOf("RTEmagic") == -1 && '. $lockPlainHeight .')) {
510 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>\';
511 }')
512 .(in_array('border', $removedProperties)?'':'
513 sz+=\'<tr><td\'+bgColor+\'><label for="iBorder">'.$LANG->getLL('border').': </label></td><td><input type="checkbox" id="iBorder" name="iBorder" value="1" /></td></tr>\';')
514 .(in_array('float', $removedProperties)?'':'
515 sz+=\'<tr><td\'+bgColor+\'><label for="iFloat">'.$LANG->getLL('float').': </label></td><td>\'+floatSelector+\'</td></tr>\';')
516 .(in_array('paddingTop', $removedProperties)?'':'
517 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>\';')
518 .(in_array('paddingRight', $removedProperties)?'':'
519 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>\';')
520 .(in_array('paddingBottom', $removedProperties)?'':'
521 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>\';')
522 .(in_array('paddingLeft', $removedProperties)?'':'
523 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>\';')
524 .(in_array('title', $removedProperties)?'':'
525 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>\';')
526 .(in_array('alt', $removedProperties)?'':'
527 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>\';')
528 .(in_array('clickenlarge', $removedProperties)?'':'
529 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>\';').'
530 sz+=\'<tr><td><input type="submit" value="'.$LANG->getLL('update').'" onClick="return setImageProperties();"></td></tr>\';
531 sz+=\'</form></table>\';
532 return sz;
533 }
534 function setImageProperties() {
535 var classesImage = ' . ($this->thisConfig['classesImage']?'true':'false') . ';
536 if (selectedImageRef) {
537 if (document.imageData.iWidth) {
538 if (document.imageData.iWidth.value && parseInt(document.imageData.iWidth.value)) {
539 selectedImageRef.style.width = "";
540 selectedImageRef.width = parseInt(document.imageData.iWidth.value);
541 }
542 }
543 if (document.imageData.iHeight) {
544 if (document.imageData.iHeight.value && parseInt(document.imageData.iHeight.value)) {
545 selectedImageRef.style.height = "";
546 selectedImageRef.height = parseInt(document.imageData.iHeight.value);
547 }
548 }
549 if (document.imageData.iPaddingTop) {
550 if (document.imageData.iPaddingTop.value != "" && !isNaN(parseInt(document.imageData.iPaddingTop.value))) {
551 selectedImageRef.style.paddingTop = parseInt(document.imageData.iPaddingTop.value) + "px";
552 } else {
553 selectedImageRef.style.paddingTop = "";
554 }
555 }
556 if (document.imageData.iPaddingRight) {
557 if (document.imageData.iPaddingRight.value != "" && !isNaN(parseInt(document.imageData.iPaddingRight.value))) {
558 selectedImageRef.style.paddingRight = parseInt(document.imageData.iPaddingRight.value) + "px";
559 } else {
560 selectedImageRef.style.paddingRight = "";
561 }
562 }
563 if (document.imageData.iPaddingBottom) {
564 if (document.imageData.iPaddingBottom.value != "" && !isNaN(parseInt(document.imageData.iPaddingBottom.value))) {
565 selectedImageRef.style.paddingBottom = parseInt(document.imageData.iPaddingBottom.value) + "px";
566 } else {
567 selectedImageRef.style.paddingBottom = "";
568 }
569 }
570 if (document.imageData.iPaddingLeft) {
571 if (document.imageData.iPaddingLeft.value != "" && !isNaN(parseInt(document.imageData.iPaddingLeft.value))) {
572 selectedImageRef.style.paddingLeft = parseInt(document.imageData.iPaddingLeft.value) + "px";
573 } else {
574 selectedImageRef.style.paddingLeft = "";
575 }
576 }
577 if (document.imageData.iTitle) {
578 selectedImageRef.title=document.imageData.iTitle.value;
579 }
580 if (document.imageData.iAlt) {
581 selectedImageRef.alt=document.imageData.iAlt.value;
582 }
583
584 if (document.imageData.iBorder) {
585 selectedImageRef.style.borderStyle = "";
586 selectedImageRef.style.borderWidth = "";
587 selectedImageRef.style.border = ""; // this statement ignored by Mozilla 1.3.1
588 selectedImageRef.style.borderTopStyle = "";
589 selectedImageRef.style.borderRightStyle = "";
590 selectedImageRef.style.borderBottomStyle = "";
591 selectedImageRef.style.borderLeftStyle = "";
592 selectedImageRef.style.borderTopWidth = "";
593 selectedImageRef.style.borderRightWidth = "";
594 selectedImageRef.style.borderBottomWidth = "";
595 selectedImageRef.style.borderLeftWidth = "";
596 if(document.imageData.iBorder.checked) {
597 selectedImageRef.style.borderStyle = "solid";
598 selectedImageRef.style.borderWidth = "thin";
599 }
600 selectedImageRef.removeAttribute("border");
601 }
602
603 if (document.imageData.iFloat) {
604 var iFloat = document.imageData.iFloat.options[document.imageData.iFloat.selectedIndex].value;
605 if (iFloat || selectedImageRef.style.cssFloat || selectedImageRef.style.styleFloat) {
606 if (document.all) {
607 selectedImageRef.style.styleFloat = (iFloat != "none") ? iFloat : "";
608 } else {
609 selectedImageRef.style.cssFloat = (iFloat != "none") ? iFloat : "";
610 }
611 }
612 }
613
614 if (classesImage && document.imageData.iClass) {
615 var iClass = document.imageData.iClass.options[document.imageData.iClass.selectedIndex].value;
616 if (iClass || (selectedImageRef.attributes["class"] && selectedImageRef.attributes["class"].value)) {
617 selectedImageRef.className = iClass;
618 } else {
619 selectedImageRef.className = "";
620 }
621 }
622
623 if (document.imageData.iClickEnlarge) {
624 if (document.imageData.iClickEnlarge.checked) {
625 selectedImageRef.setAttribute("clickenlarge","1");
626 } else {
627 selectedImageRef.removeAttribute("clickenlarge");
628 }
629 }
630 dialog.close();
631 }
632 return false;
633 }
634 function insertImagePropertiesInForm() {
635 var classesImage = ' . ($this->thisConfig['classesImage']?'true':'false') . ';
636 if (selectedImageRef) {
637 var styleWidth, styleHeight, padding;
638 if (document.imageData.iWidth) {
639 styleWidth = selectedImageRef.style.width ? selectedImageRef.style.width : selectedImageRef.width;
640 styleWidth = parseInt(styleWidth);
641 if (!(isNaN(styleWidth) || styleWidth == 0)) {
642 document.imageData.iWidth.value = styleWidth;
643 }
644 }
645 if (document.imageData.iHeight) {
646 styleHeight = selectedImageRef.style.height ? selectedImageRef.style.height : selectedImageRef.height;
647 styleHeight = parseInt(styleHeight);
648 if (!(isNaN(styleHeight) || styleHeight == 0)) {
649 document.imageData.iHeight.value = styleHeight;
650 }
651 }
652 if (document.imageData.iPaddingTop) {
653 var padding = selectedImageRef.style.paddingTop ? selectedImageRef.style.paddingTop : selectedImageRef.vspace;
654 var padding = parseInt(padding);
655 if (isNaN(padding) || padding <= 0) { padding = ""; }
656 document.imageData.iPaddingTop.value = padding;
657 }
658 if (document.imageData.iPaddingRight) {
659 padding = selectedImageRef.style.paddingRight ? selectedImageRef.style.paddingRight : selectedImageRef.hspace;
660 var padding = parseInt(padding);
661 if (isNaN(padding) || padding <= 0) { padding = ""; }
662 document.imageData.iPaddingRight.value = padding;
663 }
664 if (document.imageData.iPaddingBottom) {
665 var padding = selectedImageRef.style.paddingBottom ? selectedImageRef.style.paddingBottom : selectedImageRef.vspace;
666 var padding = parseInt(padding);
667 if (isNaN(padding) || padding <= 0) { padding = ""; }
668 document.imageData.iPaddingBottom.value = padding;
669 }
670 if (document.imageData.iPaddingLeft) {
671 var padding = selectedImageRef.style.paddingLeft ? selectedImageRef.style.paddingLeft : selectedImageRef.hspace;
672 var padding = parseInt(padding);
673 if (isNaN(padding) || padding <= 0) { padding = ""; }
674 document.imageData.iPaddingLeft.value = padding;
675 }
676 if (document.imageData.iTitle) {
677 document.imageData.iTitle.value = selectedImageRef.title;
678 }
679 if (document.imageData.iAlt) {
680 document.imageData.iAlt.value = selectedImageRef.alt;
681 }
682 if (document.imageData.iBorder) {
683 if((selectedImageRef.style.borderStyle && selectedImageRef.style.borderStyle != "none" && selectedImageRef.style.borderStyle != "none none none none") || selectedImageRef.border) {
684 document.imageData.iBorder.checked = 1;
685 }
686 }
687 if (document.imageData.iFloat) {
688 var fObj=document.imageData.iFloat;
689 var value = (selectedImageRef.style.cssFloat ? selectedImageRef.style.cssFloat : selectedImageRef.style.styleFloat);
690 var l=fObj.length;
691 for (var a=0;a<l;a++) {
692 if (fObj.options[a].value == value) {
693 fObj.selectedIndex = a;
694 }
695 }
696 }
697
698 if (classesImage && document.imageData.iClass) {
699 var fObj=document.imageData.iClass;
700 var value=selectedImageRef.className;
701 var l=fObj.length;
702 for (var a=0;a < l; a++) {
703 if (fObj.options[a].value == value) {
704 fObj.selectedIndex = a;
705 }
706 }
707 }
708 if (document.imageData.iClickEnlarge) {
709 if (selectedImageRef.getAttribute("clickenlarge") == "1") {
710 document.imageData.iClickEnlarge.checked = 1;
711 } else {
712 document.imageData.iClickEnlarge.checked = 0;
713 }
714 }
715 return false;
716 }
717 }
718
719 var selectedImageRef = getCurrentImageRef();'; // Setting this to a reference to the image object.
720 return $JScode;
721 }
722
723 /**
724 * Session data for this class can be set from outside with this method.
725 * Call after init()
726 *
727 * @param array Session data array
728 * @return array Session data and boolean which indicates that data needs to be stored in session because it's changed
729 */
730 function processSessionData($data) {
731 $store = false;
732
733 if ($this->act != 'image') {
734 if (isset($this->act)) {
735 $data['act'] = $this->act;
736 $store = true;
737 } else {
738 $this->act = $data['act'];
739 }
740 }
741
742 if (isset($this->expandFolder)) {
743 $data['expandFolder'] = $this->expandFolder;
744 $store = true;
745 } else {
746 $this->expandFolder = $data['expandFolder'];
747 }
748
749 return array($data, $store);
750 }
751
752 /**
753 * [Describe function...]
754 *
755 * @return [type] ...
756 */
757 function main_rte() {
758 global $LANG, $TYPO3_CONF_VARS, $FILEMOUNTS, $BE_USER;
759
760 // Starting content:
761 $this->content = $this->doc->startPage($LANG->getLL('Insert Image',1));
762
763 // Making menu in top:
764 $menuDef = array();
765 if (in_array('image',$this->allowedItems) && ($this->act=='image' || t3lib_div::_GP('cWidth'))) {
766 $menuDef['page']['isActive'] = $this->act=='image';
767 $menuDef['page']['label'] = $LANG->getLL('currentImage',1);
768 $menuDef['page']['url'] = '#';
769 $menuDef['page']['addParams'] = 'onClick="jumpToUrl(\'?act=image&bparams='.$this->bparams.'\');return false;"';
770 }
771 if (in_array('magic',$this->allowedItems)){
772 $menuDef['file']['isActive'] = $this->act=='magic';
773 $menuDef['file']['label'] = $LANG->getLL('magicImage',1);
774 $menuDef['file']['url'] = '#';
775 $menuDef['file']['addParams'] = 'onClick="jumpToUrl(\'?act=magic&bparams='.$this->bparams.'\');return false;"';
776 }
777 if (in_array('plain',$this->allowedItems)) {
778 $menuDef['url']['isActive'] = $this->act=='plain';
779 $menuDef['url']['label'] = $LANG->getLL('plainImage',1);
780 $menuDef['url']['url'] = '#';
781 $menuDef['url']['addParams'] = 'onClick="jumpToUrl(\'?act=plain&bparams='.$this->bparams.'\');return false;"';
782 }
783 if (in_array('dragdrop',$this->allowedItems)) {
784 $menuDef['mail']['isActive'] = $this->act=='dragdrop';
785 $menuDef['mail']['label'] = $LANG->getLL('dragDropImage',1);
786 $menuDef['mail']['url'] = '#';
787 $menuDef['mail']['addParams'] = 'onClick="jumpToUrl(\'?act=dragdrop&bparams='.$this->bparams.'\');return false;"';
788 }
789
790 // Call hook for extra options
791 foreach ($this->hookObjects as $hookObject) {
792 $menuDef = $hookObject->modifyMenuDefinition($menuDef);
793 }
794
795 $this->content .= $this->doc->getTabMenuRaw($menuDef);
796
797 switch($this->act) {
798 case 'image':
799 $JScode = '
800 document.write(printCurrentImageOptions());
801 insertImagePropertiesInForm();';
802 $this->content.= '<br />'.$this->doc->wrapScriptTags($JScode);
803 break;
804 case 'plain':
805 case 'magic':
806 // Adding upload form, if allowed
807 $this->content .= $this->insertUploadForm($this->expandFolder);
808 // Getting flag for showing/not showing thumbnails:
809 $noThumbs = $BE_USER->getTSConfigVal('options.noThumbsInRTEimageSelect');
810 if (!$noThumbs) {
811 // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
812 $_MOD_MENU = array('displayThumbs' => '');
813 $_MCONF['name']='file_list';
814 $_MOD_SETTINGS = t3lib_BEfunc::getModuleData($_MOD_MENU, t3lib_div::_GP('SET'), $_MCONF['name']);
815 $addParams = '&act='.$this->act.'&editorNo='.$this->editorNo.'&expandFolder='.rawurlencode($this->expandFolder);
816 $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>';
817 } else {
818 $thumbNailCheck='';
819 }
820 // Create folder tree:
821 $foldertree = t3lib_div::makeInstance('tx_rtehtmlarea_image_folderTree');
822 $tree = $foldertree->getBrowsableTree();
823 list(,,$specUid) = explode('_',t3lib_div::_GP('PM'));
824 $files = $this->expandFolder($foldertree->specUIDmap[$specUid],$this->act=='plain',$noThumbs?$noThumbs:!$_MOD_SETTINGS['displayThumbs']);
825 $this->content.= '<table border=0 cellpadding=0 cellspacing=0>
826 <tr>
827 <td valign=top>'.$this->barheader($LANG->getLL('folderTree').':').$tree.'</td>
828 <td>&nbsp;</td>
829 <td valign=top>'.$files.'</td>
830 </tr>
831 </table>
832 <br />'.$thumbNailCheck;
833 // Add help message
834 $helpMessage = $this->getHelpMessage($this->act);
835 if ($helpMessage) {
836 $this->content .= $this->getMsgBox($helpMessage);
837 }
838 break;
839 case 'dragdrop':
840 $foldertree = t3lib_div::makeInstance('TBE_FolderTree');
841 $foldertree->thisScript=$this->thisScript;
842 $foldertree->ext_noTempRecyclerDirs = true;
843 $tree = $foldertree->getBrowsableTree();
844 list(,,$specUid) = explode('_',t3lib_div::_GP('PM'));
845 $files = $this->TBE_dragNDrop($foldertree->specUIDmap[$specUid], implode(',', $this->allowedFileTypes));
846 $this->content.= '<table border=0 cellpadding=0 cellspacing=0>
847 <tr>
848 <td valign=top>'.$this->barheader($LANG->getLL('folderTree').':').$tree.'</td>
849 <td>&nbsp;</td>
850 <td valign=top>'.$files.'</td>
851 </tr>
852 </table>';
853 break;
854 default:
855 // Call hook
856 foreach ($this->hookObjects as $hookObject) {
857 $this->content.= $hookObject->getTab($this->act);
858 }
859 break;
860 }
861 $this->content.= $this->doc->endPage();
862 $this->doc->JScodeArray['rtehtmlarea'] = $this->getJSCode($this->act, $this->editorNo, $this->sys_language_content);
863 $this->content = $this->doc->insertStylesAndJS($this->content);
864 return $this->content;
865 }
866
867 /**
868 * Create upload/create folder forms, if a path is given
869 *
870 * @param string $folderPath: the selected path , if any
871 *
872 * @return string the html content for the upload form
873 */
874 protected function insertUploadForm($folderPath) {
875 $content = '';
876 if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB') && !$this->readOnly && count($GLOBALS['FILEMOUNTS'])) {
877 $path = $folderPath;
878 if (!$path || !@is_dir($path)) {
879 // The closest TEMP-path is found
880 $path = $this->fileProcessor->findTempFolder().'/';
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 ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['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 // Traverse 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->thisConfig['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 (is_array($this->buttonConfig['options.']) && is_array($this->buttonConfig['options.']['plain.'])) {
1174 if ($this->buttonConfig['options.']['plain.']['maxWidth']) $this->plainMaxWidth = $this->buttonConfig['options.']['plain.']['maxWidth'];
1175 if ($this->buttonConfig['options.']['plain.']['maxHeight']) $this->plainMaxHeight = $this->buttonConfig['options.']['plain.']['maxHeight'];
1176 }
1177 if (!$this->plainMaxWidth) $this->plainMaxWidth = 640;
1178 if (!$this->plainMaxHeight) $this->plainMaxHeight = 680;
1179 if (is_array($this->buttonConfig['options.']) && is_array($this->buttonConfig['options.']['magic.'])) {
1180 if ($this->buttonConfig['options.']['magic.']['maxWidth']) $this->magicMaxWidth = $this->buttonConfig['options.']['magic.']['maxWidth'];
1181 if ($this->buttonConfig['options.']['magic.']['maxHeight']) $this->magicMaxHeight = $this->buttonConfig['options.']['magic.']['maxHeight'];
1182 }
1183 // 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
1184 if (!$this->magicMaxWidth) $this->magicMaxWidth = 300;
1185 if (!$this->magicMaxHeight) $this->magicMaxHeight = 1000;
1186 }
1187
1188 /**
1189 * Get the help message to be displayed on a given tab
1190 *
1191 * @param string $act: the identifier of the tab
1192 * @return string the text of the message
1193 */
1194 public function getHelpMessage($act) {
1195 global $LANG;
1196 switch ($act) {
1197 case 'plain':
1198 return sprintf($LANG->getLL('plainImage_msg'), $this->plainMaxWidth, $this->plainMaxHeight);
1199 break;
1200 case 'magic':
1201 return sprintf($LANG->getLL('magicImage_msg'));
1202 break;
1203 default:
1204 return '';
1205 }
1206 }
1207 }
1208
1209 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']) {
1210 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']);
1211 }
1212
1213 ?>