752cdaf456f58e22ce4b60bd820ef6c75a02feb4
[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', $this->buttonConfig);
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
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
449 $lockPlainWidth = 'false';
450 $lockPlainHeight = 'false';
451 if (is_array($this->thisConfig['proc.']) && $this->thisConfig['proc.']['plainImageMode']) {
452 $plainImageMode = $this->thisConfig['proc.']['plainImageMode'];
453 $lockPlainWidth = ($plainImageMode == 'lockDimensions')?'true':'false';
454 $lockPlainHeight = ($lockPlainWidth || $plainImageMode == 'lockRatio' || ($plainImageMode == 'lockRatioWhenSmaller'))?'true':'false';
455 }
456
457 $JScode='
458 var plugin = window.parent.RTEarea["' . $editorNo . '"].editor.getPlugin("TYPO3Image");
459 var HTMLArea = window.parent.HTMLArea;
460 function initEventListeners() {
461 if (Ext.isWebKit) {
462 Ext.EventManager.addListener(window.document.body, "dragend", plugin.onDrop, plugin, { single: true });
463 }
464 }
465 function jumpToUrl(URL,anchor) {
466 var add_act = URL.indexOf("act=")==-1 ? "&act='.$act.'" : "";
467 var add_editorNo = URL.indexOf("editorNo=")==-1 ? "&editorNo='.$editorNo.'" : "";
468 var add_sys_language_content = URL.indexOf("sys_language_content=")==-1 ? "&sys_language_content='.$sys_language_content.'" : "";
469 var RTEtsConfigParams = "&RTEtsConfigParams='.rawurlencode($this->RTEtsConfigParams).'";
470
471 var cur_width = selectedImageRef ? "&cWidth="+selectedImageRef.style.width : "";
472 var cur_height = selectedImageRef ? "&cHeight="+selectedImageRef.style.height : "";
473
474 var theLocation = URL+add_act+add_editorNo+add_sys_language_content+RTEtsConfigParams+cur_width+cur_height+(anchor?anchor:"");
475 window.location.href = theLocation;
476 return false;
477 }
478 function insertImage(file,width,height) {
479 plugin.insertImage(\'<img src="\'+file+\'"' . ($this->defaultClass?(' class="'.$this->defaultClass.'"'):'') . ' width="\'+parseInt(width)+\'" height="\'+parseInt(height)+\'" />\');
480 }
481 function launchView(url) {
482 var thePreviewWindow="";
483 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");
484 if (thePreviewWindow && thePreviewWindow.focus) {
485 thePreviewWindow.focus();
486 }
487 }
488 function getCurrentImageRef() {
489 if (plugin.image) {
490 return plugin.image;
491 } else {
492 return null;
493 }
494 }
495 function printCurrentImageOptions() {
496 var classesImage = ' . ($this->thisConfig['classesImage']?'true':'false') . ';
497 if (classesImage) var styleSelector=\'<select id="iClass" name="iClass" style="width:140px;">' . $classesImageJSOptions . '</select>\';
498 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>\';
499 if (plugin.getButton("Language")) {
500 var languageSelector = \'<select id="iLang" name="iLang">\';
501 plugin.getButton("Language").getStore().each(function (record) {
502 languageSelector +=\'<option value="\' + record.get("value") + \'">\' + record.get("text") + \'</option>\';
503 });
504 languageSelector += \'</select>\';
505 }
506 var bgColor=\' class="bgColor4"\';
507 var sz="";
508 sz+=\'<table border="0" cellpadding="1" cellspacing="1"><form action="" name="imageData">\';
509 '.(in_array('class', $removedProperties)?'':'
510 if(classesImage) {
511 sz+=\'<tr><td\'+bgColor+\'><label for="iClass">'.$LANG->getLL('class').': </label></td><td>\'+styleSelector+\'</td></tr>\';
512 }')
513 .(in_array('width', $removedProperties)?'':'
514 if (!(selectedImageRef && selectedImageRef.src.indexOf("RTEmagic") == -1 && '. $lockPlainWidth .')) {
515 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>\';
516 }')
517 .(in_array('height', $removedProperties)?'':'
518 if (!(selectedImageRef && selectedImageRef.src.indexOf("RTEmagic") == -1 && '. $lockPlainHeight .')) {
519 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>\';
520 }')
521 .(in_array('border', $removedProperties)?'':'
522 sz+=\'<tr><td\'+bgColor+\'><label for="iBorder">'.$LANG->getLL('border').': </label></td><td><input type="checkbox" id="iBorder" name="iBorder" value="1" /></td></tr>\';')
523 .(in_array('float', $removedProperties)?'':'
524 sz+=\'<tr><td\'+bgColor+\'><label for="iFloat">'.$LANG->getLL('float').': </label></td><td>\'+floatSelector+\'</td></tr>\';')
525 .(in_array('paddingTop', $removedProperties)?'':'
526 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>\';')
527 .(in_array('paddingRight', $removedProperties)?'':'
528 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>\';')
529 .(in_array('paddingBottom', $removedProperties)?'':'
530 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>\';')
531 .(in_array('paddingLeft', $removedProperties)?'':'
532 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>\';')
533 .(in_array('title', $removedProperties)?'':'
534 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>\';')
535 .(in_array('alt', $removedProperties)?'':'
536 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>\';')
537 .(in_array('lang', $removedProperties)?'':'
538 if (plugin.getButton("Language")) {
539 sz+=\'<tr><td\'+bgColor+\'><label for="iLang">\' + plugin.editor.getPlugin("Language").localize(\'Language-Tooltip\') + \': </label></td><td>\' + languageSelector + \'</td></tr>\';
540 }')
541 .(in_array('clickenlarge', $removedProperties)?'':'
542 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>\';').'
543 sz+=\'<tr><td><input type="submit" value="'.$LANG->getLL('update').'" onClick="return setImageProperties();"></td></tr>\';
544 sz+=\'</form></table>\';
545 return sz;
546 }
547 function setImageProperties() {
548 var classesImage = ' . ($this->thisConfig['classesImage']?'true':'false') . ';
549 if (selectedImageRef) {
550 if (document.imageData.iWidth) {
551 if (document.imageData.iWidth.value && parseInt(document.imageData.iWidth.value)) {
552 selectedImageRef.style.width = "";
553 selectedImageRef.width = parseInt(document.imageData.iWidth.value);
554 }
555 }
556 if (document.imageData.iHeight) {
557 if (document.imageData.iHeight.value && parseInt(document.imageData.iHeight.value)) {
558 selectedImageRef.style.height = "";
559 selectedImageRef.height = parseInt(document.imageData.iHeight.value);
560 }
561 }
562 if (document.imageData.iPaddingTop) {
563 if (document.imageData.iPaddingTop.value != "" && !isNaN(parseInt(document.imageData.iPaddingTop.value))) {
564 selectedImageRef.style.paddingTop = parseInt(document.imageData.iPaddingTop.value) + "px";
565 } else {
566 selectedImageRef.style.paddingTop = "";
567 }
568 }
569 if (document.imageData.iPaddingRight) {
570 if (document.imageData.iPaddingRight.value != "" && !isNaN(parseInt(document.imageData.iPaddingRight.value))) {
571 selectedImageRef.style.paddingRight = parseInt(document.imageData.iPaddingRight.value) + "px";
572 } else {
573 selectedImageRef.style.paddingRight = "";
574 }
575 }
576 if (document.imageData.iPaddingBottom) {
577 if (document.imageData.iPaddingBottom.value != "" && !isNaN(parseInt(document.imageData.iPaddingBottom.value))) {
578 selectedImageRef.style.paddingBottom = parseInt(document.imageData.iPaddingBottom.value) + "px";
579 } else {
580 selectedImageRef.style.paddingBottom = "";
581 }
582 }
583 if (document.imageData.iPaddingLeft) {
584 if (document.imageData.iPaddingLeft.value != "" && !isNaN(parseInt(document.imageData.iPaddingLeft.value))) {
585 selectedImageRef.style.paddingLeft = parseInt(document.imageData.iPaddingLeft.value) + "px";
586 } else {
587 selectedImageRef.style.paddingLeft = "";
588 }
589 }
590 if (document.imageData.iTitle) {
591 selectedImageRef.title=document.imageData.iTitle.value;
592 }
593 if (document.imageData.iAlt) {
594 selectedImageRef.alt=document.imageData.iAlt.value;
595 }
596 if (document.imageData.iBorder) {
597 selectedImageRef.style.borderStyle = "";
598 selectedImageRef.style.borderWidth = "";
599 selectedImageRef.style.border = ""; // this statement ignored by Mozilla 1.3.1
600 selectedImageRef.style.borderTopStyle = "";
601 selectedImageRef.style.borderRightStyle = "";
602 selectedImageRef.style.borderBottomStyle = "";
603 selectedImageRef.style.borderLeftStyle = "";
604 selectedImageRef.style.borderTopWidth = "";
605 selectedImageRef.style.borderRightWidth = "";
606 selectedImageRef.style.borderBottomWidth = "";
607 selectedImageRef.style.borderLeftWidth = "";
608 if(document.imageData.iBorder.checked) {
609 selectedImageRef.style.borderStyle = "solid";
610 selectedImageRef.style.borderWidth = "thin";
611 }
612 selectedImageRef.removeAttribute("border");
613 }
614 if (document.imageData.iFloat) {
615 var iFloat = document.imageData.iFloat.options[document.imageData.iFloat.selectedIndex].value;
616 if (document.all) {
617 selectedImageRef.style.styleFloat = iFloat ? iFloat : "";
618 } else {
619 selectedImageRef.style.cssFloat = iFloat ? iFloat : "";
620 }
621 }
622 if (classesImage && document.imageData.iClass) {
623 var iClass = document.imageData.iClass.options[document.imageData.iClass.selectedIndex].value;
624 if (iClass || (selectedImageRef.attributes["class"] && selectedImageRef.attributes["class"].value)) {
625 selectedImageRef.className = iClass;
626 } else {
627 selectedImageRef.className = "";
628 }
629 }
630 if (document.imageData.iLang) {
631 var iLang = document.imageData.iLang.options[document.imageData.iLang.selectedIndex].value;
632 var languageObject = plugin.editor.getPlugin("Language");
633 if (iLang || languageObject.getLanguageAttribute(selectedImageRef)) {
634 languageObject.setLanguageAttributes(selectedImageRef, iLang);
635 } else {
636 languageObject.setLanguageAttributes(selectedImageRef, "none");
637 }
638 }
639 if (document.imageData.iClickEnlarge) {
640 if (document.imageData.iClickEnlarge.checked) {
641 selectedImageRef.setAttribute("clickenlarge","1");
642 } else {
643 selectedImageRef.removeAttribute("clickenlarge");
644 }
645 }
646 plugin.close();
647 }
648 return false;
649 }
650 function insertImagePropertiesInForm() {
651 var classesImage = ' . ($this->thisConfig['classesImage']?'true':'false') . ';
652 if (selectedImageRef) {
653 var styleWidth, styleHeight, padding;
654 if (document.imageData.iWidth) {
655 styleWidth = selectedImageRef.style.width ? selectedImageRef.style.width : selectedImageRef.width;
656 styleWidth = parseInt(styleWidth);
657 if (!(isNaN(styleWidth) || styleWidth == 0)) {
658 document.imageData.iWidth.value = styleWidth;
659 }
660 }
661 if (document.imageData.iHeight) {
662 styleHeight = selectedImageRef.style.height ? selectedImageRef.style.height : selectedImageRef.height;
663 styleHeight = parseInt(styleHeight);
664 if (!(isNaN(styleHeight) || styleHeight == 0)) {
665 document.imageData.iHeight.value = styleHeight;
666 }
667 }
668 if (document.imageData.iPaddingTop) {
669 var padding = selectedImageRef.style.paddingTop ? selectedImageRef.style.paddingTop : selectedImageRef.vspace;
670 var padding = parseInt(padding);
671 if (isNaN(padding) || padding <= 0) { padding = ""; }
672 document.imageData.iPaddingTop.value = padding;
673 }
674 if (document.imageData.iPaddingRight) {
675 padding = selectedImageRef.style.paddingRight ? selectedImageRef.style.paddingRight : selectedImageRef.hspace;
676 var padding = parseInt(padding);
677 if (isNaN(padding) || padding <= 0) { padding = ""; }
678 document.imageData.iPaddingRight.value = padding;
679 }
680 if (document.imageData.iPaddingBottom) {
681 var padding = selectedImageRef.style.paddingBottom ? selectedImageRef.style.paddingBottom : selectedImageRef.vspace;
682 var padding = parseInt(padding);
683 if (isNaN(padding) || padding <= 0) { padding = ""; }
684 document.imageData.iPaddingBottom.value = padding;
685 }
686 if (document.imageData.iPaddingLeft) {
687 var padding = selectedImageRef.style.paddingLeft ? selectedImageRef.style.paddingLeft : selectedImageRef.hspace;
688 var padding = parseInt(padding);
689 if (isNaN(padding) || padding <= 0) { padding = ""; }
690 document.imageData.iPaddingLeft.value = padding;
691 }
692 if (document.imageData.iTitle) {
693 document.imageData.iTitle.value = selectedImageRef.title;
694 }
695 if (document.imageData.iAlt) {
696 document.imageData.iAlt.value = selectedImageRef.alt;
697 }
698 if (document.imageData.iBorder) {
699 if((selectedImageRef.style.borderStyle && selectedImageRef.style.borderStyle != "none" && selectedImageRef.style.borderStyle != "none none none none") || selectedImageRef.border) {
700 document.imageData.iBorder.checked = 1;
701 }
702 }
703 if (document.imageData.iFloat) {
704 var fObj=document.imageData.iFloat;
705 var value = (selectedImageRef.style.cssFloat ? selectedImageRef.style.cssFloat : selectedImageRef.style.styleFloat);
706 var l=fObj.length;
707 for (var a=0;a<l;a++) {
708 if (fObj.options[a].value == value) {
709 fObj.selectedIndex = a;
710 }
711 }
712 }
713 if (classesImage && document.imageData.iClass) {
714 var fObj=document.imageData.iClass;
715 var value=selectedImageRef.className;
716 var l=fObj.length;
717 for (var a=0;a < l; a++) {
718 if (fObj.options[a].value == value) {
719 fObj.selectedIndex = a;
720 }
721 }
722 }
723 if (document.imageData.iLang) {
724 var fObj=document.imageData.iLang;
725 var value=plugin.editor.getPlugin("Language").getLanguageAttribute(selectedImageRef);
726 for (var i = 0, n = fObj.length; i < n; i++) {
727 if (fObj.options[i].value == value) {
728 fObj.selectedIndex = i;
729 if (i) {
730 fObj.options[0].text = plugin.editor.getPlugin("Language").localize("Remove language mark");
731 }
732 }
733 }
734 }
735 if (document.imageData.iClickEnlarge) {
736 if (selectedImageRef.getAttribute("clickenlarge") == "1") {
737 document.imageData.iClickEnlarge.checked = 1;
738 } else {
739 document.imageData.iClickEnlarge.checked = 0;
740 }
741 }
742 return false;
743 }
744 }
745
746 var selectedImageRef = getCurrentImageRef();'; // Setting this to a reference to the image object.
747 return $JScode;
748 }
749
750 /**
751 * Session data for this class can be set from outside with this method.
752 * Call after init()
753 *
754 * @param array Session data array
755 * @return array Session data and boolean which indicates that data needs to be stored in session because it's changed
756 */
757 function processSessionData($data) {
758 $store = FALSE;
759
760 if ($this->act != 'image') {
761 if (isset($this->act)) {
762 $data['act'] = $this->act;
763 $store = TRUE;
764 } else {
765 $this->act = $data['act'];
766 }
767 }
768
769 if (isset($this->expandFolder)) {
770 $data['expandFolder'] = $this->expandFolder;
771 $store = TRUE;
772 } else {
773 $this->expandFolder = $data['expandFolder'];
774 }
775
776 return array($data, $store);
777 }
778
779 /**
780 * [Describe function...]
781 *
782 * @return [type] ...
783 */
784 function main_rte() {
785 global $LANG;
786
787 // Starting content:
788 $this->content = $this->doc->startPage($LANG->getLL('Insert Image',1));
789
790 // Making menu in top:
791 $menuDef = array();
792 if (in_array('image',$this->allowedItems) && ($this->act=='image' || t3lib_div::_GP('cWidth'))) {
793 $menuDef['page']['isActive'] = $this->act=='image';
794 $menuDef['page']['label'] = $LANG->getLL('currentImage',1);
795 $menuDef['page']['url'] = '#';
796 $menuDef['page']['addParams'] = 'onClick="jumpToUrl(\'?act=image&bparams='.$this->bparams.'\');return false;"';
797 }
798 if (in_array('magic',$this->allowedItems)){
799 $menuDef['file']['isActive'] = $this->act=='magic';
800 $menuDef['file']['label'] = $LANG->getLL('magicImage',1);
801 $menuDef['file']['url'] = '#';
802 $menuDef['file']['addParams'] = 'onClick="jumpToUrl(\'?act=magic&bparams='.$this->bparams.'\');return false;"';
803 }
804 if (in_array('plain',$this->allowedItems)) {
805 $menuDef['url']['isActive'] = $this->act=='plain';
806 $menuDef['url']['label'] = $LANG->getLL('plainImage',1);
807 $menuDef['url']['url'] = '#';
808 $menuDef['url']['addParams'] = 'onClick="jumpToUrl(\'?act=plain&bparams='.$this->bparams.'\');return false;"';
809 }
810 if (in_array('dragdrop',$this->allowedItems)) {
811 $menuDef['mail']['isActive'] = $this->act=='dragdrop';
812 $menuDef['mail']['label'] = $LANG->getLL('dragDropImage',1);
813 $menuDef['mail']['url'] = '#';
814 $menuDef['mail']['addParams'] = 'onClick="jumpToUrl(\'?act=dragdrop&bparams='.$this->bparams.'\');return false;"';
815 }
816
817 // Call hook for extra options
818 foreach ($this->hookObjects as $hookObject) {
819 $menuDef = $hookObject->modifyMenuDefinition($menuDef);
820 }
821
822 $this->content .= $this->doc->getTabMenuRaw($menuDef);
823
824 switch($this->act) {
825 case 'image':
826 $JScode = '
827 document.write(printCurrentImageOptions());
828 insertImagePropertiesInForm();';
829 $this->content.= '<br />'.$this->doc->wrapScriptTags($JScode);
830 break;
831 case 'plain':
832 case 'magic':
833 // Adding upload form, if allowed
834 $this->content .= $this->insertUploadForm($this->expandFolder);
835 // Getting flag for showing/not showing thumbnails:
836 $noThumbs = $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInRTEimageSelect');
837 if (!$noThumbs) {
838 // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
839 $_MOD_MENU = array('displayThumbs' => '');
840 $_MCONF['name']='file_list';
841 $_MOD_SETTINGS = t3lib_BEfunc::getModuleData($_MOD_MENU, t3lib_div::_GP('SET'), $_MCONF['name']);
842 $addParams = '&act='.$this->act.'&editorNo='.$this->editorNo.'&expandFolder='.rawurlencode($this->expandFolder);
843 $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>';
844 } else {
845 $thumbNailCheck='';
846 }
847 // Create folder tree:
848 $foldertree = t3lib_div::makeInstance('tx_rtehtmlarea_image_folderTree');
849 $tree = $foldertree->getBrowsableTree();
850 list(,,$specUid) = explode('_',t3lib_div::_GP('PM'));
851 $files = $this->expandFolder($foldertree->specUIDmap[$specUid],$this->act=='plain',$noThumbs?$noThumbs:!$_MOD_SETTINGS['displayThumbs']);
852 $this->content.= '<table border="0" cellpadding="0" cellspacing="0">
853 <tr>
854 <td style="vertical-align: top;">'.$this->barheader($LANG->getLL('folderTree').':').$tree.'</td>
855 <td>&nbsp;</td>
856 <td style="vertical-align: top;">'.$files.'</td>
857 </tr>
858 </table>
859 <br />'.$thumbNailCheck;
860 // Add help message
861 $helpMessage = $this->getHelpMessage($this->act);
862 if ($helpMessage) {
863 $this->content .= $this->getMsgBox($helpMessage);
864 }
865 break;
866 case 'dragdrop':
867 $foldertree = t3lib_div::makeInstance('TBE_FolderTree');
868 $foldertree->thisScript=$this->thisScript;
869 $foldertree->ext_noTempRecyclerDirs = TRUE;
870 $tree = $foldertree->getBrowsableTree();
871 list(,,$specUid) = explode('_',t3lib_div::_GP('PM'));
872 $files = $this->TBE_dragNDrop($foldertree->specUIDmap[$specUid], implode(',', $this->allowedFileTypes));
873 $this->content.= '<table border="0" cellpadding="0" cellspacing="0">
874 <tr>
875 <td style="vertical-align: top;">'.$this->barheader($LANG->getLL('folderTree').':').$tree.'</td>
876 <td>&nbsp;</td>
877 <td style="vertical-align: top;">'.$files.'</td>
878 </tr>
879 </table>';
880 break;
881 default:
882 // Call hook
883 foreach ($this->hookObjects as $hookObject) {
884 $this->content.= $hookObject->getTab($this->act);
885 }
886 break;
887 }
888 $this->content.= $this->doc->endPage();
889 $this->doc->JScodeArray['rtehtmlarea'] = $this->getJSCode($this->act, $this->editorNo, $this->sys_language_content);
890 $this->content = $this->doc->insertStylesAndJS($this->content);
891 return $this->content;
892 }
893
894 /**
895 * Create upload/create folder forms, if a path is given
896 *
897 * @param string $folderPath: the selected path , if any
898 *
899 * @return string the html content for the upload form
900 */
901 protected function insertUploadForm($folderPath) {
902 $content = '';
903 if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB') && !$this->readOnly && count($GLOBALS['FILEMOUNTS'])) {
904 $path = $folderPath;
905 if (!$path || !@is_dir($path)) {
906 // The closest TEMP-path is found
907 $path = $this->fileProcessor->findTempFolder().'/';
908 }
909 if ($path!='/' && @is_dir($path)) {
910 $uploadForm=$this->uploadForm($path);
911 $createFolder=$this->createFolder($path);
912 } else {
913 $createFolder='';
914 $uploadForm='';
915 }
916 $content .= $uploadForm;
917 if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB')) {
918 $content.=$createFolder;
919 }
920 }
921 return $content;
922 }
923
924 /***************************
925 *
926 * OTHER FUNCTIONS:
927 *
928 ***************************/
929 /**
930 * @param [type] $expandFolder: ...
931 * @param [type] $plainFlag: ...
932 * @return [type] ...
933 */
934 function expandFolder($expandFolder=0,$plainFlag=0,$noThumbs=0) {
935 global $LANG, $BACK_PATH;
936
937 $expandFolder = $expandFolder ? $expandFolder :t3lib_div::_GP('expandFolder');
938 $out='';
939
940 if ($expandFolder && $this->checkFolder($expandFolder)) {
941 $files = t3lib_div::getFilesInDir($expandFolder,($plainFlag?'jpg,jpeg,gif,png':$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']),1,1); // $extensionList="",$prependPath=0,$order="")
942 if (is_array($files)) {
943 $out.=$this->barheader(sprintf($LANG->getLL('images').' (%s):',count($files)));
944
945 $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
946 $picon='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/_icon_webfolders.gif','width="18" height="16"').' alt="" />';
947 $picon.=htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($expandFolder),$titleLen));
948 $out.='<span class="nobr">'.$picon.'</span><br />';
949
950 $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
951 $imgObj->init();
952 $imgObj->mayScaleUp=0;
953 $imgObj->tempPath=PATH_site.$imgObj->tempPath;
954
955 $lines=array();
956 foreach ($files as $filepath) {
957 $fI=pathinfo($filepath);
958
959 $origFile = t3lib_div::rawUrlEncodeFP(substr($filepath,strlen(PATH_site)));
960 $iurl = $this->siteURL.$origFile;
961 $imgInfo = $imgObj->getImageDimensions($filepath);
962 // File icon:
963 $icon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
964 $pDim = $imgInfo[0].'x'.$imgInfo[1].' '.$LANG->getLL('pixels',1);
965 $size=' ('.t3lib_div::formatSize(filesize($filepath)).$LANG->getLL('bytes',1).', '.$pDim.')';
966 $icon = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/fileicons/'.$icon.'','width="18" height="16"').' title="'.htmlspecialchars($fI['basename'].$size).'" alt="" />';
967 $ATag = '<a href="#" onclick="return jumpToUrl(\'?editorNo='.$this->editorNo.'&insertImage='.rawurlencode($filepath).'\');">';
968 $ATag_e='</a>';
969 if ($plainFlag && (($imgInfo[0] > $this->plainMaxWidth) || ($imgInfo[1] > $this->plainMaxHeight))) {
970 $ATag='';
971 $ATag_e='';
972 $ATag2='';
973 $ATag2_e='';
974 } else {
975 $ATag2='<a href="#" onClick="launchView(\''.rawurlencode($filepath).'\'); return false;">';
976 $ATag2_e='</a>';
977 }
978
979 $filenameAndIcon=$ATag.$icon.htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($filepath),$titleLen)).$ATag_e;
980
981
982 $lines[]='<tr class="bgColor4"><td nowrap="nowrap">'.$filenameAndIcon.'&nbsp;</td><td nowrap="nowrap">'.$pDim.'&nbsp;</td></tr>';
983 $lines[]='<tr><td colspan="2">'.($noThumbs ? '' : $ATag2.t3lib_BEfunc::getThumbNail($this->doc->backPath.'thumbs.php',$filepath,'hspace="5" vspace="5" border="1"').$ATag2_e).
984 '</td></tr>';
985 $lines[]='<tr><td colspan="2"><img src="clear.gif" width="1" height="3"></td></tr>';
986 }
987 $out.='<table border="0" cellpadding="0" cellspacing="1">'.implode('',$lines).'</table>';
988 }
989 }
990 return $out;
991 }
992
993 /**
994 * For RTE: This displays all IMAGES (gif,png,jpg) (from extensionList) from folder. Thumbnails are shown for images.
995 * This listing is of images located in the web-accessible paths ONLY - the listing is for drag-n-drop use in the RTE
996 *
997 * @param string The folder path to expand
998 * @param string List of fileextensions to show
999 * @return string HTML output
1000 */
1001 function TBE_dragNDrop($expandFolder=0,$extensionList='') {
1002 global $BACK_PATH;
1003
1004 $expandFolder = $expandFolder ? $expandFolder : t3lib_div::_GP('expandFolder');
1005 $out='';
1006 if ($expandFolder && $this->checkFolder($expandFolder)) {
1007 if ($this->isWebFolder($expandFolder)) {
1008
1009 // Read files from directory:
1010 $files = t3lib_div::getFilesInDir($expandFolder,$extensionList,1,1); // $extensionList="",$prependPath=0,$order='')
1011 if (is_array($files)) {
1012 $out.=$this->barheader(sprintf($GLOBALS['LANG']->getLL('files').' (%s):',count($files)));
1013
1014 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
1015 $picon='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/_icon_webfolders.gif','width="18" height="16"').' alt="" />';
1016 $picon.=htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($expandFolder),$titleLen));
1017 $out.=$picon.'<br />';
1018
1019 // Init row-array:
1020 $lines=array();
1021
1022 // Add "drag-n-drop" message:
1023 $lines[]='
1024 <tr>
1025 <td colspan="2">'.$this->getMsgBox($GLOBALS['LANG']->getLL('findDragDrop')).'</td>
1026 </tr>';
1027
1028 // Traverse files:
1029 foreach ($files as $filepath) {
1030 $fI = pathinfo($filepath);
1031
1032 // URL of image:
1033 $iurl = $this->siteURL.t3lib_div::rawurlencodeFP(substr($filepath,strlen(PATH_site)));
1034
1035 // Show only web-images
1036 if (t3lib_div::inList('gif,jpeg,jpg,png',strtolower($fI['extension']))) {
1037 $imgInfo = @getimagesize($filepath);
1038 $pDim = $imgInfo[0].'x'.$imgInfo[1].' pixels';
1039
1040 $ficon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
1041 $size=' ('.t3lib_div::formatSize(filesize($filepath)).'bytes'.($pDim?', '.$pDim:'').')';
1042 $icon = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/fileicons/'.$ficon,'width="18" height="16"').' class="absmiddle" title="'.htmlspecialchars($fI['basename'].$size).'" alt="" />';
1043 $filenameAndIcon=$icon.htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($filepath),$titleLen));
1044
1045 if (t3lib_div::_GP('noLimit')) {
1046 $maxW=10000;
1047 $maxH=10000;
1048 } else {
1049 $maxW=380;
1050 $maxH=500;
1051 }
1052 $IW = $imgInfo[0];
1053 $IH = $imgInfo[1];
1054 if ($IW>$maxW) {
1055 $IH=ceil($IH/$IW*$maxW);
1056 $IW=$maxW;
1057 }
1058 if ($IH>$maxH) {
1059 $IW=ceil($IW/$IH*$maxH);
1060 $IH=$maxH;
1061 }
1062
1063 // Make row:
1064 $lines[]='
1065 <tr class="bgColor4">
1066 <td nowrap="nowrap">'.$filenameAndIcon.'&nbsp;</td>
1067 <td nowrap="nowrap">'.
1068 ($imgInfo[0]!=$IW ? '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('noLimit'=>'1'))).'">'.
1069 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/icon_warning2.gif','width="18" height="16"').' title="'.$GLOBALS['LANG']->getLL('clickToRedrawFullSize',1).'" alt="" />'.
1070 '</a>':'').
1071 $pDim.'&nbsp;</td>
1072 </tr>';
1073 // Remove hardcoded border="1"
1074 // Add default class for images
1075 $lines[]='
1076 <tr>
1077 <td colspan="2"><img src="'.$iurl.'" width="'.$IW.'" height="'.$IH.'" alt=""' . ($this->defaultClass?(' class="'.$this->defaultClass.'"'):''). ' style="cursor:move;" /></td>
1078 </tr>';
1079 $lines[]='
1080 <tr>
1081 <td colspan="2"><img src="clear.gif" width="1" height="3" alt="" /></td>
1082 </tr>';
1083 }
1084 }
1085
1086 // Finally, wrap all rows in a table tag:
1087 $out.='
1088
1089
1090 <!--
1091 File listing / Drag-n-drop
1092 -->
1093 <table border="0" cellpadding="0" cellspacing="1" id="typo3-dragBox">
1094 '.implode('',$lines).'
1095 </table>';
1096 }
1097 } else {
1098 // Print this warning if the folder is NOT a web folder:
1099 $out.=$this->barheader($GLOBALS['LANG']->getLL('files'));
1100 $out.=$this->getMsgBox($GLOBALS['LANG']->getLL('noWebFolder'),'icon_warning2');
1101 }
1102 }
1103 return $out;
1104 }
1105
1106 /**
1107 * Initializes the configuration variables
1108 *
1109 * @return void
1110 */
1111 public function initConfiguration() {
1112 $this->thisConfig = $this->getRTEConfig();
1113 $this->buttonConfig = $this->getButtonConfig();
1114 $this->imgPath = $this->getImgPath();
1115 $this->RTEImageStorageDir = $this->getRTEImageStorageDir();
1116 $this->defaultClass = $this->getDefaultClass();
1117 $this->setMaximumImageDimensions();
1118 }
1119
1120 /**
1121 * Get the RTE configuration from Page TSConfig
1122 *
1123 * @return array RTE configuration array
1124 */
1125 protected function getRTEConfig() {
1126 $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
1127 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($RTEtsConfigParts[5]));
1128 return t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$RTEtsConfigParts[0],$RTEtsConfigParts[2],$RTEtsConfigParts[4]);
1129 }
1130
1131 /**
1132 * Get the path of the image to be inserted or modified
1133 *
1134 * @return string path to the image
1135 */
1136 protected function getImgPath() {
1137 $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
1138 return $RTEtsConfigParts[6];
1139 }
1140
1141 /**
1142 * Get the configuration of the image button
1143 *
1144 * @return array the configuration array of the image button
1145 */
1146 protected function getButtonConfig() {
1147 return ((is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['image.'])) ? $this->thisConfig['buttons.']['image.'] : array());
1148 }
1149
1150 /**
1151 * Get the allowed items or tabs
1152 *
1153 * @param string $items: initial list of possible items
1154 * @return array the allowed items
1155 */
1156 public function getAllowedItems($items) {
1157 $allowedItems = explode(',', $items);
1158 $clientInfo = t3lib_div::clientInfo();
1159 if ($clientInfo['BROWSER'] !== 'opera') {
1160 $allowedItems[] = 'dragdrop';
1161 }
1162 // Call hook for extra options
1163 foreach ($this->hookObjects as $hookObject) {
1164 $allowedItems = $hookObject->addAllowedItems($allowedItems);
1165 }
1166 // Remove tab "image" if there is no current image
1167 if ($this->act !== 'image') {
1168 $allowedItems = array_diff($allowedItems, array('image'));
1169 }
1170 // Remove options according to RTE configuration
1171 if (is_array($this->buttonConfig['options.']) && $this->buttonConfig['options.']['removeItems']) {
1172 $allowedItems = array_diff($allowedItems, t3lib_div::trimExplode(',', $this->buttonConfig['options.']['removeItems'], 1));
1173 } else {
1174 $allowedItems = array_diff($allowedItems, t3lib_div::trimExplode(',', $this->thisConfig['blindImageOptions'], 1));
1175 }
1176 return $allowedItems;
1177 }
1178
1179 /**
1180 * Get the default image class
1181 *
1182 * @return string the default class, if any
1183 */
1184 protected function getDefaultClass() {
1185 $defaultClass = '';
1186 if (is_array($this->buttonConfig['properties.'])) {
1187 if (is_array($this->buttonConfig['properties.']['class.']) && trim($this->buttonConfig['properties.']['class.']['default'])) {
1188 $defaultClass = trim($this->buttonConfig['properties.']['class.']['default']);
1189 }
1190 }
1191 return $defaultClass;
1192 }
1193
1194 /**
1195 * Set variables for maximum image dimensions
1196 *
1197 * @return void
1198 */
1199 protected function setMaximumImageDimensions() {
1200 if (is_array($this->buttonConfig['options.']) && is_array($this->buttonConfig['options.']['plain.'])) {
1201 if ($this->buttonConfig['options.']['plain.']['maxWidth']) $this->plainMaxWidth = $this->buttonConfig['options.']['plain.']['maxWidth'];
1202 if ($this->buttonConfig['options.']['plain.']['maxHeight']) $this->plainMaxHeight = $this->buttonConfig['options.']['plain.']['maxHeight'];
1203 }
1204 if (!$this->plainMaxWidth) $this->plainMaxWidth = 640;
1205 if (!$this->plainMaxHeight) $this->plainMaxHeight = 680;
1206 if (is_array($this->buttonConfig['options.']) && is_array($this->buttonConfig['options.']['magic.'])) {
1207 if ($this->buttonConfig['options.']['magic.']['maxWidth']) $this->magicMaxWidth = $this->buttonConfig['options.']['magic.']['maxWidth'];
1208 if ($this->buttonConfig['options.']['magic.']['maxHeight']) $this->magicMaxHeight = $this->buttonConfig['options.']['magic.']['maxHeight'];
1209 }
1210 // 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
1211 if (!$this->magicMaxWidth) $this->magicMaxWidth = 300;
1212 if (!$this->magicMaxHeight) $this->magicMaxHeight = 1000;
1213 }
1214
1215 /**
1216 * Get the help message to be displayed on a given tab
1217 *
1218 * @param string $act: the identifier of the tab
1219 * @return string the text of the message
1220 */
1221 public function getHelpMessage($act) {
1222 global $LANG;
1223 switch ($act) {
1224 case 'plain':
1225 return sprintf($LANG->getLL('plainImage_msg'), $this->plainMaxWidth, $this->plainMaxHeight);
1226 break;
1227 case 'magic':
1228 return sprintf($LANG->getLL('magicImage_msg'));
1229 break;
1230 default:
1231 return '';
1232 }
1233 }
1234 }
1235
1236 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php'])) {
1237 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']);
1238 }
1239
1240 ?>