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