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