2 namespace TYPO3\CMS\Rtehtmlarea;
28 use TYPO3\CMS\Recordlist\Browser\ElementBrowser;
109 protected $hookName =
'ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php';
120 $this->initHookObjects();
123 $this->insertImage();
135 parent::initVariables();
144 $pArr = explode(
'|', $this->bparams);
145 $pRteArr = explode(
':', $pArr[1]);
146 $this->editorNo = $pRteArr[0];
147 $this->sys_language_content = $pRteArr[1];
148 $this->RTEtsConfigParams = $pArr[2];
149 if (!$this->editorNo) {
154 $pArr[1] = implode(
':', array($this->editorNo, $this->sys_language_content));
155 $pArr[2] = $this->RTEtsConfigParams;
156 if ($this->act ===
'dragdrop' || $this->act ===
'plain') {
157 $this->allowedFileTypes = explode(
',', self::PLAIN_MODE_IMAGE_FILE_EXTENSIONS);
159 $pArr[3] = implode(
',', $this->allowedFileTypes);
160 $this->bparams = implode(
'|', $pArr);
175 parent::initDocumentTemplate();
177 $this->doc->bodyTagAdditions =
'onload="SelectImage.initEventListeners();"';
179 $pageRenderer = $this->getPageRenderer();
181 $pageRenderer->loadRequireJsModule(
'TYPO3/CMS/Backend/LegacyTree',
'function(Tree) {
182 Tree.ajaxID = "sc_alt_file_navframe_expandtoggle";
184 $pageRenderer->loadRequireJsModule(
'TYPO3/CMS/Rtehtmlarea/Modules/SelectImage',
'function(SelectImage) {
198 protected function insertImage()
204 $uids = explode(
'|', $uidList);
205 $insertJsStatements = array();
206 foreach ($uids as $uid) {
210 $altText = $fileObject->getProperty(
'alternative');
211 $titleText = $fileObject->getProperty(
'title');
212 switch ($this->act) {
214 $insertJsStatements[] = $this->insertMagicImage($fileObject, $altText, $titleText,
'data-htmlarea-file-uid="' . $uid .
'"');
217 $insertJsStatements[] = $this->
insertPlainImage($fileObject, $altText, $titleText,
'data-htmlarea-file-uid="' . $uid .
'"');
221 foreach ($this->hookObjects as $hookObject) {
222 if (method_exists($hookObject,
'insertElement')) {
223 $hookObject->insertElement($this->act);
241 public function insertMagicImage(File $fileObject, $altText =
'', $titleText =
'', $additionalParams =
'')
246 $magicImageService->setMagicImageMaximumDimensions($this->RTEProperties[
'default.']);
248 $imageConfiguration = array(
252 $magicImage = $magicImageService->createMagicImage($fileObject, $imageConfiguration);
253 $imageUrl = $magicImage->getPublicUrl();
255 if (substr($imageUrl, 0, 4) !==
'http') {
256 $imageUrl = $this->siteURL . $imageUrl;
259 return $this->
imageInsertJsStatement($imageUrl, $magicImage->getProperty(
'width'), $magicImage->getProperty(
'height'), $altText, $titleText, $additionalParams);
275 if (!$width || !$height) {
277 $imageInfo = @getimagesize($filePath);
278 $width = $imageInfo[0];
279 $height = $imageInfo[1];
283 if (substr($imageUrl, 0, 4) !==
'http') {
284 $imageUrl = $this->siteURL . $imageUrl;
286 return $this->
imageInsertJsStatement($imageUrl, $width, $height, $altText, $titleText, $additionalParams);
318 <title>Untitled</title>
319 <script type="text/javascript">
322 function insertImage(file,width,height,alt,title,additionalParams) {
323 imageTags.push(\'<img src="\'+file+\'" width="\'+parseInt(width)+\'" height="\'+parseInt(height)+\'"\''
324 . ($this->defaultClass ?
'+\' class="' . $this->defaultClass .
'"\'' :
'')
325 .
'+ (alt ? \' alt="\' + alt + \'"\' : \'\') + (title ? \' title="\' + title + \'"\' : \'\') + (additionalParams ? \' \' + additionalParams : \'\') +\' />\');
330 <script type="text/javascript">
331 ' . implode(LF, $insertJsStatements) .
'
332 plugin.insertImage(imageTags.join(\' \'));
349 function insertElement(table, uid, type, fileName, filePath, fileExt, fileIcon, action, close) {
352 function insertMultiple(table, uidList) {
353 var uids = uidList.join("|");
356 function jumpToUrl(URL,anchor) {
357 SelectImage.jumpToUrl(URL, anchor);
371 if ($this->act !==
'image') {
373 $data[
'act'] = $this->act;
376 $this->act = $data[
'act'];
379 if (isset($this->expandFolder)) {
380 $data[
'expandFolder'] = $this->expandFolder;
383 $this->expandFolder = $data[
'expandFolder'];
385 return array($data, $store);
399 $this->content = $this->doc->startPage(
$lang->getLL(
'Insert Image',
true));
401 $this->content .= $this->doc->getTabMenuRaw($this->
buildMenuArray($wiz, $this->allowedItems));
402 switch ($this->act) {
404 $classesImage = $this->buttonConfig[
'properties.'][
'class.'][
'allowedClasses'] || $this->RTEProperties[
'default.'][
'classesImage'] ?
'true' :
'false';
405 $removedProperties = array();
406 if (is_array($this->buttonConfig[
'properties.'])) {
407 if ($this->buttonConfig[
'properties.'][
'removeItems']) {
411 $classesImageJSOptions =
'';
412 if ($this->buttonConfig[
'properties.'][
'class.'][
'allowedClasses']) {
414 $classesImageJSOptions =
'<option value=""></option>';
415 foreach ($classesImageArray as $class) {
416 $classesImageJSOptions .=
'<option value="' . $class .
'">' . $class .
'</option>';
419 $lockPlainWidth =
'false';
420 $lockPlainHeight =
'false';
421 if (is_array($this->RTEProperties[
'default.'][
'proc.']) && $this->RTEProperties[
'default.'][
'proc.'][
'plainImageMode']) {
422 $plainImageMode = $this->RTEProperties[
'default.'][
'proc.'][
'plainImageMode'];
423 $lockPlainWidth = $plainImageMode ==
'lockDimensions' ?
'true' :
'false';
424 $lockPlainHeight = $lockPlainWidth || $plainImageMode ==
'lockRatio' || $plainImageMode ==
'lockRatioWhenSmaller' ?
'true' :
'false';
426 $labels = array(
'notSet',
'nonFloating',
'right',
'left',
'class',
'width',
'height',
'border',
'float',
'padding_top',
'padding_left',
'padding_bottom',
'padding_right',
'title',
'alt',
'update');
427 foreach ($labels as $label) {
428 $localizedLabels[$label] =
$lang->getLL($label);
430 $localizedLabels[
'image_zoom'] =
$lang->sL(
'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:image_zoom',
true);
432 require(["TYPO3/CMS/Rtehtmlarea/Modules/SelectImage"], function(SelectImage) {
433 SelectImage.editorNo = "' . $this->editorNo .
'";
434 SelectImage.act = "' . $this->act .
'";
435 SelectImage.sys_language_content = "' . $this->sys_language_content .
'";
436 SelectImage.RTEtsConfigParams = "' . rawurlencode($this->RTEtsConfigParams) .
'";
437 SelectImage.bparams = "' . $this->bparams .
'";
438 SelectImage.classesImage = ' . $classesImage .
';
439 SelectImage.labels = ' . json_encode($localizedLabels) .
';
440 SelectImage.Form.build(' .
GeneralUtility::quoteJSvalue($classesImageJSOptions) .
', ' . json_encode($removedProperties) .
', ' . $lockPlainWidth .
', ' . $lockPlainHeight .
');
441 SelectImage.Form.insertImageProperties();
443 $this->content .=
'<br />' . $this->doc->wrapScriptTags($JScode);
449 $foldertree->thisScript = $this->thisScript;
450 $tree = $foldertree->getBrowsableTree();
452 if ($this->curUrlInfo[
'value'] && $this->curUrlInfo[
'act'] === $this->act) {
453 $cmpPath = $this->curUrlInfo[
'value'];
454 if (!isset($this->expandFolder)) {
455 $this->expandFolder = $cmpPath;
459 $selectedFolder =
false;
460 if ($this->expandFolder) {
461 $fileOrFolderObject = null;
464 }
catch (\Exception $e) {
467 if ($fileOrFolderObject instanceof
Folder) {
469 $selectedFolder = $fileOrFolderObject;
473 $selectedFolder = $fileOrFolderObject->getParentFolder();
474 }
catch (\Exception $e) {
481 if (!$selectedFolder) {
483 $selectedFolder = $backendUser->getDefaultUploadFolder();
484 }
catch (\Exception $e) {
491 if ($selectedFolder) {
492 $uploadForm = $this->uploadForm($selectedFolder);
493 $createFolder = $this->createFolder($selectedFolder);
496 if ($backendUser->getTSConfigVal(
'options.uploadFieldsInTopOfEB')) {
497 $this->content .= $uploadForm;
501 if ($selectedFolder) {
502 $files = $this->TBE_expandFolder(
504 $this->act ===
'plain' ? self::PLAIN_MODE_IMAGE_FILE_EXTENSIONS :
$GLOBALS[
'TYPO3_CONF_VARS'][
'GFX'][
'imagefile_ext'],
505 $backendUser->getTSConfigVal(
'options.noThumbsInRTEimageSelect')
509 $this->doc->JScode .= $this->doc->wrapScriptTags(
'
510 require(["TYPO3/CMS/Recordlist/BrowseFiles"], function(BrowseFiles) {
511 BrowseFiles.addElements(' . json_encode($this->elements) .
');
517 Wrapper table for folder tree / file/folder list:
519 <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkFiles">
521 <td class="c-wCell" valign="top">' . $this->barheader((
$lang->getLL(
'folderTree') .
':')) . $tree .
'</td>
522 <td class="c-wCell" valign="top">' . $files .
'</td>
533 if (!$backendUser->getTSConfigVal(
'options.uploadFieldsInTopOfEB')) {
534 $this->content .= $uploadForm;
536 $this->content .= $createFolder;
537 $this->content .=
'<br />';
541 $foldertree->setLinkParameterProvider($this);
542 $foldertree->thisScript = $this->thisScript;
543 $foldertree->ext_noTempRecyclerDirs =
true;
544 $tree = $foldertree->getBrowsableTree();
546 if ($this->curUrlInfo[
'value'] && $this->curUrlInfo[
'act'] === $this->act) {
547 $cmpPath = $this->curUrlInfo[
'value'];
548 if (!isset($this->expandFolder)) {
549 $this->expandFolder = $cmpPath;
552 $selectedFolder =
false;
553 if ($this->expandFolder) {
556 }
catch (\Exception $e) {
561 if ($selectedFolder) {
562 $files = $this->TBE_dragNDrop($selectedFolder, implode(
',', $this->allowedFileTypes));
565 $this->content .=
'<table border="0" cellpadding="0" cellspacing="0">
567 <td style="vertical-align: top;">' . $this->barheader((
$lang->getLL(
'folderTree') .
':')) . $tree .
'</td>
569 <td style="vertical-align: top;">' . $files .
'</td>
575 foreach ($this->hookObjects as $hookObject) {
576 $this->content .= $hookObject->getTab($this->act);
579 $this->content .= $this->doc->endPage();
580 $this->doc->JScodeArray[
'rtehtmlarea'] = $this->
getJSCode($this->act, $this->editorNo, $this->sys_language_content);
581 $this->content = $this->doc->insertStylesAndJS($this->content);
596 if (in_array(
'image', $this->allowedItems) && ($this->act ===
'image' || $this->addModifyTab)) {
597 $menuDef[
'image'][
'isActive'] =
false;
598 $menuDef[
'image'][
'label'] =
$lang->getLL(
'currentImage',
true);
599 $menuDef[
'image'][
'url'] =
'#';
600 $menuDef[
'image'][
'addParams'] =
'onclick="jumpToUrl(' .
GeneralUtility::quoteJSvalue($this->getThisScript()) .
' + \'act=image\');return false;"';
602 if (in_array(
'magic', $this->allowedItems)) {
603 $menuDef[
'magic'][
'isActive'] =
false;
604 $menuDef[
'magic'][
'label'] =
$lang->getLL(
'magicImage',
true);
605 $menuDef[
'magic'][
'url'] =
'#';
606 $menuDef[
'magic'][
'addParams'] =
'onclick="jumpToUrl(' .
GeneralUtility::quoteJSvalue($this->getThisScript()) .
' + \'act=magic\');return false;"';
608 if (in_array(
'plain', $this->allowedItems)) {
609 $menuDef[
'plain'][
'isActive'] =
false;
610 $menuDef[
'plain'][
'label'] =
$lang->getLL(
'plainImage',
true);
611 $menuDef[
'plain'][
'url'] =
'#';
612 $menuDef[
'plain'][
'addParams'] =
'onclick="jumpToUrl(' .
GeneralUtility::quoteJSvalue($this->getThisScript()) .
' + \'act=plain\');return false;"';
614 if (in_array(
'dragdrop', $this->allowedItems)) {
615 $menuDef[
'dragdrop'][
'isActive'] =
false;
616 $menuDef[
'dragdrop'][
'label'] =
$lang->getLL(
'dragDropImage',
true);
617 $menuDef[
'dragdrop'][
'url'] =
'#';
618 $menuDef[
'dragdrop'][
'addParams'] =
'onclick="jumpToUrl(' .
GeneralUtility::quoteJSvalue($this->getThisScript()) .
' + \'act=dragdrop\');return false;"';
621 foreach ($this->hookObjects as $hookObject) {
622 $menuDef = $hookObject->modifyMenuDefinition($menuDef);
628 if ($this->act ===
false || !in_array($this->act, $this->allowedItems)) {
629 $this->act = key($menuDef);
631 $menuDef[$this->act][
'isActive'] =
true;
642 $RTEtsConfigParts = explode(
':', $this->RTEtsConfigParams);
643 return $RTEtsConfigParts[6];
653 return isset($this->RTEProperties[
'default.'][
'buttons.'][
'image.'])
654 ? $this->RTEProperties[
'default.'][
'buttons.'][
'image.']
668 if ($clientInfo[
'BROWSER'] !==
'opera') {
672 foreach ($this->hookObjects as $hookObject) {
676 if ($this->act !==
'image' && !$this->addModifyTab) {
680 if (is_array($this->buttonConfig[
'options.']) && $this->buttonConfig[
'options.'][
'removeItems']) {
699 $orderedMenuDefinition = array();
700 if (is_array($this->buttonConfig[
'options.']) && $this->buttonConfig[
'options.'][
'orderItems']) {
702 $orderItems = array_intersect($orderItems, $this->allowedItems);
703 foreach ($orderItems as $item) {
704 $orderedMenuDefinition[$item] = $menuDefinition[$item];
707 $orderedMenuDefinition = $menuDefinition;
709 return $orderedMenuDefinition;
720 if (is_array($this->buttonConfig[
'properties.'])) {
721 if (is_array($this->buttonConfig[
'properties.'][
'class.']) && trim($this->buttonConfig[
'properties.'][
'class.'][
'default'])) {
722 $defaultClass = trim($this->buttonConfig[
'properties.'][
'class.'][
'default']);
735 if (is_array($this->buttonConfig[
'options.']) && is_array($this->buttonConfig[
'options.'][
'plain.'])) {
736 if ($this->buttonConfig[
'options.'][
'plain.'][
'maxWidth']) {
737 $this->plainMaxWidth = $this->buttonConfig[
'options.'][
'plain.'][
'maxWidth'];
739 if ($this->buttonConfig[
'options.'][
'plain.'][
'maxHeight']) {
740 $this->plainMaxHeight = $this->buttonConfig[
'options.'][
'plain.'][
'maxHeight'];
743 if (!$this->plainMaxWidth) {
744 $this->plainMaxWidth = 640;
746 if (!$this->plainMaxHeight) {
747 $this->plainMaxHeight = 680;
761 return sprintf($this->
getLanguageService()->getLL(
'plainImage_msg'), $this->plainMaxWidth, $this->plainMaxHeight);
783 $this->act !==
'plain'
786 && $imgInfo[0] <= $this->plainMaxWidth