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