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