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