[BUGFIX] Re-introduce read-only file mounts
[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 * @todo Define visibility
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 * @todo Define visibility
44 */
45 public $browser;
46
47 /**
48 * Document template object
49 *
50 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
51 * @todo Define visibility
52 */
53 public $doc;
54
55 /**
56 * Constructor
57 */
58 public function __construct() {
59 $GLOBALS['SOBE'] = $this;
60 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_browse_links.xlf');
61 $GLOBALS['BACK_PATH'] = '';
62
63 $this->init();
64 }
65
66 /**
67 * Not really needed but for backwards compatibility ...
68 *
69 * @return void
70 */
71 protected function init() {
72 // Find "mode"
73 $this->mode = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('mode');
74 if (!$this->mode) {
75 $this->mode = 'rte';
76 }
77 // Creating backend template object:
78 // this might not be needed but some classes refer to $GLOBALS['SOBE']->doc, so ...
79 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
80 $this->doc->backPath = $GLOBALS['BACK_PATH'];
81 // Apply the same styles as those of the base script
82 $this->doc->bodyTagId = 'typo3-browse-links-php';
83
84 }
85
86 /**
87 * Main function, detecting the current mode of the element browser and branching out to internal methods.
88 *
89 * @return void
90 */
91 public function main() {
92 // Clear temporary DB mounts
93 $tmpMount = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('setTempDBmount');
94 if (isset($tmpMount)) {
95 $GLOBALS['BE_USER']->setAndSaveSessionData('pageTree_temporaryMountPoint', (int)$tmpMount);
96 }
97 // Set temporary DB mounts
98 $tempDBmount = (int)$GLOBALS['BE_USER']->getSessionData('pageTree_temporaryMountPoint');
99 if ($tempDBmount) {
100 $altMountPoints = $tempDBmount;
101 }
102 if ($altMountPoints) {
103 $GLOBALS['BE_USER']->groupData['webmounts'] = implode(',', array_unique(\TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $altMountPoints)));
104 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
105 }
106 $this->content = '';
107 // Look for alternative mountpoints
108 switch ((string) $this->mode) {
109 case 'rte':
110 case 'db':
111 case 'wizard':
112 // Setting alternative browsing mounts (ONLY local to browse_links.php this script so they stay "read-only")
113 $altMountPoints = trim($GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.altElementBrowserMountPoints'));
114 if ($altMountPoints) {
115 $GLOBALS['BE_USER']->groupData['webmounts'] = implode(',', array_unique(\TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $altMountPoints)));
116 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
117 }
118 }
119 // Render type by user func
120 $browserRendered = FALSE;
121 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'])) {
122 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'] as $classRef) {
123 $browserRenderObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
124 if (is_object($browserRenderObj) && method_exists($browserRenderObj, 'isValid') && method_exists($browserRenderObj, 'render')) {
125 if ($browserRenderObj->isValid($this->mode, $this)) {
126 $this->content .= $browserRenderObj->render($this->mode, $this);
127 $browserRendered = TRUE;
128 break;
129 }
130 }
131 }
132 }
133 // if type was not rendered use default rendering functions
134 if (!$browserRendered) {
135 $this->browser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Recordlist\\Browser\\ElementBrowser');
136 $this->browser->init();
137 $modData = $GLOBALS['BE_USER']->getModuleData('browse_links.php', 'ses');
138 list($modData, $store) = $this->browser->processSessionData($modData);
139 $GLOBALS['BE_USER']->pushModuleData('browse_links.php', $modData);
140 // Output the correct content according to $this->mode
141 switch ((string) $this->mode) {
142 case 'rte':
143 $this->content = $this->browser->main_rte();
144 break;
145 case 'db':
146 $this->content = $this->browser->main_db();
147 break;
148 case 'file':
149 case 'filedrag':
150 $this->content = $this->browser->main_file();
151 break;
152 case 'folder':
153 $this->content = $this->browser->main_folder();
154 break;
155 case 'wizard':
156 $this->content = $this->browser->main_rte(1);
157 break;
158 }
159 }
160 }
161
162 /**
163 * Print module content
164 *
165 * @return void
166 */
167 public function printContent() {
168 echo $this->content;
169 }
170
171 }