[TASK] Fix dummy parameter and return texts in phpDoc
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / Controller / UserElementsController.php
1 <?php
2 namespace TYPO3\CMS\Rtehtmlarea\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
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.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * User defined content for htmlArea RTE
22 *
23 * @author Kasper Skårhøj <kasper@typo3.com>
24 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
25 */
26 class UserElementsController {
27
28 /**
29 * @var string
30 */
31 public $content;
32
33 /**
34 * @var array
35 */
36 public $modData;
37
38 /**
39 * @var string
40 */
41 public $siteUrl;
42
43 /**
44 * document template object
45 *
46 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
47 */
48 public $doc;
49
50 /**
51 * @var string
52 */
53 public $editorNo;
54
55 /**
56 * Initialize language files
57 */
58 public function __construct() {
59 $GLOBALS['LANG']->includeLLFile('EXT:rtehtmlarea/mod5/locallang.xlf');
60 $GLOBALS['LANG']->includeLLFile('EXT:rtehtmlarea/htmlarea/locallang_dialogs.xlf');
61 }
62
63 /**
64 * @return void
65 */
66 public function init() {
67 $this->editorNo = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('editorNo');
68 $this->siteUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
69 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
70 $this->doc->backPath = $GLOBALS['BACK_PATH'];
71 $this->doc->bodyTagAdditions = 'onload="Init();"';
72 $this->doc->form = '
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')) . '" />
76 ';
77 $JScode = '
78 var plugin = window.parent.RTEarea["' . $this->editorNo . '"].editor.getPlugin("UserElements");
79 var HTMLArea = window.parent.HTMLArea;
80 var editor = plugin.editor;
81
82 function Init() {
83 };
84 function insertHTML(content,noHide) {
85 plugin.restoreSelection();
86 editor.getSelection().insertHtml(content);
87 if(!noHide) plugin.close();
88 };
89 function wrapHTML(wrap1,wrap2,noHide) {
90 plugin.restoreSelection();
91 if(!editor.getSelection().isEmpty()) {
92 editor.getSelection().surroundHtml(wrap1,wrap2);
93 } else {
94 alert(' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->getLL('noTextSelection')) . ');
95 }
96 if(!noHide) plugin.close();
97 };
98 function processSelection(script) {
99 plugin.restoreSelection();
100 document.process.action = script;
101 document.process.processContent.value = editor.getSelection().getHtml();
102 document.process.submit();
103 };
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;
109 }
110 ';
111
112 // unset the default jumpToUrl() function
113 unset($this->doc->JScodeArray['jumpToUrl']);
114
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);
121 }
122 }
123
124 /**
125 * Main function
126 *
127 * @return void
128 */
129 public function main() {
130 $this->content = '';
131 $this->content .= $this->main_user($this->modData['openKeys']);
132 }
133
134 /**
135 * Print content
136 *
137 * @return void
138 */
139 public function printContent() {
140 echo $this->content;
141 }
142
143 /********************************
144 *
145 * Other functions
146 *
147 *********************************/
148 /**
149 * @param array $imgInfo
150 * @param int $maxW
151 * @param int $maxH
152 * @return array
153 */
154 public function calcWH($imgInfo, $maxW = 380, $maxH = 500) {
155 $IW = $imgInfo[0];
156 $IH = $imgInfo[1];
157 if ($IW > $maxW) {
158 $IH = ceil($IH / $IW * $maxW);
159 $IW = $maxW;
160 }
161 if ($IH > $maxH) {
162 $IW = ceil($IW / $IH * $maxH);
163 $IH = $maxH;
164 }
165 $imgInfo[3] = 'width="' . $IW . '" height="' . $IH . '"';
166 return $imgInfo;
167 }
168
169 /**
170 * Rich Text Editor (RTE) user element selector
171 *
172 * @param array $openKeys
173 * @return string
174 */
175 public function main_user($openKeys) {
176 // Starting content:
177 $content = $this->doc->startPage($GLOBALS['LANG']->getLL('Insert Custom Element', TRUE));
178 $RTEtsConfigParts = explode(':', \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('RTEtsConfigParams'));
179 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
180 $thisConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
181 if (is_array($thisConfig['userElements.'])) {
182 $categories = array();
183 foreach ($thisConfig['userElements.'] as $k => $value) {
184 $ki = (int)$k;
185 $v = $thisConfig['userElements.'][$ki . '.'];
186 if (substr($k, -1) == '.' && is_array($v)) {
187 $subcats = array();
188 $openK = $ki;
189 if ($openKeys[$openK]) {
190 $mArray = '';
191 if ($v['load'] === 'images_from_folder') {
192 $mArray = array();
193 if ($v['path'] && @is_dir((PATH_site . $v['path']))) {
194 $files = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir(PATH_site . $v['path'], 'gif,jpg,jpeg,png', 0, '');
195 if (is_array($files)) {
196 $c = 0;
197 foreach ($files as $filename) {
198 $iInfo = @getimagesize((PATH_site . $v['path'] . $filename));
199 $iInfo = $this->calcWH($iInfo, 50, 100);
200 $ks = (string)(100 + $c);
201 $mArray[$ks] = $filename;
202 $mArray[$ks . '.'] = array(
203 'content' => '<img src="' . $this->siteUrl . $v['path'] . $filename . '" />',
204 '_icon' => '<img src="' . $this->siteUrl . $v['path'] . $filename . '" ' . $iInfo[3] . ' />',
205 'description' => $GLOBALS['LANG']->getLL('filesize') . ': ' . str_replace('&nbsp;', ' ', \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize(@filesize((PATH_site . $v['path'] . $filename)))) . ', ' . $GLOBALS['LANG']->getLL('pixels', 1) . ': ' . $iInfo[0] . 'x' . $iInfo[1]
206 );
207 $c++;
208 }
209 }
210 }
211 }
212 if (is_array($mArray)) {
213 if ($v['merge']) {
214 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($mArray, $v);
215 $v = $mArray;
216 } else {
217 $v = $mArray;
218 }
219 }
220 foreach ($v as $k2 => $dummyValue) {
221 $k2i = (int)$k2;
222 if (substr($k2, -1) == '.' && is_array($v[$k2i . '.'])) {
223 $title = trim($v[$k2i]);
224 if (!$title) {
225 $title = '[' . $GLOBALS['LANG']->getLL('noTitle', TRUE) . ']';
226 } else {
227 $title = $GLOBALS['LANG']->sL($title, TRUE);
228 }
229 $description = $GLOBALS['LANG']->sL($v[($k2i . '.')]['description'], TRUE) . '<br />';
230 if (!$v[($k2i . '.')]['dontInsertSiteUrl']) {
231 $v[$k2i . '.']['content'] = str_replace('###_URL###', $this->siteUrl, $v[$k2i . '.']['content']);
232 }
233 $logo = $v[$k2i . '.']['_icon'] ?: '';
234 $onClickEvent = '';
235 switch ((string)$v[($k2i . '.')]['mode']) {
236 case 'wrap':
237 $wrap = explode('|', $v[$k2i . '.']['content']);
238 $onClickEvent = 'wrapHTML(' . GeneralUtility::quoteJSvalue($wrap[0]) . ',' . GeneralUtility::quoteJSvalue($wrap[1]) . ',false);';
239 break;
240 case 'processor':
241 $script = trim($v[$k2i . '.']['submitToScript']);
242 if (substr($script, 0, 4) != 'http') {
243 $script = $this->siteUrl . $script;
244 }
245 if ($script) {
246 $onClickEvent = 'processSelection(' . GeneralUtility::quoteJSvalue($script) . ');';
247 }
248 break;
249 case 'insert':
250
251 default:
252 $onClickEvent = 'insertHTML(' . GeneralUtility::quoteJSvalue($v[($k2i . '.')]['content']) . ');';
253 }
254 $A = array('<a href="#" onClick="' . $onClickEvent . 'return false;">', '</a>');
255 $subcats[$k2i] = '<tr>
256 <td></td>
257 <td class="bgColor4" valign="top">' . $A[0] . $logo . $A[1] . '</td>
258 <td class="bgColor4" valign="top">' . $A[0] . '<strong>' . $title . '</strong><br />' . $description . $A[1] . '</td>
259 </tr>';
260 }
261 }
262 ksort($subcats);
263 }
264 $categories[$ki] = implode('', $subcats);
265 }
266 }
267 ksort($categories);
268 // Render menu of the items:
269 $lines = array();
270 foreach ($categories as $k => $v) {
271 $title = trim($thisConfig['userElements.'][$k]);
272 $openK = $k;
273 if (!$title) {
274 $title = '[' . $GLOBALS['LANG']->getLL('noTitle', TRUE) . ']';
275 } else {
276 $title = $GLOBALS['LANG']->sL($title, TRUE);
277 }
278 $lines[] = '<tr><td colspan="3" class="bgColor5"><a href="#" title="' . $GLOBALS['LANG']->getLL('expand', TRUE) . '" onClick="jumpToUrl(' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('rtehtmlarea_wizard_user', array('OC_key' => ($openKeys[$openK] ? 'C|' : 'O|') . $openK))) . ');return false;"><img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/ol/' . ($openKeys[$openK] ? 'minus' : 'plus') . 'bullet.gif'), 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('expand', TRUE) . '" /><strong>' . $title . '</strong></a></td></tr>';
279 $lines[] = $v;
280 }
281 $content .= '<table border="0" cellpadding="1" cellspacing="1">' . implode('', $lines) . '</table>';
282 }
283 $content .= $this->doc->endPage();
284 return $content;
285 }
286
287 }