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