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