ElementBrowser.php

Benjamin Schmidt, 2013-07-22 17:13

Download (96.8 KB)

 
1
<?php
2
namespace TYPO3\CMS\Recordlist\Browser;
3

    
4
/**
5
 * class for the Element Browser window.
6
 *
7
 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
8
 */
9
class ElementBrowser {
10

    
11
        // Internal, static:
12
        // Current site URL (Frontend)
13
        /**
14
         * @todo Define visibility
15
         */
16
        public $siteURL;
17

    
18
        // the script to link to
19
        /**
20
         * @todo Define visibility
21
         */
22
        public $thisScript;
23

    
24
        // RTE specific TSconfig
25
        /**
26
         * @todo Define visibility
27
         */
28
        public $thisConfig;
29

    
30
        // Target (RTE specific)
31
        /**
32
         * @todo Define visibility
33
         */
34
        public $setTarget;
35

    
36
        // CSS Class (RTE specific)
37
        /**
38
         * @todo Define visibility
39
         */
40
        public $setClass;
41

    
42
        // title (RTE specific)
43
        /**
44
         * @todo Define visibility
45
         */
46
        public $setTitle;
47

    
48
        // Backend template object
49
        /**
50
         * @todo Define visibility
51
         */
52
        public $doc;
53

    
54
        // Holds information about files
55
        /**
56
         * @todo Define visibility
57
         */
58
        public $elements = array();
59

    
60
        // GPvars:        (Input variables from outside)
61
        /**
62
         * The mode determines the main kind of output from the element browser.
63
         * There are these options for values: rte, db, file, filedrag, wizard.
64
         * "rte" will show the link selector for the Rich Text Editor (see main_rte())
65
         * "db" will allow you to browse for pages or records in the page tree (for TCEforms, see main_db())
66
         * "file"/"filedrag" will allow you to browse for files or folders in the folder mounts (for TCEforms, main_file())
67
         * "wizard" will allow you to browse for links (like "rte") which are passed back to TCEforms (see main_rte(1))
68
         *
69
         * @see main()
70
         * @todo Define visibility
71
         */
72
        public $mode;
73

    
74
        /**
75
         * Link selector action.
76
         * page,file,url,mail,spec are allowed values.
77
         * These are only important with the link selector function and in that case they switch
78
         * between the various menu options.
79
         *
80
         * @todo Define visibility
81
         */
82
        public $act;
83

    
84
        /**
85
         * When you click a page title/expand icon to see the content of a certain page, this
86
         * value will contain that value (the ID of the expanded page). If the value is NOT set,
87
         * then it will be restored from the module session data (see main(), mode="db")
88
         *
89
         * @todo Define visibility
90
         */
91
        public $expandPage;
92

    
93
        /**
94
         * When you click a folder name/expand icon to see the content of a certain file folder,
95
         * this value will contain that value (the path of the expanded file folder). If the
96
         * value is NOT set, then it will be restored from the module session data (see main(),
97
         * mode="file"/"filedrag"). Example value: "/www/htdocs/typo3/32/3dsplm/fileadmin/css/"
98
         *
99
         * @todo Define visibility
100
         */
101
        public $expandFolder;
102

    
103
        /**
104
         * the folder object of a parent folder that was selected
105
         *
106
         * @param \TYPO3\CMS\Core\Resource\Folder
107
         */
108
        protected $selectedFolder;
109

    
110
        /**
111
         * TYPO3 Element Browser, wizard mode parameters. There is a heap of parameters there, better debug() them out if you need something... :-)
112
         *
113
         * @todo Define visibility
114
         */
115
        public $P;
116

    
117
        /**
118
         * Active with TYPO3 Element Browser: Contains the name of the form field for which this window opens - thus allows us to make references back to the main window in which the form is.
119
         * Example value: "data[pages][39][bodytext]|||tt_content|" or "data[tt_content][NEW3fba56fde763d][image]|||gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai|"
120
         *
121
         * Values:
122
         * 0: form field name reference, eg. "data[tt_content][123][image]"
123
         * 1: htlmArea RTE parameters: editorNo:contentTypo3Language:contentTypo3Charset
124
         * 2: RTE config parameters: RTEtsConfigParams
125
         * 3: allowed types. Eg. "tt_content" or "gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai"
126
         * 4: IRRE uniqueness: target level object-id to perform actions/checks on, eg. "data[79][tt_address][1][<field>][<foreign_table>]"
127
         * 5: IRRE uniqueness: name of function in opener window that checks if element is already used, eg. "inline.checkUniqueElement"
128
         * 6: IRRE uniqueness: name of function in opener window that performs some additional(!) action, eg. "inline.setUniqueElement"
129
         * 7: IRRE uniqueness: name of function in opener window that performs action instead of using addElement/insertElement, eg. "inline.importElement"
130
         *
131
         * $pArr = explode('|', $this->bparams);
132
         * $formFieldName = $pArr[0];
133
         * $allowedTablesOrFileTypes = $pArr[3];
134
         *
135
         * @todo Define visibility
136
         */
137
        public $bparams;
138

    
139
        /**
140
         * Used with the Rich Text Editor.
141
         * Example value: "tt_content:NEW3fba58c969f5c:bodytext:23:text:23:"
142
         *
143
         * @todo Define visibility
144
         */
145
        public $RTEtsConfigParams;
146

    
147
        /**
148
         * Plus/Minus icon value. Used by the tree class to open/close notes on the trees.
149
         *
150
         * @todo Define visibility
151
         */
152
        public $PM;
153

    
154
        /**
155
         * Pointer, used when browsing a long list of records etc.
156
         *
157
         * @todo Define visibility
158
         */
159
        public $pointer;
160

    
161
        /**
162
         * Used with the link selector: Contains the GET input information about the CURRENT link in the RTE/TCEform field. This consists of "href", "target" and "title" keys. This information is passed around in links.
163
         *
164
         * @todo Define visibility
165
         */
166
        public $curUrlArray;
167

    
168
        /**
169
         * Used with the link selector: Contains a processed version of the input values from curUrlInfo. This is splitted into pageid, content element id, label value etc. This is used for the internal processing of that information.
170
         *
171
         * @todo Define visibility
172
         */
173
        public $curUrlInfo;
174

    
175
        /**
176
         * array which holds hook objects (initialised in init() )
177
         */
178
        protected $hookObjects = array();
179

    
180
        /**
181
         * object for t3lib_basicFileFunctions
182
         */
183
        public $fileProcessor;
184

    
185
        /**
186
         * Constructor:
187
         * Initializes a lot of variables, setting JavaScript functions in header etc.
188
         *
189
         * @return void
190
         * @todo Define visibility
191
         */
192
        public function init() {
193
                // Main GPvars:
194
                $this->pointer = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('pointer');
195
                $this->bparams = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('bparams');
196
                $this->P = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('P');
197
                $this->RTEtsConfigParams = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('RTEtsConfigParams');
198
                $this->expandPage = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('expandPage');
199
                $this->expandFolder = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('expandFolder');
200
                $this->PM = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('PM');
201
                // Find "mode"
202
                $this->mode = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('mode');
203
                if (!$this->mode) {
204
                        $this->mode = 'rte';
205
                }
206
                // Creating backend template object:
207
                $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
208
                $this->doc->backPath = $GLOBALS['BACK_PATH'];
209
                // Load the Prototype library and browse_links.js
210
                $this->doc->getPageRenderer()->loadPrototype();
211
                $this->doc->loadJavascriptLib('js/browse_links.js');
212
                $this->doc->loadJavascriptLib('js/tree.js');
213
                // init hook objects:
214
                $this->hookObjects = array();
215
                if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'])) {
216
                        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'] as $classData) {
217
                                $processObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classData);
218
                                if (!$processObject instanceof \TYPO3\CMS\Core\ElementBrowser\ElementBrowserHookInterface) {
219
                                        throw new \UnexpectedValueException('$processObject must implement interface TYPO3\\CMS\\Core\\ElementBrowser\\ElementBrowserHookInterface', 1195039394);
220
                                }
221
                                $parameters = array();
222
                                $processObject->init($this, $parameters);
223
                                $this->hookObjects[] = $processObject;
224
                        }
225
                }
226
                // Site URL
227
                // Current site url
228
                $this->siteURL = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
229
                // The script to link to
230
                $this->thisScript = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('SCRIPT_NAME');
231
                // Init fileProcessor
232
                $this->fileProcessor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\BasicFileUtility');
233
                $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
234
                // CurrentUrl - the current link url must be passed around if it exists
235
                if ($this->mode == 'wizard') {
236
                        $currentValues = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(LF, trim($this->P['currentValue']));
237
                        if (count($currentValues) > 0) {
238
                                $currentValue = array_pop($currentValues);
239
                        } else {
240
                                $currentValue = '';
241
                        }
242
                        $currentLinkParts = \TYPO3\CMS\Core\Utility\GeneralUtility::unQuoteFilenames($currentValue, TRUE);
243
                        $initialCurUrlArray = array(
244
                                'href' => $currentLinkParts[0],
245
                                'target' => $currentLinkParts[1],
246
                                'class' => $currentLinkParts[2],
247
                                'title' => $currentLinkParts[3],
248
                                'params' => $currentLinkParts[4]
249
                        );
250
                        $this->curUrlArray = is_array(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('curUrl')) ? array_merge($initialCurUrlArray, \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('curUrl')) : $initialCurUrlArray;
251
                        // Additional fields for page links
252
                        if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendUrlArray']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendUrlArray'])) {
253
                                $_params = array(
254
                                        'conf' => &$conf,
255
                                        'linkParts' => $currentLinkParts
256
                                );
257
                                foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendUrlArray'] as $objRef) {
258
                                        $processor =& \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($objRef);
259
                                        $processor->extendUrlArray($_params, $this);
260
                                }
261
                        }
262
                        $this->curUrlInfo = $this->parseCurUrl($this->siteURL . '?id=' . $this->curUrlArray['href'], $this->siteURL);
263
                        // pageid == 0 means that this is not an internal (page) link
264
                        if ($this->curUrlInfo['pageid'] == 0 && $this->curUrlArray['href']) {
265
                                // Check if there is the FAL API
266
                                if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($this->curUrlArray['href'], 'file:')) {
267
                                        $this->curUrlInfo = $this->parseCurUrl($this->curUrlArray['href'], $this->siteURL);
268
                                        // Remove the "file:" prefix
269
                                        $currentLinkParts[0] = rawurldecode(substr($this->curUrlArray['href'], 5));
270
                                } elseif (file_exists(PATH_site . rawurldecode($this->curUrlArray['href']))) {
271
                                        if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($this->curUrlArray['href'], PATH_site)) {
272
                                                $currentLinkParts[0] = substr($this->curUrlArray['href'], strlen(PATH_site));
273
                                        }
274
                                        $this->curUrlInfo = $this->parseCurUrl($this->siteURL . $this->curUrlArray['href'], $this->siteURL);
275
                                } elseif (strstr($this->curUrlArray['href'], '@')) {
276
                                        // check for email link
277
                                        if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($this->curUrlArray['href'], 'mailto:')) {
278
                                                $currentLinkParts[0] = substr($this->curUrlArray['href'], 7);
279
                                        }
280
                                        $this->curUrlInfo = $this->parseCurUrl('mailto:' . $this->curUrlArray['href'], $this->siteURL);
281
                                } else {
282
                                        // nothing of the above. this is an external link
283
                                        if (strpos($this->curUrlArray['href'], '://') === FALSE) {
284
                                                $currentLinkParts[0] = 'http://' . $this->curUrlArray['href'];
285
                                        }
286
                                        $this->curUrlInfo = $this->parseCurUrl($currentLinkParts[0], $this->siteURL);
287
                                }
288
                        } elseif (!$this->curUrlArray['href']) {
289
                                $this->curUrlInfo = array();
290
                                $this->act = 'page';
291
                        } else {
292
                                $this->curUrlInfo = $this->parseCurUrl($this->siteURL . '?id=' . $this->curUrlArray['href'], $this->siteURL);
293
                        }
294
                } else {
295
                        $this->curUrlArray = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('curUrl');
296
                        if ($this->curUrlArray['all']) {
297
                                $this->curUrlArray = \TYPO3\CMS\Core\Utility\GeneralUtility::get_tag_attributes($this->curUrlArray['all']);
298
                        }
299
                        $this->curUrlInfo = $this->parseCurUrl($this->curUrlArray['href'], $this->siteURL);
300
                }
301
                // Determine nature of current url:
302
                $this->act = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('act');
303
                if (!$this->act) {
304
                        $this->act = $this->curUrlInfo['act'];
305
                }
306
                // Rich Text Editor specific configuration:
307
                $addPassOnParams = '';
308
                if ((string) $this->mode == 'rte') {
309
                        $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
310
                        $addPassOnParams .= '&RTEtsConfigParams=' . rawurlencode($this->RTEtsConfigParams);
311
                        $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
312
                        $this->thisConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
313
                }
314
                // Initializing the target value (RTE)
315
                $this->setTarget = $this->curUrlArray['target'] != '-' ? rawurlencode($this->curUrlArray['target']) : '';
316
                if ($this->thisConfig['defaultLinkTarget'] && !isset($this->curUrlArray['target'])) {
317
                        $this->setTarget = $this->thisConfig['defaultLinkTarget'];
318
                }
319
                // Initializing the class value (RTE)
320
                $this->setClass = $this->curUrlArray['class'] != '-' ? rawurlencode($this->curUrlArray['class']) : '';
321
                // Initializing the title value (RTE)
322
                $this->setTitle = $this->curUrlArray['title'] != '-' ? rawurlencode($this->curUrlArray['title']) : '';
323
                // Initializing the params value
324
                $this->setParams = $this->curUrlArray['params'] != '-' ? rawurlencode($this->curUrlArray['params']) : '';
325
                // BEGIN accumulation of header JavaScript:
326
                $JScode = '
327
                                // This JavaScript is primarily for RTE/Link. jumpToUrl is used in the other cases as well...
328
                        var add_href="' . ($this->curUrlArray['href'] ? '&curUrl[href]=' . rawurlencode($this->curUrlArray['href']) : '') . '";
329
                        var add_target="' . ($this->setTarget ? '&curUrl[target]=' . rawurlencode($this->setTarget) : '') . '";
330
                        var add_class="' . ($this->setClass ? '&curUrl[class]=' . rawurlencode($this->setClass) : '') . '";
331
                        var add_title="' . ($this->setTitle ? '&curUrl[title]=' . rawurlencode($this->setTitle) : '') . '";
332
                        var add_params="' . ($this->bparams ? '&bparams=' . rawurlencode($this->bparams) : '') . '";
333

334
                        var cur_href="' . ($this->curUrlArray['href'] ? rawurlencode($this->curUrlArray['href']) : '') . '";
335
                        var cur_target="' . ($this->setTarget ? $this->setTarget : '') . '";
336
                        var cur_class = "' . ($this->setClass ? $this->setClass : '') . '";
337
                        var cur_title="' . ($this->setTitle ? $this->setTitle : '') . '";
338
                        var cur_params="' . ($this->setParams ? $this->setParams : '') . '";
339

340
                        function browse_links_setTarget(target) {        //
341
                                cur_target=target;
342
                                add_target="&curUrl[target]="+escape(target);
343
                        }
344
                        function browse_links_setClass(cssClass) {   //
345
                                cur_class = cssClass;
346
                                add_class = "&curUrl[class]=" + escape(cssClass);
347
                        }
348
                        function browse_links_setTitle(title) {        //
349
                                cur_title=title;
350
                                add_title="&curUrl[title]="+escape(title);
351
                        }
352
                        function browse_links_setValue(value) {        //
353
                                cur_href=value;
354
                                add_href="&curUrl[href]="+value;
355
                        }
356
                        function browse_links_setParams(params) {        //
357
                                cur_params=params;
358
                                add_params="&curUrl[params]="+escape(params);
359
                        }
360
                ';
361
                // Functions used, if the link selector is in wizard mode (= TCEforms fields)
362
                if ($this->mode == 'wizard') {
363
                        if (!$this->areFieldChangeFunctionsValid() && !$this->areFieldChangeFunctionsValid(TRUE)) {
364
                                $this->P['fieldChangeFunc'] = array();
365
                        }
366
                        unset($this->P['fieldChangeFunc']['alert']);
367
                        $update = '';
368
                        foreach ($this->P['fieldChangeFunc'] as $k => $v) {
369
                                $update .= '
370
                                window.opener.' . $v;
371
                        }
372
                        $P2 = array();
373
                        $P2['itemName'] = $this->P['itemName'];
374
                        $P2['formName'] = $this->P['formName'];
375
                        $P2['fieldChangeFunc'] = $this->P['fieldChangeFunc'];
376
                        $P2['fieldChangeFuncHash'] = \TYPO3\CMS\Core\Utility\GeneralUtility::hmac(serialize($this->P['fieldChangeFunc']));
377
                        $P2['params']['allowedExtensions'] = $this->P['params']['allowedExtensions'];
378
                        $P2['params']['blindLinkOptions'] = $this->P['params']['blindLinkOptions'];
379
                        $P2['params']['blindLinkFields'] = $this->P['params']['blindLinkFields'];
380
                        $addPassOnParams .= \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('P', $P2);
381
                        $JScode .= '
382
                                function link_typo3Page(id,anchor) {        //
383
                                        updateValueInMainForm(id + (anchor ? anchor : ""));
384
                                        close();
385
                                        return false;
386
                                }
387
                                function link_folder(folder) {        //
388
                                        updateValueInMainForm(folder);
389
                                        close();
390
                                        return false;
391
                                }
392
                                function link_current() {        //
393
                                        if (cur_href!="http://" && cur_href!="mailto:") {
394
                                                returnBeforeCleaned = cur_href;
395
                                                if (returnBeforeCleaned.substr(0, 7) == "http://") {
396
                                                        returnToMainFormValue = returnBeforeCleaned.substr(7);
397
                                                } else if (returnBeforeCleaned.substr(0, 7) == "mailto:") {
398
                                                        if (returnBeforeCleaned.substr(0, 14) == "mailto:mailto:") {
399
                                                                returnToMainFormValue = returnBeforeCleaned.substr(14);
400
                                                        } else {
401
                                                                returnToMainFormValue = returnBeforeCleaned.substr(7);
402
                                                        }
403
                                                } else {
404
                                                        returnToMainFormValue = returnBeforeCleaned;
405
                                                }
406
                                                updateValueInMainForm(returnToMainFormValue);
407
                                                close();
408
                                        }
409
                                        return false;
410
                                }
411
                                function checkReference() {        //
412
                                        if (window.opener && window.opener.document && window.opener.document.' . $this->P['formName'] . ' && window.opener.document.' . $this->P['formName'] . '["' . $this->P['itemName'] . '"] ) {
413
                                                return window.opener.document.' . $this->P['formName'] . '["' . $this->P['itemName'] . '"];
414
                                        } else {
415
                                                close();
416
                                        }
417
                                }
418
                                function updateValueInMainForm(input) {        //
419
                                        var field = checkReference();
420
                                        if (field) {
421
                                                if (cur_target == "" && (cur_class != "" || cur_title != "" || cur_params != "")) {
422
                                                        cur_target = "-";
423
                                                }
424
                                                if (cur_class == "" && (cur_title != "" || cur_params != "")) {
425
                                                        cur_class = "-";
426
                                                }
427
                                                cur_class = cur_class.replace(/[\'\\"]/g, "");
428
                                                if (cur_class.indexOf(" ") != -1) {
429
                                                        cur_class = "\\"" + cur_class + "\\"";
430
                                                }
431
                                                if (cur_title == "" && cur_params != "") {
432
                                                         cur_title = "-";
433
                                                 }
434
                                                cur_title = cur_title.replace(/(^\\")|(\\"$)/g, "");
435
                                                if (cur_title.indexOf(" ") != -1) {
436
                                                        cur_title = "\\"" + cur_title + "\\"";
437
                                                }
438
                                                if (cur_params) {
439
                                                        cur_params = cur_params.replace(/\\bid\\=.*?(\\&|$)/, "");
440
                                                }
441
                                                input = input + " " + cur_target + " " + cur_class + " " + cur_title + " " + cur_params;
442
                                                if(field.value && field.className.search(/textarea/) != -1) {
443
                                                        field.value += "\\n" + input;
444
                                                } else {
445
                                                        field.value = input;
446
                                                }
447
                                                ' . $update . '
448
                                        }
449
                                }
450
                        ';
451
                } else {
452
                        // Functions used, if the link selector is in RTE mode:
453
                        $JScode .= '
454
                                function link_typo3Page(id,anchor) {        //
455
                                        var theLink = \'' . $this->siteURL . '?id=\'+id+(anchor?anchor:"");
456
                                        self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
457
                                        return false;
458
                                }
459
                                function link_folder(folder) {        //
460
                                        var theLink = \'' . $this->siteURL . '\'+folder;
461
                                        self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
462
                                        return false;
463
                                }
464
                                function link_spec(theLink) {        //
465
                                        self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
466
                                        return false;
467
                                }
468
                                function link_current() {        //
469
                                        if (cur_href!="http://" && cur_href!="mailto:") {
470
                                                self.parent.parent.renderPopup_addLink(cur_href, cur_target, cur_class, cur_title);
471
                                        }
472
                                        return false;
473
                                }
474
                        ';
475
                }
476
                // General "jumpToUrl" function:
477
                $JScode .= '
478
                        function jumpToUrl(URL,anchor) {        //
479
                                var add_act = URL.indexOf("act=")==-1 ? "&act=' . $this->act . '" : "";
480
                                var add_mode = URL.indexOf("mode=")==-1 ? "&mode=' . $this->mode . '" : "";
481
                                var theLocation = URL + add_act + add_mode + add_href + add_target + add_class + add_title + add_params' . ($addPassOnParams ? '+"' . $addPassOnParams . '"' : '') . '+(anchor?anchor:"");
482
                                window.location.href = theLocation;
483
                                return false;
484
                        }
485
                ';
486
                /**
487
                 * Splits parts of $this->bparams
488
                 *
489
                 * @see $bparams
490
                 */
491
                $pArr = explode('|', $this->bparams);
492
                // This is JavaScript especially for the TBE Element Browser!
493
                $formFieldName = 'data[' . $pArr[0] . '][' . $pArr[1] . '][' . $pArr[2] . ']';
494
                // insertElement - Call check function (e.g. for uniqueness handling):
495
                if ($pArr[4] && $pArr[5]) {
496
                        $JScodeCheck = '
497
                                        // Call a check function in the opener window (e.g. for uniqueness handling):
498
                                if (parent.window.opener) {
499
                                        var res = parent.window.opener.' . $pArr[5] . '("' . addslashes($pArr[4]) . '",table,uid,type);
500
                                        if (!res.passed) {
501
                                                if (res.message) alert(res.message);
502
                                                performAction = false;
503
                                        }
504
                                } else {
505
                                        alert("Error - reference to main window is not set properly!");
506
                                        parent.close();
507
                                }
508
                        ';
509
                }
510
                // insertElement - Call helper function:
511
                if ($pArr[4] && $pArr[6]) {
512
                        $JScodeHelper = '
513
                                                // Call helper function to manage data in the opener window:
514
                                        if (parent.window.opener) {
515
                                                parent.window.opener.' . $pArr[6] . '("' . addslashes($pArr[4]) . '",table,uid,type,"' . addslashes($pArr[0]) . '");
516
                                        } else {
517
                                                alert("Error - reference to main window is not set properly!");
518
                                                parent.close();
519
                                        }
520
                        ';
521
                }
522
                // insertElement - perform action commands:
523
                if ($pArr[4] && $pArr[7]) {
524
                        // Call user defined action function:
525
                        $JScodeAction = '
526
                                        if (parent.window.opener) {
527
                                                parent.window.opener.' . $pArr[7] . '("' . addslashes($pArr[4]) . '",table,uid,type);
528
                                                if (close) { focusOpenerAndClose(close); }
529
                                        } else {
530
                                                alert("Error - reference to main window is not set properly!");
531
                                                if (close) { parent.close(); }
532
                                        }
533
                        ';
534
                        $JScodeActionMultiple = '
535
                                                // Call helper function to manage data in the opener window:
536
                                        if (parent.window.opener) {
537
                                                parent.window.opener.' . $pArr[7] . 'Multiple("' . addslashes($pArr[4]) . '",table,uid,type,"' . addslashes($pArr[0]) . '");
538
                                        } else {
539
                                                alert("Error - reference to main window is not set properly!");
540
                                                parent.close();
541
                                        }
542
                        ';
543
                } elseif ($pArr[0] && !$pArr[1] && !$pArr[2]) {
544
                        $JScodeAction = '
545
                                        addElement(filename,table+"_"+uid,fp,close);
546
                        ';
547
                } else {
548
                        $JScodeAction = '
549
                                        if (setReferences()) {
550
                                                parent.window.opener.group_change("add","' . $pArr[0] . '","' . $pArr[1] . '","' . $pArr[2] . '",elRef,targetDoc);
551
                                        } else {
552
                                                alert("Error - reference to main window is not set properly!");
553
                                        }
554
                                        focusOpenerAndClose(close);
555
                        ';
556
                }
557
                $JScode .= '
558
                        var elRef="";
559
                        var targetDoc="";
560

561
                        function launchView(url) {        //
562
                                var thePreviewWindow="";
563
                                thePreviewWindow = window.open("' . $GLOBALS['BACK_PATH'] . 'show_item.php?table="+url,"ShowItem","height=300,width=410,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
564
                                if (thePreviewWindow && thePreviewWindow.focus) {
565
                                        thePreviewWindow.focus();
566
                                }
567
                        }
568
                        function setReferences() {        //
569
                                if (parent.window.opener && parent.window.opener.content && parent.window.opener.content.document.editform && parent.window.opener.content.document.editform["' . $formFieldName . '"]) {
570
                                        targetDoc = parent.window.opener.content.document;
571
                                        elRef = targetDoc.editform["' . $formFieldName . '"];
572
                                        return true;
573
                                } else {
574
                                        return false;
575
                                }
576
                        }
577
                        function insertElement(table, uid, type, filename, fp, filetype, imagefile, action, close) {        //
578
                                var performAction = true;
579
                                ' . $JScodeCheck . '
580
                                        // Call performing function and finish this action:
581
                                if (performAction) {
582
                                                ' . $JScodeHelper . $JScodeAction . '
583
                                }
584
                                return false;
585
                        }
586
                        function insertMultiple(table, uid) {
587
                                var type = "";
588
                                                ' . $JScodeActionMultiple . '
589
                                return false;
590
                        }
591
                        function addElement(elName, elValue, altElValue, close) {        //
592
                                if (parent.window.opener && parent.window.opener.setFormValueFromBrowseWin) {
593
                                        parent.window.opener.setFormValueFromBrowseWin("' . $pArr[0] . '",altElValue?altElValue:elValue,elName);
594
                                        focusOpenerAndClose(close);
595
                                } else {
596
                                        alert("Error - reference to main window is not set properly!");
597
                                        parent.close();
598
                                }
599
                        }
600
                        function focusOpenerAndClose(close) {        //
601
                                BrowseLinks.focusOpenerAndClose(close);
602
                        }
603
                ';
604
                // extends JavaScript code
605
                if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendJScode']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendJScode'])) {
606
                        $_params = array(
607
                                'conf' => &$conf,
608
                                'wizardUpdate' => $update,
609
                                'addPassOnParams' => $addPassOnParams
610
                        );
611
                        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendJScode'] as $objRef) {
612
                                $processor =& \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($objRef);
613
                                $JScode .= $processor->extendJScode($_params, $this);
614
                        }
615
                }
616
                // Finally, add the accumulated JavaScript to the template object:
617
                $this->doc->JScode .= $this->doc->wrapScriptTags($JScode);
618
        }
619

    
620
        /**
621
         * Session data for this class can be set from outside with this method.
622
         * Call after init()
623
         *
624
         * @param array $data Session data array
625
         * @return array Session data and boolean which indicates that data needs to be stored in session because it's changed
626
         * @todo Define visibility
627
         */
628
        public function processSessionData($data) {
629
                $store = FALSE;
630
                switch ((string) $this->mode) {
631
                case 'db':
632
                        if (isset($this->expandPage)) {
633
                                $data['expandPage'] = $this->expandPage;
634
                                $store = TRUE;
635
                        } else {
636
                                $this->expandPage = $data['expandPage'];
637
                        }
638
                        break;
639
                case 'file':
640

    
641
                case 'filedrag':
642

    
643
                case 'folder':
644
                        if (isset($this->expandFolder)) {
645
                                $data['expandFolder'] = $this->expandFolder;
646
                                $store = TRUE;
647
                        } else {
648
                                $this->expandFolder = $data['expandFolder'];
649
                        }
650
                        break;
651
                }
652
                return array($data, $store);
653
        }
654

    
655
        /******************************************************************
656
         *
657
         * Main functions
658
         *
659
         ******************************************************************/
660
        /**
661
         * Rich Text Editor (RTE) link selector (MAIN function)
662
         * Generates the link selector for the Rich Text Editor.
663
         * Can also be used to select links for the TCEforms (see $wiz)
664
         *
665
         * @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
666
         * @return string Modified content variable.
667
         * @todo Define visibility
668
         */
669
        public function main_rte($wiz = 0) {
670
                // Starting content:
671
                $content = $this->doc->startPage('RTE link');
672
                // Initializing the action value, possibly removing blinded values etc:
673
                $allowedItems = array_diff(explode(',', 'page,file,folder,url,mail,spec'), \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->thisConfig['blindLinkOptions'], 1));
674
                $allowedItems = array_diff($allowedItems, \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->P['params']['blindLinkOptions']));
675
                // Call hook for extra options
676
                foreach ($this->hookObjects as $hookObject) {
677
                        $allowedItems = $hookObject->addAllowedItems($allowedItems);
678
                }
679
                // Removing link fields if configured
680
                $allowedFields = array_diff(array('target', 'title', 'class', 'params'), \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->thisConfig['blindLinkFields'], TRUE), \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->P['params']['blindLinkFields'], TRUE));
681
                // If $this->act is not allowed, default to first allowed
682
                if (!in_array($this->act, $allowedItems)) {
683
                        $this->act = reset($allowedItems);
684
                }
685
                // Making menu in top:
686
                $menuDef = array();
687
                if (!$wiz) {
688
                        $menuDef['removeLink']['isActive'] = $this->act == 'removeLink';
689
                        $menuDef['removeLink']['label'] = $GLOBALS['LANG']->getLL('removeLink', 1);
690
                        $menuDef['removeLink']['url'] = '#';
691
                        $menuDef['removeLink']['addParams'] = 'onclick="self.parent.parent.renderPopup_unLink();return false;"';
692
                }
693
                if (in_array('page', $allowedItems)) {
694
                        $menuDef['page']['isActive'] = $this->act == 'page';
695
                        $menuDef['page']['label'] = $GLOBALS['LANG']->getLL('page', 1);
696
                        $menuDef['page']['url'] = '#';
697
                        $menuDef['page']['addParams'] = 'onclick="jumpToUrl(\'?act=page\');return false;"';
698
                }
699
                if (in_array('file', $allowedItems)) {
700
                        $menuDef['file']['isActive'] = $this->act == 'file';
701
                        $menuDef['file']['label'] = $GLOBALS['LANG']->getLL('file', 1);
702
                        $menuDef['file']['url'] = '#';
703
                        $menuDef['file']['addParams'] = 'onclick="jumpToUrl(\'?act=file\');return false;"';
704
                }
705
                if (in_array('folder', $allowedItems)) {
706
                        $menuDef['folder']['isActive'] = $this->act == 'folder';
707
                        $menuDef['folder']['label'] = $GLOBALS['LANG']->getLL('folder', 1);
708
                        $menuDef['folder']['url'] = '#';
709
                        $menuDef['folder']['addParams'] = 'onclick="jumpToUrl(\'?act=folder\');return false;"';
710
                }
711
                if (in_array('url', $allowedItems)) {
712
                        $menuDef['url']['isActive'] = $this->act == 'url';
713
                        $menuDef['url']['label'] = $GLOBALS['LANG']->getLL('extUrl', 1);
714
                        $menuDef['url']['url'] = '#';
715
                        $menuDef['url']['addParams'] = 'onclick="jumpToUrl(\'?act=url\');return false;"';
716
                }
717
                if (in_array('mail', $allowedItems)) {
718
                        $menuDef['mail']['isActive'] = $this->act == 'mail';
719
                        $menuDef['mail']['label'] = $GLOBALS['LANG']->getLL('email', 1);
720
                        $menuDef['mail']['url'] = '#';
721
                        $menuDef['mail']['addParams'] = 'onclick="jumpToUrl(\'?act=mail\');return false;"';
722
                }
723
                if (is_array($this->thisConfig['userLinks.']) && in_array('spec', $allowedItems)) {
724
                        $menuDef['spec']['isActive'] = $this->act == 'spec';
725
                        $menuDef['spec']['label'] = $GLOBALS['LANG']->getLL('special', 1);
726
                        $menuDef['spec']['url'] = '#';
727
                        $menuDef['spec']['addParams'] = 'onclick="jumpToUrl(\'?act=spec\');return false;"';
728
                }
729
                // Call hook for extra options
730
                foreach ($this->hookObjects as $hookObject) {
731
                        $menuDef = $hookObject->modifyMenuDefinition($menuDef);
732
                }
733
                $content .= $this->doc->getTabMenuRaw($menuDef);
734
                // Adding the menu and header to the top of page:
735
                $content .= $this->printCurrentUrl($this->curUrlInfo['info']) . '<br />';
736
                // Depending on the current action we will create the actual module content for selecting a link:
737
                switch ($this->act) {
738
                case 'mail':
739
                        $extUrl = '
740

741
                        <!--
742
                                Enter mail address:
743
                        -->
744
                                        <form action="" name="lurlform" id="lurlform">
745
                                                <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkMail">
746
                                                        <tr>
747
                                                                <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('emailAddress', 1) . ':</td>
748
                                                                <td><input type="text" name="lemail"' . $this->doc->formWidth(20) . ' value="' . htmlspecialchars(($this->curUrlInfo['act'] == 'mail' ? $this->curUrlInfo['info'] : '')) . '" /> ' . '<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink', 1) . '" onclick="browse_links_setTarget(\'\');browse_links_setValue(\'mailto:\'+document.lurlform.lemail.value); return link_current();" /></td>
749
                                                        </tr>
750
                                                </table>
751
                                        </form>';
752
                        $content .= $extUrl;
753
                        break;
754
                case 'url':
755
                        $extUrl = '
756

757
                        <!--
758
                                Enter External URL:
759
                        -->
760
                                        <form action="" name="lurlform" id="lurlform">
761
                                                <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkURL">
762
                                                        <tr>
763
                                                                <td style="width: 96px;">URL:</td>
764
                                                                <td><input type="text" name="lurl"' . $this->doc->formWidth(30) . ' value="' . htmlspecialchars(($this->curUrlInfo['act'] == 'url' ? $this->curUrlInfo['info'] : 'http://')) . '" /> ' . '<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink', 1) . '" onclick="browse_links_setValue(document.lurlform.lurl.value); return link_current();" /></td>
765
                                                        </tr>
766
                                                </table>
767
                                        </form>';
768
                        $content .= $extUrl;
769
                        break;
770
                case 'file':
771

    
772
                case 'folder':
773
                        $foldertree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('rteFolderTree');
774
                        $foldertree->thisScript = $this->thisScript;
775
                        $tree = $foldertree->getBrowsableTree();
776
                        if (!$this->curUrlInfo['value'] || $this->curUrlInfo['act'] != $this->act) {
777
                                $cmpPath = '';
778
                        } else {
779
                                $cmpPath = $this->curUrlInfo['value'];
780
                                if (!isset($this->expandFolder)) {
781
                                        $this->expandFolder = $cmpPath;
782
                                }
783
                        }
784
                        // Create upload/create folder forms, if a path is given
785
                        if ($this->expandFolder) {
786
                                $selectedFolder = FALSE;
787
                                $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
788

    
789
                                if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
790
                                        // It's a folder
791
                                        $selectedFolder = $fileOrFolderObject;
792
                                } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
793
                                        // It's a file
794
                                        // @todo: find the parent folder, right now done a bit ugly, because the file does not
795
                                        // support finding the parent folder of a file on purpose
796
                                        $folderIdentifier = dirname($fileOrFolderObject->getIdentifier());
797
                                        $selectedFolder = $fileOrFolderObject->getStorage()->getFolder($folderIdentifier);
798
                                }
799
                        }
800
                        // Or get the user's default upload folder
801
                        if (!$selectedFolder) {
802
                                $selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
803
                        }
804
                        // Build the file upload and folder creation form
805
                        $uploadForm = '';
806
                        $createFolder = '';
807
                        if ($selectedFolder && !$this->isReadOnlyFolder($selectedFolder)) {
808
                                $uploadForm = ($this->act === 'file') ? $this->uploadForm($selectedFolder) : '';
809
                                if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB')) {
810
                                        $createFolder = $this->createFolder($selectedFolder);
811
                                }
812
                        }
813
                        // Insert the upload form on top, if so configured
814
                        if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
815
                                $content .= $uploadForm;
816
                        }
817

    
818
                        // Render the filelist if there is a folder selected
819
                        if ($selectedFolder) {
820
                                $files = $this->expandFolder($selectedFolder, $this->P['params']['allowedExtensions']);
821
                        }
822
                        $this->doc->JScode .= $this->doc->wrapScriptTags('
823
                        Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
824
                ');
825
                        $content .= '
826
                        <!--
827
                                Wrapper table for folder tree / file/folder list:
828
                        -->
829
                                        <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkFiles">
830
                                                <tr>
831
                                                        <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':')) . $tree . '</td>
832
                                                        <td class="c-wCell" valign="top">' . $files . '</td>
833
                                                </tr>
834
                                        </table>
835
                                        <br />
836
                                        ';
837
                        // Adding create folder + upload forms if applicable
838
                        if (!$GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
839
                                $content .= $uploadForm;
840
                        }
841
                        $content .= $createFolder . '<br />';
842
                        break;
843
                case 'spec':
844
                        if (is_array($this->thisConfig['userLinks.'])) {
845
                                $subcats = array();
846
                                $v = $this->thisConfig['userLinks.'];
847
                                foreach ($v as $k2 => $value) {
848
                                        $k2i = intval($k2);
849
                                        if (substr($k2, -1) == '.' && is_array($v[$k2i . '.'])) {
850
                                                // Title:
851
                                                $title = trim($v[$k2i]);
852
                                                if (!$title) {
853
                                                        $title = $v[$k2i . '.']['url'];
854
                                                } else {
855
                                                        $title = $GLOBALS['LANG']->sL($title);
856
                                                }
857
                                                // Description:
858
                                                $description = $v[$k2i . '.']['description'] ? $GLOBALS['LANG']->sL($v[($k2i . '.')]['description'], 1) . '<br />' : '';
859
                                                // URL + onclick event:
860
                                                $onClickEvent = '';
861
                                                if (isset($v[$k2i . '.']['target'])) {
862
                                                        $onClickEvent .= 'browse_links_setTarget(\'' . $v[($k2i . '.')]['target'] . '\');';
863
                                                }
864
                                                $v[$k2i . '.']['url'] = str_replace('###_URL###', $this->siteURL, $v[$k2i . '.']['url']);
865
                                                if (substr($v[$k2i . '.']['url'], 0, 7) == 'http://' || substr($v[$k2i . '.']['url'], 0, 7) == 'mailto:') {
866
                                                        $onClickEvent .= 'cur_href=unescape(\'' . rawurlencode($v[($k2i . '.')]['url']) . '\');link_current();';
867
                                                } else {
868
                                                        $onClickEvent .= 'link_spec(unescape(\'' . $this->siteURL . rawurlencode($v[($k2i . '.')]['url']) . '\'));';
869
                                                }
870
                                                // Link:
871
                                                $A = array('<a href="#" onclick="' . htmlspecialchars($onClickEvent) . 'return false;">', '</a>');
872
                                                // Adding link to menu of user defined links:
873
                                                $subcats[$k2i] = '
874
                                                                <tr>
875
                                                                        <td class="bgColor4">' . $A[0] . '<strong>' . htmlspecialchars($title) . ($this->curUrlInfo['info'] == $v[$k2i . '.']['url'] ? '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_right.gif', 'width="5" height="9"') . ' class="c-blinkArrowR" alt="" />' : '') . '</strong><br />' . $description . $A[1] . '</td>
876
                                                                </tr>';
877
                                        }
878
                                }
879
                                // Sort by keys:
880
                                ksort($subcats);
881
                                // Add menu to content:
882
                                $content .= '
883

884
                        <!--
885
                                Special userdefined menu:
886
                        -->
887
                                                <table border="0" cellpadding="1" cellspacing="1" id="typo3-linkSpecial">
888
                                                        <tr>
889
                                                                <td class="bgColor5" class="c-wCell" valign="top"><strong>' . $GLOBALS['LANG']->getLL('special', 1) . '</strong></td>
890
                                                        </tr>
891
                                                        ' . implode('', $subcats) . '
892
                                                </table>
893
                                                ';
894
                        }
895
                        break;
896
                case 'page':
897
                        $pagetree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('rtePageTree');
898
                        $pagetree->thisScript = $this->thisScript;
899
                        $pagetree->ext_showPageId = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
900
                        $pagetree->ext_showNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
901
                        $pagetree->addField('nav_title');
902
                        $tree = $pagetree->getBrowsableTree();
903
                        $cElements = $this->expandPage();
904
                        // Outputting Temporary DB mount notice:
905
                        if (intval($GLOBALS['BE_USER']->getSessionData('pageTree_temporaryMountPoint'))) {
906
                                $link = '<a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('setTempDBmount' => 0))) . '">' . $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.temporaryDBmount', 1) . '</a>';
907
                                $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $link, '', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
908
                                $dbmount = $flashMessage->render();
909
                        }
910
                        $content .= '
911

912
                        <!--
913
                                Wrapper table for page tree / record list:
914
                        -->
915
                                        <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkPages">
916
                                                <tr>
917
                                                        <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('pageTree') . ':')) . $dbmount . $tree . '</td>
918
                                                        <td class="c-wCell" valign="top">' . $cElements . '</td>
919
                                                </tr>
920
                                        </table>
921
                                        ';
922
                        break;
923
                default:
924
                        // Call hook
925
                        foreach ($this->hookObjects as $hookObject) {
926
                                $content .= $hookObject->getTab($this->act);
927
                        }
928
                        break;
929
                }
930
                if (in_array('params', $allowedFields, TRUE)) {
931
                        $content .= '
932
                                <!--
933
                                        Selecting params for link:
934
                                -->
935
                                <form action="" name="lparamsform" id="lparamsform">
936
                                        <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkParams">
937
                                                <tr>
938
                                                        <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('params', 1) . '</td>
939
                                                        <td><input type="text" name="lparams" class="typo3-link-input" onchange="browse_links_setParams(this.value);" value="' . htmlspecialchars($this->setParams) . '" /></td>
940
                                                </tr>
941
                                        </table>
942
                                </form>
943
                        ';
944
                }
945
                if (in_array('class', $allowedFields, TRUE)) {
946
                        $content .= '
947
                                <!--
948
                                        Selecting class for link:
949
                                -->
950
                                <form action="" name="lclassform" id="lclassform">
951
                                        <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkClass">
952
                                                <tr>
953
                                                        <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('class', 1) . '</td>
954
                                                        <td><input type="text" name="lclass" class="typo3-link-input" onchange="browse_links_setClass(this.value);" value="' . htmlspecialchars($this->setClass) . '" /></td>
955
                                                </tr>
956
                                        </table>
957
                                </form>
958
                        ';
959
                }
960
                if (in_array('title', $allowedFields, TRUE)) {
961
                        $content .= '
962
                                <!--
963
                                        Selecting title for link:
964
                                -->
965
                                <form action="" name="ltitleform" id="ltitleform">
966
                                        <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTitle">
967
                                                <tr>
968
                                                        <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('title', 1) . '</td>
969
                                                        <td><input type="text" name="ltitle" class="typo3-link-input" onchange="browse_links_setTitle(this.value);" value="' . htmlspecialchars($this->setTitle) . '" /></td>
970
                                                </tr>
971
                                        </table>
972
                                </form>
973
                        ';
974
                }
975
                // additional fields for page links
976
                if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['addFields_PageLink']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['addFields_PageLink'])) {
977
                        $_params = array(
978
                                'conf' => &$conf
979
                        );
980
                        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['addFields_PageLink'] as $objRef) {
981
                                $processor =& \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($objRef);
982
                                $content .= $processor->addFields($_params, $this);
983
                        }
984
                }
985
                // Target:
986
                if ($this->act != 'mail' && in_array('target', $allowedFields, TRUE)) {
987
                        $ltarget = '
988

989
                        <!--
990
                                Selecting target for link:
991
                        -->
992
                                <form action="" name="ltargetform" id="ltargetform">
993
                                        <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTarget">
994
                                                <tr>
995
                                                        <td>' . $GLOBALS['LANG']->getLL('target', 1) . ':</td>
996
                                                        <td><input type="text" name="ltarget" onchange="browse_links_setTarget(this.value);" value="' . htmlspecialchars($this->setTarget) . '"' . $this->doc->formWidth(10) . ' /></td>
997
                                                        <td>
998
                                                                <select name="ltarget_type" onchange="browse_links_setTarget(this.options[this.selectedIndex].value);document.ltargetform.ltarget.value=this.options[this.selectedIndex].value;this.selectedIndex=0;">
999
                                                                        <option></option>
1000
                                                                        <option value="_top">' . $GLOBALS['LANG']->getLL('top', 1) . '</option>
1001
                                                                        <option value="_blank">' . $GLOBALS['LANG']->getLL('newWindow', 1) . '</option>
1002
                                                                </select>
1003
                                                        </td>
1004
                                                        <td>';
1005
                        if (($this->curUrlInfo['act'] == 'page' || $this->curUrlInfo['act'] == 'file' || $this->curUrlInfo['act'] == 'folder') && $this->curUrlArray['href'] && $this->curUrlInfo['act'] == $this->act) {
1006
                                $ltarget .= '
1007
                                                        <input type="submit" value="' . $GLOBALS['LANG']->getLL('update', 1) . '" onclick="return link_current();" />';
1008
                        }
1009
                        $selectJS = '
1010
                                if (document.ltargetform.popup_width.options[document.ltargetform.popup_width.selectedIndex].value>0 && document.ltargetform.popup_height.options[document.ltargetform.popup_height.selectedIndex].value>0) {
1011
                                        document.ltargetform.ltarget.value = document.ltargetform.popup_width.options[document.ltargetform.popup_width.selectedIndex].value+"x"+document.ltargetformbrowse_links_setTarget.popup_height.options[document.ltargetform.popup_height.selectedIndex].value;
1012
                                        browse_links_setTarget(document.ltargetform.ltarget.value);
1013
                                        browse_links_setClass(document.lclassform.lclass.value);
1014
                                        browse_links_setTitle(document.ltitleform.ltitle.value);
1015
                                        browse_links_setParams(document.lparamsform.lparams.value);
1016
                                        document.ltargetform.popup_width.selectedIndex=0;
1017
                                        document.ltargetform.popup_height.selectedIndex=0;
1018
                                }
1019
                        ';
1020
                        $ltarget .= '                </td>
1021
                                                </tr>
1022
                                                <tr>
1023
                                                        <td>' . $GLOBALS['LANG']->getLL('target_popUpWindow', 1) . ':</td>
1024
                                                        <td colspan="3">
1025
                                                                <select name="popup_width" onchange="' . htmlspecialchars($selectJS) . '">
1026
                                                                        <option value="0">' . $GLOBALS['LANG']->getLL('target_popUpWindow_width', 1) . '</option>
1027
                                                                        <option value="300">300</option>
1028
                                                                        <option value="400">400</option>
1029
                                                                        <option value="500">500</option>
1030
                                                                        <option value="600">600</option>
1031
                                                                        <option value="700">700</option>
1032
                                                                        <option value="800">800</option>
1033
                                                                </select>
1034
                                                                x
1035
                                                                <select name="popup_height" onchange="' . htmlspecialchars($selectJS) . '">
1036
                                                                        <option value="0">' . $GLOBALS['LANG']->getLL('target_popUpWindow_height', 1) . '</option>
1037
                                                                        <option value="200">200</option>
1038
                                                                        <option value="300">300</option>
1039
                                                                        <option value="400">400</option>
1040
                                                                        <option value="500">500</option>
1041
                                                                        <option value="600">600</option>
1042
                                                                </select>
1043
                                                        </td>
1044
                                                </tr>
1045
                                        </table>
1046
                                </form>';
1047
                        // Add "target selector" box to content:
1048
                        $content .= $ltarget;
1049
                        // Add some space
1050
                        $content .= '<br /><br />';
1051
                }
1052
                // End page, return content:
1053
                $content .= $this->doc->endPage();
1054
                $content = $this->doc->insertStylesAndJS($content);
1055
                return $content;
1056
        }
1057

    
1058
        /**
1059
         * TYPO3 Element Browser: Showing a page tree and allows you to browse for records
1060
         *
1061
         * @return string HTML content for the module
1062
         * @todo Define visibility
1063
         */
1064
        public function main_db() {
1065
                // Starting content:
1066
                $content = $this->doc->startPage('TBE record selector');
1067
                // Init variable:
1068
                $pArr = explode('|', $this->bparams);
1069
                // Making the browsable pagetree:
1070
                $pagetree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TBE_PageTree');
1071
                $pagetree->thisScript = $this->thisScript;
1072
                $pagetree->ext_pArrPages = !strcmp($pArr[3], 'pages') ? 1 : 0;
1073
                $pagetree->ext_showNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
1074
                $pagetree->ext_showPageId = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
1075
                $pagetree->addField('nav_title');
1076
                $tree = $pagetree->getBrowsableTree();
1077
                // Making the list of elements, if applicable:
1078
                $cElements = $this->TBE_expandPage($pArr[3]);
1079
                // Putting the things together, side by side:
1080
                $content .= '
1081

1082
                        <!--
1083
                                Wrapper table for page tree / record list:
1084
                        -->
1085
                        <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBrecords">
1086
                                <tr>
1087
                                        <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('pageTree') . ':')) . $tree . '</td>
1088
                                        <td class="c-wCell" valign="top">' . $cElements . '</td>
1089
                                </tr>
1090
                        </table>
1091
                        ';
1092
                // Add some space
1093
                $content .= '<br /><br />';
1094
                // End page, return content:
1095
                $content .= $this->doc->endPage();
1096
                $content = $this->doc->insertStylesAndJS($content);
1097
                return $content;
1098
        }
1099

    
1100
        /**
1101
         * TYPO3 Element Browser: Showing a folder tree, allowing you to browse for files.
1102
         *
1103
         * @return string HTML content for the module
1104
         * @todo Define visibility
1105
         */
1106
        public function main_file() {
1107
                // include JS files and set prefs for foldertree
1108
                $this->doc->getDragDropCode('folders');
1109
                $this->doc->JScode .= $this->doc->wrapScriptTags('
1110
                        Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
1111
                ');
1112
                // Starting content:
1113
                $content = $this->doc->startPage('TBE file selector');
1114
                // Init variable:
1115
                $pArr = explode('|', $this->bparams);
1116
                // The key number 3 of the pArr contains the "allowed" string. Disallowed is not passed to the element browser at all but only filtered out in TCEMain afterwards
1117
                $allowed = $pArr[3];
1118
                if ($allowed !== 'sys_file') {
1119
                        $allowedFileExtensions = $allowed;
1120
                }
1121
                $this->storages = $GLOBALS['BE_USER']->getFileStorages();
1122
                if (isset($allowedFileExtensions)) {
1123
                        // Create new filter object
1124
                        $filterObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Filter\\FileExtensionFilter');
1125
                        $filterObject->setAllowedFileExtensions($allowedFileExtensions);
1126
                        // Set file extension filters on all storages
1127
                        /** @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */
1128
                        foreach ($this->storages as $storage) {
1129
                                $storage->addFileAndFolderNameFilter(array($filterObject, 'filterFileList'));
1130
                        }
1131
                }
1132
                // Create upload/create folder forms, if a path is given
1133
                if ($this->expandFolder) {
1134
                        $this->selectedFolder = FALSE;
1135
                        $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
1136
                        if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
1137
                                // It's a folder
1138
                                $this->selectedFolder = $fileOrFolderObject;
1139
                        } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
1140
                                // It's a file
1141
                                // @todo: find the parent folder, right now done a bit ugly, because the file does not
1142
                                // support finding the parent folder of a file on purpose
1143
                                $folderIdentifier = dirname($fileOrFolderObject->getIdentifier());
1144
                                $this->selectedFolder = $fileOrFolderObject->getStorage()->getFolder($folderIdentifier);
1145
                        }
1146
                }
1147
                // Or get the user's default upload folder
1148
                if (!$this->selectedFolder) {
1149
                        $this->selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
1150
                }
1151
                        // Build the file upload and folder creation form
1152
                $uploadForm = '';
1153
                $createFolder = '';
1154
                if ($this->selectedFolder && !$this->isReadOnlyFolder($this->selectedFolder)) {
1155
                        $uploadForm = ($this->act === 'file') ? $this->uploadForm($this->selectedFolder) : '';
1156
                        if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB')) {
1157
                                $createFolder =  $this->createFolder($this->selectedFolder);
1158
                        }
1159
                }
1160
                if ($this->selectedFolder) {
1161
                        $uploadForm = $this->uploadForm($this->selectedFolder);
1162
                        $createFolder = $this->createFolder($this->selectedFolder);
1163
                } else {
1164
                        $uploadForm = $createFolder = '';
1165
                }
1166
                // Insert the upload form on top, if so configured
1167
                if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
1168
                        $content .= $uploadForm;
1169
                }
1170
                // Getting flag for showing/not showing thumbnails:
1171
                $noThumbs = $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInEB');
1172
                if (!$noThumbs) {
1173
                        // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
1174
                        $_MOD_MENU = array('displayThumbs' => '');
1175
                        $_MCONF['name'] = 'file_list';
1176
                        $_MOD_SETTINGS = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleData($_MOD_MENU, \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('SET'), $_MCONF['name']);
1177
                }
1178
                $noThumbs = $noThumbs ? $noThumbs : !$_MOD_SETTINGS['displayThumbs'];
1179
                // Create folder tree:
1180
                $foldertree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TBE_FolderTree');
1181
                $foldertree->thisScript = $this->thisScript;
1182
                $foldertree->ext_noTempRecyclerDirs = $this->mode == 'filedrag';
1183
                $tree = $foldertree->getBrowsableTree();
1184
                list(, , $specUid) = explode('_', $this->PM);
1185
                if ($this->mode == 'filedrag') {
1186
                        $files = $this->TBE_dragNDrop($this->selectedFolder, $pArr[3]);
1187
                } else {
1188
                        $files = $this->TBE_expandFolder($this->selectedFolder, $pArr[3], $noThumbs);
1189
                }
1190
                // Putting the parts together, side by side:
1191
                $content .= '
1192

1193
                        <!--
1194
                                Wrapper table for folder tree / file list:
1195
                        -->
1196
                        <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBfiles">
1197
                                <tr>
1198
                                        <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':')) . $tree . '</td>
1199
                                        <td class="c-wCell" valign="top">' . $files . '</td>
1200
                                </tr>
1201
                        </table>
1202
                        ';
1203
                // Adding create folder + upload forms if applicable:
1204
                if (!$GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
1205
                        $content .= $uploadForm;
1206
                }
1207
                $content .= $createFolder;
1208
                // Add some space
1209
                $content .= '<br /><br />';
1210
                // Setup indexed elements:
1211
                $this->doc->JScode .= $this->doc->wrapScriptTags('BrowseLinks.addElements(' . json_encode($this->elements) . ');');
1212
                // Ending page, returning content:
1213
                $content .= $this->doc->endPage();
1214
                $content = $this->doc->insertStylesAndJS($content);
1215
                return $content;
1216
        }
1217

    
1218
        /**
1219
         * TYPO3 Element Browser: Showing a folder tree, allowing you to browse for folders.
1220
         *
1221
         * @return string HTML content for the module
1222
         * @todo Define visibility
1223
         */
1224
        public function main_folder() {
1225
                // include JS files
1226
                $this->doc->getDragDropCode('folders');
1227
                // Setting prefs for foldertree
1228
                $this->doc->JScode .= $this->doc->wrapScriptTags('
1229
                        Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
1230
                ');
1231
                // Starting content:
1232
                $content = $this->doc->startPage('TBE folder selector');
1233
                // Init variable:
1234
                $parameters = explode('|', $this->bparams);
1235
                if ($this->expandFolder) {
1236
                        $this->selectedFolder = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($this->expandFolder);
1237
                }
1238
                if ($this->selectedFolder && !$this->isReadOnlyFolder($this->selectedFolder)) {
1239
                        $createFolder = $this->createFolder($this->selectedFolder);
1240
                } else {
1241
                        $createFolder = '';
1242
                }
1243
                // Or get the user's default upload folder
1244
                if (!$this->selectedFolder) {
1245
                        $this->selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
1246
                }
1247
                // Create folder tree:
1248
                $foldertree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TBE_FolderTree');
1249
                $foldertree->thisScript = $this->thisScript;
1250
                $foldertree->ext_noTempRecyclerDirs = $this->mode == 'filedrag';
1251
                $tree = $foldertree->getBrowsableTree(FALSE);
1252
                list(, , $specUid) = explode('_', $this->PM);
1253
                if ($this->mode == 'filedrag') {
1254
                        $folders = $this->TBE_dragNDrop($this->selectedFolder, $parameters[3]);
1255
                } else {
1256
                        $folders = $this->TBE_expandSubFolders($this->selectedFolder);
1257
                }
1258
                // Putting the parts together, side by side:
1259
                $content .= '
1260

1261
                        <!--
1262
                                Wrapper table for folder tree / folder list:
1263
                        -->
1264
                        <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBfiles">
1265
                                <tr>
1266
                                        <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':')) . $tree . '</td>
1267
                                        <td class="c-wCell" valign="top">' . $folders . '</td>
1268
                                </tr>
1269
                        </table>
1270
                        ';
1271
                // Adding create folder if applicable:
1272
                if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB')) {
1273
                        $content .= $createFolder;
1274
                }
1275
                // Add some space
1276
                $content .= '<br /><br />';
1277
                // Ending page, returning content:
1278
                $content .= $this->doc->endPage();
1279
                $content = $this->doc->insertStylesAndJS($content);
1280
                return $content;
1281
        }
1282

    
1283
        /******************************************************************
1284
         *
1285
         * Record listing
1286
         *
1287
         ******************************************************************/
1288
        /**
1289
         * For RTE: This displays all content elements on a page and lets you create a link to the element.
1290
         *
1291
         * @return string HTML output. Returns content only if the ->expandPage value is set (pointing to a page uid to show tt_content records from ...)
1292
         * @todo Define visibility
1293
         */
1294
        public function expandPage() {
1295
                $out = '';
1296
                // Set page id (if any) to expand
1297
                $expPageId = $this->expandPage;
1298
                // If there is an anchor value (content element reference) in the element reference, then force an ID to expand:
1299
                if (!$this->expandPage && $this->curUrlInfo['cElement']) {
1300
                        // Set to the current link page id.
1301
                        $expPageId = $this->curUrlInfo['pageid'];
1302
                }
1303
                // Draw the record list IF there is a page id to expand:
1304
                if ($expPageId && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($expPageId) && $GLOBALS['BE_USER']->isInWebMount($expPageId)) {
1305
                        // Set header:
1306
                        $out .= $this->barheader($GLOBALS['LANG']->getLL('contentElements') . ':');
1307
                        // Create header for listing, showing the page title/icon:
1308
                        $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
1309
                        $mainPageRec = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL('pages', $expPageId);
1310
                        $picon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', $mainPageRec);
1311
                        $picon .= \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle('pages', $mainPageRec, TRUE);
1312
                        $out .= $picon . '<br />';
1313
                        // Look up tt_content elements from the expanded page:
1314
                        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,header,hidden,starttime,endtime,fe_group,CType,colPos,bodytext', 'tt_content', 'pid=' . intval($expPageId) . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tt_content') . \TYPO3\CMS\Backend\Utility\BackendUtility::versioningPlaceholderClause('tt_content'), '', 'colPos,sorting');
1315
                        $cc = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
1316
                        // Traverse list of records:
1317
                        $c = 0;
1318
                        while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1319
                                $c++;
1320
                                $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('tt_content', $row);
1321
                                if ($this->curUrlInfo['act'] == 'page' && $this->curUrlInfo['cElement'] == $row['uid']) {
1322
                                        $arrCol = '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif', 'width="5" height="9"') . ' class="c-blinkArrowL" alt="" />';
1323
                                } else {
1324
                                        $arrCol = '';
1325
                                }
1326
                                // Putting list element HTML together:
1327
                                $out .= '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/ol/join' . ($c == $cc ? 'bottom' : '') . '.gif'), 'width="18" height="16"') . ' alt="" />' . $arrCol . '<a href="#" onclick="return link_typo3Page(\'' . $expPageId . '\',\'#' . $row['uid'] . '\');">' . $icon . \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle('tt_content', $row, TRUE) . '</a><br />';
1328
                                // Finding internal anchor points:
1329
                                if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('text,textpic', $row['CType'])) {
1330
                                        $split = preg_split('/(<a[^>]+name=[\'"]?([^"\'>[:space:]]+)[\'"]?[^>]*>)/i', $row['bodytext'], -1, PREG_SPLIT_DELIM_CAPTURE);
1331
                                        foreach ($split as $skey => $sval) {
1332
                                                if ($skey % 3 == 2) {
1333
                                                        // Putting list element HTML together:
1334
                                                        $sval = substr($sval, 0, 100);
1335
                                                        $out .= '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/ol/line.gif', 'width="18" height="16"') . ' alt="" />' . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/ol/join' . ($skey + 3 > count($split) ? 'bottom' : '') . '.gif'), 'width="18" height="16"') . ' alt="" />' . '<a href="#" onclick="return link_typo3Page(\'' . $expPageId . '\',\'#' . rawurlencode($sval) . '\');">' . htmlspecialchars((' <A> ' . $sval)) . '</a><br />';
1336
                                                }
1337
                                        }
1338
                                }
1339
                        }
1340
                }
1341
                return $out;
1342
        }
1343

    
1344
        /**
1345
         * For TYPO3 Element Browser: This lists all content elements from the given list of tables
1346
         *
1347
         * @param string $tables Commalist of tables. Set to "*" if you want all tables.
1348
         * @return string HTML output.
1349
         * @todo Define visibility
1350
         */
1351
        public function TBE_expandPage($tables) {
1352
                $out = '';
1353
                if ($this->expandPage >= 0 && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->expandPage) && $GLOBALS['BE_USER']->isInWebMount($this->expandPage)) {
1354
                        // Set array with table names to list:
1355
                        if (!strcmp(trim($tables), '*')) {
1356
                                $tablesArr = array_keys($GLOBALS['TCA']);
1357
                        } else {
1358
                                $tablesArr = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $tables, 1);
1359
                        }
1360
                        reset($tablesArr);
1361
                        // Headline for selecting records:
1362
                        $out .= $this->barheader($GLOBALS['LANG']->getLL('selectRecords') . ':');
1363
                        // Create the header, showing the current page for which the listing is. Includes link to the page itself, if pages are amount allowed tables.
1364
                        $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
1365
                        $mainPageRec = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL('pages', $this->expandPage);
1366
                        $ATag = '';
1367
                        $ATag_e = '';
1368
                        $ATag2 = '';
1369
                        $picon = '';
1370
                        if (is_array($mainPageRec)) {
1371
                                $picon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', $mainPageRec);
1372
                                if (in_array('pages', $tablesArr)) {
1373
                                        $ATag = '<a href="#" onclick="return insertElement(\'pages\', \'' . $mainPageRec['uid'] . '\', \'db\', ' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($mainPageRec['title']) . ', \'\', \'\', \'\',\'\',1);">';
1374
                                        $ATag2 = '<a href="#" onclick="return insertElement(\'pages\', \'' . $mainPageRec['uid'] . '\', \'db\', ' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($mainPageRec['title']) . ', \'\', \'\', \'\',\'\',0);">';
1375
                                        $ATag_alt = substr($ATag, 0, -4) . ',\'\',1);">';
1376
                                        $ATag_e = '</a>';
1377
                                }
1378
                        }
1379
                        $pBicon = $ATag2 ? '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif', 'width="18" height="16"') . ' alt="" />' : '';
1380
                        $pText = htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($mainPageRec['title'], $titleLen));
1381
                        $out .= $picon . $ATag2 . $pBicon . $ATag_e . $ATag . $pText . $ATag_e . '<br />';
1382
                        // Initialize the record listing:
1383
                        $id = $this->expandPage;
1384
                        $pointer = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
1385
                        $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
1386
                        $pageinfo = \TYPO3\CMS\Backend\Utility\BackendUtility::readPageAccess($id, $perms_clause);
1387
                        $table = '';
1388
                        // Generate the record list:
1389
                        /** @var $dblist \TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList */
1390
                        $dblist = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\RecordList\\ElementBrowserRecordList');
1391
                        $dblist->thisScript = $this->thisScript;
1392
                        $dblist->backPath = $GLOBALS['BACK_PATH'];
1393
                        $dblist->thumbs = 0;
1394
                        $dblist->calcPerms = $GLOBALS['BE_USER']->calcPerms($pageinfo);
1395
                        $dblist->noControlPanels = 1;
1396
                        $dblist->clickMenuEnabled = 0;
1397
                        $dblist->tableList = implode(',', $tablesArr);
1398
                        $pArr = explode('|', $this->bparams);
1399
                        // a string like "data[pages][79][storage_pid]"
1400
                        $fieldPointerString = $pArr[0];
1401
                        // parts like: data, pages], 79], storage_pid]
1402
                        $fieldPointerParts = explode('[', $fieldPointerString);
1403
                        $relatingTableName = substr($fieldPointerParts[1], 0, -1);
1404
                        $relatingFieldName = substr($fieldPointerParts[3], 0, -1);
1405
                        if ($relatingTableName && $relatingFieldName) {
1406
                                $dblist->setRelatingTableAndField($relatingTableName, $relatingFieldName);
1407
                        }
1408
                        $dblist->start($id, \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('table'), $pointer, \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('search_field'), \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('search_levels'), \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('showLimit'));
1409
                        $dblist->setDispFields();
1410
                        $dblist->generateList();
1411
                        $dblist->writeBottom();
1412
                        //        Add the HTML for the record list to output variable:
1413
                        $out .= $dblist->HTMLcode;
1414
                        // Add support for fieldselectbox in singleTableMode
1415
                        if ($dblist->table) {
1416
                                $out .= $dblist->fieldSelectBox($dblist->table);
1417
                        }
1418
                        $out .= $dblist->getSearchBox();
1419
                }
1420
                // Return accumulated content:
1421
                return $out;
1422
        }
1423

    
1424
        /**
1425
         * Render list of folders inside a folder.
1426
         *
1427
         * @param string $folder String of the current folder
1428
         * @return string HTML output
1429
         * @todo Define visibility
1430
         */
1431
        public function TBE_expandSubFolders(\TYPO3\CMS\Core\Resource\Folder $folder) {
1432
                $content = '';
1433
                if ($folder->checkActionPermission('read')) {
1434
                        $content .= $this->folderList($folder);
1435
                }
1436
                // Return accumulated content for folderlisting:
1437
                return $content;
1438
        }
1439

    
1440
        /******************************************************************
1441
         *
1442
         * File listing
1443
         *
1444
         ******************************************************************/
1445
        /**
1446
         * For RTE: This displays all files from folder. No thumbnails shown
1447
         *
1448
         * @param string $folder The folder path to expand
1449
         * @param string $extensionList List of fileextensions to show
1450
         * @return string HTML output
1451
         * @todo Define visibility
1452
         */
1453
        public function expandFolder(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList = '') {
1454
                $out = '';
1455
                $renderFolders = $this->act === 'folder';
1456
                if ($folder->checkActionPermission('read')) {
1457
                        // Create header for filelisting:
1458
                        $out .= $this->barheader($GLOBALS['LANG']->getLL('files') . ':');
1459
                        // Prepare current path value for comparison (showing red arrow)
1460
                        $currentIdentifier = '';
1461
                        if ($this->curUrlInfo['value']) {
1462
                                $currentIdentifier = $this->curUrlInfo['info'];
1463
                        }
1464
                        // Create header element; The folder from which files are listed.
1465
                        $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
1466
                        $folderIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile('folder');
1467
                        $folderIcon .= htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen));
1468
                        $picon = '<a href="#" onclick="return link_folder(\'file:' . $folder->getCombinedIdentifier() . '\');">' . $folderIcon . '</a>';
1469
                        if ($this->curUrlInfo['act'] == 'folder' && $currentIdentifier == $folder->getCombinedIdentifier()) {
1470
                                $out .= '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif', 'width="5" height="9"') . ' class="c-blinkArrowL" alt="" />';
1471
                        }
1472
                        $out .= $picon . '<br />';
1473
                        // Get files from the folder:
1474
                        if ($renderFolders) {
1475
                                $items = $folder->getSubfolders();
1476
                        } else {
1477
                                $filter = new \TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter();
1478
                                $filter->setAllowedFileExtensions($extensionList);
1479
                                $folder->getStorage()->setFileAndFolderNameFilters(array(array($filter, 'filterFileList')));
1480

    
1481
                                $items = $folder->getFiles();
1482
                        }
1483
                        $c = 0;
1484
                        $totalItems = count($items);
1485
                        foreach ($items as $fileOrFolderObject) {
1486
                                $c++;
1487
                                if ($renderFolders) {
1488
                                        $fileIdentifier = $fileOrFolderObject->getCombinedIdentifier();
1489
                                        $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile('folder');
1490
                                        $itemUid = 'file:' . $fileIdentifier;
1491
                                } else {
1492
                                        $fileIdentifier = $fileOrFolderObject->getUid();
1493
                                        // File icon:
1494
                                        $fileExtension = $fileOrFolderObject->getExtension();
1495
                                        // Get size and icon:
1496
                                        $size = ' (' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($fileOrFolderObject->getSize()) . 'bytes)';
1497
                                        $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileOrFolderObject->getName() . $size));
1498
                                        $itemUid = 'file:' . $fileIdentifier;
1499
                                }
1500
                                // If the listed file turns out to be the CURRENT file, then show blinking arrow:
1501
                                if (($this->curUrlInfo['act'] == 'file' || $this->curUrlInfo['act'] == 'folder') && $currentIdentifier == $fileIdentifier) {
1502
                                        $arrCol = '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif', 'width="5" height="9"') . ' class="c-blinkArrowL" alt="" />';
1503
                                } else {
1504
                                        $arrCol = '';
1505
                                }
1506
                                // Put it all together for the file element:
1507
                                $out .= '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/ol/join' . ($c == $totalItems ? 'bottom' : '') . '.gif'), 'width="18" height="16"') . ' alt="" />' . $arrCol . '<a href="#" onclick="return link_folder(\'' . $itemUid . '\');">' . $icon . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($fileOrFolderObject->getName(), $titleLen)) . '</a><br />';
1508
                        }
1509
                }
1510
                return $out;
1511
        }
1512

    
1513
        /**
1514
         * For TYPO3 Element Browser: Expand folder of files.
1515
         *
1516
         * @param \TYPO3\CMS\Core\Resource\Folder $folder The folder path to expand
1517
         * @param string $extensionList List of fileextensions to show
1518
         * @param boolean $noThumbs Whether to show thumbnails or not. If set, no thumbnails are shown.
1519
         * @return string HTML output
1520
         * @todo Define visibility
1521
         */
1522
        public function TBE_expandFolder(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList = '', $noThumbs = 0) {
1523
                $extensionList = $extensionList == '*' ? '' : $extensionList;
1524
                $content = '';
1525
                if ($folder->checkActionPermission('read')) {
1526
                        // Listing the files:
1527
                        $files = $folder->getFiles($extensionList);
1528
                        $content = $this->fileList($files, $folder, $noThumbs);
1529
                }
1530
                // Return accumulated content for filelisting:
1531
                return $content;
1532
        }
1533

    
1534
        /**
1535
         * Render list of files.
1536
         *
1537
         * @param array $files List of files. See \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir
1538
         * @param string \TYPO3\CMS\Core\Resource\Folder $folder If set a header with a folder icon and folder name are shown
1539
         * @param boolean $noThumbs Whether to show thumbnails or not. If set, no thumbnails are shown.
1540
         * @return string HTML output
1541
         * @todo Define visibility
1542
         */
1543
        public function fileList(array $files, \TYPO3\CMS\Core\Resource\Folder $folder = NULL, $noThumbs = 0) {
1544
                $out = '';
1545
                // Listing the files:
1546
                if (is_array($files)) {
1547
                        $lines = array();
1548
                        // Create headline (showing number of files):
1549
                        $filesCount = count($files);
1550
                        $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', $filesCount));
1551
                        $out .= '<div id="filelist">';
1552
                        $out .= $this->getBulkSelector($filesCount);
1553
                        $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
1554
                        // Create the header of current folder:
1555
                        if ($folder) {
1556
                                $folderIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile('folder');
1557
                                $lines[] = '<tr class="t3-row-header">
1558
                                        <td colspan="4">' . $folderIcon . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen)) . '</td>
1559
                                </tr>';
1560
                        }
1561
                        if ($filesCount == 0) {
1562
                                $lines[] = '
1563
                                        <tr class="file_list_normal">
1564
                                                <td colspan="4">No files found.</td>
1565
                                        </tr>';
1566
                        }
1567
                        // Init graphic object for reading file dimensions:
1568
                        /** @var $imgObj \TYPO3\CMS\Core\Imaging\GraphicalFunctions */
1569
                        $imgObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Imaging\\GraphicalFunctions');
1570
                        $imgObj->init();
1571
                        $imgObj->mayScaleUp = 0;
1572
                        $imgObj->tempPath = PATH_site . $imgObj->tempPath;
1573
                        // Traverse the file list:
1574
                        foreach ($files as $fileObject) {
1575
                                $fileExtension = $fileObject->getExtension();
1576
                                // Thumbnail/size generation:
1577
                                if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList(strtolower($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']), strtolower($fileExtension)) && !$noThumbs) {
1578
                                        $imageUrl = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => 64, 'height' => 64))->getPublicUrl(TRUE);
1579
                                        $imgInfo = $imgObj->getImageDimensions($fileObject->getForLocalProcessing(FALSE));
1580
                                        $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
1581
                                        $clickIcon = '<img src="' . $imageUrl . '" hspace="5" vspace="5" border="1"';
1582
                                } else {
1583
                                        $clickIcon = '';
1584
                                        $pDim = '';
1585
                                }
1586
                                // Create file icon:
1587
                                $size = ' (' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
1588
                                $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName() . $size));
1589
                                // Create links for adding the file:
1590
                                $filesIndex = count($this->elements);
1591
                                $this->elements['file_' . $filesIndex] = array(
1592
                                        'type' => 'file',
1593
                                        'table' => 'sys_file',
1594
                                        'uid' => $fileObject->getUid(),
1595
                                        'fileName' => $fileObject->getName(),
1596
                                        'filePath' => $fileObject->getUid(),
1597
                                        'fileExt' => $fileExtension,
1598
                                        'fileIcon' => $icon
1599
                                );
1600
                                $ATag = '<a href="#" onclick="return BrowseLinks.File.insertElement(\'file_' . $filesIndex . '\');">';
1601
                                $ATag_alt = substr($ATag, 0, -4) . ',1);">';
1602
                                $bulkCheckBox = '<input type="checkbox" class="typo3-bulk-item" name="file_' . $filesIndex . '" value="0" /> ';
1603
                                $ATag_e = '</a>';
1604
                                // Create link to showing details about the file in a window:
1605
                                $Ahref = $GLOBALS['BACK_PATH'] . 'show_item.php?type=file&table=_FILE&uid=' . rawurlencode($fileObject->getCombinedIdentifier()) . '&returnUrl=' . rawurlencode(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'));
1606
                                $ATag2 = '<a href="' . htmlspecialchars($Ahref) . '">';
1607
                                $ATag2_e = '</a>';
1608
                                // Combine the stuff:
1609
                                $filenameAndIcon = $bulkCheckBox . $ATag_alt . $icon . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($fileObject->getName(), $titleLen)) . $ATag_e;
1610
                                // Show element:
1611
                                // Image...
1612
                                if ($pDim) {
1613
                                        $lines[] = '
1614
                                                <tr class="file_list_normal">
1615
                                                        <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
1616
                                                        <td>' . $ATag . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif', 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', 1) . '" alt="" />' . $ATag_e . '</td>
1617
                                                        <td nowrap="nowrap">' . ($ATag2 . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/zoom2.gif', 'width="12" height="12"') . ' title="' . $GLOBALS['LANG']->getLL('info', 1) . '" alt="" /> ' . $GLOBALS['LANG']->getLL('info', 1) . $ATag2_e) . '</td>
1618
                                                        <td nowrap="nowrap">&nbsp;' . $pDim . '</td>
1619
                                                </tr>';
1620
                                        $lines[] = '
1621
                                                <tr>
1622
                                                        <td class="filelistThumbnail" colspan="4">' . $ATag_alt . $clickIcon . $ATag_e . '</td>
1623
                                                </tr>';
1624
                                } else {
1625
                                        $lines[] = '
1626
                                                <tr class="file_list_normal">
1627
                                                        <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
1628
                                                        <td>' . $ATag . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif', 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', 1) . '" alt="" />' . $ATag_e . '</td>
1629
                                                        <td nowrap="nowrap">' . ($ATag2 . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/zoom2.gif', 'width="12" height="12"') . ' title="' . $GLOBALS['LANG']->getLL('info', 1) . '" alt="" /> ' . $GLOBALS['LANG']->getLL('info', 1) . $ATag2_e) . '</td>
1630
                                                        <td>&nbsp;</td>
1631
                                                </tr>';
1632
                                }
1633
                        }
1634
                        // Wrap all the rows in table tags:
1635
                        $out .= '
1636

1637
                <!--
1638
                        File listing
1639
                -->
1640
                                <table cellpadding="0" cellspacing="0" id="typo3-filelist">
1641
                                        ' . implode('', $lines) . '
1642
                                </table>';
1643
                }
1644
                // Return accumulated content for filelisting:
1645
                $out .= '</div>';
1646
                return $out;
1647
        }
1648

    
1649
        /**
1650
         * Render list of folders.
1651
         *
1652
         * @param string \TYPO3\CMS\Core\Resource\Folder $folder List content of this folder
1653
         * @return string HTML output
1654
         * @todo Define visibility
1655
         */
1656
        public function folderList(\TYPO3\CMS\Core\Resource\Folder $folder) {
1657
                $content = '';
1658
                if ($folder) {
1659
                        $subfolders = $folder->getSubfolders();
1660
                        // Create headline (showing number of folders):
1661
                        $content .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('folders') . ' (%s):', count($subfolders)));
1662
                        $titleLength = intval($GLOBALS['BE_USER']->uc['titleLen']);
1663
                        $encodedPublicUrl = rawurlencode($folder->getPublicUrl());
1664
                        $aTag = '<a href="#" onclick="return insertElement(\'\',\'' . $encodedPublicUrl . '\', \'folder\', \'' . $encodedPublicUrl . '\', unescape(\'' . $encodedPublicUrl . '\'), \'\', \'\');">';
1665
                        $aTag_alt = substr($aTag, 0, -4) . ',\'\',1);">';
1666
                        $aTag_e = '</a>';
1667
                        // Add the foder icon
1668
                        $folderIcon = $aTag_alt;
1669
                        $folderIcon .= '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif', 'width="18" height="16"') . ' alt="" />';
1670
                        $folderIcon .= htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs(basename($folder->getName()), $titleLength));
1671
                        $folderIcon .= $aTag_e;
1672
                        $content .= $folderIcon . '<br />';
1673
                        
1674
                        // Listing the folders:
1675
                        if (count($subfolders) > 0) {
1676
                                // Traverse the folder list:
1677
                                $lines = array();
1678
                                foreach ($subfolders as $subfolder) {
1679
                                        // Create folder icon:
1680
                                        $icon = '<img src="clear.gif" width="16" height="16" alt="" /><img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif', 'width="16" height="16"') . ' title="' . htmlspecialchars($subfolder->getName()) . '" class="absmiddle" alt="" />';
1681
                                        // Create links for adding the folder:
1682
                                        $encodedPublicUrl = rawurlencode($subfolder->getPublicUrl());
1683
                                        if ($this->P['itemName'] != '' && $this->P['formName'] != '') {
1684
                                                $aTag = '<a href="#" onclick="return set_folderpath(unescape(\'' . $encodedPublicUrl . '\'));">';
1685
                                        } else {
1686
                                                $aTag = '<a href="#" onclick="return insertElement(\'\',\'' . $encodedPublicUrl . '\', \'folder\', \'' . $encodedPublicUrl . '\', unescape(\'' . $encodedPublicUrl . '\'), \'\', \'\');">';
1687
                                        }
1688
                                        $aTag_alt = substr($aTag, 0, -4) . ',\'\',1);">';
1689
                                        $aTag_e = '</a>';
1690
                                        // Combine icon and folderpath:
1691
                                        $foldernameAndIcon = $aTag_alt . $icon . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($subfolder->getName(), $titleLength)) . $aTag_e;
1692
                                        if ($this->P['itemName'] != '') {
1693
                                                $lines[] = '
1694
                                                        <tr class="bgColor4">
1695
                                                                <td nowrap="nowrap">' . $foldernameAndIcon . '&nbsp;</td>
1696
                                                                <td>&nbsp;</td>
1697
                                                        </tr>';
1698
                                        } else {
1699
                                                $lines[] = '
1700
                                                        <tr class="bgColor4">
1701
                                                                <td nowrap="nowrap">' . $foldernameAndIcon . '&nbsp;</td>
1702
                                                                <td>' . $aTag . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif', 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', 1) . '" alt="" />' . $aTag_e . ' </td>
1703
                                                                <td>&nbsp;</td>
1704
                                                        </tr>';
1705
                                        }
1706
                                        $lines[] = '
1707
                                                <tr>
1708
                                                        <td colspan="3"><img src="clear.gif" width="1" height="3" alt="" /></td>
1709
                                                </tr>';
1710
                                }
1711
                        }
1712
                        // Wrap all the rows in table tags:
1713
                        $content .= '
1714

1715
        <!--
1716
                Folder listing
1717
        -->
1718
                        <table border="0" cellpadding="0" cellspacing="1" id="typo3-folderList">
1719
                                ' . implode('', $lines) . '
1720
                        </table>';
1721
                }
1722
                // Return accumulated content for folderlisting:
1723
                return $content;
1724
        }
1725

    
1726
        /**
1727
         * For RTE: This displays all IMAGES (gif,png,jpg) (from extensionList) from folder. Thumbnails are shown for images.
1728
         * This listing is of images located in the web-accessible paths ONLY - the listing is for drag-n-drop use in the RTE
1729
         *
1730
         * @param \TYPO3\CMS\Core\Resource\Folder $folder The folder path to expand
1731
         * @param string $extensionList List of fileextensions to show
1732
         * @return string HTML output
1733
         * @todo Define visibility
1734
         */
1735
        public function TBE_dragNDrop(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList = '') {
1736
                $extensionList = $extensionList == '*' ? '' : $extensionList;
1737
                $out = '';
1738
                if ($folder) {
1739
                        if ($folder->getStorage()->isPublic()) {
1740
                                // Read files from directory:
1741
                                $files = $folder->getFiles($extensionList);
1742
                                if (is_array($files)) {
1743
                                        $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', count($files)));
1744
                                        $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
1745
                                        $picon = '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif', 'width="18" height="16"') . ' alt="" />';
1746
                                        $picon .= htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs(basename($folder->getName()), $titleLen));
1747
                                        $out .= $picon . '<br />';
1748
                                        // Init row-array:
1749
                                        $lines = array();
1750
                                        // Add "drag-n-drop" message:
1751
                                        $lines[] = '
1752
                                                <tr>
1753
                                                        <td colspan="2">' . $this->getMsgBox($GLOBALS['LANG']->getLL('findDragDrop')) . '</td>
1754
                                                </tr>';
1755
                                        // Traverse files:
1756
                                        foreach ($files as $fileObject) {
1757
                                                $fileInfo = $fileObject->getStorage()->getFileInfo($fileObject);
1758
                                                // URL of image:
1759
                                                $iUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::rawurlencodeFP($fileObject->getPublicUrl(TRUE));
1760
                                                // Show only web-images
1761
                                                $fileExtension = strtolower($fileObject->getExtension());
1762
                                                if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('gif,jpeg,jpg,png', $fileExtension)) {
1763
                                                        $imgInfo = @getimagesize($fileObject->getForLocalProcessing(FALSE));
1764
                                                        $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
1765
                                                        $size = ' (' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
1766
                                                        $filenameAndIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName() . $size));
1767
                                                        if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('noLimit')) {
1768
                                                                $maxW = 10000;
1769
                                                                $maxH = 10000;
1770
                                                        } else {
1771
                                                                $maxW = 380;
1772
                                                                $maxH = 500;
1773
                                                        }
1774
                                                        $IW = $imgInfo[0];
1775
                                                        $IH = $imgInfo[1];
1776
                                                        if ($IW > $maxW) {
1777
                                                                $IH = ceil($IH / $IW * $maxW);
1778
                                                                $IW = $maxW;
1779
                                                        }
1780
                                                        if ($IH > $maxH) {
1781
                                                                $IW = ceil($IW / $IH * $maxH);
1782
                                                                $IH = $maxH;
1783
                                                        }
1784
                                                        // Make row:
1785
                                                        $lines[] = '
1786
                                                                <tr class="bgColor4">
1787
                                                                        <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
1788
                                                                        <td nowrap="nowrap">' . ($imgInfo[0] != $IW ? '<a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('noLimit' => '1'))) . '">' . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/icon_warning2.gif', 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('clickToRedrawFullSize', 1) . '" alt="" />' . '</a>' : '') . $pDim . '&nbsp;</td>
1789
                                                                </tr>';
1790
                                                        $lines[] = '
1791
                                                                <tr>
1792
                                                                        <td colspan="2"><img src="' . $iUrl . '" data-htmlarea-file-uid="' . $fileObject->getUid() . '" width="' . $IW . '" height="' . $IH . '" border="1" alt="" /></td>
1793
                                                                </tr>';
1794
                                                        $lines[] = '
1795
                                                                <tr>
1796
                                                                        <td colspan="2"><img src="clear.gif" width="1" height="3" alt="" /></td>
1797
                                                                </tr>';
1798
                                                }
1799
                                        }
1800
                                        // Finally, wrap all rows in a table tag:
1801
                                        $out .= '
1802

1803

1804
                        <!--
1805
                                File listing / Drag-n-drop
1806
                        -->
1807
                                                <table border="0" cellpadding="0" cellspacing="1" id="typo3-dragBox">
1808
                                                        ' . implode('', $lines) . '
1809
                                                </table>';
1810
                                }
1811
                        } else {
1812
                                // Print this warning if the folder is NOT a web folder:
1813
                                $out .= $this->barheader($GLOBALS['LANG']->getLL('files'));
1814
                                $out .= $this->getMsgBox($GLOBALS['LANG']->getLL('noWebFolder'), 'icon_warning2');
1815
                        }
1816
                }
1817
                return $out;
1818
        }
1819

    
1820
        /******************************************************************
1821
         *
1822
         * Miscellaneous functions
1823
         *
1824
         ******************************************************************/
1825
        /**
1826
         * Verifies that a path is a web-folder:
1827
         *
1828
         * @param string $folder Absolute filepath
1829
         * @return boolean If the input path is found in PATH_site then it returns TRUE.
1830
         * @todo Define visibility
1831
         */
1832
        public function isWebFolder($folder) {
1833
                $folder = rtrim($folder, '/') . '/';
1834
                return \TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($folder, PATH_site) ? TRUE : FALSE;
1835
        }
1836

    
1837
        /**
1838
         * Checks, if a path is within the mountpoints of the backend user
1839
         *
1840
         * @param string $folder Absolute filepath
1841
         * @return boolean If the input path is found in the backend users filemounts, then return TRUE.
1842
         * @todo Define visibility
1843
         */
1844
        public function checkFolder($folder) {
1845
                return $this->fileProcessor->checkPathAgainstMounts(rtrim($folder, '/') . '/') ? TRUE : FALSE;
1846
        }
1847

    
1848
        /**
1849
         * Checks, if a path is within a read-only mountpoint of the backend user
1850
         *
1851
         * @param string $folder Absolute filepath
1852
         * @return boolean If the input path is found in the backend users filemounts and if the filemount is of type readonly, then return TRUE.
1853
         * @todo Define visibility
1854
         */
1855
        public function isReadOnlyFolder($folder) {
1856
                return $GLOBALS['FILEMOUNTS'][$this->fileProcessor->checkPathAgainstMounts(rtrim($folder, '/') . '/')]['type'] == 'readonly';
1857
        }
1858

    
1859
        /**
1860
         * Prints a 'header' where string is in a tablecell
1861
         *
1862
         * @param string $str The string to print in the header. The value is htmlspecialchars()'ed before output.
1863
         * @return string The header HTML (wrapped in a table)
1864
         * @todo Define visibility
1865
         */
1866
        public function barheader($str) {
1867
                return '
1868
                        <!-- Bar header: -->
1869
                        <h3>' . htmlspecialchars($str) . '</h3>
1870
                        ';
1871
        }
1872

    
1873
        /**
1874
         * Displays a message box with the input message
1875
         *
1876
         * @param string $in_msg Input message to show (will be htmlspecialchars()'ed inside of this function)
1877
         * @param string $icon Icon filename body from gfx/ (default is "icon_note") - meant to allow change to warning type icons...
1878
         * @return string HTML for the message (wrapped in a table).
1879
         * @todo Define visibility
1880
         */
1881
        public function getMsgBox($in_msg, $icon = 'icon_note') {
1882
                $msg = '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/' . $icon . '.gif'), 'width="18" height="16"') . ' alt="" />' . htmlspecialchars($in_msg);
1883
                $msg = '
1884

1885
                        <!--
1886
                                Message box:
1887
                        -->
1888
                        <table cellspacing="0" class="bgColor4" id="typo3-msgBox">
1889
                                <tr>
1890
                                        <td>' . $msg . '</td>
1891
                                </tr>
1892
                        </table>
1893
                        ';
1894
                return $msg;
1895
        }
1896

    
1897
        /**
1898
         * For RTE/link: This prints the 'currentUrl'
1899
         *
1900
         * @param string $str URL value. The value is htmlspecialchars()'ed before output.
1901
         * @return string HTML content, wrapped in a table.
1902
         * @todo Define visibility
1903
         */
1904
        public function printCurrentUrl($str) {
1905
                // Output the folder or file identifier, when working with files
1906
                if ($str && $this->act == 'file' || $this->act == 'folder') {
1907
                        try {
1908
                                $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($str);
1909
                                if (is_object($fileObject)) {
1910
                                        $str = $fileObject->getIdentifier();
1911
                                }
1912
                        } catch (\TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException $e) {
1913
                                $str = '';
1914
                        }
1915
                }
1916
                if (strlen($str)) {
1917
                        return '
1918
                                <!-- Print current URL -->
1919
                                <table border="0" cellpadding="0" cellspacing="0" id="typo3-curUrl">
1920
                                        <tr>
1921
                                                <td>' . $GLOBALS['LANG']->getLL('currentLink', 1) . ': ' . htmlspecialchars(rawurldecode($str)) . '</td>
1922
                                        </tr>
1923
                                </table>';
1924
                } else {
1925
                        return '';
1926
                }
1927
        }
1928

    
1929
        /**
1930
         * For RTE/link: Parses the incoming URL and determines if it's a page, file, external or mail address.
1931
         *
1932
         * @param string $href HREF value tp analyse
1933
         * @param string $siteUrl The URL of the current website (frontend)
1934
         * @return array Array with URL information stored in assoc. keys: value, act (page, file, spec, mail), pageid, cElement, info
1935
         * @todo Define visibility
1936
         */
1937
        public function parseCurUrl($href, $siteUrl) {
1938
                $href = trim($href);
1939
                if ($href) {
1940
                        $info = array();
1941
                        // Default is "url":
1942
                        $info['value'] = $href;
1943
                        $info['act'] = 'url';
1944
                        $specialParts = explode('#_SPECIAL', $href);
1945
                        // Special kind (Something RTE specific: User configurable links through: "userLinks." from ->thisConfig)
1946
                        if (count($specialParts) == 2) {
1947
                                $info['value'] = '#_SPECIAL' . $specialParts[1];
1948
                                $info['act'] = 'spec';
1949
                        } elseif (strpos($href, 'file:') !== FALSE) {
1950
                                $rel = substr($href, strpos($href, 'file:') + 5);
1951
                                $rel = rawurldecode($rel);
1952
                                // resolve FAL-api "file:UID-of-sys_file-record" and "file:combined-identifier"
1953
                                $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($rel);
1954
                                if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
1955
                                        $info['act'] = 'folder';
1956
                                        $info['value'] = $fileOrFolderObject->getCombinedIdentifier();
1957
                                } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
1958
                                        $info['act'] = 'file';
1959
                                        $info['value'] = $fileOrFolderObject->getUid();
1960
                                } else {
1961
                                        $info['value'] = $rel;
1962
                                }
1963
                        } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($href, $siteUrl)) {
1964
                                // If URL is on the current frontend website:
1965
                                // URL is a file, which exists:
1966
                                if (file_exists(PATH_site . rawurldecode($href))) {
1967
                                        $info['value'] = rawurldecode($href);
1968
                                        if (@is_dir((PATH_site . $info['value']))) {
1969
                                                $info['act'] = 'folder';
1970
                                        } else {
1971
                                                $info['act'] = 'file';
1972
                                        }
1973
                                } else {
1974
                                        // URL is a page (id parameter)
1975
                                        $uP = parse_url($href);
1976

    
1977
                                        $pp = preg_split('/^id=/', $uP['query']);
1978
                                        $pp[1] = preg_replace('/&id=[^&]*/', '', $pp[1]);
1979
                                        $parameters = explode('&', $pp[1]);
1980
                                        $id = array_shift($parameters);
1981
                                        if ($id) {
1982
                                                // Checking if the id-parameter is an alias.
1983
                                                if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($id)) {
1984
                                                        list($idPartR) = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordsByField('pages', 'alias', $id);
1985
                                                        $id = intval($idPartR['uid']);
1986
                                                }
1987
                                                $pageRow = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL('pages', $id);
1988
                                                $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
1989
                                                $info['value'] = ((((($GLOBALS['LANG']->getLL('page', 1) . ' \'') . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($pageRow['title'], $titleLen))) . '\' (ID:') . $id) . ($uP['fragment'] ? ', #' . $uP['fragment'] : '')) . ')';
1990
                                                $info['pageid'] = $id;
1991
                                                $info['cElement'] = $uP['fragment'];
1992
                                                $info['act'] = 'page';
1993
                                                $info['query'] = $parameters[0] ? '&' . implode('&', $parameters) : '';
1994
                                        }
1995
                                }
1996
                        } else {
1997
                                // Email link:
1998
                                if (strtolower(substr($href, 0, 7)) == 'mailto:') {
1999
                                        $info['value'] = trim(substr($href, 7));
2000
                                        $info['act'] = 'mail';
2001
                                }
2002
                        }
2003
                        $info['info'] = $info['value'];
2004
                } else {
2005
                        // NO value inputted:
2006
                        $info = array();
2007
                        $info['info'] = $GLOBALS['LANG']->getLL('none');
2008
                        $info['value'] = '';
2009
                        $info['act'] = 'page';
2010
                }
2011
                // let the hook have a look
2012
                foreach ($this->hookObjects as $hookObject) {
2013
                        $info = $hookObject->parseCurrentUrl($href, $siteUrl, $info);
2014
                }
2015
                return $info;
2016
        }
2017

    
2018
        /**
2019
         * For TBE: Makes an upload form for uploading files to the filemount the user is browsing.
2020
         * The files are uploaded to the tce_file.php script in the core which will handle the upload.
2021
         *
2022
         * @param \TYPO3\CMS\Core\Resource\Folder $folderObject Absolute filepath on server to which to upload.
2023
         * @return string HTML for an upload form.
2024
         * @todo Define visibility
2025
         */
2026
        public function uploadForm(\TYPO3\CMS\Core\Resource\Folder $folderObject) {
2027
                if (!$folderObject->checkActionPermission('write')) {
2028
                        return '';
2029
                }
2030
                // Read configuration of upload field count
2031
                $userSetting = $GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.uploadFieldsInLinkBrowser');
2032
                $count = isset($userSetting) ? $userSetting : 3;
2033
                if ($count === '0') {
2034
                        return '';
2035
                }
2036
                $count = intval($count) == 0 ? 3 : intval($count);
2037
                // Create header, showing upload path:
2038
                $header = $folderObject->getIdentifier();
2039
                $code = '
2040
                        <br />
2041
                        <!--
2042
                                Form, for uploading files:
2043
                        -->
2044
                        <form action="' . $GLOBALS['BACK_PATH'] . 'tce_file.php" method="post" name="editform" id="typo3-uplFilesForm" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">
2045
                                <table border="0" cellpadding="0" cellspacing="0" id="typo3-uplFiles">
2046
                                        <tr>
2047
                                                <td>' . $this->barheader(($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle', 1) . ':')) . '</td>
2048
                                        </tr>
2049
                                        <tr>
2050
                                                <td class="c-wCell c-hCell"><strong>' . $GLOBALS['LANG']->getLL('path', 1) . ':</strong> ' . htmlspecialchars($header) . '</td>
2051
                                        </tr>
2052
                                        <tr>
2053
                                                <td class="c-wCell c-hCell">';
2054
                // Traverse the number of upload fields (default is 3):
2055
                for ($a = 1; $a <= $count; $a++) {
2056
                        $code .= '<input type="file" multiple="multiple" name="upload_' . $a . '"' . $this->doc->formWidth(35) . ' size="50" />
2057
                                <input type="hidden" name="file[upload][' . $a . '][target]" value="' . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />
2058
                                <input type="hidden" name="file[upload][' . $a . '][data]" value="' . $a . '" /><br />';
2059
                }
2060
                // Make footer of upload form, including the submit button:
2061
                $redirectValue = $this->thisScript . '?act=' . $this->act . '&mode=' . $this->mode . '&expandFolder=' . rawurlencode($folderObject->getCombinedIdentifier()) . '&bparams=' . rawurlencode($this->bparams);
2062
                $code .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
2063
                $code .= '
2064
                        <div id="c-override">
2065
                                <label><input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xml:overwriteExistingFiles', 1) . '</label>
2066
                        </div>
2067
                        <input type="submit" name="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit', 1) . '" />
2068
                ';
2069
                $code .= '</td>
2070
                                        </tr>
2071
                                </table>
2072
                        </form><br />';
2073
                return $code;
2074
        }
2075

    
2076
        /**
2077
         * For TBE: Makes a form for creating new folders in the filemount the user is browsing.
2078
         * The folder creation request is sent to the tce_file.php script in the core which will handle the creation.
2079
         *
2080
         * @param \TYPO3\CMS\Core\Resource\Folder $folderObject Absolute filepath on server in which to create the new folder.
2081
         * @return string HTML for the create folder form.
2082
         * @todo Define visibility
2083
         */
2084
        public function createFolder(\TYPO3\CMS\Core\Resource\Folder $folderObject) {
2085
                if (!$folderObject->checkActionPermission('write')) {
2086
                        return '';
2087
                }
2088
                // Don't show Folder-create form if it's denied
2089
                if ($GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.hideCreateFolder')) {
2090
                        return '';
2091
                }
2092
                // Create header, showing upload path:
2093
                $header = $folderObject->getIdentifier();
2094
                $code = '
2095

2096
                        <!--
2097
                                Form, for creating new folders:
2098
                        -->
2099
                        <form action="' . $GLOBALS['BACK_PATH'] . 'tce_file.php" method="post" name="editform2" id="typo3-crFolderForm">
2100
                                <table border="0" cellpadding="0" cellspacing="0" id="typo3-crFolder">
2101
                                        <tr>
2102
                                                <td>' . $this->barheader(($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.pagetitle') . ':')) . '</td>
2103
                                        </tr>
2104
                                        <tr>
2105
                                                <td class="c-wCell c-hCell"><strong>' . $GLOBALS['LANG']->getLL('path', 1) . ':</strong> ' . htmlspecialchars($header) . '</td>
2106
                                        </tr>
2107
                                        <tr>
2108
                                                <td class="c-wCell c-hCell">';
2109
                // Create the new-folder name field:
2110
                $a = 1;
2111
                $code .= '<input' . $this->doc->formWidth(20) . ' type="text" name="file[newfolder][' . $a . '][data]" />' . '<input type="hidden" name="file[newfolder][' . $a . '][target]" value="' . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />';
2112
                // Make footer of upload form, including the submit button:
2113
                $redirectValue = $this->thisScript . '?act=' . $this->act . '&mode=' . $this->mode . '&expandFolder=' . rawurlencode($folderObject->getCombinedIdentifier()) . '&bparams=' . rawurlencode($this->bparams);
2114
                $code .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />' . '<input type="submit" name="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.submit', 1) . '" />';
2115
                $code .= '</td>
2116
                                        </tr>
2117
                                </table>
2118
                        </form>';
2119
                return $code;
2120
        }
2121

    
2122
        /**
2123
         * Get the HTML data required for a bulk selection of files of the TYPO3 Element Browser.
2124
         *
2125
         * @param integer $filesCount Number of files currently displayed
2126
         * @return string HTML data required for a bulk selection of files - if $filesCount is 0, nothing is returned
2127
         * @todo Define visibility
2128
         */
2129
        public function getBulkSelector($filesCount) {
2130
                if ($filesCount) {
2131
                        $labelToggleSelection = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.php:toggleSelection', 1);
2132
                        $labelImportSelection = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.php:importSelection', 1);
2133
                        // Getting flag for showing/not showing thumbnails:
2134
                        $noThumbsInEB = $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInEB');
2135
                        $out = $this->doc->spacer(10) . '<div>' . '<a href="#" onclick="BrowseLinks.Selector.handle()">' . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/import.gif', 'width="12" height="12"') . ' title="' . $labelImportSelection . '" alt="" /> ' . $labelImportSelection . '</a>&nbsp;&nbsp;&nbsp;' . '<a href="#" onclick="BrowseLinks.Selector.toggle()">' . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/clip_select.gif', 'width="12" height="12"') . ' title="' . $labelToggleSelection . '" alt="" /> ' . $labelToggleSelection . '</a>' . '</div>';
2136
                        $thumbNailCheck = '';
2137
                        if (!$noThumbsInEB && $this->selectedFolder) {
2138
                                // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
2139
                                $_MOD_MENU = array('displayThumbs' => '');
2140
                                $_MCONF['name'] = 'file_list';
2141
                                $_MOD_SETTINGS = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleData($_MOD_MENU, \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('SET'), $_MCONF['name']);
2142
                                $addParams = '&act=' . $this->act . '&mode=' . $this->mode . '&expandFolder=' . rawurlencode($this->selectedFolder->getCombinedIdentifier()) . '&bparams=' . rawurlencode($this->bparams);
2143
                                $thumbNailCheck = \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck('', 'SET[displayThumbs]', $_MOD_SETTINGS['displayThumbs'], $this->thisScript, $addParams, 'id="checkDisplayThumbs"') . ' <label for="checkDisplayThumbs">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.php:displayThumbs', 1) . '</label>';
2144
                                $out .= $this->doc->spacer(5) . $thumbNailCheck . $this->doc->spacer(15);
2145
                        } else {
2146
                                $out .= $this->doc->spacer(15);
2147
                        }
2148
                }
2149
                return $out;
2150
        }
2151

    
2152
        /**
2153
         * Determines whether submitted field change functions are valid
2154
         * and are coming from the system and not from an external abuse.
2155
         *
2156
         * @param boolean $handleFlexformSections Whether to handle flexform sections differently
2157
         * @return boolean Whether the submitted field change functions are valid
2158
         */
2159
        protected function areFieldChangeFunctionsValid($handleFlexformSections = FALSE) {
2160
                $result = FALSE;
2161
                if (isset($this->P['fieldChangeFunc']) && is_array($this->P['fieldChangeFunc']) && isset($this->P['fieldChangeFuncHash'])) {
2162
                        $matches = array();
2163
                        $pattern = '#\\[el\\]\\[(([^]-]+-[^]-]+-)(idx\\d+-)([^]]+))\\]#i';
2164
                        $fieldChangeFunctions = $this->P['fieldChangeFunc'];
2165
                        // Special handling of flexform sections:
2166
                        // Field change functions are modified in JavaScript, thus the hash is always invalid
2167
                        if ($handleFlexformSections && preg_match($pattern, $this->P['itemName'], $matches)) {
2168
                                $originalName = $matches[1];
2169
                                $cleanedName = $matches[2] . $matches[4];
2170
                                foreach ($fieldChangeFunctions as &$value) {
2171
                                        $value = str_replace($originalName, $cleanedName, $value);
2172
                                }
2173
                                unset($value);
2174
                        }
2175
                        $result = $this->P['fieldChangeFuncHash'] === \TYPO3\CMS\Core\Utility\GeneralUtility::hmac(serialize($fieldChangeFunctions));
2176
                }
2177
                return $result;
2178
        }
2179

    
2180
}
2181

    
2182

    
2183
?>