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