[TASK] Move classAliasMaps into compatibility6 extension part 6
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Classes / Controller / ElementBrowserController.php
1 <?php
2 namespace TYPO3\CMS\Recordlist\Controller;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Script class for the Element Browser window.
19 *
20 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
21 */
22 class ElementBrowserController {
23
24 /**
25 * The mode determines the main kind of output from the element browser.
26 * There are these options for values: rte, db, file, filedrag, wizard.
27 * "rte" will show the link selector for the Rich Text Editor (see main_rte())
28 * "db" will allow you to browse for pages or records in the page tree (for TCEforms, see main_db())
29 * "file"/"filedrag" will allow you to browse for files or folders in the folder mounts (for TCEforms, main_file())
30 * "wizard" will allow you to browse for links (like "rte") which are passed back to TCEforms (see main_rte(1))
31 *
32 * @see main()
33 * @var string
34 */
35 public $mode;
36
37 /**
38 * Holds Instance of main browse_links class
39 * needed fo intercommunication between various classes that need access to variables via $GLOBALS['SOBE']
40 * Not the most nice solution but introduced since we don't have another general way to return class-instances or registry for now
41 *
42 * @var \TYPO3\CMS\Recordlist\Browser\ElementBrowser
43 */
44 public $browser;
45
46 /**
47 * Document template object
48 *
49 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
50 */
51 public $doc;
52
53 /**
54 * Constructor
55 */
56 public function __construct() {
57 $GLOBALS['SOBE'] = $this;
58 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_browse_links.xlf');
59 $GLOBALS['BACK_PATH'] = '';
60
61 $this->init();
62 }
63
64 /**
65 * Not really needed but for backwards compatibility ...
66 *
67 * @return void
68 */
69 protected function init() {
70 // Find "mode"
71 $this->mode = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('mode');
72 if (!$this->mode) {
73 $this->mode = 'rte';
74 }
75 // Creating backend template object:
76 // this might not be needed but some classes refer to $GLOBALS['SOBE']->doc, so ...
77 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
78 $this->doc->backPath = $GLOBALS['BACK_PATH'];
79 // Apply the same styles as those of the base script
80 $this->doc->bodyTagId = 'typo3-browse-links-php';
81
82 }
83
84 /**
85 * Main function, detecting the current mode of the element browser and branching out to internal methods.
86 *
87 * @return void
88 */
89 public function main() {
90 // Clear temporary DB mounts
91 $tmpMount = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('setTempDBmount');
92 if (isset($tmpMount)) {
93 $GLOBALS['BE_USER']->setAndSaveSessionData('pageTree_temporaryMountPoint', (int)$tmpMount);
94 }
95 // Set temporary DB mounts
96 $tempDBmount = (int)$GLOBALS['BE_USER']->getSessionData('pageTree_temporaryMountPoint');
97 if ($tempDBmount) {
98 $altMountPoints = $tempDBmount;
99 }
100 if ($altMountPoints) {
101 $GLOBALS['BE_USER']->groupData['webmounts'] = implode(',', array_unique(\TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $altMountPoints)));
102 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
103 }
104 $this->content = '';
105 // Look for alternative mountpoints
106 switch ((string)$this->mode) {
107 case 'rte':
108 case 'db':
109 case 'wizard':
110 // Setting alternative browsing mounts (ONLY local to browse_links.php this script so they stay "read-only")
111 $altMountPoints = trim($GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.altElementBrowserMountPoints'));
112 if ($altMountPoints) {
113 $GLOBALS['BE_USER']->groupData['webmounts'] = implode(',', array_unique(\TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $altMountPoints)));
114 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
115 }
116 }
117 // Render type by user func
118 $browserRendered = FALSE;
119 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'])) {
120 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'] as $classRef) {
121 $browserRenderObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
122 if (is_object($browserRenderObj) && method_exists($browserRenderObj, 'isValid') && method_exists($browserRenderObj, 'render')) {
123 if ($browserRenderObj->isValid($this->mode, $this)) {
124 $this->content .= $browserRenderObj->render($this->mode, $this);
125 $browserRendered = TRUE;
126 break;
127 }
128 }
129 }
130 }
131 // if type was not rendered use default rendering functions
132 if (!$browserRendered) {
133 $this->browser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Recordlist\Browser\ElementBrowser::class);
134 $this->browser->init();
135 $modData = $GLOBALS['BE_USER']->getModuleData('browse_links.php', 'ses');
136 list($modData, $store) = $this->browser->processSessionData($modData);
137 $GLOBALS['BE_USER']->pushModuleData('browse_links.php', $modData);
138 // Output the correct content according to $this->mode
139 switch ((string)$this->mode) {
140 case 'rte':
141 $this->content = $this->browser->main_rte();
142 break;
143 case 'db':
144 $this->content = $this->browser->main_db();
145 break;
146 case 'file':
147 case 'filedrag':
148 $this->content = $this->browser->main_file();
149 break;
150 case 'folder':
151 $this->content = $this->browser->main_folder();
152 break;
153 case 'wizard':
154 $this->content = $this->browser->main_rte(TRUE);
155 break;
156 }
157 }
158 }
159
160 /**
161 * Print module content
162 *
163 * @return void
164 */
165 public function printContent() {
166 echo $this->content;
167 }
168
169 }