[BUGFIX] Selection of non image files in element browser
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / SelectImage.php
1 <?php
2 namespace TYPO3\CMS\Rtehtmlarea;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasper@typo3.com)
8 * (c) 2004-2013 Stanislas Rolland <typo3(arobas)jbr.ca>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the text file GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30
31 use TYPO3\CMS\Core\Utility\GeneralUtility;
32 use TYPO3\CMS\Core\Resource;
33
34 /**
35 * Script Class
36 *
37 * @author Kasper Skårhøj <kasper@typo3.com>
38 */
39 class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
40
41 /**
42 * These file extensions are allowed in the "plain" image selection mode.
43 *
44 * @const
45 */
46 const PLAIN_MODE_IMAGE_FILE_EXTENSIONS = 'jpg,jpeg,gif,png';
47
48 /**
49 * @todo Define visibility
50 */
51 public $extKey = 'rtehtmlarea';
52
53 /**
54 * @todo Define visibility
55 */
56 public $content;
57
58 public $allowedItems;
59
60 public $allowedFileTypes = array();
61
62 protected $defaultClass;
63
64 /**
65 * Relevant for RTE mode "plain": the maximum width an image must have to be selectable.
66 *
67 * @var int
68 */
69 protected $plainMaxWidth;
70
71 /**
72 * Relevant for RTE mode "plain": the maximum height an image must have to be selectable.
73 *
74 * @var int
75 */
76 protected $plainMaxHeight;
77
78 protected $magicMaxWidth;
79
80 protected $magicMaxHeight;
81
82 protected $imgPath;
83
84 public $editorNo;
85
86 public $sys_language_content;
87
88 public $thisConfig;
89
90 public $buttonConfig;
91
92 protected $imgObj;
93
94 /**
95 * Initialisation
96 *
97 * @return void
98 */
99 public function init() {
100 $this->initVariables();
101 $this->initConfiguration();
102 $this->initHookObjects();
103 // init fileProcessor
104 $this->fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\BasicFileUtility');
105 $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
106 $this->allowedItems = $this->getAllowedItems('magic,plain,image');
107 $this->insertImage();
108 // Creating backend template object:
109 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
110 // Apply the same styles as those of the base script
111 $this->doc->bodyTagId = 'typo3-browse-links-php';
112 $this->doc->bodyTagAdditions = $this->getBodyTagAdditions();
113 $this->doc->backPath = $GLOBALS['BACK_PATH'];
114 // Load the Prototype library and browse_links.js
115 $this->doc->getPageRenderer()->loadPrototype();
116 $this->doc->loadJavascriptLib('js/tree.js');
117 $this->doc->loadJavascriptLib('js/browse_links.js');
118 $this->doc->JScode .= $this->doc->wrapScriptTags('
119 Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
120 ');
121 $this->doc->getPageRenderer()->addCssFile($this->doc->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('t3skin') . 'rtehtmlarea/htmlarea.css');
122 $this->doc->getContextMenuCode();
123 }
124
125 /**
126 * Initialize class variables
127 *
128 * @return void
129 */
130 public function initVariables() {
131 // Get "act"
132 $this->act = GeneralUtility::_GP('act');
133 if (!$this->act) {
134 $this->act = FALSE;
135 }
136 // Process bparams
137 $this->bparams = GeneralUtility::_GP('bparams');
138 $pArr = explode('|', $this->bparams);
139 $pRteArr = explode(':', $pArr[1]);
140 $this->editorNo = $pRteArr[0];
141 $this->sys_language_content = $pRteArr[1];
142 $this->RTEtsConfigParams = $pArr[2];
143 if (!$this->editorNo) {
144 $this->editorNo = GeneralUtility::_GP('editorNo');
145 $this->sys_language_content = GeneralUtility::_GP('sys_language_content');
146 $this->RTEtsConfigParams = GeneralUtility::_GP('RTEtsConfigParams');
147 }
148 $this->expandPage = GeneralUtility::_GP('expandPage');
149 $this->expandFolder = GeneralUtility::_GP('expandFolder');
150 $pArr[1] = implode(':', array($this->editorNo, $this->sys_language_content));
151 $pArr[2] = $this->RTEtsConfigParams;
152 if ($this->act == 'dragdrop' || $this->act == 'plain') {
153 $this->allowedFileTypes = explode(',', self::PLAIN_MODE_IMAGE_FILE_EXTENSIONS);
154 }
155 $pArr[3] = implode(',', $this->allowedFileTypes);
156 $this->bparams = implode('|', $pArr);
157 // Find "mode"
158 $this->mode = GeneralUtility::_GP('mode');
159 if (!$this->mode) {
160 $this->mode = 'rte';
161 }
162 // Site URL
163 $this->siteURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
164 // Current site url
165 // the script to link to
166 $this->thisScript = GeneralUtility::getIndpEnv('SCRIPT_NAME');
167 }
168
169 /**
170 * Initialize hook objects implementing the hook interface
171 *
172 * @return void
173 * @throws \UnexpectedValueException
174 */
175 protected function initHookObjects() {
176 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']['browseLinksHook'])) {
177 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']['browseLinksHook'] as $classData) {
178 $processObject = GeneralUtility::getUserObj($classData);
179 if (!$processObject instanceof \TYPO3\CMS\Core\ElementBrowser\ElementBrowserHookInterface) {
180 throw new \UnexpectedValueException('$processObject must implement interface TYPO3\\CMS\\Core\\ElementBrowser\\ElementBrowserHookInterface', 1195115652);
181 }
182 $parameters = array();
183 $processObject->init($this, $parameters);
184 $this->hookObjects[] = $processObject;
185 }
186 }
187 }
188
189 /**
190 * Provide the additional parameters to be included in the template body tag
191 *
192 * @return string the body tag additions
193 */
194 public function getBodyTagAdditions() {
195 return 'onload="initEventListeners();"';
196 }
197
198 /**
199 * Get the path to the folder where RTE images are stored
200 *
201 * @return string the path to the folder where RTE images are stored
202 * @deprecated since 6.2, will be removed in two versions
203 */
204 protected function getRTEImageStorageDir() {
205 GeneralUtility::logDeprecatedFunction();
206 return $this->imgPath ?: $GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir'];
207 }
208
209 /**
210 * Insert the image in the editing area
211 *
212 * @return void
213 */
214 protected function insertImage() {
215 $table = htmlspecialchars(GeneralUtility::_GP('table'));
216 $uid = (int) GeneralUtility::_GP('uid');
217 if (GeneralUtility::_GP('insertImage') && $uid) {
218 /** @var $fileObject Resource\File */
219 $fileObject = Resource\ResourceFactory::getInstance()->getFileObject($uid);
220 // Get default values for alt and title attributes from file properties
221 $altText = $fileObject->getProperty('alternative');
222 $titleText = $fileObject->getProperty('name');
223 switch ($this->act) {
224 case 'magic':
225 $this->insertMagicImage($fileObject, $altText, $titleText, 'data-htmlarea-file-uid="' . $uid . '" data-htmlarea-file-table="' . $table . '"');
226 die;
227 break;
228 case 'plain':
229 $this->insertPlainImage($fileObject, $altText, $titleText, 'data-htmlarea-file-uid="' . $uid . '" data-htmlarea-file-table="' . $table . '"');
230 die;
231 break;
232 default:
233 // Call hook
234 foreach ($this->hookObjects as $hookObject) {
235 if (method_exists($hookObject, 'insertElement')) {
236 $hookObject->insertElement($this->act);
237 }
238 }
239 }
240 }
241 }
242
243 /**
244 * Insert a magic image
245 *
246 * @param Resource\File $fileObject: the image file
247 * @param string $altText: text for the alt attribute of the image
248 * @param string $titleText: text for the title attribute of the image
249 * @param string $additionalParams: text representing more HTML attributes to be added on the img tag
250 * @return void
251 */
252 public function insertMagicImage(Resource\File $fileObject, $altText = '', $titleText = '', $additionalParams = '') {
253 // Create the magic image service
254 /** @var $magicImageService Resource\Service\MagicImageService */
255 $magicImageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Service\\MagicImageService');
256 // Create the magic image
257 $imageConfiguration = array(
258 'width' => GeneralUtility::_GP('cWidth'),
259 'height' => GeneralUtility::_GP('cHeight'),
260 'maxW' => $this->magicMaxWidth,
261 'maxH' => $this->magicMaxHeight
262 );
263 $magicImage = $magicImageService->createMagicImage($fileObject, $imageConfiguration);
264 $imageUrl = $magicImage->getPublicUrl();
265 // If file is local, make the url absolute
266 if (substr($imageUrl, 0, 4) !== 'http') {
267 $imageUrl = $this->siteURL . $imageUrl;
268 }
269 // Insert the magic image
270 $this->imageInsertJS($imageUrl, $magicImage->getProperty('width'), $magicImage->getProperty('height'), $altText, $titleText, $additionalParams);
271 }
272
273 /**
274 * Insert a plain image
275 *
276 * @param \TYPO3\CMS\Core\Resource\File $fileObject: the image file
277 * @param string $altText: text for the alt attribute of the image
278 * @param string $titleText: text for the title attribute of the image
279 * @param string $additionalParams: text representing more HTML attributes to be added on the img tag
280 * @return void
281 */
282 public function insertPlainImage(Resource\File $fileObject, $altText = '', $titleText = '', $additionalParams = '') {
283 $width = $fileObject->getProperty('width');
284 $height = $fileObject->getProperty('height');
285 if (!$width || !$height) {
286 $filePath = $fileObject->getForLocalProcessing(FALSE);
287 $imageInfo = @getimagesize($filePath);
288 $width = $imageInfo[0];
289 $height = $imageInfo[1];
290 }
291 $imageUrl = $fileObject->getPublicUrl();
292 // If file is local, make the url absolute
293 if (substr($imageUrl, 0, 4) !== 'http') {
294 $imageUrl = $this->siteURL . $imageUrl;
295 }
296 $this->imageInsertJS($imageUrl, $width, $height, $altText, $titleText, $additionalParams);
297 }
298
299 /**
300 * Echo the HTML page and JS that will insert the image
301 *
302 * @param string $url: the url of the image
303 * @param integer $width: the width of the image
304 * @param integer $height: the height of the image
305 * @param string $altText: text for the alt attribute of the image
306 * @param string $titleText: text for the title attribute of the image
307 * @param string $additionalParams: text representing more html attributes to be added on the img tag
308 * @return void
309 */
310 protected function imageInsertJS($url, $width, $height, $altText = '', $titleText = '', $additionalParams = '') {
311 echo '
312 <!DOCTYPE html>
313 <html>
314 <head>
315 <title>Untitled</title>
316 <script type="text/javascript">
317 /*<![CDATA[*/
318 var plugin = window.parent.RTEarea["' . $this->editorNo . '"].editor.getPlugin("TYPO3Image");
319 function insertImage(file,width,height,alt,title,additionalParams) {
320 plugin.insertImage(\'<img src="\'+file+\'" width="\'+parseInt(width)+\'" height="\'+parseInt(height)+\'"\'' . ($this->defaultClass ? '+\' class="' . $this->defaultClass . '"\'' : '') . '+(alt?\' alt="\'+alt+\'"\':\'\')+(title?\' title="\'+title+\'"\':\'\')+(additionalParams?\' \'+additionalParams:\'\')+\' />\');
321 }
322 /*]]>*/
323 </script>
324 </head>
325 <body>
326 <script type="text/javascript">
327 /*<![CDATA[*/
328 insertImage(' . GeneralUtility::quoteJSvalue($url, 1) . ',' . $width . ',' . $height . ',' . GeneralUtility::quoteJSvalue($altText, 1) . ',' . GeneralUtility::quoteJSvalue($titleText, 1) . ',' . GeneralUtility::quoteJSvalue($additionalParams, 1) . ');
329 /*]]>*/
330 </script>
331 </body>
332 </html>';
333 }
334
335 /**
336 * Generate JS code to be used on the image insert/modify dialogue
337 *
338 * @param string $act: the action to be performed
339 * @param string $editorNo: the number of the RTE instance on the page
340 * @param string $sys_language_content: the language of the content element
341 * @return string the generated JS code
342 * @todo Define visibility
343 */
344 public function getJSCode($act, $editorNo, $sys_language_content) {
345 $removedProperties = array();
346 if (is_array($this->buttonConfig['properties.'])) {
347 if ($this->buttonConfig['properties.']['removeItems']) {
348 $removedProperties = GeneralUtility::trimExplode(',', $this->buttonConfig['properties.']['removeItems'], TRUE);
349 }
350 }
351 if ($this->buttonConfig['properties.']['class.']['allowedClasses']) {
352 $classesImageArray = GeneralUtility::trimExplode(',', $this->buttonConfig['properties.']['class.']['allowedClasses'], TRUE);
353 $classesImageJSOptions = '<option value=""></option>';
354 foreach ($classesImageArray as $class) {
355 $classesImageJSOptions .= '<option value="' . $class . '">' . $class . '</option>';
356 }
357 }
358 $lockPlainWidth = 'false';
359 $lockPlainHeight = 'false';
360 if (is_array($this->thisConfig['proc.']) && $this->thisConfig['proc.']['plainImageMode']) {
361 $plainImageMode = $this->thisConfig['proc.']['plainImageMode'];
362 $lockPlainWidth = $plainImageMode == 'lockDimensions' ? 'true' : 'false';
363 $lockPlainHeight = $lockPlainWidth || $plainImageMode == 'lockRatio' || $plainImageMode == 'lockRatioWhenSmaller' ? 'true' : 'false';
364 }
365 $JScode = '
366 var plugin = window.parent.RTEarea["' . $editorNo . '"].editor.getPlugin("TYPO3Image");
367 var HTMLArea = window.parent.HTMLArea;
368
369 HTMLArea.TYPO3Image.insertElement = function (table, uid, type, filename, filePath, fileExt, fileIcon) {
370 return jumpToUrl(\'?editorNo=\' + \'' . $editorNo . '\' + \'&insertImage=\' + filePath + \'&table=\' + table + \'&uid=\' + uid + \'&type=\' + type + \'bparams=\' + \'' . $this->bparams . '\');
371 }
372 function insertElement(table, uid, type, fileName, filePath, fileExt, fileIcon, action, close) {
373 return jumpToUrl(\'?editorNo=\' + \'' . $editorNo . '\' + \'&insertImage=\' + filePath + \'&table=\' + table + \'&uid=\' + uid + \'&type=\' + type + \'bparams=\' + \'' . $this->bparams . '\');
374 }
375 function initEventListeners() {
376 if (Ext.isWebKit) {
377 Ext.EventManager.addListener(window.document.body, "dragend", plugin.onDrop, plugin, { single: true });
378 }
379 }
380 function jumpToUrl(URL,anchor) {
381 var add_act = URL.indexOf("act=")==-1 ? "&act=' . $act . '" : "";
382 var add_editorNo = URL.indexOf("editorNo=")==-1 ? "&editorNo=' . $editorNo . '" : "";
383 var add_sys_language_content = URL.indexOf("sys_language_content=")==-1 ? "&sys_language_content=' . $sys_language_content . '" : "";
384 var RTEtsConfigParams = "&RTEtsConfigParams=' . rawurlencode($this->RTEtsConfigParams) . '";
385
386 var cur_width = selectedImageRef ? "&cWidth="+selectedImageRef.style.width : "";
387 var cur_height = selectedImageRef ? "&cHeight="+selectedImageRef.style.height : "";
388
389 var theLocation = URL+add_act+add_editorNo+add_sys_language_content+RTEtsConfigParams+cur_width+cur_height+(typeof(anchor)=="string"?anchor:"");
390 window.location.href = theLocation;
391 return false;
392 }
393 function insertImage(file,width,height) {
394 plugin.insertImage(\'<img src="\'+file+\'"' . ($this->defaultClass ? ' class="' . $this->defaultClass . '"' : '') . ' width="\'+parseInt(width)+\'" height="\'+parseInt(height)+\'" />\');
395 }
396 function launchView(url) {
397 var thePreviewWindow="";
398 thePreviewWindow = window.open("' . GeneralUtility::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");
399 if (thePreviewWindow && thePreviewWindow.focus) {
400 thePreviewWindow.focus();
401 }
402 }
403 function getCurrentImageRef() {
404 if (plugin.image) {
405 return plugin.image;
406 } else {
407 return null;
408 }
409 }
410 function printCurrentImageOptions() {
411 var classesImage = ' . ($this->buttonConfig['properties.']['class.']['allowedClasses'] || $this->thisConfig['classesImage'] ? 'true' : 'false') . ';
412 if (classesImage) var styleSelector=\'<select id="iClass" name="iClass" style="width:140px;">' . $classesImageJSOptions . '</select>\';
413 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>\';
414 if (plugin.getButton("Language")) {
415 var languageSelector = \'<select id="iLang" name="iLang">\';
416 plugin.getButton("Language").getStore().each(function (record) {
417 languageSelector +=\'<option value="\' + record.get("value") + \'">\' + record.get("text") + \'</option>\';
418 });
419 languageSelector += \'</select>\';
420 }
421 var sz="";
422 sz+=\'<form action="" name="imageData"><table class="htmlarea-window-table">\';
423 ' . (in_array('class', $removedProperties) ? '' : '
424 if(classesImage) {
425 sz+=\'<tr><td><label for="iClass">' . $GLOBALS['LANG']->getLL('class') . ': </label></td><td>\'+styleSelector+\'</td></tr>\';
426 }') . (in_array('width', $removedProperties) ? '' : '
427 if (!(selectedImageRef && selectedImageRef.src.indexOf("RTEmagic") == -1 && ' . $lockPlainWidth . ')) {
428 sz+=\'<tr><td><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>\';
429 }') . (in_array('height', $removedProperties) ? '' : '
430 if (!(selectedImageRef && selectedImageRef.src.indexOf("RTEmagic") == -1 && ' . $lockPlainHeight . ')) {
431 sz+=\'<tr><td><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>\';
432 }') . (in_array('border', $removedProperties) ? '' : '
433 sz+=\'<tr><td><label for="iBorder">' . $GLOBALS['LANG']->getLL('border') . ': </label></td><td><input type="checkbox" id="iBorder" name="iBorder" value="1" /></td></tr>\';') . (in_array('float', $removedProperties) ? '' : '
434 sz+=\'<tr><td><label for="iFloat">' . $GLOBALS['LANG']->getLL('float') . ': </label></td><td>\'+floatSelector+\'</td></tr>\';') . (in_array('paddingTop', $removedProperties) ? '' : '
435 sz+=\'<tr><td><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>\';') . (in_array('paddingRight', $removedProperties) ? '' : '
436 sz+=\'<tr><td><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>\';') . (in_array('paddingBottom', $removedProperties) ? '' : '
437 sz+=\'<tr><td><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>\';') . (in_array('paddingLeft', $removedProperties) ? '' : '
438 sz+=\'<tr><td><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>\';') . (in_array('title', $removedProperties) ? '' : '
439 sz+=\'<tr><td><label for="iTitle">' . $GLOBALS['LANG']->getLL('title') . ': </label></td><td><input type="text" id="iTitle" name="iTitle"' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . ' /></td></tr>\';') . (in_array('alt', $removedProperties) ? '' : '
440 sz+=\'<tr><td><label for="iAlt">' . $GLOBALS['LANG']->getLL('alt') . ': </label></td><td><input type="text" id="iAlt" name="iAlt"' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . ' /></td></tr>\';') . (in_array('lang', $removedProperties) ? '' : '
441 if (plugin.getButton("Language")) {
442 sz+=\'<tr><td><label for="iLang">\' + plugin.editor.getPlugin("Language").localize(\'Language-Tooltip\') + \': </label></td><td>\' + languageSelector + \'</td></tr>\';
443 }') . (in_array('clickenlarge', $removedProperties) || in_array('data-htmlarea-clickenlarge', $removedProperties) ? '' : '
444 sz+=\'<tr><td><label for="iClickEnlarge">' . $GLOBALS['LANG']->sL('LLL:EXT:cms/locallang_ttc.xlf:image_zoom', TRUE) . ' </label></td><td><input type="checkbox" name="iClickEnlarge" id="iClickEnlarge" value="0" /></td></tr>\';') . '
445 sz+=\'<tr><td></td><td><input type="submit" value="' . $GLOBALS['LANG']->getLL('update') . '" onClick="return setImageProperties();"></td></tr>\';
446 sz+=\'</table></form>\';
447 return sz;
448 }
449 function setImageProperties() {
450 var classesImage = ' . ($this->buttonConfig['properties.']['class.']['allowedClasses'] || $this->thisConfig['classesImage'] ? 'true' : 'false') . ';
451 if (selectedImageRef) {
452 if (document.imageData.iWidth) {
453 if (document.imageData.iWidth.value && parseInt(document.imageData.iWidth.value)) {
454 selectedImageRef.style.width = "";
455 selectedImageRef.width = parseInt(document.imageData.iWidth.value);
456 }
457 }
458 if (document.imageData.iHeight) {
459 if (document.imageData.iHeight.value && parseInt(document.imageData.iHeight.value)) {
460 selectedImageRef.style.height = "";
461 selectedImageRef.height = parseInt(document.imageData.iHeight.value);
462 }
463 }
464 if (document.imageData.iPaddingTop) {
465 if (document.imageData.iPaddingTop.value != "" && !isNaN(parseInt(document.imageData.iPaddingTop.value))) {
466 selectedImageRef.style.paddingTop = parseInt(document.imageData.iPaddingTop.value) + "px";
467 } else {
468 selectedImageRef.style.paddingTop = "";
469 }
470 }
471 if (document.imageData.iPaddingRight) {
472 if (document.imageData.iPaddingRight.value != "" && !isNaN(parseInt(document.imageData.iPaddingRight.value))) {
473 selectedImageRef.style.paddingRight = parseInt(document.imageData.iPaddingRight.value) + "px";
474 } else {
475 selectedImageRef.style.paddingRight = "";
476 }
477 }
478 if (document.imageData.iPaddingBottom) {
479 if (document.imageData.iPaddingBottom.value != "" && !isNaN(parseInt(document.imageData.iPaddingBottom.value))) {
480 selectedImageRef.style.paddingBottom = parseInt(document.imageData.iPaddingBottom.value) + "px";
481 } else {
482 selectedImageRef.style.paddingBottom = "";
483 }
484 }
485 if (document.imageData.iPaddingLeft) {
486 if (document.imageData.iPaddingLeft.value != "" && !isNaN(parseInt(document.imageData.iPaddingLeft.value))) {
487 selectedImageRef.style.paddingLeft = parseInt(document.imageData.iPaddingLeft.value) + "px";
488 } else {
489 selectedImageRef.style.paddingLeft = "";
490 }
491 }
492 if (document.imageData.iTitle) {
493 selectedImageRef.title=document.imageData.iTitle.value;
494 }
495 if (document.imageData.iAlt) {
496 selectedImageRef.alt=document.imageData.iAlt.value;
497 }
498 if (document.imageData.iBorder) {
499 selectedImageRef.style.borderStyle = "";
500 selectedImageRef.style.borderWidth = "";
501 selectedImageRef.style.border = ""; // this statement ignored by Mozilla 1.3.1
502 selectedImageRef.style.borderTopStyle = "";
503 selectedImageRef.style.borderRightStyle = "";
504 selectedImageRef.style.borderBottomStyle = "";
505 selectedImageRef.style.borderLeftStyle = "";
506 selectedImageRef.style.borderTopWidth = "";
507 selectedImageRef.style.borderRightWidth = "";
508 selectedImageRef.style.borderBottomWidth = "";
509 selectedImageRef.style.borderLeftWidth = "";
510 if(document.imageData.iBorder.checked) {
511 selectedImageRef.style.borderStyle = "solid";
512 selectedImageRef.style.borderWidth = "thin";
513 }
514 selectedImageRef.removeAttribute("border");
515 }
516 if (document.imageData.iFloat) {
517 var iFloat = document.imageData.iFloat.options[document.imageData.iFloat.selectedIndex].value;
518 if (document.all) {
519 selectedImageRef.style.styleFloat = iFloat ? iFloat : "";
520 } else {
521 selectedImageRef.style.cssFloat = iFloat ? iFloat : "";
522 }
523 }
524 if (classesImage && document.imageData.iClass) {
525 var iClass = document.imageData.iClass.options[document.imageData.iClass.selectedIndex].value;
526 if (iClass || (selectedImageRef.attributes["class"] && selectedImageRef.attributes["class"].value)) {
527 selectedImageRef.className = iClass;
528 } else {
529 selectedImageRef.className = "";
530 }
531 }
532 if (document.imageData.iLang) {
533 var iLang = document.imageData.iLang.options[document.imageData.iLang.selectedIndex].value;
534 var languageObject = plugin.editor.getPlugin("Language");
535 if (iLang || languageObject.getLanguageAttribute(selectedImageRef)) {
536 languageObject.setLanguageAttributes(selectedImageRef, iLang);
537 } else {
538 languageObject.setLanguageAttributes(selectedImageRef, "none");
539 }
540 }
541 if (document.imageData.iClickEnlarge) {
542 if (document.imageData.iClickEnlarge.checked) {
543 selectedImageRef.setAttribute("data-htmlarea-clickenlarge","1");
544 } else {
545 selectedImageRef.removeAttribute("data-htmlarea-clickenlarge");
546 selectedImageRef.removeAttribute("clickenlarge");
547 }
548 }
549 plugin.close();
550 }
551 return false;
552 }
553 function insertImagePropertiesInForm() {
554 var classesImage = ' . ($this->buttonConfig['properties.']['class.']['allowedClasses'] || $this->thisConfig['classesImage'] ? 'true' : 'false') . ';
555 if (selectedImageRef) {
556 var styleWidth, styleHeight, padding;
557 if (document.imageData.iWidth) {
558 styleWidth = selectedImageRef.style.width ? selectedImageRef.style.width : selectedImageRef.width;
559 styleWidth = parseInt(styleWidth);
560 if (!(isNaN(styleWidth) || styleWidth == 0)) {
561 document.imageData.iWidth.value = styleWidth;
562 }
563 }
564 if (document.imageData.iHeight) {
565 styleHeight = selectedImageRef.style.height ? selectedImageRef.style.height : selectedImageRef.height;
566 styleHeight = parseInt(styleHeight);
567 if (!(isNaN(styleHeight) || styleHeight == 0)) {
568 document.imageData.iHeight.value = styleHeight;
569 }
570 }
571 if (document.imageData.iPaddingTop) {
572 var padding = selectedImageRef.style.paddingTop ? selectedImageRef.style.paddingTop : selectedImageRef.vspace;
573 var padding = parseInt(padding);
574 if (isNaN(padding) || padding <= 0) { padding = ""; }
575 document.imageData.iPaddingTop.value = padding;
576 }
577 if (document.imageData.iPaddingRight) {
578 padding = selectedImageRef.style.paddingRight ? selectedImageRef.style.paddingRight : selectedImageRef.hspace;
579 var padding = parseInt(padding);
580 if (isNaN(padding) || padding <= 0) { padding = ""; }
581 document.imageData.iPaddingRight.value = padding;
582 }
583 if (document.imageData.iPaddingBottom) {
584 var padding = selectedImageRef.style.paddingBottom ? selectedImageRef.style.paddingBottom : selectedImageRef.vspace;
585 var padding = parseInt(padding);
586 if (isNaN(padding) || padding <= 0) { padding = ""; }
587 document.imageData.iPaddingBottom.value = padding;
588 }
589 if (document.imageData.iPaddingLeft) {
590 var padding = selectedImageRef.style.paddingLeft ? selectedImageRef.style.paddingLeft : selectedImageRef.hspace;
591 var padding = parseInt(padding);
592 if (isNaN(padding) || padding <= 0) { padding = ""; }
593 document.imageData.iPaddingLeft.value = padding;
594 }
595 if (document.imageData.iTitle) {
596 document.imageData.iTitle.value = selectedImageRef.title;
597 }
598 if (document.imageData.iAlt) {
599 document.imageData.iAlt.value = selectedImageRef.alt;
600 }
601 if (document.imageData.iBorder) {
602 if((selectedImageRef.style.borderStyle && selectedImageRef.style.borderStyle != "none" && selectedImageRef.style.borderStyle != "none none none none") || selectedImageRef.border) {
603 document.imageData.iBorder.checked = 1;
604 }
605 }
606 if (document.imageData.iFloat) {
607 var fObj=document.imageData.iFloat;
608 var value = (selectedImageRef.style.cssFloat ? selectedImageRef.style.cssFloat : selectedImageRef.style.styleFloat);
609 var l=fObj.length;
610 for (var a=0;a<l;a++) {
611 if (fObj.options[a].value == value) {
612 fObj.selectedIndex = a;
613 }
614 }
615 }
616 if (classesImage && document.imageData.iClass) {
617 var fObj=document.imageData.iClass;
618 var value=selectedImageRef.className;
619 var l=fObj.length;
620 for (var a=0;a < l; a++) {
621 if (fObj.options[a].value == value) {
622 fObj.selectedIndex = a;
623 }
624 }
625 }
626 if (document.imageData.iLang) {
627 var fObj=document.imageData.iLang;
628 var value=plugin.editor.getPlugin("Language").getLanguageAttribute(selectedImageRef);
629 for (var i = 0, n = fObj.length; i < n; i++) {
630 if (fObj.options[i].value == value) {
631 fObj.selectedIndex = i;
632 if (i) {
633 fObj.options[0].text = plugin.editor.getPlugin("Language").localize("Remove language mark");
634 }
635 }
636 }
637 }
638 if (document.imageData.iClickEnlarge) {
639 if (selectedImageRef.getAttribute("data-htmlarea-clickenlarge") == "1" || selectedImageRef.getAttribute("clickenlarge") == "1") {
640 document.imageData.iClickEnlarge.checked = 1;
641 } else {
642 document.imageData.iClickEnlarge.checked = 0;
643 }
644 }
645 return false;
646 }
647 }
648
649 var selectedImageRef = getCurrentImageRef();';
650 // Setting this to a reference to the image object.
651 return $JScode;
652 }
653
654 /**
655 * Session data for this class can be set from outside with this method.
656 * Call after init()
657 *
658 * @param array $data Session data array
659 * @return array Session data and boolean which indicates that data needs to be stored in session because it's changed
660 * @todo Define visibility
661 */
662 public function processSessionData($data) {
663 $store = FALSE;
664 if ($this->act != 'image') {
665 if (isset($this->act)) {
666 $data['act'] = $this->act;
667 $store = TRUE;
668 } else {
669 $this->act = $data['act'];
670 }
671 }
672 if (isset($this->expandFolder)) {
673 $data['expandFolder'] = $this->expandFolder;
674 $store = TRUE;
675 } else {
676 $this->expandFolder = $data['expandFolder'];
677 }
678 return array($data, $store);
679 }
680
681 /**
682 * @return string
683 * @todo Define visibility
684 */
685 public function main_rte() {
686 // Starting content:
687 $this->content = $this->doc->startPage($GLOBALS['LANG']->getLL('Insert Image', TRUE));
688 // Making menu in top:
689 $menuDef = array();
690 if (in_array('image', $this->allowedItems) && ($this->act === 'image' || GeneralUtility::_GP('cWidth'))) {
691 $menuDef['image']['isActive'] = FALSE;
692 $menuDef['image']['label'] = $GLOBALS['LANG']->getLL('currentImage', TRUE);
693 $menuDef['image']['url'] = '#';
694 $menuDef['image']['addParams'] = 'onClick="jumpToUrl(\'?act=image&bparams=' . $this->bparams . '\');return false;"';
695 }
696 if (in_array('magic', $this->allowedItems)) {
697 $menuDef['magic']['isActive'] = FALSE;
698 $menuDef['magic']['label'] = $GLOBALS['LANG']->getLL('magicImage', TRUE);
699 $menuDef['magic']['url'] = '#';
700 $menuDef['magic']['addParams'] = 'onClick="jumpToUrl(\'?act=magic&bparams=' . $this->bparams . '\');return false;"';
701 }
702 if (in_array('plain', $this->allowedItems)) {
703 $menuDef['plain']['isActive'] = FALSE;
704 $menuDef['plain']['label'] = $GLOBALS['LANG']->getLL('plainImage', TRUE);
705 $menuDef['plain']['url'] = '#';
706 $menuDef['plain']['addParams'] = 'onClick="jumpToUrl(\'?act=plain&bparams=' . $this->bparams . '\');return false;"';
707 }
708 if (in_array('dragdrop', $this->allowedItems)) {
709 $menuDef['dragdrop']['isActive'] = FALSE;
710 $menuDef['dragdrop']['label'] = $GLOBALS['LANG']->getLL('dragDropImage', TRUE);
711 $menuDef['dragdrop']['url'] = '#';
712 $menuDef['dragdrop']['addParams'] = 'onClick="jumpToUrl(\'?act=dragdrop&bparams=' . $this->bparams . '\');return false;"';
713 }
714 // Call hook for extra options
715 foreach ($this->hookObjects as $hookObject) {
716 $menuDef = $hookObject->modifyMenuDefinition($menuDef);
717 }
718 // Order the menu items as specified in Page TSconfig
719 $menuDef = $this->orderMenuDefinition($menuDef);
720 // Set active menu item
721 reset($menuDef);
722 if ($this->act === FALSE || !in_array($this->act, $this->allowedItems)) {
723 $this->act = key($menuDef);
724 }
725 $menuDef[$this->act]['isActive'] = TRUE;
726 $this->content .= $this->doc->getTabMenuRaw($menuDef);
727 switch ($this->act) {
728 case 'image':
729 $JScode = '
730 document.write(printCurrentImageOptions());
731 insertImagePropertiesInForm();';
732 $this->content .= '<br />' . $this->doc->wrapScriptTags($JScode);
733 break;
734 case 'plain':
735
736 case 'magic':
737 // Create folder tree:
738 $foldertree = GeneralUtility::makeInstance('TYPO3\\CMS\\Rtehtmlarea\\ImageFolderTree');
739 $foldertree->thisScript = $this->thisScript;
740 $tree = $foldertree->getBrowsableTree();
741 // Get currently selected folder
742 if (!$this->curUrlInfo['value'] || $this->curUrlInfo['act'] != $this->act) {
743 $cmpPath = '';
744 } else {
745 $cmpPath = $this->curUrlInfo['value'];
746 if (!isset($this->expandFolder)) {
747 $this->expandFolder = $cmpPath;
748 }
749 }
750 // Get the selected folder
751 $selectedFolder = FALSE;
752 if ($this->expandFolder) {
753 $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
754 if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
755 // it's a folder
756 $selectedFolder = $fileOrFolderObject;
757 } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
758 // it's a file
759 // @todo: find the parent folder, right now done a bit ugly, because the file does not
760 // support finding the parent folder of a file on purpose
761 $folderIdentifier = dirname($fileOrFolderObject->getIdentifier());
762 $selectedFolder = $fileOrFolderObject->getStorage()->getFolder($folderIdentifier);
763 }
764 }
765 // If no folder is selected, get the user's default upload folder
766 if (!$selectedFolder) {
767 $selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
768 }
769 // Build the file upload and folder creation form
770 $uploadForm = '';
771 $createFolder = '';
772 if ($selectedFolder) {
773 $uploadForm = $this->uploadForm($selectedFolder);
774 $createFolder = $this->createFolder($selectedFolder);
775 }
776 // Insert the upload form on top, if so configured
777 if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
778 $this->content .= $uploadForm;
779 }
780 // Render the filelist if there is a folder selected
781 $files = '';
782 if ($selectedFolder) {
783 $files = $this->TBE_expandFolder($selectedFolder, $this->act === 'plain' ? self::PLAIN_MODE_IMAGE_FILE_EXTENSIONS : $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInRTEimageSelect'));
784 }
785 // Setup filelist indexed elements:
786 $this->doc->JScode .= $this->doc->wrapScriptTags('BrowseLinks.addElements(' . json_encode($this->elements) . ');');
787 // Wrap tree
788 $this->content .= '
789
790 <!--
791 Wrapper table for folder tree / file/folder list:
792 -->
793 <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkFiles">
794 <tr>
795 <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':')) . $tree . '</td>
796 <td class="c-wCell" valign="top">' . $files . '</td>
797 </tr>
798 </table>
799 ';
800 // Add help message
801 $helpMessage = $this->getHelpMessage($this->act);
802 if ($helpMessage) {
803 $this->content .= $this->getMsgBox($helpMessage);
804 }
805 // Adding create folder + upload form if applicable
806 if (!$GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
807 $this->content .= $uploadForm;
808 }
809 $this->content .= $createFolder;
810 $this->content .= '<br />';
811 break;
812 case 'dragdrop':
813 $foldertree = GeneralUtility::makeInstance('TBE_FolderTree');
814 $foldertree->thisScript = $this->thisScript;
815 $foldertree->ext_noTempRecyclerDirs = TRUE;
816 $tree = $foldertree->getBrowsableTree();
817 // Get currently selected folder
818 if (!$this->curUrlInfo['value'] || $this->curUrlInfo['act'] != $this->act) {
819 $cmpPath = '';
820 } else {
821 $cmpPath = $this->curUrlInfo['value'];
822 if (!isset($this->expandFolder)) {
823 $this->expandFolder = $cmpPath;
824 }
825 }
826 $selectedFolder = FALSE;
827 if ($this->expandFolder) {
828 try {
829 $selectedFolder = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($this->expandFolder);
830 } catch (\Exception $e) {
831 }
832 }
833 // Render the filelist if there is a folder selected
834 $files = '';
835 if ($selectedFolder) {
836 $files = $this->TBE_dragNDrop($selectedFolder, implode(',', $this->allowedFileTypes));
837 }
838 // Wrap tree
839 $this->content .= '<table border="0" cellpadding="0" cellspacing="0">
840 <tr>
841 <td style="vertical-align: top;">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':')) . $tree . '</td>
842 <td>&nbsp;</td>
843 <td style="vertical-align: top;">' . $files . '</td>
844 </tr>
845 </table>';
846 break;
847 default:
848 // Call hook
849 foreach ($this->hookObjects as $hookObject) {
850 $this->content .= $hookObject->getTab($this->act);
851 }
852 }
853 $this->content .= $this->doc->endPage();
854 $this->doc->JScodeArray['rtehtmlarea'] = $this->getJSCode($this->act, $this->editorNo, $this->sys_language_content);
855 $this->content = $this->doc->insertStylesAndJS($this->content);
856 return $this->content;
857 }
858
859 /**
860 * Initializes the configuration variables
861 *
862 * @return void
863 */
864 public function initConfiguration() {
865 $this->thisConfig = $this->getRTEConfig();
866 $this->buttonConfig = $this->getButtonConfig();
867 $this->imgPath = $this->getImgPath();
868 $this->defaultClass = $this->getDefaultClass();
869 $this->setMaximumImageDimensions();
870 }
871
872 /**
873 * Get the RTE configuration from Page TSConfig
874 *
875 * @return array RTE configuration array
876 */
877 protected function getRTEConfig() {
878 $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
879 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
880 return \TYPO3\CMS\Backend\Utility\BackendUtility::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
881 }
882
883 /**
884 * Get the path of the image to be inserted or modified
885 *
886 * @return string path to the image
887 */
888 protected function getImgPath() {
889 $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
890 return $RTEtsConfigParts[6];
891 }
892
893 /**
894 * Get the configuration of the image button
895 *
896 * @return array the configuration array of the image button
897 */
898 protected function getButtonConfig() {
899 return is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['image.']) ? $this->thisConfig['buttons.']['image.'] : array();
900 }
901
902 /**
903 * Get the allowed items or tabs
904 *
905 * @param string $items: initial list of possible items
906 * @return array the allowed items
907 */
908 public function getAllowedItems($items) {
909 $allowedItems = explode(',', $items);
910 $clientInfo = GeneralUtility::clientInfo();
911 if ($clientInfo['BROWSER'] !== 'opera') {
912 $allowedItems[] = 'dragdrop';
913 }
914 // Call hook for extra options
915 foreach ($this->hookObjects as $hookObject) {
916 $allowedItems = $hookObject->addAllowedItems($allowedItems);
917 }
918 // Remove tab "image" if there is no current image
919 if ($this->act !== 'image') {
920 $allowedItems = array_diff($allowedItems, array('image'));
921 }
922 // Remove options according to RTE configuration
923 if (is_array($this->buttonConfig['options.']) && $this->buttonConfig['options.']['removeItems']) {
924 $allowedItems = array_diff($allowedItems, GeneralUtility::trimExplode(',', $this->buttonConfig['options.']['removeItems'], TRUE));
925 }
926 return $allowedItems;
927 }
928
929 /**
930 * Order the definition of menu items according to configured order
931 *
932 * @param array $menuDefinition: definition of menu items
933 * @return array ordered menu definition
934 */
935 public function orderMenuDefinition($menuDefinition) {
936 $orderedMenuDefinition = array();
937 if (is_array($this->buttonConfig['options.']) && $this->buttonConfig['options.']['orderItems']) {
938 $orderItems = GeneralUtility::trimExplode(',', $this->buttonConfig['options.']['orderItems'], TRUE);
939 $orderItems = array_intersect($orderItems, $this->allowedItems);
940 foreach ($orderItems as $item) {
941 $orderedMenuDefinition[$item] = $menuDefinition[$item];
942 }
943 } else {
944 $orderedMenuDefinition = $menuDefinition;
945 }
946 return $orderedMenuDefinition;
947 }
948
949 /**
950 * Get the default image class
951 *
952 * @return string the default class, if any
953 */
954 protected function getDefaultClass() {
955 $defaultClass = '';
956 if (is_array($this->buttonConfig['properties.'])) {
957 if (is_array($this->buttonConfig['properties.']['class.']) && trim($this->buttonConfig['properties.']['class.']['default'])) {
958 $defaultClass = trim($this->buttonConfig['properties.']['class.']['default']);
959 }
960 }
961 return $defaultClass;
962 }
963
964 /**
965 * Set variables for maximum image dimensions
966 *
967 * @return void
968 */
969 protected function setMaximumImageDimensions() {
970 if (is_array($this->buttonConfig['options.']) && is_array($this->buttonConfig['options.']['plain.'])) {
971 if ($this->buttonConfig['options.']['plain.']['maxWidth']) {
972 $this->plainMaxWidth = $this->buttonConfig['options.']['plain.']['maxWidth'];
973 }
974 if ($this->buttonConfig['options.']['plain.']['maxHeight']) {
975 $this->plainMaxHeight = $this->buttonConfig['options.']['plain.']['maxHeight'];
976 }
977 }
978 if (!$this->plainMaxWidth) {
979 $this->plainMaxWidth = 640;
980 }
981 if (!$this->plainMaxHeight) {
982 $this->plainMaxHeight = 680;
983 }
984 if (is_array($this->buttonConfig['options.']) && is_array($this->buttonConfig['options.']['magic.'])) {
985 if ($this->buttonConfig['options.']['magic.']['maxWidth']) {
986 $this->magicMaxWidth = $this->buttonConfig['options.']['magic.']['maxWidth'];
987 }
988 if ($this->buttonConfig['options.']['magic.']['maxHeight']) {
989 $this->magicMaxHeight = $this->buttonConfig['options.']['magic.']['maxHeight'];
990 }
991 }
992 // 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
993 if (!$this->magicMaxWidth) {
994 $this->magicMaxWidth = 300;
995 }
996 if (!$this->magicMaxHeight) {
997 $this->magicMaxHeight = 1000;
998 }
999 }
1000
1001 /**
1002 * Get the help message to be displayed on a given tab
1003 *
1004 * @param string $act: the identifier of the tab
1005 * @return string the text of the message
1006 */
1007 public function getHelpMessage($act) {
1008 switch ($act) {
1009 case 'plain':
1010 return sprintf($GLOBALS['LANG']->getLL('plainImage_msg'), $this->plainMaxWidth, $this->plainMaxHeight);
1011 break;
1012 case 'magic':
1013 return sprintf($GLOBALS['LANG']->getLL('magicImage_msg'));
1014 break;
1015 default:
1016 return '';
1017 }
1018 }
1019
1020 /**
1021 * Checks if the given file is selectable in the file list.
1022 *
1023 * In "plain" RTE mode only image files with a maximum width and height are selectable.
1024 *
1025 * @param \TYPO3\CMS\Core\Resource\FileInterface $file
1026 * @param array $imgInfo Image dimensions from \TYPO3\CMS\Core\Imaging\GraphicalFunctions::getImageDimensions()
1027 * @return bool TRUE if file is selectable.
1028 */
1029 protected function fileIsSelectableInFileList(\TYPO3\CMS\Core\Resource\FileInterface $file, array $imgInfo) {
1030 return (
1031 $this->act !== 'plain'
1032 || (
1033 GeneralUtility::inList(self::PLAIN_MODE_IMAGE_FILE_EXTENSIONS, strtolower($file->getExtension()))
1034 && $imgInfo[0] <= $this->plainMaxWidth
1035 && $imgInfo[1] <= $this->plainMaxHeight
1036 )
1037 );
1038 }
1039 }