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