2 namespace TYPO3\CMS\Rtehtmlarea\Controller
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
16 use Psr\Http\Message\ResponseInterface
;
17 use Psr\Http\Message\ServerRequestInterface
;
18 use TYPO3\CMS\Core\Utility\GeneralUtility
;
21 * User defined content for htmlArea RTE
23 class UserElementsController
41 * document template object
43 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
53 * Initialize language files
55 public function __construct()
57 $GLOBALS['LANG']->includeLLFile('EXT:rtehtmlarea/Resources/Private/Language/locallang_userelementscontroller.xlf');
58 $GLOBALS['LANG']->includeLLFile('EXT:rtehtmlarea/Resources/Private/Language/locallang_dialogs.xlf');
66 public function init()
68 $this->editorNo
= \TYPO3\CMS\Core\Utility\GeneralUtility
::_GP('editorNo');
69 $this->siteUrl
= \TYPO3\CMS\Core\Utility\GeneralUtility
::getIndpEnv('TYPO3_SITE_URL');
70 $this->doc
= \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate
::class);
71 $this->doc
->bodyTagAdditions
= 'onload="Init();"';
73 <form action="" id="process" name="process" method="post">
74 <input type="hidden" name="processContent" value="" />
75 <input type="hidden" name="returnUrl" value="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility
::getIndpEnv('REQUEST_URI')) . '" />
78 var plugin = window.parent.RTEarea["' . $this->editorNo
. '"].editor.getPlugin("UserElements");
79 var HTMLArea = window.parent.HTMLArea;
80 var editor = plugin.editor;
84 function insertHTML(content,noHide) {
85 plugin.restoreSelection();
86 editor.getSelection().insertHtml(content);
87 if(!noHide) plugin.close();
89 function wrapHTML(wrap1,wrap2,noHide) {
90 plugin.restoreSelection();
91 if(!editor.getSelection().isEmpty()) {
92 editor.getSelection().surroundHtml(wrap1,wrap2);
94 alert(' . GeneralUtility
::quoteJSvalue($GLOBALS['LANG']->getLL('noTextSelection')) . ');
96 if(!noHide) plugin.close();
98 function processSelection(script) {
99 plugin.restoreSelection();
100 document.process.action = script;
101 document.process.processContent.value = editor.getSelection().getHtml();
102 document.process.submit();
104 function jumpToUrl(URL) {
105 var RTEtsConfigParams = "&RTEtsConfigParams=' . rawurlencode(\TYPO3\CMS\Core\Utility\GeneralUtility
::_GP('RTEtsConfigParams')) . '";
106 var editorNo = "&editorNo=' . rawurlencode($this->editorNo
) . '";
107 theLocation = URL+RTEtsConfigParams+editorNo;
108 window.location.href = theLocation;
112 // unset the default jumpToUrl() function
113 unset($this->doc
->JScodeArray
['jumpToUrl']);
115 $this->doc
->JScode
= $this->doc
->wrapScriptTags($JScode);
116 $this->modData
= $GLOBALS['BE_USER']->getModuleData('user.php', 'ses');
117 if (\TYPO3\CMS\Core\Utility\GeneralUtility
::_GP('OC_key')) {
118 $parts = explode('|', \TYPO3\CMS\Core\Utility\GeneralUtility
::_GP('OC_key'));
119 $this->modData
['openKeys'][$parts[1]] = $parts[0] == 'O' ?
1 : 0;
120 $GLOBALS['BE_USER']->pushModuleData('user.php', $this->modData
);
125 * Injects the request object for the current request or subrequest
126 * As this controller goes only through the main_user() method, it is rather simple for now
128 * @param ServerRequestInterface $request the current request
129 * @param ResponseInterface $response the prepared response object
130 * @return ResponseInterface the response with the content
132 public function mainAction(ServerRequestInterface
$request, ResponseInterface
$response)
134 $content = $this->main_user($this->modData
['openKeys']);
135 $response->getBody()->write($content);
139 /********************************
143 *********************************/
145 * @param array $imgInfo
150 public function calcWH($imgInfo, $maxW = 380, $maxH = 500)
155 $IH = ceil($IH / $IW * $maxW);
159 $IW = ceil($IW / $IH * $maxH);
162 $imgInfo[3] = 'width="' . $IW . '" height="' . $IH . '"';
167 * Rich Text Editor (RTE) user element selector
169 * @param array $openKeys
172 public function main_user($openKeys)
175 $content = $this->doc
->startPage($GLOBALS['LANG']->getLL('Insert Custom Element', true));
176 $RTEtsConfigParts = explode(':', \TYPO3\CMS\Core\Utility\GeneralUtility
::_GP('RTEtsConfigParams'));
177 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', \TYPO3\CMS\Backend\Utility\BackendUtility
::getPagesTSconfig($RTEtsConfigParts[5]));
178 $thisConfig = \TYPO3\CMS\Backend\Utility\BackendUtility
::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
179 if (is_array($thisConfig['userElements.'])) {
180 $categories = array();
181 foreach ($thisConfig['userElements.'] as $k => $value) {
183 $v = $thisConfig['userElements.'][$ki . '.'];
184 if (substr($k, -1) == '.' && is_array($v)) {
187 if ($openKeys[$openK]) {
189 if ($v['load'] === 'images_from_folder') {
191 if ($v['path'] && @is_dir
((PATH_site
. $v['path']))) {
192 $files = \TYPO3\CMS\Core\Utility\GeneralUtility
::getFilesInDir(PATH_site
. $v['path'], 'gif,jpg,jpeg,png', 0, '');
193 if (is_array($files)) {
195 foreach ($files as $filename) {
196 $iInfo = @getimagesize
((PATH_site
. $v['path'] . $filename));
197 $iInfo = $this->calcWH($iInfo, 50, 100);
198 $ks = (string)(100 +
$c);
199 $mArray[$ks] = $filename;
200 $mArray[$ks . '.'] = array(
201 'content' => '<img src="' . $this->siteUrl
. $v['path'] . $filename . '" />',
202 '_icon' => '<img src="' . $this->siteUrl
. $v['path'] . $filename . '" ' . $iInfo[3] . ' />',
203 'description' => $GLOBALS['LANG']->getLL('filesize') . ': ' . str_replace(' ', ' ', \TYPO3\CMS\Core\Utility\GeneralUtility
::formatSize(@filesize
((PATH_site
. $v['path'] . $filename)))) . ', ' . $GLOBALS['LANG']->getLL('pixels', 1) . ': ' . $iInfo[0] . 'x' . $iInfo[1]
210 if (is_array($mArray)) {
212 \TYPO3\CMS\Core\Utility\ArrayUtility
::mergeRecursiveWithOverrule($mArray, $v);
218 foreach ($v as $k2 => $dummyValue) {
220 if (substr($k2, -1) == '.' && is_array($v[$k2i . '.'])) {
221 $title = trim($v[$k2i]);
223 $title = '[' . $GLOBALS['LANG']->getLL('noTitle', true) . ']';
225 $title = $GLOBALS['LANG']->sL($title, true);
227 $description = $GLOBALS['LANG']->sL($v[$k2i . '.']['description'], true) . '<br />';
228 if (!$v[$k2i . '.']['dontInsertSiteUrl']) {
229 $v[$k2i . '.']['content'] = str_replace('###_URL###', $this->siteUrl
, $v[$k2i . '.']['content']);
231 $logo = $v[$k2i . '.']['_icon'] ?
: '';
233 switch ((string)$v[$k2i . '.']['mode']) {
235 $wrap = explode('|', $v[$k2i . '.']['content']);
236 $onClickEvent = 'wrapHTML(' . GeneralUtility
::quoteJSvalue($wrap[0]) . ',' . GeneralUtility
::quoteJSvalue($wrap[1]) . ',false);';
239 $script = trim($v[$k2i . '.']['submitToScript']);
240 if (substr($script, 0, 4) != 'http') {
241 $script = $this->siteUrl
. $script;
244 $onClickEvent = 'processSelection(' . GeneralUtility
::quoteJSvalue($script) . ');';
250 $onClickEvent = 'insertHTML(' . GeneralUtility
::quoteJSvalue($v[$k2i . '.']['content']) . ');';
252 $A = array('<a href="#" onClick="' . $onClickEvent . 'return false;">', '</a>');
253 $subcats[$k2i] = '<tr>
255 <td class="bgColor4" valign="top">' . $A[0] . $logo . $A[1] . '</td>
256 <td class="bgColor4" valign="top">' . $A[0] . '<strong>' . $title . '</strong><br />' . $description . $A[1] . '</td>
262 $categories[$ki] = implode('', $subcats);
266 // Render menu of the items:
268 foreach ($categories as $k => $v) {
269 $title = trim($thisConfig['userElements.'][$k]);
272 $title = '[' . $GLOBALS['LANG']->getLL('noTitle', true) . ']';
274 $title = $GLOBALS['LANG']->sL($title, true);
277 $uriBuilder = GeneralUtility
::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder
::class);
278 $url = (string)$uriBuilder->buildUriFromRoute('rtehtmlarea_wizard_user_elements', array('OC_key' => ($openKeys[$openK] ?
'C|' : 'O|') . $openK));
280 $lines[] = '<tr><td colspan="3" class="bgColor5"><a href="#" title="' . $GLOBALS['LANG']->getLL('expand', true) . '" onClick="jumpToUrl(' . GeneralUtility
::quoteJSvalue($url) . ');return false;"><i class="fa fa-caret-square-o-' . ($openKeys[$openK] ?
'left' : 'right') . '" title="' . $GLOBALS['LANG']->getLL('expand', true) . '"></i><strong>' . $title . '</strong></a></td></tr>';
283 $content .= '<table border="0" cellpadding="1" cellspacing="1">' . implode('', $lines) . '</table>';
285 $content .= $this->doc
->endPage();