[TASK] Replace BrowseLinks.js with jQuery/RequireJS Module
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Classes / Browser / ElementBrowser.php
1 <?php
2 namespace TYPO3\CMS\Recordlist\Browser;
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\Core\Resource\File;
18 use TYPO3\CMS\Core\Resource\Folder;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
21 use TYPO3\CMS\Backend\Utility\IconUtility;
22
23 /**
24 * class for the Element Browser window.
25 *
26 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
27 */
28 class ElementBrowser {
29
30 /**
31 * Optional instance of a record list that TBE_expandPage() should
32 * use to render the records in a page
33 *
34 * @var \TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList
35 */
36 protected $recordList = NULL;
37
38 /**
39 * Current site URL (Frontend)
40 *
41 * @var string
42 * @internal
43 */
44 public $siteURL;
45
46 /**
47 * the script to link to
48 *
49 * @var string
50 */
51 public $thisScript;
52
53 /**
54 * RTE specific TSconfig
55 *
56 * @var array
57 */
58 public $thisConfig;
59
60 /**
61 * Target (RTE specific)
62 *
63 * @var string
64 */
65 public $setTarget;
66
67 /**
68 * CSS Class (RTE specific)
69 *
70 * @var string
71 */
72 public $setClass;
73
74 /**
75 * title (RTE specific)
76 *
77 * @var string
78 */
79 public $setTitle;
80
81 /**
82 * @var string
83 */
84 public $setParams;
85
86 /**
87 * Backend template object
88 *
89 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
90 */
91 public $doc;
92
93 /**
94 * Holds information about files
95 *
96 * @var array
97 */
98 public $elements = array();
99
100 /**
101 * The mode determines the main kind of output from the element browser.
102 * There are these options for values: rte, db, file, filedrag, wizard.
103 * "rte" will show the link selector for the Rich Text Editor (see main_rte())
104 * "db" will allow you to browse for pages or records in the page tree (for TCEforms, see main_db())
105 * "file"/"filedrag" will allow you to browse for files or folders in the folder mounts (for TCEforms, main_file())
106 * "wizard" will allow you to browse for links (like "rte") which are passed back to TCEforms (see main_rte(1))
107 *
108 * @see main()
109 * @var string
110 */
111 public $mode;
112
113 /**
114 * Link selector action.
115 * page,file,url,mail,spec are allowed values.
116 * These are only important with the link selector function and in that case they switch
117 * between the various menu options.
118 *
119 * @var string
120 */
121 public $act;
122
123 /**
124 * When you click a page title/expand icon to see the content of a certain page, this
125 * value will contain that value (the ID of the expanded page). If the value is NOT set,
126 * then it will be restored from the module session data (see main(), mode="db")
127 *
128 * @var NULL|int
129 */
130 public $expandPage;
131
132 /**
133 * When you click a folder name/expand icon to see the content of a certain file folder,
134 * this value will contain that value (the path of the expanded file folder). If the
135 * value is NOT set, then it will be restored from the module session data (see main(),
136 * mode="file"/"filedrag"). Example value: "/www/htdocs/typo3/32/3dsplm/fileadmin/css/"
137 *
138 * @var string
139 */
140 public $expandFolder;
141
142 /**
143 * the folder object of a parent folder that was selected
144 *
145 * @var Folder
146 */
147 protected $selectedFolder;
148
149 /**
150 * TYPO3 Element Browser, wizard mode parameters. There is a heap of parameters there,
151 * better debug() them out if you need something... :-)
152 *
153 * @var array
154 */
155 public $P;
156
157 /**
158 * Active with TYPO3 Element Browser: Contains the name of the form field for which this window
159 * opens - thus allows us to make references back to the main window in which the form is.
160 * Example value: "data[pages][39][bodytext]|||tt_content|"
161 * or "data[tt_content][NEW3fba56fde763d][image]|||gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai|"
162 *
163 * Values:
164 * 0: form field name reference, eg. "data[tt_content][123][image]"
165 * 1: htmlArea RTE parameters: editorNo:contentTypo3Language:contentTypo3Charset
166 * 2: RTE config parameters: RTEtsConfigParams
167 * 3: allowed types. Eg. "tt_content" or "gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai"
168 * 4: IRRE uniqueness: target level object-id to perform actions/checks on, eg. "data[79][tt_address][1][<field>][<foreign_table>]"
169 * 5: IRRE uniqueness: name of function in opener window that checks if element is already used, eg. "inline.checkUniqueElement"
170 * 6: IRRE uniqueness: name of function in opener window that performs some additional(!) action, eg. "inline.setUniqueElement"
171 * 7: IRRE uniqueness: name of function in opener window that performs action instead of using addElement/insertElement, eg. "inline.importElement"
172 *
173 * $pArr = explode('|', $this->bparams);
174 * $formFieldName = $pArr[0];
175 * $allowedTablesOrFileTypes = $pArr[3];
176 *
177 * @var string
178 */
179 public $bparams;
180
181 /**
182 * Used with the Rich Text Editor.
183 * Example value: "tt_content:NEW3fba58c969f5c:bodytext:23:text:23:"
184 *
185 * @var string
186 */
187 public $RTEtsConfigParams;
188
189 /**
190 * Plus/Minus icon value. Used by the tree class to open/close notes on the trees.
191 *
192 * @var string
193 */
194 public $PM;
195
196 /**
197 * Pointer, used when browsing a long list of records etc.
198 *
199 * @var int
200 */
201 public $pointer;
202
203 /**
204 * Used with the link selector: Contains the GET input information about the CURRENT link
205 * in the RTE/TCEform field. This consists of "href", "target" and "title" keys.
206 * This information is passed around in links.
207 *
208 * @var array
209 */
210 public $curUrlArray;
211
212 /**
213 * Used with the link selector: Contains a processed version of the input values from curUrlInfo.
214 * This is splitted into pageid, content element id, label value etc.
215 * This is used for the internal processing of that information.
216 *
217 * @var array
218 */
219 public $curUrlInfo;
220
221 /**
222 * array which holds hook objects (initialised in init())
223 *
224 * @var \TYPO3\CMS\Core\ElementBrowser\ElementBrowserHookInterface[]
225 */
226 protected $hookObjects = array();
227
228 /**
229 * @var \TYPO3\CMS\Core\Utility\File\BasicFileUtility
230 */
231 public $fileProcessor;
232
233 /**
234 * Sets the script url depending on being a module or script request
235 */
236 protected function determineScriptUrl() {
237 if ($moduleName = GeneralUtility::_GP('M')) {
238 $this->thisScript = BackendUtility::getModuleUrl($moduleName);
239 } else {
240 $this->thisScript = GeneralUtility::getIndpEnv('SCRIPT_NAME');
241 }
242 }
243
244 /**
245 * Calculate path to this script.
246 * This method is public, to be used in hooks of this class only.
247 *
248 * @return string
249 */
250 public function getThisScript() {
251 return strpos($this->thisScript, '?') === FALSE ? $this->thisScript . '?' : $this->thisScript . '&';
252 }
253
254 /**
255 * Constructor:
256 * Initializes a lot of variables, setting JavaScript functions in header etc.
257 *
258 * @return void
259 * @throws \UnexpectedValueException
260 */
261 public function init() {
262 $this->initVariables();
263
264 $this->RTEtsConfigParams = GeneralUtility::_GP('RTEtsConfigParams');
265 $this->initConfiguration();
266 $this->initDocumentTemplate();
267 // init hook objects:
268 $this->initHookObjects('typo3/class.browse_links.php');
269
270 $this->initCurrentUrl();
271
272 // Determine nature of current url:
273 $this->act = GeneralUtility::_GP('act');
274 if (!$this->act) {
275 $this->act = $this->curUrlInfo['act'];
276 }
277
278 // Initializing the target value (RTE)
279 $this->setTarget = $this->curUrlArray['target'] != '-' ? $this->curUrlArray['target'] : '';
280 if ($this->thisConfig['defaultLinkTarget'] && !isset($this->curUrlArray['target'])) {
281 $this->setTarget = $this->thisConfig['defaultLinkTarget'];
282 }
283 // Initializing the class value (RTE)
284 $this->setClass = $this->curUrlArray['class'] != '-' ? $this->curUrlArray['class'] : '';
285 // Initializing the title value (RTE)
286 $this->setTitle = $this->curUrlArray['title'] != '-' ? $this->curUrlArray['title'] : '';
287 // Initializing the params value
288 $this->setParams = $this->curUrlArray['params'] != '-' ? $this->curUrlArray['params'] : '';
289
290 // Finally, add the accumulated JavaScript to the template object:
291 // also unset the default jumpToUrl() function before
292 unset($this->doc->JScodeArray['jumpToUrl']);
293 $this->doc->JScode .= $this->doc->wrapScriptTags($this->getJSCode());
294 }
295
296 /**
297 * Initialize class variables
298 *
299 * @return void
300 */
301 public function initVariables() {
302 // Main GPvars:
303 $this->pointer = GeneralUtility::_GP('pointer');
304 $this->bparams = GeneralUtility::_GP('bparams');
305 $this->P = GeneralUtility::_GP('P');
306 $this->expandPage = GeneralUtility::_GP('expandPage');
307 $this->expandFolder = GeneralUtility::_GP('expandFolder');
308 $this->PM = GeneralUtility::_GP('PM');
309
310 // Site URL
311 // Current site url
312 $this->siteURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
313 $this->determineScriptUrl();
314
315 // Find "mode"
316 $this->mode = GeneralUtility::_GP('mode');
317 if (!$this->mode) {
318 $this->mode = 'rte';
319 }
320
321 // Init fileProcessor
322 $this->fileProcessor = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Utility\File\BasicFileUtility::class);
323 $this->fileProcessor->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
324 }
325
326 /**
327 * Initializes the configuration variables
328 *
329 * @return void
330 */
331 public function initConfiguration() {
332 // Rich Text Editor specific configuration:
333 if ((string)$this->mode === 'rte') {
334 $this->thisConfig = $this->getRTEConfig();
335 }
336 }
337
338 /**
339 * Initialize document template object
340 *
341 * @return void
342 */
343 protected function initDocumentTemplate() {
344 // Creating backend template object:
345 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
346 $this->doc->bodyTagId = 'typo3-browse-links-php';
347 $this->doc->backPath = $GLOBALS['BACK_PATH'];
348 // Load the Prototype library and the tree
349 $this->doc->getPageRenderer()->loadPrototype();
350 $this->doc->loadJavascriptLib('js/tree.js');
351 $this->doc->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/BrowseLinks');
352 }
353
354 /**
355 * Initialize hook objects implementing the interface
356 *
357 * @param string $hookKey the hook key
358 * @throws \UnexpectedValueException
359 * @return void
360 */
361 protected function initHookObjects($hookKey) {
362 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookKey]['browseLinksHook'])) {
363 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookKey]['browseLinksHook'] as $classData) {
364 $processObject = GeneralUtility::getUserObj($classData);
365 if (!$processObject instanceof \TYPO3\CMS\Core\ElementBrowser\ElementBrowserHookInterface) {
366 throw new \UnexpectedValueException('$processObject must implement interface ' . \TYPO3\CMS\Core\ElementBrowser\ElementBrowserHookInterface::class, 1195039394);
367 }
368 $parameters = array();
369 $processObject->init($this, $parameters);
370 $this->hookObjects[] = $processObject;
371 }
372 }
373 }
374
375 /**
376 * Initialize $this->curUrlArray and $this->curUrlInfo based on script parameters
377 *
378 * @return void
379 */
380 protected function initCurrentUrl() {
381 // CurrentUrl - the current link url must be passed around if it exists
382 if ($this->mode == 'wizard') {
383 $currentValues = GeneralUtility::trimExplode(LF, trim($this->P['currentValue']));
384 if (count($currentValues) > 0) {
385 $currentValue = array_pop($currentValues);
386 } else {
387 $currentValue = '';
388 }
389 $currentLinkParts = GeneralUtility::unQuoteFilenames($currentValue, TRUE);
390 $initialCurUrlArray = array(
391 'href' => $currentLinkParts[0],
392 'target' => $currentLinkParts[1],
393 'class' => $currentLinkParts[2],
394 'title' => $currentLinkParts[3],
395 'params' => $currentLinkParts[4]
396 );
397 $this->curUrlArray = is_array(GeneralUtility::_GP('curUrl'))
398 ? array_merge($initialCurUrlArray, GeneralUtility::_GP('curUrl'))
399 : $initialCurUrlArray;
400 // Additional fields for page links
401 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendUrlArray'])
402 && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendUrlArray'])
403 ) {
404 $conf = array();
405 $_params = array(
406 'conf' => &$conf,
407 'linkParts' => $currentLinkParts
408 );
409 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendUrlArray'] as $objRef) {
410 $processor =& GeneralUtility::getUserObj($objRef);
411 $processor->extendUrlArray($_params, $this);
412 }
413 }
414 $this->curUrlInfo = $this->parseCurUrl($this->siteURL . '?id=' . $this->curUrlArray['href'], $this->siteURL);
415 // pageid == 0 means that this is not an internal (page) link
416 if ($this->curUrlInfo['pageid'] == 0 && $this->curUrlArray['href']) {
417 // Check if there is the FAL API
418 if (GeneralUtility::isFirstPartOfStr($this->curUrlArray['href'], 'file:')) {
419 $this->curUrlInfo = $this->parseCurUrl($this->curUrlArray['href'], $this->siteURL);
420 // Remove the "file:" prefix
421 $currentLinkParts[0] = rawurldecode(substr($this->curUrlArray['href'], 5));
422 } elseif (file_exists(PATH_site . rawurldecode($this->curUrlArray['href']))) {
423 if (GeneralUtility::isFirstPartOfStr($this->curUrlArray['href'], PATH_site)) {
424 $currentLinkParts[0] = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($this->curUrlArray['href']);
425 }
426 $this->curUrlInfo = $this->parseCurUrl($this->siteURL . $this->curUrlArray['href'], $this->siteURL);
427 } elseif (strstr($this->curUrlArray['href'], '@')) {
428 // check for email link
429 if (GeneralUtility::isFirstPartOfStr($this->curUrlArray['href'], 'mailto:')) {
430 $currentLinkParts[0] = substr($this->curUrlArray['href'], 7);
431 }
432 $this->curUrlInfo = $this->parseCurUrl('mailto:' . $this->curUrlArray['href'], $this->siteURL);
433 } else {
434 // nothing of the above. this is an external link
435 if (strpos($this->curUrlArray['href'], '://') === FALSE) {
436 $currentLinkParts[0] = 'http://' . $this->curUrlArray['href'];
437 }
438 $this->curUrlInfo = $this->parseCurUrl($currentLinkParts[0], $this->siteURL);
439 }
440 } elseif (!$this->curUrlArray['href']) {
441 $this->curUrlInfo = array();
442 $this->act = 'page';
443 } else {
444 $this->curUrlInfo = $this->parseCurUrl($this->siteURL . '?id=' . $this->curUrlArray['href'], $this->siteURL);
445 }
446 } else {
447 $this->curUrlArray = GeneralUtility::_GP('curUrl');
448 if ($this->curUrlArray['all']) {
449 $this->curUrlArray = GeneralUtility::get_tag_attributes($this->curUrlArray['all']);
450 }
451 $this->curUrlInfo = $this->parseCurUrl($this->curUrlArray['href'], $this->siteURL);
452 }
453 }
454
455 /**
456 * Get the RTE configuration from Page TSConfig
457 *
458 * @return array RTE configuration array
459 */
460 protected function getRTEConfig() {
461 $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
462 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
463 return BackendUtility::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
464 }
465
466 /**
467 * Generate JS code to be used on the link insert/modify dialogue
468 *
469 * @return string the generated JS code
470 */
471 public function getJsCode() {
472 // Rich Text Editor specific configuration:
473 $addPassOnParams = '';
474 if ((string)$this->mode == 'rte') {
475 $addPassOnParams .= '&RTEtsConfigParams=' . rawurlencode($this->RTEtsConfigParams);
476 }
477 // BEGIN accumulation of header JavaScript:
478 $JScode = '
479 // This JavaScript is primarily for RTE/Link. jumpToUrl is used in the other cases as well...
480 var add_href=' . GeneralUtility::quoteJSvalue($this->curUrlArray['href'] ? '&curUrl[href]=' . rawurlencode($this->curUrlArray['href']) : '') . ';
481 var add_target=' . GeneralUtility::quoteJSvalue($this->setTarget ? '&curUrl[target]=' . rawurlencode($this->setTarget) : '') . ';
482 var add_class=' . GeneralUtility::quoteJSvalue($this->setClass ? '&curUrl[class]=' . rawurlencode($this->setClass) : '') . ';
483 var add_title=' . GeneralUtility::quoteJSvalue($this->setTitle ? '&curUrl[title]=' . rawurlencode($this->setTitle) : '') . ';
484 var add_params=' . GeneralUtility::quoteJSvalue($this->bparams ? '&bparams=' . rawurlencode($this->bparams) : '') . ';
485
486 var cur_href=' . GeneralUtility::quoteJSvalue($this->curUrlArray['href'] ?: '') . ';
487 var cur_target=' . GeneralUtility::quoteJSvalue($this->setTarget ?: '') . ';
488 var cur_class=' . GeneralUtility::quoteJSvalue($this->setClass ?: '') . ';
489 var cur_title=' . GeneralUtility::quoteJSvalue($this->setTitle ?: '') . ';
490 var cur_params=' . GeneralUtility::quoteJSvalue($this->setParams ?: '') . ';
491
492 function browse_links_setTarget(target) { //
493 cur_target=target;
494 add_target="&curUrl[target]="+escape(target);
495 }
496 function browse_links_setClass(cssClass) { //
497 cur_class = cssClass;
498 add_class = "&curUrl[class]=" + escape(cssClass);
499 }
500 function browse_links_setTitle(title) { //
501 cur_title=title;
502 add_title="&curUrl[title]="+escape(title);
503 }
504 function browse_links_setValue(value) { //
505 cur_href=value;
506 add_href="&curUrl[href]="+value;
507 }
508 function browse_links_setParams(params) { //
509 cur_params=params;
510 add_params="&curUrl[params]="+escape(params);
511 }
512 ';
513 // Functions used, if the link selector is in wizard mode (= TCEforms fields)
514 if ($this->mode == 'wizard') {
515 if (!$this->areFieldChangeFunctionsValid() && !$this->areFieldChangeFunctionsValid(TRUE)) {
516 $this->P['fieldChangeFunc'] = array();
517 }
518 unset($this->P['fieldChangeFunc']['alert']);
519 $update = '';
520 foreach ($this->P['fieldChangeFunc'] as $v) {
521 $update .= '
522 window.opener.' . $v;
523 }
524 $P2 = array();
525 $P2['uid'] = $this->P['uid'];
526 $P2['pid'] = $this->P['pid'];
527 $P2['itemName'] = $this->P['itemName'];
528 $P2['formName'] = $this->P['formName'];
529 $P2['fieldChangeFunc'] = $this->P['fieldChangeFunc'];
530 $P2['fieldChangeFuncHash'] = GeneralUtility::hmac(serialize($this->P['fieldChangeFunc']));
531 $P2['params']['allowedExtensions'] = isset($this->P['params']['allowedExtensions']) ? $this->P['params']['allowedExtensions'] : '';
532 $P2['params']['blindLinkOptions'] = isset($this->P['params']['blindLinkOptions']) ? $this->P['params']['blindLinkOptions'] : '';
533 $P2['params']['blindLinkFields'] = isset($this->P['params']['blindLinkFields']) ? $this->P['params']['blindLinkFields']: '';
534 $addPassOnParams .= GeneralUtility::implodeArrayForUrl('P', $P2);
535 $JScode .= '
536 function link_typo3Page(id,anchor) { //
537 updateValueInMainForm(id + (anchor ? anchor : ""));
538 close();
539 return false;
540 }
541 function link_folder(folder) { //
542 updateValueInMainForm(folder);
543 close();
544 return false;
545 }
546 function link_current() { //
547 if (cur_href!="http://" && cur_href!="mailto:") {
548 returnBeforeCleaned = cur_href;
549 if (returnBeforeCleaned.substr(0, 7) == "http://") {
550 returnToMainFormValue = returnBeforeCleaned.substr(7);
551 } else if (returnBeforeCleaned.substr(0, 7) == "mailto:") {
552 if (returnBeforeCleaned.substr(0, 14) == "mailto:mailto:") {
553 returnToMainFormValue = returnBeforeCleaned.substr(14);
554 } else {
555 returnToMainFormValue = returnBeforeCleaned.substr(7);
556 }
557 } else {
558 returnToMainFormValue = returnBeforeCleaned;
559 }
560 updateValueInMainForm(returnToMainFormValue);
561 close();
562 }
563 return false;
564 }
565 function checkReference() { //
566 if (window.opener && window.opener.document && window.opener.document.' . $this->P['formName']
567 . ' && window.opener.document.' . $this->P['formName'] . '["' . $this->P['itemName'] . '"] ) {
568 return window.opener.document.' . $this->P['formName'] . '["' . $this->P['itemName'] . '"];
569 } else {
570 close();
571 }
572 }
573 function updateValueInMainForm(input) { //
574 var field = checkReference();
575 if (field) {
576 if (cur_target == "" && (cur_class != "" || cur_title != "" || cur_params != "")) {
577 cur_target = "-";
578 }
579 if (cur_class == "" && (cur_title != "" || cur_params != "")) {
580 cur_class = "-";
581 }
582 cur_class = cur_class.replace(/[\'\\"]/g, "");
583 if (cur_class.indexOf(" ") != -1) {
584 cur_class = "\\"" + cur_class + "\\"";
585 }
586 if (cur_title == "" && cur_params != "") {
587 cur_title = "-";
588 }
589 cur_title = cur_title.replace(/(^\\")|(\\"$)/g, "");
590 if (cur_title.indexOf(" ") != -1) {
591 cur_title = "\\"" + cur_title + "\\"";
592 }
593 if (cur_params) {
594 cur_params = cur_params.replace(/\\bid\\=.*?(\\&|$)/, "");
595 }
596 input = input + " " + cur_target + " " + cur_class + " " + cur_title + " " + cur_params;
597 if(field.value && field.className.search(/textarea/) != -1) {
598 field.value += "\\n" + input;
599 } else {
600 field.value = input;
601 }
602 ' . $update . '
603 }
604 }
605 ';
606 } else {
607 // Functions used, if the link selector is in RTE mode:
608 $JScode .= '
609 function link_typo3Page(id,anchor) { //
610 var theLink = \'' . $this->siteURL . '?id=\'+id+(anchor?anchor:"");
611 self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
612 return false;
613 }
614 function link_folder(folder) { //
615 var theLink = \'' . $this->siteURL . '\'+folder;
616 self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
617 return false;
618 }
619 function link_spec(theLink) { //
620 self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
621 return false;
622 }
623 function link_current() { //
624 if (cur_href!="http://" && cur_href!="mailto:") {
625 self.parent.parent.renderPopup_addLink(cur_href, cur_target, cur_class, cur_title);
626 }
627 return false;
628 }
629 ';
630 }
631 // General "jumpToUrl" function:
632 $JScode .= '
633 function jumpToUrl(URL,anchor) { //
634 if (URL.charAt(0) === \'?\') {
635 URL = ' . GeneralUtility::quoteJSvalue($this->getThisScript()) . ' + URL.substring(1);
636 }
637 var add_act = URL.indexOf("act=")==-1 ? "&act=' . $this->act . '" : "";
638 var add_mode = URL.indexOf("mode=")==-1 ? "&mode=' . $this->mode . '" : "";
639 var theLocation = URL + add_act + add_mode + add_href + add_target + add_class + add_title + add_params'
640 . ($addPassOnParams ? '+' . GeneralUtility::quoteJSvalue($addPassOnParams) : '')
641 . '+(typeof(anchor)=="string"?anchor:"");
642 window.location.href = theLocation;
643 return false;
644 }
645 ';
646 /**
647 * Splits parts of $this->bparams
648 *
649 * @see $bparams
650 */
651 $pArr = explode('|', $this->bparams);
652 // This is JavaScript especially for the TBE Element Browser!
653 $formFieldName = 'data[' . $pArr[0] . '][' . $pArr[1] . '][' . $pArr[2] . ']';
654 // insertElement - Call check function (e.g. for uniqueness handling):
655 $JScodeCheck = '';
656 if ($pArr[4] && $pArr[5]) {
657 $JScodeCheck = '
658 // Call a check function in the opener window (e.g. for uniqueness handling):
659 if (parent.window.opener) {
660 var res = parent.window.opener.' . $pArr[5] . '("' . addslashes($pArr[4]) . '",table,uid,type);
661 if (!res.passed) {
662 if (res.message) alert(res.message);
663 performAction = false;
664 }
665 } else {
666 alert("Error - reference to main window is not set properly!");
667 parent.close();
668 }
669 ';
670 }
671 // insertElement - Call helper function:
672 $JScodeHelper = '';
673 if ($pArr[4] && $pArr[6]) {
674 $JScodeHelper = '
675 // Call helper function to manage data in the opener window:
676 if (parent.window.opener) {
677 parent.window.opener.' . $pArr[6] . '("' . addslashes($pArr[4]) . '",table,uid,type,"' . addslashes($pArr[0]) . '");
678 } else {
679 alert("Error - reference to main window is not set properly!");
680 parent.close();
681 }
682 ';
683 }
684 // insertElement - perform action commands:
685 $JScodeActionMultiple = '';
686 if ($pArr[4] && $pArr[7]) {
687 // Call user defined action function:
688 $JScodeAction = '
689 if (parent.window.opener) {
690 parent.window.opener.' . $pArr[7] . '("' . addslashes($pArr[4]) . '",table,uid,type);
691 if (close) { focusOpenerAndClose(close); }
692 } else {
693 alert("Error - reference to main window is not set properly!");
694 if (close) { parent.close(); }
695 }
696 ';
697 $JScodeActionMultiple = '
698 // Call helper function to manage data in the opener window:
699 if (parent.window.opener) {
700 parent.window.opener.' . $pArr[7] . 'Multiple("' . addslashes($pArr[4]) . '",table,uid,type,"'
701 . addslashes($pArr[0]) . '");
702 } else {
703 alert("Error - reference to main window is not set properly!");
704 parent.close();
705 }
706 ';
707 } elseif ($pArr[0] && !$pArr[1] && !$pArr[2]) {
708 $JScodeAction = '
709 addElement(filename,table+"_"+uid,fp,close);
710 ';
711 } else {
712 $JScodeAction = '
713 if (setReferences()) {
714 parent.window.opener.group_change("add","' . $pArr[0] . '","' . $pArr[1] . '","' . $pArr[2]
715 . '",elRef,targetDoc);
716 } else {
717 alert("Error - reference to main window is not set properly!");
718 }
719 focusOpenerAndClose(close);
720 ';
721 }
722 $JScode .= '
723 var elRef="";
724 var targetDoc="";
725
726 function launchView(url) { //
727 var thePreviewWindow="";
728 thePreviewWindow = window.open("' . $GLOBALS['BACK_PATH'] . 'show_item.php?table="+url,"ShowItem",'
729 . '"height=300,width=410,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
730 if (thePreviewWindow && thePreviewWindow.focus) {
731 thePreviewWindow.focus();
732 }
733 }
734 function setReferences() { //
735 if (parent.window.opener && parent.window.opener.content && parent.window.opener.content.document.editform'
736 . '&& parent.window.opener.content.document.editform["' . $formFieldName . '"]) {
737 targetDoc = parent.window.opener.content.document;
738 elRef = targetDoc.editform["' . $formFieldName . '"];
739 return true;
740 } else {
741 return false;
742 }
743 }
744 function insertElement(table, uid, type, filename, fp, filetype, imagefile, action, close) { //
745 var performAction = true;
746 ' . $JScodeCheck . '
747 // Call performing function and finish this action:
748 if (performAction) {
749 ' . $JScodeHelper . $JScodeAction . '
750 }
751 return false;
752 }
753 function insertMultiple(table, uid) {
754 var type = "";
755 ' . $JScodeActionMultiple . '
756 return false;
757 }
758 function addElement(elName, elValue, altElValue, close) { //
759 if (parent.window.opener && parent.window.opener.setFormValueFromBrowseWin) {
760 parent.window.opener.setFormValueFromBrowseWin("' . $pArr[0] . '",altElValue?altElValue:elValue,elName);
761 focusOpenerAndClose(close);
762 } else {
763 alert("Error - reference to main window is not set properly!");
764 parent.close();
765 }
766 }
767 function focusOpenerAndClose(close) { //
768 BrowseLinks.focusOpenerAndClose(close);
769 }
770 ';
771 // extends JavaScript code
772 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendJScode'])
773 && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendJScode'])
774 ) {
775 $conf = array();
776 $update = '';
777 $_params = array(
778 'conf' => &$conf,
779 'wizardUpdate' => $update,
780 'addPassOnParams' => $addPassOnParams
781 );
782 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendJScode'] as $objRef) {
783 $processor =& GeneralUtility::getUserObj($objRef);
784 $JScode .= $processor->extendJScode($_params, $this);
785 }
786 }
787 return $JScode;
788 }
789
790 /**
791 * Session data for this class can be set from outside with this method.
792 * Call after init()
793 *
794 * @param array $data Session data array
795 * @return array Session data and boolean which indicates that data needs to be stored in session because it's changed
796 */
797 public function processSessionData($data) {
798 $store = FALSE;
799 switch ((string)$this->mode) {
800 case 'db':
801 if (isset($this->expandPage)) {
802 $data['expandPage'] = $this->expandPage;
803 $store = TRUE;
804 } else {
805 $this->expandPage = $data['expandPage'];
806 }
807 break;
808 case 'file':
809
810 case 'filedrag':
811
812 case 'folder':
813 if (isset($this->expandFolder)) {
814 $data['expandFolder'] = $this->expandFolder;
815 $store = TRUE;
816 } else {
817 $this->expandFolder = $data['expandFolder'];
818 }
819 break;
820 }
821 return array($data, $store);
822 }
823
824 /******************************************************************
825 *
826 * Main functions
827 *
828 ******************************************************************/
829 /**
830 * Rich Text Editor (RTE) link selector (MAIN function)
831 * Generates the link selector for the Rich Text Editor.
832 * Can also be used to select links for the TCEforms (see $wiz)
833 *
834 * @param bool $wiz If set, the "remove link" is not shown in the menu: Used for the "Select link" wizard which is used by the TCEforms
835 * @return string Modified content variable.
836 */
837 public function main_rte($wiz = FALSE) {
838 // Starting content:
839 $content = $this->doc->startPage('RTE link');
840
841 $allowedItems = $this->getAllowedItems('page,file,folder,url,mail,spec');
842
843 // Removing link fields if configured
844 $blindLinkFields = isset($this->thisConfig['blindLinkFields'])
845 ? GeneralUtility::trimExplode(',', $this->thisConfig['blindLinkFields'], TRUE)
846 : array();
847 $pBlindLinkFields = isset($this->P['params']['blindLinkFields'])
848 ? GeneralUtility::trimExplode(',', $this->P['params']['blindLinkFields'], TRUE)
849 : array();
850 $allowedFields = array_diff(array('target', 'title', 'class', 'params'), $blindLinkFields, $pBlindLinkFields);
851
852 $content .= $this->doc->getTabMenuRaw($this->buildMenuArray($wiz, $allowedItems));
853 // Adding the menu and header to the top of page:
854 $content .= $this->printCurrentUrl($this->curUrlInfo['info']) . '<br />';
855 // Depending on the current action we will create the actual module content for selecting a link:
856 switch ($this->act) {
857 case 'mail':
858 $content .= $this->getEmailSelectorHtml();
859 break;
860 case 'url':
861 $content .= $this->getExternalUrlSelectorHtml();
862 break;
863 case 'file':
864 case 'folder':
865 $content .= $this->getFileSelectorHtml();
866 break;
867 case 'spec':
868 $content .= $this->getUserLinkSelectorHtml();
869 break;
870 case 'page':
871 $content .= $this->getPageSelectorHtml();
872 break;
873 default:
874 // Call hook
875 foreach ($this->hookObjects as $hookObject) {
876 $content .= $hookObject->getTab($this->act);
877 }
878 }
879 if (in_array('params', $allowedFields, TRUE)) {
880 $content .= '
881 <!--
882 Selecting params for link:
883 -->
884 <form action="" name="lparamsform" id="lparamsform">
885 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkParams">
886 <tr>
887 <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('params', TRUE) . '</td>
888 <td><input type="text" name="lparams" class="typo3-link-input" onchange="'
889 . 'browse_links_setParams(this.value);" value="' . htmlspecialchars($this->setParams)
890 . '" /></td>
891 </tr>
892 </table>
893 </form>
894 ';
895 }
896 if (in_array('class', $allowedFields, TRUE)) {
897 $content .= '
898 <!--
899 Selecting class for link:
900 -->
901 <form action="" name="lclassform" id="lclassform">
902 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkClass">
903 <tr>
904 <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('class', TRUE) . '</td>
905 <td><input type="text" name="lclass" class="typo3-link-input" onchange="'
906 . 'browse_links_setClass(this.value);" value="' . htmlspecialchars($this->setClass)
907 . '" /></td>
908 </tr>
909 </table>
910 </form>
911 ';
912 }
913 if (in_array('title', $allowedFields, TRUE)) {
914 $content .= '
915 <!--
916 Selecting title for link:
917 -->
918 <form action="" name="ltitleform" id="ltitleform">
919 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTitle">
920 <tr>
921 <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('title', TRUE) . '</td>
922 <td><input type="text" name="ltitle" class="typo3-link-input" onchange="'
923 . 'browse_links_setTitle(this.value);" value="' . htmlspecialchars($this->setTitle)
924 . '" /></td>
925 </tr>
926 </table>
927 </form>
928 ';
929 }
930 // additional fields for page links
931 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['addFields_PageLink'])
932 && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['addFields_PageLink'])
933 ) {
934 $conf = array();
935 $_params = array(
936 'conf' => &$conf
937 );
938 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['addFields_PageLink'] as $objRef) {
939 $processor =& GeneralUtility::getUserObj($objRef);
940 $content .= $processor->addFields($_params, $this);
941 }
942 }
943 // Target:
944 if ($this->act != 'mail' && in_array('target', $allowedFields, TRUE)) {
945 $ltarget = '
946
947 <!--
948 Selecting target for link:
949 -->
950 <form action="" name="ltargetform" id="ltargetform">
951 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTarget">
952 <tr>
953 <td>' . $GLOBALS['LANG']->getLL('target', TRUE) . ':</td>
954 <td><input type="text" name="ltarget" onchange="browse_links_setTarget(this.value);" value="'
955 . htmlspecialchars($this->setTarget) . '"' . $this->doc->formWidth(10) . ' /></td>
956 <td>
957 <select name="ltarget_type" onchange="browse_links_setTarget('
958 . 'this.options[this.selectedIndex].value);document.ltargetform.ltarget.value='
959 . 'this.options[this.selectedIndex].value;this.selectedIndex=0;">
960 <option></option>
961 <option value="_top">' . $GLOBALS['LANG']->getLL('top', TRUE) . '</option>
962 <option value="_blank">' . $GLOBALS['LANG']->getLL('newWindow', TRUE) . '</option>
963 </select>
964 </td>
965 <td>';
966 if (($this->curUrlInfo['act'] == 'page' || $this->curUrlInfo['act'] == 'file' || $this->curUrlInfo['act'] == 'folder')
967 && $this->curUrlArray['href'] && $this->curUrlInfo['act'] == $this->act
968 ) {
969 $ltarget .= '
970 <input type="submit" value="' . $GLOBALS['LANG']->getLL('update', TRUE)
971 . '" onclick="return link_current();" />';
972 }
973 $selectJS = '
974 if (document.ltargetform.popup_width.options[document.ltargetform.popup_width.selectedIndex].value>0'
975 . ' && document.ltargetform.popup_height.options[document.ltargetform.popup_height.selectedIndex].value>0) {
976 document.ltargetform.ltarget.value = document.ltargetform.popup_width.options['
977 . 'document.ltargetform.popup_width.selectedIndex].value+"x"'
978 . '+document.ltargetformbrowse_links_setTarget.popup_height.options['
979 . 'document.ltargetform.popup_height.selectedIndex].value;
980 browse_links_setTarget(document.ltargetform.ltarget.value);
981 browse_links_setClass(document.lclassform.lclass.value);
982 browse_links_setTitle(document.ltitleform.ltitle.value);
983 browse_links_setParams(document.lparamsform.lparams.value);
984 document.ltargetform.popup_width.selectedIndex=0;
985 document.ltargetform.popup_height.selectedIndex=0;
986 }
987 ';
988 $ltarget .= ' </td>
989 </tr>
990 <tr>
991 <td>' . $GLOBALS['LANG']->getLL('target_popUpWindow', TRUE) . ':</td>
992 <td colspan="3">
993 <select name="popup_width" onchange="' . htmlspecialchars($selectJS) . '">
994 <option value="0">' . $GLOBALS['LANG']->getLL('target_popUpWindow_width', TRUE) . '</option>
995 <option value="300">300</option>
996 <option value="400">400</option>
997 <option value="500">500</option>
998 <option value="600">600</option>
999 <option value="700">700</option>
1000 <option value="800">800</option>
1001 </select>
1002 x
1003 <select name="popup_height" onchange="' . htmlspecialchars($selectJS) . '">
1004 <option value="0">' . $GLOBALS['LANG']->getLL('target_popUpWindow_height', TRUE) . '</option>
1005 <option value="200">200</option>
1006 <option value="300">300</option>
1007 <option value="400">400</option>
1008 <option value="500">500</option>
1009 <option value="600">600</option>
1010 </select>
1011 </td>
1012 </tr>
1013 </table>
1014 </form>';
1015 // Add "target selector" box to content:
1016 $content .= $ltarget;
1017 // Add some space
1018 $content .= '<br /><br />';
1019 }
1020 // End page, return content:
1021 $content .= $this->doc->endPage();
1022 $content = $this->doc->insertStylesAndJS($content);
1023 return $content;
1024 }
1025
1026 /**
1027 * Get the allowed items or tabs
1028 *
1029 * @param string $items: initial list of possible items
1030 * @return array the allowed items
1031 */
1032 public function getAllowedItems($items) {
1033 // Initializing the action value, possibly removing blinded values etc:
1034 $blindLinkOptions = isset($this->thisConfig['blindLinkOptions'])
1035 ? GeneralUtility::trimExplode(',', $this->thisConfig['blindLinkOptions'], TRUE)
1036 : array();
1037 $pBlindLinkOptions = isset($this->P['params']['blindLinkOptions'])
1038 ? GeneralUtility::trimExplode(',', $this->P['params']['blindLinkOptions'])
1039 : array();
1040 $allowedItems = array_diff(explode(',', $items), $blindLinkOptions, $pBlindLinkOptions);
1041
1042 // Call hook for extra options
1043 foreach ($this->hookObjects as $hookObject) {
1044 $allowedItems = $hookObject->addAllowedItems($allowedItems);
1045 }
1046 return $allowedItems;
1047 }
1048
1049 /**
1050 * Returns an array definition of the top menu
1051 *
1052 * @param $wiz
1053 * @param $allowedItems
1054 * @return array
1055 */
1056 protected function buildMenuArray($wiz, $allowedItems) {
1057 // Making menu in top:
1058 $menuDef = array();
1059 if (!$wiz) {
1060 $menuDef['removeLink']['isActive'] = $this->act === 'removeLink';
1061 $menuDef['removeLink']['label'] = $GLOBALS['LANG']->getLL('removeLink', TRUE);
1062 $menuDef['removeLink']['url'] = '#';
1063 $menuDef['removeLink']['addParams'] = 'onclick="self.parent.parent.renderPopup_unLink();return false;"';
1064 }
1065 if (in_array('page', $allowedItems)) {
1066 $menuDef['page']['isActive'] = $this->act === 'page';
1067 $menuDef['page']['label'] = $GLOBALS['LANG']->getLL('page', TRUE);
1068 $menuDef['page']['url'] = '#';
1069 $menuDef['page']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=page') . ');return false;"';
1070 }
1071 if (in_array('file', $allowedItems)) {
1072 $menuDef['file']['isActive'] = $this->act === 'file';
1073 $menuDef['file']['label'] = $GLOBALS['LANG']->getLL('file', TRUE);
1074 $menuDef['file']['url'] = '#';
1075 $menuDef['file']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=file') . ');return false;"';
1076 }
1077 if (in_array('folder', $allowedItems)) {
1078 $menuDef['folder']['isActive'] = $this->act === 'folder';
1079 $menuDef['folder']['label'] = $GLOBALS['LANG']->getLL('folder', TRUE);
1080 $menuDef['folder']['url'] = '#';
1081 $menuDef['folder']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=folder') . ');return false;"';
1082 }
1083 if (in_array('url', $allowedItems)) {
1084 $menuDef['url']['isActive'] = $this->act === 'url';
1085 $menuDef['url']['label'] = $GLOBALS['LANG']->getLL('extUrl', TRUE);
1086 $menuDef['url']['url'] = '#';
1087 $menuDef['url']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=url') . ');return false;"';
1088 }
1089 if (in_array('mail', $allowedItems)) {
1090 $menuDef['mail']['isActive'] = $this->act === 'mail';
1091 $menuDef['mail']['label'] = $GLOBALS['LANG']->getLL('email', TRUE);
1092 $menuDef['mail']['url'] = '#';
1093 $menuDef['mail']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=mail') . ');return false;"';
1094 }
1095 if (is_array($this->thisConfig['userLinks.']) && in_array('spec', $allowedItems)) {
1096 $menuDef['spec']['isActive'] = $this->act === 'spec';
1097 $menuDef['spec']['label'] = $GLOBALS['LANG']->getLL('special', TRUE);
1098 $menuDef['spec']['url'] = '#';
1099 $menuDef['spec']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=spec') . ');return false;"';
1100 }
1101 // Call hook for extra options
1102 foreach ($this->hookObjects as $hookObject) {
1103 $menuDef = $hookObject->modifyMenuDefinition($menuDef);
1104 }
1105 return $menuDef;
1106 }
1107
1108 /**
1109 * Returns HTML of the email link from
1110 *
1111 * @return string
1112 */
1113 protected function getEmailSelectorHtml() {
1114 $extUrl = '
1115
1116 <!--
1117 Enter mail address:
1118 -->
1119 <form action="" name="lurlform" id="lurlform">
1120 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkMail">
1121 <tr>
1122 <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('emailAddress', TRUE) . ':</td>
1123 <td><input type="text" name="lemail"' . $this->doc->formWidth(20) . ' value="'
1124 . htmlspecialchars(($this->curUrlInfo['act'] === 'mail' ? $this->curUrlInfo['info'] : ''))
1125 . '" /> ' . '<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink', TRUE)
1126 . '" onclick="browse_links_setTarget(\'\');browse_links_setValue(\'mailto:\'+'
1127 . 'document.lurlform.lemail.value); return link_current();" /></td>
1128 </tr>
1129 </table>
1130 </form>';
1131 return $extUrl;
1132 }
1133
1134 /**
1135 * Returns HTML of the external url link from
1136 *
1137 * @return string
1138 */
1139 protected function getExternalUrlSelectorHtml() {
1140 $extUrl = '
1141
1142 <!--
1143 Enter External URL:
1144 -->
1145 <form action="" name="lurlform" id="lurlform">
1146 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkURL">
1147 <tr>
1148 <td style="width: 96px;">URL:</td>
1149 <td><input type="text" name="lurl"' . $this->doc->formWidth(30) . ' value="'
1150 . htmlspecialchars(($this->curUrlInfo['act'] === 'url' ? $this->curUrlInfo['info'] : 'http://'))
1151 . '" /> ' . '<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink', TRUE)
1152 . '" onclick="browse_links_setValue(document.lurlform.lurl.value); return link_current();" /></td>
1153 </tr>
1154 </table>
1155 </form>';
1156 return $extUrl;
1157 }
1158
1159 /**
1160 * Returns HTML of the file/folder link selector
1161 *
1162 * @param string $treeClassName
1163 * @return string
1164 */
1165 protected function getFileSelectorHtml($treeClassName = 'localFolderTree') {
1166 $folderTree = GeneralUtility::makeInstance($treeClassName);
1167 $folderTree->thisScript = $this->thisScript;
1168 $tree = $folderTree->getBrowsableTree();
1169 if (!$this->curUrlInfo['value'] || $this->curUrlInfo['act'] != $this->act) {
1170 $cmpPath = '';
1171 } else {
1172 $cmpPath = $this->curUrlInfo['value'];
1173 if (!isset($this->expandFolder)) {
1174 $this->expandFolder = $cmpPath;
1175 }
1176 }
1177 // Create upload/create folder forms, if a path is given
1178 $selectedFolder = FALSE;
1179 if ($this->expandFolder) {
1180 $fileOrFolderObject = NULL;
1181 try {
1182 $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
1183 } catch (\Exception $e) {
1184 // No path is selected
1185 }
1186
1187 if ($fileOrFolderObject instanceof Folder) {
1188 // It's a folder
1189 $selectedFolder = $fileOrFolderObject;
1190 } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
1191 // It's a file
1192 $selectedFolder = $fileOrFolderObject->getParentFolder();
1193 }
1194 }
1195 // If no folder is selected, get the user's default upload folder
1196 if (!$selectedFolder) {
1197 try {
1198 $selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
1199 } catch (\Exception $e) {
1200 // The configured default user folder does not exist
1201 }
1202 }
1203 // Build the file upload and folder creation form
1204 $uploadForm = '';
1205 $createFolder = '';
1206 $content = '';
1207 if ($selectedFolder) {
1208 $uploadForm = ($this->act === 'file') ? $this->uploadForm($selectedFolder) : '';
1209 $createFolder = $this->createFolder($selectedFolder);
1210 }
1211 // Insert the upload form on top, if so configured
1212 if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
1213 $content .= $uploadForm;
1214 }
1215
1216 // Render the filelist if there is a folder selected
1217 $files = '';
1218 if ($selectedFolder) {
1219 $allowedExtensions = isset($this->P['params']['allowedExtensions']) ? $this->P['params']['allowedExtensions'] : '';
1220 $files = $this->expandFolder($selectedFolder, $allowedExtensions);
1221 }
1222 // Create folder tree:
1223 $this->doc->JScode .= $this->doc->wrapScriptTags('
1224 Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
1225 ');
1226 $content .= '
1227 <!--
1228 Wrapper table for folder tree / file/folder list:
1229 -->
1230 <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkFiles">
1231 <tr>
1232 <td class="c-wCell" valign="top">'
1233 . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':')) . $tree . '</td>
1234 <td class="c-wCell" valign="top">' . $files . '</td>
1235 </tr>
1236 </table>
1237 ';
1238 // Adding create folder + upload form if applicable
1239 if (!$GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
1240 $content .= $uploadForm;
1241 }
1242 $content .= '<br />' . $createFolder . '<br />';
1243 return $content;
1244 }
1245
1246 /**
1247 * Returns HTML of the user defined link selector
1248 *
1249 * @return string
1250 */
1251 protected function getUserLinkSelectorHtml() {
1252 if (!is_array($this->thisConfig['userLinks.'])) {
1253 return '';
1254 }
1255 $subcats = array();
1256 $v = $this->thisConfig['userLinks.'];
1257 foreach ($v as $k2 => $value) {
1258 $k2i = (int)$k2;
1259 if (substr($k2, -1) === '.' && is_array($v[$k2i . '.'])) {
1260 // Title:
1261 $title = trim($v[$k2i]);
1262 if (!$title) {
1263 $title = $v[$k2i . '.']['url'];
1264 } else {
1265 $title = $GLOBALS['LANG']->sL($title);
1266 }
1267 // Description:
1268 $description = $v[$k2i . '.']['description']
1269 ? $GLOBALS['LANG']->sL($v[($k2i . '.')]['description'], TRUE) . '<br />'
1270 : '';
1271 // URL + onclick event:
1272 $onClickEvent = '';
1273 if (isset($v[$k2i . '.']['target'])) {
1274 $onClickEvent .= 'browse_links_setTarget(' . GeneralUtility::quoteJSvalue($v[($k2i . '.')]['target']) . ');';
1275 }
1276 $v[$k2i . '.']['url'] = str_replace('###_URL###', $this->siteURL, $v[$k2i . '.']['url']);
1277 if (substr($v[$k2i . '.']['url'], 0, 7) === 'http://' || substr($v[$k2i . '.']['url'], 0, 7) === 'mailto:') {
1278 $onClickEvent .= 'cur_href=' . GeneralUtility::quoteJSvalue($v[($k2i . '.')]['url']) . ';link_current();';
1279 } else {
1280 $onClickEvent .= 'link_spec(' . GeneralUtility::quoteJSvalue($this->siteURL . $v[($k2i . '.')]['url']) . ');';
1281 }
1282 // Link:
1283 $A = array('<a href="#" onclick="' . htmlspecialchars($onClickEvent) . 'return false;">', '</a>');
1284 // Adding link to menu of user defined links:
1285 $subcats[$k2i] = '
1286 <tr>
1287 <td class="bgColor4">' . $A[0] . '<strong>' . htmlspecialchars($title)
1288 . ($this->curUrlInfo['info'] == $v[$k2i . '.']['url']
1289 ? '<img' . IconUtility::skinImg(
1290 $GLOBALS['BACK_PATH'],
1291 'gfx/blinkarrow_right.gif',
1292 'width="5" height="9"'
1293 ) . ' class="c-blinkArrowR" alt="" />'
1294 : '')
1295 . '</strong><br />' . $description . $A[1] . '</td>
1296 </tr>';
1297 }
1298 }
1299 // Sort by keys:
1300 ksort($subcats);
1301 // Add menu to content:
1302 $content = '
1303
1304 <!--
1305 Special userdefined menu:
1306 -->
1307 <table border="0" cellpadding="1" cellspacing="1" id="typo3-linkSpecial">
1308 <tr>
1309 <td class="bgColor5" class="c-wCell" valign="top"><strong>'
1310 . $GLOBALS['LANG']->getLL('special', TRUE) . '</strong></td>
1311 </tr>
1312 ' . implode('', $subcats) . '
1313 </table>
1314 ';
1315 return $content;
1316 }
1317
1318 /**
1319 * Returns HTML of the page link selector
1320 *
1321 * @param string $treeClassName name of the class used for page tree rendering
1322 * @return string
1323 */
1324 protected function getPageSelectorHtml($treeClassName = 'localPageTree') {
1325 $pageTree = GeneralUtility::makeInstance($treeClassName);
1326 $pageTree->thisScript = $this->thisScript;
1327 $pageTree->ext_showPageId = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
1328 $pageTree->ext_showNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
1329 $pageTree->addField('nav_title');
1330 $tree = $pageTree->getBrowsableTree();
1331 $cElements = $this->expandPage();
1332 $dbmount = $this->getTemporaryTreeMountCancelNotice();
1333 $content = '
1334
1335 <!--
1336 Wrapper table for page tree / record list:
1337 -->
1338 <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkPages">
1339 <tr>
1340 <td class="c-wCell" valign="top">'
1341 . $this->barheader(($GLOBALS['LANG']->getLL('pageTree') . ':'))
1342 . $dbmount
1343 . $tree . '</td>
1344 <td class="c-wCell" valign="top">' . $cElements . '</td>
1345 </tr>
1346 </table>
1347 ';
1348 return $content;
1349 }
1350
1351 /**
1352 * TYPO3 Element Browser: Showing a page tree and allows you to browse for records
1353 *
1354 * @return string HTML content for the module
1355 */
1356 public function main_db() {
1357 // Starting content:
1358 $content = $this->doc->startPage('TBE record selector');
1359 // Init variable:
1360 $pArr = explode('|', $this->bparams);
1361 $tables = $pArr[3];
1362
1363 // Making the browsable pagetree:
1364 /** @var \TBE_PageTree $pageTree */
1365 $pageTree = GeneralUtility::makeInstance(\TBE_PageTree::class);
1366 $pageTree->thisScript = $this->thisScript;
1367 $pageTree->ext_pArrPages = $tables === 'pages' ? 1 : 0;
1368 $pageTree->ext_showNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
1369 $pageTree->ext_showPageId = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
1370 $pageTree->addField('nav_title');
1371
1372 $withTree = TRUE;
1373 if (($tables !== '') && ($tables !== '*')) {
1374 $tablesArr = GeneralUtility::trimExplode(',', $tables, TRUE);
1375 $onlyRootLevel = TRUE;
1376 foreach ($tablesArr as $currentTable) {
1377 $tableTca = $GLOBALS['TCA'][$currentTable];
1378 if (isset($tableTca)) {
1379 if (!isset($tableTca['ctrl']['rootLevel']) || ((int)$tableTca['ctrl']['rootLevel']) != 1) {
1380 $onlyRootLevel = FALSE;
1381 }
1382 }
1383 }
1384 if ($onlyRootLevel) {
1385 $withTree = FALSE;
1386 // page to work on will be root
1387 $this->expandPage = 0;
1388 }
1389 }
1390
1391 $tree = $pageTree->getBrowsableTree();
1392 // Making the list of elements, if applicable:
1393 $cElements = $this->TBE_expandPage($tables);
1394 // Putting the things together, side by side:
1395 $content .= '
1396
1397 <!--
1398 Wrapper table for page tree / record list:
1399 -->
1400 <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBrecords">
1401 <tr>';
1402 if ($withTree) {
1403 $content .= '<td class="c-wCell" valign="top">'
1404 . $this->barheader(($GLOBALS['LANG']->getLL('pageTree') . ':'))
1405 . $this->getTemporaryTreeMountCancelNotice()
1406 . $tree . '</td>';
1407 }
1408 $content .= '<td class="c-wCell" valign="top">' . $cElements . '</td>
1409 </tr>
1410 </table>
1411 ';
1412 // Add some space
1413 $content .= '<br /><br />';
1414 // End page, return content:
1415 $content .= $this->doc->endPage();
1416 $content = $this->doc->insertStylesAndJS($content);
1417 return $content;
1418 }
1419
1420 /**
1421 * TYPO3 Element Browser: Showing a folder tree, allowing you to browse for files.
1422 *
1423 * @return string HTML content for the module
1424 */
1425 public function main_file() {
1426 // include JS files and set prefs for foldertree
1427 $this->doc->getDragDropCode('folders');
1428 $this->doc->JScode .= $this->doc->wrapScriptTags('
1429 Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
1430 ');
1431 // Starting content:
1432 $content = $this->doc->startPage('TBE file selector');
1433 // Init variable:
1434 $pArr = explode('|', $this->bparams);
1435 // The key number 3 of the pArr contains the "allowed" string. Disallowed is not passed to
1436 // the element browser at all but only filtered out in TCEMain afterwards
1437 $allowed = $pArr[3];
1438 if ($allowed !== 'sys_file') {
1439 $allowedFileExtensions = $allowed;
1440 }
1441
1442 if (isset($allowedFileExtensions)) {
1443 // Create new filter object
1444 $filterObject = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter::class);
1445 $filterObject->setAllowedFileExtensions($allowedFileExtensions);
1446 // Set file extension filters on all storages
1447 $storages = $GLOBALS['BE_USER']->getFileStorages();
1448 /** @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */
1449 foreach ($storages as $storage) {
1450 $storage->addFileAndFolderNameFilter(array($filterObject, 'filterFileList'));
1451 }
1452 }
1453 // Create upload/create folder forms, if a path is given
1454 $this->selectedFolder = FALSE;
1455 if ($this->expandFolder) {
1456 $fileOrFolderObject = NULL;
1457
1458 // Try to fetch the folder the user had open the last time he browsed files
1459 // Fallback to the default folder in case the last used folder is not existing
1460 try {
1461 $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
1462 } catch (\TYPO3\CMS\Core\Resource\Exception $accessException) {
1463 // We're just catching the exception here, nothing to be done if folder does not exist or is not accessible.
1464 }
1465
1466 if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
1467 // It's a folder
1468 $this->selectedFolder = $fileOrFolderObject;
1469 } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
1470 // It's a file
1471 $this->selectedFolder = $fileOrFolderObject->getParentFolder();
1472 }
1473 }
1474 // Or get the user's default upload folder
1475 if (!$this->selectedFolder) {
1476 try {
1477 $this->selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
1478 } catch (\Exception $e) {
1479 // The configured default user folder does not exist
1480 }
1481 }
1482 // Build the file upload and folder creation form
1483 $uploadForm = '';
1484 $createFolder = '';
1485 if ($this->selectedFolder) {
1486 $uploadForm = $this->uploadForm($this->selectedFolder);
1487 $createFolder = $this->createFolder($this->selectedFolder);
1488 }
1489 // Insert the upload form on top, if so configured
1490 if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
1491 $content .= $uploadForm;
1492 }
1493 // Getting flag for showing/not showing thumbnails:
1494 $noThumbs = $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInEB');
1495 $_MOD_SETTINGS = array();
1496 if (!$noThumbs) {
1497 // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
1498 $_MOD_MENU = array('displayThumbs' => '');
1499 $_MCONF['name'] = 'file_list';
1500 $_MOD_SETTINGS = BackendUtility::getModuleData($_MOD_MENU, GeneralUtility::_GP('SET'), $_MCONF['name']);
1501 }
1502 $noThumbs = $noThumbs ?: !$_MOD_SETTINGS['displayThumbs'];
1503 // Create folder tree:
1504 $folderTree = GeneralUtility::makeInstance(\TBE_FolderTree::class);
1505 $folderTree->thisScript = $this->thisScript;
1506 $folderTree->ext_noTempRecyclerDirs = $this->mode == 'filedrag';
1507 $tree = $folderTree->getBrowsableTree();
1508 list(, , $specUid) = explode('_', $this->PM);
1509 if ($this->selectedFolder) {
1510 if ($this->mode == 'filedrag') {
1511 $files = $this->TBE_dragNDrop($this->selectedFolder, $pArr[3]);
1512 } else {
1513 $files = $this->TBE_expandFolder($this->selectedFolder, $pArr[3], $noThumbs);
1514 }
1515 } else {
1516 $files = '';
1517 }
1518 // Add the FlashMessages if any
1519 $content .= $this->doc->getFlashMessages();
1520
1521 // Putting the parts together, side by side:
1522 $content .= '
1523
1524 <!--
1525 Wrapper table for folder tree / file list:
1526 -->
1527 <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBfiles">
1528 <tr>
1529 <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':'))
1530 . $tree . '</td>
1531 <td class="c-wCell" valign="top">' . $files . '</td>
1532 </tr>
1533 </table>
1534 ';
1535 // Adding create folder + upload forms if applicable:
1536 if (!$GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
1537 $content .= $uploadForm;
1538 }
1539 $content .= $createFolder;
1540 // Add some space
1541 $content .= '<br /><br />';
1542 // Setup indexed elements:
1543 $this->doc->JScode .= $this->doc->wrapScriptTags('
1544 require(["TYPO3/CMS/Backend/BrowseLinks"], function(BrowseLinks) {
1545 BrowseLinks.addElements(' . json_encode($this->elements) . ');
1546 });');
1547 // Ending page, returning content:
1548 $content .= $this->doc->endPage();
1549 $content = $this->doc->insertStylesAndJS($content);
1550 return $content;
1551 }
1552
1553 /**
1554 * TYPO3 Element Browser: Showing a folder tree, allowing you to browse for folders.
1555 *
1556 * @return string HTML content for the module
1557 */
1558 public function main_folder() {
1559 // include JS files
1560 $this->doc->getDragDropCode('folders');
1561 // Setting prefs for foldertree
1562 $this->doc->JScode .= $this->doc->wrapScriptTags('
1563 Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
1564 ');
1565 // Starting content:
1566 $content = $this->doc->startPage('TBE folder selector');
1567 // Init variable:
1568 $parameters = explode('|', $this->bparams);
1569 if ($this->expandFolder) {
1570 $this->selectedFolder = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($this->expandFolder);
1571 }
1572 if ($this->selectedFolder) {
1573 $createFolder = $this->createFolder($this->selectedFolder);
1574 } else {
1575 $createFolder = '';
1576 }
1577 // Create folder tree:
1578 $folderTree = GeneralUtility::makeInstance(\TBE_FolderTree::class);
1579 $folderTree->thisScript = $this->thisScript;
1580 $folderTree->ext_noTempRecyclerDirs = $this->mode == 'filedrag';
1581 $tree = $folderTree->getBrowsableTree(FALSE);
1582 list(, , $specUid) = explode('_', $this->PM);
1583 if ($this->mode == 'filedrag') {
1584 $folders = $this->TBE_dragNDrop($this->selectedFolder, $parameters[3]);
1585 } else {
1586 $folders = $this->TBE_expandSubFolders($this->selectedFolder);
1587 }
1588 // Putting the parts together, side by side:
1589 $content .= '
1590
1591 <!--
1592 Wrapper table for folder tree / folder list:
1593 -->
1594 <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBfiles">
1595 <tr>
1596 <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':'))
1597 . $tree . '</td>
1598 <td class="c-wCell" valign="top">' . $folders . '</td>
1599 </tr>
1600 </table>
1601 ';
1602 // Adding create folder if applicable:
1603 $content .= $createFolder;
1604 // Add some space
1605 $content .= '<br /><br />';
1606 // Ending page, returning content:
1607 $content .= $this->doc->endPage();
1608 $content = $this->doc->insertStylesAndJS($content);
1609 return $content;
1610 }
1611
1612 /******************************************************************
1613 *
1614 * Record listing
1615 *
1616 ******************************************************************/
1617 /**
1618 * For RTE: This displays all content elements on a page and lets you create a link to the element.
1619 *
1620 * @return string HTML output. Returns content only if the ->expandPage value is set (pointing to a page uid to show tt_content records from ...)
1621 */
1622 public function expandPage() {
1623 $out = '';
1624 // Set page id (if any) to expand
1625 $expPageId = $this->expandPage;
1626 // If there is an anchor value (content element reference) in the element reference, then force an ID to expand:
1627 if (!$this->expandPage && $this->curUrlInfo['cElement']) {
1628 // Set to the current link page id.
1629 $expPageId = $this->curUrlInfo['pageid'];
1630 }
1631 // Draw the record list IF there is a page id to expand:
1632 if ($expPageId
1633 && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($expPageId)
1634 && $GLOBALS['BE_USER']->isInWebMount($expPageId)
1635 ) {
1636 // Set header:
1637 $out .= $this->barheader($GLOBALS['LANG']->getLL('contentElements') . ':');
1638 // Create header for listing, showing the page title/icon:
1639 $mainPageRec = BackendUtility::getRecordWSOL('pages', $expPageId);
1640 $picon = IconUtility::getSpriteIconForRecord('pages', $mainPageRec);
1641 $picon .= BackendUtility::getRecordTitle('pages', $mainPageRec, TRUE);
1642 $out .= $picon . '<br />';
1643 // Look up tt_content elements from the expanded page:
1644 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1645 'uid,header,hidden,starttime,endtime,fe_group,CType,colPos,bodytext',
1646 'tt_content',
1647 'pid=' . (int)$expPageId . BackendUtility::deleteClause('tt_content')
1648 . BackendUtility::versioningPlaceholderClause('tt_content'),
1649 '',
1650 'colPos,sorting'
1651 );
1652 $cc = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
1653 // Traverse list of records:
1654 $c = 0;
1655 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1656 $c++;
1657 $icon = IconUtility::getSpriteIconForRecord('tt_content', $row);
1658 if ($this->curUrlInfo['act'] == 'page' && $this->curUrlInfo['cElement'] == $row['uid']) {
1659 $arrCol = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif', 'width="5" height="9"')
1660 . ' class="c-blinkArrowL" alt="" />';
1661 } else {
1662 $arrCol = '';
1663 }
1664 // Putting list element HTML together:
1665 $out .= '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/ol/join' . ($c == $cc ? 'bottom' : '')
1666 . '.gif'), 'width="18" height="16"') . ' alt="" />' . $arrCol
1667 . '<a href="#" onclick="return link_typo3Page(\'' . $expPageId . '\',\'#' . $row['uid'] . '\');">'
1668 . $icon . BackendUtility::getRecordTitle('tt_content', $row, TRUE) . '</a><br />';
1669 // Finding internal anchor points:
1670 if (GeneralUtility::inList('text,textpic', $row['CType'])) {
1671 $split = preg_split('/(<a[^>]+name=[\'"]?([^"\'>[:space:]]+)[\'"]?[^>]*>)/i', $row['bodytext'], -1, PREG_SPLIT_DELIM_CAPTURE);
1672 foreach ($split as $skey => $sval) {
1673 if ($skey % 3 == 2) {
1674 // Putting list element HTML together:
1675 $sval = substr($sval, 0, 100);
1676 $out .= '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/ol/line.gif',
1677 'width="18" height="16"') . ' alt="" />'
1678 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/ol/join'
1679 . ($skey + 3 > count($split) ? 'bottom' : '') . '.gif'), 'width="18" height="16"')
1680 . ' alt="" />' . '<a href="#" onclick="return link_typo3Page(' . GeneralUtility::quoteJSvalue($expPageId)
1681 . ',' . GeneralUtility::quoteJSvalue('#' . $sval) . ');">' . htmlspecialchars((' <A> ' . $sval))
1682 . '</a><br />';
1683 }
1684 }
1685 }
1686 }
1687 }
1688 return $out;
1689 }
1690
1691 /**
1692 * For TYPO3 Element Browser: This lists all content elements from the given list of tables
1693 *
1694 * @param string $tables Comma separated list of tables. Set to "*" if you want all tables.
1695 * @return string HTML output.
1696 */
1697 public function TBE_expandPage($tables) {
1698 if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->expandPage)
1699 || $this->expandPage < 0
1700 || !$GLOBALS['BE_USER']->isInWebMount($this->expandPage)
1701 ) {
1702 return '';
1703 }
1704 // Set array with table names to list:
1705 if (trim($tables) === '*') {
1706 $tablesArr = array_keys($GLOBALS['TCA']);
1707 } else {
1708 $tablesArr = GeneralUtility::trimExplode(',', $tables, TRUE);
1709 }
1710 reset($tablesArr);
1711 // Headline for selecting records:
1712 $out = $this->barheader($GLOBALS['LANG']->getLL('selectRecords') . ':');
1713 // Create the header, showing the current page for which the listing is.
1714 // Includes link to the page itself, if pages are amount allowed tables.
1715 $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
1716 $mainPageRec = BackendUtility::getRecordWSOL('pages', $this->expandPage);
1717 $ATag = '';
1718 $ATag_e = '';
1719 $ATag2 = '';
1720 $picon = '';
1721 if (is_array($mainPageRec)) {
1722 $picon = IconUtility::getSpriteIconForRecord('pages', $mainPageRec);
1723 if (in_array('pages', $tablesArr)) {
1724 $ATag = '<a href="#" onclick="return insertElement(\'pages\', \'' . $mainPageRec['uid'] . '\', \'db\', '
1725 . GeneralUtility::quoteJSvalue($mainPageRec['title']) . ', \'\', \'\', \'\',\'\',1);">';
1726 $ATag2 = '<a href="#" onclick="return insertElement(\'pages\', \'' . $mainPageRec['uid'] . '\', \'db\', '
1727 . GeneralUtility::quoteJSvalue($mainPageRec['title']) . ', \'\', \'\', \'\',\'\',0);">';
1728 $ATag_e = '</a>';
1729 }
1730 }
1731 $pBicon = $ATag2 ? '<img'
1732 . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif', 'width="18" height="16"')
1733 . ' alt="" />' : '';
1734 $pText = htmlspecialchars(GeneralUtility::fixed_lgd_cs($mainPageRec['title'], $titleLen));
1735 $out .= $picon . $ATag2 . $pBicon . $ATag_e . $ATag . $pText . $ATag_e . '<br />';
1736 // Initialize the record listing:
1737 $id = $this->expandPage;
1738 $pointer = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
1739 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
1740 $pageInfo = BackendUtility::readPageAccess($id, $perms_clause);
1741 // Generate the record list:
1742 /** @var $dbList \TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList */
1743 if (is_object($this->recordList)) {
1744 $dbList = $this->recordList;
1745 } else {
1746 $dbList = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList::class);
1747 }
1748 $dbList->thisScript = $this->thisScript;
1749 $dbList->backPath = $GLOBALS['BACK_PATH'];
1750 $dbList->thumbs = 0;
1751 $dbList->calcPerms = $GLOBALS['BE_USER']->calcPerms($pageInfo);
1752 $dbList->noControlPanels = 1;
1753 $dbList->clickMenuEnabled = 0;
1754 $dbList->tableList = implode(',', $tablesArr);
1755 $pArr = explode('|', $this->bparams);
1756 // a string like "data[pages][79][storage_pid]"
1757 $fieldPointerString = $pArr[0];
1758 // parts like: data, pages], 79], storage_pid]
1759 $fieldPointerParts = explode('[', $fieldPointerString);
1760 $relatingTableName = substr($fieldPointerParts[1], 0, -1);
1761 $relatingFieldName = substr($fieldPointerParts[3], 0, -1);
1762 if ($relatingTableName && $relatingFieldName) {
1763 $dbList->setRelatingTableAndField($relatingTableName, $relatingFieldName);
1764 }
1765 $dbList->start($id, GeneralUtility::_GP('table'), $pointer, GeneralUtility::_GP('search_field'),
1766 GeneralUtility::_GP('search_levels'), GeneralUtility::_GP('showLimit')
1767 );
1768 $dbList->setDispFields();
1769 $dbList->generateList();
1770 $out .= $dbList->getSearchBox();
1771 $out .= "<script>document.getElementById('db_list-searchbox-toolbar').style.display = 'block';document.getElementById('db_list-searchbox-toolbar').style.position = 'relative';</script>";
1772
1773 // Add the HTML for the record list to output variable:
1774 $out .= $dbList->HTMLcode;
1775 // Add support for fieldselectbox in singleTableMode
1776 if ($dbList->table) {
1777 $out .= $dbList->fieldSelectBox($dbList->table);
1778 }
1779
1780 // Return accumulated content:
1781 return $out;
1782 }
1783
1784 /**
1785 * Render list of folders inside a folder.
1786 *
1787 * @param Folder $folder Folder
1788 * @return string HTML output
1789 */
1790 public function TBE_expandSubFolders(Folder $folder) {
1791 $content = '';
1792 if ($folder->checkActionPermission('read')) {
1793 $content .= $this->folderList($folder);
1794 }
1795 // Return accumulated content for folderlisting:
1796 return $content;
1797 }
1798
1799 /******************************************************************
1800 *
1801 * File listing
1802 *
1803 ******************************************************************/
1804 /**
1805 * For RTE: This displays all files from folder. No thumbnails shown
1806 *
1807 * @param Folder $folder The folder path to expand
1808 * @param string $extensionList List of file extensions to show
1809 * @return string HTML output
1810 */
1811 public function expandFolder(Folder $folder, $extensionList = '') {
1812 if (!$folder->checkActionPermission('read')) {
1813 return '';
1814 }
1815 $renderFolders = $this->act === 'folder';
1816 // Create header for file listing:
1817 $out = $this->barheader($GLOBALS['LANG']->getLL('files') . ':');
1818 // Prepare current path value for comparison (showing red arrow)
1819 $currentIdentifier = '';
1820 if ($this->curUrlInfo['value']) {
1821 $currentIdentifier = $this->curUrlInfo['info'];
1822 }
1823 // Create header element; The folder from which files are listed.
1824 $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
1825 $folderIcon = IconUtility::getSpriteIconForResource($folder);
1826 $folderIcon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen));
1827 $picon = '<a href="#" onclick="return link_folder(\'file:' . $folder->getCombinedIdentifier() . '\');">'
1828 . $folderIcon . '</a>';
1829 if ($this->curUrlInfo['act'] == 'folder' && $currentIdentifier == $folder->getCombinedIdentifier()) {
1830 $out .= '<img'
1831 . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif', 'width="5" height="9"')
1832 . ' class="c-blinkArrowL" alt="" />';
1833 }
1834 $out .= $picon . '<br />';
1835 // Get files from the folder:
1836 if ($renderFolders) {
1837 $items = $folder->getSubfolders();
1838 } else {
1839 $items = $this->getFilesInFolder($folder, $extensionList);
1840 }
1841 $c = 0;
1842 $totalItems = count($items);
1843 foreach ($items as $fileOrFolderObject) {
1844 $c++;
1845 if ($renderFolders) {
1846 $fileIdentifier = $fileOrFolderObject->getCombinedIdentifier();
1847 $overlays = array();
1848 if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\InaccessibleFolder) {
1849 $overlays = array('status-overlay-locked' => array());
1850 }
1851 $icon = IconUtility::getSpriteIcon(
1852 IconUtility::mapFileExtensionToSpriteIconName('folder'),
1853 array('title' => $fileOrFolderObject->getName()),
1854 $overlays);
1855 $itemUid = 'file:' . $fileIdentifier;
1856 } else {
1857 $fileIdentifier = $fileOrFolderObject->getUid();
1858 // File icon:
1859 $fileExtension = $fileOrFolderObject->getExtension();
1860 // Get size and icon:
1861 $size = ' (' . GeneralUtility::formatSize($fileOrFolderObject->getSize()) . 'bytes)';
1862 $icon = IconUtility::getSpriteIconForResource($fileOrFolderObject, array('title' => $fileOrFolderObject->getName() . $size));
1863 $itemUid = 'file:' . $fileIdentifier;
1864 }
1865 // If the listed file turns out to be the CURRENT file, then show blinking arrow:
1866 if (($this->curUrlInfo['act'] == 'file' || $this->curUrlInfo['act'] == 'folder')
1867 && $currentIdentifier == $fileIdentifier
1868 ) {
1869 $arrCol = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif',
1870 'width="5" height="9"') . ' class="c-blinkArrowL" alt="" />';
1871 } else {
1872 $arrCol = '';
1873 }
1874 // Put it all together for the file element:
1875 $out .=
1876 '<img' .
1877 IconUtility::skinImg(
1878 $GLOBALS['BACK_PATH'],
1879 ('gfx/ol/join' . ($c == $totalItems ? 'bottom' : '') . '.gif'),
1880 'width="18" height="16"'
1881 ) . ' alt="" />' . $arrCol .
1882 '<a href="#" onclick="return link_folder(\'' . $itemUid . '\');">' .
1883 $icon .
1884 htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileOrFolderObject->getName(), $titleLen)) .
1885 '</a><br />';
1886 }
1887 return $out;
1888 }
1889
1890 /**
1891 * For TYPO3 Element Browser: Expand folder of files.
1892 *
1893 * @param Folder $folder The folder path to expand
1894 * @param string $extensionList List of fileextensions to show
1895 * @param bool $noThumbs Whether to show thumbnails or not. If set, no thumbnails are shown.
1896 * @return string HTML output
1897 */
1898 public function TBE_expandFolder(Folder $folder, $extensionList = '', $noThumbs = FALSE) {
1899 if (!$folder->checkActionPermission('read')) {
1900 return '';
1901 }
1902 $extensionList = $extensionList == '*' ? '' : $extensionList;
1903 $files = $this->getFilesInFolder($folder, $extensionList);
1904 return $this->fileList($files, $folder, $noThumbs);
1905 }
1906
1907 /**
1908 * Render list of files.
1909 *
1910 * @param File[] $files List of files
1911 * @param Folder $folder If set a header with a folder icon and folder name are shown
1912 * @param bool $noThumbs Whether to show thumbnails or not. If set, no thumbnails are shown.
1913 * @return string HTML output
1914 */
1915 protected function fileList(array $files, Folder $folder = NULL, $noThumbs = FALSE) {
1916 $out = '';
1917
1918 $lines = array();
1919 // Create headline (showing number of files):
1920 $filesCount = count($files);
1921 $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', $filesCount));
1922 $out .= '<div id="filelist">';
1923 $out .= $this->getBulkSelector($filesCount);
1924 $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
1925 // Create the header of current folder:
1926 if ($folder) {
1927 $folderIcon = IconUtility::getSpriteIconForResource($folder);
1928 $lines[] = '<tr class="t3-row-header">
1929 <td colspan="4">' . $folderIcon
1930 . htmlspecialchars(GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen)) . '</td>
1931 </tr>';
1932 }
1933 if ($filesCount == 0) {
1934 $lines[] = '
1935 <tr class="file_list_normal">
1936 <td colspan="4">No files found.</td>
1937 </tr>';
1938 }
1939 // Traverse the file list:
1940 /** @var $fileObject \TYPO3\CMS\Core\Resource\File */
1941 foreach ($files as $fileObject) {
1942 $fileExtension = $fileObject->getExtension();
1943 // Thumbnail/size generation:
1944 $imgInfo = array();
1945 if (GeneralUtility::inList(strtolower($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']), strtolower($fileExtension)) && !$noThumbs) {
1946 $imageUrl = $fileObject->process(
1947 \TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW,
1948 array('width' => 64, 'height' => 64)
1949 )->getPublicUrl(TRUE);
1950 $imgInfo = array(
1951 $fileObject->getProperty('width'),
1952 $fileObject->getProperty('height')
1953 );
1954 $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
1955 $clickIcon = '<img src="' . $imageUrl . '" hspace="5" vspace="5" border="1" />';
1956 } else {
1957 $clickIcon = '';
1958 $pDim = '';
1959 }
1960 // Create file icon:
1961 $size = ' (' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
1962 $icon = IconUtility::getSpriteIconForResource($fileObject, array('title' => $fileObject->getName() . $size));
1963 // Create links for adding the file:
1964 $filesIndex = count($this->elements);
1965 $this->elements['file_' . $filesIndex] = array(
1966 'type' => 'file',
1967 'table' => 'sys_file',
1968 'uid' => $fileObject->getUid(),
1969 'fileName' => $fileObject->getName(),
1970 'filePath' => $fileObject->getUid(),
1971 'fileExt' => $fileExtension,
1972 'fileIcon' => $icon
1973 );
1974 if ($this->fileIsSelectableInFileList($fileObject, $imgInfo)) {
1975 $ATag = '<a href="#" onclick="return BrowseLinks.File.insertElement(\'file_' . $filesIndex . '\');">';
1976 $ATag_alt = substr($ATag, 0, -4) . ',1);">';
1977 $bulkCheckBox = '<input type="checkbox" class="typo3-bulk-item" name="file_' . $filesIndex . '" value="0" /> ';
1978 $ATag_e = '</a>';
1979 } else {
1980 $ATag = '';
1981 $ATag_alt = '';
1982 $ATag_e = '';
1983 $bulkCheckBox = '';
1984 }
1985 // Create link to showing details about the file in a window:
1986 $Ahref = $GLOBALS['BACK_PATH'] . 'show_item.php?type=file&table=_FILE&uid='
1987 . rawurlencode($fileObject->getCombinedIdentifier())
1988 . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'));
1989 $ATag2 = '<a href="' . htmlspecialchars($Ahref) . '">';
1990 $ATag2_e = '</a>';
1991 // Combine the stuff:
1992 $filenameAndIcon = $bulkCheckBox . $ATag_alt . $icon
1993 . htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getName(), $titleLen)) . $ATag_e;
1994 // Show element:
1995 if ($pDim) {
1996 // Image...
1997 $lines[] = '
1998 <tr class="file_list_normal">
1999 <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
2000 <td>' . ($ATag . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif',
2001 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', TRUE)
2002 . '" alt="" />' . $ATag_e) . '</td>
2003 <td nowrap="nowrap">' . ($ATag2 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'],
2004 'gfx/zoom2.gif', 'width="12" height="12"') . ' title="'
2005 . $GLOBALS['LANG']->getLL('info', TRUE) . '" alt="" /> '
2006 . $GLOBALS['LANG']->getLL('info', TRUE) . $ATag2_e) . '</td>
2007 <td nowrap="nowrap">&nbsp;' . $pDim . '</td>
2008 </tr>';
2009 $lines[] = '
2010 <tr>
2011 <td class="filelistThumbnail" colspan="4">' . $ATag_alt . $clickIcon . $ATag_e . '</td>
2012 </tr>';
2013 } else {
2014 $lines[] = '
2015 <tr class="file_list_normal">
2016 <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
2017 <td>' . ($ATag . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif',
2018 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', TRUE)
2019 . '" alt="" />' . $ATag_e) . '</td>
2020 <td nowrap="nowrap">' . ($ATag2 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'],
2021 'gfx/zoom2.gif', 'width="12" height="12"') . ' title="'
2022 . $GLOBALS['LANG']->getLL('info', TRUE) . '" alt="" /> '
2023 . $GLOBALS['LANG']->getLL('info', TRUE) . $ATag2_e) . '</td>
2024 <td>&nbsp;</td>
2025 </tr>';
2026 }
2027 }
2028 // Wrap all the rows in table tags:
2029 $out .= '
2030
2031 <!--
2032 File listing
2033 -->
2034 <table cellpadding="0" cellspacing="0" id="typo3-filelist">
2035 ' . implode('', $lines) . '
2036 </table>';
2037 // Return accumulated content for file listing:
2038 $out .= '</div>';
2039 return $out;
2040 }
2041
2042 /**
2043 * Checks if the given file is selectable in the file list.
2044 *
2045 * By default all files are selectable. This method may be overwritten in child classes.
2046 *
2047 * @param \TYPO3\CMS\Core\Resource\FileInterface $file
2048 * @param array $imgInfo Image dimensions from \TYPO3\CMS\Core\Imaging\GraphicalFunctions::getImageDimensions()
2049 * @return bool TRUE if file is selectable.
2050 */
2051 protected function fileIsSelectableInFileList(\TYPO3\CMS\Core\Resource\FileInterface $file, array $imgInfo) {
2052 return TRUE;
2053 }
2054
2055 /**
2056 * Render list of folders.
2057 *
2058 * @param Folder $baseFolder
2059 * @return string HTML output
2060 */
2061 public function folderList(Folder $baseFolder) {
2062 $content = '';
2063 $folders = $baseFolder->getSubfolders();
2064 $baseFolderPath = $baseFolder->getPublicUrl();
2065 // Create headline (showing number of folders):
2066 $content .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('folders') . ' (%s):', count($folders)));
2067 $titleLength = (int)$GLOBALS['BE_USER']->uc['titleLen'];
2068 // Create the header of current folder:
2069 $aTag = '<a href="#" onclick="return insertElement(\'\',' . GeneralUtility::quoteJSvalue($baseFolderPath)
2070 . ', \'folder\', ' . GeneralUtility::quoteJSvalue($baseFolderPath) . ', ' . GeneralUtility::quoteJSvalue($baseFolderPath)
2071 . ', \'\', \'\',\'\',1);">';
2072 // Add the foder icon
2073 $folderIcon = $aTag;
2074 $folderIcon .= '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif',
2075 'width="18" height="16"') . ' alt="" />';
2076 $folderIcon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs(basename($baseFolder), $titleLength));
2077 $folderIcon .= '</a>';
2078 $content .= $folderIcon . '<br />';
2079
2080 $lines = array();
2081 // Traverse the folder list:
2082 foreach ($folders as $folderPath) {
2083 $pathInfo = pathinfo($folderPath);
2084 // Create folder icon:
2085 $icon = '<img src="clear.gif" width="16" height="16" alt="" /><img'
2086 . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif',
2087 'width="16" height="16"') . ' title="' . htmlspecialchars(($pathInfo['basename']))
2088 . '" class="absmiddle" alt="" />';
2089 // Create links for adding the folder:
2090 if ($this->P['itemName'] != '' && $this->P['formName'] != '') {
2091 $aTag = '<a href="#" onclick="return set_folderpath(' . GeneralUtility::quoteJSvalue($folderPath)
2092 . ');">';
2093 } else {
2094 $aTag = '<a href="#" onclick="return insertElement(\'\',' . GeneralUtility::quoteJSvalue($folderPath)
2095 . ', \'folder\', ' . GeneralUtility::quoteJSvalue($folderPath) . ', '
2096 . GeneralUtility::quoteJSvalue($folderPath) . ', \'' . $pathInfo['extension'] . '\', \'\');">';
2097 }
2098 if (strstr($folderPath, ',') || strstr($folderPath, '|')) {
2099 // In case an invalid character is in the filepath, display error message:
2100 $errorMessage = GeneralUtility::quoteJSvalue(sprintf($GLOBALS['LANG']->getLL('invalidChar'), ', |'));
2101 $aTag = ($aTag_alt = '<a href="#" onclick="alert(' . $errorMessage . ');return false;">');
2102 } else {
2103 // If foldername is OK, just add it:
2104 $aTag_alt = substr($aTag, 0, -4) . ',\'\',1);">';
2105 }
2106 $aTag_e = '</a>';
2107 // Combine icon and folderpath:
2108 $foldernameAndIcon = $aTag_alt . $icon
2109 . htmlspecialchars(GeneralUtility::fixed_lgd_cs(basename($folderPath), $titleLength)) . $aTag_e;
2110 if ($this->P['itemName'] != '') {
2111 $lines[] = '
2112 <tr class="bgColor4">
2113 <td nowrap="nowrap">' . $foldernameAndIcon . '&nbsp;</td>
2114 <td>&nbsp;</td>
2115 </tr>';
2116 } else {
2117 $lines[] = '
2118 <tr class="bgColor4">
2119 <td nowrap="nowrap">' . $foldernameAndIcon . '&nbsp;</td>
2120 <td>' . $aTag . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif',
2121 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', TRUE)
2122 . '" alt="" />' . $aTag_e . ' </td>
2123 <td>&nbsp;</td>
2124 </tr>';
2125 }
2126 $lines[] = '
2127 <tr>
2128 <td colspan="3"><img src="clear.gif" width="1" height="3" alt="" /></td>
2129 </tr>';
2130 }
2131 // Wrap all the rows in table tags:
2132 $content .= '
2133
2134 <!--
2135 Folder listing
2136 -->
2137 <table border="0" cellpadding="0" cellspacing="1" id="typo3-folderList">
2138 ' . implode('', $lines) . '
2139 </table>';
2140 // Return accumulated content for folderlisting:
2141 return $content;
2142 }
2143
2144 /**
2145 * For RTE: This displays all IMAGES (gif,png,jpg) (from extensionList) from folder. Thumbnails are shown for images.
2146 * This listing is of images located in the web-accessible paths ONLY - the listing is for drag-n-drop use in the RTE
2147 *
2148 * @param Folder $folder The folder path to expand
2149 * @param string $extensionList List of file extensions to show
2150 * @return string HTML output
2151 */
2152 public function TBE_dragNDrop(Folder $folder, $extensionList = '') {
2153 if (!$folder) {
2154 return '';
2155 }
2156 if (!$folder->getStorage()->isPublic()) {
2157 // Print this warning if the folder is NOT a web folder
2158 return $this->barheader($GLOBALS['LANG']->getLL('files'))
2159 . $this->getMsgBox($GLOBALS['LANG']->getLL('noWebFolder'), 'icon_warning2');
2160 }
2161 $out = '';
2162
2163 // Read files from directory:
2164 $extensionList = $extensionList == '*' ? '' : $extensionList;
2165 $files = $this->getFilesInFolder($folder, $extensionList);
2166
2167 $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', count($files)));
2168 $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
2169 $picon = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif', 'width="18" height="16"') . ' alt="" />';
2170 $picon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs(basename($folder->getName()), $titleLen));
2171 $out .= $picon . '<br />';
2172 // Init row-array:
2173 $lines = array();
2174 // Add "drag-n-drop" message:
2175 $lines[] = '
2176 <tr>
2177 <td colspan="2">' . $this->getMsgBox($GLOBALS['LANG']->getLL('findDragDrop')) . '</td>
2178 </tr>';
2179 // Traverse files:
2180 foreach ($files as $fileObject) {
2181 $fileInfo = $fileObject->getStorage()->getFileInfo($fileObject);
2182 // URL of image:
2183 $iUrl = GeneralUtility::rawurlencodeFP($fileObject->getPublicUrl(TRUE));
2184 // Show only web-images
2185 $fileExtension = strtolower($fileObject->getExtension());
2186 if (GeneralUtility::inList('gif,jpeg,jpg,png', $fileExtension)) {
2187 $imgInfo = array(
2188 $fileObject->getProperty('width'),
2189 $fileObject->getProperty('height')
2190 );
2191 $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
2192 $size = ' (' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
2193 $filenameAndIcon = IconUtility::getSpriteIconForResource($fileObject, array('title' => $fileObject->getName() . $size));
2194 if (GeneralUtility::_GP('noLimit')) {
2195 $maxW = 10000;
2196 $maxH = 10000;
2197 } else {
2198 $maxW = 380;
2199 $maxH = 500;
2200 }
2201 $IW = $imgInfo[0];
2202 $IH = $imgInfo[1];
2203 if ($IW > $maxW) {
2204 $IH = ceil($IH / $IW * $maxW);
2205 $IW = $maxW;
2206 }
2207 if ($IH > $maxH) {
2208 $IW = ceil($IW / $IH * $maxH);
2209 $IH = $maxH;
2210 }
2211 // Make row:
2212 $lines[] = '
2213 <tr class="bgColor4">
2214 <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
2215 <td nowrap="nowrap">' . ($imgInfo[0] != $IW
2216 ? '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('noLimit' => '1')))
2217 . '">' . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/icon_warning2.gif',
2218 'width="18" height="16"') . ' title="'
2219 . $GLOBALS['LANG']->getLL('clickToRedrawFullSize', TRUE) . '" alt="" />' . '</a>'
2220 : '')
2221 . $pDim . '&nbsp;</td>
2222 </tr>';
2223 $lines[] = '
2224 <tr>
2225 <td colspan="2"><img src="' . htmlspecialchars($iUrl) . '" data-htmlarea-file-uid="' . $fileObject->getUid()
2226 . '" width="' . htmlspecialchars($IW) . '" height="' . htmlspecialchars($IH) . '" border="1" alt="" /></td>
2227 </tr>';
2228 $lines[] = '
2229 <tr>
2230 <td colspan="2"><img src="clear.gif" width="1" height="3" alt="" /></td>
2231 </tr>';
2232 }
2233 }
2234 // Finally, wrap all rows in a table tag:
2235 $out .= '
2236
2237
2238 <!--
2239 File listing / Drag-n-drop
2240 -->
2241 <table border="0" cellpadding="0" cellspacing="1" id="typo3-dragBox">
2242 ' . implode('', $lines) . '
2243 </table>';
2244
2245 return $out;
2246 }
2247
2248 /******************************************************************
2249 *
2250 * Miscellaneous functions
2251 *
2252 ******************************************************************/
2253
2254 /**
2255 * Prints a 'header' where string is in a tablecell
2256 *
2257 * @param string $str The string to print in the header. The value is htmlspecialchars()'ed before output.
2258 * @return string The header HTML (wrapped in a table)
2259 */
2260 public function barheader($str) {
2261 return '
2262 <!-- Bar header: -->
2263 <h3>' . htmlspecialchars($str) . '</h3>
2264 ';
2265 }
2266
2267 /**
2268 * Displays a message box with the input message
2269 *
2270 * @param string $in_msg Input message to show (will be htmlspecialchars()'ed inside of this function)
2271 * @param string $icon Icon filename body from gfx/ (default is "icon_note") - meant to allow change to warning type icons...
2272 * @return string HTML for the message (wrapped in a table).
2273 */
2274 public function getMsgBox($in_msg, $icon = 'icon_note') {
2275 $msg = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/' . $icon . '.gif'), 'width="18" height="16"')
2276 . ' alt="" />' . htmlspecialchars($in_msg);
2277 $msg = '
2278
2279 <!--
2280 Message box:
2281 -->
2282 <table cellspacing="0" class="bgColor4" id="typo3-msgBox">
2283 <tr>
2284 <td>' . $msg . '</td>
2285 </tr>
2286 </table>
2287 ';
2288 return $msg;
2289 }
2290
2291 /**
2292 * For RTE/link: This prints the 'currentUrl'
2293 *
2294 * @param string $str URL value. The value is htmlspecialchars()'ed before output.
2295 * @return string HTML content, wrapped in a table.
2296 */
2297 public function printCurrentUrl($str) {
2298 // Output the folder or file identifier, when working with files
2299 if (isset($str) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($str)
2300 && ($this->act === 'file' || $this->act === 'folder')
2301 ) {
2302 try {
2303 $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($str);
2304 } catch (\TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException $e) {
2305 $fileObject = NULL;
2306 }
2307 $str = is_object($fileObject) ? $fileObject->getIdentifier() : '';
2308 }
2309 if (strlen($str)) {
2310 return '
2311 <!-- Print current URL -->
2312 <table border="0" cellpadding="0" cellspacing="0" id="typo3-curUrl">
2313 <tr>
2314 <td>' . $GLOBALS['LANG']->getLL('currentLink', TRUE) . ': '
2315 . htmlspecialchars(rawurldecode($str)) . '</td>
2316 </tr>
2317 </table>';
2318 } else {
2319 return '';
2320 }
2321 }
2322
2323 /**
2324 * For RTE/link: Parses the incoming URL and determines if it's a page, file, external or mail address.
2325 *
2326 * @param string $href HREF value tp analyse
2327 * @param string $siteUrl The URL of the current website (frontend)
2328 * @return array Array with URL information stored in assoc. keys: value, act (page, file, spec, mail), pageid, cElement, info
2329 */
2330 public function parseCurUrl($href, $siteUrl) {
2331 $href = trim($href);
2332 if ($href) {
2333 $info = array();
2334 // Default is "url":
2335 $info['value'] = $href;
2336 $info['act'] = 'url';
2337 $specialParts = explode('#_SPECIAL', $href);
2338 // Special kind (Something RTE specific: User configurable links through: "userLinks." from ->thisConfig)
2339 if (count($specialParts) == 2) {
2340 $info['value'] = '#_SPECIAL' . $specialParts[1];
2341 $info['act'] = 'spec';
2342 } elseif (strpos($href, 'file:') !== FALSE) {
2343 $rel = substr($href, strpos($href, 'file:') + 5);
2344 $rel = rawurldecode($rel);
2345 // resolve FAL-api "file:UID-of-sys_file-record" and "file:combined-identifier"
2346 $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($rel);
2347 if ($fileOrFolderObject instanceof Folder) {
2348 $info['act'] = 'folder';
2349 $info['value'] = $fileOrFolderObject->getCombinedIdentifier();
2350 } elseif ($fileOrFolderObject instanceof File) {
2351 $info['act'] = 'file';
2352 $info['value'] = $fileOrFolderObject->getUid();
2353 } else {
2354 $info['value'] = $rel;
2355 }
2356 } elseif (GeneralUtility::isFirstPartOfStr($href, $siteUrl)) {
2357 // If URL is on the current frontend website:
2358 // URL is a file, which exists:
2359 if (file_exists(PATH_site . rawurldecode($href))) {
2360 $info['value'] = rawurldecode($href);
2361 if (@is_dir((PATH_site . $info['value']))) {
2362 $info['act'] = 'folder';
2363 } else {
2364 $info['act'] = 'file';
2365 }
2366 } else {
2367 // URL is a page (id parameter)
2368 $uP = parse_url($href);
2369
2370 $pp = preg_split('/^id=/', $uP['query']);
2371 $pp[1] = preg_replace('/&id=[^&]*/', '', $pp[1]);
2372 $parameters = explode('&', $pp[1]);
2373 $id = array_shift($parameters);
2374 if ($id) {
2375 // Checking if the id-parameter is an alias.
2376 if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($id)) {
2377 list($idPartR) = BackendUtility::getRecordsByField('pages', 'alias', $id);
2378 $id = (int)$idPartR['uid'];
2379 }
2380 $pageRow = BackendUtility::getRecordWSOL('pages', $id);
2381 $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
2382 $info['value'] = ((((($GLOBALS['LANG']->getLL('page', TRUE) . ' \'')
2383 . htmlspecialchars(GeneralUtility::fixed_lgd_cs($pageRow['title'], $titleLen)))
2384 . '\' (ID:') . $id) . ($uP['fragment'] ? ', #' . $uP['fragment'] : '')) . ')';
2385 $info['pageid'] = $id;
2386 $info['cElement'] = $uP['fragment'];
2387 $info['act'] = 'page';
2388 $info['query'] = $parameters[0] ? '&' . implode('&', $parameters) : '';
2389 }
2390 }
2391 } else {
2392 // Email link:
2393 if (strtolower(substr($href, 0, 7)) == 'mailto:') {
2394 $info['value'] = trim(substr($href, 7));
2395 $info['act'] = 'mail';
2396 }
2397 }
2398 $info['info'] = $info['value'];
2399 } else {
2400 // NO value input:
2401 $info = array();
2402 $info['info'] = $GLOBALS['LANG']->getLL('none');
2403 $info['value'] = '';
2404 $info['act'] = 'page';
2405 }
2406 // let the hook have a look
2407 foreach ($this->hookObjects as $hookObject) {
2408 $info = $hookObject->parseCurrentUrl($href, $siteUrl, $info);
2409 }
2410 return $info;
2411 }
2412
2413 /**
2414 * Setter for the class that should be used by TBE_expandPage() to generate the record list.
2415 * This method is intended to be used by Extensions that implement their own browsing functionality.
2416 *
2417 * @param \TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList $recordList
2418 * @throws \InvalidArgumentException
2419 * @return void
2420 * @api
2421 */
2422 public function setRecordList($recordList) {
2423 if (!$recordList instanceof \TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList) {
2424 throw new \InvalidArgumentException('$recordList needs to be an instance of \\TYPO3\\CMS\\Backend\\RecordList\\ElementBrowserRecordList', 1370878522);
2425 }
2426 $this->recordList = $recordList;
2427 }
2428
2429 /**
2430 * For TBE: Makes an upload form for uploading files to the filemount the user is browsing.
2431 * The files are uploaded to the tce_file.php script in the core which will handle the upload.
2432 *
2433 * @param Folder $folderObject Absolute filepath on server to which to upload.
2434 * @return string HTML for an upload form.
2435 */
2436 public function uploadForm(Folder $folderObject) {
2437 if (!$folderObject->checkActionPermission('write')) {
2438 return '';
2439 }
2440 // Read configuration of upload field count
2441 $userSetting = $GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.uploadFieldsInLinkBrowser');
2442 $count = isset($userSetting) ? $userSetting : 1;
2443 if ($count === '0') {
2444 return '';
2445 }
2446 $count = (int)$count === 0 ? 1 : (int)$count;
2447 // Create header, showing upload path:
2448 $header = $folderObject->getIdentifier();
2449 $code = '
2450 <br />
2451 <!--
2452 Form, for uploading files:
2453 -->
2454 <form action="' . $GLOBALS['BACK_PATH'] . 'tce_file.php" method="post" name="editform"'
2455 . 'id="typo3-uplFilesForm" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">
2456 <table border="0" cellpadding="0" cellspacing="0" id="typo3-uplFiles">
2457 <tr>
2458 <td>' . $this->barheader($GLOBALS['LANG']->sL(
2459 'LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle', TRUE) . ':') . '</td>
2460 </tr>
2461 <tr>
2462 <td class="c-wCell c-hCell"><strong>' . $GLOBALS['LANG']->getLL('path', TRUE) . ':</strong> '
2463 . htmlspecialchars($header) . '</td>
2464 </tr>
2465 <tr>
2466 <td class="c-wCell c-hCell">';
2467 // Traverse the number of upload fields (default is 3):
2468 for ($a = 1; $a <= $count; $a++) {
2469 $code .= '<input type="file" multiple="multiple" name="upload_' . $a . '[]"' . $this->doc->formWidth(35)
2470 . ' size="50" />
2471 <input type="hidden" name="file[upload][' . $a . '][target]" value="'
2472 . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />
2473 <input type="hidden" name="file[upload][' . $a . '][data]" value="' . $a . '" /><br />';
2474 }
2475 // Make footer of upload form, including the submit button:
2476 $redirectValue = $this->getThisScript() . 'act=' . $this->act . '&mode=' . $this->mode
2477 . '&expandFolder=' . rawurlencode($folderObject->getCombinedIdentifier())
2478 . '&bparams=' . rawurlencode($this->bparams);
2479 $code .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
2480 $code .= \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction');
2481 $code .= '
2482 <div id="c-override">
2483 <label><input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> '
2484 . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:overwriteExistingFiles', TRUE) . '</label>
2485 </div>
2486 <input type="submit" name="submit" value="'
2487 . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', TRUE) . '" />
2488 ';
2489 $code .= '</td>
2490 </tr>
2491 </table>
2492 </form><br />';
2493 return $code;
2494 }
2495
2496 /**
2497 * For TBE: Makes a form for creating new folders in the filemount the user is browsing.
2498 * The folder creation request is sent to the tce_file.php script in the core which will handle the creation.
2499 *
2500 * @param Folder $folderObject Absolute filepath on server in which to create the new folder.
2501 * @return string HTML for the create folder form.
2502 */
2503 public function createFolder(Folder $folderObject) {
2504 if (!$folderObject->checkActionPermission('write')) {
2505 return '';
2506 }
2507 if (!($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB'))) {
2508 return '';
2509 }
2510 // Don't show Folder-create form if it's denied
2511 if ($GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.hideCreateFolder')) {
2512 return '';
2513 }
2514 // Create header, showing upload path:
2515 $header = $folderObject->getIdentifier();
2516 $code = '
2517
2518 <!--
2519 Form, for creating new folders:
2520 -->
2521 <form action="' . $GLOBALS['BACK_PATH'] . 'tce_file.php" method="post" name="editform2" id="typo3-crFolderForm">
2522 <table border="0" cellpadding="0" cellspacing="0" id="typo3-crFolder">
2523 <tr>
2524 <td>' . $this->barheader($GLOBALS['LANG']->sL(
2525 'LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle') . ':') . '</td>
2526 </tr>
2527 <tr>
2528 <td class="c-wCell c-hCell"><strong>'
2529 . $GLOBALS['LANG']->getLL('path', TRUE) . ':</strong> ' . htmlspecialchars($header) . '</td>
2530 </tr>
2531 <tr>
2532 <td class="c-wCell c-hCell">';
2533 // Create the new-folder name field:
2534 $a = 1;
2535 $code .= '<input' . $this->doc->formWidth(20) . ' type="text" name="file[newfolder][' . $a . '][data]" />'
2536 . '<input type="hidden" name="file[newfolder][' . $a . '][target]" value="'
2537 . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />';
2538 // Make footer of upload form, including the submit button:
2539 $redirectValue = $this->getThisScript() . 'act=' . $this->act . '&mode=' . $this->mode
2540 . '&expandFolder=' . rawurlencode($folderObject->getCombinedIdentifier())
2541 . '&bparams=' . rawurlencode($this->bparams);
2542 $code .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />'
2543 . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction')
2544 . '<input type="submit" name="submit" value="'
2545 . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.submit', TRUE) . '" />';
2546 $code .= '</td>
2547 </tr>
2548 </table>
2549 </form>';
2550 return $code;
2551 }
2552
2553 /**
2554 * Get the HTML data required for a bulk selection of files of the TYPO3 Element Browser.
2555 *
2556 * @param int $filesCount Number of files currently displayed
2557 * @return string HTML data required for a bulk selection of files - if $filesCount is 0, nothing is returned
2558 */
2559 public function getBulkSelector($filesCount) {
2560 if (!$filesCount) {
2561 return '';
2562 }
2563
2564 $labelToggleSelection = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.xlf:toggleSelection', TRUE);
2565 $labelImportSelection = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.xlf:importSelection', TRUE);
2566 // Getting flag for showing/not showing thumbnails:
2567 $noThumbsInEB = $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInEB');
2568 $out = $this->doc->spacer(10) . '<div>' . '<a href="#" onclick="BrowseLinks.Selector.handle()">'
2569 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/import.gif', 'width="12" height="12"')
2570 . ' title="' . $labelImportSelection . '" alt="" /> ' . $labelImportSelection . '</a>&nbsp;&nbsp;&nbsp;'
2571 . '<a href="#" onclick="BrowseLinks.Selector.toggle()">' . '<img'
2572 . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/clip_select.gif', 'width="12" height="12"')
2573 . ' title="' . $labelToggleSelection . '" alt="" /> ' . $labelToggleSelection . '</a>' . '</div>';
2574 $thumbNailCheck = '';
2575 if (!$noThumbsInEB && $this->selectedFolder) {
2576 // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
2577 $_MOD_MENU = array('displayThumbs' => '');
2578 $_MCONF['name'] = 'file_list';
2579 $_MOD_SETTINGS = BackendUtility::getModuleData($_MOD_MENU, GeneralUtility::_GP('SET'), $_MCONF['name']);
2580 $addParams = '&act=' . $this->act . '&mode=' . $this->mode
2581 . '&expandFolder=' . rawurlencode($this->selectedFolder->getCombinedIdentifier())
2582 . '&bparams=' . rawurlencode($this->bparams);
2583 $thumbNailCheck = BackendUtility::getFuncCheck('', 'SET[displayThumbs]', $_MOD_SETTINGS['displayThumbs'],
2584 GeneralUtility::_GP('M') ? '' : $this->thisScript, $addParams, 'id="checkDisplayThumbs"')
2585 . ' <label for="checkDisplayThumbs">'
2586 . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:displayThumbs', TRUE) . '</label>';
2587 $out .= $this->doc->spacer(5) . $thumbNailCheck . $this->doc->spacer(15);
2588 } else {
2589 $out .= $this->doc->spacer(15);
2590 }
2591 return $out;
2592 }
2593
2594 /**
2595 * Determines whether submitted field change functions are valid
2596 * and are coming from the system and not from an external abuse.
2597 *
2598 * @param bool $handleFlexformSections Whether to handle flexform sections differently
2599 * @return bool Whether the submitted field change functions are valid
2600 */
2601 protected function areFieldChangeFunctionsValid($handleFlexformSections = FALSE) {
2602 $result = FALSE;
2603 if (isset($this->P['fieldChangeFunc']) && is_array($this->P['fieldChangeFunc']) && isset($this->P['fieldChangeFuncHash'])) {
2604 $matches = array();
2605 $pattern = '#\\[el\\]\\[(([^]-]+-[^]-]+-)(idx\\d+-)([^]]+))\\]#i';
2606 $fieldChangeFunctions = $this->P['fieldChangeFunc'];
2607 // Special handling of flexform sections:
2608 // Field change functions are modified in JavaScript, thus the hash is always invalid
2609 if ($handleFlexformSections && preg_match($pattern, $this->P['itemName'], $matches)) {
2610 $originalName = $matches[1];
2611 $cleanedName = $matches[2] . $matches[4];
2612 foreach ($fieldChangeFunctions as &$value) {
2613 $value = str_replace($originalName, $cleanedName, $value);
2614 }
2615 unset($value);
2616 }
2617 $result = $this->P['fieldChangeFuncHash'] === GeneralUtility::hmac(serialize($fieldChangeFunctions));
2618 }
2619 return $result;
2620 }
2621
2622 /**
2623 * Check if a temporary tree mount is set and return a cancel button
2624 *
2625 * @return string
2626 */
2627 protected function getTemporaryTreeMountCancelNotice() {
2628 if ((int)$GLOBALS['BE_USER']->getSessionData('pageTree_temporaryMountPoint') === 0) {
2629 return '';
2630 }
2631 $link = '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('setTempDBmount' => 0))) . '">'
2632 . $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xlf:labels.temporaryDBmount', TRUE) . '</a>';
2633 /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
2634 $flashMessage = GeneralUtility::makeInstance(
2635 \TYPO3\CMS\Core\Messaging\FlashMessage::class,
2636 $link,
2637 '',
2638 \TYPO3\CMS\Core\Messaging\FlashMessage::INFO
2639 );
2640 return $flashMessage->render();
2641 }
2642
2643 /**
2644 * Get a list of Files in a folder filtered by extension
2645 *
2646 * @param \TYPO3\CMS\Core\Resource\Folder $folder
2647 * @param string $extensionList
2648 * @return \TYPO3\CMS\Core\Resource\File[]
2649 */
2650 protected function getFilesInFolder(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList) {
2651 if ($extensionList !== '') {
2652 /** @var \TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter $filter */
2653 $filter = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter::class);
2654 $filter->setAllowedFileExtensions($extensionList);
2655 $folder->setFileAndFolderNameFilters(array(array($filter, 'filterFileList')));
2656 }
2657 return $folder->getFiles();
2658 }
2659 }